* @param msgLogger the logger to which to log deserialization messages.
* @return an instance of CoreFunction.
* @throws IOException
*/
public static final CoreFunction load (RecordInputStream s, ModuleTypeInfo mti, CompilerMessageLogger msgLogger) throws IOException {
RecordHeaderInfo rhi = s.findRecord(ModuleSerializationTags.CORE_FUNCTION);
if (rhi == null) {
throw new IOException("Unable to find CoreFunction record header.");
}
DeserializationHelper.checkSerializationSchema(rhi.getSchema(), serializationSchema, mti.getModuleName(), "CoreFunction", msgLogger);
QualifiedName name = s.readQualifiedName();
try {
byte flags = s.readByte();
boolean aliasOfExists = (flags & 0x01) > 0;
boolean isTailRecursive = (flags & 0x02) > 0;
boolean functionCanBeEagerlyEvaluated = (flags &0x04) > 0;
int nArgs = s.readShortCompressed();
String[] argNames = new String[nArgs];
for (int i = 0; i < nArgs; ++i) {
argNames[i] = s.readUTF();
}
int nBytesForArgFlags = (nArgs + 7) / 8;
byte[] argFlags = new byte[nBytesForArgFlags];
for (int i = 0; i < argFlags.length; ++i) {
argFlags[i] = s.readByte();
}
boolean[] argStrictness = RecordInputStream.bitArrayToBooleans(argFlags, nArgs);
TypeExpr[] argTypes = new TypeExpr[nArgs];
for (int i = 0; i < argFlags.length; ++i) {
argFlags[i] = s.readByte();
}
boolean[] typeExistence = RecordInputStream.bitArrayToBooleans(argFlags, nArgs);
int nArgsPresent = 0;
for (int i = 0; i < nArgs; ++i) {
if (typeExistence[i]) {
nArgsPresent++;
}
}
TypeExpr[] types = TypeExpr.load(s, mti, nArgsPresent+1, msgLogger);
int iSource = 0;
// length of type existence is the number of args
for(int iDest = 0; iDest < nArgs; ++iDest){
if (typeExistence[iDest]){
argTypes[iDest] = types[iSource++];
}
}
TypeExpr resultType = types[nArgsPresent];
QualifiedName aliasOf = null;
if (aliasOfExists) {
aliasOf = s.readQualifiedName();
}
long timeStamp = s.readLong();
int nConnectedComponents = s.readShortCompressed();
Set<String> connectedComponents = new HashSet<String>();
for (int i = 0; i < nConnectedComponents; ++i) {
String componentName = s.readUTF();
connectedComponents.add(componentName);
}
byte type = s.readByte();
CoreFunction cf = new CoreFunction (name,
argNames,
argStrictness,
argTypes,
resultType,
type,
functionCanBeEagerlyEvaluated,
timeStamp);
cf.setIsTailRecursive(isTailRecursive);
cf.setAliasOf(aliasOf);
cf.setStronglyConnectedComponents(connectedComponents);
if (!s.atEndOfRecord()) {
boolean b = s.readBoolean();
if (b) {
byte typeByte = s.readByte();
if (typeByte == LITERAL_TYPE_CHARACTER) {
cf.literalValue = Character.valueOf(s.readChar());
} else if (typeByte == LITERAL_TYPE_BOOLEAN) {
cf.literalValue = Boolean.valueOf(s.readBoolean());
} else if (typeByte == LITERAL_TYPE_INTEGER) {
cf.literalValue = Integer.valueOf(s.readInt());
} else if (typeByte == LITERAL_TYPE_DOUBLE) {
cf.literalValue = Double.valueOf(s.readDouble());
} else if (typeByte == LITERAL_TYPE_BYTE) {
cf.literalValue = Byte.valueOf(s.readByte());
} else if (typeByte == LITERAL_TYPE_SHORT) {
cf.literalValue = Short.valueOf(s.readShort());
} else if (typeByte == LITERAL_TYPE_FLOAT) {
cf.literalValue = Float.valueOf(s.readFloat());
} else if (typeByte == LITERAL_TYPE_LONG) {
cf.literalValue = Long.valueOf(s.readLong());
} else if (typeByte == LITERAL_TYPE_STRING) {
cf.literalValue = s.readUTF();
} else if (typeByte == LITERAL_TYPE_BIG_INTEGER) {
String ds = s.readUTF();
cf.literalValue = new BigInteger(ds);
} else {
throw new IOException ("Attemp to read unhandled literal value.");
}
}
}
boolean isForAdjunct = s.readBoolean();
cf.setForAdjunct(isForAdjunct);
if (rhi.getSchema() >= serializationSchema){
boolean hadUnsafeCoerce = s.readBoolean();
if (hadUnsafeCoerce){
cf.setHadUnsafeCoerce();
}
}