use of org.wso2.ballerinalang.compiler.tree.BLangInvokableNode in project ballerina by ballerina-lang.
the class CodeGenerator method addParameterDefaultValues.
private void addParameterDefaultValues(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo) {
int paramDefaultsAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE.value());
ParamDefaultValueAttributeInfo paramDefaulValAttrInfo = new ParamDefaultValueAttributeInfo(paramDefaultsAttrNameIndex);
// Only named parameters can have default values.
for (BLangVariableDef param : invokableNode.defaultableParams) {
DefaultValue defaultVal = getDefaultValue((BLangLiteral) param.var.expr);
paramDefaulValAttrInfo.addParamDefaultValueInfo(defaultVal);
}
callableUnitInfo.addAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE, paramDefaulValAttrInfo);
}
use of org.wso2.ballerinalang.compiler.tree.BLangInvokableNode in project ballerina by ballerina-lang.
the class Desugar method addReturnIfNotPresent.
private void addReturnIfNotPresent(BLangInvokableNode invokableNode) {
if (Symbols.isNative(invokableNode.symbol)) {
return;
}
// This will only check whether last statement is a return and just add a return statement.
// This won't analyse if else blocks etc to see whether return statements are present
BLangBlockStmt blockStmt = invokableNode.body;
if (invokableNode.workers.size() == 0 && invokableNode.retParams.isEmpty() && (blockStmt.stmts.size() < 1 || blockStmt.stmts.get(blockStmt.stmts.size() - 1).getKind() != NodeKind.RETURN)) {
BLangReturn returnStmt = (BLangReturn) TreeBuilder.createReturnNode();
DiagnosticPos invPos = invokableNode.pos;
DiagnosticPos pos = new DiagnosticPos(invPos.src, invPos.eLine, invPos.eLine, invPos.sCol, invPos.sCol);
returnStmt.pos = pos;
blockStmt.addStatement(returnStmt);
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangInvokableNode in project ballerina by ballerina-lang.
the class TaintAnalyzer method analyzeReturnTaintedStatus.
private void analyzeReturnTaintedStatus(BLangInvokableNode invokableNode, SymbolEnv symbolEnv) {
invokableNode.endpoints.forEach(endpoint -> endpoint.accept(this));
if (invokableNode.workers.isEmpty()) {
analyzeNode(invokableNode.body, symbolEnv);
} else {
for (BLangWorker worker : invokableNode.workers) {
worker.endpoints.forEach(endpoint -> endpoint.accept(this));
analyzeNode(worker, symbolEnv);
if (this.blockedNode != null || taintErrorSet.size() > 0) {
break;
}
}
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangInvokableNode in project ballerina by ballerina-lang.
the class CodeGenerator method processWorker.
private void processWorker(BLangInvokableNode invokableNode, WorkerInfo workerInfo, BLangBlockStmt body, LocalVariableAttributeInfo localVarAttributeInfo, SymbolEnv invokableSymbolEnv, boolean defaultWorker, VariableIndex lvIndexCopy) {
int codeAttrNameCPIndex = this.addUTF8CPEntry(this.currentPkgInfo, AttributeInfo.Kind.CODE_ATTRIBUTE.value());
workerInfo.codeAttributeInfo.attributeNameIndex = codeAttrNameCPIndex;
workerInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
if (body != null) {
localVarAttrInfo = new LocalVariableAttributeInfo(localVarAttributeInfo.attributeNameIndex);
localVarAttrInfo.localVars = new ArrayList<>(localVarAttributeInfo.localVars);
workerInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttrInfo);
workerInfo.codeAttributeInfo.codeAddrs = nextIP();
this.lvIndexes = lvIndexCopy;
this.currentWorkerInfo = workerInfo;
this.genNode(body, invokableSymbolEnv);
}
this.endWorkerInfoUnit(workerInfo.codeAttributeInfo);
this.emit(InstructionCodes.HALT);
}
use of org.wso2.ballerinalang.compiler.tree.BLangInvokableNode in project ballerina by ballerina-lang.
the class CodeGenerator method visitInvokableNode.
private void visitInvokableNode(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo, SymbolEnv invokableSymbolEnv) {
int localVarAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttrNameIndex);
// TODO Read annotations attached to this callableUnit
// Add local variable indexes to the parameters and return parameters
visitInvokableNodeParams(invokableNode.symbol, callableUnitInfo, localVarAttributeInfo);
if (Symbols.isNative(invokableNode.symbol)) {
this.processWorker(invokableNode, callableUnitInfo.defaultWorkerInfo, null, localVarAttributeInfo, invokableSymbolEnv, true, null);
} else {
// Clone lvIndex structure here. This structure contain local variable indexes of the input and
// out parameters and they are common for all the workers.
VariableIndex lvIndexCopy = this.copyVarIndex(lvIndexes);
this.processWorker(invokableNode, callableUnitInfo.defaultWorkerInfo, invokableNode.body, localVarAttributeInfo, invokableSymbolEnv, true, lvIndexCopy);
for (BLangWorker worker : invokableNode.getWorkers()) {
this.processWorker(invokableNode, callableUnitInfo.getWorkerInfo(worker.name.value), worker.body, localVarAttributeInfo, invokableSymbolEnv, false, this.copyVarIndex(lvIndexCopy));
}
}
}
Aggregations