Example #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);
            }
        }
Example #2
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);
        }
Example #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));
        }
Example #4
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);
        }
Example #5
0
        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;
        }
Example #6
0
 protected static bool IsRecursiveContinue(ScopeMember member)
 {
     return(member == null || member.IsTypeGroup() || member.IsFunctionGroup());
 }
Example #7
0
 protected static bool IsRecursiveContinue(ScopeMember member)
 {
     return member == null || member.IsTypeGroup() || member.IsFunctionGroup();
 }