use of org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry 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());
}
}
use of org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry in project ballerina by ballerina-lang.
the class ProgramFileReader method resolveConnectorMethodTables.
private void resolveConnectorMethodTables(PackageInfo packageInfo) {
ConnectorInfo[] connectorInfoEntries = packageInfo.getConnectorInfoEntries();
for (ConnectorInfo connectorInfo : connectorInfoEntries) {
BConnectorType connectorType = connectorInfo.getType();
VarTypeCountAttributeInfo attributeInfo = (VarTypeCountAttributeInfo) connectorInfo.getAttributeInfo(AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE);
connectorType.setFieldTypeCount(attributeInfo.getVarTypeCount());
Map<Integer, Integer> methodTableInteger = connectorInfo.getMethodTableIndex();
Map<BConnectorType, ConnectorInfo> methodTableType = new HashMap<>();
for (Integer key : methodTableInteger.keySet()) {
int keyType = methodTableInteger.get(key);
TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) packageInfo.getCPEntry(key);
StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) packageInfo.getCPEntry(keyType);
ConnectorInfo connectorInfoType = (ConnectorInfo) structureRefCPEntry.getStructureTypeInfo();
methodTableType.put((BConnectorType) typeRefCPEntry.getType(), connectorInfoType);
}
connectorInfo.setMethodTableType(methodTableType);
for (ActionInfo actionInfo : connectorInfo.getActionInfoEntries()) {
setCallableUnitSignature(actionInfo, actionInfo.getSignature(), packageInfo);
}
}
}
use of org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry 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());
}
}
use of org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry 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;
}
}
}
use of org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry in project ballerina by ballerina-lang.
the class CPU method createNewConnector.
private static void createNewConnector(WorkerExecutionContext ctx, int[] operands, WorkerData sf) {
int cpIndex = operands[0];
int i = operands[1];
StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) ctx.constPool[cpIndex];
ConnectorInfo connectorInfo = (ConnectorInfo) structureRefCPEntry.getStructureTypeInfo();
BConnector bConnector = new BConnector(connectorInfo.getType());
sf.refRegs[i] = bConnector;
}
Aggregations