Search in sources :

Example 31 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class TypeChecker method checkStructLiteralKeyExpr.

private BType checkStructLiteralKeyExpr(BLangRecordKey key, BType recordType, RecordKind recKind) {
    Name fieldName;
    BLangExpression keyExpr = key.expr;
    if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
        BLangSimpleVarRef varRef = (BLangSimpleVarRef) keyExpr;
        fieldName = names.fromIdNode(varRef.variableName);
    } else {
        // keys of the struct literal can only be a varRef (identifier)
        dlog.error(keyExpr.pos, DiagnosticCode.INVALID_STRUCT_LITERAL_KEY);
        return symTable.errType;
    }
    // Check weather the struct field exists
    BSymbol fieldSymbol = symResolver.resolveStructField(keyExpr.pos, this.env, fieldName, recordType.tsymbol);
    if (fieldSymbol == symTable.notFoundSymbol) {
        dlog.error(keyExpr.pos, DiagnosticCode.UNDEFINED_STRUCT_FIELD, fieldName, recordType.tsymbol);
        return symTable.errType;
    }
    // Setting the struct field symbol for future use in Desugar and code generator.
    key.fieldSymbol = (BVarSymbol) fieldSymbol;
    return fieldSymbol.type;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 32 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class BLangService method bindToEndpoint.

@Override
public void bindToEndpoint(SimpleVariableReferenceNode endpointRef) {
    final BLangSimpleVarRef endpointVar = (BLangSimpleVarRef) endpointRef;
    this.boundEndpoints.add(0, endpointVar);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)

Example 33 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createForeach.

static BLangForeach createForeach(DiagnosticPos pos, BLangBlockStmt target, BLangSimpleVarRef collectionVarRef, List<BLangSimpleVarRef> varRefs, List<BType> inputTypes) {
    final BLangForeach foreach = (BLangForeach) TreeBuilder.createForeachNode();
    foreach.pos = pos;
    target.addStatement(foreach);
    foreach.body = ASTBuilderUtil.createBlockStmt(pos);
    foreach.collection = collectionVarRef;
    foreach.varRefs.addAll(varRefs);
    foreach.varTypes = inputTypes;
    return foreach;
}
Also used : BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach)

Example 34 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createVariableRef.

static BLangSimpleVarRef createVariableRef(DiagnosticPos pos, BVarSymbol varSymbol) {
    final BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
    varRef.pos = pos;
    varRef.variableName = createIdentifier(pos, varSymbol.name.value);
    varRef.symbol = varSymbol;
    varRef.type = varSymbol.type;
    return varRef;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)

Example 35 with BLangSimpleVarRef

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.

the class Desugar method visitFunctionPointerInvocation.

// private functions
private void visitFunctionPointerInvocation(BLangInvocation iExpr) {
    BLangVariableReference expr;
    if (iExpr.expr == null) {
        expr = new BLangSimpleVarRef();
    } else {
        BLangFieldBasedAccess fieldBasedAccess = new BLangFieldBasedAccess();
        fieldBasedAccess.expr = iExpr.expr;
        fieldBasedAccess.field = iExpr.name;
        expr = fieldBasedAccess;
    }
    expr.symbol = (BVarSymbol) iExpr.symbol;
    expr.type = iExpr.symbol.type;
    expr = rewriteExpr(expr);
    result = new BFunctionPointerInvocation(iExpr, expr);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BFunctionPointerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BFunctionPointerInvocation)

Aggregations

BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)36 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)11 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 Name (org.wso2.ballerinalang.compiler.util.Name)8 ArrayList (java.util.ArrayList)7 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)6 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)5 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)4 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)3 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)3 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)3 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)2 BLangFieldBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess)2 BLangJSONLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral)2 BLangMapLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral)2