use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo 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.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method createConnectorInfoEntry.
private void createConnectorInfoEntry(BLangConnector connectorNode) {
BConnectorType connectorType = (BConnectorType) connectorNode.symbol.type;
// Add connector name as an UTFCPEntry to the constant pool
int connectorNameCPIndex = addUTF8CPEntry(currentPkgInfo, connectorNode.name.value);
// Create connector info
ConnectorInfo connectorInfo = new ConnectorInfo(currentPackageRefCPIndex, connectorNameCPIndex, connectorNode.symbol.flags);
connectorInfo.paramTypes = connectorType.paramTypes.toArray(new BType[0]);
connectorInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateConnectorSig(connectorInfo));
// Add connector level variables
int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
connectorNode.params.forEach(var -> visitVarSymbol(var.symbol, fieldIndexes, localVarAttributeInfo));
connectorNode.varDefs.forEach(var -> visitVarSymbol(var.var.symbol, fieldIndexes, localVarAttributeInfo));
connectorInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
// Create variable count attribute info
prepareIndexes(fieldIndexes);
int[] fieldCount = new int[] { fieldIndexes.tInt, fieldIndexes.tFloat, fieldIndexes.tString, fieldIndexes.tBoolean, fieldIndexes.tBlob, fieldIndexes.tRef };
addVariableCountAttributeInfo(currentPkgInfo, connectorInfo, fieldCount);
// Create the init function info
BLangFunction connectorInitFunction = (BLangFunction) connectorNode.getInitFunction();
createFunctionInfoEntry(connectorInitFunction);
this.currentPkgInfo.connectorInfoMap.put(connectorNode.name.value, connectorInfo);
// Create action info entries for all actions
connectorNode.actions.forEach(res -> createActionInfoEntry(res, connectorInfo));
createActionInfoEntry(connectorNode.initAction, connectorInfo);
fieldIndexes = new VariableIndex(FIELD);
}
use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo 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));
}
}
}
use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method visitVarSymbol.
private void visitVarSymbol(BVarSymbol varSymbol, VariableIndex variableIndex, LocalVariableAttributeInfo localVarAttrInfo) {
varSymbol.varIndex = getRegIndexInternal(varSymbol.type.tag, variableIndex.kind);
LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
localVarAttrInfo.localVars.add(localVarInfo);
}
Aggregations