[sgen] Write barrier nursery checks might be needed
[mono.git] / mcs / tools / corcompare / mono-api-html / ApiChange.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Xml.Linq;
5
6 namespace Xamarin.ApiDiff
7 {
8         public class ApiChange
9         {
10                 public string Header;
11                 public StringBuilder Member = new StringBuilder ();
12                 public bool Breaking;
13                 public bool AnyChange;
14                 public bool HasIgnoredChanges;
15
16                 public ApiChange Append (string text)
17                 {
18                         Member.Append (text);
19                         return this;
20                 }
21
22                 public ApiChange AppendAdded (string text, bool breaking = false)
23                 {
24                         if (breaking)
25                                 Member.Append ("<u>");
26                         if (State.Colorize)
27                                 Member.Append (breaking ? "<font color='green'>" : "<font color='green'>");
28                         Member.Append (text);
29                         if (State.Colorize)
30                                 Member.Append (breaking ? "</font>" : "</font>");
31                         if (breaking)
32                                 Member.Append ("</u>");
33                         Breaking |= breaking;
34                         AnyChange = true;
35                         return this;
36                 }
37
38                 public ApiChange AppendRemoved (string text, bool breaking = true)
39                 {
40                         Member.Append ("<s>");
41                         if (State.Colorize && breaking)
42                                 Member.Append ("<font color='red'>");
43                         Member.Append (text);
44                         if (State.Colorize && breaking)
45                                 Member.Append ("</font>");
46                         Member.Append ("</s>");
47                         Breaking |= breaking;
48                         AnyChange = true;
49                         return this;
50                 }
51
52                 public ApiChange AppendModified (string old, string @new, bool breaking = true)
53                 {
54                         if (old.Length > 0)
55                                 AppendRemoved (old, breaking);
56                         if (old.Length > 0 && @new.Length > 0)
57                                 Append (" ");
58                         if (@new.Length > 0)
59                                 AppendAdded (@new);
60                         Breaking |= breaking;
61                         AnyChange = true;
62                         return this;
63                 }
64         }
65
66         public class ApiChanges : Dictionary<string, List<ApiChange>> {
67                 public void Add (XElement source, XElement target, ApiChange change)
68                 {
69                         if (!change.AnyChange) {
70                                 // This is most likely because the rendering doesn't take into account something that's different (solution: fix rendering).
71                                 if (!change.HasIgnoredChanges)
72                                         Console.WriteLine ("Comparison resulting in no changes (src: {2} dst: {3}) :\n{0}\n{1}\n\n", source.ToString (), target.ToString (), source.GetMethodAttributes (), target.GetMethodAttributes ());
73                                 return;
74                         }
75
76                         List<ApiChange> list;
77                         if (!TryGetValue (change.Header, out list)) {
78                                 list = new List<ApiChange> ();
79                                 base.Add (change.Header, list);
80                         }
81                         list.Add (change);
82                 }
83         }
84 }
85