public override AstNode Visit(UsingStatement node) { // Visit the using member. Expression member = node.GetMember(); member.Accept(this); // Cast the pseudo-scope. PseudoScope scope = (PseudoScope)node.GetScope(); // Get the member type. IChelaType memberType = member.GetNodeType(); if (memberType.IsMetaType()) { // Get the actual type. MetaType meta = (MetaType)memberType; memberType = meta.GetActualType(); // Only structure relatives. if (memberType.IsStructure() || memberType.IsClass() || memberType.IsInterface()) { scope.AddAlias(memberType.GetName(), (ScopeMember)memberType); } else { Error(node, "unexpected type."); } } else if (memberType.IsReference()) { // Only static members supported. ScopeMember theMember = (ScopeMember)member.GetNodeValue(); MemberFlags instanceFlags = MemberFlags.InstanceMask & theMember.GetFlags(); if (instanceFlags != MemberFlags.Static) { Error(node, "unexpected member type."); } // Store the member. scope.AddAlias(theMember.GetName(), theMember); } else if (memberType.IsNamespace()) { // Set the namespace chain. Namespace space = (Namespace)member.GetNodeValue(); scope.SetChainNamespace(space); } else { Error(node, "unsupported object to use."); } base.Visit(node); return(node); }
private void ProcessBases(StructDefinition node) { // Process the bases. int numbases = 0; AstNode baseNode = node.GetBases(); Structure building = node.GetStructure(); for (; baseNode != null; baseNode = baseNode.GetNext()) { // Visit the base. baseNode.Accept(this); // Get the node type. IChelaType baseType = baseNode.GetNodeType(); baseType = ExtractActualType(node, baseType); // Check base security. if (baseType.IsUnsafe()) { UnsafeError(node, "safe class/struct/interface with unsafe base/interface."); } // Check the class/struct/iface matches. if (!baseType.IsInterface() && baseType.IsClass() != building.IsClass()) { Error(baseNode, "incompatible base type."); } // Check for interface inheritance. if (building.IsInterface() && !baseType.IsInterface()) { Error(baseNode, "interfaces only can have interfaces as bases."); } // Only single inheritance, multiple interfaces. if (numbases >= 1 && !baseType.IsInterface()) { Error(baseNode, "only single inheritance and multiples interfaces is supported."); } // Set the base building. if (baseType.IsInterface()) { building.AddInterface((Structure)baseType); } else { Structure oldBase = building.GetBase(); Structure baseBuilding = (Structure)baseType; if (oldBase != null && oldBase != baseBuilding) { Error(node, "incompatible partial class bases."); } building.SetBase(baseBuilding); numbases++; } } // Notify the building. building.CompletedBases(); }
internal void PrepareSerialization(ChelaModule module) { // Register types and external members used. InstructionDescription desc = InstructionDescription.GetInstructionTable()[(int)opcode]; InstructionArgumentType[] args = desc.GetArguments(); for (int i = 0, k = 0; i < arguments.Length; i++, k++) { object arg = arguments[i]; switch (args[k]) { case InstructionArgumentType.UInt8V: case InstructionArgumentType.Int8V: case InstructionArgumentType.UInt16V: case InstructionArgumentType.Int16V: case InstructionArgumentType.UInt32V: case InstructionArgumentType.Int32V: case InstructionArgumentType.UInt64V: case InstructionArgumentType.Int64V: case InstructionArgumentType.Fp32V: case InstructionArgumentType.Fp64V: { // Ignore the vector arguments. byte n = (byte)arg; i += n; } break; case InstructionArgumentType.TypeID: { // Prepare serialization of generic instances. IChelaType argType = (IChelaType)arg; if (argType.IsGenericInstance() && (argType.IsStructure() || argType.IsClass() || argType.IsInterface())) { ScopeMember member = (ScopeMember)argType; member.PrepareSerialization(); } // Register types. module.RegisterType(argType); } break; case InstructionArgumentType.GlobalID: case InstructionArgumentType.FieldID: case InstructionArgumentType.FunctionID: { // Register external members. ScopeMember member = (ScopeMember)arg; if (member != null) { if (member.IsGenericInstance()) { member.PrepareSerialization(); } module.RegisterMember(member); } } break; case InstructionArgumentType.JumpTable: { // Ignore the jump table ushort tableLen = (ushort)arg; i += tableLen * 2; } break; default: // Do nothing. break; } } }
/// <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; }