clang  14.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 
18 #include "clang/AST/Decl.h"
19 #include "llvm/ADT/DenseMap.h"
20 // FIXME We need this because of ImportError.
21 #include "clang/AST/ASTImporter.h"
22 
23 namespace clang {
24 
25 class TranslationUnitDecl;
26 
27 /// Importer specific state, which may be shared amongst several ASTImporter
28 /// objects.
30 
31  /// Pointer to the import specific lookup table.
32  std::unique_ptr<ASTImporterLookupTable> LookupTable;
33 
34  /// Mapping from the already-imported declarations in the "to"
35  /// context to the error status of the import of that declaration.
36  /// This map contains only the declarations that were not correctly
37  /// imported. The same declaration may or may not be included in
38  /// ImportedFromDecls. This map is updated continuously during imports and
39  /// never cleared (like ImportedFromDecls).
40  llvm::DenseMap<Decl *, ImportError> ImportErrors;
41 
42  // FIXME put ImportedFromDecls here!
43  // And from that point we can better encapsulate the lookup table.
44 
45 public:
46  ASTImporterSharedState() = default;
47 
49  LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
50  }
51 
52  ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
53 
54  void addDeclToLookup(Decl *D) {
55  if (LookupTable)
56  if (auto *ND = dyn_cast<NamedDecl>(D))
57  LookupTable->add(ND);
58  }
59 
61  if (LookupTable)
62  if (auto *ND = dyn_cast<NamedDecl>(D))
63  LookupTable->remove(ND);
64  }
65 
67  auto Pos = ImportErrors.find(ToD);
68  if (Pos != ImportErrors.end())
69  return Pos->second;
70  else
71  return Optional<ImportError>();
72  }
73 
74  void setImportDeclError(Decl *To, ImportError Error) {
75  ImportErrors[To] = Error;
76  }
77 };
78 
79 } // namespace clang
80 #endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:20
clang::ASTImporterSharedState::ASTImporterSharedState
ASTImporterSharedState(TranslationUnitDecl &ToTU)
Definition: ASTImporterSharedState.h:48
llvm::Optional
Definition: LLVM.h:40
clang::ASTImporterSharedState::addDeclToLookup
void addDeclToLookup(Decl *D)
Definition: ASTImporterSharedState.h:54
Decl.h
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82
clang::ASTImporterSharedState::getLookupTable
ASTImporterLookupTable * getLookupTable()
Definition: ASTImporterSharedState.h:52
clang::ASTImporterSharedState
Importer specific state, which may be shared amongst several ASTImporter objects.
Definition: ASTImporterSharedState.h:29
clang::ASTImporterLookupTable
Definition: ASTImporterLookupTable.h:47
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
ASTImporter.h
clang
Definition: CalledOnceCheck.h:17
clang::ASTImporterSharedState::setImportDeclError
void setImportDeclError(Decl *To, ImportError Error)
Definition: ASTImporterSharedState.h:74
clang::ASTImporterSharedState::removeDeclFromLookup
void removeDeclFromLookup(Decl *D)
Definition: ASTImporterSharedState.h:60
ASTImporterLookupTable.h
clang::ASTImporterSharedState::getImportDeclErrorIfAny
llvm::Optional< ImportError > getImportDeclErrorIfAny(Decl *ToD) const
Definition: ASTImporterSharedState.h:66
clang::ImportError
Definition: ASTImporter.h:52
clang::ASTImporterSharedState::ASTImporterSharedState
ASTImporterSharedState()=default