Beispiel #1
0
        /// <summary>
        /// Returns true if the given object is an identifier that identifies the same object as this identifier.
        /// </summary>
        //^ [Confined]
        public override bool Equals(object /*?*/ obj)
        {
            if (obj == (object)this)
            {
                return(true);
            }
            ModuleIdentity /*?*/ otherMod = obj as ModuleIdentity;

            if (otherMod == null)
            {
                return(false);
            }
            if (this.containingAssembly == null)
            {
                if (otherMod.ContainingAssembly != null)
                {
                    return(false);
                }
            }
            else
            {
                if (otherMod.ContainingAssembly == null)
                {
                    return(false);
                }
                if (!this.containingAssembly.Equals(otherMod.containingAssembly))
                {
                    return(false);
                }
            }
            if (this.Name.UniqueKeyIgnoringCase != otherMod.Name.UniqueKeyIgnoringCase)
            {
                return(false);
            }
            if (this.containingAssembly != null)
            {
                return(true);
            }
            return(string.Compare(this.Location, otherMod.Location, StringComparison.OrdinalIgnoreCase) == 0);
        }
 /// <summary>
 /// Returns the module corresponding to passed moduleIdentifier if it was loaded.
 /// </summary>
 /// <param name="moduleIdentity"></param>
 /// <returns></returns>
 public IModule /*?*/ FindModule(ModuleIdentity moduleIdentity)
 {
     return(this.LookupModule(null, moduleIdentity));
 }
Beispiel #3
0
 /// <summary>
 /// The module that matches the given reference, or a dummy module if no matching module can be found.
 /// </summary>
 public virtual IModule LoadModule(ModuleIdentity moduleIdentity) {
   if (moduleIdentity.Location == null) return Dummy.Module;
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(moduleIdentity, out unit);
   }
   if (unit == null) {
     if (moduleIdentity.Location == "" || moduleIdentity.Location == "unknown://location") {
       unit = Dummy.Module;
       this.unitCache.Add(moduleIdentity, unit);
     } else
       unit = this.LoadUnitFrom(moduleIdentity.Location);
   }
   IModule/*?*/ result = unit as IModule;
   if (result == null) result = Dummy.Module;
   return result;
 }
Beispiel #4
0
 public IModule LoadModule(ModuleIdentity moduleIdentity)
 {
     Contract.Requires(moduleIdentity != null);
     Contract.Ensures(Contract.Result <IModule>() != null);
     throw new NotImplementedException();
 }
Beispiel #5
0
 /// <summary>
 /// This method is called when the module reference is being resolved and its not already loaded by the host.
 /// </summary>
 /// <param name="referringUnit">The unit that is referencing the module.</param>
 /// <param name="referencedModule">Module identifier for the assembly being referenced.</param>
 public void ResolvingModuleReference(IUnit referringUnit, ModuleIdentity referencedModule) {
   Contract.Requires(referringUnit != null);
   Contract.Requires(referencedModule != null);
   throw new NotImplementedException();
 }
Beispiel #6
0
 /// <summary>
 /// The module that matches the given reference, or a dummy module if no matching module can be found.
 /// </summary>
 public virtual IModule LoadModule(ModuleIdentity moduleIdentity) {
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(moduleIdentity, out unit);
   }
   IModule/*?*/ result;
   if (unit != null)
     result = unit as IModule;
   else {
     if (moduleIdentity.Location == "" || moduleIdentity.Location == "unknown://location") {
       result = Dummy.Module;
       lock (GlobalLock.LockingObject) {
         this.unitCache.Add(moduleIdentity, result);
       }
     } else {
       unit = this.LoadUnitFrom(moduleIdentity.Location);
       result = unit as IModule;
       if (result != null)
         lock (GlobalLock.LockingObject) {
           this.unitCache.Add(moduleIdentity, result);
           this.coreIdentities.Add(result.CoreAssemblySymbolicIdentity);
         }
     }
   }
   if (result == null) result = Dummy.Module;
   return result;
 }
Beispiel #7
0
 uint IInternFactory.GetModuleInternedKey(ModuleIdentity moduleIdentity) {
   lock (GlobalLock.LockingObject) {
     ModuleStore moduleStore = this.GetModuleStore(moduleIdentity);
     return moduleStore.InternedId;
   }
 }
Beispiel #8
0
 internal ModuleStore(
   ModuleIdentity moduleIdentitity,
   uint internedId,
   uint rootNamespaceInternedId
 ) {
   this.ModuleIdentitity = moduleIdentitity;
   this.InternedId = internedId;
   this.RootNamespaceInternedId = rootNamespaceInternedId;
 }
 public IModule LoadModule(ModuleIdentity moduleIdentity) {
   return Dummy.Module;
 }
Beispiel #10
0
 public uint GetModuleInternedKey(ModuleIdentity moduleIdentity)
 {
     return m_factory.GetModuleInternedKey(moduleIdentity);
 }
 ModuleIdentity IMetadataHost.ProbeModuleReference(IUnit referringUnit, ModuleIdentity referencedModule)
 {
     throw new NotImplementedException();
 }
 IModule IMetadataHost.LoadModule(ModuleIdentity moduleIdentity)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
 /// <summary>
 /// Allocates a reference to a .NET module.
 /// </summary>
 /// <param name="host">Provides a standard abstraction over the applications that host components that provide or consume objects from the metadata model.</param>
 /// <param name="moduleIdentity"></param>
 public ModuleReference(IMetadataHost host, ModuleIdentity moduleIdentity)
 {
     this.host = host;
       this.moduleIdentity = moduleIdentity;
 }
Beispiel #14
0
 public uint GetModuleInternedKey(ModuleIdentity moduleIdentity)
 {
     return(m_factory.GetModuleInternedKey(moduleIdentity));
 }
Beispiel #15
0
 public ModuleIdentity ProbeModuleReference(IUnit referringUnit, ModuleIdentity referencedModule) {
   throw new NotImplementedException();
 }
 public ModuleIdentity ProbeModuleReference(IUnit unit, ModuleIdentity referedModuleIdentity) {
   return referedModuleIdentity;
 }
Beispiel #17
0
 /// <summary>
 /// This method is called when the module reference is being resolved and its not already loaded by the Read/Write host.
 /// </summary>
 /// <param name="referringUnit">The unit that is referencing the module.</param>
 /// <param name="referencedModule">Module identity for the assembly being referenced.</param>
 public virtual void ResolvingModuleReference(IUnit referringUnit, ModuleIdentity referencedModule) {
 }
 public uint GetModuleInternedKey(ModuleIdentity moduleIdentity) {
   return 0;
 }
Beispiel #19
0
    ModuleStore GetModuleStore(ModuleIdentity moduleIdentity) {
      Contract.Requires(moduleIdentity != null);
      Contract.Ensures(Contract.Result<ModuleStore>() != null);

      IName moduleName = moduleIdentity.Name;
      foreach (ModuleStore mStore in this.ModuleHashtable.GetValuesFor((uint)moduleName.UniqueKey)) {
        if (moduleIdentity.Equals(mStore.ModuleIdentitity)) return mStore;
      }
      uint value;
      if (moduleIdentity.ContainingAssembly != null) {
        AssemblyStore assemblyStore = this.GetAssemblyStore(moduleIdentity.ContainingAssembly);
        assemblyStore.InternedIdWithCount++;
        value = assemblyStore.InternedIdWithCount;
      } else {
        value = this.CurrentModuleInternValue++;
      }
      ModuleStore mStore1 = new ModuleStore(moduleIdentity, value, this.CurrentNamespaceInternValue++);
      this.ModuleHashtable.Add((uint)moduleName.UniqueKey, mStore1);
      return mStore1;
    }
 /// <summary>
 /// Method to open the module in the MetadataReader. This method loads the module and returns the object corresponding to the opened module.
 /// Also returns the ModuleIDentifier corresponding to the module as the out parameter. Modules are opened as if they are not contained in any assembly.
 /// </summary>
 /// <param name="binaryDocument">The binary document that needes to be opened as an module.</param>
 /// <param name="moduleIdentity">Contains the module identity of the binary document in case it is an module.</param>
 /// <returns>Module that is loaded or Dummy.Module in case module could not be loaded.</returns>
 public IModule OpenModule(
   IBinaryDocument binaryDocument,
   out ModuleIdentity/*?*/ moduleIdentity
 ) {
   moduleIdentity = null;
   lock (GlobalLock.LockingObject) {
     IBinaryDocumentMemoryBlock/*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
     if (binaryDocumentMemoryBlock == null) {
       //  Error...
       return Dummy.Module;
     }
     PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
     if (peFileReader.ReaderState < ReaderState.Metadata) {
       //  Error...
       return Dummy.Module;
     }
     //^ assert peFileReader.ReaderState >= ReaderState.Metadata;
     if (peFileReader.IsAssembly) {
       AssemblyIdentity assemblyIdentity = this.GetAssemblyIdentifier(peFileReader);
       moduleIdentity = assemblyIdentity;
       Assembly/*?*/ lookupAssembly = this.LookupAssembly(null, assemblyIdentity);
       if (lookupAssembly != null) {
         return lookupAssembly;
       }
     } else {
       moduleIdentity = this.GetModuleIdentifier(peFileReader);
       Module/*?*/ lookupModule = this.LookupModule(null, moduleIdentity);
       if (lookupModule != null) {
         return lookupModule;
       }
     }
     try {
       PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, moduleIdentity, null, this.metadataReaderHost.PointerSize);
       this.LoadedModule(peFileToObjectModel.Module);
       Assembly/*?*/ assembly = peFileToObjectModel.Module as Assembly;
       if (assembly != null) {
         this.OpenMemberModules(binaryDocument, assembly);
       }
       return peFileToObjectModel.Module;
     } catch (MetadataReaderException) {
       //  Error...
     }
   }
   return Dummy.Module;
 }
Beispiel #21
0
 /// <summary>
 /// Finds the module that matches the given identifier among the already loaded set of modules,
 /// or a dummy module if no matching module can be found.
 /// </summary>
 public IModule FindModule(ModuleIdentity moduleIdentity) {
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(moduleIdentity, out unit);
   }
   IModule/*?*/ result = unit as IModule;
   if (result != null)
     return result;
   return Dummy.Module;
 }
 /// <summary>
 /// Does a look up in the loaded modules if the given module identified by moduleIdentifier is loaded. This also gives a chance to MetadataReaderHost to
 /// delay load the module if needed.
 /// </summary>
 /// <param name="referringModule"></param>
 /// <param name="moduleIdentity"></param>
 /// <returns></returns>
 internal Module/*?*/ LookupModule(IModule/*?*/ referringModule, ModuleIdentity moduleIdentity) {
   lock (GlobalLock.LockingObject) {
     uint internedModuleId = (uint)this.metadataReaderHost.InternFactory.GetModuleInternedKey(moduleIdentity);
     Module/*?*/ module = this.InternedIdToModuleMap.Find(internedModuleId);
     if (module == null && referringModule != null) {
       this.metadataReaderHost.ResolvingModuleReference(referringModule, moduleIdentity);
       module = this.InternedIdToModuleMap.Find(internedModuleId);
     }
     return module;
   }
 }
Beispiel #23
0
 public virtual ModuleIdentity ProbeModuleReference(IUnit referringUnit, ModuleIdentity referencedModule) {
   return new ModuleIdentity(referencedModule.Name, "unknown://location", referencedModule.ContainingAssembly);
 }
 /// <summary>
 /// Returns the module corresponding to passed moduleIdentifier if it was loaded.
 /// </summary>
 /// <param name="moduleIdentity"></param>
 /// <returns></returns>
 public IModule/*?*/ FindModule(ModuleIdentity moduleIdentity) {
   return this.LookupModule(null, moduleIdentity);
 }
Beispiel #25
0
 public IModule LoadModule(ModuleIdentity moduleIdentity) {
   throw new NotImplementedException();
 }
Beispiel #26
0
 public void ModuleOpened(IModule module, ModuleIdentity moduleIdentity, uint size)
 {
     ModuleOpened(module.Name.Value, moduleIdentity == null ? "" : moduleIdentity.Location, module.GetHashCode(), (int) size);
 }