Search in sources :

Example 16 with BLangNode

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

the class CodeGenerator method genNode.

// private methods
private <T extends BLangNode, U extends SymbolEnv> T genNode(T t, U u) {
    SymbolEnv prevEnv = this.env;
    this.env = u;
    t.accept(this);
    this.env = prevEnv;
    return t;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 17 with BLangNode

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

the class Desugar method rewrite.

@SuppressWarnings("unchecked")
private <E extends BLangStatement> E rewrite(E statement, SymbolEnv env) {
    if (statement == null) {
        return null;
    }
    BLangStatementLink link = new BLangStatementLink();
    link.parent = currentLink;
    currentLink = link;
    BLangStatement stmt = (BLangStatement) rewrite((BLangNode) statement, env);
    // Link Statements.
    link.statement = stmt;
    stmt.statementLink = link;
    currentLink = link.parent;
    return (E) stmt;
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangStatementLink(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement.BLangStatementLink)

Example 18 with BLangNode

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

the class Desugar method rewriteExpr.

@SuppressWarnings("unchecked")
private <E extends BLangExpression> E rewriteExpr(E node) {
    if (node == null) {
        return null;
    }
    if (node.desugared) {
        return node;
    }
    BLangExpression expr = node;
    if (node.impConversionExpr != null) {
        expr = node.impConversionExpr;
        node.impConversionExpr = null;
    }
    expr.accept(this);
    BLangNode resultNode = this.result;
    this.result = null;
    resultNode.desugared = true;
    return (E) resultNode;
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 19 with BLangNode

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

the class TreeVisitor method visit.

// Visitor methods
public void visit(BLangPackage pkgNode) {
    SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgNode.symbol);
    // Then visit each top-level element sorted using the compilation unit
    String fileName = documentServiceContext.get(DocumentServiceKeys.FILE_NAME_KEY);
    List<TopLevelNode> topLevelNodes = pkgNode.topLevelNodes.stream().filter(node -> node.getPosition().getSource().getCompilationUnitName().equals(fileName)).collect(Collectors.toList());
    if (topLevelNodes.isEmpty()) {
        this.setTerminateVisitor(true);
        acceptNode(null, null);
    } else {
        cursorPositionResolver = PackageNodeScopeResolver.class;
        topLevelNodes.forEach(topLevelNode -> {
            cursorPositionResolver = TopLevelNodeScopeResolver.class;
            this.blockOwnerStack.push(pkgNode);
            acceptNode((BLangNode) topLevelNode, pkgEnv);
        });
    }
}
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) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 20 with BLangNode

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

the class TreeVisitor method acceptNode.

// Private Methods
private void acceptNode(BLangNode node, SymbolEnv env) {
    if (this.terminateVisitor) {
        return;
    }
    SymbolEnv prevEnv = this.symbolEnv;
    this.symbolEnv = env;
    node.accept(this);
    this.symbolEnv = prevEnv;
    this.setPreviousNode(node);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)17 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)13 ArrayList (java.util.ArrayList)7 CompletionItem (org.eclipse.lsp4j.CompletionItem)7 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)7 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)5 List (java.util.List)4 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)4 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Stack (java.util.Stack)2 Collectors (java.util.stream.Collectors)2 Token (org.antlr.v4.runtime.Token)2 TokenStream (org.antlr.v4.runtime.TokenStream)2