clang  15.0.0git
ASTImporterSharedState.h
Go to the documentation of this file.
1 //===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ASTImporter specific state, which may be shared
10 // amongst several ASTImporter objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
15 #define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
16 
19 #include "clang/AST/Decl.h"
20 #include "llvm/ADT/DenseMap.h"
21 
22 namespace clang {
23 
24 class TranslationUnitDecl;
25 
26 /// Importer specific state, which may be shared amongst several ASTImporter
27 /// objects.
29 
30  /// Pointer to the import specific lookup table.
31  std::unique_ptr<ASTImporterLookupTable> LookupTable;
32 
33  /// Mapping from the already-imported declarations in the "to"
34  /// context to the error status of the import of that declaration.
35  /// This map contains only the declarations that were not correctly
36  /// imported. The same declaration may or may not be included in
37  /// ImportedFromDecls. This map is updated continuously during imports and
38  /// never cleared (like ImportedFromDecls).
39  llvm::DenseMap<Decl *, ASTImportError> ImportErrors;
40 
41  /// Set of the newly created declarations.
42  llvm::DenseSet<Decl *> NewDecls;
43 
44  // FIXME put ImportedFromDecls here!
45  // And from that point we can better encapsulate the lookup table.
46 
47 public:
48  ASTImporterSharedState() = default;
49 
51  LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
52  }
53 
54  ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
55 
56  void addDeclToLookup(Decl *D) {
57  if (LookupTable)
58  if (auto *ND = dyn_cast<NamedDecl>(D))
59  LookupTable->add(ND);
60  }
61 
63  if (LookupTable)
64  if (auto *ND = dyn_cast<NamedDecl>(D))
65  LookupTable->remove(ND);
66  }
67 
69  auto Pos = ImportErrors.find(ToD);
70  if (Pos != ImportErrors.end())
71  return Pos->second;
72  else
73  return Optional<ASTImportError>();
74  }
75 
77  ImportErrors[To] = Error;
78  }
79 
80  bool isNewDecl(const Decl *ToD) const { return NewDecls.count(ToD); }
81 
82  void markAsNewDecl(Decl *ToD) { NewDecls.insert(ToD); }
83 };
84 
85 } // namespace clang
86 #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
ASTImportError.h
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:20
clang::ASTImporterSharedState::getImportDeclErrorIfAny
llvm::Optional< ASTImportError > getImportDeclErrorIfAny(Decl *ToD) const
Definition: ASTImporterSharedState.h:68
clang::ASTImporterSharedState::isNewDecl
bool isNewDecl(const Decl *ToD) const
Definition: ASTImporterSharedState.h:80
clang::ASTImporterSharedState::ASTImporterSharedState
ASTImporterSharedState(TranslationUnitDecl &ToTU)
Definition: ASTImporterSharedState.h:50
llvm::Optional
Definition: LLVM.h:40
clang::ASTImporterSharedState::addDeclToLookup
void addDeclToLookup(Decl *D)
Definition: ASTImporterSharedState.h:56
Decl.h
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:80
clang::ASTImporterSharedState::setImportDeclError
void setImportDeclError(Decl *To, ASTImportError Error)
Definition: ASTImporterSharedState.h:76
clang::ASTImporterSharedState::getLookupTable
ASTImporterLookupTable * getLookupTable()
Definition: ASTImporterSharedState.h:54
clang::ASTImporterSharedState
Importer specific state, which may be shared amongst several ASTImporter objects.
Definition: ASTImporterSharedState.h:28
llvm::DenseSet
Definition: Sema.h:77
clang::ASTImporterLookupTable
Definition: ASTImporterLookupTable.h:46
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang
Definition: CalledOnceCheck.h:17
clang::ASTImporterSharedState::removeDeclFromLookup
void removeDeclFromLookup(Decl *D)
Definition: ASTImporterSharedState.h:62
ASTImporterLookupTable.h
clang::ASTImportError
Definition: ASTImportError.h:21
clang::ASTImporterSharedState::markAsNewDecl
void markAsNewDecl(Decl *ToD)
Definition: ASTImporterSharedState.h:82
clang::ASTImporterSharedState::ASTImporterSharedState
ASTImporterSharedState()=default