Search in sources :

Example 6 with BLangAnnotationAttachmentPoint

use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint 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 7 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

public void visit(BLangAction actionNode) {
    BSymbol actionSymbol = actionNode.symbol;
    SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, env);
    actionNode.annAttachments.forEach(a -> {
        a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ACTION);
        this.analyzeDef(a, actionEnv);
    });
    actionNode.docAttachments.forEach(doc -> analyzeDef(doc, actionEnv));
    if (Symbols.isNative(actionSymbol)) {
        return;
    }
    actionNode.requiredParams.forEach(p -> this.analyzeDef(p, actionEnv));
    actionNode.defaultableParams.forEach(p -> this.analyzeDef(p, actionEnv));
    if (actionNode.restParam != null) {
        this.analyzeDef(actionNode.restParam, actionEnv);
    }
    actionNode.endpoints.forEach(e -> analyzeDef(e, actionEnv));
    analyzeStmt(actionNode.body, actionEnv);
    this.processWorkers(actionNode, actionEnv);
}
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 8 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

public void visit(BLangAnnotation annotationNode) {
    SymbolEnv annotationEnv = SymbolEnv.createAnnotationEnv(annotationNode, annotationNode.symbol.scope, env);
    annotationNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ANNOTATION);
        annotationAttachment.accept(this);
    });
    annotationNode.docAttachments.forEach(doc -> analyzeDef(doc, annotationEnv));
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 9 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangEnum enumNode) {
    BSymbol enumSymbol = enumNode.symbol;
    SymbolEnv enumEnv = SymbolEnv.createPkgLevelSymbolEnv(enumNode, enumSymbol.scope, env);
    enumNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENUM);
        annotationAttachment.accept(this);
    });
    enumNode.docAttachments.forEach(doc -> analyzeDef(doc, enumEnv));
}
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 10 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

public void visit(BLangFunction funcNode) {
    SymbolEnv funcEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
    funcNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.FUNCTION);
        this.analyzeDef(annotationAttachment, funcEnv);
    });
    funcNode.docAttachments.forEach(doc -> analyzeDef(doc, funcEnv));
    funcNode.requiredParams.forEach(p -> this.analyzeDef(p, funcEnv));
    funcNode.defaultableParams.forEach(p -> this.analyzeDef(p, funcEnv));
    if (funcNode.restParam != null) {
        this.analyzeDef(funcNode.restParam, funcEnv);
    }
    // Check for native functions
    if (Symbols.isNative(funcNode.symbol) || funcNode.interfaceFunction) {
        return;
    }
    funcNode.endpoints.forEach(e -> {
        symbolEnter.defineNode(e, funcEnv);
        analyzeDef(e, funcEnv);
    });
    analyzeStmt(funcNode.body, funcEnv);
    this.processWorkers(funcNode, funcEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Aggregations

BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)12 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 CaseFormat (com.google.common.base.CaseFormat)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonNull (com.google.gson.JsonNull)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1