public override AstNode Visit(StructDefinition node) { // Fix the vtable. try { node.GetStructure().FixInheritance(); } catch (ModuleException error) { Error(node, error.Message); } // Create default constructor. CreateDefaultConstructor(node); // Update the scope. PushScope(node.GetScope()); // Visit his children. VisitList(node.GetChildren()); // Restore the scope. PopScope(); return(node); }
public override AstNode Visit(StructDefinition node) { // Use the generic scope. PseudoScope genScope = node.GetGenericScope(); if (genScope != null) { PushScope(genScope); } // Process the base structures. node.GetStructure().SetBase(currentModule.GetValueTypeClass()); // Process the base interfaces. ProcessBases(node); // Update the scope. PushScope(node.GetScope()); // Visit his children. VisitList(node.GetChildren()); // Restore the scope. PopScope(); // Pop the generic scope. if (genScope != null) { PopScope(); } return(node); }
public override AstNode Visit(StructDefinition node) { // Parse the generic signature. GenericSignature genericSign = node.GetGenericSignature(); GenericPrototype genProto = GenericPrototype.Empty; PseudoScope protoScope = null; if (genericSign != null) { // Visit the generic signature. genericSign.Accept(this); // Connect the generic prototype. genProto = genericSign.GetPrototype(); // Create the placeholders scope. protoScope = new PseudoScope(currentScope, genProto); node.SetGenericScope(protoScope); } // Prevent redefinition. ScopeMember old = currentContainer.FindType(node.GetName(), genProto); if (old != null) { Error(node, "trying to redefine a struct."); } // Create the structure Structure building = new Structure(node.GetName(), node.GetFlags(), currentContainer); building.SetGenericPrototype(genProto); node.SetStructure(building); building.Position = node.GetPosition(); // Use the prototype scope. if (protoScope != null) { PushScope(protoScope); } // Register type association. string fullName = building.GetFullName(); IChelaType assoc; if (assocClasses.TryGetValue(fullName, out assoc)) { currentModule.RegisterAssociatedClass(assoc, building); } // Add into the current scope. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddType(building); } else if (currentContainer.IsStructure() || currentContainer.IsInterface() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; parent.AddType(building); } else { Error(node, "unexpected place for a structure."); } // Push the building unsafe. if (building.IsUnsafe()) { PushUnsafe(); } // Update the scope. PushScope(building); // Visit the building children. VisitList(node.GetChildren()); // Restore the scope. PopScope(); // Pop the building unsafe. if (building.IsUnsafe()) { PopUnsafe(); } // Restore the prototype scope. if (protoScope != null) { PopScope(); } return(node); }