private void RegisterAnonTypeLeaf(IChelaType type, bool registered) { // Make sure lower types are registered. if(!registered) RegisterType(type); if(type.IsReference()) { ReferenceType refType = (ReferenceType)type; RegisterAnonTypeLeaf(refType.GetReferencedType()); } else if(type.IsPointer()) { PointerType pointerType = (PointerType)type; RegisterAnonTypeLeaf(pointerType.GetPointedType()); } else if(type.IsConstant()) { ConstantType constType = (ConstantType)type; RegisterAnonTypeLeaf(constType.GetValueType()); } else if(type.IsArray()) { ArrayType arrayType = (ArrayType)type; RegisterAnonTypeLeaf(arrayType.GetValueType()); } else if(type.IsVector()) { VectorType vectorType = (VectorType)type; RegisterAnonTypeLeaf(vectorType.GetPrimitiveType()); } else if(type.IsMatrix()) { MatrixType matrixType = (MatrixType)type; RegisterAnonTypeLeaf(matrixType.GetPrimitiveType()); } else if(type.IsFunction()) { FunctionType functionType = (FunctionType)type; // Register the return type. RegisterAnonTypeLeaf(functionType.GetReturnType()); // Register the function arguments. for(int i = 0; i < functionType.GetArgumentCount(); ++i) RegisterAnonTypeLeaf(functionType.GetArgument(i)); } else if(type.IsPlaceHolderType()) { // Register the base types. PlaceHolderType placeholder = (PlaceHolderType)type; for(int i = 0; i < placeholder.GetBaseCount(); ++i) RegisterMember(placeholder.GetBase(i)); } else if(type.IsPrimitive()) { // Do nothing. } else if(type.IsTypeInstance()) { StructureInstance instance = (StructureInstance)type; instance.PrepareSerialization(); RegisterMember(instance); } else { // Found a leaf. ScopeMember member = (ScopeMember)type; RegisterMember(member); } }
/// <summary> /// Registers a type in the module, giving back his id. /// </summary> internal uint RegisterType(IChelaType type) { // Used to link standard runtime types with his respective aliases. IChelaType typeMapped = TypeMap(type); if(typeMapped != null && typeMapped != type) return RegisterType(typeMapped); if(type.IsPrimitive()) { PrimitiveType primType = (PrimitiveType) type; return (uint)primType.GetPrimitiveId(); } uint res; if(registeredTypes.TryGetValue(type, out res)) return res; // Don't allow registration when writing the module. if(writingModule) throw new BugException("Writing unregistered type " + type.GetFullName()); // Add into the type table. res = (uint)(typeTable.Count + 0x100); typeTable.Add(type); // Add into anonymous types. if(!type.IsClass() && !type.IsStructure() && !type.IsInterface() && !type.IsTypeInstance()) { anonymousTypeMap.Add(type, (uint)anonymousTypes.Count); anonymousTypes.Add(type); } else { // Make sure the member is registered. RegisterMember((ScopeMember)type); } // Add into the registered types. registeredTypes.Add(type, res); return res; }