use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method readConnectorInfoEntries.
private void readConnectorInfoEntries(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
int connectorCount = dataInStream.readShort();
for (int i = 0; i < connectorCount; i++) {
// Read connector name cp index
int connectorNameCPIndex = dataInStream.readInt();
UTF8CPEntry connectorNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(connectorNameCPIndex);
int flags = dataInStream.readInt();
// Create connector info
String connectorName = connectorNameUTF8Entry.getValue();
ConnectorInfo connectorInfo = new ConnectorInfo(packageInfo.getPkgNameCPIndex(), packageInfo.getPkgPath(), connectorNameCPIndex, connectorName, flags);
packageInfo.addConnectorInfo(connectorName, connectorInfo);
// Set connector type
BConnectorType bConnectorType = new BConnectorType(connectorName, packageInfo.getPkgPath());
connectorInfo.setType(bConnectorType);
}
}
use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method readServiceInfoEntries.
private void readServiceInfoEntries(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
int serviceCount = dataInStream.readShort();
for (int i = 0; i < serviceCount; i++) {
// Read connector name cp index
int serviceNameCPIndex = dataInStream.readInt();
UTF8CPEntry serviceNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(serviceNameCPIndex);
int flags = dataInStream.readInt();
// Read connector signature cp index;
int endpointNameCPIndex = dataInStream.readInt();
UTF8CPEntry endpointNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(endpointNameCPIndex);
ServiceInfo serviceInfo = new ServiceInfo(packageInfo.getPkgNameCPIndex(), packageInfo.getPkgPath(), serviceNameCPIndex, serviceNameUTF8Entry.getValue(), flags, endpointNameCPIndex, endpointNameUTF8Entry.getValue());
serviceInfo.setPackageInfo(packageInfo);
packageInfo.addServiceInfo(serviceInfo.getName(), serviceInfo);
serviceInfo.setType(new BServiceType(serviceInfo.getName(), packageInfo.getPkgPath()));
}
}
use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry 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.UTF8CPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method readPackageInfo.
private void readPackageInfo(DataInputStream dataInStream) throws IOException {
PackageInfo packageInfo = new PackageInfo();
// Read constant pool in the package.
readConstantPool(dataInStream, packageInfo);
int pkgNameCPIndex = dataInStream.readInt();
UTF8CPEntry pkgNameCPEntry = (UTF8CPEntry) packageInfo.getCPEntry(pkgNameCPIndex);
packageInfo.nameCPIndex = pkgNameCPIndex;
packageInfo.pkgPath = pkgNameCPEntry.getValue();
packageInfo.setProgramFile(programFile);
programFile.addPackageInfo(packageInfo.pkgPath, packageInfo);
// Read struct info entries
readStructInfoEntries(dataInStream, packageInfo);
// Read enum info entries
readEnumInfoEntries(dataInStream, packageInfo);
// Read connector info entries
readConnectorInfoEntries(dataInStream, packageInfo);
// Read service info entries
readServiceInfoEntries(dataInStream, packageInfo);
// Resolve user-defined type i.e. structs and connectors
resolveUserDefinedTypes(packageInfo);
// Read connector action info entries
readConnectorActionInfoEntries(dataInStream, packageInfo);
// Read resource info entries.
readResourceInfoEntries(dataInStream, packageInfo);
// Read constant info entries
readConstantInfoEntries(dataInStream, packageInfo);
// Read global var info entries
readGlobalVarInfoEntries(dataInStream, packageInfo);
// Read function info entries in the package
readFunctionInfoEntries(dataInStream, packageInfo);
// Read transformer info entries in the package
readTransformerInfoEntries(dataInStream, packageInfo);
// TODO Read annotation info entries
// Resolve unresolved CP entries.
resolveCPEntries();
resolveConnectorMethodTables(packageInfo);
// Read attribute info entries
readAttributeInfoEntries(dataInStream, packageInfo, packageInfo);
// Read instructions
readInstructions(dataInStream, packageInfo);
packageInfo.complete();
}
use of org.ballerinalang.util.codegen.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method getAttributeInfo.
private AttributeInfo getAttributeInfo(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
int attribNameCPIndex = dataInStream.readInt();
UTF8CPEntry attribNameCPEntry = (UTF8CPEntry) constantPool.getCPEntry(attribNameCPIndex);
AttributeInfo.Kind attribKind = AttributeInfo.Kind.fromString(attribNameCPEntry.getValue());
if (attribKind == null) {
throw new ProgramFileFormatException("unknown attribute kind " + attribNameCPEntry.getValue());
}
switch(attribKind) {
case CODE_ATTRIBUTE:
CodeAttributeInfo codeAttributeInfo = new CodeAttributeInfo();
codeAttributeInfo.setAttributeNameIndex(attribNameCPIndex);
codeAttributeInfo.setCodeAddrs(dataInStream.readInt());
codeAttributeInfo.setMaxLongLocalVars(dataInStream.readUnsignedShort());
codeAttributeInfo.setMaxDoubleLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxStringLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxIntLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxByteLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxRefLocalVars(dataInStream.readShort());
codeAttributeInfo.setMaxLongRegs(dataInStream.readShort());
codeAttributeInfo.setMaxDoubleRegs(dataInStream.readShort());
codeAttributeInfo.setMaxStringRegs(dataInStream.readShort());
codeAttributeInfo.setMaxIntRegs(dataInStream.readShort());
codeAttributeInfo.setMaxByteRegs(dataInStream.readShort());
codeAttributeInfo.setMaxRefRegs(dataInStream.readShort());
return codeAttributeInfo;
case VARIABLE_TYPE_COUNT_ATTRIBUTE:
VarTypeCountAttributeInfo varCountAttributeInfo = new VarTypeCountAttributeInfo(attribNameCPIndex);
varCountAttributeInfo.setMaxLongVars(dataInStream.readShort());
varCountAttributeInfo.setMaxDoubleVars(dataInStream.readShort());
varCountAttributeInfo.setMaxStringVars(dataInStream.readShort());
varCountAttributeInfo.setMaxIntVars(dataInStream.readShort());
varCountAttributeInfo.setMaxByteVars(dataInStream.readShort());
varCountAttributeInfo.setMaxRefVars(dataInStream.readShort());
return varCountAttributeInfo;
case ERROR_TABLE:
ErrorTableAttributeInfo tableAttributeInfo = new ErrorTableAttributeInfo(attribNameCPIndex);
int tableEntryCount = dataInStream.readShort();
for (int i = 0; i < tableEntryCount; i++) {
int ipFrom = dataInStream.readInt();
int ipTo = dataInStream.readInt();
int ipTarget = dataInStream.readInt();
int priority = dataInStream.readInt();
int errorStructCPIndex = dataInStream.readInt();
ErrorTableEntry tableEntry = new ErrorTableEntry(ipFrom, ipTo, ipTarget, priority, errorStructCPIndex);
if (errorStructCPIndex != -1) {
StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) constantPool.getCPEntry(errorStructCPIndex);
tableEntry.setError((StructInfo) structureRefCPEntry.getStructureTypeInfo());
}
tableAttributeInfo.addErrorTableEntry(tableEntry);
}
return tableAttributeInfo;
case LOCAL_VARIABLES_ATTRIBUTE:
LocalVariableAttributeInfo localVarAttrInfo = new LocalVariableAttributeInfo(attribNameCPIndex);
int localVarInfoCount = dataInStream.readShort();
for (int i = 0; i < localVarInfoCount; i++) {
LocalVariableInfo localVariableInfo = getLocalVariableInfo(dataInStream, constantPool);
localVarAttrInfo.addLocalVarInfo(localVariableInfo);
}
return localVarAttrInfo;
case LINE_NUMBER_TABLE_ATTRIBUTE:
LineNumberTableAttributeInfo lnNoTblAttrInfo = new LineNumberTableAttributeInfo(attribNameCPIndex);
int lineNoInfoCount = dataInStream.readShort();
for (int i = 0; i < lineNoInfoCount; i++) {
LineNumberInfo lineNumberInfo = getLineNumberInfo(dataInStream, constantPool);
lnNoTblAttrInfo.addLineNumberInfo(lineNumberInfo);
}
return lnNoTblAttrInfo;
case DEFAULT_VALUE_ATTRIBUTE:
DefaultValue defaultValue = getDefaultValue(dataInStream, constantPool);
DefaultValueAttributeInfo defaultValAttrInfo = new DefaultValueAttributeInfo(attribNameCPIndex, defaultValue);
return defaultValAttrInfo;
case PARAMETER_DEFAULTS_ATTRIBUTE:
ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = new ParamDefaultValueAttributeInfo(attribNameCPIndex);
int paramDefaultsInfoCount = dataInStream.readShort();
for (int i = 0; i < paramDefaultsInfoCount; i++) {
DefaultValue paramDefaultValue = getDefaultValue(dataInStream, constantPool);
paramDefaultValAttrInfo.addParamDefaultValueInfo(paramDefaultValue);
}
return paramDefaultValAttrInfo;
default:
throw new ProgramFileFormatException("unsupported attribute kind " + attribNameCPEntry.getValue());
}
}
Aggregations