示例#1
0
        public void InheritFrom(MmdGenericTypeVarScope superScope, InheritanceHandler inheritanceHandler)
        {
            if (superScope == null)
            {
                return;
            }

            foreach (MmdGenericTypeVar superGenericTypeVar in superScope.Values)
            {
                String            name = superGenericTypeVar.Name;
                MmdGenericTypeVar localGenericTypeVar = this.Get(name);

                if (localGenericTypeVar == null)
                {
                    this.Add(name, superGenericTypeVar);
                }
                else
                {
                    localGenericTypeVar.ResolveArgAndBounds(this);

                    if (superGenericTypeVar.IsAssignment() && localGenericTypeVar.IsAssignment() &&
                        !superGenericTypeVar.Arg.Equals(localGenericTypeVar.Arg))
                    {
                        throw new MetaMetadataException("incompatiable assignments to a generic type var: "
                                                        + name);
                    }
                    else if (superGenericTypeVar.IsAssignment() && localGenericTypeVar.IsBound())
                    {
                        throw new MetaMetadataException("generic type already assigned: " + name);
                    }
                    else if (superGenericTypeVar.IsBound() && localGenericTypeVar.IsAssignment())
                    {
                        CheckAssignmentWithBounds(name, localGenericTypeVar, superGenericTypeVar,
                                                  inheritanceHandler);
                    }
                    else
                    {
                        CheckBoundsWithBounds(name, localGenericTypeVar, superGenericTypeVar, inheritanceHandler);
                    }
                }
            }
        }
        public bool IsUsingGenerics(MetaMetadataField field)
        {
            if (field.GenericTypeVars != null && field.GenericTypeVars.Count > 0)
            {
                return(true);
            }
            MmdGenericTypeVarScope gtvScope = (MmdGenericTypeVarScope)scopeStack.Peek().Get(
                GENERIC_TYPE_VAR_SCOPE);

            if (gtvScope == null)
            {
                return(false);
            }
            if (((field.GetMmdType() != null) && gtvScope.ContainsKey(field.GetMmdType())) || field.GetMmdType() == null &&
                ((field.Name != null) && gtvScope.ContainsKey(field.Name)) ||
                ((field.GetMmdExtendsAttribute() != null) && gtvScope.ContainsKey(field.GetMmdExtendsAttribute())))
            {
                return(true);
            }
            return(false);
        }
        public void ResolveArgAndBounds(MmdGenericTypeVarScope genericTypeVarScope)
        {
            if (IsAssignment())
            {
                MmdGenericTypeVar gtv = genericTypeVarScope.Get(arg);
                if (gtv != null)
                {
                    gtv.ResolveArgAndBounds(genericTypeVarScope);

                    if (gtv.IsAssignment())
                    {
                        arg = gtv.arg;
                    }
                    else if (gtv.IsBound())
                    {
                        arg = null;
                        extendsAttribute = gtv.extendsAttribute;
                        // superAttribute = gtv.superAttribute;
                    }
                }
            }
            else if (IsBound())
            {
                MmdGenericTypeVar extendsGtv = genericTypeVarScope.Get(extendsAttribute);
                if (extendsGtv != null)
                {
                    extendsGtv.ResolveArgAndBounds(genericTypeVarScope);
                    extendsAttribute = extendsGtv.arg != null ? extendsGtv.arg : extendsGtv.extendsAttribute;
                }

                // TODO superAttribute
            }
            else
            {
                throw new MetaMetadataException(
                          "wrong meta-metadata generic type var type! must either be an assignment or a bound.");
            }
        }
        public void Push(MetaMetadataField mmField)
        {
            Debug.WriteLine("pushing " + mmField);
            mmStack.Push(mmField);

            // put mmd scope
            MultiAncestorScope <Object> scope = new MultiAncestorScope <Object>();

            if (scopeStack.Count > 0)
            {
                scope.AddAncestor(scopeStack.Peek());
            }
            scopeStack.Push(scope);

            // put generic type var scope
            MmdGenericTypeVarScope existingMmdGenericTypeVarScope = (MmdGenericTypeVarScope)scope.Get(GENERIC_TYPE_VAR_SCOPE);
            MmdGenericTypeVarScope currentMmdGenericTypeVarScope  = mmField.GenericTypeVars;

            if (currentMmdGenericTypeVarScope != null && existingMmdGenericTypeVarScope != null)
            {
                currentMmdGenericTypeVarScope.InheritFrom(existingMmdGenericTypeVarScope, this);
            }
            scope.AddIfValueNotNull(GENERIC_TYPE_VAR_SCOPE, mmField.GenericTypeVars);
        }
 public void SetNestedGenericTypeVars(MmdGenericTypeVarScope nestedGenericTypeVars)
 {
     this.nestedGenericTypeVars = nestedGenericTypeVars;
 }
        public MetaMetadata ResolveMmdName(String mmdName, NameType[] nameType)
        {
            if (mmdName == null)
            {
                return(null);
            }
            Object            resultObj = null;
            MetaMetadata      result    = null;
            MetaMetadataField field     = mmStack.Peek();

            if (nameType != null && nameType.Length > 0)
            {
                nameType[0] = NameType.NONE;
            }

            // step 1: try to resolve the name as a concrete meta-metadata name, using the mmdScope.
            if (field is MetaMetadataNestedField)
            {
                MetaMetadataNestedField nested = (MetaMetadataNestedField)field;
                nested.Scope.TryGetValue(mmdName, out resultObj);
                result = (MetaMetadata)resultObj;
                if (result != null)
                {
                    if (nameType != null && nameType.Length > 0)
                    {
                        nameType[0] = NameType.MMD;
                    }
                }
            }

            // step 2: if step 1 failed, try to use it as a generic type var name
            if (result == null && mmdName.ToUpper().Equals(mmdName))
            {
                List <Object> gtvScopes = scopeStack.Peek().GetAll(GENERIC_TYPE_VAR_SCOPE);
                foreach (MmdGenericTypeVarScope gtvScope_object in gtvScopes)
                {
                    if (!(gtvScope_object is MmdGenericTypeVarScope))
                    {
                        throw new MetaMetadataException("Object is not instance of MmdGenericTypeVarScope");
                    }
                    MmdGenericTypeVarScope gtvScope = gtvScope_object;

                    MmdGenericTypeVar gtv = gtvScope.Get(mmdName);
                    if (gtv != null)
                    {
                        if (gtv.Arg != null)
                        {
                            result = ResolveMmdName(gtv.Arg);
                        }
                        else if (gtv.ExtendsAttribute != null)
                        {
                            result = ResolveMmdName(gtv.ExtendsAttribute);
                        }
                        // TODO superAttribute?
                    }
                }
                if (result != null)
                {
                    if (nameType != null && nameType.Length > 0)
                    {
                        nameType[0] = NameType.GENERIC;
                    }
                }
            }

            return(result);
        }