Search in sources :

Example 41 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(BLangCatch bLangCatch) {
    SymbolEnv catchBlockEnv = SymbolEnv.createBlockEnv(bLangCatch.body, env);
    analyzeNode(bLangCatch.param, catchBlockEnv);
    if (!this.types.checkStructEquivalency(bLangCatch.param.type, symTable.errStructType)) {
        dlog.error(bLangCatch.param.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.errStructType, bLangCatch.param.type);
    }
    analyzeStmt(bLangCatch.body, catchBlockEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 42 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(BLangStruct structNode) {
    BSymbol structSymbol = structNode.symbol;
    SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, env);
    structNode.fields.forEach(field -> analyzeDef(field, structEnv));
    structNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.STRUCT);
        annotationAttachment.accept(this);
    });
    analyzeDef(structNode.initFunction, structEnv);
    structNode.docAttachments.forEach(doc -> analyzeDef(doc, structEnv));
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 43 with SymbolEnv

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

the class SemanticAnalyzer method defineResourceEndpoint.

private void defineResourceEndpoint(BLangResource resourceNode, SymbolEnv resourceEnv) {
    if (!resourceNode.getParameters().isEmpty()) {
        final BLangVariable variable = resourceNode.getParameters().get(0);
        if (variable.type == symTable.endpointType) {
            String actualVarName = variable.name.value.substring(1);
            variable.name = new BLangIdentifier();
            variable.name.value = actualVarName;
            if (resourceEnv.enclService.endpointType != null) {
                variable.type = resourceEnv.enclService.endpointType;
                final BEndpointVarSymbol bEndpointVarSymbol = symbolEnter.defineEndpointVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
                variable.symbol = bEndpointVarSymbol;
                endpointSPIAnalyzer.populateEndpointSymbol((BStructSymbol) variable.type.tsymbol, bEndpointVarSymbol);
            } else {
                variable.type = symTable.errType;
                variable.symbol = symbolEnter.defineVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
            }
            // Replace old symbol with new one.
            resourceNode.symbol.params.remove(0);
            resourceNode.symbol.params.add(0, variable.symbol);
            ((BInvokableType) resourceNode.symbol.type).paramTypes.remove(0);
            ((BInvokableType) resourceNode.symbol.type).paramTypes.add(0, variable.type);
        }
    }
}
Also used : BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) Flag(org.ballerinalang.model.elements.Flag) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 44 with SymbolEnv

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

the class SemanticAnalyzer method analyzeNode.

BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
    SymbolEnv prevEnv = this.env;
    BType preExpType = this.expType;
    DiagnosticCode preDiagCode = this.diagCode;
    // TODO Check the possibility of using a try/finally here
    this.env = env;
    this.expType = expType;
    this.diagCode = diagCode;
    node.accept(this);
    this.env = prevEnv;
    this.expType = preExpType;
    this.diagCode = preDiagCode;
    return resType;
}
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)

Example 45 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(BLangForkJoin forkJoin) {
    SymbolEnv forkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.env);
    forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, forkJoinEnv));
    forkJoin.workers.forEach(e -> this.analyzeDef(e, forkJoinEnv));
    if (!this.isJoinResultType(forkJoin.joinResultVar)) {
        this.dlog.error(forkJoin.joinResultVar.pos, DiagnosticCode.INVALID_WORKER_JOIN_RESULT_TYPE);
    }
    /* create code black and environment for join result section, i.e. (map results) */
    BLangBlockStmt joinResultsBlock = this.generateCodeBlock(this.createVarDef(forkJoin.joinResultVar));
    SymbolEnv joinResultsEnv = SymbolEnv.createBlockEnv(joinResultsBlock, this.env);
    this.analyzeNode(joinResultsBlock, joinResultsEnv);
    /* create an environment for the join body, making the enclosing environment the earlier
         * join result's environment */
    SymbolEnv joinBodyEnv = SymbolEnv.createBlockEnv(forkJoin.joinedBody, joinResultsEnv);
    this.analyzeNode(forkJoin.joinedBody, joinBodyEnv);
    if (forkJoin.timeoutExpression != null) {
        if (!this.isJoinResultType(forkJoin.timeoutVariable)) {
            this.dlog.error(forkJoin.timeoutVariable.pos, DiagnosticCode.INVALID_WORKER_TIMEOUT_RESULT_TYPE);
        }
        /* create code black and environment for timeout section */
        BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
        SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.env);
        this.typeChecker.checkExpr(forkJoin.timeoutExpression, timeoutVarEnv, Arrays.asList(symTable.intType));
        this.analyzeNode(timeoutVarBlock, timeoutVarEnv);
        /* create an environment for the timeout body, making the enclosing environment the earlier
             * timeout var's environment */
        SymbolEnv timeoutBodyEnv = SymbolEnv.createBlockEnv(forkJoin.timeoutBody, timeoutVarEnv);
        this.analyzeNode(forkJoin.timeoutBody, timeoutBodyEnv);
    }
    this.validateJoinWorkerList(forkJoin, forkJoinEnv);
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

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