use of org.wso2.ballerinalang.compiler.tree.BLangInvokableNode 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.tree.BLangInvokableNode in project ballerina by ballerina-lang.
the class EndpointDesugar method rewriteEndpoint.
void rewriteEndpoint(BLangEndpoint endpoint, SymbolEnv env) {
final BSymbol encSymbol, varSymbol;
final BLangBlockStmt initBlock, startBlock;
BLangBlockStmt stopBlock = null;
if (env.enclInvokable != null) {
// Function, Action, Resource. Code generate to its body directly.
encSymbol = varSymbol = env.enclInvokable.symbol;
initBlock = startBlock = ((BLangInvokableNode) env.node).body;
} else if (env.enclService != null) {
encSymbol = env.enclService.symbol;
varSymbol = ((BLangService) env.node).initFunction.symbol;
initBlock = startBlock = ((BLangService) env.node).initFunction.body;
} else {
// Pkg level endpoint.
encSymbol = env.enclPkg.symbol;
varSymbol = ((BLangPackage) env.node).initFunction.symbol;
initBlock = ((BLangPackage) env.node).initFunction.body;
startBlock = ((BLangPackage) env.node).startFunction.body;
stopBlock = ((BLangPackage) env.node).stopFunction.body;
}
BLangBlockStmt genInit, genInitCall, genStartCall, genStopCall;
genInit = generateEndpointInit(endpoint, env, encSymbol);
genInitCall = generateEndpointInitFunctionCall(endpoint, env, encSymbol, varSymbol);
genStartCall = generateEndpointStartOrStop(endpoint, endpoint.symbol.startFunction, env, encSymbol);
genStopCall = generateEndpointStartOrStop(endpoint, endpoint.symbol.stopFunction, env, encSymbol);
if (env.enclInvokable != null) {
ASTBuilderUtil.prependStatements(genStartCall, startBlock);
ASTBuilderUtil.prependStatements(genInitCall, initBlock);
// TODO : Implement stop.
ASTBuilderUtil.prependStatements(genInit, initBlock);
} else if (env.enclService != null) {
ASTBuilderUtil.appendStatements(genInit, initBlock);
ASTBuilderUtil.appendStatements(genInitCall, initBlock);
ASTBuilderUtil.appendStatements(genStartCall, startBlock);
// TODO : Implement stop.
} else {
ASTBuilderUtil.appendStatements(genInit, initBlock);
ASTBuilderUtil.appendStatements(genInitCall, initBlock);
ASTBuilderUtil.appendStatements(genStartCall, startBlock);
ASTBuilderUtil.appendStatements(genStopCall, Objects.requireNonNull(stopBlock));
}
}
Aggregations