[csdoc-patches] CVS: csdoc/src/csdoc AssemblyObjectNames.cs,NONE,1.1 cs-tokenizer.cs,1.8,1.9 driver.
Status: Planning
Brought to you by:
mastergaurav
|
From: Gaurav V. <mas...@us...> - 2003-04-10 05:14:47
|
Update of /cvsroot/csdoc/csdoc/src/csdoc
In directory sc8-pr-cvs1:/tmp/cvs-serv9208
Modified Files:
cs-tokenizer.cs driver.cs makefile ChangeLog
Added Files:
AssemblyObjectNames.cs
Log Message:
2003-04-10 Gaurav Vaish <mastergaurav AT users DOT sf DOT net>
* makefile : Modified doc target to build binary as
$(BINARY) instead of default driver.exe
: Use AssemblyObjectNames.cs
: clean now also removes *.xml
* AssemblyObjectNames.cs
: Added new class. To take care of all
the defined names.
* cs-tokenizer.cs : trim the commentString before returing.
--- NEW FILE ---
/**
*
* Project : Master C# Documentation Generator
* URL : http://csdoc.sourceforge.net
* Namespace : Mono.CSharp
* Class : AssemblyObjectNames
* Author : Gaurav Vaish
*
* Copyright : (C) 2002-2003, with Gaurav Vaish
*/
using System;
using System.Collections;
namespace Mono.CSharp
{
public class AssemblyObjectNames
{
private static AssemblyObjectNames root =
new AssemblyObjectNames();
private string thisName;
private AssemblyObjectNames[] children;
private AssemblyObjectNames()
{
this.thisName = String.Empty;
this.children = null;
}
private AssemblyObjectNames(string fullName)
{
int colon = fullName.IndexOf('.');
string first = (colon == -1 ?
fullName : fullName.Substring(0, colon));
string remainder = (colon == -1 ?
String.Empty : fullName.Substring(colon + 1));
this.thisName = first;
if(colon > 0)
{
AddChild(remainder);
}
}
public AssemblyObjectNames Root
{
get
{
return root;
}
}
public string Name
{
get
{
return this.thisName;
}
}
public AssemblyObjectNames[] Children
{
get
{
return this.children;
}
}
// false == could not add. Name already defined
public bool AddChild(string fullName)
{
if(IsDefined(fullName))
return false;
return Root.AddChild(ref Root.children, fullName);
}
private bool AddChild(ref AssemblyObjectNames[] names,
string subName)
{
int colon = subName.IndexOf('.');
string first = (colon == -1 ?
subName : subName.Substring(0, colon));
string remainder = (colon == -1 ?
String.Empty : subName.Substring(colon + 1));
int addIndex = -1;
bool existed = false;
if(names == null)
{
names = new AssemblyObjectNames[1];
names[0] = new AssemblyObjectNames();
names[0].thisName = first;
names[0].children = null;
addIndex = 0;
} else
{
for(int index = 0; index < names.Length; index++)
{
if(names[index].thisName == first)
{
addIndex = index;
existed = true;
break;
}
}
if(!existed)
{
int len = names.Length;
AssemblyObjectNames[] newNames =
new AssemblyObjectNames[len];
Array.Copy(names, newNames, len);
names = new AssemblyObjectNames[len + 1];
Array.Copy(newNames, names, len);
names[len] = new AssemblyObjectNames();
names[len].thisName = first;
names[len].children = null;
addIndex = len;
}
}
if(remainder == String.Empty)
{
return !existed;
}
return AddChild(ref names[addIndex].children, remainder);
}
private static string GetBasename(string nsName,
int level)
{
string[] split = nsName.Split(new char[] { '.' });
if(level < split.Length)
{
return split[level];
}
return String.Empty;
}
private static bool IsDefined(string fullName)
{
throw new NotImplementedException();
}
}
}
Index: cs-tokenizer.cs
===================================================================
RCS file: /cvsroot/csdoc/csdoc/src/csdoc/cs-tokenizer.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- cs-tokenizer.cs 27 Mar 2003 17:50:52 -0000 1.8
+++ cs-tokenizer.cs 10 Apr 2003 05:14:44 -0000 1.9
@@ -74,7 +74,7 @@
public string GetDocs()
{
- string retVal = commentString;
+ string retVal = commentString.Trim();
SaveDocument();
return retVal;
}
Index: driver.cs
===================================================================
RCS file: /cvsroot/csdoc/csdoc/src/csdoc/driver.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- driver.cs 8 Apr 2003 06:24:42 -0000 1.10
+++ driver.cs 10 Apr 2003 05:14:44 -0000 1.11
@@ -1,1171 +1,1193 @@
-//
-// Author: Gaurav Vaish <mas...@us...>
-//
-// Licensed under the terms of the GNU GPL.
-//
-// (C) 2003 Gaurav Vaish
-// Original Authors: Miguel, Ravi, Martin
-//
-
-namespace Mono.CSharp
-{
- using System;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Collections;
- using System.IO;
- using System.Text;
- using System.Globalization;
- using Mono.Languages;
-
- enum Target {
- Library, Exe, Module, WinExe
- };
-
- /// <summary>
- /// The compiler driver.
- /// </summary>
- public class Driver
- {
-
- //
- // Assemblies references to be linked. Initialized with
- // mscorlib.dll here.
- static ArrayList references;
-
- //
- // If any of these fail, we ignore the problem. This is so
- // that we can list all the assemblies in Windows and not fail
- // if they are missing on Linux.
- //
- static ArrayList soft_references;
-
- // Lookup paths
- static ArrayList link_paths;
-
- // Whether we want Yacc to output its progress
- static bool yacc_verbose = false;
-
- static string first_source;
-
- //static Target target = Target.Exe;
- //static string target_ext = ".exe";
-
- static bool want_debugging_support = false;
-
- //static bool parse_only = false;
- //static bool timestamps = false;
- //static bool pause = false;
-
- //
- // Whether to load the initial config file (what CSC.RSP has by default)
- //
- static bool load_default_config = true;
-
- static Hashtable response_file_list;
-
- //
- // A list of resource files
- //
- static ArrayList resources;
- static ArrayList embedded_resources;
-
- //
- // An array of the defines from the command line
- //
- static ArrayList defines;
-
- //
- // Output file
- //
- static string output_file = null;
-
- //
- // Last time we took the time
- //
- static DateTime last_time, first_time;
-
- //
- // Encoding: ISO-Latin1 is 28591
- //
- static Encoding encoding;
-
- //
- // Whether the user has specified a different encoder manually
- //
- static bool using_default_encoder = true;
-
- public static void ShowTime(string msg)
- {
- DateTime now = DateTime.Now;
- TimeSpan span = now - last_time;
- last_time = now;
-
- Console.WriteLine (
- "[{0:00}:{1:000}] {2}",
- (int) span.TotalSeconds, span.Milliseconds, msg);
- }
-
- public static void ShowTotalTime(string msg)
- {
- DateTime now = DateTime.Now;
- TimeSpan span = now - first_time;
- last_time = now;
-
- Console.WriteLine (
- "[{0:00}:{1:000}] {2}",
- (int) span.TotalSeconds, span.Milliseconds, msg);
- }
-
- // MonoTODO("Change error code for aborted compilation to something reasonable")]
- static void parse(SourceFile file)
- {
- CSharpParser parser;
- Stream input;
-
- try
- {
- input = File.OpenRead(file.Name);
- } catch
- {
- Report.Error(2001, "Source file '" + file.Name + "' could not be opened");
- return;
- }
-
- StreamReader reader = new StreamReader(input, encoding, using_default_encoder);
-
- parser = new CSharpParser (reader, file, defines);
- parser.yacc_verbose = yacc_verbose;
- try
- {
- parser.parse();
- } catch(Exception ex)
- {
- Report.Error(666, "Compilation aborted: " + ex);
- } finally {
- input.Close ();
- }
- }
-
- static void Usage()
- {
- // Doclet defaultDoclet = new CSDoclet(...);
- // string options = defaultDoclet.UsageString();
- Console.WriteLine("" +
- "C# Document Generator, (C) 2003 Gaurav Vaish\n" +
- "\n" +
- "usage: \n" +
- "csdoc [options] [namespace-names] [sourcefiles] [@files] \n" +
- " -overview <file> Read overview documentation from HTML file\n" +
- " -public Show only public classes and members\n" +
- " -protected Show protected/public classes and members\n" +
- " -internal Show internal/protected/public classes and members\n" +
- " -private Show all classes and members\n" +
- " -doclet <class> Generate output via alternate doclet\n" +
- //" -verbose Be verbose of what is being done\n" +
- //" --reference:ASS Reference the specified assembly\n" +
- " -r:ASS Same as --reference\n" +
- " --help Display command line options and exit\n" +
- " --about About the CSDoc Document Generator\n" +
- "\n" +
- "Resources:\n" +
- " --linkresource FILE[,ID] Links FILE as a resource\n" +
- " --resource FILE[,ID] Embed FILE as a resource\n" +
- "\n" +
- "Options can be of the form -option or /option" + /* options */
- "");
- }
-
- static void About()
- {
- Console.WriteLine("" +
- " The CSDoc Document Generator is (C) 2003, Gaurav Vaish.\n" +
- " The source code is released under the terms of the GNU GPL.\n" +
- "\n" +
- " For more information on CSDoc, visit the website:\n" +
- " http://csdoc.sourceforge.net\n" +
- "\n" +
- " The application is mastermind of Gaurav Vaish.\n" +
- "");
- }
-
- public static int Main(string[] args)
- {
- bool ok = MainDriver(args);
-
- if (ok && Report.Errors == 0)
- {
- Console.Write("Compilation succeeded");
- if(Report.Warnings > 0)
- {
- Console.Write(" - {0} warning(s)", Report.Warnings);
- }
- Console.WriteLine();
- return 0;
- } else
- {
- Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
- Report.Errors, Report.Warnings);
- return 1;
- }
- }
-
- static public void LoadAssembly(string assembly, bool soft)
- {
- Assembly a;
- string total_log = "";
-
- try
- {
- char[] path_chars = { '/', '\\', '.' };
-
- if (assembly.IndexOfAny(path_chars) != -1)
- {
- a = Assembly.LoadFrom(assembly);
- } else
- {
- a = Assembly.Load(assembly);
- }
- TypeManager.AddAssembly(a);
-
- } catch(FileNotFoundException)
- {
- foreach (string dir in link_paths)
- {
- string full_path = Path.Combine(dir, assembly);
- if(!assembly.EndsWith(".dll"))
- full_path += ".dll";
-
- try
- {
- a = Assembly.LoadFrom(full_path);
- TypeManager.AddAssembly(a);
- return;
- } catch (FileNotFoundException ff)
- {
- total_log += ff.FusionLog;
- continue;
- }
- }
- if(!soft)
- {
- Report.Error(6, "Cannot find assembly `" + assembly + "'" );
- Console.WriteLine("Log: \n" + total_log);
- }
- } catch(BadImageFormatException f)
- {
- Report.Error(6, "Cannot load assembly (bad file format)" + f.FusionLog);
- } catch(FileLoadException f)
- {
- Report.Error(6, "Cannot load assembly " + f.FusionLog);
- } catch(ArgumentNullException)
- {
- Report.Error(6, "Cannot load assembly (null argument)");
- }
- }
-
- /// <summary>
- /// Loads all assemblies referenced on the command line
- /// </summary>
- static public void LoadReferences()
- {
- foreach(string r in references)
- LoadAssembly(r, false);
-
- foreach(string r in soft_references)
- LoadAssembly(r, true);
-
- return;
- }
-
- static void SetupDefaultDefines()
- {
- defines = new ArrayList ();
- defines.Add("__MonoCS__");
- defines.Add("__MCSDoc__");
- }
-
- static string [] LoadArgs(string file)
- {
- StreamReader f;
- ArrayList args = new ArrayList();
- string line;
- try
- {
- f = new StreamReader(file);
- } catch
- {
- return null;
- }
-
- StringBuilder sb = new StringBuilder ();
-
- while((line = f.ReadLine()) != null)
- {
- int t = line.Length;
-
- for (int i = 0; i < t; i++)
- {
- char c = line [i];
-
- if (c == '"' || c == '\'')
- {
- char end = c;
-
- for(i++; i < t; i++)
- {
- c = line [i];
-
- if (c == end)
- break;
- sb.Append (c);
- }
- } else if (c == ' ')
- {
- if (sb.Length > 0)
- {
- args.Add (sb.ToString ());
- sb.Length = 0;
- }
- } else
- sb.Append (c);
- }
- if (sb.Length > 0)
- {
- args.Add (sb.ToString ());
- sb.Length = 0;
- }
- }
-
- string[] ret_value = new string[args.Count];
- args.CopyTo(ret_value, 0);
-
- return ret_value;
- }
-
- //
- // Returns the directory where the system assemblies are installed
- //
- static string GetSystemDir()
- {
- Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
-
- foreach (Assembly a in assemblies)
- {
- string codebase = a.Location;
- if(codebase.EndsWith ("corlib.dll"))
- {
- return codebase.Substring(0, codebase.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
- }
- }
-
- Report.Error (-15, "Can not compute my system path");
- return "";
- }
-
- //
- // Given a path specification, splits the path from the file/pattern
- //
- static void SplitPathAndPattern(string spec, out string path, out string pattern)
- {
- int p = spec.LastIndexOf("/");
- if (p != -1){
- //
- // Windows does not like /file.cs, switch that to:
- // "\", "file.cs"
- //
- if (p == 0)
- {
- path = "\\";
- pattern = spec.Substring(1);
- } else
- {
- path = spec.Substring(0, p);
- pattern = spec.Substring(p + 1);
- }
- return;
- }
-
- p = spec.LastIndexOf("\\");
- if (p != -1)
- {
- path = spec.Substring(0, p);
- pattern = spec.Substring(p + 1);
- return;
- }
-
- path = ".";
- pattern = spec;
- }
-
- static void ProcessFile(string f)
- {
- if (first_source == null)
- first_source = f;
-
- Location.AddFile(f);
- }
-
- static void ProcessFiles()
- {
- Location.Initialize();
-
- foreach(SourceFile file in Location.SourceFiles)
- {
- parse(file);
- }
- }
-
- static void CompileFiles(string spec, bool recurse)
- {
- string path, pattern;
-
- SplitPathAndPattern(spec, out path, out pattern);
- if(pattern.IndexOf("*") == -1)
- {
- ProcessFile(spec);
- return;
- }
-
- string[] files = null;
- try
- {
- files = Directory.GetFiles (path, pattern);
- } catch (System.IO.DirectoryNotFoundException)
- {
- Report.Error (2001, "Source file `" + spec + "' could not be found");
- return;
- } catch (System.IO.IOException)
- {
- Report.Error (2001, "Source file `" + spec + "' could not be found");
- return;
- }
-
- foreach(string f in files)
- {
- ProcessFile(f);
- }
-
- if(!recurse)
- return;
-
- string[] dirs = null;
-
- try
- {
- dirs = Directory.GetDirectories (path);
- } catch { }
-
- foreach(string d in dirs)
- {
- // Don't include path in this string, as each
- // directory entry already does
- CompileFiles (d + "/" + pattern, true);
- }
- }
-
- static void DefineDefaultConfig()
- {
- //
- // For now the "default config" is harcoded into the compiler
- // we can move this outside later
- //
- string[] default_config =
- {
- "System",
- "System.Xml",
-#if false
- //
- // Is it worth pre-loading all this stuff?
- //
- "Accessibility",
- "System.Configuration.Install",
- "System.Data",
- "System.Design",
- "System.DirectoryServices",
- "System.Drawing.Design",
- "System.Drawing",
- "System.EnterpriseServices",
- "System.Management",
- "System.Messaging",
- "System.Runtime.Remoting",
- "System.Runtime.Serialization.Formatters.Soap",
- "System.Security",
- "System.ServiceProcess",
- "System.Web",
- "System.Web.RegularExpressions",
- "System.Web.Services",
- "System.Windows.Forms"
-#endif
- };
-
- int p = 0;
- foreach(string def in default_config)
- soft_references.Insert(p++, def);
- }
-
- static void SetOutputFile(string name)
- {
- output_file = name;
- }
-
- static void SetWarningLevel(string s)
- {
- int level = 0;
-
- try
- {
- level = Int32.Parse(s);
- } catch
- {
- Report.Error(1900, "--wlevel requires an value from 0 to 4");
- Environment.Exit(1);
- }
- if (level < 0 || level > 4)
- {
- Report.Error(1900, "Warning level must be 0 to 4");
- Environment.Exit(1);
- } else
- RootContext.WarningLevel = level;
- }
-
- static void Version()
- {
- string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
- Console.WriteLine("C# Document Generator Version {0}", version);
- Environment.Exit(0);
- }
-
- //
- // Currently handles the Unix-like command line options, but will be
- // deprecated in favor of the CSCParseOption, which will also handle the
- // options that start with a dash in the future.
- //
- static bool UnixParseOption(string arg, ref string [] args, ref int i)
- {
- switch (arg)
- {
-
- case "--version":
- Version();
- return true;
-
- case "/?": case "/h": case "/help":
- case "--help":
- Usage();
- Environment.Exit(0);
- return true;
-
- case "--about":
- About();
- Environment.Exit(0);
- return true;
-
- case "--recurse":
- if ((i + 1) >= args.Length)
- {
- Report.Error(5, "--recurse requires an argument");
- Environment.Exit(1);
- }
- CompileFiles(args [++i], true);
- return true;
-
- case "--linkresource":
- case "--linkres":
- if((i + 1) >= args.Length)
- {
- Usage();
- Report.Error(5, "Missing argument to --linkres");
- Environment.Exit(1);
- }
- if (resources == null)
- resources = new ArrayList();
-
- resources.Add(args[++i]);
- return true;
-
- case "--resource":
- case "--res":
- if ((i + 1) >= args.Length)
- {
- Usage();
- Report.Error(5, "Missing argument to --resource");
- Environment.Exit(1);
- }
- if (embedded_resources == null)
- embedded_resources = new ArrayList();
-
- embedded_resources.Add(args[++i]);
- return true;
-
- }
- return false;
- }
-
- //
- // Currently it is very basic option parsing, but eventually, this will
- // be the complete option parser
- //
- static bool CSCParseOption(string option, ref string [] args, ref int i)
- {
- int idx = option.IndexOf(":");
- string arg, value;
-
- if (idx == -1)
- {
- arg = option;
- value = "";
- } else
- {
- arg = option.Substring (0, idx);
- value = option.Substring (idx + 1);
- }
-
- switch(arg)
- {
- case "/nologo":
- return true;
-
- case "/recurse":
- if (value == ""){
- Report.Error (5, "/recurse requires an argument");
- Environment.Exit (1);
- }
- CompileFiles (value, true);
- return true;
-
- case "/help":
- case "/?":
- Usage ();
- Environment.Exit (0);
- return true;
-
- case "/linkresource":
- case "/linkres":
- if ((i + 1) >= args.Length)
- {
- Usage();
- Report.Error(5, "Missing argument to --linkres");
- Environment.Exit(1);
- }
- if (resources == null)
- resources = new ArrayList();
-
- resources.Add(args[++i]);
- return true;
-
- case "/resource":
- case "/res":
- if ((i + 1) >= args.Length)
- {
- Usage();
- Report.Error(5, "Missing argument to --resource");
- Environment.Exit(1);
- }
- if (embedded_resources == null)
- embedded_resources = new ArrayList();
-
- embedded_resources.Add(args[++i]);
- return true;
-
- }
- return false;
- }
-
- /// <summary>
- /// Parses the arguments, and drives the compilation
- /// process.
- /// </summary>
- ///
- /// <remarks>
- /// TODO: Mostly structured to debug the compiler
- /// now, needs to be turned into a real driver soon.
- /// </remarks>
- // [MonoTODO("Change error code for unknown argument to something reasonable")]
- static bool MainDriver (string [] args)
- {
- int i;
- bool parsing_options = true;
-
- try
- {
- encoding = Encoding.GetEncoding (28591);
- } catch
- {
- Console.WriteLine ("Error: could not load encoding 28591, trying 1252");
- encoding = Encoding.GetEncoding (1252);
- }
-
- references = new ArrayList();
- soft_references = new ArrayList();
- link_paths = new ArrayList();
-
- SetupDefaultDefines();
-
- //
- // Setup defaults
- //
- // This is not required because Assembly.Load knows about this
- // path.
- //
-
- int argc = args.Length;
- for (i = 0; i < argc; i++)
- {
- string arg = args [i];
-
- if (arg.StartsWith ("@")){
- string [] new_args, extra_args;
- string response_file = arg.Substring (1);
-
- if (response_file_list == null)
- response_file_list = new Hashtable ();
-
- if (response_file_list.Contains (response_file)){
- Report.Error (
- 1515, "Response file `" + response_file +
- "' specified multiple times");
- Environment.Exit (1);
- }
-
- response_file_list.Add (response_file, response_file);
-
- extra_args = LoadArgs (response_file);
- if (extra_args == null){
- Report.Error (2011, "Unable to open response file: " +
- response_file);
- return false;
- }
-
- new_args = new string [extra_args.Length + argc];
- args.CopyTo (new_args, 0);
- extra_args.CopyTo (new_args, argc);
- args = new_args;
- argc = new_args.Length;
- continue;
- }
-
- if (parsing_options){
- if (arg == "--"){
- parsing_options = false;
- continue;
- }
-
- if (arg.StartsWith ("-")){
- if (UnixParseOption (arg, ref args, ref i))
- continue;
-
- // Try a -CSCOPTION
- string csc_opt = "/" + arg.Substring (1);
- if (CSCParseOption (csc_opt, ref args, ref i))
- continue;
- } else {
- if (arg.StartsWith ("/")){
- if (CSCParseOption (arg, ref args, ref i))
- continue;
- }
- }
- }
-
- CompileFiles(arg, false);
- }
-
- ProcessFiles();
-
- if (first_source == null){
- Report.Error (2008, "No files to compile were specified");
- return false;
- }
-
- if (Report.Errors > 0)
- return false;
-
- //
- // Load Core Library for default compilation
- //
- if (RootContext.StdLib)
- references.Insert (0, "mscorlib");
-
- if (load_default_config)
- DefineDefaultConfig();
-
- if (Report.Errors > 0)
- {
- return false;
- }
-
- //
- // Load assemblies required
- //
- first_time = last_time = DateTime.Now;
-
- //ShowTime("Loading references");
-
- link_paths.Add(GetSystemDir());
- LoadReferences();
-
- //ShowTime(" References loaded");
-
- if(Report.Errors > 0)
- {
- return false;
- }
-
- //
- // Quick hack
- //
- // Unfortunately, I'll need to keep this. :-((
- output_file = "MCSDoc.dll";
-
- CodeGen.Init(output_file, null, want_debugging_support);
-
- TypeManager.AddModule(CodeGen.ModuleBuilder);
-
-#if false
- DateTime start = DateTime.Now;
- TypeManager.GetAssemblyNamespaces (output_file);
- DateTime end = DateTime.Now;
- //Console.WriteLine ("Loading namespaces: " + (end - start));
- start = DateTime.Now;
- //TypeManager.GetAllTypes ();
- end = DateTime.Now;
- //Console.WriteLine ("Getting Types: " + (end - start));
-#endif
-
- //
- // Before emitting, we need to get the core
- // types emitted from the user defined types
- // or from the system ones.
- //
- //ShowTime("Initializing Core Types");
-
- if(!RootContext.StdLib)
- {
- RootContext.ResolveCore();
- if(Report.Errors > 0)
- return false;
- }
-
- TypeManager.InitCoreTypes();
-
- //ShowTime(" Core Types done");
-
- //
- // The second pass of the compiler
- //
- //ShowTime("Resolving tree");
-
- RootContext.ResolveTree();
-
- //ShowTime("Populate tree");
-
- if (!RootContext.StdLib)
- RootContext.BootCorlib_PopulateCoreTypes();
- RootContext.PopulateTypes();
- RootContext.DefineTypes();
-
- TypeManager.InitCodeHelpers();
-
- if(Report.Errors > 0)
- {
- System.Console.WriteLine("Exiting after initializing code helpers...");
- return false;
- }
-
- TypeContainer root = RootContext.Tree.Types;
- Console.WriteLine("Root type: " + root.GetType());
-
- ManageAttributeTypes(RootContext.AttributeTypes);
-
- ManageTypeContainer(root);
- Console.WriteLine();
-
-/*
- ArrayList allns = Namespace.AllNamespaces;
- foreach(Namespace nsallns in allns)
- {
- if(nsallns.Name.Trim().Length > 0)
- {
- Console.WriteLine("->" + nsallns.Name);
- }
- }
-*/
-/*
- Hashtable nss = RootContext.Tree.Namespaces;
- //Hashtable nss = TypeManager.GetNamespaces();
-
- Console.WriteLine("Total namespaces: " + nss.Count);
- foreach(object objk in nss.Keys)
- {
- SourceFile sf = (SourceFile) objk;
- object obj = nss[objk];
- Console.WriteLine("-> " + sf.Name);
- //Console.WriteLine("\t-> " + ((Namespace)nss[sf.Name]).Name);
- //Console.WriteLine("->" + obj.ToString());
- //Console.WriteLine("->" + obj.GetType());
- if(obj is Hashtable)
- {
- Hashtable ht = (Hashtable) obj;
- foreach(object objht in ht.Keys)
- {
- Console.WriteLine("\t->" + ((Namespace)ht[objht]).Name);
- }
- }
- }
- Console.WriteLine();
-//*/
-
- return Report.Errors == 0;
- //
- // The code generator
- //
- // Now, I don't need the rest of the stuff.
-#if false
- if (timestamps)
- ShowTime ("Emitting code");
- ShowTotalTime ("Total so far");
- RootContext.EmitCode();
- if (timestamps)
- ShowTime (" done");
-
- if (Report.Errors > 0){
- return false;
- }
-
- if (timestamps)
- ShowTime ("Closing types");
-
- if (RootContext.WarningLevel >= 4)
- if (!Namespace.VerifyUsing ())
- return false;
-
- RootContext.CloseTypes ();
-
- PEFileKinds k = PEFileKinds.ConsoleApplication;
-
- if (target == Target.Library || target == Target.Module)
- k = PEFileKinds.Dll;
- else if (target == Target.Exe)
- k = PEFileKinds.ConsoleApplication;
- else if (target == Target.WinExe)
- k = PEFileKinds.WindowApplication;
-
- if (target == Target.Exe || target == Target.WinExe){
- MethodInfo ep = RootContext.EntryPoint;
-
- if (ep == null){
- if (Report.Errors == 0)
- Report.Error (5001, "Program " + output_file +
- " does not have an entry point defined");
- return false;
- }
-
- CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
- }
-
- //
- // Add the resources
- //
- if (resources != null){
- foreach (string spec in resources){
- string file, res;
- int cp;
-
- cp = spec.IndexOf (',');
- if (cp != -1){
- file = spec.Substring (0, cp);
- res = spec.Substring (cp + 1);
- } else
- file = res = spec;
-
- CodeGen.AssemblyBuilder.AddResourceFile (res, file);
- }
- }
-
- if (embedded_resources != null){
- object[] margs = new object [2];
- Type[] argst = new Type [2];
- argst [0] = argst [1] = typeof (string);
- MethodInfo embed_res = typeof (AssemblyBuilder).GetMethod ("EmbedResourceFile", argst);
- if (embed_res == null) {
- Report.Warning (0, new Location (-1), "Cannot embed resources on this runtime: try the Mono runtime instead.");
- } else {
- foreach (string spec in embedded_resources) {
- int cp;
-
- cp = spec.IndexOf (',');
- if (cp != -1){
- margs [0] = spec.Substring (cp + 1);
- margs [1] = spec.Substring (0, cp);
- } else
- margs [0] = margs [1] = spec;
-
- if (File.Exists ((string) margs [1]))
- embed_res.Invoke (CodeGen.AssemblyBuilder, margs);
- else {
- Report.Error (1566, "Can not find the resource " + margs [1]);
- }
- }
- }
- }
-
- if (Report.Errors > 0)
- return false;
-
- CodeGen.Save (output_file);
- if (timestamps) {
- ShowTime ("Saved output");
- ShowTotalTime ("Total");
- }
-
- Timer.ShowTimers ();
-
- if (Report.ExpectedError != 0){
- Console.WriteLine("Failed to report expected error " + Report.ExpectedError);
- Environment.Exit (1);
- return false;
- }
-#endif
-#if DEBUGME
- Console.WriteLine ("Size of strings held: " + DeclSpace.length);
- Console.WriteLine ("Size of strings short: " + DeclSpace.small);
-#endif
- //return (Report.Errors == 0);
- }
-
- static void ManageAttributeTypes(ArrayList types)
- {
- Console.WriteLine("\n Attributes:");
- foreach(TypeContainer tc in types)
- {
- Console.WriteLine(" " + tc.Name);
- }
- Console.WriteLine();
- }
-
- public static void ManageTypeContainer(TypeContainer tc)
- {
- //ManageTypeContainer("", tc);
- ListAllMembers(tc);
- }
-
- public static void ListAllMembers(TypeContainer root)
- {
- if(root.Namespace != null)
- {
- Console.WriteLine("Root Namespace: " + root.Namespace.Name);
- Console.WriteLine();
- }
- ListTCs("", root);
- }
-
- public static void ListEnums(string tab, ArrayList enums)
- {
- if(enums != null && enums.Count > 0)
- {
- foreach(Mono.CSharp.Enum e in enums)
- {
- Console.WriteLine("Enum: " + /* tab + */ e.Name);
- }
- }
- }
-
- public static void ListInterfaces(string tab, ArrayList interfaces)
- {
- if(interfaces != null && interfaces.Count > 0)
- {
- foreach(Interface i in interfaces)
- {
- Console.WriteLine("Iface: " + /* tab + */ i.Name);
- }
- }
- }
-
- public static void ListDelegates(string tab, ArrayList delegs)
- {
- if(delegs != null && delegs.Count > 0)
- {
- foreach(Delegate d in delegs)
- {
- Console.WriteLine("Deleg: " + /* tab + */ d.Name);
- }
- }
- }
-
- public static bool IsException(TypeContainer tc)
- {
- Type baseType = tc.BaseType;
- return (baseType == TypeManager.exception_type ||
- baseType.IsSubclassOf(TypeManager.exception_type));
- }
-
- public static bool IsAttribute(TypeContainer tc)
- {
- Type baseType = tc.BaseType;
- return (baseType == TypeManager.attribute_type ||
- baseType.IsSubclassOf(TypeManager.attribute_type));
- }
-
- public static void ListTCs(string tab, TypeContainer tc)
- {
- if(tc.Types != null && tc.Types.Count > 0)
- {
- foreach(TypeContainer objs in tc.Types)
- {
- string type = "Struct: ";
- if(objs is Class)
- type = "Class: ";
- Console.WriteLine(type + /*tab + */ objs.Name);// + " -:- " + objs.BaseType);
- if(IsException(objs))
- {
- Console.WriteLine("\t\t" + objs.Name + " is Exception");
- } else if(IsAttribute(objs))
- {
- Console.WriteLine("\t\t" + objs.Name + " is Attribute");
- }
- ListTCs(tab + "\t", objs);
- }
- }
- ListEnums(tab, tc.Enums);
- ListInterfaces(tab, tc.Interfaces);
- ListDelegates(tab, tc.Delegates);
- }
-
- public static void ManageTypeContainer(string tab, TypeContainer tc)
- {
- foreach(object current in tc.Types)
- {
- DeclSpace ds = (DeclSpace)current;
- //Console.Write("\t" + ds.Namespace.Name);
- //Console.WriteLine("" + ds.Documentation);
- Console.WriteLine(tab + "::" + ds.Name);
- if(tc.Parent != null)
- {
- Console.WriteLine("TypeContainer of : \"" + ds.Name + "\" = \"" + tc.Parent.Name + "\"");
- }
- if(ds is TypeContainer)
- {
- //Console.WriteLine();
- /*
- if(ds is Class)
- {
- Class c = (Class)ds;
- ArrayList b = c.Bases;
- if(b != null && b.Count > 0)
- {
- foreach(object currentBase in b)
- {
- //System.Console.WriteLine("Base of {0}: {1}\tTYPE: {3}",
- // ds.Name, currentBase.ToString(),
- // currentBase.GetType());
- System.Console.WriteLine("Base of " + ds.Name + ": " + currentBase.ToString()
- + "\tTYPE: " + currentBase.GetType());
- }
- }
- }*/
- ManageTypeContainer(tab + "\t", (TypeContainer)ds);
- }
- }
- }
- }
-}
+//
+// Author: Gaurav Vaish <mas...@us...>
+//
+// Licensed under the terms of the GNU GPL.
+//
+// (C) 2003 Gaurav Vaish
+// Original Authors: Miguel, Ravi, Martin
+//
+
+namespace Mono.CSharp
+{
+ using System;
+ using System.Reflection;
+ using System.Reflection.Emit;
+ using System.Collections;
+ using System.IO;
+ using System.Text;
+ using System.Globalization;
+ using Mono.Languages;
+
+ enum Target {
+ Library, Exe, Module, WinExe
+ };
+
+ /// <summary>
+ /// The compiler driver.
+ /// </summary>
+ public class Driver
+ {
+
+ //
+ // Assemblies references to be linked. Initialized with
+ // mscorlib.dll here.
+ static ArrayList references;
+
+ //
+ // If any of these fail, we ignore the problem. This is so
+ // that we can list all the assemblies in Windows and not fail
+ // if they are missing on Linux.
+ //
+ static ArrayList soft_references;
+
+ // Lookup paths
+ static ArrayList link_paths;
+
+ // Whether we want Yacc to output its progress
+ static bool yacc_verbose = false;
+
+ static string first_source;
+
+ //static Target target = Target.Exe;
+ //static string target_ext = ".exe";
+
+ static bool want_debugging_support = false;
+
+ //static bool parse_only = false;
+ //static bool timestamps = false;
+ //static bool pause = false;
+
+ //
+ // Whether to load the initial config file (what CSC.RSP has by default)
+ //
+ static bool load_default_config = true;
+
+ static Hashtable response_file_list;
+
+ //
+ // A list of resource files
+ //
+ static ArrayList resources;
+ static ArrayList embedded_resources;
+
+ //
+ // An array of the defines from the command line
+ //
+ static ArrayList defines;
+
+ //
+ // Output file
+ //
+ static string output_file = null;
+
+ //
+ // Last time we took the time
+ //
+ static DateTime last_time, first_time;
+
+ //
+ // Encoding: ISO-Latin1 is 28591
+ //
+ static Encoding encoding;
+
+ //
+ // Whether the user has specified a different encoder manually
+ //
+ static bool using_default_encoder = true;
+
+ public static void ShowTime(string msg)
+ {
+ DateTime now = DateTime.Now;
+ TimeSpan span = now - last_time;
+ last_time = now;
+
+ Console.WriteLine (
+ "[{0:00}:{1:000}] {2}",
+ (int) span.TotalSeconds, span.Milliseconds, msg);
+ }
+
+ public static void ShowTotalTime(string msg)
+ {
+ DateTime now = DateTime.Now;
+ TimeSpan span = now - first_time;
+ last_time = now;
+
+ Console.WriteLine (
+ "[{0:00}:{1:000}] {2}",
+ (int) span.TotalSeconds, span.Milliseconds, msg);
+ }
+
+ // MonoTODO("Change error code for aborted compilation to something reasonable")]
+ static void parse(SourceFile file)
+ {
+ CSharpParser parser;
+ Stream input;
+
+ try
+ {
+ input = File.OpenRead(file.Name);
+ } catch
+ {
+ Report.Error(2001, "Source file '" + file.Name + "' could not be opened");
+ return;
+ }
+
+ StreamReader reader = new StreamReader(input, encoding, using_default_encoder);
+
+ parser = new CSharpParser (reader, file, defines);
+ parser.yacc_verbose = yacc_verbose;
+ try
+ {
+ parser.parse();
+ } catch(Exception ex)
+ {
+ Report.Error(666, "Compilation aborted: " + ex);
+ } finally {
+ input.Close ();
+ }
+ }
+
+ static void Usage()
+ {
+ // Doclet defaultDoclet = new CSDoclet(...);
+ // string options = defaultDoclet.UsageString();
+ Console.WriteLine("" +
+ "C# Document Generator, (C) 2003 Gaurav Vaish\n" +
+ "\n" +
+ "usage: \n" +
+ "csdoc [options] [namespace-names] [sourcefiles] [@files] \n" +
+ " -overview <file> Read overview documentation from HTML file\n" +
+ " -public Show only public classes and members\n" +
+ " -protected Show protected/public classes and members\n" +
+ " -internal Show internal/protected/public classes and members\n" +
+ " -private Show all classes and members\n" +
+ " -doclet <class> Generate output via alternate doclet\n" +
+ //" -verbose Be verbose of what is being done\n" +
+ //" --reference:ASS Reference the specified assembly\n" +
+ " -r:ASS Same as --reference\n" +
+ " --help Display command line options and exit\n" +
+ " --about About the CSDoc Document Generator\n" +
+ "\n" +
+ "Resources:\n" +
+ " --linkresource FILE[,ID] Links FILE as a resource\n" +
+ " --resource FILE[,ID] Embed FILE as a resource\n" +
+ "\n" +
+ "Options can be of the form -option or /option" + /* options */
+ "");
+ }
+
+ static void About()
+ {
+ Console.WriteLine("" +
+ " The CSDoc Document Generator is (C) 2003, Gaurav Vaish.\n" +
+ " The source code is released under the terms of the GNU GPL.\n" +
+ "\n" +
+ " For more information on CSDoc, visit the website:\n" +
+ " http://csdoc.sourceforge.net\n" +
+ "\n" +
+ " The application is mastermind of Gaurav Vaish.\n" +
+ "");
+ }
+
+ public static int Main(string[] args)
+ {
+ bool ok = MainDriver(args);
+
+ if (ok && Report.Errors == 0)
+ {
+ Console.Write("Compilation succeeded");
+ if(Report.Warnings > 0)
+ {
+ Console.Write(" - {0} warning(s)", Report.Warnings);
+ }
+ Console.WriteLine();
+ return 0;
+ } else
+ {
+ Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
+ Report.Errors, Report.Warnings);
+ return 1;
+ }
+ }
+
+ static public void LoadAssembly(string assembly, bool soft)
+ {
+ Assembly a;
+ string total_log = "";
+
+ try
+ {
+ char[] path_chars = { '/', '\\', '.' };
+
+ if (assembly.IndexOfAny(path_chars) != -1)
+ {
+ a = Assembly.LoadFrom(assembly);
+ } else
+ {
+ a = Assembly.Load(assembly);
+ }
+ TypeManager.AddAssembly(a);
+
+ } catch(FileNotFoundException)
+ {
+ foreach (string dir in link_paths)
+ {
+ string full_path = Path.Combine(dir, assembly);
+ if(!assembly.EndsWith(".dll"))
+ full_path += ".dll";
+
+ try
+ {
+ a = Assembly.LoadFrom(full_path);
+ TypeManager.AddAssembly(a);
+ return;
+ } catch (FileNotFoundException ff)
+ {
+ total_log += ff.FusionLog;
+ continue;
+ }
+ }
+ if(!soft)
+ {
+ Report.Error(6, "Cannot find assembly `" + assembly + "'" );
+ Console.WriteLine("Log: \n" + total_log);
+ }
+ } catch(BadImageFormatException f)
+ {
+ Report.Error(6, "Cannot load assembly (bad file format)" + f.FusionLog);
+ } catch(FileLoadException f)
+ {
+ Report.Error(6, "Cannot load assembly " + f.FusionLog);
+ } catch(ArgumentNullException)
+ {
+ Report.Error(6, "Cannot load assembly (null argument)");
+ }
+ }
+
+ /// <summary>
+ /// Loads all assemblies referenced on the command line
+ /// </summary>
+ static public void LoadReferences()
+ {
+ foreach(string r in references)
+ LoadAssembly(r, false);
+
+ foreach(string r in soft_references)
+ LoadAssembly(r, true);
+
+ return;
+ }
+
+ static void SetupDefaultDefines()
+ {
+ defines = new ArrayList ();
+ defines.Add("__MonoCS__");
+ defines.Add("__MCSDoc__");
+ }
+
+ static string [] LoadArgs(string file)
+ {
+ StreamReader f;
+ ArrayList args = new ArrayList();
+ string line;
+ try
+ {
+ f = new StreamReader(file);
+ } catch
+ {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder ();
+
+ while((line = f.ReadLine()) != null)
+ {
+ int t = line.Length;
+
+ for (int i = 0; i < t; i++)
+ {
+ char c = line [i];
+
+ if (c == '"' || c == '\'')
+ {
+ char end = c;
+
+ for(i++; i < t; i++)
+ {
+ c = line [i];
+
+ if (c == end)
+ break;
+ sb.Append (c);
+ }
+ } else if (c == ' ')
+ {
+ if (sb.Length > 0)
+ {
+ args.Add (sb.ToString ());
+ sb.Length = 0;
+ }
+ } else
+ sb.Append (c);
+ }
+ if (sb.Length > 0)
+ {
+ args.Add (sb.ToString ());
+ sb.Length = 0;
+ }
+ }
+
+ string[] ret_value = new string[args.Count];
+ args.CopyTo(ret_value, 0);
+
+ return ret_value;
+ }
+
+ //
+ // Returns the directory where the system assemblies are installed
+ //
+ static string GetSystemDir()
+ {
+ Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
+
+ foreach (Assembly a in assemblies)
+ {
+ string codebase = a.Location;
+ if(codebase.EndsWith ("corlib.dll"))
+ {
+ return codebase.Substring(0, codebase.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
+ }
+ }
+
+ Report.Error (-15, "Can not compute my system path");
+ return "";
+ }
+
+ //
+ // Given a path specification, splits the path from the file/pattern
+ //
+ static void SplitPathAndPattern(string spec, out string path, out string pattern)
+ {
+ int p = spec.LastIndexOf("/");
+ if (p != -1){
+ //
+ // Windows does not like /file.cs, switch that to:
+ // "\", "file.cs"
+ //
+ if (p == 0)
+ {
+ path = "\\";
+ pattern = spec.Substring(1);
+ } else
+ {
+ path = spec.Substring(0, p);
+ pattern = spec.Substring(p + 1);
+ }
+ return;
+ }
+
+ p = spec.LastIndexOf("\\");
+ if (p != -1)
+ {
+ path = spec.Substring(0, p);
+ pattern = spec.Substring(p + 1);
+ return;
+ }
+
+ path = ".";
+ pattern = spec;
+ }
+
+ static void ProcessFile(string f)
+ {
+ if (first_source == null)
+ first_source = f;
+
+ Location.AddFile(f);
+ }
+
+ static void ProcessFiles()
+ {
+ Location.Initialize();
+
+ foreach(SourceFile file in Location.SourceFiles)
+ {
+ parse(file);
+ }
+ }
+
+ static void CompileFiles(string spec, bool recurse)
+ {
+ string path, pattern;
+
+ SplitPathAndPattern(spec, out path, out pattern);
+ if(pattern.IndexOf("*") == -1)
+ {
+ ProcessFile(spec);
+ return;
+ }
+
+ string[] files = null;
+ try
+ {
+ files = Directory.GetFiles (path, pattern);
+ } catch (System.IO.DirectoryNotFoundException)
+ {
+ Report.Error (2001, "Source file `" + spec + "' could not be found");
+ return;
+ } catch (System.IO.IOException)
+ {
+ Report.Error (2001, "Source file `" + spec + "' could not be found");
+ return;
+ }
+
+ foreach(string f in files)
+ {
+ ProcessFile(f);
+ }
+
+ if(!recurse)
+ return;
+
+ string[] dirs = null;
+
+ try
+ {
+ dirs = Directory.GetDirectories (path);
+ } catch { }
+
+ foreach(string d in dirs)
+ {
+ // Don't include path in this string, as each
+ // directory entry already does
+ CompileFiles (d + "/" + pattern, true);
+ }
+ }
+
+ static void DefineDefaultConfig()
+ {
+ //
+ // For now the "default config" is harcoded into the compiler
+ // we can move this outside later
+ //
+ string[] default_config =
+ {
+ "System",
+ "System.Xml",
+#if false
+ //
+ // Is it worth pre-loading all this stuff?
+ //
+ "Accessibility",
+ "System.Configuration.Install",
+ "System.Data",
+ "System.Design",
+ "System.DirectoryServices",
+ "System.Drawing.Design",
+ "System.Drawing",
+ "System.EnterpriseServices",
+ "System.Management",
+ "System.Messaging",
+ "System.Runtime.Remoting",
+ "System.Runtime.Serialization.Formatters.Soap",
+ "System.Security",
+ "System.ServiceProcess",
+ "System.Web",
+ "System.Web.RegularExpressions",
+ "System.Web.Services",
+ "System.Windows.Forms"
+#endif
+ };
+
+ int p = 0;
+ foreach(string def in default_config)
+ soft_references.Insert(p++, def);
+ }
+
+ static void SetOutputFile(string name)
+ {
+ output_file = name;
+ }
+
+ static void SetWarningLevel(string s)
+ {
+ int level = 0;
+
+ try
+ {
+ level = Int32.Parse(s);
+ } catch
+ {
+ Report.Error(1900, "--wlevel requires an value from 0 to 4");
+ Environment.Exit(1);
+ }
+ if (level < 0 || level > 4)
+ {
+ Report.Error(1900, "Warning level must be 0 to 4");
+ Environment.Exit(1);
+ } else
+ RootContext.WarningLevel = level;
+ }
+
+ static void Version()
+ {
+ string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
+ Console.WriteLine("C# Document Generator Version {0}", version);
+ Environment.Exit(0);
+ }
+
+ //
+ // Currently handles the Unix-like command line options, but will be
+ // deprecated in favor of the CSCParseOption, which will also handle the
+ // options that start with a dash in the future.
+ //
+ static bool UnixParseOption(string arg, ref string [] args, ref int i)
+ {
+ switch (arg)
+ {
+
+ case "--version":
+ Version();
+ return true;
+
+ case "/?": case "/h": case "/help":
+ case "--help":
+ Usage();
+ Environment.Exit(0);
+ return true;
+
+ case "--about":
+ About();
+ Environment.Exit(0);
+ return true;
+
+ case "--recurse":
+ if ((i + 1) >= args.Length)
+ {
+ Report.Error(5, "--recurse requires an argument");
+ Environment.Exit(1);
+ }
+ CompileFiles(args [++i], true);
+ return true;
+
+ case "--linkresource":
+ case "--linkres":
+ if((i + 1) >= args.Length)
+ {
+ Usage();
+ Report.Error(5, "Missing argument to --linkres");
+ Environment.Exit(1);
+ }
+ if (resources == null)
+ resources = new ArrayList();
+
+ resources.Add(args[++i]);
+ return true;
+
+ case "--resource":
+ case "--res":
+ if ((i + 1) >= args.Length)
+ {
+ Usage();
+ Report.Error(5, "Missing argument to --resource");
+ Environment.Exit(1);
+ }
+ if (embedded_resources == null)
+ embedded_resources = new ArrayList();
+
+ embedded_resources.Add(args[++i]);
+ return true;
+
+ }
+ return false;
+ }
+
+ //
+ // Currently it is very basic option parsing, but eventually, this will
+ // be the complete option parser
+ //
+ static bool CSCParseOption(string option, ref string [] args, ref int i)
+ {
+ int idx = option.IndexOf(":");
+ string arg, value;
+
+ if (idx == -1)
+ {
+ arg = option;
+ value = "";
+ } else
+ {
+ arg = option.Substring (0, idx);
+ value = option.Substring (idx + 1);
+ }
+
+ switch(arg)
+ {
+ case "/nologo":
+ return true;
+
+ case "/recurse":
+ if (value == ""){
+ Report.Error (5, "/recurse requires an argument");
+ Environment.Exit (1);
+ }
+ CompileFiles (value, true);
+ return true;
+
+ case "/help":
+ case "/?":
+ Usage ();
+ Environment.Exit (0);
+ return true;
+
+ case "/linkresource":
+ case "/linkres":
+ if ((i + 1) >= args.Length)
+ {
+ Usage();
+ Report.Error(5, "Missing argument to --linkres");
+ Environment.Exit(1);
+ }
+ if (resources == null)
+ resources = new ArrayList();
+
+ resources.Add(args[++i]);
+ return true;
+
+ case "/resource":
+ case "/res":
+ if ((i + 1) >= args.Length)
+ {
+ Usage();
+ Report.Error(5, "Missing argument to --resource");
+ Environment.Exit(1);
+ }
+ if (embedded_resources == null)
+ embedded_resources = new ArrayList();
+
+ embedded_resources.Add(args[++i]);
+ return true;
+
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Parses the arguments, and drives the compilation
+ /// process.
+ /// </summary>
+ ///
+ /// <remarks>
+ /// TODO: Mostly structured to debug the compiler
+ /// now, needs to be turned into a real driver soon.
+ /// </remarks>
+ // [MonoTODO("Change error code for unknown argument to something reasonable")]
+ static bool MainDriver (string [] args)
+ {
+ int i;
+ bool parsing_options = true;
+
+ try
+ {
+ encoding = Encoding.GetEncoding (28591);
+ } catch
+ {
+ Console.WriteLine ("Error: could not load encoding 28591, trying 1252");
+ encoding = Encoding.GetEncoding (1252);
+ }
+
+ references = new ArrayList();
+ soft_references = new ArrayList();
+ link_paths = new ArrayList();
+
+ SetupDefaultDefines();
+
+ //
+ // Setup defaults
+ //
+ // This is not required because Assembly.Load knows about this
+ // path.
+ //
+
+ int argc = args.Length;
+ for (i = 0; i < argc; i++)
+ {
+ string arg = args [i];
+
+ if (arg.StartsWith ("@")){
+ string [] new_args, extra_args;
+ string response_file = arg.Substring (1);
+
+ if (response_file_list == null)
+ response_file_list = new Hashtable ();
+
+ if (response_file_list.Contains (response_file)){
+ Report.Error (
+ 1515, "Response file `" + response_file +
+ "' specified multiple times");
+ Environment.Exit (1);
+ }
+
+ response_file_list.Add (response_file, response_file);
+
+ extra_args = LoadArgs (response_file);
+ if (extra_args == null){
+ Report.Error (2011, "Unable to open response file: " +
+ response_file);
+ return false;
+ }
+
+ new_args = new string [extra_args.Length + argc];
+ args.CopyTo (new_args, 0);
+ extra_args.CopyTo (new_args, argc);
+ args = new_args;
+ argc = new_args.Length;
+ continue;
+ }
+
+ if (parsing_options){
+ if (arg == "--"){
+ parsing_options = false;
+ continue;
+ }
+
+ if (arg.StartsWith ("-")){
+ if (UnixParseOption (arg, ref args, ref i))
+ continue;
+
+ // Try a -CSCOPTION
+ string csc_opt = "/" + arg.Substring (1);
+ if (CSCParseOption (csc_opt, ref args, ref i))
+ continue;
+ } else {
+ if (arg.StartsWith ("/")){
+ if (CSCParseOption (arg, ref args, ref i))
+ continue;
+ }
+ }
+ }
+
+ CompileFiles(arg, false);
+ }
+
+ ProcessFiles();
+
+ if (first_source == null){
+ Report.Error (2008, "No files to compile were specified");
+ return false;
+ }
+
+ if (Report.Errors > 0)
+ return false;
+
+ //
+ // Load Core Library for default compilation
+ //
+ if (RootContext.StdLib)
+ references.Insert (0, "mscorlib");
+
+ if (load_default_config)
+ DefineDefaultConfig();
+
+ if (Report.Errors > 0)
+ {
+ return false;
+ }
+
+ //
+ // Load assemblies required
+ //
+ first_time = last_time = DateTime.Now;
+
+ //ShowTime("Loading references");
+
+ link_paths.Add(GetSystemDir());
+ LoadReferences();
+
+ //ShowTime(" References loaded");
+
+ if(Report.Errors > 0)
+ {
+ return false;
+ }
+
+ //
+ // Quick hack
+ //
+ // Unfortunately, I'll need to keep this. :-((
+ output_file = "MCSDoc.dll";
+
+ CodeGen.Init(output_file, null, want_debugging_support);
+
+ TypeManager.AddModule(CodeGen.ModuleBuilder);
+
+#if false
+ DateTime start = DateTime.Now;
+ TypeManager.GetAssemblyNamespaces (output_file);
+ DateTime end = DateTime.Now;
+ //Console.WriteLine ("Loading namespaces: " + (end - start));
+ start = DateTime.Now;
+ //TypeManager.GetAllTypes ();
+ end = DateTime.Now;
+ //Console.WriteLine ("Getting Types: " + (end - start));
+#endif
+
+ //
+ // Before emitting, we need to get the core
+ // types emitted from the user defined types
+ // or from the system ones.
+ //
+ //ShowTime("Initializing Core Types");
+
+ if(!RootContext.StdLib)
+ {
+ RootContext.ResolveCore();
+ if(Report.Errors > 0)
+ return false;
+ }
+
+ TypeManager.InitCoreTypes();
+
+ //ShowTime(" Core Types done");
+
+ //
+ // The second pass of the compiler
+ //
+ //ShowTime("Resolving tree");
+
+ RootContext.ResolveTree();
+
+ //ShowTime("Populate tree");
+
+ if (!RootContext.StdLib)
+ RootContext.BootCorlib_PopulateCoreTypes();
+ RootContext.PopulateTypes();
+ RootContext.DefineTypes();
+
+ TypeManager.InitCodeHelpers();
+
+ if(Report.Errors > 0)
+ {
+ System.Console.WriteLine("Exiting after initializing code helpers...");
+ return false;
+ }
+
+ TypeContainer root = RootContext.Tree.Types;
+ Console.WriteLine("Root type: " + root.GetType());
+
+ ManageAttributeTypes(RootContext.AttributeTypes);
+
+ ManageTypeContainer(root);
+ Console.WriteLine();
+
+/*
+ ArrayList allns = Namespace.AllNamespaces;
+ foreach(Namespace nsallns in allns)
+ {
+ if(nsallns.Name.Trim().Length > 0)
+ {
+ Console.WriteLine("->" + nsallns.Name);
+ }
+ }
+*/
+/*
+ Hashtable nss = RootContext.Tree.Namespaces;
+ //Hashtable nss = TypeManager.GetNamespaces();
+
+ Console.WriteLine("Total namespaces: " + nss.Count);
+ foreach(object objk in nss.Keys)
+ {
+ SourceFile sf = (SourceFile) objk;
+ object obj = nss[objk];
+ Console.WriteLine("-> " + sf.Name);
+ //Console.WriteLine("\t-> " + ((Namespace)nss[sf.Name]).Name);
+ //Console.WriteLine("->" + obj.ToString());
+ //Console.WriteLine("->" + obj.GetType());
+ if(obj is Hashtable)
+ {
+ Hashtable ht = (Hashtable) obj;
+ foreach(object objht in ht.Keys)
+ {
+ Console.WriteLine("\t->" + ((Namespace)ht[objht]).Name);
+ }
+ }
+ }
+ Console.WriteLine();
+//*/
+
+ return Report.Errors == 0;
+ //
+ // The code generator
+ //
+ // Now, I don't need the rest of the stuff.
+#if false
+ if (timestamps)
+ ShowTime ("Emitting code");
+ ShowTotalTime ("Total so far");
+ RootContext.EmitCode();
+ if (timestamps)
+ ShowTime (" done");
+
+ if (Report.Errors > 0){
+ return false;
+ }
+
+ if (timestamps)
+ ShowTime ("Closing types");
+
+ if (RootContext.WarningLevel >= 4)
+ if (!Namespace.VerifyUsing ())
+ return false;
+
+ RootContext.CloseTypes ();
+
+ PEFileKinds k = PEFileKinds.ConsoleApplication;
+
+ if (target == Target.Library || target == Target.Module)
+ k = PEFileKinds.Dll;
+ else if (target == Target.Exe)
+ k = PEFileKinds.ConsoleApplication;
+ else if (target == Target.WinExe)
+ k = PEFileKinds.WindowApplication;
+
+ if (target == Target.Exe || target == Target.WinExe){
+ MethodInfo ep = RootContext.EntryPoint;
+
+ if (ep == null){
+ if (Report.Errors == 0)
+ Report.Error (5001, "Program " + output_file +
+ " does not have an entry point defined");
+ return false;
+ }
+
+ CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
+ }
+
+ //
+ // Add the resources
+ //
+ if (resources != null){
+ foreach (string spec in resources){
+ string file, res;
+ int cp;
+
+ cp = spec.IndexOf (',');
+ if (cp != -1){
+ file = spec.Substring (0, cp);
+ res = spec.Substring (cp + 1);
+ } else
+ file = res = spec;
+
+ CodeGen.AssemblyBuilder.AddResourceFile (res, file);
+ }
+ }
+
+ if (embedded_resources != null){
+ object[] margs = new object [2];
+ Type[] argst = new Type [2];
+ argst [0] = argst [1] = typeof (string);
+ MethodInfo embed_res = typeof (AssemblyBuilder).GetMethod ("EmbedResourceFile", argst);
+ if (embed_res == null) {
+ Report.Warning (0, new Location (-1), "Cannot embed resources on this runtime: try the Mono runtime instead.");
+ } else {
+ foreach (string spec in embedded_resources) {
+ int cp;
+
+ cp = spec.IndexOf (',');
+ if (cp != -1){
+ margs [0] = spec.Substring (cp + 1);
+ margs [1] = spec.Substring (0, cp);
+ } else
+ margs [0] = margs [1] = spec;
+
+ if (File.Exists ((string) margs [1]))
+ embed_res.Invoke (CodeGen.AssemblyBuilder, margs);
+ else {
+ Report.Error (1566, "Can not find the resource " + margs [1]);
+ }
+ }
+ }
+ }
+
+ if (Report.Errors > 0)
+ return false;
+
+ CodeGen.Save (output_file);
+ if (timestamps) {
+ ShowTime ("Saved output");
+ ShowTotalTime ("Total");
+ }
+
+ Timer.ShowTimers ();
+
+ if (Report.ExpectedError != 0){
+ Console.WriteLine("Failed to report expected error " + Report.ExpectedError);
+ Environment.Exit (1);
+ return false;
+ }
+#endif
+#if DEBUGME
+ Console.WriteLine ("Size of strings held: " + DeclSpace.length);
+ Console.WriteLine ("Size of strings short: " + DeclSpace.small);
+#endif
+ //return (Report.Errors == 0);
+ }
+
+ static void ManageAttributeTypes(ArrayList types)
+ {
+ if(types == null || types.Count == 0)
+ return;
+ Console.WriteLine("\n Attributes:");
+ foreach(TypeContainer tc in types)
+ {
+ Console.WriteLine(" " + tc.Name);
+ }
+ Console.WriteLine();
+ }
+
+ public static void ManageTypeContainer(TypeContainer tc)
+ {
+ //ManageTypeContainer("", tc);
+ ListAllMembers(tc);
+ }
+
+ public static void ListAllMembers(TypeContainer root)
+ {
+ if(root.Namespace != null && root.Namespace.Name.Length > 0)
+ {
+ Console.WriteLine("Root Namespace: " + root.Namespace.Name);
+ Console.WriteLine();
+ }
+ ListTCs("", root);
+ }
+
+ public static void ListEnums(string tab, ArrayList enums)
+ {
+ if(enums != null && enums.Count > 0)
+ {
+ foreach(Mono.CSharp.Enum e in enums)
+ {
+ if(e.Documentation.Length > 0)
+ {
+ Console.WriteLine("Enum: " + /* tab + */ e.Name);
+ Console.WriteLine("Documentation: \n" + e.Documentation);
+ Console.WriteLine();
+ }
+ }
+ }
+ }
+
+ public static void ListInterfaces(string tab, ArrayList interfaces)
+ {
+ if(interfaces != null && interfaces.Count > 0)
+ {
+ foreach(Interface i in interfaces)
+ {
+ if(i.Documentation.Length > 0)
+ {
+ Console.WriteLine("Iface: " + /* tab + */ i.Name);
+ Console.WriteLine("Documentation: \n" + i.Documentation);
+ Console.WriteLine();
+ }
+ }
+ }
+ }
+
+ public static void ListDelegates(string tab, ArrayList delegs)
+ {
+ if(delegs != null && delegs.Count > 0)
+ {
+ foreach(Delegate d in delegs)
+ {
+ if(d.Documentation.Length > 0)
+ {
+ Console.WriteLine("Deleg: " + /* tab + */ d.Name);
+ Console.WriteLine("Documentation: \n" + d.Documentation);
+ Console.WriteLine();
+ }
+ }
+ }
+ }
+
+ public static bool IsException(TypeContainer tc)
+ {
+ Type baseType = tc.BaseType;
+ return (baseType == TypeManager.exception_type ||
+ baseType.IsSubclassOf(TypeManager.exception_type));
+ }
+
+ public static bool IsAttribute(TypeContainer tc)
+ {
+ Type baseType = tc.BaseType;
+ return (baseType == TypeManager.attribute_type ||
+ baseType.IsSubclassOf(TypeManager.attribute_type));
+ }
+
+ public static void ListTCs(string tab, TypeContainer tc)
+ {
+ if(tc.Types != null && tc.Types.Count > 0)
+ {
+ foreach(TypeContainer objs in tc.Types)
+ {
+ if(objs.Documentation.Trim().Length > 0)
+ {
+ string type = "Struct: ";
+ if(objs is Class)
+ type = "Class: ";
+ Console.WriteLine(type + /*tab + */ objs.Name);// + " -:- " + objs.BaseType);
+ if(IsException(objs))
+ {
+ Console.WriteLine("\t\t" + objs.Name + " is Exception");
+ } else if(IsAttribute(objs))
+ {
+ Console.WriteLine("\t\t" + objs.Name + " is Attribute");
+ }
+ Console.WriteLine("D...
[truncated message content] |