public static IAssemblyReference GetAssemblyReference(IType value)
        {
            ITypeReference typeReference = value as ITypeReference;

            if (typeReference != null)
            {
                ITypeReference declaringType = typeReference.Owner as ITypeReference;
                if (declaringType != null)
                {
                    return(GetAssemblyReference(declaringType));
                }

                IModuleReference moduleReference = typeReference.Owner as IModuleReference;
                if (moduleReference != null)
                {
                    IModule module = moduleReference.Resolve();
                    return(module.Assembly);
                }

                IAssemblyReference assemblyReference = typeReference.Owner as IAssemblyReference;
                if (assemblyReference != null)
                {
                    return(assemblyReference);
                }
            }

            throw new NotSupportedException();
        }
Пример #2
0
 public override void Visit(IModuleReference moduleReference)
 {
     if (moduleReference != this.module)
     {
         RecordModuleReference(moduleReference);
     }
 }
Пример #3
0
 /// <summary>
 /// Returns a "live" System.Reflection.Module instance that provides reflective access to the referenced module.
 /// If the module cannot be found or cannot be loaded, the result is null.
 /// </summary>
 public Module/*?*/ GetModule(IModuleReference/*?*/ moduleReference) {
   if (moduleReference == null) return null;
   if (moduleReference.ContainingAssembly == null) return null;
   var assembly = this.GetAssembly(moduleReference.ContainingAssembly);
   if (assembly == null) return null;
   return assembly.GetModule(moduleReference.Name.Value);
 }
Пример #4
0
 public override void Visit(IModuleReference moduleReference)
 {
     if (moduleReference != Context.Module)
     {
         RecordModuleReference(moduleReference);
     }
 }
 public override void Visit(IModuleReference moduleReference)
 {
     if (Process(moduleReference))
     {
         visitor.Visit(moduleReference);
     }
     base.Visit(moduleReference);
 }
Пример #6
0
 public override IModuleReference Rewrite(IModuleReference moduleReference)
 {
     if (this.sourceUnitIdentities.ContainsKey(moduleReference.UnitIdentity))
     {
         return(this.targetAssembly);
     }
     return(base.Rewrite(moduleReference));
 }
Пример #7
0
 public TupleTypeReference(ImmutableArray <ITypeReference> elementTypes,
                           ImmutableArray <string> elementNames = default(ImmutableArray <string>),
                           IModuleReference valueTupleAssembly  = null)
 {
     this.ValueTupleAssembly = valueTupleAssembly;
     this.ElementTypes       = elementTypes;
     this.ElementNames       = elementNames;
 }
Пример #8
0
 /// <summary>
 /// Rewrites the given module reference.
 /// </summary>
 /// <param name="moduleReference"></param>
 /// <returns></returns>
 public override IModuleReference Rewrite(IModuleReference moduleReference)
 {
     if (moduleReference.UnitIdentity.Equals(this.sourceUnitIdentity))
     {
         return((IModuleReference)this.targetUnit);
     }
     return(base.Rewrite(moduleReference));
 }
Пример #9
0
 public TypeReference(IModuleReference <ModuleDef> module, UTF8String @namespace, UTF8String name, IReference <IResolutionScope> scope) : this((ITypeReference <ITypeDefOrRef>)null, @namespace, name)
 {
     if (@namespace is null)
     {
         throw new ArgumentNullException(nameof(@namespace), nameof(@namespace) + " cannot be null, use an empty string for the default namespace instead");
     }
     Module    = module;
     Scope     = scope;
     Namespace = @namespace;
 }
Пример #10
0
        private int WriteAssemblyInfo(IAssembly assembly, ILanguageWriterConfiguration configuration)
        {
            ILanguage   language   = LanguageManager.ActiveLanguage;
            ITranslator translator = TranslatorManager.CreateDisassembler("Xml", null);

            int exceptions = 0;

            using (StreamWriter streamWriter = CreateFile(string.Empty, "AssemblyInfo"))
            {
                TextFormatter formatter = new TextFormatter();
                try
                {
                    ILanguageWriter writer = language.GetWriter(formatter, configuration);
                    assembly = translator.TranslateAssembly(assembly, false);
                    writer.WriteAssembly(assembly);

                    foreach (IModule module in assembly.Modules)
                    {
                        IModule visitedModule = translator.TranslateModule(module, false);
                        writer.WriteModule(visitedModule);

                        foreach (IAssemblyReference assemblyReference in module.AssemblyReferences)
                        {
                            IAssemblyReference visitedAssemblyReference = translator.TranslateAssemblyReference(assemblyReference);
                            writer.WriteAssemblyReference(visitedAssemblyReference);
                        }

                        foreach (IModuleReference moduleReference in module.ModuleReferences)
                        {
                            IModuleReference visitedModuleReference = translator.TranslateModuleReference(moduleReference);
                            writer.WriteModuleReference(visitedModuleReference);
                        }
                    }

                    foreach (IResource resource in assembly.Resources)
                    {
                        writer.WriteResource(resource);
                    }
                }
                catch (Exception exception)
                {
                    streamWriter.WriteLine(exception.ToString());
                    WriteLine(exception.ToString());
                    exceptions++;
                }

                string output = formatter.ToString().Replace("\r\n", "\n").Replace("\n", "\r\n");
                streamWriter.WriteLine(output);
            }
            return(exceptions);
        }
        private static List <IMethodDefinition> CreateWindowsHelpers(
            IMetadataHost host,
            ITypeDefinition typeDef,
            string prefix,
            string loadLibraryMethodName,
            string freeLibraryMethodName,
            string getProcAddressMethodName,
            IModuleReference moduleRef,
            PInvokeCallingConvention callingConvention)
        {
            var loadLibrary    = CreateLoadLibraryMethod(host, typeDef, moduleRef, prefix, loadLibraryMethodName, callingConvention);
            var freeLibrary    = CreateFreeLibraryMethod(host, typeDef, moduleRef, prefix, freeLibraryMethodName, callingConvention);
            var getProcAddress = CreateGetProcAddressMethod(host, typeDef, moduleRef, prefix, getProcAddressMethodName, callingConvention);

            return(new List <IMethodDefinition> {
                loadLibrary, freeLibrary, getProcAddress
            });
        }
Пример #12
0
        /// <summary>
        /// Returns a "live" System.Reflection.Module instance that provides reflective access to the referenced module.
        /// If the module cannot be found or cannot be loaded, the result is null.
        /// </summary>
        public Module /*?*/ GetModule(IModuleReference /*?*/ moduleReference)
        {
            if (moduleReference == null)
            {
                return(null);
            }
            if (moduleReference.ContainingAssembly == null)
            {
                return(null);
            }
            var assembly = this.GetAssembly(moduleReference.ContainingAssembly);

            if (assembly == null)
            {
                return(null);
            }
            return(assembly.GetModule(moduleReference.Name.Value));
        }
Пример #13
0
        /// <summary>
        /// Use this routine, rather than IUnitReference.Dispatch, to call the appropriate derived overload of an IUnitReference.
        /// The former routine will call Visit(IAssembly) rather than Visit(IAssemblyReference), etc.
        /// in the case where a definition is used as the reference to itself.
        /// </summary>
        /// <param name="unitReference">A reference to a unit. Note that a unit can serve as a reference to itself.</param>
        private void DispatchAsReference(IUnitReference unitReference)
        {
            IAssemblyReference assemblyReference = unitReference as IAssemblyReference;

            if (assemblyReference != null)
            {
                this.Visit(assemblyReference);
                return;
            }

            IModuleReference moduleReference = unitReference as IModuleReference;

            if (moduleReference != null)
            {
                this.Visit(moduleReference);
                return;
            }
        }
Пример #14
0
        protected void Init(IModuleReference mainAssembly, IEnumerable <IModuleReference> assemblyReferences)
        {
            if (mainAssembly == null)
            {
                throw new ArgumentNullException(nameof(mainAssembly));
            }
            if (assemblyReferences == null)
            {
                throw new ArgumentNullException(nameof(assemblyReferences));
            }
            var context = new SimpleTypeResolveContext(this);

            this.mainModule = mainAssembly.Resolve(context);
            List <IModule> assemblies = new List <IModule>();

            assemblies.Add(this.mainModule);
            List <IModule> referencedAssemblies = new List <IModule>();

            foreach (var asmRef in assemblyReferences)
            {
                IModule asm;
                try
                {
                    asm = asmRef.Resolve(context);
                }
                catch (InvalidOperationException)
                {
                    throw new InvalidOperationException("Tried to initialize compilation with an invalid assembly reference. (Forgot to load the assembly reference ? - see CecilLoader)");
                }
                if (asm != null && !assemblies.Contains(asm))
                {
                    assemblies.Add(asm);
                }
                if (asm != null && !referencedAssemblies.Contains(asm))
                {
                    referencedAssemblies.Add(asm);
                }
            }
            this.assemblies           = assemblies.AsReadOnly();
            this.referencedAssemblies = referencedAssemblies.AsReadOnly();
            this.knownTypeCache       = new KnownTypeCache(this);
            this.initialized          = true;
        }
Пример #15
0
        public static IAssemblyReference GetAssemblyReference(this ITypeReference type)
        {
            IUnitReference unit = TypeHelper.GetDefiningUnitReference(type);

            IAssemblyReference assembly = unit as IAssemblyReference;

            if (assembly != null)
            {
                return(assembly);
            }

            IModuleReference module = unit as IModuleReference;

            if (module != null)
            {
                return(module.ContainingAssembly);
            }

            return(null);
        }
        private static List <IMethodDefinition> CreateUnixSpecificHelpers(
            IMetadataHost host,
            ITypeDefinition typeDef,
            string prefix,
            string loadLibraryMethodName,
            string freeLibraryMethodName,
            string getProcAddressMethodName,
            IModuleReference moduleRef,
            PInvokeCallingConvention callingConvention)
        {
            var loadLibrary = CreateLoadLibraryMethod(host, typeDef, moduleRef, prefix, loadLibraryMethodName, callingConvention);

            loadLibrary.Parameters.Add(new ParameterDefinition {
                Index = 1, Type = host.PlatformType.SystemInt32
            });
            var freeLibrary    = CreateFreeLibraryMethod(host, typeDef, moduleRef, prefix, freeLibraryMethodName, callingConvention);
            var getProcAddress = CreateGetProcAddressMethod(host, typeDef, moduleRef, prefix, getProcAddressMethodName, callingConvention);

            return(new List <IMethodDefinition> {
                loadLibrary, freeLibrary, getProcAddress
            });
        }
Пример #17
0
        /// <summary>
        /// Returns true if the given two unit references are to be considered equivalent as containers.
        /// </summary>
        public static bool UnitsAreContainmentEquivalent(IUnitReference unit1, IUnitReference unit2)
        {
            if (unit1 == null || unit2 == null)
            {
                return(false);
            }
            if (unit1 == unit2)
            {
                return(true);
            }
            IModuleReference /*?*/ moduleRef1 = unit1 as IModuleReference;
            IModuleReference /*?*/ moduleRef2 = unit2 as IModuleReference;

            if (moduleRef1 != null && moduleRef2 != null)
            {
                if (UnitHelper.AssembliesAreEquivalent(moduleRef1.ContainingAssembly, moduleRef2.ContainingAssembly))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #18
0
 /// <summary>
 /// Returns true if the given two module references are to be considered equivalent.
 /// </summary>
 public static bool ModulesAreEquivalent(IModuleReference /*?*/ module1, IModuleReference /*?*/ module2)
 {
     if (module1 == null || module2 == null)
     {
         return(false);
     }
     if (module1 == module2)
     {
         return(true);
     }
     if (module1.ContainingAssembly != null)
     {
         if (module2.ContainingAssembly == null)
         {
             return(false);
         }
         if (!UnitHelper.AssembliesAreEquivalent(module1.ContainingAssembly, module2.ContainingAssembly))
         {
             return(false);
         }
     }
     return(module1.Name.UniqueKeyIgnoringCase == module2.Name.UniqueKeyIgnoringCase);
 }
Пример #19
0
        public static IAssemblyReference GetAssemblyReference(IType value)
        {
            ITypeReference reference = value as ITypeReference;

            if (reference != null)
            {
                ITypeReference owner = reference.Owner as ITypeReference;
                if (owner != null)
                {
                    return(GetAssemblyReference(owner));
                }
                IModuleReference reference4 = reference.Owner as IModuleReference;
                if (reference4 != null)
                {
                    return(reference4.Resolve().Assembly);
                }
                IAssemblyReference reference3 = reference.Owner as IAssemblyReference;
                if (reference3 != null)
                {
                    return(reference3);
                }
            }
            throw new NotSupportedException();
        }
Пример #20
0
        public override void Visit(INamespaceTypeReference namespaceTypeReference)
        {
            if (!this.typeReferenceNeedsToken && namespaceTypeReference.TypeCode != PrimitiveTypeCode.NotPrimitive)
            {
                return;
            }

            RecordTypeReference(namespaceTypeReference);

            IUnitReference unit = namespaceTypeReference.GetUnit(Context);

            IAssemblyReference assemblyReference = unit as IAssemblyReference;

            if (assemblyReference != null)
            {
                this.Visit(assemblyReference);
            }
            else
            {
                IModuleReference moduleReference = unit as IModuleReference;
                if (moduleReference != null)
                {
                    // If this is a module from a referenced multi-module assembly,
                    // the assembly should be used as the resolution scope.
                    assemblyReference = moduleReference.GetContainingAssembly(Context);
                    if (assemblyReference != null && assemblyReference != Context.Module.GetContainingAssembly(Context))
                    {
                        this.Visit(assemblyReference);
                    }
                    else
                    {
                        this.Visit(moduleReference);
                    }
                }
            }
        }
        private IAssemblyReference GetAssemblyReference(ITypeReference value)
        {
            if (value.Owner is ITypeReference)
            {
                return(this.GetAssemblyReference(value.Owner as ITypeReference));
            }
            else if (value.Owner is IAssemblyReference)
            {
                return(value.Owner as IAssemblyReference);
            }
            else if (value.Owner is IModuleReference)
            {
                IModuleReference moduleReference = (IModuleReference)value.Owner;
                IModule          module          = moduleReference.Resolve();
                if (module != null)
                {
                    return(module.Assembly);
                }

                return(null);
            }

            throw new NotSupportedException("Unable to get assembly reference for type of code identifier.");
        }
 void ModuleAsReference(IModuleReference module) {
   IAssemblyReference assembly = module as IAssemblyReference;
   if (assembly != null) {
     this.ILDasmPaper.Symbol("[");
     this.ILDasmPaper.Identifier(assembly.Name.Value);
     this.ILDasmPaper.Symbol("]");
     return;
   }
   this.ILDasmPaper.Symbol("[");
   this.ILDasmPaper.Directive(".module");
   this.ILDasmPaper.Identifier(module.Name.Value);
   this.ILDasmPaper.Symbol("]");
   return;
 }
Пример #23
0
 protected override void RecordModuleReference(IModuleReference moduleReference)
 {
     this.metadataWriter.GetModuleRefIndex(moduleReference.Name);
 }
        public string Decompile(int languageIndex, object o)
        {
            if (o == null)
            {
                return(String.Empty);
            }

            IFormatter      formatter  = CreateFormatter(this.LanguageManager.Languages[languageIndex].Name);
            ILanguageWriter writer     = this.LanguageManager.Languages[languageIndex].GetWriter(formatter, _langurageWriterConfiguration);
            ITranslator     translator = this.TranslatorManager.CreateDisassembler(null, null);

            if (o is IMethodDeclaration)
            {
                IMethodDeclaration m2;
                if (IsIL(languageIndex))
                {
                    m2 = (IMethodDeclaration)o;
                }
                else
                {
                    m2 = translator.TranslateMethodDeclaration((IMethodDeclaration)o);
                }
                writer.WriteMethodDeclaration(m2);
            }
            else if (o is IPropertyDeclaration)
            {
                IPropertyDeclaration p2 = translator.TranslatePropertyDeclaration((IPropertyDeclaration)o);
                writer.WritePropertyDeclaration(p2);
            }
            else if (o is IFieldDeclaration)
            {
                IFieldDeclaration f2 = translator.TranslateFieldDeclaration((IFieldDeclaration)o);
                writer.WriteFieldDeclaration(f2);
            }
            else if (o is ITypeDeclaration)
            {
                ITypeDeclaration t2 = translator.TranslateTypeDeclaration((ITypeDeclaration)o, true, false);
                writer.WriteTypeDeclaration(t2);
            }
            else if (o is IEventDeclaration)
            {
                IEventDeclaration e2 = translator.TranslateEventDeclaration((IEventDeclaration)o);
                writer.WriteEventDeclaration(e2);
            }
            else if (o is IModule)
            {
                IModule m2 = translator.TranslateModule((IModule)o, true);
                writer.WriteModule(m2);
            }
            else if (o is IModuleReference)
            {
                IModuleReference mr2 = translator.TranslateModuleReference((IModuleReference)o);
                writer.WriteModuleReference(mr2);
            }
            else if (o is IAssembly)
            {
                IAssembly a2 = translator.TranslateAssembly((IAssembly)o, true);
                writer.WriteAssembly(a2);
            }
            else if (o is IAssemblyReference)
            {
                IAssemblyReference ar2 = translator.TranslateAssemblyReference((IAssemblyReference)o);
                writer.WriteAssemblyReference(ar2);
            }
            else if (o is IResource)
            {
                writer.WriteResource((IResource)o);
            }
            else if (o is INamespace)
            {
                writer.WriteNamespace((INamespace)o);
            }

            return(formatter.ToString());
        }
Пример #25
0
 public void Visit(IModuleReference moduleReference)
 {
     this.traverser.Traverse(moduleReference);
 }
Пример #26
0
 /// <summary>
 /// Traverses the module reference.
 /// </summary>
 public void Traverse(IModuleReference moduleReference)
 {
     Contract.Requires(moduleReference != null);
       var assemblyReference = moduleReference as IAssemblyReference;
       if (assemblyReference != null) {
     this.Traverse(assemblyReference);
     return;
       }
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(moduleReference)) return;
       if (this.preorderVisitor != null) moduleReference.DispatchAsReference(this.preorderVisitor);
       if (this.stopTraversal) return;
       this.TraverseChildren(moduleReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) moduleReference.DispatchAsReference(this.postorderVisitor);
 }
Пример #27
0
 protected abstract void RecordModuleReference(IModuleReference moduleReference);
Пример #28
0
 protected override void RecordModuleReference(IModuleReference moduleReference)
 {
 }
Пример #29
0
 /// <summary>
 /// Performs some computation with the given module reference.
 /// </summary>
 /// <param name="moduleReference"></param>
 public virtual void Visit(IModuleReference moduleReference)
   //^ ensures this.path.Count == old(this.path.Count);
 {
 }
Пример #30
0
 public override IModuleReference Rewrite(IModuleReference moduleReference)
 {
     if (moduleReference.UnitIdentity.Equals(this.sourceUnitIdentity)) {
       return (IModuleReference)this.targetUnit;
     }
     return base.Rewrite(moduleReference);
 }
        private static List <IMethodDefinition> CreateUnixHelpers(IMetadataHost host, ITypeDefinition typeDef, ITypeReference marshalClass, List <IMethodDefinition> linuxMethodList, List <IMethodDefinition> darwinMethodList, List <IMethodDefinition> bsdMethodList, IModuleReference libc)
        {
            var intPtrZero = new FieldReference
            {
                Name           = host.NameTable.GetNameFor("Zero"),
                ContainingType = host.PlatformType.SystemIntPtr,
                Type           = host.PlatformType.SystemIntPtr
            };

            var allocalHGlobal = new Microsoft.Cci.MutableCodeModel.MethodReference
            {
                Name           = host.NameTable.GetNameFor("AllocHGlobal"),
                ContainingType = marshalClass,
                Type           = host.PlatformType.SystemIntPtr,
                Parameters     = new List <IParameterTypeInformation> {
                    new ParameterDefinition {
                        Index = 0, Type = host.PlatformType.SystemInt32
                    }
                }
            };

            var ptrToStringAnsi = new Microsoft.Cci.MutableCodeModel.MethodReference
            {
                Name           = host.NameTable.GetNameFor("PtrToStringAnsi"),
                ContainingType = marshalClass,
                Type           = host.PlatformType.SystemString,
                Parameters     = new List <IParameterTypeInformation> {
                    new ParameterDefinition {
                        Index = 0, Type = host.PlatformType.SystemIntPtr
                    }
                }
            };

            var freeHGlobal = new Microsoft.Cci.MutableCodeModel.MethodReference
            {
                Name           = host.NameTable.GetNameFor("FreeHGlobal"),
                ContainingType = marshalClass,
                Type           = host.PlatformType.SystemVoid,
                Parameters     = new List <IParameterTypeInformation> {
                    new ParameterDefinition {
                        Index = 0, Type = host.PlatformType.SystemIntPtr
                    }
                }
            };

            var intPtrOpInEquality = new Microsoft.Cci.MutableCodeModel.MethodReference
            {
                Name           = host.NameTable.OpInequality,
                ContainingType = host.PlatformType.SystemIntPtr,
                Type           = host.PlatformType.SystemBoolean,
                Parameters     = new List <IParameterTypeInformation> {
                    new ParameterDefinition {
                        Index = 0, Type = host.PlatformType.SystemIntPtr
                    }, new ParameterDefinition {
                        Index = 1, Type = host.PlatformType.SystemIntPtr
                    }
                }
            };

            var stringOpEquality = new Microsoft.Cci.MutableCodeModel.MethodReference
            {
                Name           = host.NameTable.OpEquality,
                ContainingType = host.PlatformType.SystemString,
                Type           = host.PlatformType.SystemBoolean,
                Parameters     = new List <IParameterTypeInformation> {
                    new ParameterDefinition {
                        Index = 0, Type = host.PlatformType.SystemString
                    }, new ParameterDefinition {
                        Index = 1, Type = host.PlatformType.SystemString
                    }
                }
            };

            var unamePInvokeMethod = CreateUnamePInvokeMethod(host, typeDef, libc);
            var unameMethod        = CreateUnameMethod(host, typeDef, intPtrZero, allocalHGlobal, ptrToStringAnsi, freeHGlobal, unamePInvokeMethod, intPtrOpInEquality);
            var getosmethod        = CreateGetOperatingSystemMethod(host, typeDef, stringOpEquality, unameMethod);

            var dlopen  = CreateDLOpen(host, typeDef, getosmethod, linuxMethodList[0], darwinMethodList[0], bsdMethodList[0]);
            var dlclose = CreateDLClose(host, typeDef, getosmethod, linuxMethodList[1], darwinMethodList[1], bsdMethodList[1]);
            var dlsym   = CreateDLSym(host, typeDef, getosmethod, linuxMethodList[2], darwinMethodList[2], bsdMethodList[2]);

            return(new List <IMethodDefinition> {
                dlopen, dlclose, dlsym, unameMethod, unamePInvokeMethod, getosmethod
            });
        }
 private static IMethodDefinition CreateUnamePInvokeMethod(IMetadataHost host, ITypeDefinition typeDef, IModuleReference libc)
 {
     return(CreatePInvokeMethod(host, typeDef, new List <IParameterDefinition> {
         new ParameterDefinition {
             Index = 0, Type = host.PlatformType.SystemIntPtr
         }
     }, host.PlatformType.SystemInt32, libc, string.Empty, "uname", PInvokeCallingConvention.CDecl));
 }
 private static MethodDefinition CreatePInvokeMethod(IMetadataHost host, ITypeDefinition typeDef, List <IParameterDefinition> parameters, ITypeReference returnType, IModuleReference moduleRef, string prefix, string methodName, PInvokeCallingConvention callingConvention)
 {
     return(new MethodDefinition
     {
         ContainingTypeDefinition = typeDef,
         Type = returnType,
         Parameters = parameters,
         Name = host.NameTable.GetNameFor(prefix + methodName),
         Visibility = TypeMemberVisibility.Public,
         IsStatic = true,
         IsPlatformInvoke = true,
         PreserveSignature = true,
         IsHiddenBySignature = true,
         IsExternal = true,
         PlatformInvokeData = new PlatformInvokeInformation
         {
             PInvokeCallingConvention = callingConvention,
             ImportModule = moduleRef,
             ImportName = host.NameTable.GetNameFor(methodName)
         }
     });
 }
Пример #34
0
 public void Visit(IModuleReference moduleReference)
 {
     throw new NotImplementedException();
 }
Пример #35
0
        public override void TraverseChildren(IModuleReference moduleReference)
{ MethodEnter(moduleReference);
            base.TraverseChildren(moduleReference);
     MethodExit();   }
Пример #36
0
 protected override void RecordModuleReference(IModuleReference moduleReference)
 {
     this.metadataWriter.GetModuleRefIndex(moduleReference.Name);
 }
        public virtual IModuleReferenceCollection TransformModuleReferenceCollection(IModuleReferenceCollection value)
        {
            IModuleReference[] array = new IModuleReference[value.Count];
            for (int i = 0; i < value.Count; i++)
            {
                array[i] = this.TransformModuleReference(value[i]);
            }

            IModuleReferenceCollection target = new ModuleReferenceCollection();
            target.AddRange(array);
            return target;
        }
Пример #38
0
 public override void Visit(IModuleReference moduleReference)
 {
     if (moduleReference != this.module)
     {
         RecordModuleReference(moduleReference);
     }
 }
 /// <summary>
 /// Rewrites the given module reference.
 /// </summary>
 public virtual IModuleReference Rewrite(IModuleReference moduleReference)
 {
     return moduleReference;
 }
Пример #40
0
 protected override void RecordModuleReference(IModuleReference moduleReference)
 {
 }
Пример #41
0
        internal PlatformInvokeInformation(ITypeDeclarationMember declaringMember, SourceCustomAttribute dllImportAttribute)
        {
            this.importModule = Dummy.ModuleReference;
              this.importName = declaringMember.Name.Name;
              this.noMangle = false;
              this.pinvokeCallingConvention = PInvokeCallingConvention.WinApi;
              this.stringFormat = StringFormatKind.Unspecified;
              this.useBestFit = null;
              this.throwExceptionForUnmappableChar = null;

              INameTable nameTable = dllImportAttribute.ContainingBlock.NameTable;
              int bestFitMappingKey = nameTable.GetNameFor("BestFitMapping").UniqueKey;
              int callingConventionKey = nameTable.GetNameFor("CallingConvention").UniqueKey;
              int charSetKey = nameTable.GetNameFor("CharSet").UniqueKey;
              int entryPointKey = nameTable.GetNameFor("EntryPoint").UniqueKey;
              int exactSpellingKey = nameTable.GetNameFor("ExactSpelling").UniqueKey;
              int setLastErrorKey = nameTable.GetNameFor("SetLastError").UniqueKey;
              int throwOnUnmappableCharKey = nameTable.GetNameFor("ThrowOnUnmappableChar").UniqueKey;

              foreach (Expression expr in dllImportAttribute.Arguments) {
            CompileTimeConstant cc = expr as CompileTimeConstant;
            if (cc != null && cc.Value is string) {
              IName moduleName = expr.NameTable.GetNameFor((string)cc.Value);
              this.importModule = new Immutable.ModuleReference(dllImportAttribute.ContainingBlock.Compilation.HostEnvironment, new ModuleIdentity(moduleName, string.Empty));
              continue;
            }
            NamedArgument narg = expr as NamedArgument;
            if (narg == null) continue;
            int key = narg.ArgumentName.Name.UniqueKey;
            if (key == bestFitMappingKey) {
              if (narg.ArgumentValue.Value is bool)
            this.useBestFit = (bool)narg.ArgumentValue.Value;
              continue;
            }
            if (key == callingConventionKey) {
              if (narg.ArgumentValue.Value is int) {
            switch ((CallingConvention)(int)narg.ArgumentValue.Value) {
              case CallingConvention.C: this.pinvokeCallingConvention = PInvokeCallingConvention.CDecl; break;
              case CallingConvention.Standard: this.pinvokeCallingConvention = PInvokeCallingConvention.StdCall; break;
              case CallingConvention.ExplicitThis: this.pinvokeCallingConvention = PInvokeCallingConvention.ThisCall; break;
              case CallingConvention.FastCall: this.pinvokeCallingConvention = PInvokeCallingConvention.FastCall; break;
            }
              }
              continue;
            }
            if (key == charSetKey) {
              if (narg.ArgumentValue.Value is int) {
            switch ((CharSet)(int)narg.ArgumentValue.Value) {
              case CharSet.Ansi: this.stringFormat = StringFormatKind.Ansi; break;
              case CharSet.Auto: this.stringFormat = StringFormatKind.AutoChar; break;
              case CharSet.Unicode: this.stringFormat = StringFormatKind.Unicode; break;
            }
              }
              continue;
            }
            if (key == entryPointKey) {
              string/*?*/ importName = narg.ArgumentValue.Value as string;
              if (importName != null) {
            this.importName = nameTable.GetNameFor(importName);
              }
              continue;
            }
            if (key == exactSpellingKey) {
              if (narg.ArgumentValue.Value is bool)
            this.noMangle = (bool)narg.ArgumentValue.Value;
              continue;
            }
            if (key == setLastErrorKey) {
              if (narg.ArgumentValue.Value is bool)
            this.supportsLastError = (bool)narg.ArgumentValue.Value;
              continue;
            }
            if (key == throwOnUnmappableCharKey) {
              if (narg.ArgumentValue.Value is bool)
            this.throwExceptionForUnmappableChar = (bool)narg.ArgumentValue.Value;
              continue;
            }
              }
        }
Пример #42
0
 /// <summary>
 /// Traverses the children of the module reference.
 /// </summary>
 public virtual void TraverseChildren(IModuleReference moduleReference)
 {
     Contract.Requires(moduleReference != null);
       this.TraverseChildren((IUnitReference)moduleReference);
 }
Пример #43
0
 public virtual void Visit(IModuleReference moduleReference)
 {
 }
Пример #44
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given module reference.
 /// </summary>
 /// <param name="moduleReference"></param>
 public virtual void Visit(IModuleReference moduleReference)
 {
 }
 public override void TraverseChildren(IModuleReference moduleReference) {
   base.TraverseChildren(moduleReference);
 }
Пример #46
0
 public virtual void VisitModuleReference(IModuleReference value)
 {
 }
Пример #47
0
 public virtual void onMetadataElement(IModuleReference moduleReference) { }
Пример #48
0
 /// <summary>
 /// Performs some computation with the given module reference.
 /// </summary>
 public void Visit(IModuleReference moduleReference)
 {
     this.Visit((IUnitReference)moduleReference);
 }
 public void ModuleReference(IModuleReference moduleReference) {
   this.ILDasmPaper.Directive(".module extern");
   this.ILDasmPaper.DataString(moduleReference.Name.Value);
   this.ILDasmPaper.NewLine();
 }
Пример #50
0
 /// <summary>
 /// Traverses the children of the module reference.
 /// </summary>
 public virtual void TraverseChildren(IModuleReference moduleReference)
 {
     this.TraverseChildren((IUnitReference)moduleReference);
 }
 public override void Visit(IModuleReference moduleReference)
 {
     if(Process(moduleReference)){visitor.Visit(moduleReference);}
     base.Visit(moduleReference);
 }
Пример #52
0
        private IMethodDefinition CreateLoadLibraryMethod(ITypeDefinition typeDefinition, IModuleReference moduleRef, IFieldReference fieldRef)
        {
            var methodDefinition = new MethodDefinition
            {
                IsStatic = true,
                Type     = this.platformType.SystemVoid,
                ContainingTypeDefinition = typeDefinition,
                Name           = this.nameTable.GetNameFor("LoadLibrary" + moduleRef.Name.Value),
                IsNeverInlined = true,
                Visibility     = TypeMemberVisibility.Public,
                Parameters     = new List <IParameterDefinition> {
                    new ParameterDefinition {
                        Index = 0, Type = this.platformType.SystemString, Name = this.host.NameTable.GetNameFor("nativeLibraryFilePath")
                    }
                }
            };

            var ilGenerator = new ILGenerator(this.host, methodDefinition);

            ilGenerator.Emit(OperationCode.Ldarg_0);
            ilGenerator.Emit(OperationCode.Call, this.loadLibrary);
            ilGenerator.Emit(OperationCode.Stsfld, fieldRef);
            ilGenerator.Emit(OperationCode.Ret);

            var ilMethodBody = new ILGeneratorMethodBody(ilGenerator, false, 2, methodDefinition, Enumerable.Empty <ILocalDefinition>(), Enumerable.Empty <ITypeDefinition>());

            methodDefinition.Body = ilMethodBody;

            return(methodDefinition);
        }
 public void WriteModuleReference(IModuleReference value)
 {
     this.formatter.Write("// Module Reference");
     this.formatter.Write(" ");
     this.formatter.WriteDeclaration(value.Name);
     this.formatter.WriteLine();
 }
Пример #54
0
 protected abstract void RecordModuleReference(IModuleReference moduleReference);
Пример #55
0
 public override void Visit(IModuleReference moduleReference)
 {
     if (moduleReference != Context.Module)
     {
         RecordModuleReference(moduleReference);
     }
 }
Пример #56
0
 public override void TraverseChildren(IModuleReference moduleReference)
 {
     MethodEnter(moduleReference);
     base.TraverseChildren(moduleReference);
     MethodExit();
 }
 public virtual IModuleReference TransformModuleReference(IModuleReference value)
 {
     return value;
 }