コード例 #1
0
 public ImportScopeEntry(PEFile module, MetadataReader metadata, bool isEmbedded, ImportScopeHandle handle)
 {
     this.offset = isEmbedded ? null : (int?)metadata.GetTableMetadataOffset(TableIndex.ImportScope)
                   + metadata.GetTableRowSize(TableIndex.ImportScope) * (MetadataTokens.GetRowNumber(handle) - 1);
     this.module     = module;
     this.metadata   = metadata;
     this.handle     = handle;
     this.localScope = metadata.GetImportScope(handle);
 }
コード例 #2
0
        private static void PopulateImports(
            MetadataReader reader,
            ImportScopeHandle handle,
            EESymbolProvider <TTypeSymbol, TLocalSymbol> symbolProvider,
            bool isVisualBasicMethod,
            ArrayBuilder <ImmutableArray <ImportRecord> > importGroupsBuilder,
            ArrayBuilder <ExternAliasRecord> externAliasesBuilder
            )
        {
            var importGroupBuilder = ArrayBuilder <ImportRecord> .GetInstance();

            while (!handle.IsNil)
            {
                var importScope = reader.GetImportScope(handle);

                try
                {
                    PopulateImports(
                        reader,
                        importScope,
                        symbolProvider,
                        importGroupBuilder,
                        externAliasesBuilder
                        );
                }
                catch (BadImageFormatException)
                {
                    // ignore invalid imports
                }

                // Portable PDBs represent project-level scope as the root of the chain of scopes.
                // This scope might contain aliases for assembly references, but is not considered
                // to be part of imports groups.
                if (isVisualBasicMethod || !importScope.Parent.IsNil)
                {
                    importGroupsBuilder.Add(importGroupBuilder.ToImmutable());
                    importGroupBuilder.Clear();
                }
                else
                {
                    // C# currently doesn't support global imports in PDBs
                    // https://github.com/dotnet/roslyn/issues/21862
                    Debug.Assert(importGroupBuilder.Count == 0);
                }

                handle = importScope.Parent;
            }

            importGroupBuilder.Free();
        }
コード例 #3
0
        private static void PopulateImports(
            MetadataReader reader,
            ImportScopeHandle handle,
            EESymbolProvider <TTypeSymbol, TLocalSymbol> symbolProvider,
            bool isVisualBasicMethod,
            ArrayBuilder <ImmutableArray <ImportRecord> > importGroupsBuilder,
            ArrayBuilder <ExternAliasRecord> externAliasesBuilder)
        {
            var importGroupBuilder = ArrayBuilder <ImportRecord> .GetInstance();

            while (!handle.IsNil)
            {
                var importScope = reader.GetImportScope(handle);

                try
                {
                    PopulateImports(reader, importScope, symbolProvider, importGroupBuilder, externAliasesBuilder);
                }
                catch (BadImageFormatException)
                {
                    // ignore invalid imports
                }

                // VB always expects two import groups (even if they are empty).
                // TODO: consider doing this for C# as well and handle empty groups in the binder.
                if (isVisualBasicMethod || importGroupBuilder.Count > 0)
                {
                    importGroupsBuilder.Add(importGroupBuilder.ToImmutable());
                    importGroupBuilder.Clear();
                }

                handle = importScope.Parent;
            }

            importGroupBuilder.Free();
        }
コード例 #4
0
        /// <exception cref="BadImageFormatException">Invalid data format.</exception>
        private static void PopulateImports(
            MetadataReader reader,
            ImportScopeHandle handle,
            EESymbolProvider <TTypeSymbol, TLocalSymbol> symbolProvider,
            bool isVisualBasicMethod,
            ArrayBuilder <ImmutableArray <ImportRecord> > importGroupsBuilder,
            ArrayBuilder <ExternAliasRecord> externAliasesBuilder)
        {
            var importGroupBuilder = ArrayBuilder <ImportRecord> .GetInstance();

            while (!handle.IsNil)
            {
                var importScope = reader.GetImportScope(handle);

                foreach (ImportDefinition import in importScope.GetImports())
                {
                    switch (import.Kind)
                    {
                    case ImportDefinitionKind.ImportNamespace:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Namespace,
                                                   targetString: ReadUtf8String(reader, import.TargetNamespace)));
                        break;

                    case ImportDefinitionKind.ImportAssemblyNamespace:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Namespace,
                                                   targetString: ReadUtf8String(reader, import.TargetNamespace),
                                                   targetAssembly: symbolProvider.GetReferencedAssembly(import.TargetAssembly)));
                        break;

                    case ImportDefinitionKind.ImportType:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Type,
                                                   targetType: symbolProvider.GetType(import.TargetType)));
                        break;

                    case ImportDefinitionKind.ImportXmlNamespace:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.XmlNamespace,
                                                   alias: ReadUtf8String(reader, import.Alias),
                                                   targetString: ReadUtf8String(reader, import.TargetNamespace)));
                        break;

                    case ImportDefinitionKind.ImportAssemblyReferenceAlias:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Assembly,
                                                   alias: ReadUtf8String(reader, import.Alias)));
                        break;

                    case ImportDefinitionKind.AliasAssemblyReference:
                        externAliasesBuilder.Add(new ExternAliasRecord(
                                                     alias: ReadUtf8String(reader, import.Alias),
                                                     targetAssembly: symbolProvider.GetReferencedAssembly(import.TargetAssembly)));
                        break;

                    case ImportDefinitionKind.AliasNamespace:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Namespace,
                                                   alias: ReadUtf8String(reader, import.Alias),
                                                   targetString: ReadUtf8String(reader, import.TargetNamespace)));
                        break;

                    case ImportDefinitionKind.AliasAssemblyNamespace:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Namespace,
                                                   alias: ReadUtf8String(reader, import.Alias),
                                                   targetString: ReadUtf8String(reader, import.TargetNamespace),
                                                   targetAssembly: symbolProvider.GetReferencedAssembly(import.TargetAssembly)));
                        break;

                    case ImportDefinitionKind.AliasType:
                        importGroupBuilder.Add(new ImportRecord(
                                                   ImportTargetKind.Type,
                                                   alias: ReadUtf8String(reader, import.Alias),
                                                   targetType: symbolProvider.GetType(import.TargetType)));
                        break;
                    }
                }

                // VB always expects two import groups (even if they are empty).
                // TODO: consider doing this for C# as well and handle empty groups in the binder.
                if (isVisualBasicMethod || importGroupBuilder.Count > 0)
                {
                    importGroupsBuilder.Add(importGroupBuilder.ToImmutable());
                    importGroupBuilder.Clear();
                }

                handle = importScope.Parent;
            }

            importGroupBuilder.Free();
        }
コード例 #5
0
 public static ImportScope GetImportScope(this ImportScopeHandle handle, MetadataReader reader) => reader.GetImportScope(handle);