ASTImporterSharedState.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ASTImporter specific state, which may be shared
  15. // amongst several ASTImporter objects.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
  19. #define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
  20. #include "clang/AST/ASTImporterLookupTable.h"
  21. #include "clang/AST/Decl.h"
  22. #include "llvm/ADT/DenseMap.h"
  23. // FIXME We need this because of ImportError.
  24. #include "clang/AST/ASTImporter.h"
  25. namespace clang {
  26. class TranslationUnitDecl;
  27. /// Importer specific state, which may be shared amongst several ASTImporter
  28. /// objects.
  29. class ASTImporterSharedState {
  30. /// Pointer to the import specific lookup table.
  31. std::unique_ptr<ASTImporterLookupTable> LookupTable;
  32. /// Mapping from the already-imported declarations in the "to"
  33. /// context to the error status of the import of that declaration.
  34. /// This map contains only the declarations that were not correctly
  35. /// imported. The same declaration may or may not be included in
  36. /// ImportedFromDecls. This map is updated continuously during imports and
  37. /// never cleared (like ImportedFromDecls).
  38. llvm::DenseMap<Decl *, ImportError> ImportErrors;
  39. // FIXME put ImportedFromDecls here!
  40. // And from that point we can better encapsulate the lookup table.
  41. public:
  42. ASTImporterSharedState() = default;
  43. ASTImporterSharedState(TranslationUnitDecl &ToTU) {
  44. LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
  45. }
  46. ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
  47. void addDeclToLookup(Decl *D) {
  48. if (LookupTable)
  49. if (auto *ND = dyn_cast<NamedDecl>(D))
  50. LookupTable->add(ND);
  51. }
  52. void removeDeclFromLookup(Decl *D) {
  53. if (LookupTable)
  54. if (auto *ND = dyn_cast<NamedDecl>(D))
  55. LookupTable->remove(ND);
  56. }
  57. llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
  58. auto Pos = ImportErrors.find(ToD);
  59. if (Pos != ImportErrors.end())
  60. return Pos->second;
  61. else
  62. return Optional<ImportError>();
  63. }
  64. void setImportDeclError(Decl *To, ImportError Error) {
  65. ImportErrors[To] = Error;
  66. }
  67. };
  68. } // namespace clang
  69. #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
  70. #ifdef __GNUC__
  71. #pragma GCC diagnostic pop
  72. #endif