use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos 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;
}
use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos 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;
}
use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.
the class EndpointDesugar method getTypeAccessExpression.
private BLangTypeofExpr getTypeAccessExpression(DiagnosticPos pos, BType serviceType) {
BLangTypeofExpr typeAccessExpr = (BLangTypeofExpr) TreeBuilder.createTypeAccessNode();
typeAccessExpr.pos = pos;
typeAccessExpr.resolvedType = serviceType;
typeAccessExpr.type = symTable.typeDesc;
return typeAccessExpr;
}
use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos 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.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateCalculateAverage.
/**
* Generates following.
*
* result = result / count
*
* @param blockStmt target
* @param ctx current context
*/
private void generateCalculateAverage(BLangBlockStmt blockStmt, IterableContext ctx) {
final DiagnosticPos pos = blockStmt.pos;
final BLangBinaryExpr divide = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
divide.pos = pos;
divide.type = ctx.resultVar.symbol.type;
divide.opKind = OperatorKind.ADD;
divide.lhsExpr = ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol);
divide.rhsExpr = ASTBuilderUtil.createVariableRef(pos, ctx.countVar.symbol);
divide.opSymbol = (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.DIV, divide.type, ctx.countVar.symbol.type);
final BLangAssignment countAdd = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
countAdd.varRefs.add(ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol));
countAdd.expr = divide;
}
Aggregations