condition tests passes
[mono.git] / mcs / mcs / driver.cs
index 3a5885aa218e724da429435c09ed98d335141ee3..cf409aea1d4165f6fc7cda77fbc746497981b80c 100644 (file)
@@ -199,7 +199,9 @@ namespace Mono.CSharp
                        try {
                                parser.parse ();
                        } catch (Exception ex) {
-                               Report.Error(666, "Compilation aborted: " + ex);
+                               Report.Error(
+                                       666, String.Format ("Compilation aborted in file {0}, parser at {1}: {2}",
+                                                           file.Name, parser.Lexer.Location, ex));
                        } finally {
                                input.Close ();
                        }
@@ -215,7 +217,6 @@ namespace Mono.CSharp
                                "   --stacktrace       Shows stack trace at error location\n" +
                                "   --timestamp        Displays time stamps of various compiler events\n" +
                                "   --expect-error X   Expect that error X will be encountered\n" +
-                               "   -2                 Enables experimental C# features\n" +
                                "   -v                 Verbose parsing (for debugging the parser)\n" + 
                                "   --mcs-debug X      Sets MCS debugging level to X\n");
                }
@@ -223,40 +224,42 @@ namespace Mono.CSharp
                static void Usage ()
                {
                        Console.WriteLine (
-                               "Mono C# compiler, (C) 2001 - 2005 Novell, Inc.\n" +
+                               "Mono C# compiler, (C) 2001 - 2008 Novell, Inc.\n" +
                                "mcs [options] source-files\n" +
                                "   --about            About the Mono C# compiler\n" +
-                               "   -addmodule:MODULE  Adds the module to the generated assembly\n" + 
-                               "   -checked[+|-]      Set default context to checked\n" +
+                               "   -addmodule:M1[,Mn] Adds the module to the generated assembly\n" + 
+                               "   -checked[+|-]      Sets default aritmetic overflow context\n" +
                                "   -codepage:ID       Sets code page to the one in ID (number, utf8, reset)\n" +
-                               "   -clscheck[+|-]     Disables CLS Compliance verifications" + Environment.NewLine +
-                               "   -define:S1[;S2]    Defines one or more symbols (short: /d:)\n" +
+                               "   -clscheck[+|-]     Disables CLS Compliance verifications\n" +
+                               "   -define:S1[;S2]    Defines one or more conditional symbols (short: -d)\n" +
                                "   -debug[+|-], -g    Generate debugging information\n" + 
                                "   -delaysign[+|-]    Only insert the public key into the assembly (no signing)\n" +
-                               "   -doc:FILE          XML Documentation file to generate\n" + 
-                               "   -keycontainer:NAME The key pair container used to strongname the assembly\n" +
-                               "   -keyfile:FILE      The strongname key file used to strongname the assembly\n" +
-                               "   -langversion:TEXT  Specifies language version modes: ISO-1 or Default\n" + 
-                               "   -lib:PATH1,PATH2   Adds the paths to the assembly link path\n" +
-                               "   -main:class        Specified the class that contains the entry point\n" +
+                               "   -doc:FILE          Process documentation comments to XML file\n" + 
+                               "   -help              Lists all compiler options (short: -?)\n" + 
+                               "   -keycontainer:NAME The key pair container used to sign the output assembly\n" +
+                               "   -keyfile:FILE      The key file used to strongname the ouput assembly\n" +
+                               "   -langversion:TEXT  Specifies language version modes: ISO-1, ISO-2, or Default\n" + 
+                               "   -lib:PATH1[,PATHn] Specifies the location of referenced assemblies\n" +
+                               "   -main:CLASS        Specifies the class with the Main method (short: -m)\n" +
                                "   -noconfig[+|-]     Disables implicit references to assemblies\n" +
-                               "   -nostdlib[+|-]     Does not load core libraries\n" +
-                               "   -nowarn:W1[,W2]    Disables one or more warnings\n" + 
-                               "   -optimize[+|-]     Enables code optimalizations\n" + 
-                               "   -out:FNAME         Specifies output file\n" +
+                               "   -nostdlib[+|-]     Does not reference mscorlib.dll library\n" +
+                               "   -nowarn:W1[,Wn]    Suppress one or more compiler warnings\n" + 
+                               "   -optimize[+|-]     Enables advanced compiler optimizations (short: -o)\n" + 
+                               "   -out:FILE          Specifies output assembly name\n" +
                                "   -pkg:P1[,Pn]       References packages P1..Pn\n" + 
-                               "   -recurse:SPEC      Recursively compiles the files in SPEC ([dir]/file)\n" + 
-                               "   -reference:ASS     References the specified assembly (-r:ASS)\n" +
-                               "   -target:KIND       Specifies the target (KIND is one of: exe, winexe,\n" +
-                               "                      library, module), (short: /t:)\n" +
-                               "   -unsafe[+|-]       Allows unsafe code\n" +
-                               "   -warnaserror[+|-]  Treat warnings as errors\n" +
-                               "   -warn:LEVEL        Sets warning level (the highest is 4, the default is 2)\n" +
-                               "   -help2             Show other help flags\n" + 
+                               "   -recurse:SPEC      Recursively compiles files according to SPEC pattern\n" + 
+                               "   -reference:A1[,An] Imports metadata from the specified assembly (short: -r)\n" +
+                               "   -reference:ALIAS=A Imports metadata using specified extern alias (short: -r)\n" +                           
+                               "   -target:KIND       Specifies the format of the output assembly (short: -t)\n" +
+                               "                      KIND can be one of: exe, winexe, library, module\n" +
+                               "   -unsafe[+|-]       Allows to compile code which uses unsafe keyword\n" +
+                               "   -warnaserror[+|-]  Treats all warnings as errors\n" +
+                               "   -warn:0-4          Sets warning level, the default is 3 (short -w:)\n" +
+                               "   -help2             Shows internal compiler options\n" + 
                                "\n" +
                                "Resources:\n" +
-                               "   -linkresource:FILE[,ID] Links FILE as a resource\n" +
-                               "   -resource:FILE[,ID]     Embed FILE as a resource\n" +
+                               "   -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
+                               "   -resource:FILE[,ID]     Embed FILE as a resource (short: -res)\n" +
                                "   -win32res:FILE          Specifies Win32 resource file (.res)\n" +
                                "   -win32icon:FILE         Use this icon for the output\n" +
                                 "   @file                   Read response file for more options\n\n" +
@@ -271,13 +274,13 @@ namespace Mono.CSharp
                static void About ()
                {
                        Console.WriteLine (
-                               "The Mono C# compiler is (C) 2001-2005, Novell, Inc.\n\n" +
+                               "The Mono C# compiler is (C) 2001-2008, Novell, Inc.\n\n" +
                                "The compiler source code is released under the terms of the GNU GPL\n\n" +
 
                                "For more information on Mono, visit the project Web site\n" +
-                               "   http://www.go-mono.com\n\n" +
+                               "   http://www.mono-project.com\n\n" +
 
-                               "The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath");
+                               "The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto");
                        Environment.Exit (0);
                }
 
@@ -285,9 +288,8 @@ namespace Mono.CSharp
                
                public static int Main (string[] args)
                {
-#if GMCS_SOURCE
                        RootContext.Version = LanguageVersion.Default;
-#endif
+
                        Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
 
                        bool ok = MainDriver (args);
@@ -389,6 +391,8 @@ namespace Mono.CSharp
                                                        err = false;
                                                        break;
                                                } catch (FileNotFoundException ff) {
+                                                       if (soft)
+                                                               return;
                                                        total_log += ff.FusionLog;
                                                }
                                        }
@@ -456,12 +460,18 @@ namespace Mono.CSharp
                /// </summary>
                static public void LoadReferences ()
                {
-                       foreach (string r in references)
-                               LoadAssembly (r, false);
+                       //
+                       // Load Core Library for default compilation
+                       //
+                       if (RootContext.StdLib)
+                               LoadAssembly ("mscorlib", false);
 
                        foreach (string r in soft_references)
                                LoadAssembly (r, true);
 
+                       foreach (string r in references)
+                               LoadAssembly (r, false);
+
                        foreach (DictionaryEntry entry in external_aliases)
                                LoadAssembly ((string) entry.Value, (string) entry.Key, false);
                        
@@ -634,7 +644,14 @@ namespace Mono.CSharp
                        //
                        string [] default_config = {
                                "System",
-                               "System.Xml",
+#if NET_2_1
+                               "agclr",
+                               "System.Core",
+                               "System.Silverlight",
+                               "System.Xml.Core",
+#else
+                               "System.Xml"
+#endif
 #if false
                                //
                                // Is it worth pre-loading all this stuff?
@@ -660,9 +677,10 @@ namespace Mono.CSharp
 #endif
                        };
                        
-                       int p = 0;
-                       foreach (string def in default_config)
-                               soft_references.Insert (p++, def);
+                       if (RootContext.Version == LanguageVersion.LINQ)
+                               soft_references.Add ("System.Core");
+
+                       soft_references.AddRange (default_config);
                }
 
                public static string OutputFile
@@ -687,54 +705,15 @@ namespace Mono.CSharp
                                Report.Error (1900, "Warning level must be in the range 0-4");
                                return;
                        }
-                       RootContext.WarningLevel = level;
+                       Report.WarningLevel = level;
                }
 
-               static void SetupV2 ()
-               {
-                       RootContext.Version = LanguageVersion.Default;
-                       defines.Add ("__V2__");
-               }
-               
                static void Version ()
                {
                        string version = Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
                        Console.WriteLine ("Mono C# compiler version {0}", version);
                        Environment.Exit (0);
                }
-
-               //
-               // This is to test the tokenizer internal parser that is used to deambiguate
-               // '(' type identifier from '(' type others so that we are able to parse
-               // without introducing reduce/reduce conflicts in the grammar.
-               // 
-               static void LambdaTypeParseTest (string fname)
-               {
-                       bool fail = false;
-
-                       using (FileStream fs = File.OpenRead (fname)){
-                               StreamReader r = new StreamReader (fs, encoding);
-                               string line;
-                               
-                               while ((line = r.ReadLine ())!= null){
-                                       if (line [0] == '!')
-                                               continue;
-                                       bool must_pass = line [0] == '+';
-                                       StringReader test = new StringReader (line.Substring (1));
-                                       SeekableStreamReader reader = new SeekableStreamReader (test);
-                                       SourceFile file = new SourceFile (fname, fname, 0);
-                                       
-                                       Tokenizer lexer = new Tokenizer (reader, file, defines);
-                                       bool res = lexer.parse_type_and_parameter ();
-                                       
-                                       Console.WriteLine ("{3} ({1}=={2}): {0}", line.Substring (1), res, must_pass, res == must_pass);
-                                       if (res != must_pass)
-                                               fail = true;
-                               }
-                       }
-                       Console.WriteLine ("fail={0}", fail);
-                       Environment.Exit (fail ? 1 : 0);
-               }
                
                //
                // Currently handles the Unix-like command line options, but will be
@@ -1001,14 +980,6 @@ namespace Mono.CSharp
                                Report.Warning (-29, 1, "Compatibility: Use -noconfig option instead of --noconfig");
                                load_default_config = false;
                                return true;
-
-                       case "--typetest":
-                               if ((i + 1) >= args.Length){
-                                       Report.Error (5, "--typetest requires a filename argument");
-                                       Environment.Exit (1);
-                               }
-                               LambdaTypeParseTest (args [++i]);
-                               return true;
                        }
 
                        return false;
@@ -1071,11 +1042,14 @@ namespace Mono.CSharp
                                OutputFile = value;
                                return true;
 
+                       case "/o":
+                       case "/o+":
                        case "/optimize":
                        case "/optimize+":
                                RootContext.Optimize = true;
                                return true;
 
+                       case "/o-":
                        case "/optimize-":
                                RootContext.Optimize = false;
                                return true;
@@ -1088,15 +1062,16 @@ namespace Mono.CSharp
 
                        case "/d":
                        case "/define": {
-                               string [] defs;
-
                                if (value.Length == 0){
                                        Usage ();
                                        Environment.Exit (1);
                                }
 
-                               defs = value.Split (new Char [] {';', ','});
-                               foreach (string d in defs){
+                               foreach (string d in value.Split (';', ',')){
+                                       if (!Tokenizer.IsValidIdentifier (d)) {
+                                               Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", d);
+                                               continue;
+                                       }
                                        defines.Add (d);
                                }
                                return true;
@@ -1399,12 +1374,6 @@ namespace Mono.CSharp
                                RootContext.StrongNameDelaySign = false;
                                return true;
 
-                       case "/v2":
-                       case "/2":
-                               Console.WriteLine ("The compiler option -2 is obsolete. Please use /langversion instead");
-                               SetupV2 ();
-                               return true;
-                               
                        case "/langversion":
                                switch (value.ToLower (CultureInfo.InvariantCulture)) {
                                case "iso-1":
@@ -1412,14 +1381,22 @@ namespace Mono.CSharp
                                        return true;
                                        
                                case "default":
-                                       SetupV2 ();
+                                       RootContext.Version = LanguageVersion.Default;
+#if GMCS_SOURCE                                        
+                                       defines.Add ("__V2__");
+#endif
+                                       return true;
+#if GMCS_SOURCE
+                               case "iso-2":
+                                       RootContext.Version = LanguageVersion.ISO_2;
                                        return true;
                                        
                                case "linq":
-                                       RootContext.Version = LanguageVersion.LINQ;
+                                       Report.Warning (-30, 1, "Deprecated: The `linq' option is no longer required and should not be used");
                                        return true;
+#endif
                                }
-                               Report.Error (1617, "Invalid option `{0}' for /langversion. It must be either `ISO-1' or `Default'", value);
+                               Report.Error (1617, "Invalid option `{0}' for /langversion. It must be either `ISO-1', `ISO-2' or `Default'", value);
                                return true;
 
                        case "/codepage":
@@ -1645,12 +1622,6 @@ namespace Mono.CSharp
                        if (parse_only)
                                return true;
 
-                       //
-                       // Load Core Library for default compilation
-                       //
-                       if (RootContext.StdLib)
-                               references.Insert (0, "mscorlib");
-
                        if (load_default_config)
                                DefineDefaultConfig ();
 
@@ -2038,8 +2009,9 @@ namespace Mono.CSharp
                static void Reset ()
                {
                        Driver.Reset ();
-                       Location.Reset ();
                        RootContext.Reset ();
+                       Tokenizer.Reset ();
+                       Location.Reset ();
                        Report.Reset ();
                        TypeManager.Reset ();
                        TypeHandle.Reset ();