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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations