1 //===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ASTImporter specific state, which may be shared
11 // amongst several ASTImporter objects.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
16 #define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
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"
26 class TranslationUnitDecl;
28 /// Importer specific state, which may be shared amongst several ASTImporter
30 class ASTImporterSharedState {
32 /// Pointer to the import specific lookup table.
33 std::unique_ptr<ASTImporterLookupTable> LookupTable;
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;
43 // FIXME put ImportedFromDecls here!
44 // And from that point we can better encapsulate the lookup table.
47 ASTImporterSharedState() = default;
49 ASTImporterSharedState(TranslationUnitDecl &ToTU) {
50 LookupTable = llvm::make_unique<ASTImporterLookupTable>(ToTU);
53 ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
55 void addDeclToLookup(Decl *D) {
57 if (auto *ND = dyn_cast<NamedDecl>(D))
61 void removeDeclFromLookup(Decl *D) {
63 if (auto *ND = dyn_cast<NamedDecl>(D))
64 LookupTable->remove(ND);
67 llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
68 auto Pos = ImportErrors.find(ToD);
69 if (Pos != ImportErrors.end())
72 return Optional<ImportError>();
75 void setImportDeclError(Decl *To, ImportError Error) {
76 ImportErrors[To] = Error;
81 #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H