예제 #1
0
        /// <summary>
        /// Updates our classes dictionary from a type's base classes, updating for both
        /// the inheritance hierachy as well as the order the types appear as bases.
        /// </summary>
        private static void GenerateMroGraph(Dictionary <DynamicType, MroRatingInfo> classes, DynamicType parent, Tuple bases, ref int count)
        {
            MroRatingInfo parentList, innerList;

            if (!classes.TryGetValue(parent, out parentList))
            {
                parentList = classes[parent] = new MroRatingInfo();
            }

            // only set order once - if we see a type multiple times,
            // the earliest one is the most important.
            if (parentList.Order == 0)
            {
                parentList.Order = count++;
            }

            DynamicType prevType = null;

            foreach (DynamicType baseType in bases)
            {
                if (!parentList.Contains(baseType))
                {
                    parentList.Add(baseType);
                }

                if (prevType != null)
                {
                    if (!classes.TryGetValue(prevType, out innerList))
                    {
                        innerList = classes[prevType] = new MroRatingInfo();
                    }

                    if (!innerList.Contains(baseType))
                    {
                        innerList.Add(baseType);
                    }
                }

                prevType = baseType;

                GenerateMroGraph(classes, baseType, baseType.BaseClasses, ref count);
            }
        }
예제 #2
0
        private static void PropagateBases(Dictionary <DynamicType, MroRatingInfo> classes, DynamicType dt)
        {
            MroRatingInfo innerInfo, mroInfo = classes[dt];

            mroInfo.Processing = true;

            // recurse down to the bottom of the tree
            foreach (DynamicType lesser in mroInfo)
            {
                if (classes[lesser].Processing)
                {
                    throw Ops.TypeError("invalid order for base classes: {0} and {1}", dt.__name__, lesser.__name__);
                }

                PropagateBases(classes, lesser);
            }

            // then propagate the bases up the tree as we go.
            int startingCount = mroInfo.Count;

            for (int i = 0; i < startingCount; i++)
            {
                DynamicType lesser = mroInfo[i];

                if (!classes.TryGetValue(lesser, out innerInfo))
                {
                    continue;
                }

                foreach (DynamicType newList in innerInfo)
                {
                    if (!mroInfo.Contains(newList))
                    {
                        mroInfo.Add(newList);
                    }
                }
            }

            mroInfo.Processing = false;
        }