* @param visitedTypeExpr
* @param msgLogger the logger to which to log deserialization messages.
* @return an instance of RecordVar.
*/
static RecordVar load (RecordInputStream s, ModuleTypeInfo mti, Map<Short, TypeExpr> visitedTypeExpr, Map<Short, RecordVar> visitedRecordVar, CompilerMessageLogger msgLogger) throws IOException {
RecordHeaderInfo rhi = s.findRecord(RECORD_VAR_RECORD_TAGS);
if (rhi == null) {
throw new IOException("Unable to find RecordVar record header.");
}
switch(rhi.getRecordTag()) {
case ModuleSerializationTags.ALREADY_VISITED_RECORD_VAR:
{
DeserializationHelper.checkSerializationSchema(rhi.getSchema(), alreadyVisitedRecordVarSerializationSchema, mti.getModuleName(), "RecordVar", msgLogger);
// Read the key and do the lookup.
short id = s.readShortCompressed();
RecordVar recordVar = visitedRecordVar.get(new Short(id));
if (recordVar == null) {
throw new IOException ("Unable to resolve previously encountered RecordVar instance in RecordVar.");
}
s.skipRestOfRecord();
return recordVar;
}
case ModuleSerializationTags.RECORD_VAR:
{
DeserializationHelper.checkSerializationSchema(rhi.getSchema(), serializationSchema, mti.getModuleName(), "RecordVar", msgLogger);
byte flags = s.readByte();
// Short-circuit for the special NO_FIELDS case
if((flags & (HAS_LACKS_FIELD_CONSTRAINTS | HAS_TYPE_CLASS_CONSTRAINTS)) == 0) {
s.skipRestOfRecord();
visitedRecordVar.put(new Short((short)visitedRecordVar.size()), NO_FIELDS);
return NO_FIELDS;
}
RecordVar rv = new RecordVar();
visitedRecordVar.put(new Short((short)visitedRecordVar.size()), rv);
RecordType instance = null;
if ((flags & HAS_NON_NULL_INSTANCE) > 0) {
instance = (RecordType)TypeExpr.load(s, mti, visitedTypeExpr, visitedRecordVar, msgLogger);
}
Set<FieldName> lacksFieldSet = null;
if ((flags & HAS_LACKS_FIELD_CONSTRAINTS) > 0) {
int nLacksFields = s.readShortCompressed();
if (nLacksFields > 0) {
lacksFieldSet = new HashSet<FieldName>();
for (int i = 0; i < nLacksFields; ++i) {
FieldName fn = FieldNameIO.load(s, mti.getModuleName(), msgLogger);
lacksFieldSet.add(fn);
}
} else {
lacksFieldSet = NO_LACKS_FIELDS;
}
}
SortedSet<TypeClass> typeClassConstraintSet = TypeClass.NO_CLASS_CONSTRAINTS;
if((flags & HAS_TYPE_CLASS_CONSTRAINTS) > 0) {
int nTC = s.readShortCompressed();
if (nTC > 0) {
typeClassConstraintSet = TypeClass.makeNewClassConstraintSet();
for (int i = 0; i < nTC; ++i) {
QualifiedName qn = s.readQualifiedName();
TypeClass tc = mti.getReachableTypeClass(qn);
// This could be a type from a non-direct dependee module.
if (tc == null) {
IOException ioe = new IOException("Unable to resolve TypeClass " + qn + " while loading RecordVar.");
throw ioe;
}
typeClassConstraintSet.add(tc);
}
}
}
rv.lacksFieldsSet = lacksFieldSet;
rv.typeClassConstraintSet = typeClassConstraintSet;
if (instance != null) {
rv.setInstance(instance);
}
rv.preferredName = s.readUTF();
s.skipRestOfRecord();
return rv;
}
default:
{
throw new IOException("Unexpected record tag " + rhi.getRecordTag() + " found when looking for RecordVar.");
}
}
}