use of org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo 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.DefaultValueAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method getDefaultValueAttributeInfo.
private DefaultValueAttributeInfo getDefaultValueAttributeInfo(BLangLiteral literalExpr) {
DefaultValue defaultValue = getDefaultValue(literalExpr);
UTF8CPEntry defaultValueAttribUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.DEFAULT_VALUE_ATTRIBUTE.toString());
int defaultValueAttribNameIndex = currentPkgInfo.addCPEntry(defaultValueAttribUTF8CPEntry);
return new DefaultValueAttributeInfo(defaultValueAttribNameIndex, defaultValue);
}
use of org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo in project ballerina by ballerina-lang.
the class CodeGenerator method createStructInfoEntry.
private void createStructInfoEntry(BLangStruct structNode) {
BStructSymbol structSymbol = (BStructSymbol) structNode.symbol;
// Add Struct name as an UTFCPEntry to the constant pool
int structNameCPIndex = addUTF8CPEntry(currentPkgInfo, structSymbol.name.value);
StructInfo structInfo = new StructInfo(currentPackageRefCPIndex, structNameCPIndex, structSymbol.flags);
currentPkgInfo.addStructInfo(structSymbol.name.value, structInfo);
structInfo.structType = (BStructType) structSymbol.type;
List<BLangVariable> structFields = structNode.fields;
for (BLangVariable structField : structFields) {
// Create StructFieldInfo Entry
int fieldNameCPIndex = addUTF8CPEntry(currentPkgInfo, structField.name.value);
int sigCPIndex = addUTF8CPEntry(currentPkgInfo, structField.type.getDesc());
StructFieldInfo structFieldInfo = new StructFieldInfo(fieldNameCPIndex, sigCPIndex, structField.symbol.flags);
structFieldInfo.fieldType = structField.type;
// Populate default values
if (structField.expr != null && structField.expr.getKind() == NodeKind.LITERAL) {
DefaultValueAttributeInfo defaultVal = getDefaultValueAttributeInfo((BLangLiteral) structField.expr);
structFieldInfo.addAttributeInfo(AttributeInfo.Kind.DEFAULT_VALUE_ATTRIBUTE, defaultVal);
}
structInfo.fieldInfoEntries.add(structFieldInfo);
structField.symbol.varIndex = getFieldIndex(structField.symbol.type.tag);
}
// 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, structInfo, fieldCount);
fieldIndexes = new VariableIndex(FIELD);
// Create attached function info entries
for (BAttachedFunction attachedFunc : structSymbol.attachedFuncs) {
int funcNameCPIndex = addUTF8CPEntry(currentPkgInfo, attachedFunc.funcName.value);
// Remove the first type. The first type is always the type to which the function is attached to
BType[] paramTypes = attachedFunc.type.paramTypes.toArray(new BType[0]);
if (paramTypes.length == 1) {
paramTypes = new BType[0];
} else {
paramTypes = attachedFunc.type.paramTypes.toArray(new BType[0]);
paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length);
}
int sigCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(paramTypes, attachedFunc.type.retTypes.toArray(new BType[0])));
int flags = attachedFunc.symbol.flags;
structInfo.attachedFuncInfoEntries.add(new AttachedFunctionInfo(funcNameCPIndex, sigCPIndex, flags));
}
}
Aggregations