Author: toshok
Date: 2008-01-02 20:14:34 -0500 (Wed, 02 Jan 2008)
New Revision: 92143
Modified:
trunk/mono-tools/gui-compare/CecilMetadata.cs
trunk/mono-tools/gui-compare/ChangeLog
trunk/mono-tools/gui-compare/CompareContext.cs
trunk/mono-tools/gui-compare/Comparison.cs
trunk/mono-tools/gui-compare/MasterMetadata.cs
trunk/mono-tools/gui-compare/Masterinfo.cs
trunk/mono-tools/gui-compare/Metadata.cs
Log:
* Metadata.cs: make the class, interface, delegate, and enum classes
implement ICompHasBaseType, and add DisplayName to CompNamed, which
we'll use instead of Name to populate the tree.
* CecilMetadata.cs: Add type prettification to set the DisplayName on
the comparison nodes (show the actual operator, type name
replacement for system types, etc). Also, implement the
GetBaseType stuff.
* CompareContext.cs: compare base types. use ComparisonNode.AddError
* MasterMetadata.cs: implement all the GetBaseType methods.
* Masterinfo.cs: remove tons of stuff from corcompare that we no longer
need.
* Comparison.cs: add ComparisonNode.AddError which sets the status and
adds the message.
Modified: trunk/mono-tools/gui-compare/CecilMetadata.cs
===================================================================
--- trunk/mono-tools/gui-compare/CecilMetadata.cs 2008-01-03 01:11:42 UTC
(rev 92142)
+++ trunk/mono-tools/gui-compare/CecilMetadata.cs 2008-01-03 01:14:34 UTC
(rev 92143)
@@ -10,6 +10,51 @@
namespace GuiCompare {
static class CecilUtils {
+ public static string PrettyType (string type)
+ {
+ /* handle suffixes first, recursively */
+ if (type.EndsWith ("[]"))
+ return String.Concat (PrettyType
(type.Substring (0, type.Length - 2)), "[]");
+ else if (type.EndsWith ("*"))
+ return String.Concat (PrettyType
(type.Substring (0, type.Length - 1)), "*");
+ else if (type.EndsWith ("&"))
+ return String.Concat (PrettyType
(type.Substring (0, type.Length - 1)), "&");
+
+ /* handle the system types we know about */
+ switch (type) {
+ case "System.Boolean": return "bool";
+ case "System.Byte": return "byte";
+ case "System.Char": return "char";
+ case "System.Decimal": return "decimal";
+ case "System.Double": return "double";
+ case "System.Int16": return "short";
+ case "System.Int32": return "int";
+ case "System.Int64": return "long";
+ case "System.Object": return "object";
+ case "System.SByte": return "sbyte";
+ case "System.Single": return "float";
+ case "System.String": return "string";
+ case "System.UInt16": return "ushort";
+ case "System.UInt32": return "uint";
+ case "System.UInt64": return "ulong";
+ case "System.Void": return "void";
+ }
+
+ /* for other types, just return the type name */
+ return type.Substring (type.LastIndexOf ('.')+1);
+ }
+
+ // the corcompare xml output uses a different formatting than
Cecil.
+ // Cecil uses / for nested classes, ala:
+ // Namespace.Class/NestedClass
+ // while corcompare uses:
+ // Namespace.Class+NestedClass
+ // also, generic methods are done differently as well.
+ // cecil: Foo<T>
+ // corcompare: Foo[T]
+ //
+ // so let's just convert everything to corcompare's way of
thinking for comparisons.
+ //
public static string FormatTypeLikeCorCompare (string type)
{
string rv = type.Replace ('/', '+');
@@ -186,8 +231,7 @@
public CecilAssembly (string path)
: base (Path.GetFileName (path))
{
- Dictionary<string, Dictionary <string, TypeDefinition>>
namespaces
- = new Dictionary<string, Dictionary <string,
TypeDefinition>> ();
+ Dictionary<string, Dictionary <string, TypeDefinition>>
namespaces = new Dictionary<string, Dictionary <string, TypeDefinition>> ();
AssemblyDefinition assembly =
AssemblyFactory.GetAssembly(path);
@@ -303,6 +347,8 @@
public CecilInterface (TypeDefinition type_def)
: base (CecilUtils.FormatTypeLikeCorCompare
(type_def.Name))
{
+ this.type_def = type_def;
+
interfaces = new List<CompNamed>();
constructors = new List<CompNamed>();
methods = new List<CompNamed>();
@@ -334,6 +380,11 @@
attributes = new List<CompNamed>();
}
+ public override string GetBaseType ()
+ {
+ return (type_def == null || type_def.BaseType == null)
? null : CecilUtils.FormatTypeLikeCorCompare (type_def.BaseType.FullName);
+ }
+
public override List<CompNamed> GetInterfaces ()
{
return interfaces;
@@ -376,6 +427,7 @@
List<CompNamed> fields;
List<CompNamed> events;
List<CompNamed> attributes;
+ TypeDefinition type_def;
}
public class CecilDelegate : CompDelegate {
@@ -385,6 +437,11 @@
this.type_def = type_def;
}
+ public override string GetBaseType ()
+ {
+ return type_def.BaseType == null ? null :
CecilUtils.FormatTypeLikeCorCompare (type_def.BaseType.FullName);
+ }
+
TypeDefinition type_def;
}
@@ -407,6 +464,11 @@
attributes = CecilUtils.GetCustomAttributes (type_def,
todos);
}
+ public override string GetBaseType ()
+ {
+ return type_def.BaseType == null ? null :
CecilUtils.FormatTypeLikeCorCompare (type_def.BaseType.FullName);
+ }
+
public override List<CompNamed> GetFields()
{
return fields;
@@ -459,6 +521,11 @@
attributes = CecilUtils.GetCustomAttributes (type_def,
todos);
}
+ public override string GetBaseType ()
+ {
+ return type_def.BaseType == null ? null :
CecilUtils.FormatTypeLikeCorCompare (type_def.BaseType.FullName);
+ }
+
public override List<CompNamed> GetInterfaces ()
{
return interfaces;
@@ -570,10 +637,11 @@
public class CecilMethod : CompMethod {
public CecilMethod (MethodDefinition method_def)
- : base (MasterinfoFormattedName (method_def))
+ : base (FormatName (method_def, false))
{
this.method_def = method_def;
this.attributes = CecilUtils.GetCustomAttributes
(method_def, todos);
+ DisplayName = FormatName (method_def, true);
}
public override string GetMemberType ()
@@ -601,13 +669,49 @@
return attributes;
}
- static string MasterinfoFormattedName (MethodDefinition
method_def)
+ void SetDisplayName ()
{
+
+ }
+
+ static string FormatName (MethodDefinition method_def, bool
beautify)
+ {
StringBuilder sb = new StringBuilder ();
if (!method_def.IsConstructor)
- sb.Append (CecilUtils.FormatTypeLikeCorCompare
(method_def.ReturnType.ReturnType.FullName));
+ sb.Append (beautify
+ ? CecilUtils.PrettyType
(method_def.ReturnType.ReturnType.FullName)
+ :
CecilUtils.FormatTypeLikeCorCompare
(method_def.ReturnType.ReturnType.FullName));
sb.Append (" ");
- sb.Append (method_def.Name);
+ if (method_def.IsSpecialName && beautify) {
+ if (method_def.Name.StartsWith ("op_")) {
+ switch (method_def.Name) {
+ case "op_Explicit": sb.Append
("operator explicit"); break;
+ case "op_Implicit": sb.Append
("operator implicit"); break;
+ case "op_Equality": sb.Append
("operator =="); break;
+ case "op_Inequality": sb.Append
("operator !="); break;
+ case "op_Addition": sb.Append
("operator +"); break;
+ case "op_Subtraction": sb.Append
("operator -"); break;
+ case "op_Division": sb.Append
("operator /"); break;
+ case "op_Multiply": sb.Append
("operator *"); break;
+ case "op_Modulus": sb.Append ("operator
%"); break;
+ case "op_GreaterThan": sb.Append
("operator >"); break;
+ case "op_GreaterThanOrEqual": sb.Append
("operator >="); break;
+ case "op_LessThan": sb.Append
("operator <"); break;
+ case "op_LessThanOrEqual": sb.Append
("operator <="); break;
+ case "op_UnaryNegation": sb.Append
("operator -"); break;
+ case "op_UnaryPlus": sb.Append
("operator +"); break;
+ case "op_Decrement": sb.Append
("operator --"); break;
+ case "op_Increment": sb.Append
("operator ++"); break;
+ default: Console.WriteLine ("unhandled
operator named {0}", method_def.Name); sb.Append (method_def.Name); break;
+ }
+ }
+ else {
+ sb.Append (method_def.Name);
+ }
+ }
+ else {
+ sb.Append (method_def.Name);
+ }
if (method_def.GenericParameters.Count > 0) {
sb.Append ("<");
bool first_gp = true;
@@ -629,7 +733,13 @@
sb.Append ("in ");
else if (p.IsOut)
sb.Append ("out ");
- sb.Append (CecilUtils.FormatTypeLikeCorCompare
(p.ParameterType.FullName));
+ sb.Append (beautify
+ ? CecilUtils.PrettyType
(p.ParameterType.FullName)
+ :
CecilUtils.FormatTypeLikeCorCompare (p.ParameterType.FullName));
+ if (beautify) {
+ sb.Append (" ");
+ sb.Append (p.Name);
+ }
}
sb.Append (')');
Modified: trunk/mono-tools/gui-compare/ChangeLog
===================================================================
--- trunk/mono-tools/gui-compare/ChangeLog 2008-01-03 01:11:42 UTC (rev
92142)
+++ trunk/mono-tools/gui-compare/ChangeLog 2008-01-03 01:14:34 UTC (rev
92143)
@@ -1,3 +1,18 @@
+2008-01-02 Chris Toshok <[EMAIL PROTECTED]>
+
+ * Metadata.cs: make the class, interface, delegate, and enum classes
+ implement ICompHasBaseType, and add DisplayName to CompNamed, which
+ we'll use instead of Name to populate the tree.
+ * CecilMetadata.cs: Add type prettification to set the DisplayName on
the
+ comparison nodes (show the actual operator, type name replacement for
+ system types, etc). Also, implement the GetBaseType stuff.
+ * CompareContext.cs: compare base types. use ComparisonNode.AddError
+ * MasterMetadata.cs: implement all the GetBaseType methods.
+ * Masterinfo.cs: remove tons of stuff from corcompare that we no longer
+ need.
+ * Comparison.cs: add ComparisonNode.AddError which sets the status and
adds
+ the message.
+
2008-01-02 Miguel de Icaza <[EMAIL PROTECTED]>
* MainWindow.cs: Load defauls from the configuration file
Modified: trunk/mono-tools/gui-compare/CompareContext.cs
===================================================================
--- trunk/mono-tools/gui-compare/CompareContext.cs 2008-01-03 01:11:42 UTC
(rev 92142)
+++ trunk/mono-tools/gui-compare/CompareContext.cs 2008-01-03 01:14:34 UTC
(rev 92143)
@@ -96,6 +96,7 @@
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());
@@ -178,10 +179,20 @@
ProgressOnGuiThread
((double)comparisons_performed / total_comparisons * 100.0, String.Format
("Comparing {0} {1}", master_list[m].Type, master_list[m].Name));
/* the names match, further
investigation is required */
-// Console.WriteLine ("{0} {1} is in both,
doing more comparisons", master_list[m].Type, master_list[m].Name);
ComparisonNode comparison =
assembly_list[a].GetComparisonNode();
parent.AddChild (comparison);
+ // compare base types
+ if (master_list[m] is ICompHasBaseType
&& assembly_list[a] is ICompHasBaseType) {
+ if
(((ICompHasBaseType)master_list[m]).GetBaseType() !=
+
((ICompHasBaseType)assembly_list[a]).GetBaseType()) {
+ comparison.AddError
(String.Format ("reference type {0} has base class of {1}, assembly has base
class of {2}",
+
master_list[m].Name,
+
((ICompHasBaseType)master_list[m]).GetBaseType(),
+
((ICompHasBaseType)assembly_list[a]).GetBaseType()));
+ }
+ }
+
// compare nested types
if (master_list[m] is
ICompTypeContainer && assembly_list[a] is ICompTypeContainer) {
CompareNestedTypes (comparison,
@@ -310,26 +321,24 @@
string assembly_type =
((CompMember)assembly_list[a]).GetMemberType();
if (reference_type !=
assembly_type) {
- comparison.status =
ComparisonStatus.Error;
- comparison.messages.Add
(String.Format ("reference type is <i>{0}</i>, target type is <i>{1}</i>",
-
reference_type, assembly_type));
+ comparison.AddError
(String.Format ("reference type is <i>{0}</i>, target type is <i>{1}</i>",
+
reference_type, assembly_type));
}
string reference_access =
((CompMember)master_list[m]).GetMemberAccess();
string assembly_access =
((CompMember)assembly_list[a]).GetMemberAccess();
if (reference_access !=
assembly_access) {
- comparison.status =
ComparisonStatus.Error;
-
// Try to give some
hints to the developer, best we can do with
// strings.
string extra_msg = "";
if
(reference_access.IndexOf ("Public, Final, Virtual, HideBySig") != -1 &&
-
assembly_access.IndexOf ("Public, HideBySig") != -1){
+
assembly_access.IndexOf ("Public, HideBySig") != -1){
extra_msg =
"\n\t\t<b>Hint:</b> reference uses an implicit interface implementation, target
doesn't";
}
-
- comparison.messages.Add
(String.Format ("reference access is '<i>{0}</i>', target access is
'<i>{1}</i>'{2}",
-
reference_access, assembly_access, extra_msg));
+
+ comparison.AddError
(String.Format ("reference access is '<i>{0}</i>', target access is
'<i>{1}</i>'{2}",
+
reference_access, assembly_access, extra_msg));
+ comparison.status =
ComparisonStatus.Error;
}
}
Modified: trunk/mono-tools/gui-compare/Comparison.cs
===================================================================
--- trunk/mono-tools/gui-compare/Comparison.cs 2008-01-03 01:11:42 UTC (rev
92142)
+++ trunk/mono-tools/gui-compare/Comparison.cs 2008-01-03 01:14:34 UTC (rev
92143)
@@ -45,7 +45,12 @@
}
}
-
+ public void AddError (string msg)
+ {
+ status = ComparisonStatus.Error;
+ messages.Add (msg);
+ }
+
public ComparisonStatus status;
public CompType type;
Modified: trunk/mono-tools/gui-compare/MasterMetadata.cs
===================================================================
--- trunk/mono-tools/gui-compare/MasterMetadata.cs 2008-01-03 01:11:42 UTC
(rev 92142)
+++ trunk/mono-tools/gui-compare/MasterMetadata.cs 2008-01-03 01:14:34 UTC
(rev 92143)
@@ -215,6 +215,8 @@
public MasterInterface (XMLClass xml_cls)
: base (xml_cls.name)
{
+ this.xml_cls = xml_cls;
+
interfaces = new List<CompNamed>();
constructors = new List<CompNamed>();
methods = new List<CompNamed>();
@@ -245,6 +247,11 @@
attributes = new List<CompNamed>();
}
+ public override string GetBaseType()
+ {
+ return xml_cls == null ? null : xml_cls.baseName;
+ }
+
public override List<CompNamed> GetInterfaces ()
{
return interfaces;
@@ -280,6 +287,7 @@
return attributes;
}
+ XMLClass xml_cls;
List<CompNamed> interfaces;
List<CompNamed> constructors;
List<CompNamed> methods;
@@ -296,6 +304,11 @@
xml_cls = cls;
}
+ public override string GetBaseType ()
+ {
+ return xml_cls.baseName;
+ }
+
XMLClass xml_cls;
}
@@ -317,6 +330,11 @@
}
+ public override string GetBaseType()
+ {
+ return xml_cls.baseName;
+ }
+
public override List<CompNamed> GetFields()
{
return fields;
@@ -366,6 +384,11 @@
struct_list);
}
+ public override string GetBaseType ()
+ {
+ return xml_cls.baseName;
+ }
+
public override List<CompNamed> GetInterfaces ()
{
return interfaces;
Modified: trunk/mono-tools/gui-compare/Masterinfo.cs
===================================================================
--- trunk/mono-tools/gui-compare/Masterinfo.cs 2008-01-03 01:11:42 UTC (rev
92142)
+++ trunk/mono-tools/gui-compare/Masterinfo.cs 2008-01-03 01:14:34 UTC (rev
92143)
@@ -179,95 +179,10 @@
attr.Value = value;
node.Attributes.Append (attr);
}
-
- protected void AddExtra (XmlNode node)
- {
- //TODO: count all the subnodes?
- AddAttribute (node, "presence", "extra");
- AddAttribute (node, "ok", "1");
- AddAttribute (node, "ok_total", "1");
- AddAttribute (node, "extra", "1");
- AddAttribute (node, "extra_total", "1");
- }
-
- public void AddCountersAttributes (XmlNode node)
- {
- if (counters.Missing > 0)
- AddAttribute (node, "missing",
counters.Missing.ToString ());
-
- if (counters.Present > 0)
- AddAttribute (node, "present",
counters.Present.ToString ());
-
- if (counters.Extra > 0)
- AddAttribute (node, "extra",
counters.Extra.ToString ());
-
- if (counters.Ok > 0)
- AddAttribute (node, "ok", counters.Ok.ToString
());
-
- if (counters.Total > 0) {
- int percent = (100 * counters.Ok /
counters.Total);
- AddAttribute (node, "complete",
percent.ToString ());
- }
-
- if (counters.Todo > 0)
- AddAttribute (node, "todo",
counters.Todo.ToString ());
-
- if (counters.Warning > 0)
- AddAttribute (node, "warning",
counters.Warning.ToString ());
-
- if (counters.MissingTotal > 0)
- AddAttribute (node, "missing_total",
counters.MissingTotal.ToString ());
-
- if (counters.PresentTotal > 0)
- AddAttribute (node, "present_total",
counters.PresentTotal.ToString ());
-
- if (counters.ExtraTotal > 0)
- AddAttribute (node, "extra_total",
counters.ExtraTotal.ToString ());
-
- if (counters.OkTotal > 0)
- AddAttribute (node, "ok_total",
counters.OkTotal.ToString ());
-
- if (counters.AbsTotal > 0) {
- int percent = (100 * counters.OkTotal /
counters.AbsTotal);
- AddAttribute (node, "complete_total",
percent.ToString ());
- }
-
- if (counters.TodoTotal > 0) {
- AddAttribute (node, "todo_total",
counters.TodoTotal.ToString ());
- //TODO: should be different on error. check
error cases in corcompare.
- AddAttribute (node, "error_total",
counters.Todo.ToString ());
- }
-
- if (counters.WarningTotal > 0)
- AddAttribute (node, "warning_total",
counters.WarningTotal.ToString ());
-
- }
-
- protected void AddWarning (XmlNode parent, string fmt, params
object [] args)
- {
- counters.Warning++;
- haveWarnings = true;
- XmlNode warnings = parent.SelectSingleNode ("warnings");
- if (warnings == null) {
- warnings = document.CreateElement ("warnings",
null);
- parent.AppendChild (warnings);
- }
-
- AddAttribute (parent, "error", "warning");
- XmlNode warning = document.CreateElement ("warning",
null);
- AddAttribute (warning, "text", String.Format (fmt,
args));
- warnings.AppendChild (warning);
- }
-
- public bool HaveWarnings {
- get { return haveWarnings; }
- }
public Counters Counters {
get { return counters; }
}
-
- public abstract void CompareTo (XmlDocument doc, XmlNode
parent, object other);
}
public abstract class XMLNameGroup : XMLData
@@ -304,56 +219,6 @@
{
}
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- this.document = doc;
- if (group == null)
- group = doc.CreateElement (GroupName, null);
-
- Hashtable okeys = null;
- if (other != null && ((XMLNameGroup) other).keys !=
null) {
- okeys = ((XMLNameGroup) other).keys;
- }
-
- XmlNode node = null;
- bool onull = (okeys == null);
- if (keys != null) {
- foreach (DictionaryEntry entry in keys) {
- node = doc.CreateElement (Name, null);
- group.AppendChild (node);
- string key = (string) entry.Key;
- string name = (string) entry.Value;
- AddAttribute (node, "name", name);
-
- if (!onull && HasKey (key, okeys)) {
- CompareToInner (key, node,
(XMLNameGroup) other);
- okeys.Remove (key);
- counters.Present++;
- } else {
- AddAttribute (node, "presence",
"missing");
- counters.Missing++;
- }
- }
- }
-
- if (!onull && okeys.Count != 0) {
- foreach (string value in okeys.Values) {
- node = doc.CreateElement (Name, null);
- AddAttribute (node, "name", (string)
value);
- AddAttribute (node, "presence",
"extra");
- group.AppendChild (node);
- counters.Extra++;
- }
- }
-
- if (group.HasChildNodes)
- parent.AppendChild (group);
- }
-
- protected virtual void CompareToInner (string name, XmlNode
node, XMLNameGroup other)
- {
- }
-
public virtual string GetNodeKey (string name, XmlNode node)
{
return name;
@@ -414,87 +279,6 @@
namespaces = (XMLNamespace []) LoadRecursive
(atts.ChildNodes, typeof (XMLNamespace));
}
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- XMLAssembly assembly = (XMLAssembly) other;
-
- XmlNode childA = doc.CreateElement ("assembly", null);
- AddAttribute (childA, "name", name);
- AddAttribute (childA, "version", version);
- if (name != assembly.name)
- AddWarning (childA, "Assembly names not equal:
{0}, {1}", name, assembly.name);
-
- if (version != assembly.version)
- AddWarning (childA, "Assembly version not
equal: {0}, {1}", version, assembly.version);
-
- parent.AppendChild (childA);
-
- attributes.CompareTo (doc, childA, assembly.attributes);
- counters.AddPartialToPartial (attributes.Counters);
-
- CompareNamespaces (childA, assembly.namespaces);
- if (assembly.attributes != null &&
assembly.attributes.IsTodo) {
- counters.Todo++;
- counters.TodoTotal++;
- counters.ErrorTotal++;
- AddAttribute (childA, "error", "todo");
- if (assembly.attributes.Comment != null)
- AddAttribute (childA, "comment",
assembly.attributes.Comment);
- }
-
- AddCountersAttributes (childA);
- }
-
- void CompareNamespaces (XmlNode parent, XMLNamespace [] other)
- {
- ArrayList newNS = new ArrayList ();
- XmlNode group = document.CreateElement ("namespaces",
null);
- parent.AppendChild (group);
-
- Hashtable oh = CreateHash (other);
- XmlNode node = null;
- int count = (namespaces == null) ? 0 :
namespaces.Length;
- for (int i = 0; i < count; i++) {
- XMLNamespace xns = namespaces [i];
-
- node = document.CreateElement ("namespace",
null);
- newNS.Add (node);
- AddAttribute (node, "name", xns.Name);
-
- int idx = -1;
- if (oh.ContainsKey (xns.Name))
- idx = (int) oh [xns.Name];
- XMLNamespace ons = idx >= 0 ? (XMLNamespace)
other [idx] : null;
- xns.CompareTo (document, node, ons);
- if (idx >= 0)
- other [idx] = null;
- xns.AddCountersAttributes (node);
- counters.Present++;
- counters.PresentTotal++;
- counters.AddPartialToTotal (xns.Counters);
- }
-
- if (other != null) {
- count = other.Length;
- for (int i = 0; i < count; i++) {
- XMLNamespace n = other [i];
- if (n == null)
- continue;
-
- node = document.CreateElement
("namespace", null);
- newNS.Add (node);
- AddAttribute (node, "name", n.Name);
- AddExtra (node);
- counters.ExtraTotal++;
- }
- }
-
- XmlNode [] nodes = (XmlNode []) newNS.ToArray (typeof
(XmlNode));
- Array.Sort (nodes, XmlNodeComparer.Default);
- foreach (XmlNode nn in nodes)
- group.AppendChild (nn);
- }
-
static Hashtable CreateHash (XMLNamespace [] other)
{
Hashtable result = new Hashtable ();
@@ -508,20 +292,6 @@
return result;
}
- public XmlDocument CompareAndGetDocument (XMLAssembly other)
- {
- XmlDocument doc = new XmlDocument ();
- this.document = doc;
- XmlNode parent = doc.CreateElement ("assemblies", null);
- doc.AppendChild (parent);
-
- CompareTo (doc, parent, other);
-
- XmlNode decl = doc.CreateXmlDeclaration ("1.0", null,
null);
- doc.InsertBefore (decl, doc.DocumentElement);
-
- return doc;
- }
}
public class XMLNamespace : XMLData
@@ -550,63 +320,6 @@
types = (XMLClass []) LoadRecursive
(classes.ChildNodes, typeof (XMLClass));
}
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- this.document = doc;
- XMLNamespace nspace = (XMLNamespace) other;
-
- XmlNode childA = doc.CreateElement ("classes", null);
- parent.AppendChild (childA);
-
- CompareTypes (childA, nspace != null ? nspace.types :
new XMLClass [0]);
- }
-
- void CompareTypes (XmlNode parent, XMLClass [] other)
- {
- ArrayList newNodes = new ArrayList ();
- Hashtable oh = CreateHash (other);
- XmlNode node = null;
- int count = (types == null) ? 0 : types.Length;
- for (int i = 0; i < count; i++) {
- XMLClass xclass = types [i];
-
- node = document.CreateElement ("class", null);
- newNodes.Add (node);
- AddAttribute (node, "name", xclass.Name);
- AddAttribute (node, "type", xclass.Type);
-
- int idx = -1;
- if (oh.ContainsKey (xclass.Name))
- idx = (int) oh [xclass.Name];
- xclass.CompareTo (document, node, idx >= 0 ?
other [idx] : new XMLClass ());
- if (idx >= 0)
- other [idx] = null;
- counters.AddPartialToPartial (xclass.Counters);
- }
-
- if (other != null) {
- count = other.Length;
- for (int i = 0; i < count; i++) {
- XMLClass c = other [i];
- if (c == null || IsMonoTODOAttribute
(c.Name))
- continue;
-
- node = document.CreateElement ("class",
null);
- newNodes.Add (node);
- AddAttribute (node, "name", c.Name);
- AddAttribute (node, "type", c.Type);
- AddExtra (node);
- counters.Extra++;
- counters.ExtraTotal++;
- }
- }
-
- XmlNode [] nodes = (XmlNode []) newNodes.ToArray
(typeof (XmlNode));
- Array.Sort (nodes, XmlNodeComparer.Default);
- foreach (XmlNode nn in nodes)
- parent.AppendChild (nn);
- }
-
static Hashtable CreateHash (XMLClass [] other)
{
Hashtable result = new Hashtable ();
@@ -629,7 +342,7 @@
{
public string name;
public string type;
- string baseName;
+ public string baseName;
bool isSealed;
bool isSerializable;
bool isAbstract;
@@ -738,165 +451,6 @@
nested = (XMLClass []) LoadRecursive (child.ChildNodes,
typeof (XMLClass));
}
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- this.document = doc;
- XMLClass oclass = (XMLClass) other;
-
- if (attributes != null || oclass.attributes != null) {
- if (attributes == null)
- attributes = new XMLAttributes ();
-
- attributes.CompareTo (doc, parent,
oclass.attributes);
- counters.AddPartialToPartial
(attributes.Counters);
- if (oclass.attributes != null &&
oclass.attributes.IsTodo) {
- counters.Todo++;
- counters.TodoTotal++;
- counters.ErrorTotal++;
- AddAttribute (parent, "error", "todo");
- if (oclass.attributes.Comment != null)
- AddAttribute (parent,
"comment", oclass.attributes.Comment);
- }
- }
-
- if (type != oclass.type)
- AddWarning (parent, "Class type is wrong: {0}
!= {1}", type, oclass.type);
-
- if (baseName != oclass.baseName)
- AddWarning (parent, "Base class is wrong: {0}
!= {1}", baseName, oclass.baseName);
-
- if (isAbstract != oclass.isAbstract || isSealed !=
oclass.isSealed) {
- if ((isAbstract && isSealed) ||
(oclass.isAbstract && oclass.isSealed))
- AddWarning (parent, "Should {0}be
static", (isAbstract && isSealed) ? "" : "not ");
- else if (isAbstract != oclass.isAbstract)
- AddWarning (parent, "Should {0}be
abstract", isAbstract ? "" : "not ");
- else if (isSealed != oclass.isSealed)
- AddWarning (parent, "Should {0}be
sealed", isSealed ? "" : "not ");
- }
-
- if (isSerializable != oclass.isSerializable)
- AddWarning (parent, "Should {0}be
serializable", isSerializable ? "" : "not ");
-
- if (charSet != oclass.charSet)
- AddWarning (parent, "CharSet is wrong: {0} !=
{1}", charSet, oclass.charSet);
-
- if (layout != oclass.layout)
- AddWarning (parent, "Layout is wrong: {0} !=
{1}", layout, oclass.layout);
-
- if (interfaces != null || oclass.interfaces != null) {
- if (interfaces == null)
- interfaces = new XMLInterfaces ();
-
- interfaces.CompareTo (doc, parent,
oclass.interfaces);
- counters.AddPartialToPartial
(interfaces.Counters);
- }
-
- if (genericConstraints != null ||
oclass.genericConstraints != null) {
- if (genericConstraints == null)
- genericConstraints = new
XMLGenericTypeConstraints ();
-
- genericConstraints.CompareTo (doc, parent,
oclass.genericConstraints);
- counters.AddPartialToPartial
(genericConstraints.Counters);
- }
-
- if (fields != null || oclass.fields != null) {
- if (fields == null)
- fields = new XMLFields ();
-
- fields.CompareTo (doc, parent, oclass.fields);
- counters.AddPartialToPartial (fields.Counters);
- }
-
- if (constructors != null || oclass.constructors !=
null) {
- if (constructors == null)
- constructors = new XMLConstructors ();
-
- constructors.CompareTo (doc, parent,
oclass.constructors);
- counters.AddPartialToPartial
(constructors.Counters);
- }
-
- if (properties != null || oclass.properties != null) {
- if (properties == null)
- properties = new XMLProperties ();
-
- properties.CompareTo (doc, parent,
oclass.properties);
- counters.AddPartialToPartial
(properties.Counters);
- }
-
- if (events != null || oclass.events != null) {
- if (events == null)
- events = new XMLEvents ();
-
- events.CompareTo (doc, parent, oclass.events);
- counters.AddPartialToPartial (events.Counters);
- }
-
- if (methods != null || oclass.methods != null) {
- if (methods == null)
- methods = new XMLMethods ();
-
- methods.CompareTo (doc, parent, oclass.methods);
- counters.AddPartialToPartial (methods.Counters);
- }
-
- if (nested != null || oclass.nested != null) {
- XmlNode n = doc.CreateElement ("classes", null);
- parent.AppendChild (n);
- CompareTypes (n, oclass.nested);
- }
-
- AddCountersAttributes (parent);
- }
-
- void CompareTypes (XmlNode parent, XMLClass [] other)
- {
- ArrayList newNodes = new ArrayList ();
- Hashtable oh = CreateHash (other);
- XmlNode node = null;
- int count = (nested == null) ? 0 : nested.Length;
- for (int i = 0; i < count; i++) {
- XMLClass xclass = nested [i];
-
- node = document.CreateElement ("class", null);
- newNodes.Add (node);
- AddAttribute (node, "name", xclass.Name);
- AddAttribute (node, "type", xclass.Type);
-
- if (oh.ContainsKey (xclass.Name)) {
- int idx = (int) oh [xclass.Name];
- xclass.CompareTo (document, node, other
[idx]);
- other [idx] = null;
- counters.AddPartialToPartial
(xclass.Counters);
- } else {
- // TODO: Should I count here?
- AddAttribute (node, "presence",
"missing");
- counters.Missing++;
- counters.MissingTotal++;
- }
- }
-
- if (other != null) {
- count = other.Length;
- for (int i = 0; i < count; i++) {
- XMLClass c = other [i];
- if (c == null || IsMonoTODOAttribute
(c.Name))
- continue;
-
- node = document.CreateElement ("class",
null);
- newNodes.Add (node);
- AddAttribute (node, "name", c.Name);
- AddExtra (node);
- counters.Extra++;
- counters.ExtraTotal++;
- }
- }
-
- XmlNode [] nodes = (XmlNode []) newNodes.ToArray
(typeof (XmlNode));
- Array.Sort (nodes, XmlNodeComparer.Default);
- foreach (XmlNode nn in nodes)
- parent.AppendChild (nn);
- }
-
static Hashtable CreateHash (XMLClass [] other)
{
Hashtable result = new Hashtable ();
@@ -961,47 +515,6 @@
}
}
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- this.document = doc;
-
- XMLParameter oparm = (XMLParameter) other;
-
- if (type != oparm.type)
- AddWarning (parent, "Parameter type is wrong:
{0} != {1}", type, oparm.type);
-
- if (attrib != oparm.attrib)
- AddWarning (parent, "Parameter attributes
wrong: {0} != {1}", attrib, oparm.attrib);
-
- if (direction != oparm.direction)
- AddWarning (parent, "Parameter direction wrong:
{0} != {1}", direction, oparm.direction);
-
- if (isUnsafe != oparm.isUnsafe)
- AddWarning (parent, "Parameter unsafe wrong:
{0} != {1}", isUnsafe, oparm.isUnsafe);
-
- if (isOptional != oparm.isOptional)
- AddWarning (parent, "Parameter optional wrong:
{0} != {1}", isOptional, oparm.isOptional);
-
- if (defaultValue != oparm.defaultValue)
- AddWarning (parent, "Parameter default value
wrong: {0} != {1}", (defaultValue == null) ? "(no default value)" :
defaultValue, (oparm.defaultValue == null) ? "(no default value)" :
oparm.defaultValue);
-
- if (attributes != null || oparm.attributes != null) {
- if (attributes == null)
- attributes = new XMLAttributes ();
-
- attributes.CompareTo (doc, parent,
oparm.attributes);
- counters.AddPartialToPartial
(attributes.Counters);
- if (oparm.attributes != null &&
oparm.attributes.IsTodo) {
- counters.Todo++;
- counters.TodoTotal++;
- counters.ErrorTotal++;
- AddAttribute (parent, "error", "todo");
- if (oparm.attributes.Comment != null)
- AddAttribute (parent,
"comment", oparm.attributes.Comment);
- }
- }
- }
-
public string Name {
get { return name; }
}
@@ -1058,28 +571,6 @@
}
}
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- this.document = doc;
-
- Hashtable other_properties =
((XMLAttributeProperties)other).properties;
- foreach (DictionaryEntry de in other_properties) {
- object other_value = properties [de.Key];
-
- if (de.Value == null) {
- if (other_value != null)
- AddWarning (parent, "Property
'{0}' is 'null' and should be '{1}'", de.Key, other_value);
- continue;
- }
-
- if (de.Value.Equals (other_value))
- continue;
-
- AddWarning (parent, "Property '{0}' is '{1}'
and should be '{2}'",
- de.Key, de.Value, other_value == null ?
"null" : other_value);
- }
- }
-
public override string GroupName {
get {
return "properties";
@@ -1115,17 +606,6 @@
return true;
}
- protected override void CompareToInner (string name, XmlNode
node, XMLNameGroup other)
- {
- XMLAttributeProperties other_prop =
((XMLAttributes)other).properties [name] as XMLAttributeProperties;
- XMLAttributeProperties this_prop = properties [name] as
XMLAttributeProperties;
- if (other_prop == null || this_prop == null)
- return;
-
- this_prop.CompareTo (document, node, other_prop);
- counters.AddPartialToPartial (this_prop.Counters);
- }
-
public override string GetNodeKey (string name, XmlNode node)
{
string key = null;
@@ -1225,15 +705,6 @@
{
attributes = ((XmlElement) node).GetAttribute
("generic-attribute");
}
-
- protected override void CompareToInner (string name, XmlNode
parent, XMLNameGroup other)
- {
- base.CompareToInner (name, parent, other);
-
- XMLGenericGroup g = (XMLGenericGroup) other;
- if (attributes != g.attributes)
- AddWarning (parent, "Incorrect generic
attributes: '{0}' != '{1}'", attributes, g.attributes);
- }
}
public class XMLGenericTypeConstraints : XMLGenericGroup
@@ -1288,51 +759,6 @@
base.LoadExtraData (name, orig);
}
- protected override void CompareToInner (string name, XmlNode
parent, XMLNameGroup other)
- {
- base.CompareToInner (name, parent, other);
- XMLMember mb = other as XMLMember;
- XMLAttributes att = null;
- XMLAttributes oatt = null;
- if (attributeMap != null)
- att = attributeMap [name] as XMLAttributes;
-
- if (mb != null && mb.attributeMap != null)
- oatt = mb.attributeMap [name] as XMLAttributes;
-
- if (att != null || oatt != null) {
- if (att == null)
- att = new XMLAttributes ();
-
- att.CompareTo (document, parent, oatt);
- counters.AddPartialToPartial(att.Counters);
- if (oatt != null && oatt.IsTodo) {
- counters.Todo++;
- counters.ErrorTotal++;
- AddAttribute (parent, "error", "todo");
- if (oatt.Comment != null)
- AddAttribute (parent,
"comment", oatt.Comment);
- }
- }
-
- XMLMember member = (XMLMember) other;
- string acc = access [name] as string;
- if (acc == null)
- return;
-
- string oacc = null;
- if (member.access != null)
- oacc = member.access [name] as string;
-
- string accName = ConvertToString (Int32.Parse (acc));
- string oaccName = "";
- if (oacc != null)
- oaccName = ConvertToString (Int32.Parse (oacc));
-
- if (accName != oaccName)
- AddWarning (parent, "Incorrect attributes:
'{0}' != '{1}'", accName, oaccName);
- }
-
public virtual string ConvertToString (int att)
{
return null;
@@ -1365,30 +791,6 @@
base.LoadExtraData (name, node);
}
- protected override void CompareToInner (string name, XmlNode
parent, XMLNameGroup other)
- {
- base.CompareToInner (name, parent, other);
- XMLFields fields = (XMLFields) other;
- if (fieldTypes != null) {
- string ftype = fieldTypes [name] as string;
- string oftype = null;
- if (fields.fieldTypes != null)
- oftype = fields.fieldTypes [name] as
string;
-
- if (ftype != oftype)
- AddWarning (parent, "Field type is {0}
and should be {1}", oftype, ftype);
- }
- if (fieldValues != null) {
- string fvalue = fieldValues [name] as string;
- string ofvalue = null;
- if (fields.fieldValues != null)
- ofvalue = fields.fieldValues [name] as
string;
-
- if (fvalue != ofvalue)
- AddWarning (parent, "Field value is {0}
and should be {1}", ofvalue, fvalue);
- }
- }
-
public override string ConvertToString (int att)
{
FieldAttributes fa = (FieldAttributes) att;
@@ -1441,84 +843,12 @@
{
return node.Attributes["position"].Value;
}
-
- public override void CompareTo (XmlDocument doc, XmlNode
parent, object other)
- {
- this.document = doc;
- if (group == null)
- group = doc.CreateElement (GroupName, null);
-
- Hashtable okeys = null;
- if (other != null && ((XMLParameters) other).keys !=
null) {
- okeys = ((XMLParameters) other).keys;
- }
-
- XmlNode node = null;
- bool onull = (okeys == null);
- if (keys != null) {
- foreach (DictionaryEntry entry in keys) {
- node = doc.CreateElement (Name, null);
- group.AppendChild (node);
- string key = (string) entry.Key;
- XMLParameter parm = (XMLParameter)
entry.Value;
- AddAttribute (node, "name", parm.Name);
-
- if (!onull && HasKey (key, okeys)) {
- parm.CompareTo (document, node,
okeys[key]);
- counters.AddPartialToPartial
(parm.Counters);
- okeys.Remove (key);
- counters.Present++;
- } else {
- AddAttribute (node, "presence",
"missing");
- counters.Missing++;
- }
- }
- }
-
- if (!onull && okeys.Count != 0) {
- foreach (XMLParameter value in okeys.Values) {
- node = doc.CreateElement (Name, null);
- AddAttribute (node, "name", value.Name);
- AddAttribute (node, "presence",
"extra");
- group.AppendChild (node);
- counters.Extra++;
- }
- }
-
- if (group.HasChildNodes)
- parent.AppendChild (group);
- }
}
public class XMLProperties : XMLMember
{
public Hashtable nameToMethod = new Hashtable ();
- protected override void CompareToInner (string name, XmlNode
parent, XMLNameGroup other)
- {
- Counters copy = counters;
- counters = new Counters();
-
- XMLProperties oprop = other as XMLProperties;
- if (oprop != null) {
- XMLMethods m = nameToMethod [name] as
XMLMethods;
- XMLMethods om = oprop.nameToMethod [name] as
XMLMethods;
- if (m != null || om != null) {
- if (m == null)
- m = new XMLMethods ();
-
- m.CompareTo(document, parent, om);
-
counters.AddPartialToPartial(m.Counters);
- }
- }
-
- base.CompareToInner (name, parent, other);
- AddCountersAttributes(parent);
-
- copy.AddPartialToPartial(counters);
- counters = copy;
- }
-
protected override void LoadExtraData (string name, XmlNode
node)
{
XmlNode orig = node;
@@ -1573,32 +903,6 @@
base.LoadExtraData (name, node);
}
- protected override void CompareToInner (string name, XmlNode
parent, XMLNameGroup other)
- {
- Counters copy = counters;
- counters = new Counters ();
-
- try {
- base.CompareToInner (name, parent, other);
- AddCountersAttributes (parent);
- if (eventTypes == null)
- return;
-
- XMLEvents evt = (XMLEvents) other;
- string etype = eventTypes [name] as string;
- string oetype = null;
- if (evt.eventTypes != null)
- oetype = evt.eventTypes [name] as
string;
-
- if (etype != oetype)
- AddWarning (parent, "Event type is {0}
and should be {1}", oetype, etype);
- } finally {
- AddCountersAttributes (parent);
- copy.AddPartialToPartial (counters);
- counters = copy;
- }
- }
-
public override string ConvertToString (int att)
{
EventAttributes ea = (EventAttributes) att;
@@ -1696,61 +1000,6 @@
return name;
}
- protected override void CompareToInner (string name, XmlNode
parent, XMLNameGroup other)
- {
- // create backup of actual counters
- Counters copy = counters;
- // initialize counters for current method
- counters = new Counters();
-
- try {
- base.CompareToInner(name, parent, other);
- XMLMethods methods = (XMLMethods) other;
-
- SignatureFlags flags = signatureFlags != null &&
- signatureFlags.ContainsKey (name) ?
- (SignatureFlags) signatureFlags [name] :
- SignatureFlags.None;
- SignatureFlags oflags = methods.signatureFlags
!= null &&
- methods.signatureFlags.ContainsKey
(name) ?
- (SignatureFlags) methods.signatureFlags
[name] :
- SignatureFlags.None;
-
- if (flags!= oflags) {
- if (flags == SignatureFlags.None)
- AddWarning (parent,
String.Format ("should not be {0}", oflags));
- else if (oflags == SignatureFlags.None)
- AddWarning (parent,
String.Format ("should be {0}", flags));
- else
- AddWarning (parent,
String.Format ("{0} and should be {1}", oflags, flags));
- }
-
- if (returnTypes != null) {
- string rtype = returnTypes[name] as
string;
- string ortype = null;
- if (methods.returnTypes != null)
- ortype =
methods.returnTypes[name] as string;
-
- if (rtype != ortype)
- AddWarning (parent, "Return
type is {0} and should be {1}", ortype, rtype);
- }
-
- if (parameters != null) {
- XMLParameters parms = parameters[name]
as XMLParameters;
- parms.CompareTo (document, parent,
methods.parameters[name]);
- counters.AddPartialToPartial
(parms.Counters);
- }
- } finally {
- // output counter attributes in result document
- AddCountersAttributes(parent);
-
- // add temporary counters to actual counters
- copy.AddPartialToPartial(counters);
- // restore backup of actual counters
- counters = copy;
- }
- }
-
public override string ConvertToString (int att)
{
MethodAttributes ma = (MethodAttributes) att;
Modified: trunk/mono-tools/gui-compare/Metadata.cs
===================================================================
--- trunk/mono-tools/gui-compare/Metadata.cs 2008-01-03 01:11:42 UTC (rev
92142)
+++ trunk/mono-tools/gui-compare/Metadata.cs 2008-01-03 01:14:34 UTC (rev
92143)
@@ -29,6 +29,11 @@
List<CompNamed> GetAttributes ();
}
+ public interface ICompHasBaseType
+ {
+ string GetBaseType();
+ }
+
public interface ICompTypeContainer
{
List<CompNamed> GetNestedClasses();
@@ -51,6 +56,7 @@
public abstract class CompNamed {
public CompNamed (string name, CompType type)
{
+ this.DisplayName = null;
this.name = name;
this.type = type;
this.todos = new List<string>();
@@ -61,6 +67,11 @@
get { return name; }
}
+ public string DisplayName {
+ set { displayName = value; }
+ get { return displayName == null ? name : displayName; }
+ }
+
public CompType Type {
set { type = value; }
get { return type; }
@@ -68,7 +79,7 @@
public ComparisonNode GetComparisonNode ()
{
- ComparisonNode node = new ComparisonNode (type, name);
+ ComparisonNode node = new ComparisonNode (type,
DisplayName);
node.todos.AddRange (todos);
return node;
}
@@ -78,6 +89,7 @@
return String.Compare (x.Name, y.Name);
}
+ string displayName;
string name;
CompType type;
public List<string> todos;
@@ -106,7 +118,7 @@
public abstract List<CompNamed> GetNestedDelegates ();
}
- public abstract class CompInterface : CompNamed,
ICompAttributeContainer, ICompMemberContainer {
+ public abstract class CompInterface : CompNamed,
ICompAttributeContainer, ICompMemberContainer, ICompHasBaseType {
public CompInterface (string name)
: base (name, CompType.Interface)
{
@@ -120,9 +132,11 @@
public abstract List<CompNamed> GetProperties();
public abstract List<CompNamed> GetFields();
public abstract List<CompNamed> GetEvents();
+
+ public abstract string GetBaseType();
}
- public abstract class CompEnum : CompNamed, ICompAttributeContainer,
ICompMemberContainer {
+ public abstract class CompEnum : CompNamed, ICompAttributeContainer,
ICompMemberContainer, ICompHasBaseType {
public CompEnum (string name)
: base (name, CompType.Enum)
{
@@ -137,17 +151,20 @@
public abstract List<CompNamed> GetFields();
public abstract List<CompNamed> GetAttributes ();
+
+ public abstract string GetBaseType();
}
- public abstract class CompDelegate : CompNamed {
+ public abstract class CompDelegate : CompNamed, ICompHasBaseType {
public CompDelegate (string name)
: base (name, CompType.Delegate)
{
}
+ public abstract string GetBaseType();
}
- public abstract class CompClass : CompNamed, ICompAttributeContainer,
ICompTypeContainer, ICompMemberContainer {
+ public abstract class CompClass : CompNamed, ICompAttributeContainer,
ICompTypeContainer, ICompMemberContainer, ICompHasBaseType {
public CompClass (string name, CompType type)
: base (name, type)
{
@@ -167,6 +184,8 @@
public abstract List<CompNamed> GetNestedStructs ();
public abstract List<CompNamed> GetNestedEnums ();
public abstract List<CompNamed> GetNestedDelegates ();
+
+ public abstract string GetBaseType();
}
public abstract class CompMember : CompNamed, ICompAttributeContainer {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches