internal PEAssemblySymbol(PEAssembly assembly, DocumentationProvider documentationProvider, bool isLinked, MetadataImportOptions importOptions) { Debug.Assert(assembly != null); Debug.Assert(documentationProvider != null); _assembly = assembly; _documentationProvider = documentationProvider; var modules = new ModuleSymbol[assembly.Modules.Length]; for (int i = 0; i < assembly.Modules.Length; i++) { modules[i] = new PEModuleSymbol(this, assembly.Modules[i], importOptions, i); } _modules = modules.AsImmutableOrNull(); _isLinked = isLinked; }
internal PEAssemblySymbol(PEAssembly assembly, DocumentationProvider documentationProvider, bool isLinked, MetadataImportOptions importOptions) { Debug.Assert(assembly != null); Debug.Assert(documentationProvider != null); this.assembly = assembly; this.documentationProvider = documentationProvider; var modules = new ModuleSymbol[assembly.Modules.Length]; for (int i = 0; i < assembly.Modules.Length; i++) { modules[i] = new PEModuleSymbol(this, assembly.Modules[i], importOptions, i); } this.modules = modules.AsImmutableOrNull(); this.isLinked = isLinked; }
internal PEAssemblySymbol(PEAssembly assembly, DocumentationProvider documentationProvider, string filePath, bool isLinked, MetadataImportOptions importOptions) { Debug.Assert(assembly != null); Debug.Assert(documentationProvider != null); _assembly = assembly; _documentationProvider = documentationProvider; _filePath = filePath; var modules = new ModuleSymbol[assembly.Modules.Length]; for (int i = 0; i < assembly.Modules.Length; i++) { modules[i] = new PEModuleSymbol(this, assembly.Modules[i], importOptions, i); } _modules = modules.AsImmutableOrNull(); _isLinked = isLinked; if (IsPchpCor(assembly)) { _specialAssembly = SpecialAssembly.PchpCorLibrary; // initialize CoreTypes this.PrimaryModule.GlobalNamespace.GetTypeMembers(); } else if (assembly.Identity.Name == "System.Runtime") { _specialAssembly = SpecialAssembly.CorLibrary; } else if (assembly.AssemblyReferences.Length == 0 && assembly.DeclaresTheObjectClass) { _specialAssembly = SpecialAssembly.CorLibrary; } else { // extension assembly ? //var attrs = this.GetAttributes(); } }
internal static MetadataReader GetMetadataReader(this PEAssembly assembly) { return(assembly.ManifestModule.MetadataReader); }
internal static PEAssemblySymbol Create(PortableExecutableReference reference, PEAssembly ass = null) { if (ass == null) { ass = ((AssemblyMetadata)reference.GetMetadata()).GetAssembly(); } return(new PEAssemblySymbol( ass, reference.DocumentationProvider, reference.FilePath, true, IsPchpCor(ass) ? MetadataImportOptions.Internal : MetadataImportOptions.Public)); }
internal static bool IsPchpCor(PEAssembly ass) => ass.Identity.Name == "Peachpie.Runtime";
/// <summary> /// Used to validate metadata blobs emitted for MarshalAs. /// </summary> internal static void MarshalAsMetadataValidator(PEAssembly assembly, Func <string, PEAssembly, TestEmitters, byte[]> getExpectedBlob, TestEmitters emitOptions, bool isField = true) { var metadataReader = assembly.GetMetadataReader(); // no custom attributes should be emitted on parameters, fields or methods: foreach (var ca in metadataReader.CustomAttributes) { Assert.NotEqual("MarshalAsAttribute", GetAttributeName(metadataReader, ca)); } int expectedMarshalCount = 0; if (isField) { // fields foreach (var fieldDef in metadataReader.FieldDefinitions) { var field = metadataReader.GetFieldDefinition(fieldDef); string fieldName = metadataReader.GetString(field.Name); byte[] expectedBlob = getExpectedBlob(fieldName, assembly, emitOptions); if (expectedBlob != null) { BlobHandle descriptor = metadataReader.GetFieldDefinition(fieldDef).GetMarshallingDescriptor(); Assert.False(descriptor.IsNil, "Expecting record in FieldMarshal table"); Assert.NotEqual(0, (int)(field.Attributes & FieldAttributes.HasFieldMarshal)); expectedMarshalCount++; byte[] actualBlob = metadataReader.GetBlobBytes(descriptor); AssertEx.Equal(expectedBlob, actualBlob); } else { Assert.Equal(0, (int)(field.Attributes & FieldAttributes.HasFieldMarshal)); } } } else { // parameters foreach (var methodHandle in metadataReader.MethodDefinitions) { var methodDef = metadataReader.GetMethodDefinition(methodHandle); string memberName = metadataReader.GetString(methodDef.Name); foreach (var paramHandle in methodDef.GetParameters()) { var paramRow = metadataReader.GetParameter(paramHandle); string paramName = metadataReader.GetString(paramRow.Name); byte[] expectedBlob = getExpectedBlob(memberName + ":" + paramName, assembly, emitOptions); if (expectedBlob != null) { Assert.NotEqual(0, (int)(paramRow.Attributes & ParameterAttributes.HasFieldMarshal)); expectedMarshalCount++; BlobHandle descriptor = metadataReader.GetParameter(paramHandle).GetMarshallingDescriptor(); Assert.False(descriptor.IsNil, "Expecting record in FieldMarshal table"); byte[] actualBlob = metadataReader.GetBlobBytes(descriptor); AssertEx.Equal(expectedBlob, actualBlob); } else { Assert.Equal(0, (int)(paramRow.Attributes & ParameterAttributes.HasFieldMarshal)); } } } } Assert.Equal(expectedMarshalCount, metadataReader.GetTableRowCount(TableIndex.FieldMarshal)); }
internal static bool IsPchpCor(PEAssembly ass) => ass.Identity.Name == "pchpcor";