diff options
-rwxr-xr-x | mcs/mcs/ChangeLog | 19 | ||||
-rwxr-xr-x | mcs/mcs/class.cs | 58 | ||||
-rwxr-xr-x | mcs/mcs/codegen.cs | 7 | ||||
-rwxr-xr-x | mcs/mcs/cs-parser.jay | 34 | ||||
-rwxr-xr-x | mcs/mcs/decl.cs | 5 | ||||
-rw-r--r-- | mcs/mcs/delegate.cs | 5 | ||||
-rwxr-xr-x | mcs/mcs/driver.cs | 364 | ||||
-rwxr-xr-x | mcs/mcs/ecore.cs | 2 | ||||
-rwxr-xr-x | mcs/mcs/enum.cs | 4 | ||||
-rwxr-xr-x | mcs/mcs/expression.cs | 6 | ||||
-rwxr-xr-x | mcs/mcs/interface.cs | 5 | ||||
-rw-r--r-- | mcs/mcs/report.cs | 58 | ||||
-rwxr-xr-x | mcs/mcs/rootcontext.cs | 57 | ||||
-rwxr-xr-x | mcs/mcs/tree.cs | 7 |
14 files changed, 367 insertions, 264 deletions
diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog index 09eae412282..4a31b4fcd87 100755 --- a/mcs/mcs/ChangeLog +++ b/mcs/mcs/ChangeLog @@ -1,5 +1,24 @@ 2001-12-18 Miguel de Icaza <miguel@ximian.com> + * class.cs (Method.Define): Allow the entry point to be in a + specific class. + + * driver.cs: Rewrite the argument handler to clean it up a bit. + + * rootcontext.cs: Made it just an auxiliary namespace feature by + making everything static. + + * driver.cs: Adapt code to use RootContext type name instead of + instance variable. + + * delegate.cs: Remove RootContext argument. + + * class.cs: (Struct, TypeContainer, Class): Remove RootContext + argument. + + * class.cs (Event.Define): The lookup can fail. + + * cs-tokenizer.cs: Begin implementation of pre-procesor. * expression.cs: Resolve the this instance before invoking the code. diff --git a/mcs/mcs/class.cs b/mcs/mcs/class.cs index deae5886225..5ddabce7704 100755 --- a/mcs/mcs/class.cs +++ b/mcs/mcs/class.cs @@ -94,8 +94,8 @@ namespace Mono.CSharp { public bool Inherited; - public TypeContainer (RootContext rc, TypeContainer parent, string name, Location l) - : base (rc, name, l) + public TypeContainer (TypeContainer parent, string name, Location l) + : base (name, l) { string n; types = new ArrayList (); @@ -1590,9 +1590,8 @@ namespace Mono.CSharp { Modifiers.ABSTRACT | Modifiers.SEALED; - public Class (RootContext rc, TypeContainer parent, string name, int mod, - Attributes attrs, Location l) - : base (rc, parent, name, l) + public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l) + : base (parent, name, l) { int accmods; @@ -1627,9 +1626,8 @@ namespace Mono.CSharp { Modifiers.INTERNAL | Modifiers.PRIVATE; - public Struct (RootContext rc, TypeContainer parent, string name, int mod, - Attributes attrs, Location l) - : base (rc, parent, name, l) + public Struct (TypeContainer parent, string name, int mod, Attributes attrs, Location l) + : base (parent, name, l) { int accmods; @@ -1891,6 +1889,15 @@ namespace Mono.CSharp { return type_return_type; } + void DuplicatEntryPoint (MethodInfo b) + { + Report.Error ( + 17, Location, + "Program `" + RootContext.CodeGen.FileName + + "' has more than one entry point defined: `" + + b.DeclaringType.Name + "." + b.Name + "'"); + } + // // Creates the type // @@ -2102,16 +2109,22 @@ namespace Mono.CSharp { // // FIXME: Allow pluggable entry point, check arguments, etc. // - if (Name == "Main"){ - if ((ModFlags & Modifiers.STATIC) != 0){ - parent.RootContext.EntryPoint = MethodBuilder; - - // - // FIXME: Verify that the method signature - // is valid for an entry point, and report - // error 28 if not. - // + if (Name == "Main" && + ((ModFlags & Modifiers.STATIC) != 0) && + (RootContext.MainClass == null || + RootContext.MainClass == parent.TypeBuilder.FullName)){ + if (RootContext.EntryPoint != null){ + DuplicatEntryPoint (MethodBuilder); + DuplicatEntryPoint (RootContext.EntryPoint); } + + RootContext.EntryPoint = MethodBuilder; + + // + // FIXME: Verify that the method signature + // is valid for an entry point, and report + // error 28 if not. + // } // @@ -2441,6 +2454,9 @@ namespace Mono.CSharp { if (t == null) return; + + if (!TypeContainer.AsAccessible (t, ModFlags)) + return; FieldBuilder = parent.TypeBuilder.DefineField ( Name, t, Modifiers.FieldAttr (ModFlags)); @@ -2859,20 +2875,22 @@ namespace Mono.CSharp { return; MethodAttributes m_attr = Modifiers.MethodAttr (ModFlags); - EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName; - MethodBuilder mb; EventType = parent.LookupType (Type, false); + if (EventType == null) + return; + if (!TypeContainer.AsAccessible (EventType, ModFlags)) + return; + if (!EventType.IsSubclassOf (TypeManager.delegate_type)) { Report.Error (66, Location, "'" + parent.Name + "." + Name + "' : event must be of a delegate type"); return; } - Type [] parameters = new Type [1]; parameters [0] = EventType; diff --git a/mcs/mcs/codegen.cs b/mcs/mcs/codegen.cs index b6155cd5497..649196047d4 100755 --- a/mcs/mcs/codegen.cs +++ b/mcs/mcs/codegen.cs @@ -42,11 +42,14 @@ namespace Mono.CSharp { return name.Substring (0, pos); } + + public string FileName; public CodeGen (string name, string output) { AssemblyName an; - + + FileName = output; an = new AssemblyName (); an.Name = TrimExt (Basename (name)); current_domain = AppDomain.CurrentDomain; @@ -157,7 +160,7 @@ namespace Mono.CSharp { this.ig = ig; TypeContainer = parent; - CheckState = parent.RootContext.Checked; + CheckState = RootContext.Checked; IsStatic = (code_flags & Modifiers.STATIC) != 0; ReturnType = return_type; IsConstructor = is_constructor; diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index 95ad31fce1a..69e0a841056 100755 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -72,18 +72,10 @@ namespace Mono.CSharp // </summmary> bool parsing_indexer; - // <summary> - // Used to record all types defined - // </summary> - Tree tree; - // // An out-of-band stack. // Stack oob_stack; - - RootContext rc; - %} %token EOF @@ -298,7 +290,7 @@ using_namespace_directive namespace_declaration : NAMESPACE qualified_identifier { - current_namespace = tree.RecordNamespace (current_namespace, (string) $2); + current_namespace = RootContext.Tree.RecordNamespace (current_namespace, (string) $2); } namespace_body opt_semicolon { @@ -587,11 +579,11 @@ struct_declaration Struct new_struct; string full_struct_name = MakeName ((string) $4); - new_struct = new Struct (rc, current_container, full_struct_name, (int) $2, + new_struct = new Struct (current_container, full_struct_name, (int) $2, (Attributes) $1, lexer.Location); current_container = new_struct; current_container.Namespace = current_namespace; - tree.RecordStruct (full_struct_name, new_struct); + RootContext.Tree.RecordStruct (full_struct_name, new_struct); } opt_struct_interfaces struct_body @@ -1001,7 +993,7 @@ interface_declaration Interface new_interface; string full_interface_name = MakeName ((string) $4); - new_interface = new Interface (rc, current_container, full_interface_name, (int) $2, + new_interface = new Interface (current_container, full_interface_name, (int) $2, (Attributes) $1, lexer.Location); if (current_interface != null) { Location l = lexer.Location; @@ -1009,7 +1001,7 @@ interface_declaration } current_interface = new_interface; new_interface.Namespace = current_namespace; - tree.RecordInterface (full_interface_name, new_interface); + RootContext.Tree.RecordInterface (full_interface_name, new_interface); } opt_interface_base interface_body @@ -1493,7 +1485,7 @@ enum_declaration opt_semicolon { string name = (string) $4; - Enum e = new Enum (rc, (string) $5, (int) $2, name, (Attributes) $1, lexer.Location); + Enum e = new Enum ((string) $5, (int) $2, name, (Attributes) $1, lexer.Location); foreach (VariableDeclaration ev in (ArrayList) $6){ CheckDef (e.AddEnumMember (ev.identifier, @@ -1565,7 +1557,7 @@ delegate_declaration CLOSE_PARENS SEMICOLON { - Delegate del = new Delegate (rc, (string) $4, (int) $2, + Delegate del = new Delegate ((string) $4, (int) $2, MakeName ((string) $5), (Parameters) $7, (Attributes) $1, lexer.Location); @@ -1579,7 +1571,7 @@ delegate_declaration CLOSE_PARENS SEMICOLON { - Delegate del = new Delegate (rc, "System.Void", (int) $2, (string) $5, (Parameters) $7, + Delegate del = new Delegate ("System.Void", (int) $2, (string) $5, (Parameters) $7, (Attributes) $1, lexer.Location); CheckDef (current_container.AddDelegate (del), del.Name); @@ -2384,11 +2376,11 @@ class_declaration Class new_class; string full_class_name = MakeName ((string) $4); - new_class = new Class (rc, current_container, full_class_name, (int) $2, + new_class = new Class (current_container, full_class_name, (int) $2, (Attributes) $1, lexer.Location); current_container = new_class; current_container.Namespace = current_namespace; - tree.RecordClass (full_class_name, new_class); + RootContext.Tree.RecordClass (full_class_name, new_class); } opt_class_base class_body @@ -3547,14 +3539,12 @@ public Tokenizer Lexer { } } -public CSharpParser(RootContext rc, string name, System.IO.Stream input) +public CSharpParser (string name, System.IO.Stream input) { current_namespace = new Namespace (null, ""); - this.rc = rc; - this.tree = rc.Tree; this.name = name; this.input = input; - current_container = tree.Types; + current_container = RootContext.Tree.Types; current_container.Namespace = current_namespace; oob_stack = new Stack (); diff --git a/mcs/mcs/decl.cs b/mcs/mcs/decl.cs index aa1bbffe71c..c4891d3df51 100755 --- a/mcs/mcs/decl.cs +++ b/mcs/mcs/decl.cs @@ -52,8 +52,6 @@ namespace Mono.CSharp { } } - public readonly RootContext RootContext; - string name, basename; /// <summary> @@ -106,10 +104,9 @@ namespace Mono.CSharp { /// </summary> protected Hashtable defined_names; - public DeclSpace (RootContext rc, string name, Location l) + public DeclSpace (string name, Location l) { this.name = name; - this.RootContext = rc; this.basename = name.Substring (1 + name.LastIndexOf ('.')); defined_names = new Hashtable (); Location = l; diff --git a/mcs/mcs/delegate.cs b/mcs/mcs/delegate.cs index b559da97023..5509eda8eb1 100644 --- a/mcs/mcs/delegate.cs +++ b/mcs/mcs/delegate.cs @@ -34,8 +34,6 @@ namespace Mono.CSharp { public MethodBuilder BeginInvokeBuilder;
public MethodBuilder EndInvokeBuilder;
- public readonly RootContext RootContext;
-
Type [] param_types;
Type ret_type;
@@ -51,10 +49,9 @@ namespace Mono.CSharp { Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Delegate (RootContext rc, string type, int mod_flags, string name, Parameters param_list,
+ public Delegate (string type, int mod_flags, string name, Parameters param_list,
Attributes attrs, Location loc)
{
- this.RootContext = rc;
this.Name = name;
this.ReturnType = type;
this.mod_flags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PUBLIC);
diff --git a/mcs/mcs/driver.cs b/mcs/mcs/driver.cs index a20b41861e8..fc9748e024f 100755 --- a/mcs/mcs/driver.cs +++ b/mcs/mcs/driver.cs @@ -29,25 +29,23 @@ namespace Mono.CSharp // // Assemblies references to be linked. Initialized with // mscorlib.dll here. - ArrayList references; + static ArrayList references; // Lookup paths - ArrayList link_paths; + static ArrayList link_paths; - RootContext context; + static bool yacc_verbose = false; - bool yacc_verbose = false; + static int error_count = 0; - int error_count = 0; + static string first_source; - string first_source; + static Target target = Target.Exe; + static string target_ext = ".exe"; - Target target = Target.Exe; - string target_ext = ".exe"; - - bool parse_only = false; + static bool parse_only = false; - public int parse (string input_file) + static int parse (string input_file) { CSharpParser parser; System.IO.Stream input; @@ -60,7 +58,7 @@ namespace Mono.CSharp return 1; } - parser = new CSharpParser (context, input_file, input); + parser = new CSharpParser (input_file, input); parser.yacc_verbose = yacc_verbose; try { errors = parser.parse ();
@@ -73,49 +71,69 @@ namespace Mono.CSharp return errors; } - public void Usage () + static void Usage (bool is_error) { Console.WriteLine ( - "compiler [options] source-files\n\n" + - "-v Verbose parsing\n"+ - "-o Specifies output file\n" + - "-L Specifies path for loading assemblies\n" + - "--checked Set default context to checked\n" + - "--fatal Makes errors fatal\n" + - "--nostdlib Does not load core libraries\n" + - "--optimize Optimizes\n" + - "--parse Only parses the source file\n" + - "--probe X L Probes for the source to generate code X on line L\n" + - "--target Specifies the target (exe, winexe, library, module)\n" + - "-r References an assembly\n"); - + "Mono C# compiler, (C) 2001 Ximian, Inc.\n" + + "mcs [options] source-files\n" + + " --about About the Mono C# compiler\n" + + " --checked Set default context to checked\n" + + " --fatal Makes errors fatal\n" + + " -L PATH Adds PATH to the assembly link path\n" + + " --nostdlib Does not load core libraries\n" + + " --nowarn XXX Ignores warning number XXX\n" + + " -o FNAME Specifies output file\n" + + " --optimize Optimizes\n" + + " --parse Only parses the source file\n" + + " --probe X L Probes for the source to generate code X on line L\n" + + " --target KIND Specifies the target (KIND is one of: exe, winexe, " + + "library, module)\n" + + " --unsafe Allows unsafe code\n" + + " --werror Treat warnings as errors\n" + + " --wlevel LEVEL Sets warning level (the highest is 4, the default)\n" + + " -r References an assembly\n" + + " -v Verbose parsing (for debugging the parser)\n"); + if (is_error) + error_count++; } - public static void error (string msg) + static void About () + { + Console.WriteLine ( + "The Mono C# compiler is (C) 2001 Ximian, Inc.\n\n" + + "The compiler source code is released under the terms of the GNU GPL\n\n" + + + "For more information on Mono, visit the project Web site\n" + + " http://www.go-mono.com\n\n" + + + "The compiler was written by Miguel de Icaza and Ravi Pratap"); + } + + static void error (string msg) { Console.WriteLine ("Error: " + msg); } - public static void notice (string msg) + static void notice (string msg) { Console.WriteLine (msg); } - public static int Main(string[] args) + public static int Main (string[] args) { - Driver driver = new Driver (args); - - return driver.error_count; + MainDriver (args); + + return error_count; } - public int LoadAssembly (string assembly) + static public int LoadAssembly (string assembly) { Assembly a; string total_log = ""; try { a = Assembly.Load (assembly); - context.TypeManager.AddAssembly (a); + RootContext.TypeManager.AddAssembly (a); return 0; } catch (FileNotFoundException){ foreach (string dir in link_paths){ @@ -123,7 +141,7 @@ namespace Mono.CSharp try { a = Assembly.LoadFrom (full_path); - context.TypeManager.AddAssembly (a); + RootContext.TypeManager.AddAssembly (a); return 0; } catch (FileNotFoundException ff) { total_log += ff.FusionLog; @@ -152,7 +170,7 @@ namespace Mono.CSharp /// <summary> /// Loads all assemblies referenced on the command line /// </summary> - public int LoadReferences () + static public int LoadReferences () { int errors = 0; @@ -172,13 +190,11 @@ namespace Mono.CSharp /// TODO: Mostly structured to debug the compiler /// now, needs to be turned into a real driver soon. /// </remarks> - public Driver (string [] args) + static void MainDriver (string [] args) { - ITreeDump generator = null; int errors = 0, i; string output_file = null; - context = new RootContext (); references = new ArrayList (); link_paths = new ArrayList (); @@ -189,113 +205,164 @@ namespace Mono.CSharp // path. // link_paths.Add ("file:///C:/WINNT/Microsoft.NET/Framework/v1.0.2914"); - - for (i = 0; i < args.Length; i++){ + + int argc = args.Length; + for (i = 0; i < argc; i++){ string arg = args [i]; - - try { - if (arg.StartsWith ("-")){ - if (arg == "-v"){ - yacc_verbose = true; - continue; + + if (arg.StartsWith ("-")){ + switch (arg){ + case "-v": + yacc_verbose = true; + continue; + + case "--parse": + parse_only = true; + continue; + + case "--main": case "-m": + if ((i + 1) >= argc){ + Usage (true); + return; } + RootContext.MainClass = args [++i]; + continue; + + case "--unsafe": + RootContext.Unsafe = true; + break; - if (arg == "--parse"){ - parse_only = true; - continue; - } + case "--optimize": + RootContext.Optimize = true; + continue; - if (arg == "--optimize"){ - RootContext.Optimize = true; - continue; - } + case "--help": + Usage (false); + return; - if (arg == "--probe"){ - int code, line; + case "--probe": { + int code, line; + + code = Int32.Parse (args [++i], 0); + line = Int32.Parse (args [++i], 0); + Report.SetProbe (code, line); + continue; + } - code = Int32.Parse (args [++i], 0); - line = Int32.Parse (args [++i], 0); - Report.SetProbe (code, line); - continue; + case "-o": case "--output": + if ((i + 1) >= argc){ + Usage (true); + return; } + output_file = args [++i]; + continue; - if (arg == "-z"){ - generator.ParseOptions (args [++i]); - continue; - } + case "--checked": + RootContext.Checked = true; + continue; - if (arg == "-o" || arg == "--output"){ - try { - output_file = args [++i]; - } catch (Exception){ - error ("Could not write to `"+args [i]); - error_count++; - return; - } - continue; + case "--target": + if ((i + 1) >= argc){ + Usage (true); + return; } - if (arg == "--checked"){ - context.Checked = true; - continue; - } - - if (arg == "--target"){ - string type = args [++i]; + string type = args [++i]; + switch (type){ + case "library": + target = Target.Library; + target_ext = ".dll"; + break; + + case "exe": + target = Target.Exe; + break; + + case "winexe": + target = Target.WinExe; + break; - switch (type){ - case "library": - target = Target.Library; - target_ext = ".dll"; - break; - - case "exe": - target = Target.Exe; - break; - - case "winexe": - target = Target.WinExe; - break; - - case "module": - target = Target.Module; - target_ext = ".dll"; - break; - } - continue; + case "module": + target = Target.Module; + target_ext = ".dll"; + break; } + continue; + + case "-r": + if ((i + 1) >= argc){ + Usage (true); + return; + } + + references.Add (args [++i]); + continue; - if (arg == "-r"){ - references.Add (args [++i]); - continue; + case "-L": + if ((i + 1) >= argc){ + Usage (true); + return; } + link_paths.Add (args [++i]); + continue; + + case "--nostdlib": + RootContext.StdLib = false; + continue; - if (arg == "-L"){ - link_paths.Add (args [++i]); - continue; + case "--fatal": + Report.Fatal = true; + continue; + + case "--werror": + Report.WarningsAreErrors = true; + continue; + + case "--nowarn": + if ((i + 1) >= argc){ + Usage (true); + return; } + int warn; - if (arg == "--nostdlib"){ - context.StdLib = false; - continue; + try { + warn = Int32.Parse (args [++i]); + } catch { + Usage (true); + return; + } + Report.SetIgnoreWarning (warn); + continue; + + case "--wlevel": + if ((i + 1) >= argc){ + Usage (true); + error_count++; + return; } + int level; - if (arg == "--fatal"){ - Report.Fatal = true; - continue; + try { + level = Int32.Parse (args [++i]); + } catch { + Usage (true); + return; } - Usage (); - error_count++; + if (level < 0 || level > 4){ + Report.Error (1900, "Warning level must be 0 to 4"); + return; + } else + RootContext.WarningLevel = level; + continue; + + case "--about": + About (); + return; + + default: + Usage (true); return; } - } catch (System.IndexOutOfRangeException){ - Usage (); - error_count++; - return; - } catch (System.FormatException) { - Usage (); - error_count++; - return; } if (first_source == null) @@ -326,7 +393,7 @@ namespace Mono.CSharp // // Load Core Library for default compilation // - if (context.StdLib){ + if (RootContext.StdLib){ references.Insert (0, "mscorlib"); references.Insert (1, "System"); } @@ -346,35 +413,6 @@ namespace Mono.CSharp return; } - - // - // Dumping the parsed tree. - // - // This code generation interface is only here - // for debugging the parser. - // - if (generator != null){ - if (output_file == null){ - error ("Error: no output file specified"); - return; - } - - Stream output_stream = File.Create (output_file); - StreamWriter output = new StreamWriter (output_stream); - - errors += generator.Dump (context.Tree, output); - - if (errors > 0){ - error ("Compilation failed"); - return; - } else - notice ("Compilation successful"); - - output.Flush (); - output.Close (); - } - - error_count = errors; // @@ -386,22 +424,22 @@ namespace Mono.CSharp output_file = first_source.Substring (0, pos) + target_ext; } - context.CodeGen = new CodeGen (output_file, output_file); + RootContext.CodeGen = new CodeGen (output_file, output_file); // // Before emitting, we need to get the core // types emitted from the user defined types // or from the system ones. // - context.TypeManager.InitCoreTypes (); + RootContext.TypeManager.InitCoreTypes (); - context.TypeManager.AddModule (context.CodeGen.ModuleBuilder); + RootContext.TypeManager.AddModule (RootContext.CodeGen.ModuleBuilder); // // The second pass of the compiler // - context.ResolveTree (); - context.PopulateTypes (); + RootContext.ResolveTree (); + RootContext.PopulateTypes (); if (Report.Errors > 0){ error ("Compilation failed"); @@ -411,14 +449,14 @@ namespace Mono.CSharp // // The code generator // - context.EmitCode (); + RootContext.EmitCode (); if (Report.Errors > 0){ error ("Compilation failed"); return; } - context.CloseTypes (); + RootContext.CloseTypes (); PEFileKinds k = PEFileKinds.ConsoleApplication; @@ -430,7 +468,7 @@ namespace Mono.CSharp k = PEFileKinds.WindowApplication; if (target == Target.Exe || target == Target.WinExe){ - MethodInfo ep = context.EntryPoint; + MethodInfo ep = RootContext.EntryPoint; if (ep == null){ Report.Error (5001, "Program " + output_file + @@ -438,10 +476,10 @@ namespace Mono.CSharp return; } - context.CodeGen.AssemblyBuilder.SetEntryPoint (ep, k); + RootContext.CodeGen.AssemblyBuilder.SetEntryPoint (ep, k); } - context.CodeGen.Save (output_file); + RootContext.CodeGen.Save (output_file); if (Report.Errors > 0){ error ("Compilation failed"); diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index 165f4c1b981..8db395c5c09 100755 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -423,7 +423,7 @@ namespace Mono.CSharp { do { MemberInfo [] mi; - mi = ec.TypeContainer.RootContext.TypeManager.FindMembers ( + mi = RootContext.TypeManager.FindMembers ( current_type, mt, bf | BindingFlags.DeclaredOnly, Type.FilterName, name); diff --git a/mcs/mcs/enum.cs b/mcs/mcs/enum.cs index 0f91e1ccd24..7ccd46e1131 100755 --- a/mcs/mcs/enum.cs +++ b/mcs/mcs/enum.cs @@ -47,8 +47,8 @@ namespace Mono.CSharp { Modifiers.INTERNAL | Modifiers.PRIVATE; - public Enum (RootContext rc, string type, int mod_flags, string name, Attributes attrs, Location l) - : base (rc, name, l) + public Enum (string type, int mod_flags, string name, Attributes attrs, Location l) + : base (name, l) { this.BaseType = type; this.EnumName = name; diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index 610f5516fc6..6d0f31c324a 100755 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -3583,7 +3583,7 @@ namespace Mono.CSharp { byte [] data = MakeByteBlob (ArrayData, underlying_type, loc); if (data != null) { - fb = ec.TypeContainer.RootContext.MakeStaticData (data); + fb = RootContext.MakeStaticData (data); if (is_expression) ig.Emit (OpCodes.Dup); @@ -4455,7 +4455,7 @@ namespace Mono.CSharp { if (ilist == null) ilist = Indexers.GetIndexersForType ( - indexer_type, ec.TypeContainer.RootContext.TypeManager, ea.loc); + indexer_type, RootContext.TypeManager, ea.loc); // @@ -4484,7 +4484,7 @@ namespace Mono.CSharp { if (ilist == null) ilist = Indexers.GetIndexersForType ( - indexer_type, ec.TypeContainer.RootContext.TypeManager, ea.loc); + indexer_type, RootContext.TypeManager, ea.loc); if (ilist != null && ilist.setters != null && ilist.setters.Count > 0){ set_arguments = (ArrayList) ea.Arguments.Clone (); diff --git a/mcs/mcs/interface.cs b/mcs/mcs/interface.cs index bb0d69c36c9..a7b03e2f6b9 100755 --- a/mcs/mcs/interface.cs +++ b/mcs/mcs/interface.cs @@ -65,9 +65,8 @@ namespace Mono.CSharp { Modifiers.INTERNAL | Modifiers.PRIVATE; - public Interface (RootContext rc, TypeContainer parent, string name, int mod, - Attributes attrs, Location l) - : base (rc, name, l) + public Interface (TypeContainer parent, string name, int mod, Attributes attrs, Location l) + : base (name, l) { this.mod_flags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE); this.parent = parent; diff --git a/mcs/mcs/report.cs b/mcs/mcs/report.cs index 9dc6fd3e3bd..5626b656c9e 100644 --- a/mcs/mcs/report.cs +++ b/mcs/mcs/report.cs @@ -7,6 +7,7 @@ // using System; +using System.Collections; namespace Mono.CSharp { @@ -21,6 +22,9 @@ namespace Mono.CSharp { // for debugging the compiler static bool fatal; + // whether we consider warnings to be errors. + static bool warnings_are_errors; + // // If the error code is reported on the given line, // then the process exits with a unique error code. @@ -29,6 +33,11 @@ namespace Mono.CSharp { // static int probe_error = 0; static int probe_line = 0; + + // + // Keeps track of the warnings that we are ignoring + // + static Hashtable warning_ignore_table; static void Check (int code) { @@ -57,12 +66,32 @@ namespace Mono.CSharp { static public void Warning (int code, Location l, string text) { - Console.WriteLine (l.Name + "(" + l.Row + - "): warning CS"+code+": " + text); - warnings++; - Check (code); + if (warning_ignore_table != null){ + if (warning_ignore_table.Contains (code)) + return; + } + + if (warnings_are_errors) + Error (code, l, text); + else { + string row; + + if (Location.IsNull (l)) + row = ""; + else + row = l.Row.ToString (); + + Console.WriteLine (l.Name + "(" + row + "): warning CS"+code+": " + text); + warnings++; + Check (code); + } } + static public void Warning (int code, string text) + { + Warning (code, Location.Null, text); + } + static public void Error (int code, string text) { string msg = "error CS"+code+": "+text; @@ -71,13 +100,6 @@ namespace Mono.CSharp { Check (code); } - static public void Warning (int code, string text) - { - Console.WriteLine ("warning CS"+code+": "+text); - warnings++; - Check (code); - } - static public void Message (Message m) { if (m is ErrorMessage) @@ -86,6 +108,14 @@ namespace Mono.CSharp { Warning (m.code, m.text); } + static public void SetIgnoreWarning (int code) + { + if (warning_ignore_table == null) + warning_ignore_table = new Hashtable (); + + warning_ignore_table [code] = true; + } + static public void SetProbe (int code, int line) { probe_error = code; @@ -119,6 +149,12 @@ namespace Mono.CSharp { return fatal; } } + + static public bool WarningsAreErrors { + set { + warnings_are_errors = true; + } + } } public class Message { diff --git a/mcs/mcs/rootcontext.cs b/mcs/mcs/rootcontext.cs index ae262b0b52b..03ab3577669 100755 --- a/mcs/mcs/rootcontext.cs +++ b/mcs/mcs/rootcontext.cs @@ -20,17 +20,17 @@ namespace Mono.CSharp { // // Contains the parsed tree // - Tree tree; + static Tree tree; // // Contains loaded assemblies and our generated code as we go. // - public TypeManager TypeManager; + static public TypeManager TypeManager; // // The System.Reflection.Emit CodeGenerator // - CodeGen cg; + static CodeGen cg; static public bool Optimize; @@ -55,31 +55,35 @@ namespace Mono.CSharp { // or abstract as well as the parent names (to implement new, // override). // - ArrayList type_container_resolve_order; - ArrayList interface_resolve_order; + static ArrayList type_container_resolve_order; + static ArrayList interface_resolve_order; // // Holds a reference to the Private Implementation Details // class. // - TypeBuilder impl_details_class; + static TypeBuilder impl_details_class; + public static int WarningLevel = 4; + // // Constructor // - public RootContext () + static RootContext () { - tree = new Tree (this); + tree = new Tree (); TypeManager = new TypeManager (); } - public Tree Tree { + static public Tree Tree { get { return tree; } } - public CodeGen CodeGen { + static public string MainClass; + + static public CodeGen CodeGen { get { return cg; } @@ -98,9 +102,14 @@ namespace Mono.CSharp { // // The default compiler checked state // - public bool Checked = false; + static public bool Checked = false; - string MakeFQN (string nsn, string name) + // + // Whether to allow Unsafe code + // + static public bool Unsafe = false; + + static string MakeFQN (string nsn, string name) { string prefix = (nsn == "" ? "" : nsn + "."); @@ -114,7 +123,7 @@ namespace Mono.CSharp { // It creates the TypeBuilder's as it processes the user defined // types. // </remarks> - public void ResolveTree () + static public void ResolveTree () { // // Interfaces are processed first, as classes and @@ -164,7 +173,7 @@ namespace Mono.CSharp { // methods, fields, etc) we need to "Define" them before we // can save the Assembly // </remarks> - public void CloseTypes () + static public void CloseTypes () { TypeContainer root = Tree.Types; @@ -200,7 +209,7 @@ namespace Mono.CSharp { // // Returns: Type or null if they type can not be found. // - public Type LookupType (DeclSpace ds, string name, bool silent) + static public Type LookupType (DeclSpace ds, string name, bool silent) { Type t; @@ -243,12 +252,12 @@ namespace Mono.CSharp { // This is the silent version of LookupType, you can use this // to `probe' for a type // </summary> - public Type LookupType (TypeContainer tc, string name) + static public Type LookupType (TypeContainer tc, string name) { return LookupType (tc, name, true); } - public bool IsNamespace (string name) + static public bool IsNamespace (string name) { Namespace ns; @@ -268,7 +277,7 @@ namespace Mono.CSharp { // // This is invoked after all interfaces, structs and classes // have been defined through `ResolveTree' - public void PopulateTypes () + static public void PopulateTypes () { if (interface_resolve_order != null) foreach (Interface iface in interface_resolve_order) @@ -292,7 +301,7 @@ namespace Mono.CSharp { } - public void EmitCode () + static public void EmitCode () { if (type_container_resolve_order != null) foreach (TypeContainer tc in type_container_resolve_order) @@ -302,7 +311,7 @@ namespace Mono.CSharp { // <summary> // Compiling against Standard Libraries property. // </summary> - public bool StdLib { + static public bool StdLib { get { return stdlib; } @@ -312,7 +321,7 @@ namespace Mono.CSharp { } } - public static ModuleBuilder ModuleBuilder { + static public ModuleBuilder ModuleBuilder { get { return mb; } @@ -322,12 +331,12 @@ namespace Mono.CSharp { // Public Field, used to track which method is the public entry // point. // - public MethodInfo EntryPoint; + static public MethodInfo EntryPoint; // // These are used to generate unique names on the structs and fields. // - int field_count; + static int field_count; // // Makes an initialized struct, returns the field builder that @@ -343,7 +352,7 @@ namespace Mono.CSharp { // // 2. Define the field on the impl_details_class // - public FieldBuilder MakeStaticData (byte [] data) + static public FieldBuilder MakeStaticData (byte [] data) { FieldBuilder fb; int size = data.Length; diff --git a/mcs/mcs/tree.cs b/mcs/mcs/tree.cs index 62d4ff474cb..2dd754ccbf7 100755 --- a/mcs/mcs/tree.cs +++ b/mcs/mcs/tree.cs @@ -53,12 +53,9 @@ namespace Mono.CSharp // </summary> Hashtable namespaces; - RootContext rc; - - public Tree (RootContext rc) + public Tree () { - root_types = new TypeContainer (rc, null, "", new Location (-1)); - this.rc = rc; + root_types = new TypeContainer (null, "", new Location (-1)); } |