Search in sources :

Example 1 with BLangActionInvocation

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

the class CodeGenerator method visit.

public void visit(BLangActionInvocation aIExpr) {
    BInvokableSymbol actionSymbol = (BInvokableSymbol) aIExpr.symbol;
    int pkgRefCPIndex = addPackageRefCPEntry(currentPkgInfo, actionSymbol.pkgID);
    int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionSymbol.name.value);
    ActionRefCPEntry actionRefCPEntry = new ActionRefCPEntry(pkgRefCPIndex, actionNameCPIndex);
    int actionRefCPIndex = currentPkgInfo.addCPEntry(actionRefCPEntry);
    Operand[] operands = getFuncOperands(aIExpr, actionRefCPIndex);
    emit(InstructionCodes.ACALL, operands);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 2 with BLangActionInvocation

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation 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 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)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 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 ActionRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry)1