* Makefile: Specify --exceptions=all in mdoc-update invocations.
authorJonathan Pryor <jpryor@novell.com>
Fri, 5 Dec 2008 01:07:32 +0000 (01:07 -0000)
committerJonathan Pryor <jpryor@novell.com>
Fri, 5 Dec 2008 01:07:32 +0000 (01:07 -0000)
* exceptions.cs: Add support for documenting a *subset* of all
  possible exceptions.  Subsets include: the member itself, the member
  and methods it calls that are in the same assembly, and all possible
  methods across all assemblies.
* monodocer.cs: Allow --exceptions to take a SOURCES argument, to
  control which location sources will be searched for exceptions.

svn path=/trunk/mcs/; revision=120798

mcs/tools/mdoc/ChangeLog
mcs/tools/mdoc/Makefile
mcs/tools/mdoc/Mono.Documentation/exceptions.cs
mcs/tools/mdoc/Mono.Documentation/monodocer.cs

index d9846abbe6c9054ca757855313b29e7cadb8bbe8..30687c33d710f698d27711b874dccd860db09fe4 100644 (file)
@@ -1,3 +1,13 @@
+2008-12-04  Jonathan Pryor <jpryor@novell.com>
+
+       * Makefile: Specify --exceptions=all in mdoc-update invocations.
+       * exceptions.cs: Add support for documenting a *subset* of all
+         possible exceptions.  Subsets include: the member itself, the member
+         and methods it calls that are in the same assembly, and all possible
+         methods across all assemblies.
+       * monodocer.cs: Allow --exceptions to take a SOURCES argument, to
+         control which location sources will be searched for exceptions.
+
 2008-12-02  Jonathan Pryor <jpryor@novell.com>
 
        * Makefile: Add --exceptions to `mdoc update` invocations to test
index d40cfd34740262c061ee605a03b9b0c111d9e8fe..4dbe48cea8477f3ff07a00d197356aa964408d39 100644 (file)
@@ -79,50 +79,50 @@ Test/DocTest.dll-v2:
 check-monodocer-update: mdoc.exe
        find Test/en.expected -name \*.xml -exec rm "{}" \;
        $(MAKE) Test/DocTest.dll-v1
-       $(MONO) mdoc.exe update --exceptions -o Test/en.expected Test/DocTest.dll
+       $(MONO) mdoc.exe update --exceptions=all -o Test/en.expected Test/DocTest.dll
 
 check-monodocer: mdoc.exe
        -rm -Rf Test/en.actual
        $(MAKE) Test/DocTest.dll-v1
-       $(MONO) mdoc.exe update --exceptions -o Test/en.actual Test/DocTest.dll
+       $(MONO) mdoc.exe update --exceptions=all -o Test/en.actual Test/DocTest.dll
        diff --exclude=.svn -rup Test/en.expected Test/en.actual
-       $(MONO) mdoc.exe update --exceptions -o Test/en.actual Test/DocTest.dll 
+       $(MONO) mdoc.exe update --exceptions=all -o Test/en.actual Test/DocTest.dll 
        diff --exclude=.svn -rup Test/en.expected Test/en.actual
 
 check-monodocer-since-update: mdoc.exe
        find Test/en.expected.since -name \*.xml -exec rm "{}" \;
        $(MAKE) Test/DocTest.dll-v1
-       $(MONO) mdoc.exe update --exceptions -o Test/en.expected.since Test/DocTest.dll 
+       $(MONO) mdoc.exe update --exceptions=all -o Test/en.expected.since Test/DocTest.dll 
        $(MAKE) Test/DocTest.dll-v2
-       $(MONO) mdoc.exe update --exceptions --since="Version 2.0" \
+       $(MONO) mdoc.exe update --exceptions=all --since="Version 2.0" \
                -o Test/en.expected.since Test/DocTest.dll 
 
 check-monodocer-since: mdoc.exe
        rm -Rf Test/en.actual
        $(MAKE) Test/DocTest.dll-v1
-       $(MONO) mdoc.exe update --exceptions -o Test/en.actual Test/DocTest.dll 
+       $(MONO) mdoc.exe update --exceptions=all -o Test/en.actual Test/DocTest.dll 
        $(MAKE) Test/DocTest.dll-v2
-       $(MONO) mdoc.exe update --exceptions --since="Version 2.0" \
+       $(MONO) mdoc.exe update --exceptions=all --since="Version 2.0" \
                -o Test/en.actual Test/DocTest.dll 
        diff --exclude=.svn -rup Test/en.expected.since Test/en.actual
 
 check-monodocer-importslashdoc-update: mdoc.exe
        find Test/en.expected.importslashdoc -name \*.xml -exec rm "{}" \;
        $(MAKE) Test/DocTest.dll-v1 TEST_CSCFLAGS=-doc:Test/DocTest.xml
-       $(MONO) mdoc.exe update --exceptions -i Test/DocTest.xml \
+       $(MONO) mdoc.exe update --exceptions=all -i Test/DocTest.xml \
                -o Test/en.expected.importslashdoc Test/DocTest.dll 
 
 check-monodocer-importslashdoc: mdoc.exe
        rm -Rf Test/en.actual
        $(MAKE) Test/DocTest.dll-v1 TEST_CSCFLAGS=-doc:Test/DocTest.xml
-       $(MONO) mdoc.exe update --exceptions -i Test/DocTest.xml \
+       $(MONO) mdoc.exe update --exceptions=all -i Test/DocTest.xml \
                -o Test/en.actual Test/DocTest.dll 
        diff --exclude=.svn -rup Test/en.expected.importslashdoc Test/en.actual
 
 check-monodocer-importecmadoc-update: mdoc.exe
        find Test/en.expected.importecmadoc -name \*.xml -exec rm "{}" \;
        $(MAKE) Test/DocTest.dll-v1
-       $(MONO) mdoc.exe update --exceptions -i Test/TestEcmaDocs.xml \
+       $(MONO) mdoc.exe update --exceptions=all -i Test/TestEcmaDocs.xml \
                '--type=System.Action`1' --type=System.AsyncCallback \
                --type=System.Environment --type=System.Array \
                -o Test/en.expected.importecmadoc Test/DocTest.dll 
@@ -130,7 +130,7 @@ check-monodocer-importecmadoc-update: mdoc.exe
 check-monodocer-importecmadoc: mdoc.exe
        rm -Rf Test/en.actual
        $(MAKE) Test/DocTest.dll-v1
-       $(MONO) mdoc.exe update --exceptions -i Test/TestEcmaDocs.xml \
+       $(MONO) mdoc.exe update --exceptions=all -i Test/TestEcmaDocs.xml \
                '--type=System.Action`1' --type=System.AsyncCallback \
                --type=System.Environment --type=System.Array \
                -o Test/en.actual Test/DocTest.dll 
index 83b670e1c8e906d3cb61bcf5ba3b851547f70c90..f5c74161a67a0667e158cb4c414e435080a47479 100644 (file)
@@ -34,6 +34,14 @@ using Mono.Cecil;
 using Mono.Cecil.Cil;
 
 namespace Mono.Documentation {
+
+       [Flags]
+       public enum ExceptionLocations {
+               Member              = 0x0,
+               Assembly            = 0x1,
+               DependentAssemblies = 0x2,
+               All = Assembly | DependentAssemblies
+       }
         
        public class ExceptionSources {
                internal ExceptionSources (TypeReference exception)
@@ -57,6 +65,13 @@ namespace Mono.Documentation {
                //   where ExceptionSource.Exception == xdoc(TypeRef)
                Dictionary<string, Dictionary<string, ExceptionSources>> db = new Dictionary<string, Dictionary<string, ExceptionSources>> ();
 
+               ExceptionLocations locations;
+
+               public ExceptionLookup (ExceptionLocations locations)
+               {
+                       this.locations = locations;
+               }
+
                public IEnumerable<ExceptionSources> this [IMemberReference member] {
                        get {
                                if (member == null)
@@ -106,15 +121,23 @@ namespace Mono.Documentation {
                {
                        for (int i = 0; i < body.Instructions.Count; ++i) {
                                Instruction instruction = body.Instructions [i];
-                               Console.WriteLine ("#\topcode={0}; operand={1}", instruction.OpCode, instruction.Operand);
                                switch (instruction.OpCode.Code) {
                                        case Code.Call:
                                        case Code.Callvirt: {
-                                               IEnumerable<ExceptionSources> memberExceptions = this [(IMemberReference) instruction.Operand];
-                                               AddExceptions (body, instruction, 
-                                                               memberExceptions.Select (es => es.Exception),
-                                                               memberExceptions.SelectMany (es => es.Sources),
-                                                               exceptions);
+                                               if ((locations & ExceptionLocations.Assembly) == 0 && 
+                                                               (locations & ExceptionLocations.DependentAssemblies) == 0)
+                                                       break;
+                                               IMemberReference memberRef = ((IMemberReference) instruction.Operand);
+                                               if (((locations & ExceptionLocations.Assembly) != 0 && 
+                                                                       body.Method.DeclaringType.Scope.Name == memberRef.DeclaringType.Scope.Name) ||
+                                                               ((locations & ExceptionLocations.DependentAssemblies) != 0 && 
+                                                                       body.Method.DeclaringType.Scope.Name != memberRef.DeclaringType.Scope.Name)) {
+                                                       IEnumerable<ExceptionSources> memberExceptions = this [memberRef];
+                                                       AddExceptions (body, instruction, 
+                                                                       memberExceptions.Select (es => es.Exception),
+                                                                       memberExceptions.SelectMany (es => es.Sources),
+                                                                       exceptions);
+                                               }
                                                break;
                                        }
                                        case Code.Newobj: {
index de12ac3c2d824f0048f952346c6c7fd1e35d5566..f254408c20e3c0208e27b831c0d0af52afa82542 100644 (file)
@@ -38,7 +38,7 @@ class MDocUpdaterOptions
        public bool pretty = true;
        public string since;
        public bool show_exceptions;
-       public bool exceptions = false;
+       public ExceptionLocations? exceptions;
 }
 
 class MDocUpdater : MDocCommand
@@ -49,7 +49,8 @@ class MDocUpdater : MDocCommand
        
        static bool nooverrides = true, delete = false, ignoremembers = false;
        static bool pretty = false;
-       static bool show_exceptions = false, exceptions = false;
+       static bool show_exceptions = false;
+       static ExceptionLocations? exceptions;
        
        static int additions = 0, deletions = 0;
 
@@ -87,14 +88,20 @@ class MDocUpdater : MDocCommand
                                "Delete removed members from the XML files.",
                                v => opts.delete = v != null },
                        { "since=",
-                               "Manually specify the assembly version that new members were added in.",
+                               "Manually specify the assembly {VERSION} that new members were added in.",
                                v => opts.since = v },
                        { "type=",
                          "Only update documentation for {TYPE}.",
                                v => opts.type.Add (v) },
-                       { "exceptions",
-                         "Document potential exceptions that members can generate.",
-                               v => opts.exceptions = v != null },
+                       { "exceptions:",
+                         "Document potential exceptions that members can generate.  {SOURCES} " +
+                               "is a comma-separated list of:\n" +
+                               "  asm      Method calls in same assembly\n" +
+                               "  depasm   Method calls in dependent assemblies\n" +
+                               "  all      Record all possible exceptions\n" +
+                               "If nothing is specified, then only exceptions from the member will " +
+                               "be listed.",
+                               v => opts.exceptions = ParseExceptionLocations (v) },
                };
                opts.assembly = Parse (p, args, "update", 
                                "[OPTIONS]+ ASSEMBLIES",
@@ -108,6 +115,22 @@ class MDocUpdater : MDocCommand
                opts.name = ""; // remove warning about unused member
        }
 
+       static ExceptionLocations ParseExceptionLocations (string s)
+       {
+               ExceptionLocations loc = ExceptionLocations.Member;
+               if (s == null)
+                       return loc;
+               foreach (var type in s.Split (',')) {
+                       switch (type) {
+                               case "asm":     loc |= ExceptionLocations.Assembly; break;
+                               case "depasm":  loc |= ExceptionLocations.DependentAssemblies; break;
+                               case "all":     loc = ExceptionLocations.All; break;
+                               default:        throw new NotSupportedException ("Unsupported --exceptions value: " + type);
+                       }
+               }
+               return loc;
+       }
+
        static void Run (MDocUpdaterOptions opts)
        {
                nooverrides = !opts.overrides;
@@ -1755,7 +1778,7 @@ class MDocUpdater : MDocCommand
                if (addremarks)
                        WriteElementInitialText(e, "remarks", "To be added.");
 
-               if (exceptions && info.Member != null) {
+               if (exceptions.HasValue && info.Member != null) {
                        UpdateExceptions (e, info.Member);
                }
 
@@ -2015,7 +2038,7 @@ class MDocUpdater : MDocCommand
 
        private static void UpdateExceptions (XmlNode docs, IMemberReference member)
        {
-               foreach (var source in new ExceptionLookup ()[member]) {
+               foreach (var source in new ExceptionLookup (exceptions.Value)[member]) {
                        string cref = slashdocFormatter.GetDeclaration (source.Exception);
                        var node = docs.SelectSingleNode ("exception[@cref='" + cref + "']");
                        if (node != null)