ASTImporterSharedState.h revision 360784
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 24namespace clang { 25 26class TranslationUnitDecl; 27 28/// Importer specific state, which may be shared amongst several ASTImporter 29/// objects. 30class 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 46public: 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 82