Search in sources :

Example 1 with BLangTransformerInvocation

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

the class Desugar method visit.

@Override
public void visit(BLangTypeConversionExpr conversionExpr) {
    conversionExpr.expr = rewriteExpr(conversionExpr.expr);
    // Built-in conversion
    if (conversionExpr.conversionSymbol.tag != SymTag.TRANSFORMER) {
        result = conversionExpr;
        return;
    }
    // Named transformer invocation
    BLangInvocation transformerInvoc = conversionExpr.transformerInvocation;
    if (transformerInvoc != null) {
        transformerInvoc = rewriteExpr(transformerInvoc);
        // Add the rExpr as the first argument
        conversionExpr.transformerInvocation.requiredArgs.add(0, conversionExpr.expr);
        result = new BLangTransformerInvocation(conversionExpr.pos, transformerInvoc.requiredArgs, transformerInvoc.namedArgs, transformerInvoc.restArgs, transformerInvoc.symbol, conversionExpr.types);
        conversionExpr.transformerInvocation = transformerInvoc;
        return;
    }
    // Unnamed transformer invocation
    BConversionOperatorSymbol transformerSym = conversionExpr.conversionSymbol;
    transformerInvoc = new BLangTransformerInvocation(conversionExpr.pos, Lists.of(conversionExpr.expr), transformerSym, conversionExpr.types);
    transformerInvoc.types = transformerSym.type.getReturnTypes();
    result = transformerInvoc;
}
Also used : BLangTransformerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)

Example 2 with BLangTransformerInvocation

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

the class CodeGenerator method visit.

public void visit(BLangTransformerInvocation iExpr) {
    BInvokableSymbol transformerSymbol = (BInvokableSymbol) iExpr.symbol;
    int pkgRefCPIndex = addPackageRefCPEntry(currentPkgInfo, transformerSymbol.pkgID);
    int transformerNameCPIndex = addUTF8CPEntry(currentPkgInfo, transformerSymbol.name.value);
    TransformerRefCPEntry transformerRefCPEntry = new TransformerRefCPEntry(pkgRefCPIndex, transformerNameCPIndex);
    int transformerRefCPIndex = currentPkgInfo.addCPEntry(transformerRefCPEntry);
    Operand[] operands = getFuncOperands(iExpr, transformerRefCPIndex);
    emit(InstructionCodes.TCALL, operands);
}
Also used : TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BConversionOperatorSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)1 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)1 BLangTransformerInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 TransformerRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry)1