Search in sources :

Example 6 with BLangConnector

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

the class Desugar method visit.

@Override
public void visit(BLangConnector connectorNode) {
    SymbolEnv conEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorNode.symbol.scope, env);
    connectorNode.params = rewrite(connectorNode.params, conEnv);
    connectorNode.actions = rewrite(connectorNode.actions, conEnv);
    connectorNode.varDefs = rewrite(connectorNode.varDefs, conEnv);
    connectorNode.endpoints = rewrite(connectorNode.endpoints, conEnv);
    connectorNode.initFunction = rewrite(connectorNode.initFunction, conEnv);
    connectorNode.initAction = rewrite(connectorNode.initAction, conEnv);
    result = connectorNode;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 7 with BLangConnector

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

the class BLangPackageBuilder method endConnectorDef.

public void endConnectorDef(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicCon) {
    BLangConnector connectorNode = (BLangConnector) this.connectorNodeStack.pop();
    connectorNode.pos = pos;
    connectorNode.addWS(ws);
    connectorNode.setName(this.createIdentifier(identifier));
    if (publicCon) {
        connectorNode.flagSet.add(Flag.PUBLIC);
    }
    endEndpointDeclarationScope();
    this.compUnit.addTopLevelNode(connectorNode);
}
Also used : BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector)

Example 8 with BLangConnector

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

the class TreeVisitor method visit.

public void visit(BLangConnector connectorNode) {
    String connectorName = connectorNode.getName().getValue();
    BSymbol connectorSymbol = connectorNode.symbol;
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, symbolEnv);
    if (isWithinParameterContext(connectorName, NODE_TYPE_CONNECTOR)) {
        this.populateSymbols(this.resolveAllVisibleSymbols(connectorEnv), connectorEnv);
        setTerminateVisitor(true);
    } else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(connectorNode.getPosition(), connectorNode, this, this.documentServiceContext)) {
        // Reset the previous node
        this.setPreviousNode(null);
        // TODO: Handle Annotation attachments
        if (!(connectorNode.actions.isEmpty() && connectorNode.varDefs.isEmpty() && connectorNode.endpoints.isEmpty())) {
            // Visit the endpoints
            connectorNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, connectorEnv));
            // Since the connector def does not contains a block statement, we consider the block owner only.
            // Here it is Connector Definition
            this.blockOwnerStack.push(connectorNode);
            connectorNode.varDefs.forEach(varDef -> {
                // Cursor position is calculated against the Connector scope resolver
                cursorPositionResolver = ConnectorScopeResolver.class;
                this.acceptNode(varDef, connectorEnv);
            });
            connectorNode.actions.forEach(action -> {
                // Cursor position is calculated against the Connector scope resolver
                cursorPositionResolver = ConnectorScopeResolver.class;
                this.acceptNode(action, connectorEnv);
            });
            if (terminateVisitor) {
                this.acceptNode(null, null);
            }
            this.blockOwnerStack.pop();
        } else {
            this.isCursorWithinBlock(connectorNode.getPosition(), connectorEnv);
        }
    }
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) Arrays(java.util.Arrays) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) TokenStream(org.antlr.v4.runtime.TokenStream) Token(org.antlr.v4.runtime.Token) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) LSNodeVisitor(org.ballerinalang.langserver.common.LSNodeVisitor) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) Map(java.util.Map) ServiceScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ServiceScopeResolver) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) SymbolResolver(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) Names(org.wso2.ballerinalang.compiler.util.Names) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) ConnectorScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ConnectorScopeResolver) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) ScopeResolverConstants(org.ballerinalang.langserver.completions.util.ScopeResolverConstants) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ObjectTypeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ObjectTypeScopeResolver) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) List(java.util.List) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) ResourceParamScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ResourceParamScopeResolver) BlockStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.BlockStatementScopeResolver) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangBind(org.wso2.ballerinalang.compiler.tree.statements.BLangBind) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) PackageNodeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.PackageNodeScopeResolver) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) HashMap(java.util.HashMap) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) ArrayList(java.util.ArrayList) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) Position(org.eclipse.lsp4j.Position) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) BLangEndpointTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode) MatchStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.MatchStatementScopeResolver) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) TopLevelNodeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.TopLevelNodeScopeResolver) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) Node(org.ballerinalang.model.tree.Node) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) Collections(java.util.Collections) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) ConnectorScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ConnectorScopeResolver) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 9 with BLangConnector

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

the class SymbolEnter method visit.

@Override
public void visit(BLangConnector connectorNode) {
    BConnectorSymbol conSymbol = Symbols.createConnectorSymbol(Flags.asMask(connectorNode.flagSet), names.fromIdNode(connectorNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    connectorNode.symbol = conSymbol;
    defineSymbol(connectorNode.pos, conSymbol);
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, conSymbol.scope, env);
    connectorNode.endpoints.forEach(ep -> defineNode(ep, connectorEnv));
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BConnectorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConnectorSymbol)

Example 10 with BLangConnector

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

the class SymbolEnter method defineConnectorInitFunction.

private void defineConnectorInitFunction(BLangConnector connector, SymbolEnv conEnv) {
    BLangFunction initFunction = createInitFunction(connector.pos, connector.getName().getValue(), Names.INIT_FUNCTION_SUFFIX);
    // Add connector as a parameter to the init function
    BLangVariable param = (BLangVariable) TreeBuilder.createVariableNode();
    param.pos = connector.pos;
    param.setName(this.createIdentifier(Names.CONNECTOR.getValue()));
    BLangUserDefinedType connectorType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
    connectorType.pos = connector.pos;
    connectorType.typeName = connector.name;
    connectorType.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    param.setTypeNode(connectorType);
    initFunction.addParameter(param);
    // Add connector level variables to the init function
    connector.varDefs.stream().filter(f -> f.var.expr != null).forEachOrdered(v -> initFunction.body.addStatement(createAssignmentStmt(v.var)));
    addInitReturnStatement(initFunction.body);
    connector.initFunction = initFunction;
    BLangAction initAction = createNativeInitAction(connector.pos);
    connector.initAction = initAction;
    defineNode(connector.initFunction, conEnv);
    defineNode(connector.initAction, conEnv);
    connector.symbol.initFunctionSymbol = connector.initFunction.symbol;
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) Flag(org.ballerinalang.model.elements.Flag) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) BServiceSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) EnumSet(java.util.EnumSet) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BConnectorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConnectorSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) BXMLAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) IMPORT(org.ballerinalang.model.tree.NodeKind.IMPORT) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BStructField(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BAnnotationType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) PackageLoader(org.wso2.ballerinalang.compiler.PackageLoader) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BServiceType(org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType) Flags(org.wso2.ballerinalang.util.Flags) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) DocTag(org.ballerinalang.model.elements.DocTag) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) XMLConstants(javax.xml.XMLConstants) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BTransformerSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction)

Aggregations

BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)12 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)11 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)11 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)9 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)5 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)5 BLangObject (org.wso2.ballerinalang.compiler.tree.BLangObject)5 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)5 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)5 BLangTransformer (org.wso2.ballerinalang.compiler.tree.BLangTransformer)5 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 Collectors (java.util.stream.Collectors)4