/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ASTImporterSharedState.h
Line | Count | Source |
1 | | //===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file defines the ASTImporter specific state, which may be shared |
10 | | // amongst several ASTImporter objects. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H |
15 | | #define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H |
16 | | |
17 | | #include "clang/AST/ASTImportError.h" |
18 | | #include "clang/AST/ASTImporterLookupTable.h" |
19 | | #include "clang/AST/Decl.h" |
20 | | #include "llvm/ADT/DenseMap.h" |
21 | | |
22 | | namespace clang { |
23 | | |
24 | | class TranslationUnitDecl; |
25 | | |
26 | | /// Importer specific state, which may be shared amongst several ASTImporter |
27 | | /// objects. |
28 | | class ASTImporterSharedState { |
29 | | |
30 | | /// Pointer to the import specific lookup table. |
31 | | std::unique_ptr<ASTImporterLookupTable> LookupTable; |
32 | | |
33 | | /// Mapping from the already-imported declarations in the "to" |
34 | | /// context to the error status of the import of that declaration. |
35 | | /// This map contains only the declarations that were not correctly |
36 | | /// imported. The same declaration may or may not be included in |
37 | | /// ImportedFromDecls. This map is updated continuously during imports and |
38 | | /// never cleared (like ImportedFromDecls). |
39 | | llvm::DenseMap<Decl *, ASTImportError> ImportErrors; |
40 | | |
41 | | /// Set of the newly created declarations. |
42 | | llvm::DenseSet<Decl *> NewDecls; |
43 | | |
44 | | // FIXME put ImportedFromDecls here! |
45 | | // And from that point we can better encapsulate the lookup table. |
46 | | |
47 | | public: |
48 | 19.9k | ASTImporterSharedState() = default; |
49 | | |
50 | 2.36k | ASTImporterSharedState(TranslationUnitDecl &ToTU) { |
51 | 2.36k | LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU); |
52 | 2.36k | } |
53 | | |
54 | 3.96M | ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); } |
55 | | |
56 | 5.04M | void addDeclToLookup(Decl *D) { |
57 | 5.04M | if (LookupTable) |
58 | 16.5k | if (auto *ND = dyn_cast<NamedDecl>(D)) |
59 | 16.3k | LookupTable->add(ND); |
60 | 5.04M | } |
61 | | |
62 | 120 | void removeDeclFromLookup(Decl *D) { |
63 | 120 | if (LookupTable) |
64 | 89 | if (auto *ND = dyn_cast<NamedDecl>(D)) |
65 | 89 | LookupTable->remove(ND); |
66 | 120 | } |
67 | | |
68 | 22.3M | llvm::Optional<ASTImportError> getImportDeclErrorIfAny(Decl *ToD) const { |
69 | 22.3M | auto Pos = ImportErrors.find(ToD); |
70 | 22.3M | if (Pos != ImportErrors.end()) |
71 | 8 | return Pos->second; |
72 | 22.3M | else |
73 | 22.3M | return Optional<ASTImportError>(); |
74 | 22.3M | } |
75 | | |
76 | 292 | void setImportDeclError(Decl *To, ASTImportError Error) { |
77 | 292 | ImportErrors[To] = Error; |
78 | 292 | } |
79 | | |
80 | 198 | bool isNewDecl(const Decl *ToD) const { return NewDecls.count(ToD); } |
81 | | |
82 | 4.58M | void markAsNewDecl(Decl *ToD) { NewDecls.insert(ToD); } |
83 | | }; |
84 | | |
85 | | } // namespace clang |
86 | | #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H |