Search in sources :

Example 1 with BLangExpressionStmt

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

the class SymbolEnter method createInitFuncInvocationStmt.

private BLangExpressionStmt createInitFuncInvocationStmt(BLangImportPackage importPackage, BInvokableSymbol initFunctionSymbol) {
    BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
    invocationNode.pos = importPackage.pos;
    invocationNode.addWS(importPackage.getWS());
    BLangIdentifier funcName = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    funcName.value = initFunctionSymbol.name.value;
    invocationNode.name = funcName;
    invocationNode.pkgAlias = importPackage.alias;
    BLangExpressionStmt exprStmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
    exprStmt.pos = importPackage.pos;
    exprStmt.addWS(importPackage.getWS());
    exprStmt.expr = invocationNode;
    return exprStmt;
}
Also used : BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)

Example 2 with BLangExpressionStmt

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

the class TaintAnalyzer method visit.

public void visit(BLangExpressionStmt exprStmtNode) {
    SymbolEnv stmtEnv = new SymbolEnv(exprStmtNode, this.env.scope);
    this.env.copyTo(stmtEnv);
    analyzeNode(exprStmtNode.expr, stmtEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 3 with BLangExpressionStmt

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

the class Desugar method visit.

public void visit(BLangForever foreverStatement) {
    siddhiQueryBuilder.visit(foreverStatement);
    BLangExpressionStmt stmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
    stmt.expr = createInvocationForForeverBlock(foreverStatement);
    stmt.pos = foreverStatement.pos;
    stmt.addWS(foreverStatement.getWS());
    result = rewrite(stmt, env);
}
Also used : BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)

Example 4 with BLangExpressionStmt

use of org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt 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)

Example 5 with BLangExpressionStmt

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

the class EndpointDesugar method generateEndpointInitFunctionCall.

private BLangBlockStmt generateEndpointInitFunctionCall(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
    BLangBlockStmt temp = new BLangBlockStmt();
    if (endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
        return temp;
    }
    final String epName = endpoint.name.value;
    final DiagnosticPos pos = endpoint.pos;
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
    // EPConfigType ep_nameConf = { ep-config-expr };
    final BLangVariableDef epConfigNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
    epConfigNewStmt.var = ASTBuilderUtil.createVariable(pos, epName + "Conf", endpoint.configurationExpr.type);
    epConfigNewStmt.var.expr = endpoint.configurationExpr;
    ASTBuilderUtil.defineVariable(epConfigNewStmt.var, varEncSymbol, names);
    List<BLangVariable> args = Lists.of(epConfigNewStmt.var);
    if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() == 2) {
        // Endpoint is already desugared. Fix this correctly.
        args.add(0, epVariable);
    }
    // epName.init(ep_nameConf);
    final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
    final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.symbol.initFunction, args, symResolver);
    if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() != 2) {
        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) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Aggregations

BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)9 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)3 ArrayList (java.util.ArrayList)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 Name (org.wso2.ballerinalang.compiler.util.Name)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangUnaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr)1