X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Freflection.cs;h=5181e3f3253645d491dedad8db7c4c6097ef8784;hb=8e33e0d088c564d039dd791b7cc3e121ff87b3e4;hp=ddd704bdb02cfdafbbc588fa577328bf81fc15bb;hpb=3abe771dfe03091aa22521a9df3d4f09adc21737;p=mono.git diff --git a/mcs/mcs/reflection.cs b/mcs/mcs/reflection.cs index ddd704bdb02..5181e3f3253 100644 --- a/mcs/mcs/reflection.cs +++ b/mcs/mcs/reflection.cs @@ -22,7 +22,7 @@ namespace Mono.CSharp #if STATIC public class ReflectionImporter { - public ReflectionImporter (BuildinTypes buildin) + public ReflectionImporter (ModuleContainer module, BuiltinTypes builtin) { throw new NotSupportedException (); } @@ -43,11 +43,16 @@ namespace Mono.CSharp } } #else - public class ReflectionImporter : MetadataImporter + public sealed class ReflectionImporter : MetadataImporter { - public ReflectionImporter (BuildinTypes buildin) + public ReflectionImporter (ModuleContainer module, BuiltinTypes builtin) + : base (module) + { + Initialize (builtin); + } + + public override void AddCompiledType (TypeBuilder builder, TypeSpec spec) { - Initialize (buildin); } protected override MemberKind DetermineKindFromBaseType (Type baseType) @@ -64,14 +69,11 @@ namespace Mono.CSharp return MemberKind.Class; } - protected override bool HasVolatileModifier (FieldInfo field) + protected override bool HasVolatileModifier (Type[] modifiers) { - var reqs = field.GetRequiredCustomModifiers (); - if (reqs.Length > 0) { - foreach (var t in reqs) { - if (t == typeof (IsVolatile)) - return true; - } + foreach (var t in modifiers) { + if (t == typeof (IsVolatile)) + return true; } return false; @@ -101,7 +103,7 @@ namespace Mono.CSharp public ImportedModuleDefinition ImportModule (Module module, RootNamespace targetNamespace) { - var module_definition = new ImportedModuleDefinition (module, this); + var module_definition = new ImportedModuleDefinition (module); module_definition.ReadAttributes (); Type[] all_types; @@ -116,48 +118,65 @@ namespace Mono.CSharp return module_definition; } - void Initialize (BuildinTypes buildin) + void Initialize (BuiltinTypes builtin) { // // Setup mapping for build-in types to avoid duplication of their definition // - buildin_types.Add (typeof (object), buildin.Object); - buildin_types.Add (typeof (System.ValueType), buildin.ValueType); - buildin_types.Add (typeof (System.Attribute), buildin.Attribute); - - buildin_types.Add (typeof (int), buildin.Int); - buildin_types.Add (typeof (long), buildin.Long); - buildin_types.Add (typeof (uint), buildin.UInt); - buildin_types.Add (typeof (ulong), buildin.ULong); - buildin_types.Add (typeof (byte), buildin.Byte); - buildin_types.Add (typeof (sbyte), buildin.SByte); - buildin_types.Add (typeof (short), buildin.Short); - buildin_types.Add (typeof (ushort), buildin.UShort); - - buildin_types.Add (typeof (System.Collections.IEnumerator), buildin.IEnumerator); - buildin_types.Add (typeof (System.Collections.IEnumerable), buildin.IEnumerable); - buildin_types.Add (typeof (System.IDisposable), buildin.IDisposable); - - buildin_types.Add (typeof (char), buildin.Char); - buildin_types.Add (typeof (string), buildin.String); - buildin_types.Add (typeof (float), buildin.Float); - buildin_types.Add (typeof (double), buildin.Double); - buildin_types.Add (typeof (decimal), buildin.Decimal); - buildin_types.Add (typeof (bool), buildin.Bool); - buildin_types.Add (typeof (System.IntPtr), buildin.IntPtr); - buildin_types.Add (typeof (System.UIntPtr), buildin.UIntPtr); - - buildin_types.Add (typeof (System.MulticastDelegate), buildin.MulticastDelegate); - buildin_types.Add (typeof (System.Delegate), buildin.Delegate); - buildin_types.Add (typeof (System.Enum), buildin.Enum); - buildin_types.Add (typeof (System.Array), buildin.Array); - buildin_types.Add (typeof (void), buildin.Void); - buildin_types.Add (typeof (System.Type), buildin.Type); - buildin_types.Add (typeof (System.Exception), buildin.Exception); - buildin_types.Add (typeof (System.RuntimeFieldHandle), buildin.RuntimeFieldHandle); - buildin_types.Add (typeof (System.RuntimeTypeHandle), buildin.RuntimeTypeHandle); + compiled_types.Add (typeof (object), builtin.Object); + compiled_types.Add (typeof (System.ValueType), builtin.ValueType); + compiled_types.Add (typeof (System.Attribute), builtin.Attribute); + + compiled_types.Add (typeof (int), builtin.Int); + compiled_types.Add (typeof (long), builtin.Long); + compiled_types.Add (typeof (uint), builtin.UInt); + compiled_types.Add (typeof (ulong), builtin.ULong); + compiled_types.Add (typeof (byte), builtin.Byte); + compiled_types.Add (typeof (sbyte), builtin.SByte); + compiled_types.Add (typeof (short), builtin.Short); + compiled_types.Add (typeof (ushort), builtin.UShort); + + compiled_types.Add (typeof (System.Collections.IEnumerator), builtin.IEnumerator); + compiled_types.Add (typeof (System.Collections.IEnumerable), builtin.IEnumerable); + compiled_types.Add (typeof (System.IDisposable), builtin.IDisposable); + + compiled_types.Add (typeof (char), builtin.Char); + compiled_types.Add (typeof (string), builtin.String); + compiled_types.Add (typeof (float), builtin.Float); + compiled_types.Add (typeof (double), builtin.Double); + compiled_types.Add (typeof (decimal), builtin.Decimal); + compiled_types.Add (typeof (bool), builtin.Bool); + compiled_types.Add (typeof (System.IntPtr), builtin.IntPtr); + compiled_types.Add (typeof (System.UIntPtr), builtin.UIntPtr); + + compiled_types.Add (typeof (System.MulticastDelegate), builtin.MulticastDelegate); + compiled_types.Add (typeof (System.Delegate), builtin.Delegate); + compiled_types.Add (typeof (System.Enum), builtin.Enum); + compiled_types.Add (typeof (System.Array), builtin.Array); + compiled_types.Add (typeof (void), builtin.Void); + compiled_types.Add (typeof (System.Type), builtin.Type); + compiled_types.Add (typeof (System.Exception), builtin.Exception); + compiled_types.Add (typeof (System.RuntimeFieldHandle), builtin.RuntimeFieldHandle); + compiled_types.Add (typeof (System.RuntimeTypeHandle), builtin.RuntimeTypeHandle); + } + } + + [System.Runtime.InteropServices.StructLayout (System.Runtime.InteropServices.LayoutKind.Explicit)] + struct SingleConverter + { + [System.Runtime.InteropServices.FieldOffset (0)] + int i; + [System.Runtime.InteropServices.FieldOffset (0)] + float f; + + public static int SingleToInt32Bits (float v) + { + SingleConverter c = new SingleConverter (); + c.f = v; + return c.i; } } + #endif public class AssemblyDefinitionDynamic : AssemblyDefinition @@ -203,19 +222,11 @@ namespace Mono.CSharp ResolveAssemblySecurityAttributes (); var an = CreateAssemblyName (); - try { - Builder = file_name == null ? - domain.DefineDynamicAssembly (an, access) : - domain.DefineDynamicAssembly (an, access, Dirname (file_name)); - } catch (ArgumentException) { - // specified key may not be exportable outside it's container - if (RootContext.StrongNameKeyContainer != null) { - Report.Error (1548, "Could not access the key inside the container `" + - RootContext.StrongNameKeyContainer + "'."); - } - throw; - } + Builder = file_name == null ? + domain.DefineDynamicAssembly (an, access) : + domain.DefineDynamicAssembly (an, access, Dirname (file_name)); + module.Create (this, CreateModuleBuilder ()); builder_extra = new AssemblyBuilderMonoSpecific (Builder, Compiler); return true; #endif @@ -246,6 +257,8 @@ namespace Mono.CSharp } catch { base.SaveModule (pekind, machine); } + + Builder.Save (file_name, pekind, machine); } #endif } @@ -381,6 +394,8 @@ namespace Mono.CSharp public DynamicLoader (ReflectionImporter importer, CompilerContext compiler) : base (compiler) { + paths.Add (GetSystemDir ()); + this.importer = importer; } @@ -390,11 +405,6 @@ namespace Mono.CSharp } } - public override bool HasObjectType (Assembly assembly) - { - return assembly.GetType (compiler.BuildinTypes.Object.FullName) != null; - } - protected override string[] GetDefaultReferences () { // @@ -411,23 +421,30 @@ namespace Mono.CSharp default_references.Add ("System.Windows.Browser"); #endif - if (RootContext.Version > LanguageVersion.ISO_2) + if (compiler.Settings.Version > LanguageVersion.ISO_2) default_references.Add ("System.Core"); - if (RootContext.Version > LanguageVersion.V_3) + if (compiler.Settings.Version > LanguageVersion.V_3) default_references.Add ("Microsoft.CSharp"); return default_references.ToArray (); } - public override Assembly LoadAssemblyFile (string fileName) + // + // Returns the directory where the system assemblies are installed + // + static string GetSystemDir () { - return LoadAssemblyFile (fileName, false); + return Path.GetDirectoryName (typeof (object).Assembly.Location); } - Assembly LoadAssemblyFile (string assembly, bool soft) + public override bool HasObjectType (Assembly assembly) + { + return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null; + } + + public override Assembly LoadAssemblyFile (string assembly, bool isImplicitReference) { Assembly a = null; - string total_log = ""; try { try { @@ -442,7 +459,7 @@ namespace Mono.CSharp a = Assembly.Load (ass); } } catch (FileNotFoundException) { - bool err = !soft; + bool err = !isImplicitReference; foreach (string dir in paths) { string full_path = Path.Combine (dir, assembly); if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe")) @@ -452,12 +469,10 @@ namespace Mono.CSharp a = Assembly.LoadFrom (full_path); err = false; break; - } catch (FileNotFoundException ff) { - if (soft) - return a; - total_log += ff.FusionLog; + } catch (FileNotFoundException) { } } + if (err) { Error_FileNotFound (assembly); return a; @@ -470,11 +485,6 @@ namespace Mono.CSharp return a; } - public override Assembly LoadAssemblyDefault (string fileName) - { - return LoadAssemblyFile (fileName, true); - } - Module LoadModuleFile (AssemblyDefinitionDynamic assembly, string module) { string total_log = ""; @@ -509,10 +519,7 @@ namespace Mono.CSharp public void LoadModules (AssemblyDefinitionDynamic assembly, RootNamespace targetNamespace) { - if (RootContext.Modules.Count == 0) - return; - - foreach (var moduleName in RootContext.Modules) { + foreach (var moduleName in compiler.Settings.Modules) { var m = LoadModuleFile (assembly, moduleName); if (m == null) continue;