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

📄 rootcontext.cs

📁 C#编译器源代码。Micorsoft开放源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
//// rootcontext.cs: keeps track of our tree representation, and assemblies loaded.//// Author: Miguel de Icaza (miguel@ximian.com)//         Ravi Pratap     (ravi@ximian.com)//// Licensed under the terms of the GNU GPL//// (C) 2001 Ximian, Inc (http://www.ximian.com)// (C) 2004 Novell, Incusing System;using System.Collections;using System.Reflection;using System.Reflection.Emit;using System.Diagnostics;namespace Mono.CSharp {	public enum LanguageVersion	{		Default	= 0,		ISO_1	= 1	}	public class RootContext {		//		// Contains the parsed tree		//		static Tree tree;		//		// This hashtable contains all of the #definitions across the source code		// it is used by the ConditionalAttribute handler.		//		public static Hashtable AllDefines = new Hashtable ();				//		// Whether we are being linked against the standard libraries.		// This is only used to tell whether `System.Object' should		// have a base class or not.		//		public static bool StdLib;		//		// This keeps track of the order in which classes were defined		// so that we can poulate them in that order.		//		// Order is important, because we need to be able to tell, by		// examining the list of methods of the base class, which ones are virtual		// or abstract as well as the parent names (to implement new, 		// override).		//		static ArrayList type_container_resolve_order;		//		// Holds a reference to the Private Implementation Details		// class.		//		static ArrayList helper_classes;				static TypeBuilder impl_details_class;		public static int WarningLevel;				public static Target Target;		public static string TargetExt;		public static bool VerifyClsCompliance = true;		/// <summary>		/// Holds /optimize option		/// </summary>		public static bool Optimize = true;		public static LanguageVersion Version;		//		// We keep strongname related info here because		// it's also used as complier options from CSC 8.x		//		public static string StrongNameKeyFile;		public static string StrongNameKeyContainer;		public static bool StrongNameDelaySign;		//		// If set, enable XML documentation generation		//		public static Documentation Documentation;		static public string MainClass;		//		// Constructor		//		static RootContext ()		{			Reset ();		}		public static void Reset ()		{			tree = new Tree ();			type_container_resolve_order = new ArrayList ();			EntryPoint = null;			WarningLevel = 3;			Checked = false;			Unsafe = false;			StdLib = true;			StrongNameKeyFile = null;			StrongNameKeyContainer = null;			StrongNameDelaySign = false;			MainClass = null;			Target = Target.Exe;		    	TargetExt = ".exe";			Version = LanguageVersion.Default;			Documentation = null;			impl_details_class = null;		}				public static bool NeedsEntryPoint {			get {				return RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe;			}		}		static public Tree Tree {			get {				return tree;			}		}		public static void RegisterOrder (TypeContainer tc)		{			type_container_resolve_order.Add (tc);		}				// 		// The default compiler checked state		//		static public bool Checked;		//		// Whether to allow Unsafe code		//		static public bool Unsafe;				// <remarks>		//   This function is used to resolve the hierarchy tree.		//   It processes interfaces, structs and classes in that order.		//		//   It creates the TypeBuilder's as it processes the user defined		//   types.  		// </remarks>		static public void ResolveTree ()		{			//			// Interfaces are processed next, as classes and			// structs might inherit from an object or implement			// a set of interfaces, we need to be able to tell			// them appart by just using the TypeManager.			//			TypeContainer root = Tree.Types;			ArrayList ifaces = root.Interfaces;			if (ifaces != null){				foreach (TypeContainer i in ifaces) 					i.DefineType ();			}			foreach (TypeContainer tc in root.Types)				tc.DefineType ();			if (root.Delegates != null)				foreach (Delegate d in root.Delegates) 					d.DefineType ();			if (root.Enums != null)				foreach (Enum e in root.Enums)					e.DefineType ();		}		static void Error_TypeConflict (string name, Location loc)		{			Report.Error (				520, loc, "`" + name + "' conflicts with a predefined type");		}		static void Error_TypeConflict (string name)		{			Report.Error (				520, "`" + name + "' conflicts with a predefined type");		}		//		// Resolves a single class during the corlib bootstrap process		//		static TypeBuilder BootstrapCorlib_ResolveClass (TypeContainer root, string name)		{			object o = root.GetDefinition (name);			if (o == null){				Report.Error (518, "The predefined type `" + name + "' is not defined or imported");				return null;			}			if (!(o is Class)){				if (o is DeclSpace){					DeclSpace d = (DeclSpace) o;					Error_TypeConflict (name, d.Location);				} else					Error_TypeConflict (name);				return null;			}			return ((DeclSpace) o).DefineType ();		}		//		// Resolves a struct during the corlib bootstrap process		//		static void BootstrapCorlib_ResolveStruct (TypeContainer root, string name)		{			object o = root.GetDefinition (name);			if (o == null){				Report.Error (518, "The predefined type `" + name + "' is not defined or imported");				return;			}			if (!(o is Struct)){				if (o is DeclSpace){					DeclSpace d = (DeclSpace) o;					Error_TypeConflict (name, d.Location);				} else					Error_TypeConflict (name);				return;			}			((DeclSpace) o).DefineType ();		}		//		// Resolves a struct during the corlib bootstrap process		//		static void BootstrapCorlib_ResolveInterface (TypeContainer root, string name)		{			object o = root.GetDefinition (name);			if (o == null){				Report.Error (518, "The predefined type `" + name + "' is not defined or imported");				return;			}			if (!(o is Interface)){				if (o is DeclSpace){					DeclSpace d = (DeclSpace) o;					Error_TypeConflict (name, d.Location);				} else					Error_TypeConflict (name);				return;			}			((DeclSpace) o).DefineType ();		}		//		// Resolves a delegate during the corlib bootstrap process		//		static void BootstrapCorlib_ResolveDelegate (TypeContainer root, string name)		{			object o = root.GetDefinition (name);			if (o == null){				Report.Error (518, "The predefined type `" + name + "' is not defined or imported");				return;			}			if (!(o is Delegate)){				Error_TypeConflict (name);				return;			}			((DeclSpace) o).DefineType ();		}				/// <summary>		///    Resolves the core types in the compiler when compiling with --nostdlib		/// </summary>		static public void ResolveCore ()		{			TypeContainer root = Tree.Types;			TypeManager.object_type = BootstrapCorlib_ResolveClass (root, "System.Object");			TypeManager.value_type = BootstrapCorlib_ResolveClass (root, "System.ValueType");			TypeManager.attribute_type = BootstrapCorlib_ResolveClass (root, "System.Attribute");			TypeManager.indexer_name_type = BootstrapCorlib_ResolveClass (root, "System.Runtime.CompilerServices.IndexerNameAttribute");						string [] interfaces_first_stage = {				"System.IComparable", "System.ICloneable",				"System.IConvertible",								"System.Collections.IEnumerable",				"System.Collections.ICollection",				"System.Collections.IEnumerator",				"System.Collections.IList", 				"System.IAsyncResult",				"System.IDisposable",								"System.Runtime.Serialization.ISerializable",				"System.Reflection.IReflect",				"System.Reflection.ICustomAttributeProvider"			};			foreach (string iname in interfaces_first_stage)				BootstrapCorlib_ResolveInterface (root, iname);			//			// These are the base value types			//			string [] structs_first_stage = {				"System.Byte",    "System.SByte",				"System.Int16",   "System.UInt16",				"System.Int32",   "System.UInt32",				"System.Int64",   "System.UInt64",			};			foreach (string cname in structs_first_stage)				BootstrapCorlib_ResolveStruct (root, cname);			//			// Now, we can load the enumerations, after this point,			// we can use enums.			//			TypeManager.InitEnumUnderlyingTypes ();			string [] structs_second_stage = {				"System.Single",  "System.Double",				"System.Char",    "System.Boolean",				"System.Decimal", "System.Void",				"System.RuntimeFieldHandle",

⌨️ 快捷键说明

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