clang 20.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#include <optional>
22
23namespace clang {
24
25class 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 *, ASTImportError> ImportErrors;
41
42 /// Set of the newly created declarations.
43 llvm::DenseSet<Decl *> NewDecls;
44
45 // FIXME put ImportedFromDecls here!
46 // And from that point we can better encapsulate the lookup table.
47
48public:
50
52 LookupTable = std::make_unique<ASTImporterLookupTable>(ToTU);
53 }
54
55 ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
56
58 if (LookupTable)
59 if (auto *ND = dyn_cast<NamedDecl>(D))
60 LookupTable->add(ND);
61 }
62
64 if (LookupTable)
65 if (auto *ND = dyn_cast<NamedDecl>(D))
66 LookupTable->remove(ND);
67 }
68
69 std::optional<ASTImportError> getImportDeclErrorIfAny(Decl *ToD) const {
70 auto Pos = ImportErrors.find(ToD);
71 if (Pos != ImportErrors.end())
72 return Pos->second;
73 else
74 return std::nullopt;
75 }
76
78 ImportErrors[To] = Error;
79 }
80
81 bool isNewDecl(const Decl *ToD) const { return NewDecls.count(ToD); }
82
83 void markAsNewDecl(Decl *ToD) { NewDecls.insert(ToD); }
84};
85
86} // namespace clang
87#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
const Decl * D
Importer specific state, which may be shared amongst several ASTImporter objects.
void setImportDeclError(Decl *To, ASTImportError Error)
ASTImporterSharedState(TranslationUnitDecl &ToTU)
ASTImporterLookupTable * getLookupTable()
bool isNewDecl(const Decl *ToD) const
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *ToD) const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
The top declaration context.
Definition: Decl.h:84
The JSON file list parser is used to communicate input to InstallAPI.