コード例 #1
0
ファイル: context.cs プロジェクト: Ein/monodevelop
		public CompilerContext (ReflectionMetaImporter metaImporter, Report report)
		{
			this.meta_importer = metaImporter;
			this.report = report;

			this.attributes = new PredefinedAttributes ();
			this.root = new GlobalRootNamespace ();
		}
コード例 #2
0
ファイル: CSharpBinder.cs プロジェクト: stabbylambda/mono
		public static DynamicContext Create ()
		{
			if (dc != null)
				return dc;

			lock (compiler_initializer) {
				if (dc != null)
					return dc;

				var importer = new Compiler.ReflectionMetaImporter () {
					IgnorePrivateMembers = false
				};

				var core_types = Compiler.TypeManager.InitCoreTypes ();
				importer.Initialize ();

				// I don't think dynamically loaded assemblies can be used as dynamic
				// expression without static type to be loaded first
				// AppDomain.CurrentDomain.AssemblyLoad += (sender, e) => { throw new NotImplementedException (); };

				// Import all currently loaded assemblies
				var ns = Compiler.GlobalRootNamespace.Instance;
				foreach (System.Reflection.Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
					ns.AddAssemblyReference (a);
					importer.ImportAssembly (a, ns);
				}

				var reporter = new Compiler.Report (ErrorPrinter.Instance) {
					WarningLevel = 0
				};

				var cc = new Compiler.CompilerContext (importer, reporter) {
					IsRuntimeBinder = true
				};

				Compiler.TypeManager.InitCoreTypes (cc, core_types);
				Compiler.TypeManager.InitOptionalCoreTypes (cc);

				dc = new DynamicContext (cc);
			}

			return dc;
		}
コード例 #3
0
ファイル: CSharpBinder.cs プロジェクト: davidwaters/mono
		public static DynamicContext Create ()
		{
			if (dc != null)
				return dc;

			lock (compiler_initializer) {
				if (dc != null)
					return dc;

				var importer = new Compiler.ReflectionMetaImporter () {
					IgnorePrivateMembers = false
				};

				var reporter = new Compiler.Report (ErrorPrinter.Instance) {
					WarningLevel = 0
				};

				var cc = new Compiler.CompilerContext (importer, reporter) {
					IsRuntimeBinder = true
				};

				IList<Compiler.PredefinedTypeSpec> core_types = null;
				// HACK: To avoid re-initializing static TypeManager types, like string_type
				if (!Compiler.RootContext.EvalMode) {
					core_types = Compiler.TypeManager.InitCoreTypes ();
				}

				importer.Initialize ();

				//
				// Any later loaded assemblies are handled internally by GetAssemblyDefinition
				// domain.AssemblyLoad cannot be used as that would be too destructive as we
				// would hold all loaded assemblies even if they can be never visited
				//
				// TODO: Remove this code and rely on GetAssemblyDefinition only
				//
				Compiler.RootContext.ToplevelTypes = new Compiler.ModuleContainer (cc);
				var temp = Compiler.RootContext.ToplevelTypes.MakeExecutable ("dynamic");

				// Import all currently loaded assemblies
				var domain = AppDomain.CurrentDomain;

				temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
				foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
					importer.ImportAssembly (a, Compiler.RootContext.ToplevelTypes.GlobalRootNamespace);
				}

				if (!Compiler.RootContext.EvalMode) {
					Compiler.TypeManager.InitCoreTypes (Compiler.RootContext.ToplevelTypes, core_types);
					Compiler.TypeManager.InitOptionalCoreTypes (cc);
				}

				dc = new DynamicContext (cc);
			}

			return dc;
		}
コード例 #4
0
ファイル: context.cs プロジェクト: silk/monodevelop
		public CompilerContext (ReflectionMetaImporter metaImporter, Report report)
		{
			this.meta_importer = metaImporter;
			this.attributes = new PredefinedAttributes ();
			this.report = report;
		}
コード例 #5
0
ファイル: import.cs プロジェクト: davidwaters/mono
		public ImportedTypeDefinition (ReflectionMetaImporter metaImport, Type type)
			: base (type)
		{
			this.meta_import = metaImport;
		}
コード例 #6
0
ファイル: import.cs プロジェクト: davidwaters/mono
		//ReflectionMetaImporter metaImporter;
		
		public ImportedModuleDefinition (Module module, ReflectionMetaImporter metaImporter)
		{
			this.module = module;
			//this.metaImporter = metaImporter;
		}
コード例 #7
0
ファイル: import.cs プロジェクト: davidwaters/mono
			public static AttributesBag Read (MemberInfo mi, ReflectionMetaImporter typeImporter)
			{
				AttributesBag bag = null;
				List<string> conditionals = null;

				// It should not throw any loading exception
				IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (mi);

				foreach (var a in attrs) {
					var type = a.Constructor.DeclaringType;
					if (type == typeof (ObsoleteAttribute)) {
						if (bag == null)
							bag = new AttributesBag ();

						var args = a.ConstructorArguments;

						if (args.Count == 1) {
							bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value);
						} else if (args.Count == 2) {
							bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value, (bool) args[1].Value);
						} else {
							bag.Obsolete = new ObsoleteAttribute ();
						}

						continue;
					}

					if (type == typeof (ConditionalAttribute)) {
						if (bag == null)
							bag = new AttributesBag ();

						if (conditionals == null)
							conditionals = new List<string> (2);

						conditionals.Add ((string) a.ConstructorArguments[0].Value);
						continue;
					}

					if (type == typeof (CLSCompliantAttribute)) {
						if (bag == null)
							bag = new AttributesBag ();

						bag.IsNotCLSCompliant = !(bool) a.ConstructorArguments[0].Value;
						continue;
					}

					// Type only attributes
					if (mi.MemberType == MemberTypes.TypeInfo || mi.MemberType == MemberTypes.NestedType) {
						if (type == typeof (DefaultMemberAttribute)) {
							if (bag == null)
								bag = new AttributesBag ();

							bag.DefaultIndexerName = (string) a.ConstructorArguments[0].Value;
							continue;
						}

						if (type == typeof (AttributeUsageAttribute)) {
							if (bag == null)
								bag = new AttributesBag ();

							bag.AttributeUsage = new AttributeUsageAttribute ((AttributeTargets) a.ConstructorArguments[0].Value);
							foreach (var named in a.NamedArguments) {
								if (named.MemberInfo.Name == "AllowMultiple")
									bag.AttributeUsage.AllowMultiple = (bool) named.TypedValue.Value;
								else if (named.MemberInfo.Name == "Inherited")
									bag.AttributeUsage.Inherited = (bool) named.TypedValue.Value;
							}
							continue;
						}

						// Interface only attribute
						if (typeImporter != null && type == typeof (CoClassAttribute)) {
							if (bag == null)
								bag = new AttributesBag ();

							bag.CoClass = typeImporter.ImportType ((Type) a.ConstructorArguments[0].Value);
							continue;
						}
					}
				}

				if (bag == null)
					return Default;

				if (conditionals != null)
					bag.Conditionals = conditionals.ToArray ();
				
				return bag;
			}