Search in sources :

Example 1 with BLangStatement

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

the class SymbolEnter method defineObjectInitFunction.

private void defineObjectInitFunction(BLangObject object, SymbolEnv conEnv) {
    BLangFunction initFunction = object.initFunction;
    if (initFunction == null) {
        initFunction = createInitFunction(object.pos, "", Names.OBJECT_INIT_SUFFIX);
    }
    initFunction.attachedFunction = true;
    // Set cached receiver to the init function
    initFunction.receiver = object.receiver;
    initFunction.flagSet.add(Flag.ATTACHED);
    // Add object level variables to the init function
    BLangFunction finalInitFunction = initFunction;
    object.fields.stream().filter(f -> f.expr != null).forEachOrdered(v -> finalInitFunction.initFunctionStmts.put(v.symbol, (BLangStatement) createAssignmentStmt(v)));
    object.initFunction = initFunction;
    defineNode(object.initFunction, conEnv);
}
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) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction)

Example 2 with BLangStatement

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

the class CodeGenerator method visit.

public void visit(BLangBlockStmt blockNode) {
    SymbolEnv blockEnv = SymbolEnv.createBlockEnv(blockNode, this.env);
    for (BLangStatement stmt : blockNode.stmts) {
        if (stmt.getKind() != NodeKind.TRY && stmt.getKind() != NodeKind.CATCH && stmt.getKind() != NodeKind.IF) {
            addLineNumberInfo(stmt.pos);
        }
        genNode(stmt, blockEnv);
        // Update the maxRegIndexes structure
        setMaxRegIndexes(regIndexes, maxRegIndexes);
        // Reset the regIndexes structure for every statement
        regIndexes = new VariableIndex(REG);
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 3 with BLangStatement

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

the class CodeGenerator method generateFinallyInstructions.

private void generateFinallyInstructions(BLangStatement statement, NodeKind... expectedParentKinds) {
    BLangStatement current = statement;
    while (current != null && current.statementLink.parent != null) {
        BLangStatement parent = current.statementLink.parent.statement;
        for (NodeKind expected : expectedParentKinds) {
            if (expected == parent.getKind()) {
                return;
            }
        }
        if (NodeKind.TRY == parent.getKind()) {
            BLangTryCatchFinally tryCatchFinally = (BLangTryCatchFinally) parent;
            if (tryCatchFinally.finallyBody != null && current != tryCatchFinally.finallyBody) {
                genNode(tryCatchFinally.finallyBody, env);
            }
        } else if (NodeKind.LOCK == parent.getKind()) {
            BLangLock lockNode = (BLangLock) parent;
            if (!lockNode.lockVariables.isEmpty()) {
                Operand[] operands = getOperands(lockNode);
                emit((InstructionCodes.UNLOCK), operands);
            }
        }
        current = parent;
    }
}
Also used : NodeKind(org.ballerinalang.model.tree.NodeKind) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally)

Example 4 with BLangStatement

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

the class ASTBuilderUtil method createBlockStmt.

static BLangBlockStmt createBlockStmt(DiagnosticPos pos, List<BLangStatement> stmts) {
    final BLangBlockStmt blockNode = (BLangBlockStmt) TreeBuilder.createBlockNode();
    blockNode.pos = pos;
    blockNode.stmts = stmts;
    return blockNode;
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)

Example 5 with BLangStatement

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

the class ASTBuilderUtil method createIfElseStmt.

static BLangIf createIfElseStmt(DiagnosticPos pos, BLangExpression conditionExpr, BLangBlockStmt thenBody, BLangStatement elseStmt) {
    final BLangIf ifNode = (BLangIf) TreeBuilder.createIfElseStatementNode();
    ifNode.pos = pos;
    ifNode.expr = conditionExpr;
    ifNode.body = thenBody;
    ifNode.elseStmt = elseStmt;
    return ifNode;
}
Also used : BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf)

Aggregations

BLangStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangStatement)10 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)5 NodeKind (org.ballerinalang.model.tree.NodeKind)3 StatementNode (org.ballerinalang.model.tree.statements.StatementNode)3 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)3 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)3 BLangMatchStmtPatternClause (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)2 TreeBuilder (org.ballerinalang.model.TreeBuilder)2 StreamingQueryStatementNode (org.ballerinalang.model.tree.statements.StreamingQueryStatementNode)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2