Search in sources :

Example 26 with BLangInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createInvocationExpr.

static BLangInvocation createInvocationExpr(DiagnosticPos pos, BInvokableSymbol invokableSymbol, List<BLangVariable> requiredArgs, List<BLangVariable> namedArgs, List<BLangVariable> restArgs, SymbolResolver symResolver) {
    final BLangInvocation invokeLambda = (BLangInvocation) TreeBuilder.createInvocationNode();
    invokeLambda.pos = pos;
    invokeLambda.requiredArgs.addAll(generateArgExprs(pos, requiredArgs, invokableSymbol.params, symResolver));
    invokeLambda.namedArgs.addAll(generateArgExprs(pos, namedArgs, invokableSymbol.defaultableParams, symResolver));
    invokeLambda.restArgs.addAll(generateArgExprs(pos, restArgs, Lists.of(invokableSymbol.restParam), symResolver));
    invokeLambda.symbol = invokableSymbol;
    invokeLambda.types.addAll(((BInvokableType) invokableSymbol.type).retTypes);
    if (!invokeLambda.types.isEmpty()) {
        invokeLambda.type = invokeLambda.types.get(0);
    }
    return invokeLambda;
}
Also used : BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Example 27 with BLangInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.

the class Desugar method visitFunctionPointerInvocation.

// private functions
private void visitFunctionPointerInvocation(BLangInvocation iExpr) {
    BLangVariableReference expr;
    if (iExpr.expr == null) {
        expr = new BLangSimpleVarRef();
    } else {
        BLangFieldBasedAccess fieldBasedAccess = new BLangFieldBasedAccess();
        fieldBasedAccess.expr = iExpr.expr;
        fieldBasedAccess.field = iExpr.name;
        expr = fieldBasedAccess;
    }
    expr.symbol = (BVarSymbol) iExpr.symbol;
    expr.type = iExpr.symbol.type;
    expr = rewriteExpr(expr);
    result = new BFunctionPointerInvocation(iExpr, expr);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BFunctionPointerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BFunctionPointerInvocation)

Example 28 with BLangInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.

the class Desugar method visitActionInvocationEndpoint.

private void visitActionInvocationEndpoint(BLangInvocation iExpr) {
    final BEndpointVarSymbol epSymbol = (BEndpointVarSymbol) iExpr.expr.symbol;
    // Convert to endpoint.getClient(). iExpr has to be a VarRef.
    final BLangInvocation getClientExpr = ASTBuilderUtil.createInvocationExpr(iExpr.expr.pos, epSymbol.getClientFunction, Collections.emptyList(), symResolver);
    getClientExpr.expr = iExpr.expr;
    iExpr.expr = getClientExpr;
}
Also used : BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Example 29 with BLangInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.

the class Desugar method createInvocationFromTableExpr.

private BLangInvocation createInvocationFromTableExpr(BLangTableQueryExpression tableQueryExpression) {
    List<BLangExpression> args = new ArrayList<>();
    List<BType> retTypes = new ArrayList<>();
    String functionName = QUERY_TABLE_WITHOUT_JOIN_CLAUSE;
    // Order matters, because these are the args for a function invocation.
    args.add(getSQLPreparedStatement(tableQueryExpression));
    args.add(getFromTableVarRef(tableQueryExpression));
    // BLangTypeofExpr
    retTypes.add(tableQueryExpression.type);
    BLangSimpleVarRef joinTable = getJoinTableVarRef(tableQueryExpression);
    if (joinTable != null) {
        args.add(joinTable);
        functionName = QUERY_TABLE_WITH_JOIN_CLAUSE;
    }
    args.add(getSQLStatementParameters(tableQueryExpression));
    args.add(getReturnType(tableQueryExpression));
    return createInvocationNode(functionName, args, retTypes);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 30 with BLangInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation in project ballerina by ballerina-lang.

the class Desugar method visit.

@Override
public void visit(BLangInvocation iExpr) {
    BLangInvocation genIExpr = iExpr;
    // Reorder the arguments to match the original function signature.
    reorderArguments(iExpr);
    iExpr.requiredArgs = rewriteExprs(iExpr.requiredArgs);
    iExpr.namedArgs = rewriteExprs(iExpr.namedArgs);
    iExpr.restArgs = rewriteExprs(iExpr.restArgs);
    if (iExpr.functionPointerInvocation) {
        visitFunctionPointerInvocation(iExpr);
        return;
    } else if (iExpr.iterableOperationInvocation) {
        visitIterableOperationInvocation(iExpr);
        return;
    }
    if (iExpr.actionInvocation) {
        visitActionInvocationEndpoint(iExpr);
    }
    iExpr.expr = rewriteExpr(iExpr.expr);
    result = genIExpr;
    if (iExpr.expr == null) {
        return;
    }
    switch(iExpr.expr.type.tag) {
        case TypeTags.BOOLEAN:
        case TypeTags.STRING:
        case TypeTags.INT:
        case TypeTags.FLOAT:
        case TypeTags.BLOB:
        case TypeTags.JSON:
        case TypeTags.XML:
        case TypeTags.MAP:
        case TypeTags.TABLE:
        case TypeTags.STREAM:
        case TypeTags.FUTURE:
        case TypeTags.STRUCT:
            List<BLangExpression> argExprs = new ArrayList<>(iExpr.requiredArgs);
            argExprs.add(0, iExpr.expr);
            final BLangAttachedFunctionInvocation attachedFunctionInvocation = new BLangAttachedFunctionInvocation(iExpr.pos, argExprs, iExpr.namedArgs, iExpr.restArgs, iExpr.symbol, iExpr.types, iExpr.expr, iExpr.async);
            attachedFunctionInvocation.actionInvocation = iExpr.actionInvocation;
            result = attachedFunctionInvocation;
            break;
        case TypeTags.CONNECTOR:
            List<BLangExpression> actionArgExprs = new ArrayList<>(iExpr.requiredArgs);
            actionArgExprs.add(0, iExpr.expr);
            result = new BLangActionInvocation(iExpr.pos, actionArgExprs, iExpr.namedArgs, iExpr.restArgs, iExpr.symbol, iExpr.types, iExpr.async);
            break;
    }
}
Also used : BLangAttachedFunctionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangAttachedFunctionInvocation) BLangActionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation) ArrayList(java.util.ArrayList) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

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