⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driver.cs

📁 C#编译器源代码。Micorsoft开放源代码
💻 CS
📖 第 1 页 / 共 4 页
字号:
		//		// Given a path specification, splits the path from the file/pattern		//		static void SplitPathAndPattern (string spec, out string path, out string pattern)		{			int p = spec.LastIndexOf ('/');			if (p != -1){				//				// Windows does not like /file.cs, switch that to:				// "\", "file.cs"				//				if (p == 0){					path = "\\";					pattern = spec.Substring (1);				} else {					path = spec.Substring (0, p);					pattern = spec.Substring (p + 1);				}				return;			}			p = spec.LastIndexOf ('\\');			if (p != -1){				path = spec.Substring (0, p);				pattern = spec.Substring (p + 1);				return;			}			path = ".";			pattern = spec;		}		static void ProcessFile (string f)		{			if (first_source == null)				first_source = f;			Location.AddFile (f);		}		static void ProcessFiles ()		{			Location.Initialize ();			foreach (SourceFile file in Location.SourceFiles) {				if (tokenize) {					tokenize_file (file);				} else {					parse (file);				}			}		}		static void CompileFiles (string spec, bool recurse)		{			string path, pattern;			SplitPathAndPattern (spec, out path, out pattern);			if (pattern.IndexOf ('*') == -1){				ProcessFile (spec);				return;			}			string [] files = null;			try {				files = Directory.GetFiles (path, pattern);			} catch (System.IO.DirectoryNotFoundException) {				Report.Error (2001, "Source file `" + spec + "' could not be found");				return;			} catch (System.IO.IOException){				Report.Error (2001, "Source file `" + spec + "' could not be found");				return;			}			foreach (string f in files) {				ProcessFile (f);			}			if (!recurse)				return;						string [] dirs = null;			try {				dirs = Directory.GetDirectories (path);			} catch {			}						foreach (string d in dirs) {									// Don't include path in this string, as each				// directory entry already does				CompileFiles (d + "/" + pattern, true);			}		}		static void DefineDefaultConfig ()		{			//			// For now the "default config" is harcoded into the compiler			// we can move this outside later			//			string [] default_config = {				"System",				"System.Xml",#if false				//				// Is it worth pre-loading all this stuff?				//				"Accessibility",				"System.Configuration.Install",				"System.Data",				"System.Design",				"System.DirectoryServices",				"System.Drawing.Design",				"System.Drawing",				"System.EnterpriseServices",				"System.Management",				"System.Messaging",				"System.Runtime.Remoting",				"System.Runtime.Serialization.Formatters.Soap",				"System.Security",				"System.ServiceProcess",				"System.Web",				"System.Web.RegularExpressions",				"System.Web.Services",				"System.Windows.Forms"#endif			};						int p = 0;			foreach (string def in default_config)				soft_references.Insert (p++, def);		}		public static string OutputFile		{			set {				output_file = value;			}			get {				return Path.GetFileName (output_file);			}		}		static void SetWarningLevel (string s)		{			int level = -1;			try {				level = Int32.Parse (s);			} catch {			}			if (level < 0 || level > 4){				Report.Error (1900, "Warning level must be in the range 0-4");				return;			}			RootContext.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);		}				//		// Currently handles the Unix-like command line options, but will be		// deprecated in favor of the CSCParseOption, which will also handle the		// options that start with a dash in the future.		//		static bool UnixParseOption (string arg, ref string [] args, ref int i)		{			switch (arg){			case "-v":				CSharpParser.yacc_verbose_flag++;				return true;			case "--version":				Version ();				return true;							case "--parse":				parse_only = true;				return true;							case "--main": case "-m":				Report.Warning (-29, "Compatibility: Use -main:CLASS instead of --main CLASS or -m CLASS");				if ((i + 1) >= args.Length){					Usage ();					Environment.Exit (1);				}				RootContext.MainClass = args [++i];				return true;							case "--unsafe":				Report.Warning (-29, "Compatibility: Use -unsafe instead of --unsafe");				RootContext.Unsafe = true;				return true;							case "/?": case "/h": case "/help":			case "--help":				Usage ();				Environment.Exit (0);				return true;			case "--define":				Report.Warning (-29, "Compatibility: Use -d:SYMBOL instead of --define SYMBOL");				if ((i + 1) >= args.Length){					Usage ();					Environment.Exit (1);				}				defines.Add (args [++i]);				return true;			case "--show-counters":				show_counters = true;				return true;							case "--expect-error": {				int code = 0;								try {					code = Int32.Parse (						args [++i], NumberStyles.AllowLeadingSign);					Report.ExpectedError = code;				} catch {					Report.Error (-14, "Invalid number specified");				} 				return true;			}							case "--tokenize": 				tokenize = true;				return true;							case "-o": 			case "--output":				Report.Warning (-29, "Compatibility: Use -out:FILE instead of --output FILE or -o FILE");				if ((i + 1) >= args.Length){					Usage ();					Environment.Exit (1);				}				OutputFile = args [++i];				return true;			case "--checked":				Report.Warning (-29, "Compatibility: Use -checked instead of --checked");				RootContext.Checked = true;				return true;							case "--stacktrace":				Report.Stacktrace = true;				return true;							case "--linkresource":			case "--linkres":				Report.Warning (-29, "Compatibility: Use -linkres:VALUE instead of --linkres VALUE");				if ((i + 1) >= args.Length){					Usage ();					Report.Error (5, "Missing argument to --linkres"); 					Environment.Exit (1);				}				if (embedded_resources == null)					embedded_resources = new Resources ();								embedded_resources.Add (false, args [++i], args [i]);				return true;							case "--resource":			case "--res":				Report.Warning (-29, "Compatibility: Use -res:VALUE instead of --res VALUE");				if ((i + 1) >= args.Length){					Usage ();					Report.Error (5, "Missing argument to --resource"); 					Environment.Exit (1);				}				if (embedded_resources == null)					embedded_resources = new Resources ();								embedded_resources.Add (true, args [++i], args [i]);				return true;							case "--target":				Report.Warning (-29, "Compatibility: Use -target:KIND instead of --target KIND");				if ((i + 1) >= args.Length){					Environment.Exit (1);					return true;				}								string type = args [++i];				switch (type){				case "library":					RootContext.Target = Target.Library;					RootContext.TargetExt = ".dll";					break;									case "exe":					RootContext.Target = Target.Exe;					break;									case "winexe":					RootContext.Target = Target.WinExe;					break;									case "module":					RootContext.Target = Target.Module;					RootContext.TargetExt = ".dll";					break;				default:					TargetUsage ();					break;				}				return true;							case "-r":				Report.Warning (-29, "Compatibility: Use -r:LIBRARY instead of -r library");				if ((i + 1) >= args.Length){					Usage ();					Environment.Exit (1);				}								string val = args [++i];				int idx = val.IndexOf ('=');				if (idx > -1) {					string alias = val.Substring (0, idx);					string assembly = val.Substring (idx + 1);					AddExternAlias (alias, assembly);					return true;				}				references.Add (val);				return true;							case "-L":				Report.Warning (-29, "Compatibility: Use -lib:ARG instead of --L arg");				if ((i + 1) >= args.Length){					Usage ();						Environment.Exit (1);				}				link_paths.Add (args [++i]);				return true;							case "--nostdlib":				Report.Warning (-29, "Compatibility: Use -nostdlib instead of --nostdlib");				RootContext.StdLib = false;				return true;							case "--fatal":				Report.Fatal = true;				return true;							case "--werror":				Report.Warning (-29, "Compatibility: Use -warnaserror: option instead of --werror");				Report.WarningsAreErrors = true;				return true;							case "--nowarn":				Report.Warning (-29, "Compatibility: Use -nowarn instead of --nowarn");				if ((i + 1) >= args.Length){					Usage ();					Environment.Exit (1);				}				int warn = 0;								try {					warn = Int32.Parse (args [++i]);				} catch {					Usage ();					Environment.Exit (1);				}				Report.SetIgnoreWarning (warn);				return true;							case "--wlevel":				Report.Warning (-29, "Compatibility: Use -warn:LEVEL instead of --wlevel LEVEL");				if ((i + 1) >= args.Length){					Report.Error (						1900,						"--wlevel requires a value from 0 to 4");					Environment.Exit (1);				}				SetWarningLevel (args [++i]);				return true;			case "--mcs-debug":				if ((i + 1) >= args.Length){					Report.Error (5, "--mcs-debug requires an argument");					Environment.Exit (1);				}				try {					Report.DebugFlags = Int32.Parse (args [++i]);				} catch {					Report.Error (5, "Invalid argument to --mcs-debug");					Environment.Exit (1);				}				return true;							case "--about":				About ();				return true;							case "--recurse":				Report.Warning (-29, "Compatibility: Use -recurse:PATTERN option instead --recurse PATTERN");				if ((i + 1) >= args.Length){					Report.Error (5, "--recurse requires an argument");					Environment.Exit (1);				}				CompileFiles (args [++i], true); 				return true;							case "--timestamp":				timestamps = true;				last_time = first_time = DateTime.Now;				return true;			case "--pause":				pause = true;				return true;							case "--debug": case "-g":				Report.Warning (-29, "Compatibility: Use -debug option instead of -g or --debug");				want_debugging_support = true;				return true;							case "--noconfig":				Report.Warning (-29, "Compatibility: Use -noconfig option instead of --noconfig");				load_default_config = false;				return true;			}			return false;		}		//		// This parses the -arg and /arg options to the compiler, even if the strings		// in the following text use "/arg" on the strings.		//		static bool CSCParseOption (string option, ref string [] args, ref int i)		{			int idx = option.IndexOf (':');			string arg, value;			if (idx == -1){				arg = option;				value = "";			} else {				arg = option.Substring (0, idx);				value = option.Substring (idx + 1);			}			switch (arg){			case "/nologo":				return true;			case "/t":			case "/target":				switch (value){				case "exe":					RootContext.Target = Target.Exe;					break;				case "winexe":					RootContext.Target = Target.WinExe;					break;				case "library":					RootContext.Target = Target.Library;					RootContext.TargetExt = ".dll";					break;				case "module":					RootContext.Target = Target.Module;					RootContext.TargetExt = ".netmodule";					break;				default:					TargetUsage ();					break;				}				return true;			case "/out":				if (value == ""){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -