Search in sources :

Example 1 with BLangAttachedFunctionInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangAttachedFunctionInvocation 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

ArrayList (java.util.ArrayList)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)1 BLangActionInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation)1 BLangAttachedFunctionInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangAttachedFunctionInvocation)1