2002-08-31 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
authorRafael Teixeira <monoman@gmail.com>
Fri, 13 Sep 2002 23:05:34 +0000 (23:05 -0000)
committerRafael Teixeira <monoman@gmail.com>
Fri, 13 Sep 2002 23:05:34 +0000 (23:05 -0000)
* merged many sources from mcs/mcs, to resync

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

19 files changed:
mcs/mbas/ChangeLog
mcs/mbas/attribute.cs
mcs/mbas/cfold.cs
mcs/mbas/class.cs
mcs/mbas/codegen.cs
mcs/mbas/decl.cs
mcs/mbas/delegate.cs
mcs/mbas/driver.cs
mcs/mbas/ecore.cs
mcs/mbas/enum.cs
mcs/mbas/expression.cs
mcs/mbas/interface.cs
mcs/mbas/location.cs
mcs/mbas/namespace.cs
mcs/mbas/parameter.cs
mcs/mbas/pending.cs
mcs/mbas/rootcontext.cs
mcs/mbas/statement.cs
mcs/mbas/typemanager.cs

index fab0909903b736343e5cf3d669e80c771533ed5b..74e31ad639d0cb310e2259c9dd9ecd8f818a8560 100644 (file)
@@ -1,3 +1,6 @@
+2002-08-31  Rafael Teixeira <rafaelteixeirabr@hotmail.com>
+       * merged many sources from mcs/mcs, to resync
+
 2002-09-03  Rafael Teixeira <rafaelteixeirabr@hotmail.com>
        * integrated new version of Mono.GetOptions (reflection/attributes-based)
 
index b5f6965120b8327466b7a28f9ef158705a816be7..988c435b52fd42bf05d8405f96fdbd0e40ead498 100644 (file)
@@ -155,6 +155,7 @@ namespace Mono.CSharp {
                                        return null;
 
                                e = a.Expr;
+
                                if (e is Constant) {
                                        pos_values [i] = ((Constant) e).GetValue ();
                                } else if (e is TypeOf) {
@@ -225,7 +226,9 @@ namespace Mono.CSharp {
                                                                this.Inherited = (bool) o;
                                                }
                                                
-                                       } else { 
+                                       } else if (e is TypeOf) {
+                                               prop_values.Add (((TypeOf) e).TypeArg);
+                                       } else {
                                                Error_AttributeArgumentNotValid ();
                                                return null;
                                        }
@@ -248,7 +251,9 @@ namespace Mono.CSharp {
                                                object value = ((Constant) e).GetValue ();
                                                
                                                field_values.Add (value);
-                                       } else { 
+                                       } else if (e is TypeOf) {
+                                               field_values.Add (((TypeOf) e).TypeArg);
+                                       } else {
                                                Error_AttributeArgumentNotValid ();
                                                return null;
                                        }
@@ -273,6 +278,23 @@ namespace Mono.CSharp {
                                Error_AttributeConstructorMismatch (Location);
                                return null;
                        }
+
+                       //
+                       // Now we perform some checks on the positional args as they
+                       // cannot be null for a constructor which expects a parameter
+                       // of type object
+                       //
+
+                       ParameterData pd = Invocation.GetParameterData (constructor);
+
+                       for (int j = 0; j < pos_arg_count; ++j) {
+                               Argument a = (Argument) pos_args [j];
+                               
+                               if (a.Expr is NullLiteral && pd.ParameterType (j) == TypeManager.object_type) {
+                                       Error_AttributeArgumentNotValid ();
+                                       return null;
+                               }
+                       }
                        
                        PropertyInfo [] prop_info_arr = new PropertyInfo [prop_infos.Count];
                        FieldInfo [] field_info_arr = new FieldInfo [field_infos.Count];
@@ -290,12 +312,11 @@ namespace Mono.CSharp {
                                        (ConstructorInfo) constructor, pos_values,
                                        prop_info_arr, prop_values_arr,
                                        field_info_arr, field_values_arr); 
+
                        } catch (NullReferenceException) {
-                               Report.Warning (
-                                       -23, Location,
-                                       "The compiler can not encode this attribute in the Mono runtime\n" +
-                                       "\tdue to a known bug in it.  We know about the problem and will\n" +
-                                       "\tfix it as soon as possible.");
+                               // 
+                               // Don't know what to do here
+                               //
                        } catch {
                                //
                                // Sample:
index 9da0bc08bf8a82066c15b6b0cd47380501970008..3e8267fca4d27f73cd12978ec228ae2f8de15bb2 100644 (file)
@@ -27,7 +27,7 @@ namespace Mono.CSharp {
                //   (uint, uint)
                //   (int, int)
                //
-               static void DoConstantNumericPromotions (Binary.Operator oper,
+               static void DoConstantNumericPromotions (EmitContext ec, Binary.Operator oper,
                                                         ref Constant left, ref Constant right,
                                                         Location loc)
                {
@@ -116,6 +116,39 @@ namespace Mono.CSharp {
                                }
 
                                return;
+                       } else if (left is EnumConstant || right is EnumConstant){
+                               //
+                               // If either operand is an enum constant, the other one must
+                               // be implicitly convertable to that enum's underlying type.
+                               //
+                               EnumConstant match;
+                               Constant other;
+                               if (left is EnumConstant){
+                                       other = right;
+                                       match = (EnumConstant) left;
+                               } else {
+                                       other = left;
+                                       match = (EnumConstant) right;
+                               }
+
+                               bool need_check = (other is EnumConstant) ||
+                                       ((oper != Binary.Operator.Addition) &&
+                                        (oper != Binary.Operator.Subtraction));
+
+                               if (need_check &&
+                                   !Expression.ImplicitConversionExists (ec, match, other.Type)) {
+                                       Expression.Error_CannotConvertImplicit (loc, match.Type, other.Type);
+                                       left = null;
+                                       right = null;
+                                       return;
+                               }
+
+                               if (left is EnumConstant)
+                                       left = ((EnumConstant) left).Child;
+                               if (right is EnumConstant)
+                                       right = ((EnumConstant) right).Child;
+                               return;
+
                        } else {
                                //
                                // Force conversions to int32
@@ -165,7 +198,7 @@ namespace Mono.CSharp {
                        
                        switch (oper){
                        case Binary.Operator.BitwiseOr:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
                                
@@ -210,7 +243,7 @@ namespace Mono.CSharp {
                                break;
                                
                        case Binary.Operator.BitwiseAnd:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
                                
@@ -255,7 +288,7 @@ namespace Mono.CSharp {
                                break;
 
                        case Binary.Operator.ExclusiveOr:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
                                
@@ -340,7 +373,7 @@ namespace Mono.CSharp {
                                }
 
                                result = null;
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -424,7 +457,7 @@ namespace Mono.CSharp {
                                        return result;
 
                        case Binary.Operator.Subtraction:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -504,7 +537,7 @@ namespace Mono.CSharp {
                                break;
                                
                        case Binary.Operator.Multiply:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -584,7 +617,7 @@ namespace Mono.CSharp {
                                break;
 
                        case Binary.Operator.Division:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -668,7 +701,7 @@ namespace Mono.CSharp {
                                break;
                                
                        case Binary.Operator.Modulus:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -837,7 +870,7 @@ namespace Mono.CSharp {
                                        
                                }
                                
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -877,7 +910,7 @@ namespace Mono.CSharp {
                                                ((StringConstant) right).Value);
                                        
                                }
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -906,7 +939,7 @@ namespace Mono.CSharp {
                                return new BoolConstant (bool_res);
 
                        case Binary.Operator.LessThan:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -935,7 +968,7 @@ namespace Mono.CSharp {
                                return new BoolConstant (bool_res);
                                
                        case Binary.Operator.GreaterThan:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -964,7 +997,7 @@ namespace Mono.CSharp {
                                return new BoolConstant (bool_res);
 
                        case Binary.Operator.GreaterThanOrEqual:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
@@ -993,7 +1026,7 @@ namespace Mono.CSharp {
                                return new BoolConstant (bool_res);
 
                        case Binary.Operator.LessThanOrEqual:
-                               DoConstantNumericPromotions (oper, ref left, ref right, loc);
+                               DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
                                if (left == null || right == null)
                                        return null;
 
index 92a2c2a6ea04a186623247bb92bc1c5d6cdcdd92..5c3d861765077a85c2d16bb4885bb84a73b512e5 100644 (file)
@@ -1531,7 +1531,7 @@ namespace Mono.CSharp {
 
                        if (Delegates != null)
                                foreach (Delegate d in Delegates)
-                                       d.CloseDelegate ();
+                                       d.CloseType ();
                }
 
                public string MakeName (string n)
@@ -2803,7 +2803,7 @@ namespace Mono.CSharp {
                                //
                                if (implementing.DeclaringType.IsInterface)
                                        flags |= MethodAttributes.NewSlot;
-                               
+
                                flags |=
                                        MethodAttributes.Virtual |
                                        MethodAttributes.HideBySig;
index bc9ca7b853445a03fc319e2ce350a67a0e8155ce..a21b8671f676454fde7bfb1d9387c531f3ff8465 100644 (file)
@@ -8,6 +8,7 @@
 //
 
 using System;
+using System.IO;
 using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
@@ -65,11 +66,9 @@ namespace Mono.CSharp {
                //
                // This routine initializes the Mono runtime SymbolWriter.
                //
-               static bool InitMonoSymbolWriter (string basename, string output_file,
-                                                 string[] debug_args)
+               static bool InitMonoSymbolWriter (string basename, string symbol_output,
+                                                 string exe_output_file, string[] debug_args)
                {
-                       string symbol_output = basename + ".dbg";
-
                        Type itype = SymbolWriter.GetType ();
                        if (itype == null)
                                return false;
@@ -84,7 +83,7 @@ namespace Mono.CSharp {
                                return false;
 
                        object[] args = new object [3];
-                       args [0] = output_file;
+                       args [0] = exe_output_file;
                        args [1] = symbol_output;
                        args [2] = debug_args;
 
@@ -95,8 +94,8 @@ namespace Mono.CSharp {
                //
                // Initializes the symbol writer
                //
-               static void InitializeSymbolWriter (string basename, string output_file,
-                                                   string[] args)
+               static void InitializeSymbolWriter (string basename, string symbol_output,
+                                                   string exe_output_file, string[] args)
                {
                        SymbolWriter = ModuleBuilder.GetSymWriter ();
 
@@ -123,7 +122,8 @@ namespace Mono.CSharp {
                        
                        switch (sym_type.Name){
                        case "MonoSymbolWriter":
-                               if (!InitMonoSymbolWriter (basename, output_file, args))
+                               if (!InitMonoSymbolWriter (basename, symbol_output,
+                                                          exe_output_file, args))
                                        Report.Error (
                                                -18, "Cannot initialize the symbol writer");
                                break;
@@ -161,16 +161,24 @@ namespace Mono.CSharp {
                        ModuleBuilder = AssemblyBuilder.DefineDynamicModule (
                                Basename (name), Basename (output), want_debugging_support);
 
-                       if (want_debugging_support) {
-                               int pos = output.LastIndexOf (".");
+                       int pos = output.LastIndexOf (".");
 
-                               string basename;
-                               if (pos > 0)
-                                       basename = output.Substring (0, pos);
-                               else
-                                       basename = output;
+                       string basename;
+                       if (pos > 0)
+                               basename = output.Substring (0, pos);
+                       else
+                               basename = output;
 
-                               InitializeSymbolWriter (basename, output, debug_args);
+                       string symbol_output = basename + ".dbg";
+
+                       if (want_debugging_support)
+                               InitializeSymbolWriter (basename, symbol_output, output, debug_args);
+                       else {
+                               try {
+                                       File.Delete (symbol_output);
+                               } catch {
+                                       // Ignore errors.
+                               }
                        }
                }
 
index 5f673acacd3ca7282cf7df7ee2b0353da452a585..a02a568934b09b1af0856187dc4de8ff32b4c5a9 100644 (file)
@@ -538,13 +538,15 @@ namespace Mono.CSharp {
                                if (using_list == null)
                                        continue;
 
-                               foreach (string n in using_list){
-                                       t = LookupInterfaceOrClass (n, name, out error);
+                               foreach (Namespace.UsingEntry ue in using_list){
+                                       t = LookupInterfaceOrClass (ue.Name, name, out error);
                                        if (error)
                                                return null;
 
-                                       if (t != null)
+                                       if (t != null){
+                                               ue.Used = true;
                                                return t;
+                                       }
                                }
                                
                        }
index 3702f45e406652f6dee7ed0de6a4b5d169dd2625..ef19bbff9ac21deddd8927e72e48c8ac6db298b6 100644 (file)
@@ -489,11 +489,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public void CloseDelegate ()
-               {
-                       TypeBuilder.CreateType ();
-               }
-               
                public Expression InstanceExpression {
                        get {
                                return instance_expr;
@@ -656,7 +651,11 @@ namespace Mono.CSharp {
                        else
                                delegate_instance_expr.Emit (ec);
                        
-                       ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
+                       if (delegate_method.IsVirtual) {
+                               ec.ig.Emit (OpCodes.Dup);
+                               ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
+                       } else
+                               ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
                        ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method);
                }
        }
index 4cd95cea4ed2e05546eadf065fda437a1f3f8093..2966d2f3a132081e7091093be185ecfba436f6d1 100644 (file)
@@ -44,15 +44,14 @@ namespace Mono.Languages
                }
 
                [Option("Adds PARAM to the assembly link path", 'L')]
-               public static string[] LinkPaths = null;
+               public string[] LinkPaths = null;
 
                [Option("Defines the symbol PARAM", "define")]
-               public static string[] Defines = null;
+               public string[] Defines = null;
 
                [Option("Only parses the source file (for debugging the tokenizer)", "parse")]
-               public static bool parse_only = false;
+               public bool parse_only = false;
 
-               private static bool load_default_config = true;
 
                [Option("Disables implicit references to assemblies", "noconfig")]
                public bool NoConfig { set { load_default_config = !value; } }
@@ -60,35 +59,23 @@ namespace Mono.Languages
                [Option("Allows unsafe code", "unsafe")]
                public bool AllowUnsafeCode { set { RootContext.Unsafe = value; } }
 
-               private string output_file;
-
                [Option("Specifies output file", 'o', "output")]
-               public WhatToDoNext SetOutputFile(string FileName)
-               {
-                       output_file = FileName;
-                       string bname = CodeGen.Basename (output_file);
-                       if (bname.IndexOf (".") == -1)
-                               output_file += ".exe";
-                       return WhatToDoNext.GoAhead;
-               }
-
+               public string output_file = null;
 
                [Option("Only tokenizes source files", "tokenize")]
-               public static bool tokenize = true;
+               public bool tokenize = false;
 
                [Option("Set default context to checked", "checked")]
                public bool Checked { set { RootContext.Checked = value; } }
 
-               [Option("Shows stack trace at error location", "Stacktrace")]
+               [Option("Shows stack trace at Error location", "Stacktrace")]
                public bool Stacktrace { set { Report.Stacktrace = value; } }
 
-               private static ArrayList references = new ArrayList();
-
                [Option("References an assembly", 'r')]
-               public static string reference { set { references.Add(value); } }
+               public string reference { set { references.Add(value); } }
 
                [Option("Adds PARAM as a resource", "resource")]
-               public static string[] resources;
+               public string[] resources;
 
                [Option("Set default context to checked", "nostdlib")]
                public bool nostdlib { set { RootContext.StdLib = !value; } }
@@ -115,7 +102,7 @@ namespace Mono.Languages
        
 
                [Option("Write symbolic debugging information to FILE-debug.s", 'g', "debug")]
-               public static bool want_debugging_support = false;
+               public bool want_debugging_support = false;
 
                [Option("Debugger arguments", "debug-args")]
                public WhatToDoNext SetDebugArgs(string args)
@@ -154,7 +141,7 @@ namespace Mono.Languages
                [Option("Sets warning level (the highest is 4, the default)", "wlevel")]
                public int wlevel { set { RootContext.WarningLevel = value; } }
 
-               [Option("Sets warning level (the highest is 4, the default)")]
+               [Option("Displays time stamps of various compiler events")]
                public bool timestamp
                {
                        set
@@ -165,46 +152,25 @@ namespace Mono.Languages
                        }
                }
 
-       static void Usage (bool is_error)
-               {
-                       Console.WriteLine (     @"
-MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
-  --timestamp     Displays time stamps of various compiler events
-  @file           Read response file for more options
-");
-               }
-               
-               //
-               // 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;
-
-               static int error_count = 0;
+               // TODO : response file support
 
-               static string first_source;
-
-               static Target target = Target.Exe;
-               static string target_ext = ".exe";
-
-               static ArrayList debug_arglist = new ArrayList ();
-
-               static bool timestamps = false;
-
-               static Hashtable source_files = new Hashtable ();
-
-               //
-               // An array of the defines from the command line
-               //
-               static ArrayList defines;
+       
+               ArrayList defines = new ArrayList();
+               ArrayList references = new ArrayList();
+               ArrayList soft_references = new ArrayList();
+               string first_source = null;
+               Target target = Target.Exe;
+               string target_ext = ".exe";
+               ArrayList debug_arglist = new ArrayList ();
+               bool timestamps = false;
+               Hashtable source_files = new Hashtable ();
+               bool load_default_config = true;
 
-               
                //
                // Last time we took the time
                //
-               static DateTime last_time;
-               static void ShowTime (string msg)
+               DateTime last_time;
+               void ShowTime (string msg)
                {
                        DateTime now = DateTime.Now;
                        TimeSpan span = now - last_time;
@@ -215,21 +181,13 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                                (int) span.TotalSeconds, span.Milliseconds, msg);
                }
                        
-               static void error (string msg)
-               {
-                       Console.WriteLine ("Error: " + msg);
-               }
-
-               static void notice (string msg)
-               {
-                       Console.WriteLine (msg);
-               }
-               
                public static int Main (string[] args)
                {
                        Driver Exec = new Driver();
                        
-                       if (Exec.MainDriver(args) && Report.Errors == 0) 
+                       Exec.MainDriver(args);
+
+                       if (Report.Errors == 0) 
                        {
                                Console.Write("Compilation succeeded");
                                if (Report.Warnings > 0) 
@@ -241,24 +199,24 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                        } 
                        else 
                        {
-                               Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
+                               Console.WriteLine("Compilation failed: {0} Error(s), {1} warnings",
                                        Report.Errors, Report.Warnings);
                                return 1;
                        }
                }
 
-               static public int LoadAssembly (string assembly, bool soft)
+               public int LoadAssembly (string assembly, bool soft)
                {
                        Assembly a;
                        string total_log = "";
 
                        try {
-                               char[] path_chars = { '/', '\\', '.' };
+                               char[] path_chars = { '/', '\\' };
 
                                if (assembly.IndexOfAny (path_chars) != -1)
-                                       a = Assembly.LoadFrom (assembly);
+                                       a = Assembly.LoadFrom(assembly);
                                else
-                                       a = Assembly.Load (assembly);
+                                       a = Assembly.Load(assembly);
                                TypeManager.AddAssembly (a);
                                return 0;
                        } catch (FileNotFoundException){
@@ -277,15 +235,15 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                                if (soft)
                                        return 0;
                        } catch (BadImageFormatException f) {
-                               error ("// Bad file format while loading assembly");
-                               error ("Log: " + f.FusionLog);
+                               Error ("// Bad file format while loading assembly");
+                               Error ("Log: " + f.FusionLog);
                                return 1;
                        } catch (FileLoadException f){
-                               error ("File Load Exception: " + assembly);
-                               error ("Log: " + f.FusionLog);
+                               Error ("File Load Exception: " + assembly);
+                               Error ("Log: " + f.FusionLog);
                                return 1;
                        } catch (ArgumentNullException){
-                               error ("// Argument Null exception ");
+                               Error ("// Argument Null exception ");
                                return 1;
                        }
                        
@@ -295,10 +253,15 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                        return 0;
                }
 
+               void Error(string message)
+               {
+                       Console.WriteLine(message);
+               }
+
                /// <summary>
                ///   Loads all assemblies referenced on the command line
                /// </summary>
-               static public int LoadReferences ()
+               public int LoadReferences ()
                {
                        int errors = 0;
 
@@ -311,7 +274,7 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                        return errors;
                }
 
-               static void SetupDefaultDefines ()
+               void SetupDefaultDefines ()
                {
                        defines = new ArrayList ();
                        defines.Add ("__MonoBASIC__");
@@ -321,7 +284,7 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                //
                // Returns the directory where the system assemblies are installed
                //
-               static string GetSystemDir ()
+               string GetSystemDir ()
                {
                        Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies ();
 
@@ -339,7 +302,7 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                //
                // Given a path specification, splits the path from the file/pattern
                //
-               static void SplitPathAndPattern (string spec, out string path, out string pattern)
+               void SplitPathAndPattern (string spec, out string path, out string pattern)
                {
                        int p = spec.LastIndexOf ("/");
                        if (p != -1){
@@ -368,29 +331,20 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                        pattern = spec;
                }
 
-
-               static int ProcessSourceFile(string filename)
-               {
-                       if (tokenize)
-                               GenericParser.Tokenize(filename);
-                       else
-                               return GenericParser.Parse(filename);
-
-                       return 0;
-               }
-
-               static bool AddFiles (string spec, bool recurse)
+               bool AddFiles (string spec, bool recurse)
                {
                        string path, pattern;
 
-                       SplitPathAndPattern (spec, out path, out pattern);
-                       if (pattern.IndexOf ("*") == -1){
-                               return AddFile (spec);
+                       SplitPathAndPattern(spec, out path, out pattern);
+                       if (pattern.IndexOf("*") == -1)
+                       {
+                               AddFile(spec);
+                               return true;
                        }
 
                        string [] files = null;
                        try {
-                               files = Directory.GetFiles (path, pattern);
+                               files = Directory.GetFiles(path, pattern);
                        } catch (System.IO.DirectoryNotFoundException) {
                                Report.Error (2001, "Source file `" + spec + "' could not be found");
                                return false;
@@ -407,7 +361,7 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                        string [] dirs = null;
 
                        try {
-                               dirs = Directory.GetDirectories (path);
+                               dirs = Directory.GetDirectories(path);
                        } catch {
                        }
                        
@@ -417,12 +371,11 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                                // directory entry already does
                                AddFiles (d + "/" + pattern, true);
                        }
-                       
 
                        return true;
                }
 
-               static void DefineDefaultConfig ()
+               void DefineDefaultConfig ()
                {
                        //
                        // For now the "default config" is harcoded into the compiler
@@ -458,119 +411,119 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
 #endif
                        };
                        
-                       int p = 0;
                        foreach (string def in default_config)
-                               soft_references.Insert (p++, def);
+                               soft_references.Add(def);
                }
 
-               private static bool AddFile(string fileName)
+               [ArgumentProcessor]
+               public void AddFile(string fileName)
                {
                        string f = fileName;
                        if (first_source == null)
                                first_source = f;
 
                        if (source_files.Contains(f))
-                       {
-                               Report.Error (1516, "Source file `" + f + "' specified multiple times");
-                               return false;
-                       } 
+                               Report.Error(1516, "Source file '" + f + "' specified multiple times");
                        else
                                source_files.Add(f, f);
+               }
 
-                       return true;
+               void ProcessSourceFile(string filename)
+               {
+                       if (tokenize)
+                               GenericParser.Tokenize(filename);
+                       else
+                               GenericParser.Parse(filename);
+               }
+
+               string outputFile_Name = null;
+
+               string outputFileName
+               {
+                       get 
+                       {
+                               if (outputFile_Name == null)
+                               {
+                                       if (output_file == null)
+                                       {
+                                               int pos = first_source.LastIndexOf(".");
+
+                                               if (pos > 0)
+                                                       output_file = first_source.Substring(0, pos);
+                                               else
+                                                       output_file = first_source;
+                                       }
+                                       string bname = CodeGen.Basename(output_file);
+                                       if (bname.IndexOf(".") == -1)
+                                               output_file +=  target_ext;
+                                       outputFile_Name = output_file;
+                               }
+                               return outputFile_Name;
+                       }
                }
 
-               
                /// <summary>
-               ///    Parses the arguments, and drives the compilation
-               ///    process.
+               ///    Parses the arguments, and calls the compilation process.
                /// </summary>
-               ///
-               /// <remarks>
-               ///    TODO: Mostly structured to debug the compiler
-               ///    now, needs to be turned into a real driver soon.
-               /// </remarks>
-               bool MainDriver(string [] args)
+               void MainDriver(string [] args)
                {
-                       int errors = 0;//, i;
-                       string output_file = null;
-                       
-                       soft_references = new ArrayList ();
-                       SetupDefaultDefines ();
-                       
-                       this.ProcessArgs(args);
-
-                       foreach(string arg in this.RemainingArguments)
-                               AddFile(arg); 
+                       ProcessArgs(args);
+                       CompileAll();
+               }
 
-                       foreach(string filename in source_files.Values)
-                               errors += ProcessSourceFile(filename);
+               public Driver()
+               {
+                       SetupDefaultDefines();  
+               }
 
+               bool ParseAll() // Phase 1
+               {
                        if (first_source == null)
                        {
-                               Report.Error (2008, "No files to compile were specified");
+                               Report.Error(2008, "No files to compile were specified");
                                return false;
                        }
 
-                       if (tokenize)
-                               return true;
-                       
-                       if (Report.Errors > 0)
-                               return false;
-                       
-                       if (parse_only)
-                               return true;
-                       
-                       //
+                       foreach(string filename in source_files.Values)
+                               ProcessSourceFile(filename);
+
+                       if (tokenize || parse_only || (Report.Errors > 0))
+                               return false;           
+
+                       return true; // everything went well go ahead
+               }
+
+               void InitializeDebuggingSupport()
+               {
+                       string[] debug_args = new string [debug_arglist.Count];
+                       debug_arglist.CopyTo(debug_args);
+                       CodeGen.Init(outputFileName, outputFileName, want_debugging_support, debug_args);
+                       TypeManager.AddModule(CodeGen.ModuleBuilder);
+               }
+
+               public bool ResolveAllTypes() // Phase 2
+               {
                        // Load Core Library for default compilation
-                       //
                        if (RootContext.StdLib)
-                               references.Insert (0, "mscorlib");
+                               references.Insert(0, "mscorlib");
 
                        if (load_default_config)
-                               DefineDefaultConfig ();
+                               DefineDefaultConfig();
 
-                       if (errors > 0)
-                       {
-                               error ("Parsing failed");
-                               return false;
-                       }
+                       if (timestamps)
+                               ShowTime("Loading references");
 
-                       //
                        // Load assemblies required
-                       //
-                       if (timestamps)
-                               ShowTime ("Loading references");
-                       errors += LoadReferences ();
-                       if (timestamps)
-                               ShowTime ("   References loaded");
-                       
-                       if (errors > 0)
+                       if (LoadReferences() > 0)
                        {
-                               error ("Could not load one or more assemblies");
+                               Error ("Could not load one or more assemblies");
                                return false;
                        }
 
-                       error_count = errors;
-
-                       //
-                       // Quick hack
-                       //
-                       if (output_file == null)
-                       {
-                               int pos = first_source.LastIndexOf (".");
-
-                               if (pos > 0)
-                                       output_file = first_source.Substring (0, pos) + target_ext;
-                               else
-                                       output_file = first_source + target_ext;
-                       }
-
-                       string[] debug_args = new string [debug_arglist.Count];
-                       debug_arglist.CopyTo(debug_args);
-                       CodeGen.Init (output_file, output_file, want_debugging_support, debug_args);
+                       if (timestamps)
+                               ShowTime("References loaded");
 
-                       TypeManager.AddModule (CodeGen.ModuleBuilder);
+                       InitializeDebuggingSupport();
 
                        //
                        // Before emitting, we need to get the core
@@ -579,98 +532,106 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                        //
                        if (timestamps)
                                ShowTime ("Initializing Core Types");
+
                        if (!RootContext.StdLib)
-                       {
                                RootContext.ResolveCore ();
-                               if (Report.Errors > 0)
-                                       return false;
-                       }
+                       if (Report.Errors > 0)
+                               return false;
                        
-                       TypeManager.InitCoreTypes ();
+                       TypeManager.InitCoreTypes();
+                       if (Report.Errors > 0)
+                               return false;
+
                        if (timestamps)
                                ShowTime ("   Core Types done");
-               
-                       //
-                       // The second pass of the compiler
-                       //
+
                        if (timestamps)
                                ShowTime ("Resolving tree");
+
+                       // The second pass of the compiler
                        RootContext.ResolveTree ();
+                       if (Report.Errors > 0)
+                               return false;
+                       
                        if (timestamps)
                                ShowTime ("Populate tree");
 
+                       if (!RootContext.StdLib)
+                               RootContext.BootCorlib_PopulateCoreTypes();
                        if (Report.Errors > 0)
-                       {
-                               error ("Compilation failed");
                                return false;
-                       }
 
-                       if (!RootContext.StdLib)
-                               RootContext.BootCorlib_PopulateCoreTypes ();
-                       RootContext.PopulateTypes ();
-                       
-                       TypeManager.InitCodeHelpers ();
-                               
+                       RootContext.PopulateTypes();
                        if (Report.Errors > 0)
-                       {
-                               error ("Compilation failed");
                                return false;
-                       }
                        
+                       TypeManager.InitCodeHelpers();
+                       if (Report.Errors > 0)
+                               return false;
+
+                       return true;
+               }
+               
+               bool GenerateAssembly()
+               {
                        //
                        // The code generator
                        //
                        if (timestamps)
                                ShowTime ("Emitting code");
-                       RootContext.EmitCode ();
-                       if (timestamps)
-                               ShowTime ("   done");
 
+                       RootContext.EmitCode();
                        if (Report.Errors > 0)
-                       {
-                               error ("Compilation failed");
                                return false;
-                       }
+
+                       if (timestamps)
+                               ShowTime ("   done");
+
 
                        if (timestamps)
                                ShowTime ("Closing types");
-                       
+
                        RootContext.CloseTypes ();
+                       if (Report.Errors > 0)
+                               return false;
 
-                       //                      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){
-                       //                                      Report.Error (5001, "Program " + output_file +
-                       //                                                            " does not have an entry point defined");
-                       //                                      return;
-                       //                              }
-                       //                              
-                       //                              CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
-                       //                      }
+                       if (timestamps)
+                               ShowTime ("   done");
+
+                       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)
+                               {
+                                       Report.Error (5001, "Program " + outputFileName +
+                                               " does not have an entry point defined");
+                                       return false;
+                               }
+                                                       
+                               CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
+                       }
 
-                       //
                        // Add the resources
-                       //
                        if (resources != null)
-                       {
                                foreach (string file in resources)
                                        CodeGen.AssemblyBuilder.AddResourceFile (file, file);
-                       }
                        
-                       CodeGen.Save (output_file);
+                       CodeGen.Save(outputFileName);
+
                        if (timestamps)
                                ShowTime ("Saved output");
 
+                       
                        if (want_debugging_support) 
                        {
                                CodeGen.SaveSymbols ();
@@ -678,13 +639,22 @@ MonoBASIC Compiler, Copyright (C)2002 Rafael Teixeira.
                                        ShowTime ("Saved symbols");
                        }
 
+                       return true;
+               }
+
+               public void CompileAll()
+               {
+                       if (!ParseAll()) // Phase 1
+                               return;
+
+                       if (!ResolveAllTypes()) // Phase 2
+                               return;
+
+                       if (!GenerateAssembly()) // Phase 3 
+                               return;
+
                        if (Report.ExpectedError != 0)
-                       {
-                               Console.WriteLine("Failed to report expected error " + Report.ExpectedError);
-                               Environment.Exit (1);
-                               return false;
-                       }
-                       return (Report.Errors == 0);
+                               Error("Failed to report expected Error " + Report.ExpectedError);
                }
 
        }
index 2994eacb5661c93252ce0de28b9048ec2a7656da..e34f79cc70bfc9ba4eabe67a6225cce903a15e51 100644 (file)
@@ -155,6 +155,13 @@ namespace Mono.CSharp {
                        get;
                }
 
+               /// <summary>
+               ///   The type which declares this member.
+               /// </summary>
+               Type DeclaringType {
+                       get;
+               }
+
                /// <summary>
                ///   The instance expression associated with this member, if it's a
                ///   non-static member.
@@ -791,19 +798,8 @@ namespace Mono.CSharp {
                                        return new ULongConstant ((ulong) v);
                        }
 
-                       //
-                       // If we have an enumeration, extract the underlying type,
-                       // use this during the comparission, but wrap around the original
-                       // target_type
-                       //
-                       Type real_target_type = target_type;
-
-                       if (TypeManager.IsEnumType (real_target_type))
-                               real_target_type = TypeManager.EnumToUnderlying (real_target_type);
+                       Type real_target_type = target_type;
 
-                       if (expr_type == real_target_type)
-                               return new EmptyCast (expr, target_type);
-                       
                        if (expr_type == TypeManager.sbyte_type){
                                //
                                // From sbyte to short, int, long, float, double.
@@ -1047,7 +1043,7 @@ namespace Mono.CSharp {
 
                        return false;
                }
-               
+
                /// <summary>
                ///  Determines if a standard implicit conversion exists from
                ///  expr_type to target_type
@@ -1794,7 +1790,7 @@ namespace Mono.CSharp {
 
                        //
                        // If we have an enumeration, extract the underlying type,
-                       // use this during the comparission, but wrap around the original
+                       // use this during the comparison, but wrap around the original
                        // target_type
                        //
                        Type real_target_type = target_type;
@@ -1802,6 +1798,9 @@ namespace Mono.CSharp {
                        if (TypeManager.IsEnumType (real_target_type))
                                real_target_type = TypeManager.EnumToUnderlying (real_target_type);
 
+                       if (StandardConversionExists (expr, real_target_type))
+                               return new EmptyCast (expr, target_type);
+                       
                        if (expr_type == TypeManager.sbyte_type){
                                //
                                // From sbyte to byte, ushort, uint, ulong, char
@@ -3574,6 +3573,14 @@ namespace Mono.CSharp {
                                if (!me.IsStatic && (me.InstanceExpression == null))
                                        return e;
 
+                               if (!me.IsStatic &&
+                                   TypeManager.IsNestedChildOf (me.InstanceExpression.Type, me.DeclaringType)) {
+                                       Error (38, "Cannot access nonstatic member `" + me.Name + "' of " +
+                                              "outer type `" + me.DeclaringType + "' via nested type `" +
+                                              me.InstanceExpression.Type + "'");
+                                       return null;
+                               }
+
                                if (right_side != null)
                                        e = e.DoResolveLValue (ec, right_side);
                                else
@@ -3715,6 +3722,12 @@ namespace Mono.CSharp {
                        eclass = ExprClass.MethodGroup;
                        type = TypeManager.object_type;
                }
+
+               public Type DeclaringType {
+                       get {
+                               return Methods [0].DeclaringType;
+                       }
+               }
                
                //
                // `A method group may have associated an instance expression' 
@@ -3851,6 +3864,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public Type DeclaringType {
+                       get {
+                               return FieldInfo.DeclaringType;
+                       }
+               }
+
                public Expression InstanceExpression {
                        get {
                                return instance_expr;
@@ -4123,6 +4142,12 @@ namespace Mono.CSharp {
                        }
                }
                
+               public Type DeclaringType {
+                       get {
+                               return PropertyInfo.DeclaringType;
+                       }
+               }
+
                //
                // The instance expression associated with this expression
                //
@@ -4158,6 +4183,11 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       if ((instance_expr == null) && ec.IsStatic && !is_static) {
+                               SimpleName.Error_ObjectRefRequired (ec, loc, PropertyInfo.Name);
+                               return null;
+                       }
+
                        return this;
                }
 
@@ -4181,7 +4211,8 @@ namespace Mono.CSharp {
                        //
                        // Special case: length of single dimension array is turned into ldlen
                        //
-                       if (method == TypeManager.int_array_get_length){
+                       if ((method == TypeManager.system_int_array_get_length) ||
+                           (method == TypeManager.int_array_get_length)){
                                Type iet = instance_expr.Type;
 
                                //
@@ -4264,6 +4295,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public Type DeclaringType {
+                       get {
+                               return EventInfo.DeclaringType;
+                       }
+               }
+
                public Expression InstanceExpression {
                        get {
                                return instance_expr;
index 003506f0b6e0569635986307e0ede5c9a6e3a79d..a6d9270722acb8c8a5268338eb4c450323bd73fc 100644 (file)
@@ -257,6 +257,129 @@ namespace Mono.CSharp {
                        return;
                }
 
+               /// <summary>
+               ///  Determines if a standard implicit conversion exists from
+               ///  expr_type to target_type
+               /// </summary>
+               public static bool ImplicitConversionExists (Type expr_type, Type target_type)
+               {
+                       expr_type = TypeManager.TypeToCoreType (expr_type);
+
+                       if (expr_type == TypeManager.void_type)
+                               return false;
+                       
+                       if (expr_type == target_type)
+                               return true;
+
+                       // First numeric conversions 
+
+                       if (expr_type == TypeManager.sbyte_type){
+                               //
+                               // From sbyte to short, int, long, float, double.
+                               //
+                               if ((target_type == TypeManager.int32_type) || 
+                                   (target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.float_type)  ||
+                                   (target_type == TypeManager.short_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+                               
+                       } else if (expr_type == TypeManager.byte_type){
+                               //
+                               // From byte to short, ushort, int, uint, long, ulong, float, double
+                               // 
+                               if ((target_type == TypeManager.short_type) ||
+                                   (target_type == TypeManager.ushort_type) ||
+                                   (target_type == TypeManager.int32_type) ||
+                                   (target_type == TypeManager.uint32_type) ||
+                                   (target_type == TypeManager.uint64_type) ||
+                                   (target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+       
+                       } else if (expr_type == TypeManager.short_type){
+                               //
+                               // From short to int, long, float, double
+                               // 
+                               if ((target_type == TypeManager.int32_type) ||
+                                   (target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+                                       
+                       } else if (expr_type == TypeManager.ushort_type){
+                               //
+                               // From ushort to int, uint, long, ulong, float, double
+                               //
+                               if ((target_type == TypeManager.uint32_type) ||
+                                   (target_type == TypeManager.uint64_type) ||
+                                   (target_type == TypeManager.int32_type) ||
+                                   (target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+                                   
+                       } else if (expr_type == TypeManager.int32_type){
+                               //
+                               // From int to long, float, double
+                               //
+                               if ((target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+                                       
+                       } else if (expr_type == TypeManager.uint32_type){
+                               //
+                               // From uint to long, ulong, float, double
+                               //
+                               if ((target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.uint64_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+                                       
+                       } else if ((expr_type == TypeManager.uint64_type) ||
+                                  (expr_type == TypeManager.int64_type)) {
+                               //
+                               // From long/ulong to float, double
+                               //
+                               if ((target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+                                   
+                       } else if (expr_type == TypeManager.char_type){
+                               //
+                               // From char to ushort, int, uint, long, ulong, float, double
+                               // 
+                               if ((target_type == TypeManager.ushort_type) ||
+                                   (target_type == TypeManager.int32_type) ||
+                                   (target_type == TypeManager.uint32_type) ||
+                                   (target_type == TypeManager.uint64_type) ||
+                                   (target_type == TypeManager.int64_type) ||
+                                   (target_type == TypeManager.float_type) ||
+                                   (target_type == TypeManager.double_type) ||
+                                   (target_type == TypeManager.decimal_type))
+                                       return true;
+
+                       } else if (expr_type == TypeManager.float_type){
+                               //
+                               // float to double
+                               //
+                               if (target_type == TypeManager.double_type)
+                                       return true;
+                       }       
+                       
+                       return false;
+               }
+
                /// <summary>
                ///  This is used to lookup the value of an enum member. If the member is undefined,
                ///  it attempts to define it and return its value
@@ -318,26 +441,32 @@ namespace Mono.CSharp {
                                val = val.Resolve (ec);
                                in_transit.Remove (name);
                                ec.InEnumContext = old;
-                               
+
                                if (val == null)
                                        return null;
 
-                               if (IsValidEnumConstant (val)) {
-                                       c = (Constant) val;
-                                       default_value = c.GetValue ();
-                                       
-                                       if (default_value == null) {
-                                               Error_ConstantValueCannotBeConverted (c, loc);
-                                               return null;
-                                       }
-                                       
-                               } else {
+                               if (!IsValidEnumConstant (val)) {
                                        Report.Error (
                                                1008, loc,
                                                "Type byte, sbyte, short, ushort, int, uint, long, or " +
                                                "ulong expected (have: " + val + ")");
                                        return null;
                                }
+
+                               c = (Constant) val;
+                               default_value = c.GetValue ();
+
+                               if (default_value == null) {
+                                       Error_ConstantValueCannotBeConverted (c, loc);
+                                       return null;
+                               }
+
+                               if ((val is EnumConstant) &&
+                                   !ImplicitConversionExists (default_value.GetType (), UnderlyingType)) {
+                                       Expression.Error_CannotConvertImplicit (
+                                               loc, default_value.GetType (), UnderlyingType);
+                                       return null;
+                               }
                        }
 
                        FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static
index b8159d93152c25c3b53f60f216eb89c3c7410e2f..770c84a3f13ca052ba0778929722e98ff63e85cd 100644 (file)
@@ -1434,20 +1434,13 @@ namespace Mono.CSharp {
 
                        int errors = Report.Errors;
 
-                       target_type = target_type.Resolve (ec, ResolveFlags.Type);
+                       type = ec.DeclSpace.ResolveType (target_type, false, Location);
                        
-                       if (target_type == null){
-                               if (errors == Report.Errors)
-                                       Error (-10, "Can not resolve type");
+                       if (type == null)
                                return null;
-                       }
 
-                       type = target_type.Type;
                        eclass = ExprClass.Value;
                        
-                       if (type == null)
-                               return null;
-
                        if (expr is Constant){
                                Expression e = TryReduce (ec, type);
 
@@ -3312,6 +3305,15 @@ namespace Mono.CSharp {
                        if (argument_type == null)
                                throw new Exception ("Expression of type " + a.Expr + " does not resolve its type");
 
+                       //
+                       // This is a special case since csc behaves this way. I can't find
+                       // it anywhere in the spec but oh well ...
+                       //
+                       if (argument_expr is NullLiteral && p == TypeManager.string_type && q == TypeManager.object_type)
+                               return 1;
+                       else if (argument_expr is NullLiteral && p == TypeManager.object_type && q == TypeManager.string_type)
+                               return 0;
+                       
                        if (p == q)
                                return 0;
                        
@@ -3792,8 +3794,25 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (method == null)
+                       if (method == null) {
+                               //
+                               // Okay so we have failed to find anything so we
+                               // return by providing info about the closest match
+                               //
+                               for (int i = 0; i < me.Methods.Length; ++i) {
+
+                                       MethodBase c = (MethodBase) me.Methods [i];
+                                       ParameterData pd = GetParameterData (c);
+
+                                       if (pd.Count != argument_count)
+                                               continue;
+
+                                       VerifyArgumentsCompat (ec, Arguments, argument_count, c, false,
+                                                              null, loc);
+                               }
+                               
                                return null;
+                       }
 
                        //
                        // Now check that there are no ambiguities i.e the selected method
@@ -4833,9 +4852,12 @@ namespace Mono.CSharp {
                        byte [] element;
                        int count = array_data.Count;
 
+                       if (underlying_type.IsEnum)
+                               underlying_type = TypeManager.EnumToUnderlying (underlying_type);
+
                        factor = GetTypeSize (underlying_type);
                        if (factor == 0)
-                               return null;
+                               throw new Exception ("Unrecognized type in MakeByteBlob");
 
                        data = new byte [(count * factor + 4) & ~3];
                        int idx = 0;
@@ -4960,16 +4982,14 @@ namespace Mono.CSharp {
                        ILGenerator ig = ec.ig;
                        
                        byte [] data = MakeByteBlob (array_data, underlying_type, loc);
-                       
-                       if (data != null) {
-                               fb = RootContext.MakeStaticData (data);
 
-                               if (is_expression)
-                                       ig.Emit (OpCodes.Dup);
-                               ig.Emit (OpCodes.Ldtoken, fb);
-                               ig.Emit (OpCodes.Call,
-                                        TypeManager.void_initializearray_array_fieldhandle);
-                       }
+                       fb = RootContext.MakeStaticData (data);
+
+                       if (is_expression)
+                               ig.Emit (OpCodes.Dup);
+                       ig.Emit (OpCodes.Ldtoken, fb);
+                       ig.Emit (OpCodes.Call,
+                                TypeManager.void_initializearray_array_fieldhandle);
                }
                
                //
@@ -5302,6 +5322,12 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
+                       if (!ec.InUnsafe) {
+                               Error (233, "Sizeof may only be used in an unsafe context " +
+                                      "(consider using System.Runtime.InteropServices.Marshal.Sizeof");
+                               return null;
+                       }
+                               
                        type_queried = ec.DeclSpace.ResolveType (QueriedType, false, loc);
                        if (type_queried == null)
                                return null;
@@ -5722,6 +5748,9 @@ namespace Mono.CSharp {
                        if (Expr == null)
                                return null;
 
+                       if (Expr is Constant)
+                               return Expr;
+                       
                        eclass = Expr.eclass;
                        type = Expr.Type;
                        return this;
@@ -5765,6 +5794,9 @@ namespace Mono.CSharp {
                        if (Expr == null)
                                return null;
 
+                       if (Expr is Constant)
+                               return Expr;
+                       
                        eclass = Expr.eclass;
                        type = Expr.Type;
                        return this;
index dce7b2c5f1eb0d94b5177a0f2e2fe7b6d8991443..2aa91d11b9519fafb4733df751aa29f638caff7e 100644 (file)
@@ -53,6 +53,8 @@ namespace Mono.CSharp {
                IMemberContainer parent_container;
                MemberCache member_cache;
 
+               bool members_defined;
+
                // These will happen after the semantic analysis
                
                // Hashtable defined_indexers;
@@ -228,9 +230,22 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public MethodInfo [] GetMethods ()
+               //
+               // This might trigger a definition of the methods.  This happens only
+               // with Attributes, as Attribute classes are processed before interfaces.
+               // Ideally, we should make everything just define recursively in terms
+               // of its dependencies.
+               //
+               public MethodInfo [] GetMethods (TypeContainer container)
                {
-                       int n = method_builders.Count;
+                       int n = 0;
+                       
+                       if (!members_defined){
+                               if (DefineMembers (container))
+                                       n = method_builders.Count;
+                       } else
+                               n = method_builders.Count;
+                       
                        MethodInfo [] mi = new MethodInfo [n];
                        
                        method_builders.CopyTo (mi, 0);
@@ -297,6 +312,9 @@ namespace Mono.CSharp {
                        if (return_type.IsPointer && !UnsafeOK (this))
                                return;
 
+                       if (arg_types == null)
+                               return;
+
                        foreach (Type t in arg_types){
 
                                if (t == null)
@@ -832,7 +850,7 @@ namespace Mono.CSharp {
 
                        member_cache = new MemberCache (this);
 #endif
-
+                       members_defined = true;
                        return true;
                }
 
index 1b32f32de6e26126fb4dd22566d7569d7fdd3584..72c4485aef9b64a36c201067ee46a134cd542dde 100644 (file)
@@ -8,6 +8,7 @@
 //
 
 using System;
+using System.IO;
 using System.Collections;
 using System.Diagnostics.SymbolStore;
 
@@ -130,18 +131,20 @@ namespace Mono.CSharp {
                                if (sw == null)
                                        return null;
 
-                               if (sym_docs.Contains (Name))
+                               string path = Path.GetFullPath (Name);
+
+                               if (sym_docs.Contains (path))
                                        // If we already created an ISymbolDocumentWriter
                                        // instance for this document, return it.
-                                       doc = (ISymbolDocumentWriter) sym_docs [Name];
+                                       doc = (ISymbolDocumentWriter) sym_docs [path];
                                else {
                                        // Create a new ISymbolDocumentWriter instance and
                                        // store it in the hash table.
-                                       doc = sw.DefineDocument (Name, SymLanguageType.CSharp,
+                                       doc = sw.DefineDocument (path, SymLanguageType.CSharp,
                                                                 SymLanguageVendor.Microsoft,
                                                                 SymDocumentType.Text);
 
-                                       sym_docs.Add (Name, doc);
+                                       sym_docs.Add (path, doc);
                                }
 
                                return doc;
index d01bde48642adb163637cac88fa5a2cd58b269e2..a173b903620bcb73b4f6b50eb6553262899e17ed 100644 (file)
@@ -16,11 +16,33 @@ namespace Mono.CSharp {
        ///   Keeps track of the namespaces defined in the C# code.
        /// </summary>
        public class Namespace {
+               static ArrayList all_namespaces = new ArrayList ();
+               
                Namespace parent;
                string name;
                ArrayList using_clauses;
                Hashtable aliases;
                public bool DeclarationFound = false;
+
+               //
+               // This class holds the location where a using definition is
+               // done, and whether it has been used by the program or not.
+               //
+               // We use this to flag using clauses for namespaces that do not
+               // exist.
+               //
+               public class UsingEntry {
+                       public string Name;
+                       public bool Used;
+                       public Location Location;
+                       
+                       public UsingEntry (string name, Location loc)
+                       {
+                               Name = name;
+                               Location = loc;
+                               Used = false;
+                       }
+               }
                
                /// <summary>
                ///   Constructor Takes the current namespace and the
@@ -31,6 +53,8 @@ namespace Mono.CSharp {
                {
                        this.name = name;
                        this.parent = parent;
+
+                       all_namespaces.Add (this);
                }
 
                /// <summary>
@@ -70,7 +94,8 @@ namespace Mono.CSharp {
                        if (using_clauses == null)
                                using_clauses = new ArrayList ();
 
-                       using_clauses.Add (ns);
+                       UsingEntry ue = new UsingEntry (ns, loc);
+                       using_clauses.Add (ue);
                }
 
                public ArrayList UsingTable {
@@ -109,21 +134,46 @@ namespace Mono.CSharp {
 
                /// <summary>
                ///   Used to validate that all the using clauses are correct
-               ///   after we are finished parsing all the files
+               ///   after we are finished parsing all the files.  
                /// </summary>
-               public void VerifyUsing ()
+               public static bool VerifyUsing ()
                {
-                       foreach (DictionaryEntry de in using_clauses){
-                               if (de.Value == null){
-                                       string name = (string) de.Key;
-                                       
-                                       Report.Error (234, "The type or namespace `" +
-                                                           name + "' does not exist in the " +
-                                                           "class or namespace `" + name + "'");
+                       ArrayList unused = new ArrayList ();
+                       int errors = 0;
+                       
+                       foreach (Namespace ns in all_namespaces){
+                               ArrayList uses = ns.UsingTable;
+                               if (uses == null)
+                                       continue;
+                               
+                               foreach (UsingEntry ue in uses){
+                                       if (ue.Used)
+                                               continue;
+                                       unused.Add (ue);
                                }
                        }
+
+                       //
+                       // If we have unused using aliases, load all namespaces and check
+                       // whether it is unused, or it was missing
+                       //
+                       if (unused.Count > 0){
+                               Hashtable namespaces = TypeManager.GetNamespaces ();
+
+                               foreach (UsingEntry ue in unused){
+                                       if (namespaces.Contains (ue.Name)){
+                                               Report.Warning (6024, ue.Location, "Unused namespace in `using' declaration");
+                                               continue;
+                                       }
+
+                                       errors++;
+                                       Report.Error (246, ue.Location, "The namespace `" + ue.Name +
+                                                     "' can not be found (missing assembly reference?)");
+                               }
+                       }
+                       
+                       return errors == 0;
                }
 
        }
 }
-
index ab125da9719db7706f4402dfa288341c340e9fd6..ea9b07425262bb4c5e05f46933741fb67a1b6536 100644 (file)
@@ -170,7 +170,7 @@ namespace Mono.CSharp {
                        //
                }
 
-               static void error100 (string name)
+               static void Error_DuplicateParameterName (string name)
                {
                        Report.Error (
                                100, "The parameter name `" + name + "' is a duplicate");
@@ -192,12 +192,12 @@ namespace Mono.CSharp {
                                for (j = i + 1; j < count; j++){
                                        if (base_name != FixedParameters [j].Name)
                                                continue;
-                                       error100 (base_name);
+                                       Error_DuplicateParameterName (base_name);
                                        return false;
                                }
 
                                if (base_name == array_par_name){
-                                       error100 (base_name);
+                                       Error_DuplicateParameterName (base_name);
                                        return false;
                                }
                        }
@@ -279,14 +279,16 @@ namespace Mono.CSharp {
                                }
                        }
                        
-                       if (failed)
-                               types = null;
-                       
                        if (extra > 0){
                                if (ArrayParameter.Resolve (ds, loc))
                                        types [i] = ArrayParameter.ExternalType (ds, loc);
-                               else
-                                       return false;
+                               else 
+                                       failed = true;
+                       }
+
+                       if (failed){
+                               types = null;
+                               return false;
                        }
 
                        return true;
index 251bfd54a5a4307bedd5af72cc8192cfd6c18344..82f8e3b84f67a9cc5961adf62d069ebbd656b50e 100644 (file)
@@ -139,7 +139,7 @@ namespace Mono.CSharp {
 
                                                iface = TypeManager.LookupInterface (t);
                                                
-                                               mi = iface.GetMethods ();
+                                               mi = iface.GetMethods (container);
                                        } else
                                                mi = t.GetMethods ();
 
index 9d7ac28af7885c0bd3a9428d6e2461e1a5a543b4..22839a30dec463c60ffd2677609a47f45e03f7d2 100644 (file)
@@ -414,7 +414,7 @@ namespace Mono.CSharp {
                        
                        if (root.Delegates != null)
                                foreach (Delegate d in root.Delegates)
-                                       d.CloseDelegate ();
+                                       d.CloseType ();
 
 
                        //
@@ -492,10 +492,12 @@ namespace Mono.CSharp {
                                if (using_list == null)
                                        continue;
 
-                               foreach (string n in using_list) {
-                                       t = TypeManager.LookupType (MakeFQN (n, name));
-                                       if (t != null)
+                               foreach (Namespace.UsingEntry ue in using_list) {
+                                       t = TypeManager.LookupType (MakeFQN (ue.Name, name));
+                                       if (t != null){
+                                               ue.Used = true;
                                                return t;
+                                       }
                                }
 
                                //
index 71d5d0af2600232cb4aaca498565191a4ea61a17..f424cb4b45181fb9f66ee6cea7a4d720a7194f95 100644 (file)
@@ -500,7 +500,7 @@ namespace Mono.CSharp {
                        ec.LoopBeginTryCatchLevel = old_loop_begin_try_catch_level;
                        
                        //
-                       // Inform whether we are infinite or not
+                       // Inform whether we are infinite or not
                        //
                        if (Test != null){
                                if (Test is BoolConstant){
@@ -511,7 +511,7 @@ namespace Mono.CSharp {
                                }
                                return false;
                        } else
-                               return true;
+                               return breaks == false;
                }
        }
        
@@ -3031,7 +3031,7 @@ namespace Mono.CSharp {
 
                        if (e is StringConstant || e is NullLiteral){
                                if (required_type == TypeManager.string_type){
-                                       converted = label;
+                                       converted = e;
                                        ILLabel = ec.ig.DefineLabel ();
                                        return true;
                                }
@@ -4172,11 +4172,12 @@ namespace Mono.CSharp {
                public readonly Block  Block;
                public readonly Location Location;
 
-               Expression type;
+               Expression type_expr;
+               Type type;
                
                public Catch (Expression type, string name, Block block, Location l)
                {
-                       this.type = type;
+                       type_expr = type;
                        Name = name;
                        Block = block;
                        Location = l;
@@ -4184,34 +4185,31 @@ namespace Mono.CSharp {
 
                public Type CatchType {
                        get {
-                               if (type == null)
-                                       throw new InvalidOperationException ();
-
-                               return type.Type;
+                               return type;
                        }
                }
 
                public bool IsGeneral {
                        get {
-                               return type == null;
+                               return type_expr == null;
                        }
                }
 
                public bool Resolve (EmitContext ec)
                {
-                       if (type != null) {
-                               type = type.DoResolve (ec);
+                       if (type_expr != null) {
+                               type = ec.DeclSpace.ResolveType (type_expr, false, Location);
                                if (type == null)
                                        return false;
 
-                               Type t = type.Type;
-                               if (t != TypeManager.exception_type && !t.IsSubclassOf (TypeManager.exception_type)){
+                               if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
                                        Report.Error (155, Location,
                                                      "The type caught or thrown must be derived " +
                                                      "from System.Exception");
                                        return false;
                                }
-                       }
+                       } else
+                               type = null;
 
                        if (!Block.Resolve (ec))
                                return false;
index b5ec3e871c2797ef857ed32335a6eabc044cd413..2f7413c9e5a9fcf165b6928c2cff4f46c61ac4e7 100644 (file)
@@ -491,6 +491,35 @@ public class TypeManager {
                return null;
        }
 
+       //
+       // Returns a list of all namespaces in the assemblies and types loaded.
+       //
+       public static Hashtable GetNamespaces ()
+       {
+               Hashtable namespaces = new Hashtable ();
+
+               foreach (Assembly a in assemblies){
+                       foreach (Type t in a.GetTypes ()){
+                               string ns = t.Namespace;
+
+                               if (namespaces.Contains (ns))
+                                       continue;
+                               namespaces [ns] = ns;
+                       }
+               }
+
+               foreach (ModuleBuilder mb in modules){
+                       foreach (Type t in mb.GetTypes ()){
+                               string ns = t.Namespace;
+
+                               if (namespaces.Contains (ns))
+                                       continue;
+                               namespaces [ns] = ns;
+                       }
+               }
+               return namespaces;
+       }
+       
        /// <summary>
        ///   Returns the C# name of a type if possible, or the full type name otherwise
        /// </summary>
@@ -1040,6 +1069,14 @@ public class TypeManager {
                return false;
        }
 
+       //
+       // Checks whether `type' is a nested child of `parent'.
+       //
+       public static bool IsNestedChildOf (Type type, Type parent)
+       {
+               return IsSubclassOrNestedChildOf (type, parent) && !type.IsSubclassOf (parent);
+       }
+
        /// <summary>
        ///   Returns the User Defined Types
        /// </summary>