Esempio n. 1
0
        int CountComparisons(CompNamed named)
        {
            int rv = 1;

            if (named is ICompMemberContainer)
            {
                ICompMemberContainer container = (ICompMemberContainer)named;
                rv += CountComparisons(container.GetInterfaces());
                rv += CountComparisons(container.GetConstructors());
                rv += CountComparisons(container.GetMethods());
                rv += CountComparisons(container.GetProperties());
                rv += CountComparisons(container.GetFields());
            }
            if (named is ICompTypeContainer)
            {
                ICompTypeContainer container = (ICompTypeContainer)named;
                rv += CountComparisons(container.GetNestedInterfaces());
                rv += CountComparisons(container.GetNestedClasses());
                rv += CountComparisons(container.GetNestedStructs());
                rv += CountComparisons(container.GetNestedEnums());
                rv += CountComparisons(container.GetNestedDelegates());
            }
            if (named is ICompAttributeContainer)
            {
                rv += CountComparisons(((ICompAttributeContainer)named).GetAttributes());
            }
            return(rv);
        }
Esempio n. 2
0
        void AddExtra(ComparisonNode parent, CompNamed item)
        {
            ComparisonNode node = item.GetComparisonNode();

            parent.AddChild(node);
            node.Status = ComparisonStatus.Extra;

            profile_documentation.AddError(String.Format("Extra contents \"{0}\" in \"{1}\"", item.DisplayName, parent.Name));

            if (item is ICompTypeContainer)
            {
                ICompTypeContainer c = (ICompTypeContainer)item;
                foreach (CompNamed ifc in c.GetNestedInterfaces())
                {
                    AddExtra(node, ifc);
                }
                foreach (CompNamed cls in c.GetNestedClasses())
                {
                    AddExtra(node, cls);
                }
                foreach (CompNamed cls in c.GetNestedStructs())
                {
                    AddExtra(node, cls);
                }
                foreach (CompNamed en in c.GetNestedEnums())
                {
                    AddExtra(node, en);
                }
            }
        }
        void AddExtra(ComparisonNode parent, CompNamed item)
        {
            ComparisonNode node = item.GetComparisonNode();

            parent.AddChild(node);
            node.Status = ComparisonStatus.Extra;

            if (item is ICompTypeContainer)
            {
                ICompTypeContainer c = (ICompTypeContainer)item;
                foreach (CompNamed ifc in c.GetNestedInterfaces())
                {
                    AddExtra(node, ifc);
                }
                foreach (CompNamed cls in c.GetNestedClasses())
                {
                    AddExtra(node, cls);
                }
                foreach (CompNamed cls in c.GetNestedStructs())
                {
                    AddExtra(node, cls);
                }
                foreach (CompNamed en in c.GetNestedEnums())
                {
                    AddExtra(node, en);
                }
            }
        }
        public static int Compare(CompNamed x, CompNamed y)
        {
            var x_g = x as CompMethod;
            var y_g = y as CompMethod;

            if (x_g == null || y_g == null)
            {
                return(string.Compare(x.Name, y.Name));
            }

            var x_tp = x_g.GetTypeParameters();

            if (x_tp != null && x_tp.Count == 0)
            {
                x_tp = null;
            }

            var y_tp = y_g.GetTypeParameters();

            if (y_tp != null && y_tp.Count == 0)
            {
                y_tp = null;
            }

            if (x_tp == null && y_tp != null)
            {
                return(-1);
            }

            if (x_tp != null && y_tp == null)
            {
                return(1);
            }

            if (x_tp != null && y_tp != null)
            {
                var res = x_tp.Count.CompareTo(y_tp.Count);
                if (res != 0)
                {
                    return(res);
                }
            }

            return(string.Compare(x.Name, y.Name));
        }
Esempio n. 5
0
		void AddMissing (ComparisonNode parent, CompNamed item)
		{
			ComparisonNode node = item.GetComparisonNode ();
			parent.AddChild (node);
			node.Status = ComparisonStatus.Missing;

			comparisons_performed ++;

			if (item is ICompHasBaseType) {
				string baseTypeName = ((ICompHasBaseType)item).GetBaseType();
				if (!string.IsNullOrEmpty (baseTypeName)) {
					ComparisonNode baseTypeNode = new ComparisonNode (CompType.Class,
											  string.Format ("BaseType: {0}",
													 baseTypeName),
											  baseTypeName);
					baseTypeNode.Status = ComparisonStatus.Missing;
					node.AddChild (baseTypeNode);
				}
			}

			if (item is ICompTypeContainer) {
				ICompTypeContainer c = (ICompTypeContainer)item;

				foreach (CompNamed ifc in c.GetNestedInterfaces ())
					AddMissing (node, ifc);
				foreach (CompNamed cls in c.GetNestedClasses())
					AddMissing (node, cls);
				foreach (CompNamed cls in c.GetNestedStructs())
					AddMissing (node, cls);
				foreach (CompNamed en in c.GetNestedEnums())
					AddMissing (node, en);
			}
			if (item is ICompMemberContainer) {
				ICompMemberContainer c = (ICompMemberContainer)item;
				foreach (CompNamed ifc in c.GetInterfaces())
					AddMissing (node, ifc);
				foreach (CompNamed m in c.GetConstructors())
					AddMissing (node, m);
				foreach (CompNamed m in c.GetMethods())
					AddMissing (node, m);
				foreach (CompNamed p in c.GetProperties())
					AddMissing (node, p);
				foreach (CompNamed f in c.GetFields())
					AddMissing (node, f);
				foreach (CompNamed e in c.GetEvents())
					AddMissing (node, e);
			}
			if (item is ICompAttributeContainer) {
				ICompAttributeContainer c = (ICompAttributeContainer)item;
				foreach (CompNamed attr in c.GetAttributes())
					AddMissing (node, attr);
			}
		}
Esempio n. 6
0
		void AddExtra (ComparisonNode parent, CompNamed item)
		{
			ComparisonNode node = item.GetComparisonNode ();
			parent.AddChild (node);
			node.Status = ComparisonStatus.Extra;

			if (item is ICompTypeContainer) {
				ICompTypeContainer c = (ICompTypeContainer)item;
				foreach (CompNamed ifc in c.GetNestedInterfaces ())
					AddExtra (node, ifc);
				foreach (CompNamed cls in c.GetNestedClasses())
					AddExtra (node, cls);
				foreach (CompNamed cls in c.GetNestedStructs())
					AddExtra (node, cls);
				foreach (CompNamed en in c.GetNestedEnums())
					AddExtra (node, en);
			}
		}
Esempio n. 7
0
		int CountComparisons (CompNamed named)
		{
			int rv = 1;
			if (named is ICompMemberContainer) {
				ICompMemberContainer container = (ICompMemberContainer)named;
				rv += CountComparisons (container.GetInterfaces());
				rv += CountComparisons (container.GetConstructors());
				rv += CountComparisons (container.GetMethods());
				rv += CountComparisons (container.GetProperties());
				rv += CountComparisons (container.GetFields());
			}
			if (named is ICompTypeContainer) {
				ICompTypeContainer container = (ICompTypeContainer)named;
				rv += CountComparisons (container.GetNestedInterfaces());
				rv += CountComparisons (container.GetNestedClasses());
				rv += CountComparisons (container.GetNestedStructs());
				rv += CountComparisons (container.GetNestedEnums());
				rv += CountComparisons (container.GetNestedDelegates());
			}
			if (named is ICompAttributeContainer) {
				rv += CountComparisons (((ICompAttributeContainer)named).GetAttributes());
			}
			return rv;
		}
Esempio n. 8
0
        void AddExtra(ComparisonNode parent, CompNamed item)
        {
            ComparisonNode node = item.GetComparisonNode ();
            parent.AddChild (node);
            node.Status = ComparisonStatus.Extra;

            profile_documentation.AddError (String.Format ("Extra contents \"{0}\" in \"{1}\"", item.DisplayName, parent.Name));

            if (item is ICompTypeContainer) {
                ICompTypeContainer c = (ICompTypeContainer)item;
                foreach (CompNamed ifc in c.GetNestedInterfaces ())
                    AddExtra (node, ifc);
                foreach (CompNamed cls in c.GetNestedClasses())
                    AddExtra (node, cls);
                foreach (CompNamed cls in c.GetNestedStructs())
                    AddExtra (node, cls);
                foreach (CompNamed en in c.GetNestedEnums())
                    AddExtra (node, en);
            }
        }
Esempio n. 9
0
		public static int Compare (CompNamed x, CompNamed y)
		{
			int res = string.Compare (x.Name, y.Name);
			if (res != 0)
				return res;

			var x_g = x as CompMethod;
			var y_g = y as CompMethod;
			if (x_g == null || y_g == null)
				return res;

			var x_tp = x_g.GetTypeParameters ();
			var y_tp = y_g.GetTypeParameters ();
			if (x_tp == null && y_tp != null)
				return -1;

			if (x_tp != null && y_tp == null)
				return 1;

			if (x_tp == null && y_tp == null)
				return res;

			return x_tp.Count.CompareTo (y_tp.Count);
		}
Esempio n. 10
0
        void AddMissing(ComparisonNode parent, CompNamed item)
        {
            ComparisonNode node = item.GetComparisonNode();

            parent.AddChild(node);
            node.Status = ComparisonStatus.Missing;

            comparisons_performed++;

            if (item is ICompHasBaseType)
            {
                string baseTypeName = ((ICompHasBaseType)item).GetBaseType();
                if (!string.IsNullOrEmpty(baseTypeName))
                {
                    ComparisonNode baseTypeNode = new ComparisonNode(CompType.Class,
                                                                     string.Format("BaseType: {0}",
                                                                                   baseTypeName),
                                                                     baseTypeName);
                    baseTypeNode.Status = ComparisonStatus.Missing;
                    node.AddChild(baseTypeNode);
                }
            }

            if (item is ICompTypeContainer)
            {
                ICompTypeContainer c = (ICompTypeContainer)item;

                foreach (CompNamed ifc in c.GetNestedInterfaces())
                {
                    AddMissing(node, ifc);
                }
                foreach (CompNamed cls in c.GetNestedClasses())
                {
                    AddMissing(node, cls);
                }
                foreach (CompNamed cls in c.GetNestedStructs())
                {
                    AddMissing(node, cls);
                }
                foreach (CompNamed en in c.GetNestedEnums())
                {
                    AddMissing(node, en);
                }
            }
            if (item is ICompMemberContainer)
            {
                ICompMemberContainer c = (ICompMemberContainer)item;
                foreach (CompNamed ifc in c.GetInterfaces())
                {
                    AddMissing(node, ifc);
                }
                foreach (CompNamed m in c.GetConstructors())
                {
                    AddMissing(node, m);
                }
                foreach (CompNamed m in c.GetMethods())
                {
                    AddMissing(node, m);
                }
                foreach (CompNamed p in c.GetProperties())
                {
                    AddMissing(node, p);
                }
                foreach (CompNamed f in c.GetFields())
                {
                    AddMissing(node, f);
                }
                foreach (CompNamed e in c.GetEvents())
                {
                    AddMissing(node, e);
                }
            }
            if (item is ICompAttributeContainer)
            {
                ICompAttributeContainer c = (ICompAttributeContainer)item;
                foreach (CompNamed attr in c.GetAttributes())
                {
                    AddMissing(node, attr);
                }
            }
        }
        void CompareMemberLists(ComparisonNode parent,
                                List <CompNamed> reference_list,
                                List <CompNamed> target_list,
                                bool isSealed)
        {
            int m = 0, a = 0;

            reference_list.Sort(CompNamed.Compare);
            target_list.Sort(CompNamed.Compare);

            while (m < reference_list.Count || a < target_list.Count)
            {
                if (m == reference_list.Count)
                {
                    AddExtra(parent, target_list[a]);
                    a++;
                    continue;
                }
                else if (a == target_list.Count)
                {
                    AddMissing(parent, reference_list[m]);
                    m++;
                    continue;
                }

                int c = CompNamed.Compare(reference_list[m], target_list[a]);
                comparisons_performed++;

                if (c == 0)
                {
                    /* the names match, further investigation is required */
//                  Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name);
                    ComparisonNode comparison = target_list[a].GetComparisonNode();
                    parent.AddChild(comparison);

                    if (reference_list[m] is CompMember && target_list[a] is CompMember)
                    {
                        string reference_type = ((CompMember)reference_list[m]).GetMemberType();
                        string target_type    = ((CompMember)target_list[a]).GetMemberType();

                        if (reference_type != target_type)
                        {
                            comparison.AddError(String.Format("reference type is <i>{0}</i>, target type is <i>{1}</i>",
                                                              reference_type, target_type));
                        }

                        string reference_access = ((CompMember)reference_list[m]).GetMemberAccess();
                        string target_access    = ((CompMember)target_list[a]).GetMemberAccess();
                        if (reference_access != target_access)
                        {
                            // Try to give some hints to the developer, best we can do with
                            // strings.
                            string extra_msg = "";
                            if (reference_access.IndexOf("Private, Final, Virtual, HideBySig") != -1 &&
                                target_access.IndexOf("Public, HideBySig") != -1)
                            {
                                extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't";
                            }

                            comparison.AddError(String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}",
                                                              reference_access, target_access, extra_msg));
                            comparison.Status = ComparisonStatus.Error;
                        }
                    }

                    var r_method = reference_list[m] as CompMethod;
                    if (r_method != null)
                    {
                        var t_method = (CompMethod)target_list[a];
                        if (t_method.ThrowsNotImplementedException() && !r_method.ThrowsNotImplementedException())
                        {
                            comparison.ThrowsNIE = true;
                        }

                        CompareTypeParameters(comparison, r_method, t_method);
                        CompareParameters(comparison, r_method, t_method);
                    }
                    else if (reference_list[m] is CompProperty)
                    {
                        var m1 = ((CompProperty)reference_list[m]).GetMethods();
                        var m2 = ((CompProperty)target_list[a]).GetMethods();
                        if (m1.Count != m2.Count)
                        {
                            comparison.AddError(String.Format("Expected {0} accessors but found {1}", m1.Count, m2.Count));
                            comparison.Status = ComparisonStatus.Error;
                        }
                        else
                        {
                            for (int i = 0; i < m1.Count; ++i)
                            {
                                string reference_access = ((CompMember)m1[i]).GetMemberAccess();
                                string target_access    = ((CompMember)m2[i]).GetMemberAccess();
                                if (reference_access != target_access)
                                {
                                    // Try to give some hints to the developer, best we can do with
                                    // strings.
                                    string extra_msg = "";
                                    if (reference_access.IndexOf("Private, Final, Virtual, HideBySig") != -1 &&
                                        target_access.IndexOf("Public, HideBySig") != -1)
                                    {
                                        extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't";
                                    }

                                    comparison.AddError(String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}",
                                                                      reference_access, target_access, extra_msg));
                                    comparison.Status = ComparisonStatus.Error;
                                    break;
                                }
                            }

                            if (m1[0].Name[0] == m2[0].Name[0])
                            {
                                CompareAttributes(comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[0]);
                                if (m1.Count > 1)
                                {
                                    CompareAttributes(comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[1]);
                                }
                            }
                            else
                            {
                                CompareAttributes(comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[1]);
                                if (m1.Count > 1)
                                {
                                    CompareAttributes(comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[0]);
                                }
                            }
                        }

                        // Compare indexer parameters
                        if (m1.Count == m2.Count)
                        {
                            CompareParameters(comparison, (ICompParameters)m1[0], (ICompParameters)m2[0]);
                        }
                    }

                    if (reference_list[m] is CompField)
                    {
                        var v_ref = ((CompField)reference_list[m]).GetLiteralValue();
                        var v_tar = ((CompField)target_list[a]).GetLiteralValue();
                        if (v_ref != v_tar)
                        {
                            comparison.AddError(String.Format("Expected field value {0} but found value {1}", v_ref, v_tar));
                            comparison.Status = ComparisonStatus.Error;
                        }
                    }

                    if (reference_list[m] is ICompAttributeContainer)
                    {
                        //Console.WriteLine ("Comparing attributes for {0}", reference_list[m].Name);
                        CompareAttributes(comparison,
                                          (ICompAttributeContainer)reference_list[m],
                                          (ICompAttributeContainer)target_list[a]);
                    }

                    if (reference_list[m] is ICompMemberContainer)
                    {
                        CompareMembers(comparison,
                                       (ICompMemberContainer)reference_list[m],
                                       (ICompMemberContainer)target_list[a]);
                    }

                    //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]);
                    m++;
                    a++;
                }
                else if (c < 0)
                {
                    if (isSealed && reference_list[m].Name.Contains("~"))
                    {
                        // Ignore finalizer differences in sealed classes
                    }
                    else
                    {
                        /* reference name is before target name, reference name is missing from target */
                        AddMissing(parent, reference_list[m]);
                    }

                    m++;
                }
                else
                {
                    if (isSealed && target_list[a].Name.Contains("~"))
                    {
                        // Ignore finalizer differences in sealed classes
                    }
                    else
                    {
                        /* reference name is after target name, target name is extra */
                        AddExtra(parent, target_list[a]);
                    }

                    a++;
                }
            }
        }
        void CompareAttributes(ComparisonNode parent,
                               ICompAttributeContainer reference_container, ICompAttributeContainer target_container)
        {
            int m = 0, a = 0;

            List <CompNamed> reference_attrs = reference_container.GetAttributes();
            List <CompNamed> target_attrs = target_container.GetAttributes();

            Comparison <CompNamed> comp = (x, y) => {
                var r = CompNamed.Compare(x, y);
                if (r != 0)
                {
                    return(r);
                }

                var xa = ((CompAttribute)x).Properties.Values.ToList();
                var ya = ((CompAttribute)y).Properties.Values.ToList();

                for (int i = 0; i < Math.Min(xa.Count, ya.Count); ++i)
                {
                    r = xa[i].CompareTo(ya[i]);
                    if (r != 0)
                    {
                        return(r);
                    }
                }

                return(0);
            };

            reference_attrs.Sort(comp);
            target_attrs.Sort(comp);

            while (m < reference_attrs.Count || a < target_attrs.Count)
            {
                if (m == reference_attrs.Count)
                {
                    switch (target_attrs[a].Name)
                    {
                    case "System.Diagnostics.DebuggerDisplayAttribute":
                    case "System.Runtime.CompilerServices.AsyncStateMachineAttribute":
                    case "System.Runtime.CompilerServices.IteratorStateMachineAttribute":
                    case "System.Diagnostics.DebuggerBrowsableAttribute":
                        // Ignore extra attributes in Mono source code
                        break;

                    default:
                        AddExtra(parent, target_attrs[a]);
                        break;
                    }

                    a++;
                    continue;
                }
                else if (a == target_attrs.Count)
                {
                    AddMissing(parent, reference_attrs[m]);
                    m++;
                    continue;
                }

                int c = String.Compare(reference_attrs[m].Name, target_attrs[a].Name);
                comparisons_performed++;

                if (c == 0)
                {
                    /* the names match, further investigation is required */
                    ComparisonNode comparison = target_attrs[a].GetComparisonNode();
                    parent.AddChild(comparison);
                    CompareAttributeArguments(comparison, (CompAttribute)reference_attrs[m], (CompAttribute)target_attrs[a]);
                    m++;
                    a++;
                }
                else if (c < 0)
                {
                    /* reference name is before target name, reference name is missing from target */
                    AddMissing(parent, reference_attrs[m]);
                    m++;
                }
                else
                {
                    /* reference name is after target name, target name is extra */
                    AddExtra(parent, target_attrs[a]);
                    a++;
                }
            }
        }
Esempio n. 13
0
 public static int Compare(CompNamed x, CompNamed y)
 {
     return(String.Compare(x.Name, y.Name));
 }
Esempio n. 14
0
 public static int Compare(CompNamed x, CompNamed y)
 {
     return String.Compare (x.Name, y.Name);
 }