Search in sources :

Example 61 with BLangVariable

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

the class SemanticAnalyzer method visit.

public void visit(BLangVariable varNode) {
    int ownerSymTag = env.scope.owner.tag;
    if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
        // If the variable is parameter then the variable symbol is already defined
        if (varNode.symbol == null) {
            symbolEnter.defineNode(varNode, env);
        }
    }
    BType lhsType = varNode.symbol.type;
    varNode.type = lhsType;
    // Here we validate annotation attachments for package level variables.
    varNode.annAttachments.forEach(a -> {
        a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.CONST);
        a.accept(this);
    });
    // Here we validate document attachments for package level variables.
    varNode.docAttachments.forEach(doc -> {
        doc.accept(this);
    });
    // Analyze the init expression
    BLangExpression rhsExpr = varNode.expr;
    if (rhsExpr == null) {
        return;
    }
    // Here we create a new symbol environment to catch self references by keep the current
    // variable symbol in the symbol environment
    // e.g. int a = x + a;
    SymbolEnv varInitEnv = SymbolEnv.createVarInitEnv(varNode, env, varNode.symbol);
    // It will we done during the init-function of the respective construct is visited.
    if ((ownerSymTag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymTag & SymTag.SERVICE) == SymTag.SERVICE || (ownerSymTag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
        return;
    }
    // Return if this not a safe assignment
    if (!varNode.safeAssignment) {
        typeChecker.checkExpr(rhsExpr, varInitEnv, Lists.of(lhsType));
        return;
    }
    handleSafeAssignment(varNode.pos, lhsType, rhsExpr, varInitEnv);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 62 with BLangVariable

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

the class SemanticAnalyzer method visit.

// Streaming related methods.
public void visit(BLangForever foreverStatement) {
    for (StreamingQueryStatementNode streamingQueryStatement : foreverStatement.gettreamingQueryStatements()) {
        analyzeStmt((BLangStatement) streamingQueryStatement, env);
    }
    List<BLangVariable> globalVariableList = this.env.enclPkg.globalVars;
    if (globalVariableList != null) {
        for (BLangVariable variable : globalVariableList) {
            if (((variable).type.tsymbol) != null) {
                if ("stream".equals((((variable).type.tsymbol)).name.value)) {
                    foreverStatement.addGlobalVariable(variable);
                }
            }
        }
    }
    List<BVarSymbol> functionParameterList = ((BInvokableSymbol) this.env.scope.owner).getParameters();
    for (BVarSymbol varSymbol : functionParameterList) {
        if ("stream".equals((((varSymbol).type.tsymbol)).name.value)) {
            foreverStatement.addFunctionVariable(varSymbol);
        }
    }
}
Also used : StreamingQueryStatementNode(org.ballerinalang.model.tree.statements.StreamingQueryStatementNode) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 63 with BLangVariable

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

the class SemanticAnalyzer method validateTransformerMappingType.

private void validateTransformerMappingType(BLangVariable param) {
    BType type = param.type;
    if (types.isValueType(type) || (type instanceof BBuiltInRefType) || type.tag == TypeTags.STRUCT) {
        return;
    }
    dlog.error(param.pos, DiagnosticCode.TRANSFORMER_UNSUPPORTED_TYPES, type);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BBuiltInRefType(org.wso2.ballerinalang.compiler.semantics.model.types.BBuiltInRefType)

Example 64 with BLangVariable

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

the class CodeGenerator method createPackageVarInfo.

// Create info entries
private void createPackageVarInfo(BLangVariable varNode) {
    BVarSymbol varSymbol = varNode.symbol;
    varSymbol.varIndex = getPVIndex(varSymbol.type.tag);
    int varNameCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.name.value);
    int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.type.getDesc());
    PackageVarInfo pkgVarInfo = new PackageVarInfo(varNameCPIndex, typeSigCPIndex, varSymbol.flags, varSymbol.varIndex.value);
    currentPkgInfo.pkgVarInfoMap.put(varSymbol.name.value, pkgVarInfo);
    LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
    LocalVariableAttributeInfo pkgVarAttrInfo = (LocalVariableAttributeInfo) currentPkgInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
    pkgVarAttrInfo.localVars.add(localVarInfo);
// TODO Populate annotation attribute
}
Also used : LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) PackageVarInfo(org.wso2.ballerinalang.programfile.PackageVarInfo) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 65 with BLangVariable

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

the class CodeGenerator method visit.

public void visit(BLangVariable varNode) {
    BVarSymbol varSymbol = varNode.symbol;
    int ownerSymTag = env.scope.owner.tag;
    if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
        varSymbol.varIndex = getLVIndex(varSymbol.type.tag);
        LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
        localVarAttrInfo.localVars.add(localVarInfo);
    } else {
        // TODO Support other variable nodes
        throw new IllegalStateException("");
    }
    BLangExpression rhsExpr = varNode.expr;
    if (rhsExpr != null) {
        rhsExpr.regIndex = varSymbol.varIndex;
        genNode(rhsExpr, this.env);
    }
}
Also used : LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)77 ArrayList (java.util.ArrayList)21 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)20 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)18 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)16 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)15 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)14 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)10 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)10 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)9 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 Whitespace (org.ballerinalang.model.Whitespace)7 BLangObject (org.wso2.ballerinalang.compiler.tree.BLangObject)7 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)7 Name (org.wso2.ballerinalang.compiler.util.Name)7 HashMap (java.util.HashMap)6 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)6