Search in sources :

Example 46 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

// Visitor methods
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.TYPE_CHECK)) {
        return;
    }
    SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgNode.symbol);
    // Visit all the imported packages
    pkgNode.imports.forEach(importNode -> analyzeDef(importNode, pkgEnv));
    // Then visit each top-level element sorted using the compilation unit
    pkgNode.topLevelNodes.forEach(topLevelNode -> analyzeDef((BLangNode) topLevelNode, pkgEnv));
    analyzeDef(pkgNode.initFunction, pkgEnv);
    analyzeDef(pkgNode.startFunction, pkgEnv);
    analyzeDef(pkgNode.stopFunction, pkgEnv);
    pkgNode.completedPhases.add(CompilerPhase.TYPE_CHECK);
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 47 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangImportPackage importPkgNode) {
    BPackageSymbol pkgSymbol = importPkgNode.symbol;
    SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgSymbol);
    if (pkgEnv == null) {
        return;
    }
    analyzeDef(pkgEnv.node, pkgEnv);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 48 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangForeach foreach) {
    typeChecker.checkExpr(foreach.collection, env);
    foreach.varTypes = types.checkForeachTypes(foreach.collection, foreach.varRefs.size());
    SymbolEnv blockEnv = SymbolEnv.createBlockEnv(foreach.body, env);
    handleForeachVariables(foreach, foreach.varTypes, blockEnv);
    analyzeStmt(foreach.body, blockEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 49 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangTransformer transformerNode) {
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
    transformerNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.TRANSFORMER);
        this.analyzeDef(annotationAttachment, transformerEnv);
    });
    transformerNode.docAttachments.forEach(doc -> analyzeDef(doc, transformerEnv));
    validateTransformerMappingType(transformerNode.source);
    validateTransformerMappingType(transformerNode.retParams.get(0));
    analyzeStmt(transformerNode.body, transformerEnv);
    // TODO: update this accordingly once the unsafe conversion are supported
    int returnCount = transformerNode.retParams.size();
    if (returnCount == 0) {
        dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_MUST_HAVE_OUTPUT);
    } else if (returnCount > 1) {
        dlog.error(transformerNode.pos, DiagnosticCode.TOO_MANY_OUTPUTS_FOR_TRANSFORMER, 1, returnCount);
    }
    this.processWorkers(transformerNode, transformerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 50 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class TypeChecker method checkExpr.

public List<BType> checkExpr(BLangExpression expr, SymbolEnv env, List<BType> expTypes, DiagnosticCode diagCode) {
    // TODO Check the possibility of using a try/finally here
    SymbolEnv prevEnv = this.env;
    List<BType> preExpTypes = this.expTypes;
    DiagnosticCode preDiagCode = this.diagCode;
    this.env = env;
    this.diagCode = diagCode;
    this.expTypes = expTypes;
    expr.accept(this);
    setExprType(expr, expTypes);
    this.env = prevEnv;
    this.expTypes = preExpTypes;
    this.diagCode = preDiagCode;
    return resultTypes;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)125 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)47 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)30 Name (org.wso2.ballerinalang.compiler.util.Name)26 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)25 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)24 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)22 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)20 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)20 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)19 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)18 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)17 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)17 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)17 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)17 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)17