use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class PackageInfoWriter method writeAttributeInfo.
private static void writeAttributeInfo(DataOutputStream dataOutStream, AttributeInfo attributeInfo) throws IOException {
AttributeInfo.Kind attributeKind = attributeInfo.getKind();
dataOutStream.writeInt(attributeInfo.getAttributeNameIndex());
switch(attributeKind) {
case CODE_ATTRIBUTE:
CodeAttributeInfo codeAttributeInfo = (CodeAttributeInfo) attributeInfo;
dataOutStream.writeInt(codeAttributeInfo.codeAddrs);
dataOutStream.writeShort(codeAttributeInfo.maxLongLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxDoubleLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxStringLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxIntLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxByteLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxRefLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxLongRegs);
dataOutStream.writeShort(codeAttributeInfo.maxDoubleRegs);
dataOutStream.writeShort(codeAttributeInfo.maxStringRegs);
dataOutStream.writeShort(codeAttributeInfo.maxIntRegs);
dataOutStream.writeShort(codeAttributeInfo.maxByteRegs);
dataOutStream.writeShort(codeAttributeInfo.maxRefRegs);
break;
case VARIABLE_TYPE_COUNT_ATTRIBUTE:
VarTypeCountAttributeInfo varCountAttributeInfo = (VarTypeCountAttributeInfo) attributeInfo;
dataOutStream.writeShort(varCountAttributeInfo.getMaxLongVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxDoubleVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxStringVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxIntVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxByteVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxRefVars());
break;
case ERROR_TABLE:
ErrorTableAttributeInfo errTable = (ErrorTableAttributeInfo) attributeInfo;
ErrorTableEntry[] errorTableEntries = errTable.getErrorTableEntriesList().toArray(new ErrorTableEntry[0]);
dataOutStream.writeShort(errorTableEntries.length);
for (ErrorTableEntry errorTableEntry : errorTableEntries) {
dataOutStream.writeInt(errorTableEntry.ipFrom);
dataOutStream.writeInt(errorTableEntry.ipTo);
dataOutStream.writeInt(errorTableEntry.ipTarget);
dataOutStream.writeInt(errorTableEntry.priority);
dataOutStream.writeInt(errorTableEntry.errorStructCPIndex);
}
break;
case LOCAL_VARIABLES_ATTRIBUTE:
LocalVariableAttributeInfo localVarAttrInfo = (LocalVariableAttributeInfo) attributeInfo;
LocalVariableInfo[] localVarInfoArray = localVarAttrInfo.localVars.toArray(new LocalVariableInfo[0]);
dataOutStream.writeShort(localVarInfoArray.length);
for (LocalVariableInfo localVariableInfo : localVarInfoArray) {
writeLocalVariableInfo(dataOutStream, localVariableInfo);
}
break;
case LINE_NUMBER_TABLE_ATTRIBUTE:
LineNumberTableAttributeInfo lnNoTblAttrInfo = (LineNumberTableAttributeInfo) attributeInfo;
LineNumberInfo[] lineNumberInfoEntries = lnNoTblAttrInfo.getLineNumberInfoEntries();
dataOutStream.writeShort(lineNumberInfoEntries.length);
for (LineNumberInfo lineNumberInfo : lineNumberInfoEntries) {
writeLineNumberInfo(dataOutStream, lineNumberInfo);
}
break;
case DEFAULT_VALUE_ATTRIBUTE:
DefaultValueAttributeInfo defaultValAttrInfo = (DefaultValueAttributeInfo) attributeInfo;
writeDefaultValue(dataOutStream, defaultValAttrInfo.getDefaultValue());
break;
case PARAMETER_DEFAULTS_ATTRIBUTE:
ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = (ParamDefaultValueAttributeInfo) attributeInfo;
DefaultValue[] defaultValues = paramDefaultValAttrInfo.getDefaultValueInfo();
dataOutStream.writeShort(defaultValues.length);
for (DefaultValue defaultValue : defaultValues) {
writeDefaultValue(dataOutStream, defaultValue);
}
break;
}
// TODO Support other types of attributes
}
use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method visitForkJoinParameterDefs.
private void visitForkJoinParameterDefs(BLangVariable parameterDef, SymbolEnv forkJoinEnv) {
LocalVariableAttributeInfo localVariableAttributeInfo = new LocalVariableAttributeInfo(1);
parameterDef.symbol.varIndex = getLVIndex(parameterDef.type.tag);
this.genNode(parameterDef, forkJoinEnv);
LocalVariableInfo localVariableDetails = this.getLocalVarAttributeInfo(parameterDef.symbol);
localVariableAttributeInfo.localVars.add(localVariableDetails);
}
use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method createServiceInfoEntry.
private void createServiceInfoEntry(BLangService serviceNode) {
// Add service name as an UTFCPEntry to the constant pool
int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, serviceNode.name.value);
// Create service info
if (serviceNode.endpointType != null) {
String endPointQName = serviceNode.endpointType.tsymbol.toString();
// TODO: bvmAlias needed?
int epNameCPIndex = addUTF8CPEntry(currentPkgInfo, endPointQName);
ServiceInfo serviceInfo = new ServiceInfo(currentPackageRefCPIndex, serviceNameCPIndex, serviceNode.symbol.flags, epNameCPIndex);
// Add service level variables
int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
serviceNode.vars.forEach(var -> visitVarSymbol(var.var.symbol, pvIndexes, localVarAttributeInfo));
serviceInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
// Create the init function info
BLangFunction serviceInitFunction = (BLangFunction) serviceNode.getInitFunction();
createFunctionInfoEntry(serviceInitFunction);
serviceInfo.initFuncInfo = currentPkgInfo.functionInfoMap.get(serviceInitFunction.name.toString());
currentPkgInfo.addServiceInfo(serviceNode.name.value, serviceInfo);
// Create resource info entries for all resources
serviceNode.resources.forEach(res -> createResourceInfoEntry(res, serviceInfo));
}
}
use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.CODE_GEN)) {
if (!buildCompiledPackage) {
programFile.packageInfoMap.put(pkgNode.symbol.pkgID.bvmAlias(), pkgNode.symbol.packageInfo);
}
return;
}
// TODO Improve this design without if/else
PackageInfo packageInfo = new PackageInfo();
pkgNode.symbol.packageInfo = packageInfo;
if (buildCompiledPackage) {
// Generating the BALO
pkgNode.imports.forEach(impPkgNode -> {
int impPkgNameCPIndex = addUTF8CPEntry(packageInfo, impPkgNode.symbol.name.value);
// TODO Improve the import package version once it is available
int impPkgVersionCPIndex = addUTF8CPEntry(packageInfo, PackageID.DEFAULT.version.value);
ImportPackageInfo importPkgInfo = new ImportPackageInfo(impPkgNameCPIndex, impPkgVersionCPIndex);
packageInfo.importPkgInfoSet.add(importPkgInfo);
packageFile.packageInfo = packageInfo;
});
} else {
// Generating a BALX
// first visit all the imports
pkgNode.imports.forEach(impPkgNode -> genNode(impPkgNode, this.env));
// TODO We need to create identifier for both name and the version
programFile.packageInfoMap.put(pkgNode.symbol.pkgID.bvmAlias(), packageInfo);
}
// Add the current package to the program file
BPackageSymbol pkgSymbol = pkgNode.symbol;
currentPkgID = pkgSymbol.pkgID;
currentPkgInfo = packageInfo;
currentPkgInfo.nameCPIndex = addUTF8CPEntry(currentPkgInfo, currentPkgID.bvmAlias());
currentPkgInfo.versionCPIndex = addUTF8CPEntry(currentPkgInfo, currentPkgID.version.value);
// Insert the package reference to the constant pool of the current package
currentPackageRefCPIndex = addPackageRefCPEntry(currentPkgInfo, currentPkgID);
// This attribute keep track of line numbers
int lineNoAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE.value());
lineNoAttrInfo = new LineNumberTableAttributeInfo(lineNoAttrNameIndex);
// This attribute keep package-level variable information
int pkgVarAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
currentPkgInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, new LocalVariableAttributeInfo(pkgVarAttrNameIndex));
pkgNode.globalVars.forEach(this::createPackageVarInfo);
pkgNode.structs.forEach(this::createStructInfoEntry);
pkgNode.enums.forEach(this::createEnumInfoEntry);
pkgNode.connectors.forEach(this::createConnectorInfoEntry);
pkgNode.functions.forEach(this::createFunctionInfoEntry);
pkgNode.services.forEach(this::createServiceInfoEntry);
pkgNode.functions.forEach(this::createFunctionInfoEntry);
pkgNode.transformers.forEach(this::createTransformerInfoEntry);
// Visit package builtin function
visitBuiltinFunctions(pkgNode.initFunction);
visitBuiltinFunctions(pkgNode.startFunction);
visitBuiltinFunctions(pkgNode.stopFunction);
pkgNode.topLevelNodes.stream().filter(pkgLevelNode -> pkgLevelNode.getKind() != NodeKind.VARIABLE && pkgLevelNode.getKind() != NodeKind.XMLNS).forEach(pkgLevelNode -> genNode((BLangNode) pkgLevelNode, this.env));
currentPkgInfo.addAttributeInfo(AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE, lineNoAttrInfo);
currentPackageRefCPIndex = -1;
currentPkgID = null;
pkgNode.completedPhases.add(CompilerPhase.CODE_GEN);
}
use of org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method createPackageVarInfo.
// Create info entries
private void createPackageVarInfo(BLangVariable varNode) {
BVarSymbol varSymbol = varNode.symbol;
varSymbol.varIndex = getPVIndex(varSymbol.type.tag);
int varNameCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.name.value);
int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.type.getDesc());
PackageVarInfo pkgVarInfo = new PackageVarInfo(varNameCPIndex, typeSigCPIndex, varSymbol.flags, varSymbol.varIndex.value);
currentPkgInfo.pkgVarInfoMap.put(varSymbol.name.value, pkgVarInfo);
LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
LocalVariableAttributeInfo pkgVarAttrInfo = (LocalVariableAttributeInfo) currentPkgInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
pkgVarAttrInfo.localVars.add(localVarInfo);
// TODO Populate annotation attribute
}
Aggregations