Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 protected TypeGroup(TypeGroup group)
     : base(group.GetModule())
 {
     this.name = group.name;
     this.fullName = null;
     this.parentScope = group.GetParentScope();
     this.types = new SimpleSet<TypeGroupName> ();
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        public void AppendLevel(TypeGroup level, bool isNamespaceLevel)
        {
            foreach(TypeGroupName gname in level.types)
            {
                // Check if the object belongs to the included namespace level
                bool isNamespace = gname.IsNamespaceLevel || isNamespaceLevel;

                // Add not found types.
                TypeGroupName old = Find(gname);
                if(old == null)
                {
                    TypeGroupName newName = new TypeGroupName(gname);
                    newName.IsNamespaceLevel = isNamespace;
                    types.Add(newName);
                    continue;
                }

                // Ignore names of lower scopes.
                if(!isNamespace || !old.IsNamespaceLevel)
                    continue;

                // Now the old name is a namespace level, and we are adding another
                // namespace level type, in other words, we have detected an ambiguity.
                Structure oldType = old.GetBuilding();
                AmbiguousStructure amb;
                if(!oldType.IsAmbiguity())
                {
                    amb = new AmbiguousStructure(oldType.GetName(), oldType.GetFlags(), oldType.GetParentScope());
                    amb.AddCandidate(oldType);
                    old.SetBuilding(oldType);
                }
                else
                {
                    amb = (AmbiguousStructure)oldType;
                }

                // Add the new function into the ambiguity list.
                amb.AddCandidate(gname.GetBuilding());
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public TypeGroup CreateMerged(TypeGroup firstLevel, bool isNamespace)
 {
     TypeGroup ret = new TypeGroup(this);
     ret.mergedGroup = true;
     ret.AppendLevel(firstLevel, isNamespace);
     return ret;
 }
Exemplo n.º 7
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            TypeGroup tgroup = new TypeGroup (module);
            module.RegisterMember (tgroup);

            // Read the name.
            tgroup.name = module.GetString (header.memberName);

            // Skip the structure elements.
            reader.Skip (header.memberSize);
        }
Exemplo n.º 8
0
        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);
            }
        }