[Mono-list] Re: CS-Doc

Gaurav Vaish gvaish@adobe.com
Sat, 22 Feb 2003 12:36:15 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_005F_01C2DA6E.FDD57E00
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: 7bit

----- Original Message -----
From: "Miguel de Icaza" <miguel@ximian.com>
To: "Gaurav Vaish" <gvaish@adobe.com>
Sent: Saturday, February 22, 2003 01:35
Subject: Re: [Mono-list] Re: CS-Doc


>
> Can you show an example of what seems to be the problem?  I think that
> the property approach would effectively solve the issue that you
> mention.

--------------------------------
using System;

/// <summary>test_12</summary>
public interface test_12
{
    /// <summary>Returns M1</summary>
    int GetM1();

    /// <summary>Gets or Sets P1</summary>
    int /// <remarks>Nuisance</remarks>
        P1 { get; set; }
}
--------------------------------

Output:

--------------------------------
gvaish@MASTER /cygdrive/f/gvaish/projects/csdoc/csdoc/src/csdoc
$ ./csdoc.exe ../tests/test_12.cs
Total keys: 3
GetM1:
/// <summary>Returns M1</summary>


test_12:
/// <summary>test_12</summary>


P1:
/// <summary>Gets or Sets P1</summary>
/// <remarks>Nuisance</remarks>


Compilation succeeded
--------------------------------

    So, with the property "P1", I also collect "Nuisance", which I shouldn't
have.

    Correction: Not the property, but the attributes, since they apply to
all for which I have to collect the docs - btw, can attributes be applied to
members, like:

--------------------------------
public class X
{
    [MyAttribute("Something")]
    private int memberX;
}
--------------------------------

    if not, then I'll have to think something for members also. But I think
I will not to - since csdoc (in P.Net) has only one place - at
opt_attributes (Correct me if I am wrong).



Happy Hacking,
Gaurav
http://mastergaurav.virtualave.net/iitk
---------------------------------------



------=_NextPart_000_005F_01C2DA6E.FDD57E00
Content-Type: application/octet-stream;
	name="driver.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="driver.cs"

//=0A=
// driver.cs: The compiler command line driver.=0A=
//=0A=
// Author: Gaurav Vaish <mastergaurav@users.sourceforge.net>=0A=
//=0A=
// Licensed under the terms of the GNU GPL=0A=
//=0A=
// (C) 2003 Gaurav Vaish=0A=
//=0A=
// Original author: Miguel de Icaza (miguel@gnu.org)=0A=
// Original (C): 2001, Ximian Inc=0A=
=0A=
namespace Mono.CSharp=0A=
{=0A=
	using System;=0A=
	using System.Reflection;=0A=
	using System.Reflection.Emit;=0A=
	using System.Collections;=0A=
	using System.IO;=0A=
	using System.Text;=0A=
	using System.Globalization;=0A=
	using Mono.Languages;=0A=
=0A=
	enum Target {=0A=
		Library, Exe, Module, WinExe=0A=
	};=0A=
=0A=
	/// <summary>=0A=
	///    The compiler driver.=0A=
	/// </summary>=0A=
	public class Driver=0A=
	{=0A=
=0A=
		static string first_source;=0A=
		static bool timestamps =3D false;=0A=
		static bool pause =3D false;=0A=
=0A=
		static Hashtable response_file_list;=0A=
=0A=
		//=0A=
		// Output file=0A=
		//=0A=
		static string output_file =3D null;=0A=
=0A=
		static DateTime last_time, first_time;=0A=
=0A=
		//=0A=
		// Encoding: ISO-Latin1 is 28591=0A=
		//=0A=
		static Encoding encoding;=0A=
=0A=
		//=0A=
		// Whether the user has specified a different encoder manually=0A=
		//=0A=
		static bool using_default_encoder =3D true;=0A=
=0A=
		//static string xmlFileName =3D "";=0A=
=0A=
		public static void ShowTime (string msg)=0A=
		{=0A=
			if (!timestamps)=0A=
				return;=0A=
=0A=
			DateTime now =3D DateTime.Now;=0A=
			TimeSpan span =3D now - last_time;=0A=
			last_time =3D now;=0A=
=0A=
			Console.WriteLine (=0A=
				"[{0:00}:{1:000}] {2}",=0A=
				(int) span.TotalSeconds, span.Milliseconds, msg);=0A=
=0A=
			if (pause)=0A=
				Console.ReadLine ();=0A=
		}=0A=
=0A=
		public static void ShowTotalTime (string msg)=0A=
		{=0A=
			if (!timestamps)=0A=
				return;=0A=
=0A=
			DateTime now =3D DateTime.Now;=0A=
			TimeSpan span =3D now - first_time;=0A=
			last_time =3D now;=0A=
=0A=
			Console.WriteLine (=0A=
				"[{0:00}:{1:000}] {2}",=0A=
				(int) span.TotalSeconds, span.Milliseconds, msg);=0A=
		}=0A=
=0A=
		// MonoTODO("Change error code for aborted compilation to something =
reasonable")]=0A=
		static void parse (SourceFile file)=0A=
		{=0A=
			CSharpParser parser;=0A=
			Stream input;=0A=
=0A=
			try {=0A=
				input =3D File.OpenRead (file.Name);=0A=
			} catch {=0A=
				Report.Error (2001, "Source file '" + file.Name + "' could not be =
opened");=0A=
				return;=0A=
			}=0A=
=0A=
			StreamReader reader =3D new StreamReader (input, encoding, =
using_default_encoder);=0A=
=0A=
			//parser =3D new CSharpParser (reader, file, defines);=0A=
			parser =3D new CSharpParser(reader, file, null);=0A=
			//parser.yacc_verbose =3D yacc_verbose;=0A=
			parser.yacc_verbose =3D false;=0A=
			try {=0A=
				parser.parse ();=0A=
			} catch (Exception ex) {=0A=
				Report.Error(666, "Compilation aborted: " + ex);=0A=
			} finally {=0A=
				input.Close ();=0A=
			}=0A=
			Tokenizer lexer =3D parser.Lexer;=0A=
			Hashtable comments =3D lexer.Documentation;=0A=
			Console.WriteLine("Total keys: " + comments.Count);=0A=
			foreach(object key in comments.Keys)=0A=
			{=0A=
				string displayName =3D "";=0A=
				if(key is Class)=0A=
					displayName =3D ((Class)key).Name;=0A=
				else if(key is Method)=0A=
					displayName =3D ((Method)key).Name;=0A=
				else if(key is Event)=0A=
					displayName =3D ((Event)key).Name;=0A=
				else if(key is Const)=0A=
					displayName =3D ((Const)key).Name;=0A=
				else if(key is Constructor)=0A=
					displayName =3D ((Constructor)key).Name;=0A=
				else if(key is Interface)=0A=
					displayName =3D ((Interface)key).Name;=0A=
				else if(key is InterfaceMethod)=0A=
					displayName =3D ((InterfaceMethod)key).Name;=0A=
				else if(key is InterfaceProperty)=0A=
					displayName =3D ((InterfaceProperty)key).Name;=0A=
				else if(key is Delegate)=0A=
					displayName =3D ((Delegate)key).Name;=0A=
				System.Console.WriteLine("{0}:\n{1}\n", displayName, comments[key]);=0A=
				if(key is Method || key is Constructor)=0A=
				{=0A=
					MethodCore m =3D (MethodCore)key;=0A=
					if(m.Parameters !=3D null)=0A=
					{=0A=
						Parameters pars =3D m.Parameters;=0A=
						if(pars.FixedParameters !=3D null)=0A=
						{=0A=
							foreach(Parameter p in pars.FixedParameters)=0A=
							{=0A=
								Console.WriteLine("Param: <" + p.TypeName.ToString() + "::" + =
p.Name + ">");=0A=
							}=0A=
						}=0A=
					}=0A=
				}=0A=
			}=0A=
		}=0A=
=0A=
		static void Usage()=0A=
		{=0A=
			// Doclet defaultDoclet =3D new CSDoclet(...);=0A=
			// string options =3D defaultDoclet.UsageString();=0A=
			Console.WriteLine("" +=0A=
			    "C# Document Generator, (C) 2003 Gaurav Vaish\n" +=0A=
			    "\n" +=0A=
			    "usage: \n" +=0A=
			    "csdoc [options] [namespace-names] [sourcefiles] [@files] \n" +=0A=
			    "   -overview <file>    Read overview documentation from HTML =
file\n" +=0A=
			    "   -public             Show only public classes and members\n" +=0A=
			    "   -protected          Show protected/public classes and =
members\n" +=0A=
			    "   -internal           Show internal/protected/public classes =
and members\n" +=0A=
			    "   -private            Show all classes and members\n" +=0A=
			    "   -doclet <class>     Generate output via alternate doclet\n" +=0A=
			    //"   -verbose            Be verbose of what is being done\n" +=0A=
			    //"   --reference:ASS     Reference the specified assembly\n" +=0A=
			    "   -r:ASS              Same as --reference\n" +=0A=
			    "   --help              Display command line options and exit\n" +=0A=
			    "   --about             About the CSDoc Document Generator\n" +=0A=
			    "\n" +=0A=
			    "Options can be of the form -option or /option" + /* options */=0A=
			"");=0A=
		}=0A=
=0A=
		static void About()=0A=
		{=0A=
			Console.WriteLine("" +=0A=
			    " The CSDoc Document Generator is (C) 2003, Gaurav Vaish.\n" +=0A=
			    " The source code is released under the terms of the GNU GPL.\n" +=0A=
			    "\n" +=0A=
			    " For more information on CSDoc, visit the website:\n" +=0A=
			    "   http://csdoc.sourceforge.net\n" +=0A=
			    "\n" +=0A=
			    " The application is mastermind of Gaurav Vaish.\n" +=0A=
			"");=0A=
		}=0A=
=0A=
		public static int Main (string[] args)=0A=
		{=0A=
			bool ok =3D MainDriver (args);=0A=
=0A=
			if (ok && Report.Errors =3D=3D 0) {=0A=
				Console.Write("Compilation succeeded");=0A=
				if (Report.Warnings > 0) {=0A=
					Console.Write(" - {0} warning(s)", Report.Warnings);=0A=
				}=0A=
				Console.WriteLine();=0A=
				return 0;=0A=
			} else {=0A=
				Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",=0A=
					Report.Errors, Report.Warnings);=0A=
				return 1;=0A=
			}=0A=
		}=0A=
=0A=
		static string [] LoadArgs (string file)=0A=
		{=0A=
			StreamReader f;=0A=
			ArrayList args =3D new ArrayList ();=0A=
			string line;=0A=
			try {=0A=
				f =3D new StreamReader (file);=0A=
			} catch {=0A=
				return null;=0A=
			}=0A=
=0A=
			StringBuilder sb =3D new StringBuilder ();=0A=
=0A=
			while ((line =3D f.ReadLine ()) !=3D null){=0A=
				int t =3D line.Length;=0A=
=0A=
				for (int i =3D 0; i < t; i++){=0A=
					char c =3D line [i];=0A=
=0A=
					if (c =3D=3D '"' || c =3D=3D '\''){=0A=
						char end =3D c;=0A=
=0A=
						for (i++; i < t; i++){=0A=
							c =3D line [i];=0A=
=0A=
							if (c =3D=3D end)=0A=
								break;=0A=
							sb.Append (c);=0A=
						}=0A=
					} else if (c =3D=3D ' '){=0A=
						if (sb.Length > 0){=0A=
							args.Add (sb.ToString ());=0A=
							sb.Length =3D 0;=0A=
						}=0A=
					} else=0A=
						sb.Append (c);=0A=
				}=0A=
				if (sb.Length > 0){=0A=
					args.Add (sb.ToString ());=0A=
					sb.Length =3D 0;=0A=
				}=0A=
			}=0A=
=0A=
			string [] ret_value =3D new string [args.Count];=0A=
			args.CopyTo (ret_value, 0);=0A=
=0A=
			return ret_value;=0A=
		}=0A=
=0A=
		//=0A=
		// Returns the directory where the system assemblies are installed=0A=
		//=0A=
		static string GetSystemDir ()=0A=
		{=0A=
			Assembly [] assemblies =3D AppDomain.CurrentDomain.GetAssemblies ();=0A=
=0A=
			foreach (Assembly a in assemblies){=0A=
				string codebase =3D a.Location;=0A=
				if (codebase.EndsWith ("corlib.dll")){=0A=
					return codebase.Substring (0, codebase.LastIndexOf =
(System.IO.Path.DirectorySeparatorChar));=0A=
				}=0A=
			}=0A=
=0A=
			Report.Error (-15, "Can not compute my system path");=0A=
			return "";=0A=
		}=0A=
=0A=
		//=0A=
		// Given a path specification, splits the path from the file/pattern=0A=
		//=0A=
		static void SplitPathAndPattern (string spec, out string path, out =
string pattern)=0A=
		{=0A=
			int p =3D spec.LastIndexOf ("/");=0A=
			if (p !=3D -1){=0A=
				//=0A=
				// Windows does not like /file.cs, switch that to:=0A=
				// "\", "file.cs"=0A=
				//=0A=
				if (p =3D=3D 0){=0A=
					path =3D "\\";=0A=
					pattern =3D spec.Substring (1);=0A=
				} else {=0A=
					path =3D spec.Substring (0, p);=0A=
					pattern =3D spec.Substring (p + 1);=0A=
				}=0A=
				return;=0A=
			}=0A=
=0A=
			p =3D spec.LastIndexOf ("\\");=0A=
			if (p !=3D -1){=0A=
				path =3D spec.Substring (0, p);=0A=
				pattern =3D spec.Substring (p + 1);=0A=
				return;=0A=
			}=0A=
=0A=
			path =3D ".";=0A=
			pattern =3D spec;=0A=
		}=0A=
=0A=
		static void ProcessFile (string f)=0A=
		{=0A=
			if (first_source =3D=3D null)=0A=
				first_source =3D f;=0A=
=0A=
			Location.AddFile (f);=0A=
		}=0A=
=0A=
		static void ProcessFiles ()=0A=
		{=0A=
			Location.Initialize ();=0A=
=0A=
			foreach (SourceFile file in Location.SourceFiles) {=0A=
					parse (file);=0A=
			}=0A=
		}=0A=
=0A=
		static void CompileFiles (string spec, bool recurse)=0A=
		{=0A=
			string path, pattern;=0A=
			SplitPathAndPattern (spec, out path, out pattern);=0A=
			if (pattern.IndexOf ("*") =3D=3D -1){=0A=
				ProcessFile (spec);=0A=
				return;=0A=
			}=0A=
=0A=
			string [] files =3D null;=0A=
			try {=0A=
				files =3D Directory.GetFiles (path, pattern);=0A=
			} catch (System.IO.DirectoryNotFoundException) {=0A=
				Report.Error (2001, "Source file `" + spec + "' could not be found");=0A=
				return;=0A=
			} catch (System.IO.IOException){=0A=
				Report.Error (2001, "Source file `" + spec + "' could not be found");=0A=
				return;=0A=
			}=0A=
			foreach (string f in files) {=0A=
				ProcessFile (f);=0A=
			}=0A=
=0A=
			if (!recurse)=0A=
				return;=0A=
=0A=
			string [] dirs =3D null;=0A=
=0A=
			try {=0A=
				dirs =3D Directory.GetDirectories (path);=0A=
			} catch {=0A=
			}=0A=
=0A=
			foreach (string d in dirs) {=0A=
=0A=
				// Don't include path in this string, as each=0A=
				// directory entry already does=0A=
				CompileFiles (d + "/" + pattern, true);=0A=
			}=0A=
		}=0A=
=0A=
		static void SetOutputFile (string name)=0A=
		{=0A=
			output_file =3D name;=0A=
		}=0A=
=0A=
		static void Version ()=0A=
		{=0A=
			string version =3D Assembly.GetExecutingAssembly ().GetName =
().Version.ToString ();=0A=
			Console.WriteLine ("C# Document Generator Version {0}", version);=0A=
			Environment.Exit (0);=0A=
		}=0A=
=0A=
		//=0A=
		// Currently handles the Unix-like command line options, but will be=0A=
		// deprecated in favor of the CSCParseOption, which will also handle =
the=0A=
		// options that start with a dash in the future.=0A=
		//=0A=
		static bool UnixParseOption (string arg, ref string [] args, ref int i)=0A=
		{=0A=
			switch (arg){=0A=
=0A=
			case "--version":=0A=
				Version ();=0A=
				return true;=0A=
=0A=
			case "/?": case "/h": case "/help":=0A=
			case "--help":=0A=
				Usage ();=0A=
				Environment.Exit (0);=0A=
				return true;=0A=
=0A=
			case "--about":=0A=
				About();=0A=
				Environment.Exit(0);=0A=
				return true;=0A=
=0A=
			case "--recurse":=0A=
				if ((i + 1) >=3D args.Length){=0A=
					Report.Error (5, "--recurse requires an argument");=0A=
					Environment.Exit (1);=0A=
				}=0A=
				CompileFiles (args [++i], true);=0A=
				return true;=0A=
=0A=
			case "--timestamp":=0A=
				timestamps =3D true;=0A=
				last_time =3D first_time =3D DateTime.Now;=0A=
				return true;=0A=
			}=0A=
			return false;=0A=
		}=0A=
=0A=
		//=0A=
		// Currently it is very basic option parsing, but eventually, this will=0A=
		// be the complete option parser=0A=
		//=0A=
		static bool CSCParseOption (string option, ref string [] args, ref int =
i)=0A=
		{=0A=
			int idx =3D option.IndexOf (":");=0A=
			string arg, value;=0A=
=0A=
			if (idx =3D=3D -1){=0A=
				arg =3D option;=0A=
				value =3D "";=0A=
			} else {=0A=
				arg =3D option.Substring (0, idx);=0A=
=0A=
				value =3D option.Substring (idx + 1);=0A=
			}=0A=
=0A=
			switch (arg){=0A=
			case "/nologo":=0A=
				return true;=0A=
=0A=
			case "/recurse":=0A=
				if (value =3D=3D ""){=0A=
					Report.Error (5, "/recurse requires an argument");=0A=
					Environment.Exit (1);=0A=
				}=0A=
				CompileFiles (value, true);=0A=
				return true;=0A=
=0A=
			case "/help":=0A=
			case "/?":=0A=
				Usage ();=0A=
				Environment.Exit (0);=0A=
				return true;=0A=
			}=0A=
			return false;=0A=
		}=0A=
=0A=
		/// <summary>=0A=
		///    Parses the arguments, and drives the compilation=0A=
		///    process.=0A=
		/// </summary>=0A=
		///=0A=
		/// <remarks>=0A=
		///    TODO: Mostly structured to debug the compiler=0A=
		///    now, needs to be turned into a real driver soon.=0A=
		/// </remarks>=0A=
		// [MonoTODO("Change error code for unknown argument to something =
reasonable")]=0A=
		static bool MainDriver (string [] args)=0A=
		{=0A=
			int i;=0A=
			bool parsing_options =3D true;=0A=
=0A=
			try {=0A=
				encoding =3D Encoding.GetEncoding (28591);=0A=
			} catch {=0A=
				Console.WriteLine ("Error: could not load encoding 28591, trying =
1252");=0A=
				encoding =3D Encoding.GetEncoding (1252);=0A=
			}=0A=
=0A=
			int argc =3D args.Length;=0A=
			for (i =3D 0; i < argc; i++){=0A=
				string arg =3D args [i];=0A=
=0A=
				if (arg.StartsWith ("@")){=0A=
					string [] new_args, extra_args;=0A=
					string response_file =3D arg.Substring (1);=0A=
=0A=
					if (response_file_list =3D=3D null)=0A=
						response_file_list =3D new Hashtable ();=0A=
=0A=
					if (response_file_list.Contains (response_file)){=0A=
						Report.Error (=0A=
							1515, "Response file `" + response_file +=0A=
							"' specified multiple times");=0A=
						Environment.Exit (1);=0A=
					}=0A=
=0A=
					response_file_list.Add (response_file, response_file);=0A=
=0A=
					extra_args =3D LoadArgs (response_file);=0A=
					if (extra_args =3D=3D null){=0A=
						Report.Error (2011, "Unable to open response file: " +=0A=
							      response_file);=0A=
						return false;=0A=
					}=0A=
=0A=
					new_args =3D new string [extra_args.Length + argc];=0A=
					args.CopyTo (new_args, 0);=0A=
					extra_args.CopyTo (new_args, argc);=0A=
					args =3D new_args;=0A=
					argc =3D new_args.Length;=0A=
					continue;=0A=
				}=0A=
=0A=
				if (parsing_options){=0A=
					if (arg =3D=3D "--"){=0A=
						parsing_options =3D false;=0A=
						continue;=0A=
					}=0A=
=0A=
					if (arg.StartsWith ("-")){=0A=
						if (UnixParseOption (arg, ref args, ref i))=0A=
							continue;=0A=
=0A=
						// Try a -CSCOPTION=0A=
						string csc_opt =3D "/" + arg.Substring (1);=0A=
						if (CSCParseOption (csc_opt, ref args, ref i))=0A=
							continue;=0A=
					} else {=0A=
						if (arg.StartsWith ("/")){=0A=
							if (CSCParseOption (arg, ref args, ref i))=0A=
								continue;=0A=
						}=0A=
					}=0A=
				}=0A=
=0A=
				CompileFiles (arg, false);=0A=
			}=0A=
=0A=
			ProcessFiles ();=0A=
=0A=
			if (first_source =3D=3D null){=0A=
				Report.Error (2008, "No files to compile were specified");=0A=
				return false;=0A=
			}=0A=
=0A=
			return (Report.Errors =3D=3D 0);=0A=
		}=0A=
	}=0A=
}=0A=

------=_NextPart_000_005F_01C2DA6E.FDD57E00--