clang 10.0.0git

ASTImporterSharedState.h
Go to the documentation of this file.
1 //===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the ASTImporter specific state, which may be shared
11 // amongst several ASTImporter objects.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
16 #define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
17
18 #include "clang/AST/ASTImporterLookupTable.h"
19 #include "clang/AST/Decl.h"
20 #include "llvm/ADT/DenseMap.h"
21 // FIXME We need this because of ImportError.
22 #include "clang/AST/ASTImporter.h"
23
24 namespace clang {
25
26 class TranslationUnitDecl;
27
28 /// Importer specific state, which may be shared amongst several ASTImporter
29 /// objects.
30 class ASTImporterSharedState {
31
32 /// Pointer to the import specific lookup table.
33 std::unique_ptr<ASTImporterLookupTable> LookupTable;
34
35 /// Mapping from the already-imported declarations in the "to"
36 /// context to the error status of the import of that declaration.
37 /// This map contains only the declarations that were not correctly
38 /// imported. The same declaration may or may not be included in
39 /// ImportedFromDecls. This map is updated continuously during imports and
40 /// never cleared (like ImportedFromDecls).
41 llvm::DenseMap<Decl *, ImportError> ImportErrors;
42
43 // FIXME put ImportedFromDecls here!
44 // And from that point we can better encapsulate the lookup table.
45
46 public:
47 ASTImporterSharedState() = default;
48
49 ASTImporterSharedState(TranslationUnitDecl &ToTU) {
50 LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
51 }
52
53 ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
54
55 void addDeclToLookup(Decl *D) {
56 if (LookupTable)
57 if (auto *ND = dyn_cast<NamedDecl>(D))
58 LookupTable->add(ND);
59 }
60
61 void removeDeclFromLookup(Decl *D) {
62 if (LookupTable)
63 if (auto *ND = dyn_cast<NamedDecl>(D))
64 LookupTable->remove(ND);
65 }
66
67 llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
68 auto Pos = ImportErrors.find(ToD);
69 if (Pos != ImportErrors.end())
70 return Pos->second;
71 else
72 return Optional<ImportError>();
73 }
74
75 void setImportDeclError(Decl *To, ImportError Error) {
76 ImportErrors[To] = Error;
77 }
78 };
79
80 } // namespace clang
81 #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
llvm::Optional
Definition: LLVM.h:37
clang::ASTImporterSharedState
Importer specific state, which may be shared amongst several ASTImporter objects. ...
Definition: ASTImporterSharedState.h:30
clang::ASTImporterSharedState::ASTImporterSharedState
ASTImporterSharedState(TranslationUnitDecl &ToTU)
Definition: ASTImporterSharedState.h:49
clang::ImportError
Definition: ASTImporter.h:50
clang::ASTImporterSharedState::getLookupTable
ASTImporterLookupTable * getLookupTable()
Definition: ASTImporterSharedState.h:53
clang::ASTImporterSharedState::ASTImporterSharedState
ASTImporterSharedState()=default
ASTImporterLookupTable.h
clang::DiagnosticLevelMask::Error
Decl.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::ASTImporterSharedState::addDeclToLookup
void addDeclToLookup(Decl *D)
Definition: ASTImporterSharedState.h:55
ASTImporter.h
clang::ASTImporterLookupTable
Definition: ASTImporterLookupTable.h:47
clang::ASTImporterSharedState::setImportDeclError
void setImportDeclError(Decl *To, ImportError Error)
Definition: ASTImporterSharedState.h:75
clang::ASTImporterSharedState::removeDeclFromLookup
void removeDeclFromLookup(Decl *D)
Definition: ASTImporterSharedState.h:61
clang::ASTImporterSharedState::getImportDeclErrorIfAny
llvm::Optional< ImportError > getImportDeclErrorIfAny(Decl *ToD) const
Definition: ASTImporterSharedState.h:67
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82