Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:28

0001 //===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the ASTImporter specific state, which may be shared
0010 //  amongst several ASTImporter objects.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
0015 #define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
0016 
0017 #include "clang/AST/ASTImportError.h"
0018 #include "clang/AST/ASTImporterLookupTable.h"
0019 #include "clang/AST/Decl.h"
0020 #include "llvm/ADT/DenseMap.h"
0021 #include <optional>
0022 
0023 namespace clang {
0024 
0025 class TranslationUnitDecl;
0026 
0027 /// Importer specific state, which may be shared amongst several ASTImporter
0028 /// objects.
0029 class ASTImporterSharedState {
0030 
0031   /// Pointer to the import specific lookup table.
0032   std::unique_ptr<ASTImporterLookupTable> LookupTable;
0033 
0034   /// Mapping from the already-imported declarations in the "to"
0035   /// context to the error status of the import of that declaration.
0036   /// This map contains only the declarations that were not correctly
0037   /// imported. The same declaration may or may not be included in
0038   /// ImportedFromDecls. This map is updated continuously during imports and
0039   /// never cleared (like ImportedFromDecls).
0040   llvm::DenseMap<Decl *, ASTImportError> ImportErrors;
0041 
0042   /// Set of the newly created declarations.
0043   llvm::DenseSet<Decl *> NewDecls;
0044 
0045   // FIXME put ImportedFromDecls here!
0046   // And from that point we can better encapsulate the lookup table.
0047 
0048 public:
0049   ASTImporterSharedState() = default;
0050 
0051   ASTImporterSharedState(TranslationUnitDecl &ToTU) {
0052     LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
0053   }
0054 
0055   ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
0056 
0057   void addDeclToLookup(Decl *D) {
0058     if (LookupTable)
0059       if (auto *ND = dyn_cast<NamedDecl>(D))
0060         LookupTable->add(ND);
0061   }
0062 
0063   void removeDeclFromLookup(Decl *D) {
0064     if (LookupTable)
0065       if (auto *ND = dyn_cast<NamedDecl>(D))
0066         LookupTable->remove(ND);
0067   }
0068 
0069   std::optional<ASTImportError> getImportDeclErrorIfAny(Decl *ToD) const {
0070     auto Pos = ImportErrors.find(ToD);
0071     if (Pos != ImportErrors.end())
0072       return Pos->second;
0073     else
0074       return std::nullopt;
0075   }
0076 
0077   void setImportDeclError(Decl *To, ASTImportError Error) {
0078     ImportErrors[To] = Error;
0079   }
0080 
0081   bool isNewDecl(const Decl *ToD) const { return NewDecls.count(ToD); }
0082 
0083   void markAsNewDecl(Decl *ToD) { NewDecls.insert(ToD); }
0084 };
0085 
0086 } // namespace clang
0087 #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H