Search in sources :

Example 31 with BLangInvocation

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;
}
Also used : BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 32 with BLangInvocation

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);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)

Example 33 with BLangInvocation

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;
}
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) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) 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 34 with BLangInvocation

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);
}
Also used : BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)

Example 35 with BLangInvocation

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);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Aggregations

BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)12 ArrayList (java.util.ArrayList)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)9 Name (org.wso2.ballerinalang.compiler.util.Name)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 List (java.util.List)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)4 Paths (java.nio.file.Paths)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)3 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3