Search in sources :

Example 1 with BLangEndpoint

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

the class SymbolEnter method visit.

@Override
public void visit(BLangEndpoint endpoint) {
    BType varType = symResolver.resolveTypeNode(endpoint.endpointTypeNode, env);
    Name varName = names.fromIdNode(endpoint.name);
    endpoint.type = varType;
    endpoint.symbol = defineEndpointVarSymbol(endpoint.pos, endpoint.flagSet, varType, varName, env);
    endpointSPIAnalyzer.resolveEndpointSymbol(endpoint);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 2 with BLangEndpoint

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangEndpoint endpointNode) {
    endpointNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENDPOINT);
        this.analyzeDef(annotationAttachment, env);
    });
    if (endpointNode.configurationExpr == null) {
        return;
    }
    BType configType = symTable.errType;
    if (endpointNode.symbol != null && endpointNode.symbol.type.tag == TypeTags.STRUCT) {
        if (endpointNode.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
            // Init expression.
            configType = endpointSPIAnalyzer.getEndpointConfigType((BStructSymbol) endpointNode.symbol.type.tsymbol);
        } else {
            // assign Expression.
            configType = endpointNode.symbol.type;
        }
    }
    this.typeChecker.checkExpr(endpointNode.configurationExpr, env, Lists.of(configType));
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 3 with BLangEndpoint

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

the class EndpointDesugar method defineGlobalEndpoint.

void defineGlobalEndpoint(BLangEndpoint ep, SymbolEnv env) {
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(ep.pos, ep.name.value, ep.symbol.type);
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(ep.pos, env.enclPkg.symbol.scope, env, names.fromIdNode(ep.name), SymTag.VARIABLE);
    env.enclPkg.globalVars.add(epVariable);
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 4 with BLangEndpoint

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

the class EndpointDesugar method generateEndpointInit.

private BLangBlockStmt generateEndpointInit(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol) {
    final String epName = endpoint.name.value;
    final DiagnosticPos pos = endpoint.pos;
    BLangBlockStmt temp = new BLangBlockStmt();
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
    final BLangExpression newExpr;
    if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
        // Handle Endpoint Assignment.
        newExpr = endpoint.configurationExpr;
    } else if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
        // Handle Endpoint initialization.
        newExpr = ASTBuilderUtil.createEmptyRecordLiteral(pos, endpoint.symbol.type);
    } else {
        newExpr = null;
    }
    // EPType ep_name = {};
    if (env.enclInvokable != null) {
        // In callable unit, endpoint is same scope variable.
        final BLangVariableDef epNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
        epNewStmt.var = epVariable;
        epNewStmt.var.expr = newExpr;
    } else {
        // This is an init function. ep variable is defined in outside.
        if (env.enclService != null) {
            // Add to endpoint variable to relevant location
            final BLangVariableDef epVarDef = ASTBuilderUtil.createVariableDef(pos);
            epVarDef.var = epVariable;
            env.enclService.vars.add(epVarDef);
        }
        final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(pos, temp);
        assignmentStmt.varRefs.add(ASTBuilderUtil.createVariableRef(pos, epVariable.symbol));
        assignmentStmt.expr = newExpr;
    }
    return temp;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 5 with BLangEndpoint

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

the class EndpointDesugar method generateEndpointStartOrStop.

private BLangBlockStmt generateEndpointStartOrStop(BLangEndpoint endpoint, BInvokableSymbol funSymbol, SymbolEnv env, BSymbol encSymbol) {
    BLangBlockStmt temp = new BLangBlockStmt();
    if (funSymbol == null || endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
        // 2: If endpoint in initialized
        return temp;
    }
    final DiagnosticPos pos = endpoint.pos;
    final String epName = endpoint.name.value;
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
    final Name name = names.fromIdNode(endpoint.name);
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
    List<BLangVariable> args = new ArrayList<>();
    if (funSymbol.params.size() == 1) {
        // Endpoint is already desugared. Fix this correctly.
        args.add(0, epVariable);
    }
    final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
    final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, funSymbol, args, symResolver);
    if (funSymbol.params.size() != 1) {
        iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
    }
    expressionStmt.expr = iExpr;
    return temp;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) ArrayList(java.util.ArrayList) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)10 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)9 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)8 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)8 ArrayList (java.util.ArrayList)7 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)5 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)5 Position (org.eclipse.lsp4j.Position)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Stack (java.util.Stack)4 Collectors (java.util.stream.Collectors)4 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)4 Token (org.antlr.v4.runtime.Token)4 TokenStream (org.antlr.v4.runtime.TokenStream)4 LSNodeVisitor (org.ballerinalang.langserver.common.LSNodeVisitor)4