@Override public void addAttributeInfo(AttributeInfo.Kind attributeKind, AttributeInfo attributeInfo) { attributeInfoMap.put(attributeKind, attributeInfo); if (attributeKind == AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE) { // TODO Move this out of the program file to a program context.. Runtime representation of a program. // TODO ProgramFile is the static program data. VarTypeCountAttributeInfo varTypeCountAttribInfo = (VarTypeCountAttributeInfo) attributeInfo; int[] globalVarCount = varTypeCountAttribInfo.getVarTypeCount(); // TODO Introduce an abstraction for memory blocks // Initialize global memory block BStructureType dummyType = new BRecordType(null, "", "", 0); dummyType.setFieldTypeCount(globalVarCount); this.globalMemoryBlock = new GlobalMemoryBlock(dummyType); } }
private void initGlobalMemBlock(PackageInfo[] packageInfoArray) { for (PackageInfo packageInfo : packageInfoArray) { // Get the package-level variable count from the attribute. AttributeInfo attributeInfo = packageInfo.getAttributeInfo( AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE); VarTypeCountAttributeInfo varTypeCountAttribInfo = (VarTypeCountAttributeInfo) attributeInfo; int[] globalVarCount = varTypeCountAttribInfo.getVarTypeCount(); // We are using the struct value to hold package-level variable values for the moment. BStructureType dummyType = new BRecordType(null, "", "", 0); dummyType.setFieldTypeCount(globalVarCount); globalMemBlock[packageInfo.pkgIndex] = new GlobalMemoryBlock(dummyType); } } }
BRecordType recordType = new BRecordType(recordInfo, typeDefInfo.name, packageInfo.getPkgPath(), typeDefInfo.flags); recordInfo.setType(recordType);
@SuppressWarnings("unchecked") @Override public BRecordType toObject(BPacket packet, BValueDeserializer bValueDeserializer) { String typeName = packet.get(TYPE_NAME).stringValue(); String pkgPath = packet.get(PACKAGE_PATH).stringValue(); int flags = (int) ((BInteger) packet.get(FLAGS)).intValue(); int cpIndex = (int) ((BInteger) packet.get(REST_FIELD_SIGNATURE_CP_INDEX)).intValue(); BBoolean closed = (BBoolean) packet.get(CLOSED); RecordTypeInfo recTypeInfo = new RecordTypeInfo(); recTypeInfo.setRestFieldSignatureCPIndex(cpIndex); BValue restFieldTypeSig = packet.get(REST_FIELD_TYPE_SIGNATURE); if (restFieldTypeSig != null) { String typeSig = restFieldTypeSig.stringValue(); recTypeInfo.setRestFieldTypeSignature(typeSig); } BRecordType bRecType = new BRecordType(recTypeInfo, typeName, pkgPath, flags); Map<String, BField> fields = (Map<String, BField>) bValueDeserializer.deserialize(packet.getValue(), LinkedHashMap.class); bRecType.setFields(fields); recTypeInfo.setType(bRecType); bRecType.restFieldType = (BType) bValueDeserializer.deserialize(packet.get(REST_FIELD_TYPE), BType.class); bRecType.sealed = closed.booleanValue(); return bRecType; } }