use of org.ballerinalang.util.codegen.cpentries.IntegerCPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method getDefaultValue.
private DefaultValue getDefaultValue(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
DefaultValue defaultValue;
int typeDescCPIndex = dataInStream.readInt();
UTF8CPEntry typeDescCPEntry = (UTF8CPEntry) constantPool.getCPEntry(typeDescCPIndex);
String typeDesc = typeDescCPEntry.getValue();
int valueCPIndex;
switch(typeDesc) {
case TypeSignature.SIG_BOOLEAN:
boolean boolValue = dataInStream.readBoolean();
defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
defaultValue.setBooleanValue(boolValue);
break;
case TypeSignature.SIG_INT:
valueCPIndex = dataInStream.readInt();
IntegerCPEntry integerCPEntry = (IntegerCPEntry) constantPool.getCPEntry(valueCPIndex);
defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
defaultValue.setIntValue(integerCPEntry.getValue());
break;
case TypeSignature.SIG_FLOAT:
valueCPIndex = dataInStream.readInt();
FloatCPEntry floatCPEntry = (FloatCPEntry) constantPool.getCPEntry(valueCPIndex);
defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
defaultValue.setFloatValue(floatCPEntry.getValue());
break;
case TypeSignature.SIG_STRING:
valueCPIndex = dataInStream.readInt();
UTF8CPEntry stringCPEntry = (UTF8CPEntry) constantPool.getCPEntry(valueCPIndex);
defaultValue = new DefaultValue(typeDescCPIndex, typeDesc);
defaultValue.setStringValue(stringCPEntry.getValue());
break;
default:
throw new ProgramFileFormatException("unknown default value type " + typeDesc);
}
return defaultValue;
}
use of org.ballerinalang.util.codegen.cpentries.IntegerCPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method readCPEntry.
private ConstantPoolEntry readCPEntry(DataInputStream dataInStream, ConstantPool constantPool, ConstantPoolEntry.EntryType cpEntryType) throws IOException {
int cpIndex;
int pkgCPIndex;
UTF8CPEntry utf8CPEntry;
PackageRefCPEntry packageRefCPEntry;
Optional<PackageInfo> packageInfoOptional;
switch(cpEntryType) {
case CP_ENTRY_UTF8:
short length = dataInStream.readShort();
String strValue = null;
// Therefore we read the UTF value only if the length >= 0.
if (length >= 0) {
strValue = dataInStream.readUTF();
}
return new UTF8CPEntry(strValue);
case CP_ENTRY_INTEGER:
long longVal = dataInStream.readLong();
return new IntegerCPEntry(longVal);
case CP_ENTRY_FLOAT:
double doubleVal = dataInStream.readDouble();
return new FloatCPEntry(doubleVal);
case CP_ENTRY_STRING:
cpIndex = dataInStream.readInt();
utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
return new StringCPEntry(cpIndex, utf8CPEntry.getValue());
case CP_ENTRY_PACKAGE:
cpIndex = dataInStream.readInt();
utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
return new PackageRefCPEntry(cpIndex, utf8CPEntry.getValue());
case CP_ENTRY_FUNCTION_REF:
pkgCPIndex = dataInStream.readInt();
packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
cpIndex = dataInStream.readInt();
utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
String funcName = utf8CPEntry.getValue();
FunctionRefCPEntry functionRefCPEntry = new FunctionRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, funcName);
// Find the functionInfo
packageInfoOptional = Optional.ofNullable(programFile.getPackageInfo(packageRefCPEntry.getPackageName()));
Optional<FunctionInfo> funcInfoOptional = packageInfoOptional.map(packageInfo -> packageInfo.getFunctionInfo(funcName));
if (!funcInfoOptional.isPresent()) {
// This must reference to the current package and the current package is not been read yet.
// Therefore we add this to the unresolved CP Entry list.
unresolvedCPEntries.add(functionRefCPEntry);
return functionRefCPEntry;
}
functionRefCPEntry.setFunctionInfo(funcInfoOptional.get());
return functionRefCPEntry;
case CP_ENTRY_TRANSFORMER_REF:
pkgCPIndex = dataInStream.readInt();
packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
cpIndex = dataInStream.readInt();
utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
String transformerName = utf8CPEntry.getValue();
TransformerRefCPEntry transformerRefCPEntry = new TransformerRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, transformerName);
// Find the transformerInfo
packageInfoOptional = Optional.ofNullable(programFile.getPackageInfo(packageRefCPEntry.getPackageName()));
Optional<TransformerInfo> transInfoOptional = packageInfoOptional.map(packageInfo -> packageInfo.getTransformerInfo(transformerName));
if (!transInfoOptional.isPresent()) {
// This must reference to the current package and the current package is not been read yet.
// Therefore we add this to the unresolved CP Entry list.
unresolvedCPEntries.add(transformerRefCPEntry);
return transformerRefCPEntry;
}
transformerRefCPEntry.setTransformerInfo(transInfoOptional.get());
return transformerRefCPEntry;
case CP_ENTRY_ACTION_REF:
pkgCPIndex = dataInStream.readInt();
packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
cpIndex = dataInStream.readInt();
UTF8CPEntry nameCPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
String actionName = nameCPEntry.getValue();
return new ActionRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, actionName);
case CP_ENTRY_STRUCTURE_REF:
pkgCPIndex = dataInStream.readInt();
packageRefCPEntry = (PackageRefCPEntry) constantPool.getCPEntry(pkgCPIndex);
cpIndex = dataInStream.readInt();
utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(cpIndex);
StructureRefCPEntry structureRefCPEntry = new StructureRefCPEntry(pkgCPIndex, packageRefCPEntry.getPackageName(), cpIndex, utf8CPEntry.getValue());
packageInfoOptional = Optional.ofNullable(programFile.getPackageInfo(packageRefCPEntry.getPackageName()));
Optional<StructureTypeInfo> structInfoOptional = packageInfoOptional.map(packageInfo -> packageInfo.getStructureTypeInfo(utf8CPEntry.getValue()));
if (!structInfoOptional.isPresent()) {
// This must reference to the current package and the current package is not been read yet.
// Therefore we add this to the unresolved CP Entry list.
unresolvedCPEntries.add(structureRefCPEntry);
return structureRefCPEntry;
}
structureRefCPEntry.setStructureTypeInfo(structInfoOptional.get());
return structureRefCPEntry;
case CP_ENTRY_TYPE_REF:
int typeSigCPIndex = dataInStream.readInt();
utf8CPEntry = (UTF8CPEntry) constantPool.getCPEntry(typeSigCPIndex);
TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex, utf8CPEntry.getValue());
unresolvedCPEntries.add(typeRefCPEntry);
return typeRefCPEntry;
case CP_ENTRY_FORK_JOIN:
int forkJoinCPIndex = dataInStream.readInt();
return new ForkJoinCPEntry(forkJoinCPIndex);
case CP_ENTRY_WRKR_DATA_CHNL_REF:
int uniqueNameCPIndex = dataInStream.readInt();
UTF8CPEntry wrkrDtChnlTypesSigCPEntry = (UTF8CPEntry) constantPool.getCPEntry(uniqueNameCPIndex);
return new WorkerDataChannelRefCPEntry(uniqueNameCPIndex, wrkrDtChnlTypesSigCPEntry.getValue());
default:
throw new ProgramFileFormatException("invalid constant pool entry " + cpEntryType.getValue());
}
}
Aggregations