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

📄 rootcontext.cs

📁 C#编译器源代码。Micorsoft开放源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
				"System.RuntimeArgumentHandle",				"System.RuntimeTypeHandle",				"System.IntPtr",				"System.TypedReference",				"System.ArgIterator"			};						foreach (string cname in structs_second_stage)				BootstrapCorlib_ResolveStruct (root, cname);						//			// These are classes that depends on the core interfaces			//			string [] classes_second_stage = {				"System.Enum",				"System.String",				"System.Array",				"System.Reflection.MemberInfo",				"System.Type",				"System.Exception",				//				// These are not really important in the order, but they				// are used by the compiler later on (typemanager/CoreLookupType-d)				//				"System.Runtime.CompilerServices.RuntimeHelpers",				"System.Reflection.DefaultMemberAttribute",				"System.Threading.Monitor",								"System.AttributeUsageAttribute",				"System.Runtime.InteropServices.DllImportAttribute",				"System.Runtime.CompilerServices.MethodImplAttribute",				"System.Runtime.InteropServices.MarshalAsAttribute",				"System.Diagnostics.ConditionalAttribute",				"System.ObsoleteAttribute",				"System.ParamArrayAttribute",				"System.CLSCompliantAttribute",				"System.Security.UnverifiableCodeAttribute",				"System.Security.Permissions.SecurityAttribute",				"System.Runtime.CompilerServices.DecimalConstantAttribute",				"System.Runtime.InteropServices.InAttribute",				"System.Runtime.InteropServices.OutAttribute",				"System.Runtime.InteropServices.StructLayoutAttribute",				"System.Runtime.InteropServices.FieldOffsetAttribute",				"System.InvalidOperationException",				"System.NotSupportedException",				"System.MarshalByRefObject",				"System.Security.CodeAccessPermission",				"System.Runtime.CompilerServices.RequiredAttributeAttribute",				"System.Runtime.InteropServices.GuidAttribute",				"System.Reflection.AssemblyCultureAttribute"			};			foreach (string cname in classes_second_stage)				BootstrapCorlib_ResolveClass (root, cname);			BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");			// These will be defined indirectly during the previous ResolveDelegate.			// However make sure the rest of the checks happen.			string [] delegate_types = { "System.Delegate", "System.MulticastDelegate" };			foreach (string cname in delegate_types)				BootstrapCorlib_ResolveClass (root, cname);		}					// <summary>		//   Closes all open types		// </summary>		//		// <remarks>		//   We usually use TypeBuilder types.  When we are done		//   creating the type (which will happen after we have added		//   methods, fields, etc) we need to "Define" them before we		//   can save the Assembly		// </remarks>		static public void CloseTypes ()		{			TypeContainer root = Tree.Types;						if (root.Enums != null)				foreach (Enum en in root.Enums)					en.CloseType ();			//			// We do this in two passes, first we close the structs,			// then the classes, because it seems the code needs it this			// way.  If this is really what is going on, we should probably			// make sure that we define the structs in order as well.			//			foreach (TypeContainer tc in type_container_resolve_order){				if (tc.Kind == Kind.Struct && tc.Parent == tree.Types){					tc.CloseType ();				}			}			foreach (TypeContainer tc in type_container_resolve_order){				if (!(tc.Kind == Kind.Struct && tc.Parent == tree.Types))					tc.CloseType ();								}						if (root.Delegates != null)				foreach (Delegate d in root.Delegates)					d.CloseType ();			//			// If we have a <PrivateImplementationDetails> class, close it			//			if (helper_classes != null){				foreach (TypeBuilder type_builder in helper_classes) {#if NET_2_0					type_builder.SetCustomAttribute (TypeManager.compiler_generated_attr);#endif					type_builder.CreateType ();				}			}						type_container_resolve_order = null;			helper_classes = null;			//tree = null;			TypeManager.CleanUp ();		}		/// <summary>		///   Used to register classes that need to be closed after all the		///   user defined classes		/// </summary>		public static void RegisterCompilerGeneratedType (TypeBuilder helper_class)		{			if (helper_classes == null)				helper_classes = new ArrayList ();			helper_classes.Add (helper_class);		}				static public void PopulateCoreType (TypeContainer root, string name)		{			DeclSpace ds = (DeclSpace) root.GetDefinition (name);			ds.DefineMembers (root);			ds.Define ();		}				static public void BootCorlib_PopulateCoreTypes ()		{			TypeContainer root = tree.Types;			PopulateCoreType (root, "System.Object");			PopulateCoreType (root, "System.ValueType");			PopulateCoreType (root, "System.Attribute");			PopulateCoreType (root, "System.Runtime.CompilerServices.IndexerNameAttribute");		}				// <summary>		//   Populates the structs and classes with fields and methods		// </summary>		//		// This is invoked after all interfaces, structs and classes		// have been defined through `ResolveTree' 		static public void PopulateTypes ()		{			TypeContainer root = Tree.Types;			if (type_container_resolve_order != null){				if (RootContext.StdLib){					foreach (TypeContainer tc in type_container_resolve_order)						tc.DefineMembers (root);				} else {					foreach (TypeContainer tc in type_container_resolve_order) {						// When compiling corlib, these types have already been						// populated from BootCorlib_PopulateCoreTypes ().						if (((tc.Name == "System.Object") ||							(tc.Name == "System.Attribute") ||							(tc.Name == "System.ValueType") ||							(tc.Name == "System.Runtime.CompilerServices.IndexerNameAttribute")))						continue;						tc.DefineMembers (root);					}				} 			}			ArrayList delegates = root.Delegates;			if (delegates != null){				foreach (Delegate d in delegates)					d.DefineMembers (root);			}			ArrayList enums = root.Enums;			if (enums != null){				foreach (Enum en in enums)					en.DefineMembers (root);			}			//			// Check for cycles in the struct layout			//			if (type_container_resolve_order != null){				Hashtable seen = new Hashtable ();				foreach (TypeContainer tc in type_container_resolve_order)					TypeManager.CheckStructCycles (tc, seen);			}		}		//		// A generic hook delegate		//		public delegate void Hook ();		//		// A hook invoked when the code has been generated.		//		public static event Hook EmitCodeHook;		//		// DefineTypes is used to fill in the members of each type.		//		static public void DefineTypes ()		{			TypeContainer root = Tree.Types;			ArrayList delegates = root.Delegates;			if (delegates != null){				foreach (Delegate d in delegates)					d.Define ();			}			if (type_container_resolve_order != null){				foreach (TypeContainer tc in type_container_resolve_order) {					// When compiling corlib, these types have already been					// populated from BootCorlib_PopulateCoreTypes ().					if (!RootContext.StdLib &&					    ((tc.Name == "System.Object") ||					     (tc.Name == "System.Attribute") ||					     (tc.Name == "System.ValueType") ||					     (tc.Name == "System.Runtime.CompilerServices.IndexerNameAttribute")))						continue;					tc.Define ();				}			}			ArrayList enums = root.Enums;			if (enums != null){				foreach (Enum en in enums)					en.Define ();			}		}		static public void EmitCode ()		{			if (Tree.Types.Enums != null) {				foreach (Enum e in Tree.Types.Enums)					e.Emit ();			}			if (type_container_resolve_order != null) {				foreach (TypeContainer tc in type_container_resolve_order)					tc.EmitType ();				if (Report.Errors > 0)					return;				foreach (TypeContainer tc in type_container_resolve_order)					tc.VerifyMembers ();			}						if (Tree.Types.Delegates != null) {				foreach (Delegate d in Tree.Types.Delegates)					d.Emit ();			}						//			// Run any hooks after all the types have been defined.			// This is used to create nested auxiliary classes for example			//			if (EmitCodeHook != null)				EmitCodeHook ();			CodeGen.Assembly.Emit (Tree.Types);			CodeGen.Module.Emit (Tree.Types);		}				//		// Public Field, used to track which method is the public entry		// point.		//		static public MethodInfo EntryPoint;                //                // Track the location of the entry point.                //                static public Location EntryPointLocation;		//		// These are used to generate unique names on the structs and fields.		//		static int field_count;				//		// Makes an initialized struct, returns the field builder that		// references the data.  Thanks go to Sergey Chaban for researching		// how to do this.  And coming up with a shorter mechanism than I		// was able to figure out.		//		// This works but makes an implicit public struct $ArrayType$SIZE and		// makes the fields point to it.  We could get more control if we did		// use instead:		//		// 1. DefineNestedType on the impl_details_class with our struct.		//		// 2. Define the field on the impl_details_class		//		static public FieldBuilder MakeStaticData (byte [] data)		{			FieldBuilder fb;						if (impl_details_class == null){				impl_details_class = CodeGen.Module.Builder.DefineType (					"<PrivateImplementationDetails>",                                        TypeAttributes.NotPublic,                                        TypeManager.object_type);                                				RegisterCompilerGeneratedType (impl_details_class);			}			fb = impl_details_class.DefineInitializedData (				"$$field-" + (field_count++), data,				FieldAttributes.Static | FieldAttributes.Assembly);						return fb;		}		public static void CheckUnsafeOption (Location loc)		{			if (!Unsafe) {				Report.Error (227, loc, 					"Unsafe code requires the `unsafe' command line option to be specified");			}		}	}}	      

⌨️ 快捷键说明

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