Search in sources :

Example 31 with BInvokableSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.

the class CodeGenerator method createTransformerInfoEntry.

private void createTransformerInfoEntry(BLangInvokableNode invokable) {
    BInvokableSymbol transformerSymbol = invokable.symbol;
    BInvokableType transformerType = (BInvokableType) transformerSymbol.type;
    // Add transformer name as an UTFCPEntry to the constant pool
    int transformerNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, transformerSymbol.name.value);
    TransformerInfo transformerInfo = new TransformerInfo(currentPackageRefCPIndex, transformerNameCPIndex);
    transformerInfo.paramTypes = transformerType.paramTypes.toArray(new BType[0]);
    transformerInfo.retParamTypes = transformerType.retTypes.toArray(new BType[0]);
    transformerInfo.flags = transformerSymbol.flags;
    this.addWorkerInfoEntries(transformerInfo, invokable.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(invokable, transformerInfo);
    transformerInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(transformerInfo.paramTypes, transformerInfo.retParamTypes));
    this.currentPkgInfo.transformerInfoMap.put(transformerSymbol.name.value, transformerInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) TransformerInfo(org.wso2.ballerinalang.programfile.TransformerInfo)

Example 32 with BInvokableSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol 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 33 with BInvokableSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.

the class Desugar method visit.

@Override
public void visit(BLangAction actionNode) {
    addReturnIfNotPresent(actionNode);
    SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionNode.symbol.scope, env);
    // To preserve endpoint code gen order at action.
    Collections.reverse(actionNode.endpoints);
    actionNode.endpoints = rewrite(actionNode.endpoints, actionEnv);
    actionNode.body = rewrite(actionNode.body, actionEnv);
    actionNode.workers = rewrite(actionNode.workers, actionEnv);
    // we rewrite it's parameter list to have the receiver variable as the first parameter
    BInvokableSymbol actionSymbol = actionNode.symbol;
    List<BVarSymbol> params = actionSymbol.params;
    BVarSymbol receiverSymbol = actionNode.symbol.receiverSymbol;
    params.add(0, receiverSymbol);
    BInvokableType actionType = (BInvokableType) actionSymbol.type;
    if (receiverSymbol != null) {
        actionType.paramTypes.add(0, receiverSymbol.type);
    }
    result = actionNode;
}
Also used : BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 34 with BInvokableSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.

the class Desugar method visit.

public void visit(BLangTransformer transformerNode) {
    addTransformerReturn(transformerNode);
    SymbolEnv tranEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
    transformerNode.body = rewrite(transformerNode.body, tranEnv);
    addArgInitExpr(transformerNode, transformerNode.retParams.get(0));
    BInvokableSymbol transformerSymbol = transformerNode.symbol;
    List<BVarSymbol> params = transformerSymbol.params;
    params.add(0, transformerNode.source.symbol);
    BInvokableType transformerType = (BInvokableType) transformerSymbol.type;
    transformerType.paramTypes.add(0, transformerNode.source.type);
    result = transformerNode;
}
Also used : BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 35 with BInvokableSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol 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)

Aggregations

BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)31 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)14 ArrayList (java.util.ArrayList)12 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)11 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)10 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)7 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)7 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)7 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)6 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 HashMap (java.util.HashMap)4 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)4 BAttachedFunction (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction)4 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)4 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)4 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)4