📄 driver.cs
字号:
Usage (); Environment.Exit (1); } OutputFile = value; return true; case "/optimize": case "/optimize+": RootContext.Optimize = true; return true; case "/optimize-": RootContext.Optimize = false; return true; case "/incremental": case "/incremental+": case "/incremental-": // nothing. return true; case "/d": case "/define": { string [] defs; if (value == ""){ Usage (); Environment.Exit (1); } defs = value.Split (new Char [] {';', ','}); foreach (string d in defs){ defines.Add (d); } return true; } case "/bugreport": // // We should collect data, runtime, etc and store in the file specified // Console.WriteLine ("To file bug reports, please visit: http://www.mono-project.com/Bugs"); return true; case "/pkg": { string packages; if (value == ""){ Usage (); Environment.Exit (1); } packages = String.Join (" ", value.Split (new Char [] { ';', ',', '\n', '\r'})); ProcessStartInfo pi = new ProcessStartInfo (); pi.FileName = "pkg-config"; pi.RedirectStandardOutput = true; pi.UseShellExecute = false; pi.Arguments = "--libs " + packages; Process p = null; try { p = Process.Start (pi); } catch (Exception e) { Report.Error (-27, "Couldn't run pkg-config: " + e.Message); Environment.Exit (1); } if (p.StandardOutput == null){ Report.Warning (-27, "Specified package did not return any information"); return true; } string pkgout = p.StandardOutput.ReadToEnd (); p.WaitForExit (); if (p.ExitCode != 0) { Report.Error (-27, "Error running pkg-config. Check the above output."); Environment.Exit (1); } if (pkgout != null){ string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}). Split (new Char [] { ' ', '\t'}); args = AddArgs (args, xargs); } p.Close (); return true; } case "/linkres": case "/linkresource": case "/res": case "/resource": if (embedded_resources == null) embedded_resources = new Resources (); bool embeded = arg.StartsWith ("/r"); string[] s = value.Split (','); switch (s.Length) { case 1: if (s[0].Length == 0) goto default; embedded_resources.Add (embeded, s [0], Path.GetFileName (s[0])); break; case 2: embedded_resources.Add (embeded, s [0], s [1]); break; case 3: if (s [2] != "public" && s [2] != "private") { Report.Error (1906, "Invalid resource visibility option `{0}'. Use either `public' or `private' instead", s [2]); return true; } embedded_resources.Add (embeded, s [0], s [1], s [2] == "private"); break; default: Report.Error (-2005, "Wrong number of arguments for option `{0}'", option); break; } return true; case "/recurse": if (value == ""){ Report.Error (5, "-recurse requires an argument"); Environment.Exit (1); } CompileFiles (value, true); return true; case "/r": case "/reference": { if (value == ""){ Report.Error (5, "-reference requires an argument"); Environment.Exit (1); } string [] refs = value.Split (new char [] { ';', ',' }); foreach (string r in refs){ string val = r; int index = val.IndexOf ("="); if (index > -1) { string alias = r.Substring (0, index); string assembly = r.Substring (index + 1); AddExternAlias (alias, assembly); return true; } references.Add (val); } return true; } case "/addmodule": { if (value == ""){ Report.Error (5, arg + " requires an argument"); Environment.Exit (1); } string [] refs = value.Split (new char [] { ';', ',' }); foreach (string r in refs){ modules.Add (r); } return true; } case "/win32res": { if (value == "") { Report.Error (5, arg + " requires an argument"); Environment.Exit (1); } win32ResourceFile = value; return true; } case "/win32icon": { if (value == "") { Report.Error (5, arg + " requires an argument"); Environment.Exit (1); } win32IconFile = value; return true; } case "/doc": { if (value == ""){ Report.Error (2006, arg + " requires an argument"); Environment.Exit (1); } RootContext.Documentation = new Documentation (value); return true; } case "/lib": { string [] libdirs; if (value == ""){ Report.Error (5, "/lib requires an argument"); Environment.Exit (1); } libdirs = value.Split (new Char [] { ',' }); foreach (string dir in libdirs) link_paths.Add (dir); return true; } case "/debug-": want_debugging_support = false; return true; case "/debug": case "/debug+": want_debugging_support = true; return true; case "/checked": case "/checked+": RootContext.Checked = true; return true; case "/checked-": RootContext.Checked = false; return true; case "/clscheck": case "/clscheck+": return true; case "/clscheck-": RootContext.VerifyClsCompliance = false; return true; case "/unsafe": case "/unsafe+": RootContext.Unsafe = true; return true; case "/unsafe-": RootContext.Unsafe = false; return true; case "/warnaserror": case "/warnaserror+": Report.WarningsAreErrors = true; return true; case "/warnaserror-": Report.WarningsAreErrors = false; return true; case "/warn": SetWarningLevel (value); return true; case "/nowarn": { string [] warns; if (value == ""){ Report.Error (5, "/nowarn requires an argument"); Environment.Exit (1); } warns = value.Split (new Char [] {','}); foreach (string wc in warns){ try { int warn = Int32.Parse (wc); if (warn < 1) { throw new ArgumentOutOfRangeException("warn"); } Report.SetIgnoreWarning (warn); } catch { Report.Error (1904, String.Format("`{0}' is not a valid warning number", wc)); } } return true; } case "/noconfig-": load_default_config = true; return true; case "/noconfig": case "/noconfig+": load_default_config = false; return true; case "/help2": OtherFlags (); Environment.Exit(0); return true; case "/help": case "/?": Usage (); Environment.Exit (0); return true; case "/main": case "/m": if (value == ""){ Report.Error (5, arg + " requires an argument"); Environment.Exit (1); } RootContext.MainClass = value; return true; case "/nostdlib": case "/nostdlib+": RootContext.StdLib = false; return true; case "/nostdlib-": RootContext.StdLib = true; return true; case "/fullpaths": return true; case "/keyfile": if (value == String.Empty) { Report.Error (5, arg + " requires an argument"); Environment.Exit (1); } RootContext.StrongNameKeyFile = value; return true; case "/keycontainer": if (value == String.Empty) { Report.Error (5, arg + " requires an argument"); Environment.Exit (1); } RootContext.StrongNameKeyContainer = value; return true; case "/delaysign+": RootContext.StrongNameDelaySign = true; return true; case "/delaysign-": 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": RootContext.Version = LanguageVersion.ISO_1; return true; case "default": SetupV2 (); return true; } Report.Error (1617, "Invalid option `{0}' for /langversion. It must be either `ISO-1' or `Default'", value); return true; case "/codepage": switch (value) { case "utf8": encoding = new UTF8Encoding(); break; case "reset": encoding = Encoding.Default; break; default: try { encoding = Encoding.GetEncoding ( Int32.Parse (value)); } catch { Report.Error (2016, "Code page `{0}' is invalid or not installed", value); } break; } return true; } return false; } static void Error_WrongOption (string option) { Report.Error (2007, "Unrecognized command-line option: `{0}'", option); } static string [] AddArgs (string [] args, string [] extra_args) { string [] new_args; new_args = new string [extra_args.Length + args.Length]; // if args contains '--' we have to take that into account // split args into first half and second half based on '--' // and add the extra_args before -- int split_position = Array.IndexOf (args, "--"); if (split_position != -1) { Array.Copy (args, new_args, split_position); extra_args.CopyTo (new_args, split_position); Array.Copy (args, split_position, new_args, split_position + extra_args.Length, args.Length - split_position); } else { args.CopyTo (new_args, 0); extra_args.CopyTo (new_args, args.Length); } return new_args; } static void AddExternAlias (string identifier, string assembly) { if (assembly.Length == 0) { Report.Error (1680, "Invalid reference alias '" + identifier + "='. Missing filename"); return; } if (!IsExternAliasValid (identifier)) { Report.Error (1679, "Invalid extern alias for /reference. Alias '" + identifier + "' is not a valid identifier"); return; } // Could here hashtable throw an exception? external_aliases [identifier] = assembly; } static bool IsExternAliasValid (string identifier) { if (identifier.Length == 0) return false; if (identifier [0] != '_' && !Char.IsLetter (identifier [0])) return false; for (int i = 1; i < identifier.Length; i++) { char c = identifier [i]; if (Char.IsLetter (c) || Char.IsDigit (c)) continue; UnicodeCategory category = Char.GetUnicodeCategory (c); if (category != UnicodeCategory.Format || category != UnicodeCategory.NonSpacingMark || category != UnicodeCategory.SpacingCombiningMark || category != UnicodeCategory.ConnectorPunctuation) return false; } return true; } /// <summary> /// Parses the arguments, and drives the compilation /// process. /// </summary> /// /// <remarks> /// TODO: Mostly structured to debug the compiler /// now, needs to be turned into a real driver soon. /// </remarks> // [MonoTODO("Change error code for unknown argument to something reasonable")] internal static bool MainDriver (string [] args) { int i; bool parsing_options = true; encoding = Encoding.Default; references = new ArrayList (); external_aliases = new Hashtable (); soft_references = new ArrayList (); modules = new ArrayList (); link_paths = new ArrayList (); SetupDefaultDefines (); // // Setup defaults // // This is not required because Assembly.Load knows about this // path. // Hashtable response_file_list = null; for (i = 0; i < args.Length; i++){ string arg = args [i]; if (arg == "") continue; if (arg.StartsWith ("@")){ string [] extra_args; string response_file = arg.Substring (1); if (response_file_list == null) response_file_list = new Hashtable (); if (response_file_list.Contains (response_file)){ Report.Error ( 1515, "Response file `" + response_file + "' specified multiple times");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -