Exemple #1
0
 private ClassHierarchyNode FindGreatestCommonDescendant(ICollection <ClassHierarchyNode> typeNodes)
 {
     V_0 = null;
     V_1 = 0x7fffffff;
     V_2 = typeNodes.GetEnumerator();
     try
     {
         while (V_2.MoveNext())
         {
             V_3 = V_2.get_Current();
             V_4 = ExpressionTypeInferer.GetTypeIndex(V_3.get_NodeType());
             if (V_4 >= V_1)
             {
                 continue;
             }
             V_1 = V_4;
             V_0 = V_3;
         }
     }
     finally
     {
         if (V_2 != null)
         {
             V_2.Dispose();
         }
     }
     return(V_0);
 }
Exemple #2
0
 protected override ClassHierarchyNode FindLowestCommonAncestor(ICollection <ClassHierarchyNode> typeNodes)
 {
     V_0 = null;
     V_1 = -2147483648;
     V_2 = typeNodes.GetEnumerator();
     try
     {
         while (V_2.MoveNext())
         {
             V_3 = V_2.get_Current();
             V_4 = ExpressionTypeInferer.GetTypeIndex(V_3.get_NodeType());
             if (V_4 <= V_1)
             {
                 continue;
             }
             V_1 = V_4;
             V_0 = V_3;
         }
     }
     finally
     {
         if (V_2 != null)
         {
             V_2.Dispose();
         }
     }
     return(V_0);
 }
Exemple #3
0
 private bool IsAssignable(TypeReference toAssign, TypeReference recipient)
 {
     if (!toAssign.get_IsPrimitive() || !recipient.get_IsPrimitive())
     {
         return(true);
     }
     stackVariable6 = ExpressionTypeInferer.GetTypeIndex(toAssign);
     return(stackVariable6 + 1 == ExpressionTypeInferer.GetTypeIndex(recipient));
 }
        /// <summary>
        /// Checks if one primitive type is Directly smaller than the other.
        /// </summary>
        /// <param name="toAssign">The supposed smaller type.</param>
        /// <param name="recipient">The supposed bigger type.</param>
        /// <returns></returns>
        private bool IsAssignable(TypeReference toAssign, TypeReference recipient)
        {
            ///This method handles assignability between primitive types only.
            if (!toAssign.IsPrimitive || !recipient.IsPrimitive)
            {
                return(true);
            }
            int index  = ExpressionTypeInferer.GetTypeIndex(toAssign);
            int index2 = ExpressionTypeInferer.GetTypeIndex(recipient);

            return(index + 1 == index2);
        }
        /// <summary>
        /// As integer values can be ordered depending on their size, the graph algorithm used in TypeInferer isn't needed here.
        /// Instead, we might use the indexes to determine which is the smallest type big enough to contain every type provided in
        /// <paramref name="typeNodes"/>.
        /// </summary>
        /// <param name="typeNodes">The list of types.</param>
        /// <returns>The common parent node.</returns>
        protected override ClassHierarchyNode FindLowestCommonAncestor(ICollection <ClassHierarchyNode> typeNodes)
        {
            ClassHierarchyNode result = null;
            int maxIndex = Int32.MinValue;

            foreach (ClassHierarchyNode node in typeNodes)
            {
                int currentIndex = ExpressionTypeInferer.GetTypeIndex(node.NodeType);
                if (currentIndex > maxIndex)
                {
                    maxIndex = currentIndex;
                    result   = node;
                }
            }
            return(result);
        }
 internal static TypeReference GetContainingType(TypeDefinition leftType, TypeDefinition rightType)
 {
     if ((object)leftType == (object)rightType)
     {
         return(rightType);
     }
     if (leftType == null)
     {
         return(rightType);
     }
     if (rightType == null)
     {
         return(leftType);
     }
     if (ExpressionTypeInferer.GetTypeIndex(leftType) > ExpressionTypeInferer.GetTypeIndex(rightType))
     {
         return(leftType);
     }
     return(rightType);
 }
        /// <summary>
        /// Finds the smallest type from the given types.
        /// </summary>
        /// <param name="typeNodes">The list of type nodes.</param>
        /// <returns>Returns the smallest type.</returns>
        private ClassHierarchyNode FindGreatestCommonDescendant(ICollection <ClassHierarchyNode> typeNodes)
        {
            ClassHierarchyNode result = null;
            int minIndex = Int32.MaxValue;

            foreach (ClassHierarchyNode node in typeNodes)
            {
                int currentIndex = ExpressionTypeInferer.GetTypeIndex(node.NodeType);
                if (currentIndex < minIndex)
                {
                    minIndex = currentIndex;
                    result   = node;
                }
            }
            return(result);

            //Stack<ClassHierarchyNode> possibleGcdOrdered = new Stack<ClassHierarchyNode>();
            //HashSet<ClassHierarchyNode> possibleGcdSearchable = new HashSet<ClassHierarchyNode>();
            //foreach (ClassHierarchyNode node in typeNodes)
            //{
            //    if (possibleGcdOrdered.Count == 0) //first pass
            //    {
            //        ClassHierarchyNode currentSubtype = node;
            //        while (currentSubtype != null)
            //        {
            //            possibleGcdOrdered.Push(currentSubtype);
            //            possibleGcdSearchable.Add(currentSubtype);
            //            ClassHierarchyNode nextSubtype = null;
            //            foreach (ClassHierarchyNode x in currentSubtype.SubTypes)
            //            {
            //                if (x.IsHardNode)
            //                {
            //                    nextSubtype = x;
            //                    break;
            //                }
            //            }
            //            currentSubtype = nextSubtype;
            //        }
            //    }
            //    else
            //    {
            //        ClassHierarchyNode firstSubtype = node;
            //        while (!possibleGcdSearchable.Contains(firstSubtype))
            //        {
            //            //should not reach null, as Int32 is the ultimate GCD
            //            ClassHierarchyNode nextSubtype = null;
            //            foreach (ClassHierarchyNode x in firstSubtype.SubTypes)
            //            {
            //                if (x.IsHardNode)
            //                {
            //                    nextSubtype = x;
            //                    break;
            //                }
            //            }
            //            firstSubtype = nextSubtype;
            //        }

            //        while (possibleGcdOrdered.Peek() != firstSubtype)
            //        {
            //            ClassHierarchyNode removed = possibleGcdOrdered.Pop();
            //            possibleGcdSearchable.Remove(removed);
            //        }
            //    }
            //}
            //return possibleGcdOrdered.Peek();
        }