public void AddType(Structure type) { // Find the previous group. ScopeMember oldMember = FindMember(type.GetName()); if (oldMember != null) { if (!oldMember.IsTypeGroup()) { throw new ModuleException("expected type group."); } // Find the previous definition. TypeGroup oldGroup = (TypeGroup)oldMember; if (oldGroup.Find(type.GetGenericPrototype()) != null) { throw new ModuleException("matching type already exists."); } // Add the type into the group. oldGroup.Insert(type); } else { // Create a new type group. TypeGroup newGroup = new TypeGroup(type.GetName(), this); newGroup.Insert(type); AddMember(newGroup); } }
protected static bool RecursiveMerge(ref ScopeMember res, ScopeMember level) { if(level != null && res != null) { if(res.IsTypeGroup() && level.IsTypeGroup()) { // Merge type groups. TypeGroup lower = (TypeGroup)res; TypeGroup next = (TypeGroup)level; if(!lower.IsMergedGroup()) res = lower.CreateMerged(next, false); else lower.AppendLevel(next, false); } else if(res.IsFunctionGroup() && level.IsFunctionGroup()) { // Merge function groups. FunctionGroup lower = (FunctionGroup)res; FunctionGroup next = (FunctionGroup)level; if(!lower.IsMergedGroup()) res = lower.CreateMerged(next, false); else lower.AppendLevel(next, false); } } else if(res == null) { // Set the result to the next level. res = level; } return IsRecursiveContinue(res); }
protected static bool RecursiveMerge(ref ScopeMember res, ScopeMember level) { if (level != null && res != null) { if (res.IsTypeGroup() && level.IsTypeGroup()) { // Merge type groups. TypeGroup lower = (TypeGroup)res; TypeGroup next = (TypeGroup)level; if (!lower.IsMergedGroup()) { res = lower.CreateMerged(next, false); } else { lower.AppendLevel(next, false); } } else if (res.IsFunctionGroup() && level.IsFunctionGroup()) { // Merge function groups. FunctionGroup lower = (FunctionGroup)res; FunctionGroup next = (FunctionGroup)level; if (!lower.IsMergedGroup()) { res = lower.CreateMerged(next, false); } else { lower.AppendLevel(next, false); } } } else if (res == null) { // Set the result to the next level. res = level; } return(IsRecursiveContinue(res)); }
public virtual Structure FindType(string name, GenericPrototype prototype) { // Find the member. ScopeMember member = FindMember(name); if (member == null) { return(null); } // Use the matching type in the type group. if (member.IsTypeGroup()) { TypeGroup group = (TypeGroup)member; return(group.Find(prototype)); } else if (!member.IsClass() && !member.IsInterface() && !member.IsStructure()) { throw new ModuleException("found no structural type " + member.GetFullName()); } // Cast the member. return((Structure)member); }
public Structure ExtractClass(AstNode where, ScopeMember member) { // Make sure its a structure or type group. if(!member.IsClass() && !member.IsStructure() &&!member.IsInternal() && !member.IsTypeGroup()) Error(where, "coudn't load runtime class."); // Read the type group. if(member.IsTypeGroup()) { TypeGroup group = (TypeGroup)member; Structure building = group.GetDefaultType(); if(building == null) Error(where, "unexpected type group {0}", @group.GetDisplayName()); // Prevent ambiguity of merged type group. building.CheckAmbiguity(where.GetPosition()); return building; } return (Structure)member; }
protected static bool IsRecursiveContinue(ScopeMember member) { return(member == null || member.IsTypeGroup() || member.IsFunctionGroup()); }
protected static bool IsRecursiveContinue(ScopeMember member) { return member == null || member.IsTypeGroup() || member.IsFunctionGroup(); }