use of org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method resolveUserDefinedTypes.
private void resolveUserDefinedTypes(PackageInfo packageInfo) {
// TODO Improve this. We should be able to this in a single pass.
StructInfo[] structInfoEntries = packageInfo.getStructInfoEntries();
for (StructInfo structInfo : structInfoEntries) {
StructFieldInfo[] fieldInfoEntries = structInfo.getFieldInfoEntries();
BStructType structType = structInfo.getType();
BStructType.StructField[] structFields = new BStructType.StructField[fieldInfoEntries.length];
for (int i = 0; i < fieldInfoEntries.length; i++) {
// Get the BType from the type descriptor
StructFieldInfo fieldInfo = fieldInfoEntries[i];
String typeDesc = fieldInfo.getTypeDescriptor();
BType fieldType = getBTypeFromDescriptor(typeDesc);
fieldInfo.setFieldType(fieldType);
// Create the StructField in the BStructType. This is required for the type equivalence algorithm
BStructType.StructField structField = new BStructType.StructField(fieldType, fieldInfo.getName(), fieldInfo.flags);
structFields[i] = structField;
}
VarTypeCountAttributeInfo attributeInfo = (VarTypeCountAttributeInfo) structInfo.getAttributeInfo(AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE);
structType.setFieldTypeCount(attributeInfo.getVarTypeCount());
structType.setStructFields(structFields);
// Resolve attached function signature
int attachedFuncCount = structInfo.funcInfoEntries.size();
BStructType.AttachedFunction[] attachedFunctions = new BStructType.AttachedFunction[attachedFuncCount];
int count = 0;
for (AttachedFunctionInfo attachedFuncInfo : structInfo.funcInfoEntries.values()) {
BFunctionType funcType = getFunctionType(attachedFuncInfo.typeSignature, packageInfo);
BStructType.AttachedFunction attachedFunction = new BStructType.AttachedFunction(attachedFuncInfo.name, funcType, attachedFuncInfo.flags);
attachedFunctions[count++] = attachedFunction;
if (structInfo.initializer == attachedFuncInfo) {
structType.initializer = attachedFunction;
} else if (structInfo.defaultsValuesInitFunc == attachedFuncInfo) {
structType.defaultsValuesInitFunc = attachedFunction;
}
}
structType.setAttachedFunctions(attachedFunctions);
}
for (ConstantPoolEntry cpEntry : unresolvedCPEntries) {
switch(cpEntry.getEntryType()) {
case CP_ENTRY_TYPE_REF:
TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
String typeSig = typeRefCPEntry.getTypeSig();
BType bType = getBTypeFromDescriptor(typeSig);
typeRefCPEntry.setType(bType);
break;
default:
break;
}
}
}
use of org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method readConstantPool.
private void readConstantPool(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
int constantPoolSize = dataInStream.readInt();
for (int i = 0; i < constantPoolSize; i++) {
byte cpTag = dataInStream.readByte();
ConstantPoolEntry.EntryType cpEntryType = ConstantPoolEntry.EntryType.values()[cpTag - 1];
ConstantPoolEntry cpEntry = readCPEntry(dataInStream, constantPool, cpEntryType);
constantPool.addCPEntry(cpEntry);
}
}
use of org.ballerinalang.util.codegen.cpentries.ConstantPoolEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method resolveCPEntries.
private void resolveCPEntries() {
for (ConstantPoolEntry cpEntry : unresolvedCPEntries) {
PackageInfo packageInfo;
StructureRefCPEntry structureRefCPEntry;
switch(cpEntry.getEntryType()) {
case CP_ENTRY_FUNCTION_REF:
FunctionRefCPEntry funcRefCPEntry = (FunctionRefCPEntry) cpEntry;
packageInfo = programFile.getPackageInfo(funcRefCPEntry.getPackagePath());
FunctionInfo functionInfo = packageInfo.getFunctionInfo(funcRefCPEntry.getFunctionName());
funcRefCPEntry.setFunctionInfo(functionInfo);
break;
case CP_ENTRY_STRUCTURE_REF:
structureRefCPEntry = (StructureRefCPEntry) cpEntry;
packageInfo = programFile.getPackageInfo(structureRefCPEntry.getPackagePath());
StructureTypeInfo structureTypeInfo = packageInfo.getStructureTypeInfo(structureRefCPEntry.getStructureName());
structureRefCPEntry.setStructureTypeInfo(structureTypeInfo);
break;
case CP_ENTRY_TYPE_REF:
TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
String typeSig = typeRefCPEntry.getTypeSig();
BType bType = getBTypeFromDescriptor(typeSig);
typeRefCPEntry.setType(bType);
break;
case CP_ENTRY_TRANSFORMER_REF:
TransformerRefCPEntry transformerRefCPEntry = (TransformerRefCPEntry) cpEntry;
packageInfo = programFile.getPackageInfo(transformerRefCPEntry.getPackagePath());
TransformerInfo transformerInfo = packageInfo.getTransformerInfo(transformerRefCPEntry.getTransformerName());
transformerRefCPEntry.setTransformerInfo(transformerInfo);
break;
default:
break;
}
}
}
Aggregations