use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class Desugar method createInvocationNode.
private BLangInvocation createInvocationNode(String functionName, List<BLangExpression> args, List<BType> retTypes) {
BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
BLangIdentifier name = (BLangIdentifier) TreeBuilder.createIdentifierNode();
name.setLiteral(false);
name.setValue(functionName);
invocationNode.name = name;
invocationNode.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
// TODO: 2/28/18 need to find a good way to refer to symbols
invocationNode.symbol = symTable.rootScope.lookup(new Name(functionName)).symbol;
invocationNode.types = retTypes;
invocationNode.requiredArgs = args;
return invocationNode;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class Desugar method reorderArguments.
/**
* Reorder the invocation arguments to match the original function signature.
*
* @param iExpr Function invocation expressions to reorder the arguments
*/
private void reorderArguments(BLangInvocation iExpr) {
BSymbol symbol = iExpr.symbol;
if (symbol == null || symbol.type.tag != TypeTags.INVOKABLE) {
return;
}
BInvokableSymbol invocableSymbol = (BInvokableSymbol) symbol;
if (invocableSymbol.defaultableParams != null && !invocableSymbol.defaultableParams.isEmpty()) {
// Re-order the named args
reorderNamedArgs(iExpr, invocableSymbol);
}
if (invocableSymbol.restParam == null) {
return;
}
// leave it as is.
if (iExpr.restArgs.size() == 1 && iExpr.restArgs.get(0).getKind() == NodeKind.REST_ARGS_EXPR) {
return;
}
BLangArrayLiteral arrayLiteral = (BLangArrayLiteral) TreeBuilder.createArrayLiteralNode();
arrayLiteral.exprs = iExpr.restArgs;
arrayLiteral.type = invocableSymbol.restParam.type;
iExpr.restArgs = new ArrayList<>();
iExpr.restArgs.add(arrayLiteral);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation 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;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createTypeConversionExpr.
public void createTypeConversionExpr(DiagnosticPos pos, Set<Whitespace> ws, boolean namedTransformer) {
BLangTypeConversionExpr typeConversionNode = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
typeConversionNode.pos = pos;
typeConversionNode.addWS(ws);
typeConversionNode.typeNode = (BLangType) typeNodeStack.pop();
typeConversionNode.expr = (BLangExpression) exprNodeStack.pop();
if (namedTransformer) {
typeConversionNode.transformerInvocation = (BLangInvocation) exprNodeStack.pop();
}
addExpressionNode(typeConversionNode);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.
the class BLangPackageBuilder method createActionInvocationNode.
public void createActionInvocationNode(DiagnosticPos pos, Set<Whitespace> ws, boolean async) {
BLangInvocation invocationExpr = (BLangInvocation) exprNodeStack.pop();
invocationExpr.actionInvocation = true;
invocationExpr.pos = pos;
invocationExpr.addWS(ws);
invocationExpr.async = async;
BLangNameReference nameReference = nameReferenceStack.pop();
BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
varRef.pos = nameReference.pos;
varRef.addWS(nameReference.ws);
varRef.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
varRef.variableName = (BLangIdentifier) nameReference.name;
invocationExpr.expr = varRef;
exprNodeStack.push(invocationExpr);
}
Aggregations