use of org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateTableAggregator.
private void generateTableAggregator(BLangBlockStmt blockStmt, IterableContext ctx) {
final DiagnosticPos pos = blockStmt.pos;
List<BLangVariable> variables = new ArrayList<>(1);
variables.add(ctx.resultVar);
variables.add(ctx.iteratorResultVariables.get(0));
BInvokableSymbol addSymbol = (BInvokableSymbol) symTable.rootScope.lookup(names.fromString(TABLE_ADD_FUNCTION)).symbol;
BLangInvocation addFunctionInvocation = ASTBuilderUtil.createInvocationExpr(pos, addSymbol, variables, symResolver);
BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, blockStmt);
expressionStmt.expr = addFunctionInvocation;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addExpressionStmt.
public void addExpressionStmt(DiagnosticPos pos, Set<Whitespace> ws) {
BLangExpressionStmt exprStmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
exprStmt.pos = pos;
exprStmt.addWS(ws);
exprStmt.expr = (BLangExpression) exprNodeStack.pop();
addStmtToCurrentBlock(exprStmt);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangExpressionStmt exprStmtNode) {
// Creates a new environment here.
SymbolEnv stmtEnv = new SymbolEnv(exprStmtNode, this.env.scope);
this.env.copyTo(stmtEnv);
List<BType> bTypes = typeChecker.checkExpr(exprStmtNode.expr, stmtEnv, new ArrayList<>());
if (bTypes.size() > 0 && !(bTypes.size() == 1 && bTypes.get(0) == symTable.errType)) {
dlog.error(exprStmtNode.pos, DiagnosticCode.ASSIGNMENT_REQUIRED);
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt in project ballerina by ballerina-lang.
the class ASTBuilderUtil method createExpressionStmt.
static BLangExpressionStmt createExpressionStmt(DiagnosticPos pos, BLangBlockStmt target) {
final BLangExpressionStmt exprStmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
exprStmt.pos = pos;
target.addStatement(exprStmt);
return exprStmt;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt in project ballerina by ballerina-lang.
the class EndpointDesugar method generateServiceRegistered.
private BLangBlockStmt generateServiceRegistered(BEndpointVarSymbol endpoint, BLangService service, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
final DiagnosticPos pos = service.pos;
final String epName = endpoint.name.value;
BLangBlockStmt temp = new BLangBlockStmt();
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.type);
final Name name = endpoint.name;
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
final BLangVariableDef serviceTypeDef = ASTBuilderUtil.createVariableDefStmt(pos, temp);
serviceTypeDef.var = ASTBuilderUtil.createVariable(pos, service.name + "type", symTable.typeDesc);
ASTBuilderUtil.defineVariable(serviceTypeDef.var, varEncSymbol, names);
final BLangUnaryExpr typeOfExpr = ASTBuilderUtil.createUnaryExpr(pos);
serviceTypeDef.var.expr = typeOfExpr;
typeOfExpr.operator = OperatorKind.TYPEOF;
typeOfExpr.expr = getTypeAccessExpression(pos, service.symbol.type);
typeOfExpr.type = symTable.typeDesc;
List<BLangVariable> args = Lists.of(serviceTypeDef.var);
if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() == 2) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.registerFunction, args, symResolver);
if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() != 2) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
Aggregations