private static INamedTypeDefinition /*?*/ GetType(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, int genericParameterCount, ref int offset) { int savedOffset = offset; var nestedNamespaceDefinition = GetNamespace(nameTable, namespaceDefinition, typeName, ref offset); if (nestedNamespaceDefinition != null) { var naType = GetType(nameTable, nestedNamespaceDefinition, typeName, genericParameterCount, ref offset); if (naType != null) { return(naType); } } offset = savedOffset; var nsType = GetNamespaceType(nameTable, namespaceDefinition, typeName, genericParameterCount, ref offset); if (nsType == null) { return(null); } if (offset >= typeName.Length) { return(nsType); } return(GetNestedType(nameTable, nsType, typeName, genericParameterCount, ref offset)); }
private static INestedTypeDefinition /*?*/ GetNestedType(INameTable nameTable, ITypeDefinition typeDefinition, string typeName, ref int offset) { int len = typeName.Length; if (offset >= len) { return(null); } int dotPos = typeName.IndexOf('.', offset); if (dotPos < 0) { return(null); } IName tName = nameTable.GetNameFor(typeName.Substring(offset, dotPos < 0 ? len - offset : dotPos - offset)); foreach (var member in typeDefinition.GetMembersNamed(tName, false)) { var nestedType = member as INestedTypeDefinition; if (nestedType == null) { continue; } if (dotPos < 0) { return(nestedType); } offset = dotPos + 1; return(GetNestedType(nameTable, nestedType, typeName, ref offset)); } return(null); }
internal InstructionParser(SourceMethodBody sourceMethodBody) { Contract.Requires(sourceMethodBody != null); this.sourceMethodBody = sourceMethodBody; this.host = sourceMethodBody.host; Contract.Assume(this.host != null); this.ilMethodBody = sourceMethodBody.ilMethodBody; Contract.Assume(this.ilMethodBody != null); this.MethodDefinition = sourceMethodBody.MethodDefinition; this.nameTable = sourceMethodBody.nameTable; Contract.Assume(this.nameTable != null); this.sourceLocationProvider = sourceMethodBody.sourceLocationProvider; this.localScopeProvider = sourceMethodBody.localScopeProvider; this.options = sourceMethodBody.options; this.platformType = sourceMethodBody.platformType; Contract.Assume(this.platformType != null); this.numberOfAssignmentsToLocal = sourceMethodBody.numberOfAssignmentsToLocal; Contract.Assume(this.numberOfAssignmentsToLocal != null); this.numberOfReferencesToLocal = sourceMethodBody.numberOfReferencesToLocal; Contract.Assume(this.numberOfReferencesToLocal != null); this.gotosThatTarget = sourceMethodBody.gotosThatTarget; Contract.Assume(this.gotosThatTarget != null); this.cdfg = sourceMethodBody.cdfg; Contract.Assume(this.cdfg != null); this.bindingsThatMakeALastUseOfALocalVersion = sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion; Contract.Assume(this.bindingsThatMakeALastUseOfALocalVersion != null); if (this.localScopeProvider != null) { var syncInfo = this.localScopeProvider.GetSynchronizationInformation(sourceMethodBody); if (syncInfo != null) { var syncPointFor = this.synchronizatonPointLocationFor = new Hashtable<SynchronizationPointLocation>(); IDocument doc = Dummy.Document; foreach (var loc in this.MethodDefinition.Locations) { doc = loc.Document; break; } foreach (var syncPoint in syncInfo.SynchronizationPoints) { Contract.Assume(syncPoint != null); var syncLoc = new SynchronizationPointLocation(doc, syncPoint); syncPointFor[syncPoint.SynchronizeOffset] = syncLoc; if (syncPoint.ContinuationMethod == null) syncPointFor[syncPoint.ContinuationOffset] = syncLoc; } } } }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> /// <param name="factory">The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory.</param> protected MetadataHostEnvironment(INameTable nameTable, IInternFactory factory, byte pointerSize) //^ requires pointerSize == 0 || pointerSize == 4 || pointerSize == 8; { this.nameTable = nameTable; this.internFactory = factory; this.pointerSize = pointerSize; }
/// <summary> /// Specifies whether this attribute applies to derived types and/or overridden methods. /// This information is obtained from an attribute on the attribute type definition. /// </summary> public static bool Inherited(ITypeDefinition attributeType, INameTable nameTable) { Contract.Requires(attributeType != null); Contract.Requires(nameTable != null); foreach (ICustomAttribute ca in attributeType.Attributes) { if (!TypeHelper.TypesAreEquivalent(ca.Type, attributeType.PlatformType.SystemAttributeUsageAttribute)) { continue; } foreach (IMetadataNamedArgument namedArgument in ca.NamedArguments) { if (namedArgument.ArgumentName.UniqueKey == nameTable.AllowMultiple.UniqueKey) { IMetadataConstant /*?*/ compileTimeConst = namedArgument.ArgumentValue as IMetadataConstant; if (compileTimeConst == null || compileTimeConst.Value == null || !(compileTimeConst.Value is bool)) { continue; } //^ assume false; //Unboxing cast might fail return((bool)compileTimeConst.Value); } } } return(false); }
/*^ #pragma warning disable 2669 * ^*/ /// <summary> /// Allocates a factory for loading assemblies and modules persisted as portable executable (pe) files. /// </summary> /// <param name="metadataReaderHost"> /// The host is used for providing access to pe files (OpenBinaryDocument), /// applying host specific unification policies (UnifyAssembly, UnifyAssemblyReference, UnifyModuleReference) and for deciding /// whether and how to load referenced assemblies and modules (ResolvingAssemblyReference, ResolvingModuleReference). /// </param> public PeReader( IMetadataReaderHost metadataReaderHost ) { this.ErrorsReporter = new MetadataReaderErrorsReporter(); this.metadataReaderHost = metadataReaderHost; _internedIdToModuleMap = new Hashtable <Module>(); INameTable nameTable = metadataReaderHost.NameTable; this.value__ = nameTable.GetNameFor("value__"); this.AsyncCallback = nameTable.GetNameFor("AsyncCallback"); this.ParamArrayAttribute = nameTable.GetNameFor("ParamArrayAttribute"); this.IAsyncResult = nameTable.GetNameFor("IAsyncResult"); this.ICloneable = nameTable.GetNameFor("ICloneable"); this.RuntimeArgumentHandle = nameTable.GetNameFor("RuntimeArgumentHandle"); this.RuntimeFieldHandle = nameTable.GetNameFor("RuntimeFieldHandle"); this.RuntimeMethodHandle = nameTable.GetNameFor("RuntimeMethodHandle"); this.RuntimeTypeHandle = nameTable.GetNameFor("RuntimeTypeHandle"); this.ArgIterator = nameTable.GetNameFor("ArgIterator"); this.IList = nameTable.GetNameFor("IList"); this.IEnumerable = nameTable.GetNameFor("IEnumerable"); this.IList1 = nameTable.GetNameFor("IList`1"); this.ICollection1 = nameTable.GetNameFor("ICollection`1"); this.IEnumerable1 = nameTable.GetNameFor("IEnumerable`1"); this.Mscorlib = nameTable.GetNameFor("mscorlib"); this.System_Collections_Generic = nameTable.GetNameFor("System.Collections.Generic"); this._Deleted_ = nameTable.GetNameFor("_Deleted*"); this._Module_ = nameTable.GetNameFor("<Module>"); }
public HostEnvironment(INameTable table, IEnumerable<String> assemblyPaths, IEnumerable<String> referencedAssemblies) : base(table, new InternFactory(), 4, assemblyPaths, true) { _peReader = new PeReader(this); _assemblyPaths = assemblyPaths; _referencedAssemblies = referencedAssemblies; }
private static INestedUnitNamespace /*?*/ GetNamespace(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, ref int offset) { Contract.Requires(nameTable != null); Contract.Requires(namespaceDefinition != null); Contract.Requires(typeName != null); Contract.Requires(offset >= 0); Contract.Ensures(offset >= 0); int len = typeName.Length; if (offset >= len) { return(null); } int dotPos = typeName.IndexOf('.', offset); if (dotPos < 0) { return(null); } Contract.Assume(dotPos >= offset); //if a dot has been found, it must be at offset or later IName neName = nameTable.GetNameFor(typeName.Substring(offset, dotPos - offset)); foreach (var member in namespaceDefinition.GetMembersNamed(neName, false)) { var nestedNamespace = member as INestedUnitNamespace; if (nestedNamespace == null) { continue; } offset = dotPos + 1; return(nestedNamespace); } return(null); }
private static INestedUnitNamespace /*?*/ GetNamespace(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, ref int offset) { int len = typeName.Length; if (offset >= len) { return(null); } int dotPos = typeName.IndexOf('.', offset); if (dotPos < 0) { return(null); } IName neName = nameTable.GetNameFor(typeName.Substring(offset, dotPos - offset)); foreach (var member in namespaceDefinition.GetMembersNamed(neName, false)) { var nestedNamespace = member as INestedUnitNamespace; if (nestedNamespace == null) { continue; } offset = dotPos + 1; return(nestedNamespace); } return(null); }
public HostEnvironment(INameTable table, IEnumerable <String> assemblyPaths, IEnumerable <String> referencedAssemblies) : base(table, new InternFactory(), 4, assemblyPaths, true) { _peReader = new PeReader(this); _assemblyPaths = assemblyPaths; _referencedAssemblies = referencedAssemblies; }
private static IMethodBody/*?*/ FirstStatementIsIteratorCreation(IMetadataHost host, ISourceMethodBody possibleIterator, INameTable nameTable, IStatement statement) { ICreateObjectInstance createObjectInstance = GetICreateObjectInstance(statement); if (createObjectInstance == null) { // If the first statement in the method body is not the creation of iterator closure, return a dummy. // Possible corner case not handled: a local is used to hold the constant value for the initial state of the closure. return null; } ITypeReference closureType/*?*/ = createObjectInstance.MethodToCall.ContainingType; ITypeReference unspecializedClosureType = ContractHelper.Unspecialized(closureType); if (!AttributeHelper.Contains(unspecializedClosureType.Attributes, host.PlatformType.SystemRuntimeCompilerServicesCompilerGeneratedAttribute)) return null; INestedTypeReference closureTypeAsNestedTypeReference = unspecializedClosureType as INestedTypeReference; if (closureTypeAsNestedTypeReference == null) return null; ITypeReference unspecializedClosureContainingType = ContractHelper.Unspecialized(closureTypeAsNestedTypeReference.ContainingType); if (closureType != null && TypeHelper.TypesAreEquivalent(possibleIterator.MethodDefinition.ContainingTypeDefinition, unspecializedClosureContainingType)) { IName MoveNextName = nameTable.GetNameFor("MoveNext"); foreach (ITypeDefinitionMember member in closureType.ResolvedType.GetMembersNamed(MoveNextName, false)) { IMethodDefinition moveNext = member as IMethodDefinition; if (moveNext != null) { ISpecializedMethodDefinition moveNextGeneric = moveNext as ISpecializedMethodDefinition; if (moveNextGeneric != null) moveNext = moveNextGeneric.UnspecializedVersion.ResolvedMethod; return moveNext.Body; } } } return null; }
private static INamespaceTypeDefinition /*?*/ GetNamespaceType(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, int genericParameterCount, ref int offset) { int len = typeName.Length; if (offset >= len) { return(null); } int dotPos = typeName.IndexOf('.', offset); if (dotPos < 0) { dotPos = len; } IName tName = nameTable.GetNameFor(typeName.Substring(offset, dotPos - offset)); foreach (var member in namespaceDefinition.GetMembersNamed(tName, false)) { var namespaceType = member as INamespaceTypeDefinition; if (namespaceType == null) { continue; } if (namespaceType.GenericParameterCount != genericParameterCount) { continue; } offset = dotPos + 1; return(namespaceType); } return(null); }
internal Parser(Compilation compilation, ISourceLocation sourceLocation, List<IErrorMessage> scannerAndParserErrors) { this.compilation = compilation; this.nameTable = compilation.NameTable; this.scannerAndParserErrors = this.originalScannerAndParserErrors = scannerAndParserErrors; this.scanner = new Scanner(scannerAndParserErrors, sourceLocation, true); this.insideBlock = false; this.insideType = false; }
/// <summary> /// Allocates a simple host environment using default settings inherited from MetadataReaderHost and that /// uses PeReader as its metadata reader. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> public PortableHost(INameTable nameTable) : base(nameTable, new InternFactory(), 0, null, false) { Contract.Requires(nameTable != null); Contract.Ensures(base.NameTable == nameTable); this.peReader = new PeReader(this); }
/// <summary> /// /// </summary> /// <param name="method"></param> /// <param name="host"></param> internal ClosureFinder(IMethodDefinition method, IMetadataHost host) { this.method = method; this.fieldForCapturedLocalOrParameter = new Dictionary<object, BoundField>(); this.host = host; this.nameTable = host.NameTable; this.counter = 0; this.classList.Add((INamedTypeDefinition)method.ContainingTypeDefinition); }
/// <summary> /// /// </summary> /// <param name="method"></param> /// <param name="host"></param> internal ClosureFinder(IMethodDefinition method, IMetadataHost host) { this.method = method; this.fieldForCapturedLocalOrParameter = new Dictionary <object, BoundField>(); this.host = host; this.nameTable = host.NameTable; this.counter = 0; this.classList.Add((INamedTypeDefinition)method.ContainingTypeDefinition); }
/// <summary> /// Initializing func for Serializer. /// </summary> /// <param name="H">Header of the package</param> /// <param name="NT">NameTable of package.</param> /// <param name="ET">ExportTable of package.</param> /// <param name="IT">ImportTable of Package</param> /// <param name="body">Readed and decrypted bytes of package body. </param> /// <seealso cref="L2Package.PackageReader"/> public void Initialize(IHeader H, INameTable NT, IExportTable ET, IImportTable IT, byte[] body) { Header = H; NameTable = NT; ExportTable = ET; ImportTable = IT; Bytes = body; Initialized = true; }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="factory"> /// The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory. /// </param> /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> /// <param name="searchPaths"> /// A collection of strings that are interpreted as valid paths which are used to search for units. /// </param> /// <param name="searchInGAC"> /// Whether the GAC (Global Assembly Cache) should be searched when resolving references. /// </param> protected MetadataHostEnvironment(INameTable nameTable, IInternFactory factory, byte pointerSize, IEnumerable<string> searchPaths, bool searchInGAC) //^ requires pointerSize == 0 || pointerSize == 4 || pointerSize == 8; { this.nameTable = nameTable; this.internFactory = factory; this.pointerSize = pointerSize; this.libPaths = searchPaths == null ? new List<string>(0) : new List<string>(searchPaths); this.SearchInGAC = searchInGAC; }
public MethodTransformationMetadataRewriter(IMethodReference loadLibrary, IMethodReference getProcAddress, IMethodReference isLibraryInitialized, IMetadataHost host, IPInvokeMethodsProvider methodsProvider) : base(host, copyAndRewriteImmutableReferences: false) { this.platformType = host.PlatformType; this.nameTable = host.NameTable; this.methodsProvider = methodsProvider; this.loadLibrary = loadLibrary; this.getProcAddress = getProcAddress; this.isLibraryInitialized = isLibraryInitialized; }
/// <summary> /// Rewrites the blocks in the given cdfg so that every assignment to a local or parameter is to a new local (and thus each local is just /// assigned to in exactly one place in the graph). The new names introduced by the writes are connected to the reads in successor blocks /// by means of join points (a.k.a. Phi nodes) that are found in the Reads property of an SSABasicBlock. /// </summary> /// <param name="cdfg"> /// A set of basic blocks, each of which has a list of successor blocks and some other information. /// Each block consists of a list of instructions, each of which can point to previous instructions that compute the operands it consumes. /// </param> /// <param name="cfgQueries"> /// Presents information derived from a simple control flow graph. For example, traversal orders, predecessors, dominators and dominance frontiers. /// </param> /// <param name="nameTable"> /// An extensible collection of IName instances that represent names that are commonly used during compilation. /// </param> /// <param name="sourceLocationProvider"></param> public static void GetInSingleAssignmentForm(INameTable nameTable, ControlAndDataFlowGraph <BasicBlock, Instruction> cdfg, ControlGraphQueries <BasicBlock, Instruction> cfgQueries, ISourceLocationProvider sourceLocationProvider) { Contract.Requires(nameTable != null); Contract.Requires(cdfg != null); Contract.Requires(cfgQueries != null); var singleAssigner = new SingleAssigner <BasicBlock, Instruction>(nameTable, cdfg, cfgQueries, sourceLocationProvider); singleAssigner.GetInSingleAssignmentForm(); }
/// <summary> /// Finds a type in the given module using the given type name, expressed in C# notion with dots separating both namespaces and types. /// If no such type can be found Dummy.NamespaceTypeDefinition is returned. /// </summary> /// <param name="nameTable">The table used to intern name strings.</param> /// <param name="module">The module to search for the type.</param> /// <param name="typeName">A string containing the fully qualified type name, using C# formatting conventions.</param> public static INamedTypeDefinition FindType(INameTable nameTable, IModule module, string typeName) { int offset = 0; INamedTypeDefinition /*?*/ result = GetType(nameTable, module.UnitNamespaceRoot, typeName, ref offset); if (result != null) { return(result); } return(Dummy.NamespaceTypeDefinition); }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="factory"> /// The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory. /// </param> /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> /// <param name="searchPaths"> /// A collection of strings that are interpreted as valid paths which are used to search for units. May be null. /// </param> /// <param name="searchInGAC"> /// Whether the GAC (Global Assembly Cache) should be searched when resolving references. /// </param> protected MetadataHostEnvironment(INameTable nameTable, IInternFactory factory, byte pointerSize, IEnumerable<string>/*?*/ searchPaths, bool searchInGAC) { Contract.Requires(nameTable != null); Contract.Requires(factory != null); Contract.Requires(pointerSize == 0 || pointerSize == 4 || pointerSize == 8); this.nameTable = nameTable; this.internFactory = factory; this.pointerSize = pointerSize; this.libPaths = searchPaths == null ? new List<string>(0) : new List<string>(searchPaths); this.SearchInGAC = searchInGAC; }
/// <summary> /// Finds a type in the given module using the given type name, expressed in C# notation with dots separating both namespaces and types. /// If no such type can be found Dummy.NamespaceTypeDefinition is returned. /// </summary> /// <param name="nameTable">A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances.</param> /// <param name="unit">The unit of metadata to search for the type.</param> /// <param name="typeName">A string containing the fully qualified type name, using C# formatting conventions.</param> /// <param name="genericParameterCount">The number of generic parameters the returned type should have.</param> public static INamedTypeDefinition FindType(INameTable nameTable, IUnit unit, string typeName, int genericParameterCount) { int offset = 0; INamedTypeDefinition /*?*/ result = GetType(nameTable, unit.UnitNamespaceRoot, typeName, genericParameterCount, ref offset); if (result != null) { return(result); } return(Dummy.NamespaceTypeDefinition); }
/// <summary> /// Initializes an instance of SingleAssigner. /// </summary> /// <param name="cdfg"> /// A set of basic blocks, each of which has a list of successor blocks and some other information. /// Each block consists of a list of instructions, each of which can point to previous instructions that compute the operands it consumes. /// </param> /// <param name="nameTable"> /// An extensible collection of IName instances that represent names that are commonly used during compilation. /// </param> /// <param name="cfgQueries"></param> /// <param name="sourceLocationProvider">An object that can map some kinds of ILocation objects to IPrimarySourceLocation objects. May be null.</param> private SingleAssigner(INameTable nameTable, ControlAndDataFlowGraph <BasicBlock, Instruction> cdfg, ControlGraphQueries <BasicBlock, Instruction> cfgQueries, ISourceLocationProvider sourceLocationProvider) { Contract.Requires(nameTable != null); Contract.Requires(cdfg != null); Contract.Requires(cfgQueries != null); this.nameTable = nameTable; this.cdfg = cdfg; this.cfgQueries = cfgQueries; this.sourceLocationProvider = sourceLocationProvider; }
private static INestedTypeDefinition /*?*/ GetNestedType(INameTable nameTable, ITypeDefinition typeDefinition, string typeName, int genericParameterCount, ref int offset) { Contract.Requires(nameTable != null); Contract.Requires(typeDefinition != null); Contract.Requires(typeName != null); Contract.Requires(genericParameterCount >= 0); Contract.Requires(offset >= 0); Contract.Ensures(offset >= 0); int len = typeName.Length; if (offset >= len) { return(null); } int dotPos = typeName.IndexOf('.', offset); Contract.Assume(dotPos < 0 || (dotPos >= offset && dotPos < len)); if (dotPos < 0) { dotPos = len; } IName tName = nameTable.GetNameFor(typeName.Substring(offset, dotPos - offset)); foreach (var member in typeDefinition.GetMembersNamed(tName, false)) { var nestedType = member as INestedTypeDefinition; if (nestedType == null) { continue; } if (dotPos == len) { if (nestedType.GenericParameterCount != genericParameterCount) { continue; } return(nestedType); } if (nestedType.GenericParameterCount > genericParameterCount) { continue; } offset = dotPos + 1; var nt = GetNestedType(nameTable, nestedType, typeName, genericParameterCount - nestedType.GenericParameterCount, ref offset); if (nt != null) { return(nt); } } return(null); }
public static AssemblyIdentity Parse(INameTable nameTable, string formattedName) { var name = new System.Reflection.AssemblyName(formattedName); return new AssemblyIdentity(nameTable.GetNameFor(name.Name), name.CultureName, name.Version, name.GetPublicKeyToken(), #if COREFX ""); #else name.CodeBase); #endif }
public NodeVisitor(IMetadataHost host, CommonSemanticModel semanticModel, ISourceLocationProvider /*?*/ sourceLocationProvider) { this.host = host; this.nameTable = host.NameTable; this.semanticModel = semanticModel; this.sourceLocationProvider = sourceLocationProvider; this.contractMethods = new ContractMethods(host); // translate the entire metadata model for the assembly // the actual visit is just to get method bodies for any methods // defined in the cone that is visited. this.mapper = ReferenceMapper.TranslateAssembly(host, semanticModel.Compilation.Assembly); }
internal static IMethodDefinition GetStaticConstructor(INameTable nametable, ITypeDefinition t) { Contract.Requires(nametable != null); Contract.Requires(t != null); Contract.Requires(!(t is Dummy)); Contract.Ensures(Contract.Result <IMethodDefinition>() != null); // return the "first" we find. will be eithe r0 or 1 static constructor. foreach (var cctor in t.ResolvedType.GetMembersNamed(nametable.Cctor, false)) { return(cctor as IMethodDefinition); } return(Dummy.Method); }
public static AssemblyIdentity Parse(INameTable nameTable, string formattedName) { var name = new System.Reflection.AssemblyName(formattedName); return(new AssemblyIdentity(nameTable.GetNameFor(name.Name), name.CultureName, name.Version, name.GetPublicKeyToken(), #if COREFX "")); #else name.CodeBase); #endif }
/// <summary> /// Specifies whether this attribute applies to derived types and/or overridden methods. /// This information is obtained from an attribute on the attribute type definition. /// </summary> public static bool Inherited(ITypeDefinition attributeType, INameTable nameTable) { foreach (ICustomAttribute ca in attributeType.Attributes) { if (!TypeHelper.TypesAreEquivalent(ca.Type, attributeType.PlatformType.SystemAttributeUsageAttribute)) continue; foreach (IMetadataNamedArgument namedArgument in ca.NamedArguments) { if (namedArgument.ArgumentName.UniqueKey == nameTable.AllowMultiple.UniqueKey) { IMetadataConstant/*?*/ compileTimeConst = namedArgument.ArgumentValue as IMetadataConstant; if (compileTimeConst == null || compileTimeConst.Value == null || !(compileTimeConst.Value is bool)) continue; //^ assume false; //Unboxing cast might fail return (bool)compileTimeConst.Value; } } } return false; }
/// <summary> /// Finds a type in the given module using the given type name, expressed in C# notation with dots separating both namespaces and types. /// If no such type can be found Dummy.NamespaceTypeDefinition is returned. /// </summary> /// <param name="nameTable">A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances.</param> /// <param name="unit">The unit of metadata to search for the type.</param> /// <param name="typeName">A string containing the fully qualified type name, using C# formatting conventions.</param> public static INamedTypeDefinition FindType(INameTable nameTable, IUnit unit, string typeName) { Contract.Requires(nameTable != null); Contract.Requires(unit != null); Contract.Requires(typeName != null); Contract.Ensures(Contract.Result <INamedTypeDefinition>() != null); int offset = 0; INamedTypeDefinition /*?*/ result = GetType(nameTable, unit.UnitNamespaceRoot, typeName, 0, ref offset); if (result != null) { return(result); } return(Dummy.NamespaceTypeDefinition); }
static void Main(string[] args) { //Alloc pf = new PackageReader(); pf.Read("D:\\la2\\maps\\17_21.unr"); //pf.Read("D:\\la2\\system\\lineageeffect.u"); header = new Header(pf.Bytes); ExportTable = new ExportTable(header, pf.Bytes); ImportTable = new ImportTable(header, pf.Bytes); NameTable = new NameTable(header, pf.Bytes); Property.Resolve = Resolver; //GetAllPropertyNames(); Console.ReadKey(); }
public static AssemblyIdentity Parse(INameTable nameTable, string formattedName) { var name = new System.Reflection.AssemblyName(formattedName); return(new AssemblyIdentity(nameTable.GetNameFor(name.Name), #if FEATURE_ASSEMBLYNAME_CULTUREINFO name.CultureInfo.Name, #else name.CultureName, #endif name.Version, name.GetPublicKeyToken(), #if FEATURE_ASSEMBLYNAME_CODEBASE name.CodeBase)); #else string.Empty); #endif }
public void Initialize() { try { //Alloc pf = new PackageReader(); pf.Read("D:\\la2\\maps\\17_21.unr"); header = new Header(pf.Bytes); ExportTable = new ExportTable(header, pf.Bytes); ImportTable = new ImportTable(header, pf.Bytes); NameTable = new NameTable(header, pf.Bytes); Property.Resolve = Resolver; } catch (Exception ex) { //Assert (no exceptions reading...) Assert.Fail(ex.ToString()); } }
public ModuleReaderTestClass() { this.HostEnv = new HostEnvironment(); this.NameTable = this.HostEnv.NameTable; string location = Directory.GetCurrentDirectory(); string cppAssemblyPath = Path.Combine(location, "MRW_CppAssembly.dll"); string ilAsmAssemblyPath = Path.Combine(location, "MRW_ILAsmAssembly.dll"); string module1Path = Path.Combine(location, "MRW_Module1.netmodule"); string module2Path = Path.Combine(location, "MRW_Module2.netmodule"); string phxArchMsilPath = Path.Combine(location, "arch-msil.dll"); string testAssemblyPath = Path.Combine(location, "MRW_TestAssembly.dll"); string assemblyPath = Path.Combine(location, "MRW_Assembly.dll"); string vjslibPath = Path.Combine(location, "vjslib.dll"); ExtractResource("PEReaderTests.TestModules.MRW_CppAssembly.dll", cppAssemblyPath); ExtractResource("PEReaderTests.TestModules.MRW_ILAsmAssembly.dll", ilAsmAssemblyPath); ExtractResource("PEReaderTests.TestModules.MRW_Module1.netmodule", module1Path); ExtractResource("PEReaderTests.TestModules.MRW_Module2.netmodule", module2Path); ExtractResource("PEReaderTests.TestModules.arch-msil.dll", phxArchMsilPath); ExtractResource("PEReaderTests.TestModules.MRW_TestAssembly.dll", testAssemblyPath); ExtractResource("PEReaderTests.TestModules.MRW_Assembly.dll", assemblyPath); ExtractResource("PEReaderTests.TestModules.vjslib.dll", vjslibPath); DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(typeof(object).Assembly.Location)); string clrLocation = dirInfo.Parent.FullName + "\\" + "v2.0.50727\\"; this.MscorlibAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(clrLocation + "mscorlib.dll"); this.SystemAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(clrLocation + "System.dll"); this.VjslibAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(vjslibPath); this.AssemblyAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(assemblyPath); this.CppAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(cppAssemblyPath); this.TestAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(testAssemblyPath); this.Module1 = (IModule)this.HostEnv.LoadUnitFrom(module1Path); this.Module2 = (IModule)this.HostEnv.LoadUnitFrom(module2Path); this.ILAsmAssembly = (IAssembly)this.HostEnv.LoadUnitFrom(ilAsmAssemblyPath); this.PhxArchMsil = (IAssembly)this.HostEnv.LoadUnitFrom(phxArchMsilPath); }
internal ILGeneratorScope(uint offset, INameTable nameTable, IMethodDefinition containingMethod) { this.offset = offset; this.nameTable = nameTable; this.methodDefinition = containingMethod; }
/// <summary> /// Allocates a simple host environment using default settings inherited from MetadataReaderHost and that /// uses PeReader as its metadata reader. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> public DefaultHost(INameTable nameTable) : base(nameTable, new InternFactory(), 0, null, false) { this.peReader = new PeReader(this); }
public HostEnvironment(INameTable nameTable, IInternFactory internFactory) : base(nameTable, internFactory, 0, null, false) { _reader = new PeReader(this); _unresolvedIdentities = new HashSet <UnresolvedReference <IUnit, AssemblyIdentity> >(); }
public HostEnvironment(INameTable nameTable) : this(nameTable, new InternFactory()) { }
internal TypeNameParser( INameTable nameTable, string typeName ) { this.NameTable = nameTable; this.TypeName = typeName; this.Length = typeName.Length; this.Version = nameTable.GetNameFor("Version"); this.Retargetable = nameTable.GetNameFor("Retargetable"); this.PublicKeyToken = nameTable.GetNameFor("PublicKeyToken"); this.Culture = nameTable.GetNameFor("Culture"); this.neutral = nameTable.GetNameFor("neutral"); this.CurrentIdentifierInfo = nameTable.EmptyName; this.NextToken(false); }
/*^ #pragma warning disable 2666, 2669, 2677, 2674 ^*/ internal PEFileToObjectModel( PeReader peReader, PEFileReader peFileReader, ModuleIdentity moduleIdentity, Assembly/*?*/ containingAssembly, byte pointerSize ) //^ requires peFileReader.IsAssembly ==> moduleIdentity.ContainingAssembly != null; //^ requires peFileReader.IsAssembly ==> containingAssembly == null; //^ requires !(moduleIdentity.Location != null && moduleIdentity.Location.Length != 0); { this.pointerSize = pointerSize; this.document = new MetadataObjectDocument(this); this.ModuleReader = peReader; this.PEFileReader = peFileReader; this.NameTable = peReader.metadataReaderHost.NameTable; this.InternFactory = peReader.metadataReaderHost.InternFactory; this.StringIndexToNameTable = new Hashtable<IName>(); this.StringIndexToUnmangledNameTable = new Hashtable<IName>(); this.typeCache = new TypeCache(this); uint moduleNameOffset = peFileReader.ModuleTable.GetName(1); IName moduleName = this.GetNameFromOffset(moduleNameOffset); AssemblyIdentity/*?*/ assemblyIdentity = moduleIdentity as AssemblyIdentity; if (peFileReader.IsAssembly) { //^ assert assemblyIdentity != null; AssemblyRow assemblyRow = peFileReader.AssemblyTable[1]; IName assemblyName = this.GetNameFromOffset(assemblyRow.Name); byte[] publicKeyArray = TypeCache.EmptyByteArray; if (assemblyRow.PublicKey != 0) { publicKeyArray = peFileReader.BlobStream[assemblyRow.PublicKey]; } uint internedModuleId = (uint)peReader.metadataReaderHost.InternFactory.GetAssemblyInternedKey(assemblyIdentity); Assembly assem = new Assembly(this, moduleName, peFileReader.COR20Header.COR20Flags, internedModuleId, assemblyIdentity, assemblyName, assemblyRow.Flags, publicKeyArray); this.ContainingAssembly = assem; this.Module = assem; } else { uint internedModuleId = (uint)peReader.metadataReaderHost.InternFactory.GetModuleInternedKey(moduleIdentity); this.ContainingAssembly = containingAssembly; this.Module = new Module(this, moduleName, peFileReader.COR20Header.COR20Flags, internedModuleId, moduleIdentity); } this.LoadAssemblyReferences(); this.LoadModuleReferences(); this.RootModuleNamespace = new RootNamespace(this); this.NamespaceINameHashtable = new Hashtable<Namespace>(); this.LoadNamespaces(); this.NamespaceReferenceINameHashtable = new DoubleHashtable<NamespaceReference>(); this.NamespaceTypeTokenTable = new DoubleHashtable(peFileReader.TypeDefTable.NumberOfRows + peFileReader.ExportedTypeTable.NumberOfRows); this.NestedTypeTokenTable = new DoubleHashtable(peFileReader.NestedClassTable.NumberOfRows + peFileReader.ExportedTypeTable.NumberOfRows); this.PreLoadTypeDefTableLookup(); this.ModuleTypeDefArray = new TypeBase/*?*/[peFileReader.TypeDefTable.NumberOfRows + 1]; this.ModuleTypeDefLoadState = new LoadState[peFileReader.TypeDefTable.NumberOfRows + 1]; this.RedirectedTypeDefArray = new INamedTypeReference/*?*/[peFileReader.TypeDefTable.NumberOfRows + 1]; this.ModuleTypeDefLoadState[0] = LoadState.Loaded; this.ExportedTypeArray = new ExportedTypeAliasBase/*?*/[peFileReader.ExportedTypeTable.NumberOfRows + 1]; this.ExportedTypeLoadState = new LoadState[peFileReader.ExportedTypeTable.NumberOfRows + 1]; this.ExportedTypeLoadState[0] = LoadState.Loaded; this.ModuleGenericParamArray = new GenericParameter[peFileReader.GenericParamTable.NumberOfRows + 1]; if (peFileReader.MethodSpecTable.NumberOfRows > 0) { this.ModuleMethodSpecHashtable = new DoubleHashtable<IGenericMethodInstanceReference>(peFileReader.MethodSpecTable.NumberOfRows + 1); } this.ModuleTypeRefReferenceArray = new INamedTypeReference[peFileReader.TypeRefTable.NumberOfRows + 1]; this.ModuleTypeRefReferenceLoadState = new LoadState[peFileReader.TypeRefTable.NumberOfRows + 1]; this.ModuleTypeRefReferenceLoadState[0] = LoadState.Loaded; if (peFileReader.TypeSpecTable.NumberOfRows > 0) { this.ModuleTypeSpecHashtable = new DoubleHashtable<TypeSpecReference>(peFileReader.TypeSpecTable.NumberOfRows + 1); } this.ModuleFieldArray = new FieldDefinition[peFileReader.FieldTable.NumberOfRows + 1]; this.ModuleMethodArray = new IMethodDefinition[peFileReader.MethodTable.NumberOfRows + 1]; this.ModuleEventArray = new EventDefinition[peFileReader.EventTable.NumberOfRows + 1]; this.ModulePropertyArray = new PropertyDefinition[peFileReader.PropertyTable.NumberOfRows + 1]; this.ModuleMemberReferenceArray = new MemberReference/*?*/[peFileReader.MemberRefTable.NumberOfRows + 1]; this.UnspecializedMemberReferenceArray = new MemberReference/*?*/[peFileReader.MemberRefTable.NumberOfRows + 1]; this.SpecializedFieldHashtable = new DoubleHashtable<ISpecializedFieldReference>(); this.SpecializedMethodHashtable = new DoubleHashtable<ISpecializedMethodReference>(); this.CustomAttributeArray = new ICustomAttribute/*?*/[peFileReader.CustomAttributeTable.NumberOfRows + 1]; this.DeclSecurityArray = new ISecurityAttribute/*?*/[peFileReader.DeclSecurityTable.NumberOfRows + 1]; this._Module_ = this.Create_Module_Type(); }
/// <summary> /// Allocates a simple host environment using default settings inherited from MetadataReaderHost and that /// uses PeReader as its metadata reader. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="projectToCLRTypes">True if the host should project references to certain Windows Runtime types and methods /// to corresponding CLR types and methods, in order to emulate the runtime behavior of the CLR.</param> public DefaultWindowsRuntimeHost(INameTable nameTable, bool projectToCLRTypes = true) : base(nameTable, new InternFactory(), 0, null, false, projectToCLRTypes) { this.peReader = new PeReader(this); }
internal NamespaceTypeName(INameTable nameTable, NamespaceName/*?*/ namespaceName, IName name) { this.NamespaceName = namespaceName; this.Name = name; string nameStr = null; TypeCache.SplitMangledTypeName(name.Value, out nameStr, out this.genericParameterCount); if (this.genericParameterCount > 0) this.unmanagledTypeName = nameTable.GetNameFor(nameStr); else this.unmanagledTypeName = name; }
/// <summary> /// Allocates a visitor that traverses a code model and generates explicit assert and assume statements based on implicit checks and assumptions /// that are present in the object model. For example, any array index expression implicitly asserts that the array index is within bounds. /// The purpose of this visitor is to produce an object model that can be checked by a static checker, without requiring the static checker to /// have special cases for all of the implicit assertions and assumes in the code. /// </summary> /// <param name="nameTable">A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances.</param> /// <param name="insertAssumeFalseAtLine"></param> public AssertAssumeAdderVisitor(INameTable nameTable, uint? insertAssumeFalseAtLine) : base() { this.nameTable = nameTable; this.insertAssumeFalseAtLine = insertAssumeFalseAtLine; }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// Remember to call the Dispose method when the resulting object is no longer needed. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="factory"> /// The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory. /// </param> /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> /// <param name="searchPaths"> /// A collection of strings that are interpreted as valid paths which are used to search for units. /// </param> /// <param name="searchInGAC"> /// Whether the GAC (Global Assembly Cache) should be searched when resolving references. /// </param> protected MetadataReaderHost(INameTable nameTable, IInternFactory factory, byte pointerSize, IEnumerable<string> searchPaths, bool searchInGAC) : base(nameTable, factory, pointerSize, searchPaths, searchInGAC) { Contract.Requires(pointerSize == 0 || pointerSize == 4 || pointerSize == 8); }
private ReferenceMapper(IMetadataHost host, R.IAssemblySymbol assemblySymbol) { this.host = host; this.nameTable = host.NameTable; this.assemblyBeingTranslated = assemblySymbol; }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> protected MetadataReaderHost(INameTable nameTable) : this(nameTable, 0) { }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> protected MetadataHostEnvironment(INameTable nameTable, byte pointerSize) :this(nameTable, new InternFactory(), pointerSize) //^ requires pointerSize == 0 || pointerSize == 4 || pointerSize == 8; { }
/// <summary> /// Allocates a metadata (IL) representation along with a source level representation of the body of a method or of a property/event accessor. /// </summary> /// <param name="ilMethodBody">A method body whose IL operations should be decompiled into a block of statements that will be the /// result of the Block property of the resulting source method body.</param> /// <param name="host">An object representing the application that is hosting the converter. It is used to obtain access to some global /// objects and services such as the shared name table and the table for interning references.</param> /// <param name="sourceLocationProvider">An object that can map some kinds of ILocation objects to IPrimarySourceLocation objects. May be null.</param> /// <param name="localScopeProvider">An object that can provide information about the local scopes of a method.</param> /// <param name="options">Set of options that control decompilation.</param> public SourceMethodBody(IMethodBody ilMethodBody, IMetadataHost host, ISourceLocationProvider/*?*/ sourceLocationProvider, ILocalScopeProvider/*?*/ localScopeProvider, DecompilerOptions options = DecompilerOptions.None) : base(host, sourceLocationProvider) { this.ilMethodBody = ilMethodBody; this.host = host; this.nameTable = host.NameTable; this.sourceLocationProvider = sourceLocationProvider; this.pdbReader = sourceLocationProvider as PdbReader; this.localScopeProvider = localScopeProvider; this.options = options; this.platformType = ilMethodBody.MethodDefinition.ContainingTypeDefinition.PlatformType; this.operationEnumerator = ilMethodBody.Operations.GetEnumerator(); if (IteratorHelper.EnumerableIsNotEmpty(ilMethodBody.LocalVariables)) this.LocalsAreZeroed = ilMethodBody.LocalsAreZeroed; else this.LocalsAreZeroed = true; this.MethodDefinition = ilMethodBody.MethodDefinition; }
private NamespaceTypeName(INameTable nameTable, NamespaceName/*?*/ namespaceName, IName name, IName unmangledTypeName) { this.NamespaceName = namespaceName; this.Name = name; this.unmanagledTypeName = unmangledTypeName; }
// Caller should lock peFileToObjectModel internal CoreTypes(PEFileToObjectModel peFileToObjectModel) { INameTable nameTable = peFileToObjectModel.NameTable; PEFileReader peFileReader = peFileToObjectModel.PEFileReader; PeReader peReader = peFileToObjectModel.ModuleReader; Module module = peFileToObjectModel.Module; AssemblyIdentity /*?*/ assemblyIdentity = module.ModuleIdentity as AssemblyIdentity; int systemName = nameTable.System.UniqueKey; int voidName = nameTable.Void.UniqueKey; int booleanName = nameTable.Boolean.UniqueKey; int charName = nameTable.Char.UniqueKey; int byteName = nameTable.Byte.UniqueKey; int sByteName = nameTable.SByte.UniqueKey; int int16Name = nameTable.Int16.UniqueKey; int uint16Name = nameTable.UInt16.UniqueKey; int int32Name = nameTable.Int32.UniqueKey; int uint32Name = nameTable.UInt32.UniqueKey; int int64Name = nameTable.Int64.UniqueKey; int uint64Name = nameTable.UInt64.UniqueKey; int stringName = nameTable.String.UniqueKey; int intPtrName = nameTable.IntPtr.UniqueKey; int uintPtrName = nameTable.UIntPtr.UniqueKey; int objectName = nameTable.Object.UniqueKey; int singleName = nameTable.Single.UniqueKey; int doubleName = nameTable.Double.UniqueKey; int decimalName = nameTable.Decimal.UniqueKey; int typedReference = nameTable.TypedReference.UniqueKey; int enumName = nameTable.Enum.UniqueKey; int valueTypeName = nameTable.ValueType.UniqueKey; int multicastDelegateName = nameTable.MulticastDelegate.UniqueKey; int typeName = nameTable.Type.UniqueKey; int arrayName = nameTable.Array.UniqueKey; int paramArrayAttributeName = peReader.ParamArrayAttribute.UniqueKey; if (assemblyIdentity != null && assemblyIdentity.Equals(peReader.metadataReaderHost.CoreAssemblySymbolicIdentity)) { peReader.RegisterCoreAssembly(module as Assembly); uint numberOfTypeDefs = peFileReader.TypeDefTable.NumberOfRows; for (uint i = 1; i <= numberOfTypeDefs; ++i) { TypeDefRow typeDefRow = peFileReader.TypeDefTable[i]; if (!typeDefRow.IsNested) { int namespaceName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Namespace).UniqueKey; if (namespaceName == systemName) { int typeDefName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Name).UniqueKey; if (typeDefName == voidName) { this.SystemVoid = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Void); } else if (typeDefName == booleanName) { this.SystemBoolean = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Boolean); } else if (typeDefName == charName) { this.SystemChar = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Char); } else if (typeDefName == byteName) { this.SystemByte = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Byte); } else if (typeDefName == sByteName) { this.SystemSByte = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.SByte); } else if (typeDefName == int16Name) { this.SystemInt16 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Int16); } else if (typeDefName == uint16Name) { this.SystemUInt16 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UInt16); } else if (typeDefName == int32Name) { this.SystemInt32 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Int32); } else if (typeDefName == uint32Name) { this.SystemUInt32 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UInt32); } else if (typeDefName == int64Name) { this.SystemInt64 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Int64); } else if (typeDefName == uint64Name) { this.SystemUInt64 = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UInt64); } else if (typeDefName == stringName) { this.SystemString = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.String); } else if (typeDefName == intPtrName) { this.SystemIntPtr = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.IntPtr); } else if (typeDefName == uintPtrName) { this.SystemUIntPtr = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.UIntPtr); } else if (typeDefName == objectName) { this.SystemObject = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Object); } else if (typeDefName == singleName) { this.SystemSingle = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Single); } else if (typeDefName == doubleName) { this.SystemDouble = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.Double); } else if (typeDefName == decimalName) { this.SystemDecimal = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == typedReference) { this.SystemTypedReference = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.TypedReference); } else if (typeDefName == enumName) { this.SystemEnum = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == valueTypeName) { this.SystemValueType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == multicastDelegateName) { this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == typeName) { this.SystemType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == arrayName) { this.SystemArray = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == paramArrayAttributeName) { this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } } } } } else { uint numberOfTypeRefs = peFileReader.TypeRefTable.NumberOfRows; AssemblyReference /*?*/ coreAssemblyRef = peFileToObjectModel.FindAssemblyReference(peReader.metadataReaderHost.CoreAssemblySymbolicIdentity); if (coreAssemblyRef == null) { // Error... coreAssemblyRef = new AssemblyReference(peFileToObjectModel, 0, peReader.metadataReaderHost.CoreAssemblySymbolicIdentity, AssemblyFlags.Retargetable); } uint coreAssemblyRefToken = coreAssemblyRef.TokenValue; for (uint i = 1; i <= numberOfTypeRefs; ++i) { TypeRefRow typeRefRow = peFileReader.TypeRefTable[i]; if (typeRefRow.ResolutionScope != coreAssemblyRefToken) { continue; } int namespaceName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Namespace).UniqueKey; if (namespaceName == systemName) { int typeDefName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Name).UniqueKey; if (typeDefName == voidName) { this.SystemVoid = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Void); } else if (typeDefName == booleanName) { this.SystemBoolean = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Boolean); } else if (typeDefName == charName) { this.SystemChar = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Char); } else if (typeDefName == byteName) { this.SystemByte = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Byte); } else if (typeDefName == sByteName) { this.SystemSByte = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.SByte); } else if (typeDefName == int16Name) { this.SystemInt16 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Int16); } else if (typeDefName == uint16Name) { this.SystemUInt16 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UInt16); } else if (typeDefName == int32Name) { this.SystemInt32 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Int32); } else if (typeDefName == uint32Name) { this.SystemUInt32 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UInt32); } else if (typeDefName == int64Name) { this.SystemInt64 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Int64); } else if (typeDefName == uint64Name) { this.SystemUInt64 = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UInt64); } else if (typeDefName == stringName) { this.SystemString = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.String); } else if (typeDefName == intPtrName) { this.SystemIntPtr = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.IntPtr); } else if (typeDefName == uintPtrName) { this.SystemUIntPtr = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.UIntPtr); } else if (typeDefName == objectName) { this.SystemObject = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Object); } else if (typeDefName == singleName) { this.SystemSingle = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Single); } else if (typeDefName == doubleName) { this.SystemDouble = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.Double); } else if (typeDefName == decimalName) { this.SystemDecimal = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == typedReference) { this.SystemTypedReference = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.TypedReference); } else if (typeDefName == enumName) { this.SystemEnum = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == valueTypeName) { this.SystemValueType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == multicastDelegateName) { this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == typeName) { this.SystemType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == arrayName) { this.SystemArray = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == paramArrayAttributeName) { this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, ModuleSignatureTypeCode.NotModulePrimitive); } } } NamespaceReference systemNSR = peFileToObjectModel.GetNamespaceReferenceForString(coreAssemblyRef, nameTable.System); if (this.SystemVoid == null) { this.SystemVoid = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Void, ModuleSignatureTypeCode.Void); } if (this.SystemBoolean == null) { this.SystemBoolean = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Boolean, ModuleSignatureTypeCode.Boolean); } if (this.SystemChar == null) { this.SystemChar = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Char, ModuleSignatureTypeCode.Char); } if (this.SystemByte == null) { this.SystemByte = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Byte, ModuleSignatureTypeCode.Byte); } if (this.SystemSByte == null) { this.SystemSByte = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.SByte, ModuleSignatureTypeCode.SByte); } if (this.SystemInt16 == null) { this.SystemInt16 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Int16, ModuleSignatureTypeCode.Int16); } if (this.SystemUInt16 == null) { this.SystemUInt16 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UInt16, ModuleSignatureTypeCode.UInt16); } if (this.SystemInt32 == null) { this.SystemInt32 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Int32, ModuleSignatureTypeCode.Int32); } if (this.SystemUInt32 == null) { this.SystemUInt32 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UInt32, ModuleSignatureTypeCode.UInt32); } if (this.SystemInt64 == null) { this.SystemInt64 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Int64, ModuleSignatureTypeCode.Int64); } if (this.SystemUInt64 == null) { this.SystemUInt64 = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UInt64, ModuleSignatureTypeCode.UInt64); } if (this.SystemString == null) { this.SystemString = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.String, ModuleSignatureTypeCode.String); } if (this.SystemIntPtr == null) { this.SystemIntPtr = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.IntPtr, ModuleSignatureTypeCode.IntPtr); } if (this.SystemUIntPtr == null) { this.SystemUIntPtr = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.UIntPtr, ModuleSignatureTypeCode.UIntPtr); } if (this.SystemObject == null) { this.SystemObject = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Object, ModuleSignatureTypeCode.Object); } if (this.SystemSingle == null) { this.SystemSingle = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Single, ModuleSignatureTypeCode.Single); } if (this.SystemDouble == null) { this.SystemDouble = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Double, ModuleSignatureTypeCode.Double); } if (this.SystemDecimal == null) { this.SystemDecimal = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Decimal, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemTypedReference == null) { this.SystemTypedReference = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.TypedReference, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemEnum == null) { this.SystemEnum = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Enum, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemValueType == null) { this.SystemValueType = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.ValueType, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemMulticastDelegate == null) { this.SystemMulticastDelegate = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.MulticastDelegate, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemType == null) { this.SystemType = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Type, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemArray == null) { this.SystemArray = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, nameTable.Array, ModuleSignatureTypeCode.NotModulePrimitive); } if (this.SystemParamArrayAttribute == null) { this.SystemParamArrayAttribute = peFileToObjectModel.typeCache.CreateCoreTypeReference(coreAssemblyRef, systemNSR, peReader.ParamArrayAttribute, ModuleSignatureTypeCode.NotModulePrimitive); } } }
/// <summary> /// Allocates a simple host environment using default settings inherited from MetadataReaderHost and that /// uses PeReader as its metadata reader. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> public DefaultHost(INameTable nameTable) : base(nameTable) { this.peReader = new PeReader(this); }
private NamespaceName/*?*/ GetNamespaceName(INameTable nameTable, INestedUnitNamespaceReference/*?*/ nestedUnitNamespaceReference) { if (nestedUnitNamespaceReference == null) return null; var parentNamespaceName = this.GetNamespaceName(nameTable, nestedUnitNamespaceReference.ContainingUnitNamespace as INestedUnitNamespaceReference); return new NamespaceName(nameTable, parentNamespaceName, nestedUnitNamespaceReference.Name); }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="factory">The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory.</param> /// /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> protected MetadataReaderHost(INameTable nameTable, IInternFactory factory, byte pointerSize) : base(nameTable, factory, pointerSize) //^ requires pointerSize == 0 || pointerSize == 4 || pointerSize == 8; { }
internal NestedTypeName(INameTable nameTable, NominalTypeName containingTypeName, IName mangledName) { this.ContainingTypeName = containingTypeName; this.Name = mangledName; string nameStr = null; TypeCache.SplitMangledTypeName(mangledName.Value, out nameStr, out this.genericParameterCount); this.unmangledTypeName = nameTable.GetNameFor(nameStr); }
internal NamespaceName(INameTable nameTable, NamespaceName/*?*/ parentNamespaceName, IName name) { this.ParentNamespaceName = parentNamespaceName; this.Name = name; if (parentNamespaceName == null) this.FullyQualifiedName = name; else this.FullyQualifiedName = nameTable.GetNameFor(parentNamespaceName.FullyQualifiedName.Value + "." + name); }
/// <summary> /// Allocates an object that provides an abstraction over the application hosting compilers based on this framework. /// </summary> /// <param name="nameTable"> /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. /// </param> /// <param name="factory"> /// The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory. /// </param> /// <param name="pointerSize">The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. /// </param> /// <param name="searchPaths"> /// A collection of strings that are interpreted as valid paths which are used to search for units. /// </param> /// <param name="searchInGAC"> /// Whether the GAC (Global Assembly Cache) should be searched when resolving references. /// </param> protected SourceEditHostEnvironment(INameTable nameTable, IInternFactory factory, byte pointerSize, IEnumerable<string> searchPaths, bool searchInGAC) : base(nameTable, factory, pointerSize, searchPaths, searchInGAC) //^ requires pointerSize == 0 || pointerSize == 4 || pointerSize == 8; { }
// Caller should lock peFileToObjectModel internal CoreTypes(PEFileToObjectModel peFileToObjectModel) { INameTable nameTable = peFileToObjectModel.NameTable; PEFileReader peFileReader = peFileToObjectModel.PEFileReader; PeReader peReader = peFileToObjectModel.ModuleReader; Module module = peFileToObjectModel.Module; AssemblyIdentity /*?*/ assemblyIdentity = module.ModuleIdentity as AssemblyIdentity; //This does more than just initialize the five types exposed above, since it is also //necessary to initialize any typedefs and typerefs to types with short forms //in such a way that they have the correct type codes. int systemName = nameTable.System.UniqueKey; int voidName = nameTable.Void.UniqueKey; int booleanName = nameTable.Boolean.UniqueKey; int charName = nameTable.Char.UniqueKey; int byteName = nameTable.Byte.UniqueKey; int sByteName = nameTable.SByte.UniqueKey; int int16Name = nameTable.Int16.UniqueKey; int uint16Name = nameTable.UInt16.UniqueKey; int int32Name = nameTable.Int32.UniqueKey; int uint32Name = nameTable.UInt32.UniqueKey; int int64Name = nameTable.Int64.UniqueKey; int uint64Name = nameTable.UInt64.UniqueKey; int stringName = nameTable.String.UniqueKey; int intPtrName = nameTable.IntPtr.UniqueKey; int uintPtrName = nameTable.UIntPtr.UniqueKey; int objectName = nameTable.Object.UniqueKey; int singleName = nameTable.Single.UniqueKey; int doubleName = nameTable.Double.UniqueKey; int decimalName = nameTable.Decimal.UniqueKey; int typedReference = nameTable.TypedReference.UniqueKey; int enumName = nameTable.Enum.UniqueKey; int valueTypeName = nameTable.ValueType.UniqueKey; int multicastDelegateName = nameTable.MulticastDelegate.UniqueKey; int typeName = nameTable.Type.UniqueKey; int arrayName = nameTable.Array.UniqueKey; int paramArrayAttributeName = peReader.ParamArrayAttribute.UniqueKey; if (assemblyIdentity != null && assemblyIdentity.Equals(peReader.metadataReaderHost.CoreAssemblySymbolicIdentity)) { peReader.RegisterCoreAssembly(module as Assembly); uint numberOfTypeDefs = peFileReader.TypeDefTable.NumberOfRows; for (uint i = 1; i <= numberOfTypeDefs; ++i) { TypeDefRow typeDefRow = peFileReader.TypeDefTable[i]; if (!typeDefRow.IsNested) { int namespaceName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Namespace).UniqueKey; if (namespaceName == systemName) { int typeDefName = peFileToObjectModel.GetNameFromOffset(typeDefRow.Name).UniqueKey; if (typeDefName == voidName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Void); } else if (typeDefName == booleanName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Boolean); } else if (typeDefName == charName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Char); } else if (typeDefName == byteName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Byte); } else if (typeDefName == sByteName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.SByte); } else if (typeDefName == int16Name) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Int16); } else if (typeDefName == uint16Name) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt16); } else if (typeDefName == int32Name) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Int32); } else if (typeDefName == uint32Name) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt32); } else if (typeDefName == int64Name) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Int64); } else if (typeDefName == uint64Name) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt64); } else if (typeDefName == stringName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.String); } else if (typeDefName == intPtrName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.IntPtr); } else if (typeDefName == uintPtrName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.UIntPtr); } else if (typeDefName == objectName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Object); } else if (typeDefName == singleName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Single); } else if (typeDefName == doubleName) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.Double); } else if (typeDefName == typedReference) { peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.TypedReference); } else if (typeDefName == enumName) { this.SystemEnum = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == valueTypeName) { this.SystemValueType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == multicastDelegateName) { this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == typeName) { this.SystemType = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == paramArrayAttributeName) { this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeDefinitionAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } } } } } else { uint numberOfTypeRefs = peFileReader.TypeRefTable.NumberOfRows; AssemblyReference /*?*/ coreAssemblyRef = peFileToObjectModel.FindAssemblyReference(peFileToObjectModel.CoreAssemblySymbolicIdentity); if (coreAssemblyRef == null) { // Error... coreAssemblyRef = new AssemblyReference(peFileToObjectModel, 1, peFileToObjectModel.CoreAssemblySymbolicIdentity, AssemblyFlags.Retargetable); } uint coreAssemblyRefToken = coreAssemblyRef.TokenValue; for (uint i = 1; i <= numberOfTypeRefs; ++i) { TypeRefRow typeRefRow = peFileReader.TypeRefTable[i]; if (typeRefRow.ResolutionScope != coreAssemblyRefToken) { continue; } int namespaceName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Namespace).UniqueKey; if (namespaceName == systemName) { int typeDefName = peFileToObjectModel.GetNameFromOffset(typeRefRow.Name).UniqueKey; if (typeDefName == voidName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Void); } else if (typeDefName == booleanName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Boolean); } else if (typeDefName == charName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Char); } else if (typeDefName == byteName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Byte); } else if (typeDefName == sByteName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.SByte); } else if (typeDefName == int16Name) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Int16); } else if (typeDefName == uint16Name) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt16); } else if (typeDefName == int32Name) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Int32); } else if (typeDefName == uint32Name) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt32); } else if (typeDefName == int64Name) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Int64); } else if (typeDefName == uint64Name) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UInt64); } else if (typeDefName == stringName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.String); } else if (typeDefName == intPtrName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.IntPtr); } else if (typeDefName == uintPtrName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.UIntPtr); } else if (typeDefName == objectName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Object); } else if (typeDefName == singleName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Single); } else if (typeDefName == doubleName) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.Double); } else if (typeDefName == typedReference) { peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.TypedReference); } else if (typeDefName == enumName) { this.SystemEnum = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == valueTypeName) { this.SystemValueType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == multicastDelegateName) { this.SystemMulticastDelegate = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == typeName) { this.SystemType = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } else if (typeDefName == paramArrayAttributeName) { this.SystemParamArrayAttribute = peFileToObjectModel.GetPredefinedTypeRefReferenceAtRowWorker(i, MetadataReaderSignatureTypeCode.NotModulePrimitive); } } } NamespaceReference systemNSR = peFileToObjectModel.GetNamespaceReferenceForString(coreAssemblyRef, nameTable.System); if (this.SystemEnum == null || (peFileToObjectModel.SystemEnumAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemEnumAssembly)) { this.SystemEnum = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemEnumAssembly ?? coreAssemblyRef, systemNSR, nameTable.Enum, MetadataReaderSignatureTypeCode.NotModulePrimitive); } if (this.SystemValueType == null || (peFileToObjectModel.SystemValueTypeAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemValueTypeAssembly)) { this.SystemValueType = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemValueTypeAssembly ?? coreAssemblyRef, systemNSR, nameTable.ValueType, MetadataReaderSignatureTypeCode.NotModulePrimitive); } if (this.SystemMulticastDelegate == null || (peFileToObjectModel.SystemMulticastDelegateAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemMulticastDelegateAssembly)) { this.SystemMulticastDelegate = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemMulticastDelegateAssembly ?? coreAssemblyRef, systemNSR, nameTable.MulticastDelegate, MetadataReaderSignatureTypeCode.NotModulePrimitive); } if (this.SystemType == null || (peFileToObjectModel.SystemTypeAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemTypeAssembly)) { this.SystemType = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemTypeAssembly ?? coreAssemblyRef, systemNSR, nameTable.Type, MetadataReaderSignatureTypeCode.NotModulePrimitive); } if (this.SystemParamArrayAttribute == null || (peFileToObjectModel.SystemParamArrayAttributeAssembly != null && coreAssemblyRef != peFileToObjectModel.SystemParamArrayAttributeAssembly)) { this.SystemParamArrayAttribute = peFileToObjectModel.typeCache.CreateCoreTypeReference(peFileToObjectModel.SystemParamArrayAttributeAssembly ?? coreAssemblyRef, systemNSR, peReader.ParamArrayAttribute, MetadataReaderSignatureTypeCode.NotModulePrimitive); } } }