[svn] r6785: nemerle/trunk/tools/ndp: AssemblyAnalyzer.n DataTree.n Makefile XMLMacro.n

marcinm svnadmin at nemerle.org
Wed Oct 25 23:11:57 CEST 2006


Log:


Author: marcinm
Date: Wed Oct 25 23:11:55 2006
New Revision: 6785

Modified:
   nemerle/trunk/tools/ndp/AssemblyAnalyzer.n
   nemerle/trunk/tools/ndp/DataTree.n
   nemerle/trunk/tools/ndp/Makefile
   nemerle/trunk/tools/ndp/XMLMacro.n

Modified: nemerle/trunk/tools/ndp/AssemblyAnalyzer.n
==============================================================================
--- nemerle/trunk/tools/ndp/AssemblyAnalyzer.n	(original)
+++ nemerle/trunk/tools/ndp/AssemblyAnalyzer.n	Wed Oct 25 23:11:55 2006
@@ -1,26 +1,52 @@
 using System;
 using System.Reflection;
 
+// #define Console.WriteLine nic
+
+namespace NemerleDoc
+{
+
 module AssemblyAnalyzer
 {
   mutable ass : Assembly;
   public analyze (filename : string, tree : DataTree) : void
   {
     ass = Assembly.LoadFile(filename);
+    // Console.WriteLine("Codebase={0}\nFullName={1}\nLocation={2}", ass.CodeBase, ass.FullName, ass.Location);
     foreach (t in ass.GetTypes())
     {
-      // Console.WriteLine("Namespace: {0}, name: {1}", t.Namespace, t.FullName);
-      foreach (_m in t.GetMembers()) {
-        mutable info = "";
-        when (t.IsAbstract) info += " abstract ";
-        when (t.IsArray) info += " array ";
-        when (t.IsClass) info += " class ";
-        when (t.IsInterface) info += " interface ";
-        tree.AddItem(t.ToString(), t.Attributes, info);
-        // Console.WriteLine("   nazwa {0}, opis {1}, atrybut {2}", t.Name, t.ToString(), t.Attributes);
+      // Console.WriteLine("\n\n--> NameSp: {0}, name: {1}, FullName: {2}", t.Namespace,  t.Name, t.FullName,);
+      // Console.WriteLine("--> Attrib {0}, BaseType: {1}, DeclaredType: {2}", t.Attributes, t.BaseType, t.DeclaringType);
+      
+      /*
+      when (t.IsAbstract)  Console.WriteLine("--> abstract");
+      when (t.IsArray)     Console.WriteLine("--> array ");
+      when (t.IsClass)     Console.WriteLine("--> class ");
+      when (t.IsInterface) Console.WriteLine("--> interface ");
+      */
+      
+      tree.AddItem(t.FullName, t.Attributes, ElementType.Type());
+      
+      foreach (m in t.GetMembers()) {
+        // Console.WriteLine("----> DeclType {0}, MemTye {1}, Name {2}, ReflType {3}", m.DeclaringType, m.MemberType, m.Name, m.ReflectedType);
+        // Console.WriteLine("----> GetType {0} ", m.GetType());
+        def ty =
+          match (m.MemberType) {
+            | Method => ElementType.Method()
+            | Property => ElementType.Property()
+            | Constructor => ElementType.Method()
+            | Field => ElementType.Field()
+            | NestedType => ElementType.Unknown()
+            | _ => null
+          }
+        if (ty != null)
+          tree.AddItem(m.DeclaringType.ToString(), m.Name, ty)
+        else Console.WriteLine("*** Rejected {0} ***, {1}", m.Name, m.MemberType);
+          
       }
     }
   
   }
 
 }
+}

Modified: nemerle/trunk/tools/ndp/DataTree.n
==============================================================================
--- nemerle/trunk/tools/ndp/DataTree.n	(original)
+++ nemerle/trunk/tools/ndp/DataTree.n	Wed Oct 25 23:11:55 2006
@@ -2,6 +2,7 @@
 using Nemerle.Collections;
 
 
+namespace NemerleDoc {
 module HtmlGenerator
 {
   public Page (f : void -> string, fname : string) : void
@@ -51,6 +52,10 @@
   | Type
 }
 
+/// <summary>
+/// Top node of the tree representing a 'top' namespace, even if it is
+/// empty (how's it called, by the way?)
+/// </summary>
 class TopNode
 {
   
@@ -70,11 +75,15 @@
   internal parent : TopNode;
   
   
-  internal page_content (elements : list [ Node ], ns : string) : string
+  /// <summary>
+  /// Create html description (i.e. TOC) of the namespace
+  /// </summary>
+  internal namespace2html (elements : list [ Node ], ns : string) : string
   {
+    // def page_ref = "<a href=\"" + ns + "\">";
     mutable res = "";
     res += "<div class=\"ns-index\">\n";
-    res += "<span class=\"ns-index\" id=\"" + this.href + "\">Namespace " + (if (ns.Length ==0) "?Empty?" else ns) +"</span>\n";
+    res += "<span class=\"ns-index\" id=\"" + this.href + "\">Namespace " + (if (ns.Length == 0) "&lt;empty&gt;" else ns) +"</span>\n";
     foreach (e in elements)      
       when (e.elemType.Equals(ElementType.Type()) || e.elemType.Equals(ElementType.Unknown()))
       {
@@ -91,6 +100,10 @@
     res
   }
   
+  /// <summary>
+  /// Creates Table of Content for the current namespace. The current node is
+  /// always a namespace.
+  /// </summary>
   public virtual ToIndex (content : ref string) : void
   {
     // first group types in 'anonymous' namespace
@@ -101,31 +114,40 @@
     // add elements in anonymous
     when (is_anonymous_ns)
     {
-      content += page_content(this.elements, "");
+      content += namespace2html(this.elements, "");
+      foreach (e in this.elements)
+          unless (e.elemType.Equals(ElementType.Unknown())) content += e.ToHtml()
     }
         
     foreach (e in elements)
        when (e.elemType.Equals(ElementType.Unknown())) e.ToIndex(ref content)
   }
   
+  /// <summary>
+  /// Creates description of the current node, i.e. of the current namespace
+  /// </summary>
   public virtual infoPages () : void
   {       
     foreach (e in elements)
         when (e.elemType.Equals(ElementType.Unknown())) e.infoPages();    
   }
   
+  /// <summary>Add comment to the current element</summary>
   public Comment(str : string) : void { 
     current.comment += str;
   }
   
+  /// <summary>Add remark to the current element</summary>
   public Remark(str : string) : void { 
     current.remark += str;
   }
   
+  /// <summary>Add return info to the current element</summary>
   public Return(str : string) : void { 
     current.return += str;
   }
   
+  /// <summary>Add param info to the current element</summary>
   public Param(str : string) : void { 
     current.param += str;
   }   
@@ -138,34 +160,39 @@
   public mutable elemType : ElementType = ElementType.Unknown();
   /// <summary>Name of the element</summary>
   public mutable name : string;
-  /// <summary>Full name (with namespaces path)</summary>
+  /// <summary>Full name of the element (with namespaces path)</summary>
   public mutable full_name : string = "";
   
+  /// <summary>Returns the name of a file including description of the current node</summary>
   public html_file : string {
     get { if (parent is Node) (parent :> Node).full_name + ".html" else "index.html"}
-  
   }
   
+  /// <summary>
+  /// If the current node is a namespace, it creates a table of content.
+  /// </summary>
   public override ToIndex (content : ref string) : void
   {
     when (this.elemType.Equals(ElementType.Unknown()))
     {
       // Console.WriteLine("Podstrona typu {0}, nazwa {1}", this.elemType, this.full_name);
       // self-explanation
-      content += page_content(this.elements, this.full_name);
+      content += namespace2html(this.elements, this.full_name);
     
       foreach (e in elements)
         when (e.elemType.Equals(ElementType.Unknown())) e.ToIndex(ref content);
     }
   }
 
+  /// <summary>
+  /// Creates a html page for the current namespace
+  /// </summary>
   public override infoPages () : void
   {    
-    // create page for current namespace
     // Console.WriteLine("Zapis pliku {0}", this);
     when (this.elemType.Equals(ElementType.Unknown()))
     {
-      def fname = this.full_name ;
+      def fname = this.full_name;
       mutable content = "";
       content += HtmlGenerator.Title("Nemerle Library", "Namespace " + fname);
       foreach (e in elements)
@@ -194,6 +221,9 @@
     res;
   }
   
+  /// <summary>
+  /// Create html explanation for the current node.
+  /// </summary>
   public ToHtml () : string
   {
     mutable res = "";
@@ -202,13 +232,10 @@
     com += if (return.Length > 0) "<div class=\"return\">Return: " + return + "</div>" else "";
     com += if (param.Length > 0) "<div class=\"param\">Parameter: " + param + "</div>" else "";
     
-    /*
-    mutable att = this.info;
-    when (!this.attr.Equals(null))
+    
+    mutable att = "";
+    unless (this.attr.Equals(null))
         att += " " + this.attr.ToString() + " ";
-    att += " ";
-    */
-    def att = "";
     
     match (elemType) {
       | Unknown => 
@@ -223,7 +250,7 @@
           **/
           res = "";
       | Property => res += "Property: " + att + name + com;
-      | Method => res += "Method: " + att + name + com;
+      | Method => res += "<span title=\"" + this.full_name + "\">Method: " + att + name + com + "</span>";
       | Field => res += "Field: " + att + name + com;
       | Type =>
           res += "<div class=\"ns-index\"" + ("id=\"" + this.href + "\"") + ">Class " + att;
@@ -270,10 +297,21 @@
     sources += [ src ]
   }     
   
-  smart_strip(path : string) : list [ string ]
+  smart_strip1(path : string) : list [ string ]
+  {
+    smart_strip(path, '(')
+  }
+  
+  /// <summary>Strip, but avoid stripping '[' char</summary>
+  smart_strip2(path : string) : list [ string ]
+  {
+    smart_strip(path, '[')
+  }
+  
+  smart_strip(path : string, sep : char) : list [ string ]
   {
     // first split into name and parameters
-    def par_pos = path.IndexOf('(');
+    def par_pos = path.IndexOf(sep);
     def path_name = if (par_pos != -1) path.Substring(0, par_pos) else path;
     def param = if (par_pos != -1) path.Substring(par_pos) else "";
     
@@ -307,14 +345,18 @@
     res;
   }
   
-  public AddItem(str : string, attr : System.Reflection.TypeAttributes, info : string) : void
+  /// <summary>
+  /// Add a new element to the tree. Used by assembly analyzer.
+  /// </summary>
+  public AddItem(str : string, attr : System.Reflection.TypeAttributes, ty : ElementType) : void
   {
-    def path = str.Split(array ['.']);
+    def path = smart_strip2(str);
+    // Console.WriteLine("ĹšcieĹźka {0}", str);
     mutable pointer = tree;
     mutable next;
     foreach (edge in path)
     {    
-      // Console.WriteLine("ścieşka " + edge);
+      // Console.WriteLine("--> podścieşka " + edge);
       next = memb(pointer, edge);
       when (next == null)
       {
@@ -325,9 +367,36 @@
       pointer = next;
     }
     pointer.attr = attr; 
-    pointer.info = info; 
+    next.elemType = ty
   }
   
+  /// <summary>
+  /// Add a new element to the tree. Used by XML analyzer.
+  /// </summary>
+  public AddItem(ns_path : string, typename : string, ty : ElementType) : void
+  {
+    def path = smart_strip2(ns_path) + [ typename ];
+    // Console.WriteLine("ĹšcieĹźka {0}", str);
+    mutable pointer = tree;
+    mutable next;
+    foreach (edge in path)
+    {    
+      // Console.WriteLine("--> podścieşka " + edge);
+      next = memb(pointer, edge);
+      when (next == null)
+      {
+        def pref = if (pointer is Node) ((pointer :> Node).full_name + "." + edge) else edge;
+        next = Node(edge, pref, pointer);
+        pointer.elements = pointer.elements + [ next ];
+      }
+      pointer = next;
+    }
+    next.elemType = ty
+  }
+  
+  /// <summary>
+  /// Add a new element to the tree. Used by assembly analyzer.
+  /// </summary>
   public AddItem (str : string) : void
   {
     // System.Console.WriteLine("---> " + str);
@@ -342,7 +411,7 @@
         | _   => ElementType.Unknown()
       }
       
-    def pathList = smart_strip(path);
+    def pathList = smart_strip1(path);
     mutable pointer = tree;
     mutable next;
     foreach (edge in pathList)
@@ -405,3 +474,4 @@
   
 }
 
+}

Modified: nemerle/trunk/tools/ndp/Makefile
==============================================================================
--- nemerle/trunk/tools/ndp/Makefile	(original)
+++ nemerle/trunk/tools/ndp/Makefile	Wed Oct 25 23:11:55 2006
@@ -1,3 +1,18 @@
+# Nemerle Documentation Project
 
-nemerledoc.exe: XMLMacro.n DataTree.n AssemblyAnalyzer.n
-	ncc -g -Ot -texe -doc:test.xml -out:$@ $^
+SOURCES = NemerleDoc.n XMLMacro.n DataTree.n AssemblyAnalyzer.n
+DIST_FILES = $(SOURCES) Makefile COPYRIGHT
+EXE = nemerledoc.exe
+CLEAN_FILES = $(EXE) $(EXE:.exe=.exe.mdb)
+DOC = nemerledoc.xml
+
+$(EXE): $(SOURCES) 
+	ncc -g -Ot -texe -doc:$(DOC) -out:$@ $^
+#	mono $(EXE) $(EXE) $(DOC)
+
+clean:
+	rm  $(CLEAN_FILES)
+
+dist:
+	echo $(DIST_FILES)
+	tar -zcf nemerle-doc.tgz $(DIST_FILES)

Modified: nemerle/trunk/tools/ndp/XMLMacro.n
==============================================================================
--- nemerle/trunk/tools/ndp/XMLMacro.n	(original)
+++ nemerle/trunk/tools/ndp/XMLMacro.n	Wed Oct 25 23:11:55 2006
@@ -8,8 +8,10 @@
 // using System.Xml.XPath;
 using Nemerle.Assertions;
 
+namespace NemerleDoc
+{
 
-module NemerleDocXml
+module XmlDocAnalyzer
 {
 
   _info () : void
@@ -173,27 +175,15 @@
         docTag();
   }
 
-
-  public static Main(arg : array [ string ]) : void
-  {
-    tree = DataTree();
-    foreach (file in arg)
-    {
-      when (file.EndsWith(".dll"))
-        AssemblyAnalyzer.analyze(file, tree);
-        
-      when (file.EndsWith(".xml"))
+  public start(tr : DataTree, file : string) : void
       {
+    tree = tr;
         cursor = XmlTextReader(file);
         cursor.WhitespaceHandling = WhitespaceHandling.None;
         _ = cursor.Read();
         rootTag();
       }
       
-      tree.AddSource(file);
-    }
-    tree.indexPage();
-    tree.infoPages();
-  }
 
-} // -- NemerleDocXml
+  } // -- NemerleDocXml
+}



More information about the svn mailing list