clang: lib/AST/ASTImporterLookupTable.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
17#include "llvm/Support/FormatVariadic.h"
18
20
21namespace {
22
24 ASTImporterLookupTable <
25 Builder(ASTImporterLookupTable <) : LT(LT) {}
26
27 bool VisitTypedefNameDecl(TypedefNameDecl *D) {
28 QualType Ty = D->getUnderlyingType();
29 Ty = Ty.getCanonicalType();
30 if (const auto *RTy = dyn_cast(Ty)) {
31 LT.add(RTy->getAsRecordDecl());
32
33 for (auto *it : RTy->getAsRecordDecl()->fields()) {
34 LT.add(it);
35 }
36 }
37 return true;
38 }
39
40 bool VisitNamedDecl(NamedDecl *D) {
41 LT.add(D);
42 return true;
43 }
44
45
46
47
48
49 bool VisitFriendDecl(FriendDecl *D) {
50 if (D->getFriendType()) {
51 QualType Ty = D->getFriendType()->getType();
52
53
54
55
56 if (!Ty->isDependentType()) {
57 if (const auto *RTy = dyn_cast(Ty))
58 LT.add(RTy->getAsCXXRecordDecl());
59 else if (const auto *SpecTy = dyn_cast(Ty))
60 LT.add(SpecTy->getAsCXXRecordDecl());
61 else if (const auto *SubstTy =
62 dyn_cast(Ty)) {
63 if (SubstTy->getAsCXXRecordDecl())
64 LT.add(SubstTy->getAsCXXRecordDecl());
65 } else {
67
68
70
71 } else {
72 llvm_unreachable("Unhandled type of friend class");
73 }
74 }
75 }
76 }
77 return true;
78 }
79
80
81 bool shouldVisitTemplateInstantiations() const { return true; }
82 bool shouldVisitImplicitCode() const { return true; }
83};
84
85}
86
88 Builder B(*this);
89 B.TraverseDecl(&TU);
90
91
92 if (auto *D =
94
95
96
97
98 if (auto *Ns = dyn_cast(D->getDeclContext()))
99 add(&TU, Ns);
100 add(D->getDeclContext(), D);
101 }
102}
103
105 DeclList &Decls = LookupTable[DC][ND->getDeclName()];
106
107 Decls.insert(ND);
108}
109
110void ASTImporterLookupTable::remove(DeclContext *DC, NamedDecl *ND) {
111 const DeclarationName Name = ND->getDeclName();
112 DeclList &Decls = LookupTable[DC][Name];
113 bool EraseResult = Decls.remove(ND);
114 (void)EraseResult;
115#ifndef NDEBUG
116 if (!EraseResult) {
117 std::string Message =
118 llvm::formatv(
119 "Trying to remove not contained Decl '{0}' of type {1} from a {2}",
120 Name.getAsString(), ND->getDeclKindName(), DC->getDeclKindName())
121 .str();
122 llvm_unreachable(Message.c_str());
123 }
124#endif
125}
126
127void ASTImporterLookupTable::add(NamedDecl *ND) {
128 assert(ND);
130 add(DC, ND);
132 if (DC != ReDC)
133 add(ReDC, ND);
134}
135
136void ASTImporterLookupTable::remove(NamedDecl *ND) {
137 assert(ND);
139 remove(DC, ND);
141 if (DC != ReDC)
142 remove(ReDC, ND);
143}
144
147 "DeclContext should be changed before update");
149 assert((OldDC, ND) &&
150 "Decl should not be found in the old context if already in the new");
151 return;
152 }
153
154 remove(OldDC, ND);
155 add(ND);
156}
157
159 LookupTable[OldDC][ND->getDeclName()].remove(ND);
160 add(ND);
161}
162
165 auto DCI = LookupTable.find(DC);
166 if (DCI == LookupTable.end())
167 return {};
168
169 const auto &FoundNameMap = DCI->second;
170 auto NamesI = FoundNameMap.find(Name);
171 if (NamesI == FoundNameMap.end())
172 return {};
173
174 return NamesI->second;
175}
176
180
182 auto DCI = LookupTable.find(DC);
183 if (DCI == LookupTable.end())
184 llvm::errs() << "empty\n";
185 const auto &FoundNameMap = DCI->second;
186 for (const auto &Entry : FoundNameMap) {
188 llvm::errs() << "==== Name: ";
190 const DeclList& List = Entry.second;
192 ND->dump();
193 }
194 }
195}
196
198 for (const auto &Entry : LookupTable) {
200 llvm::errs() << "== DC:" << cast(DC) << "\n";
202 }
203}
204
205}
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
void dump() const
Definition ASTImporterLookupTable.cpp:197
void update(NamedDecl *ND, DeclContext *OldDC)
Definition ASTImporterLookupTable.cpp:145
LookupResult lookup(DeclContext *DC, DeclarationName Name) const
Definition ASTImporterLookupTable.cpp:164
void updateForced(NamedDecl *ND, DeclContext *OldDC)
Definition ASTImporterLookupTable.cpp:158
ASTImporterLookupTable(TranslationUnitDecl &TU)
Definition ASTImporterLookupTable.cpp:87
bool contains(DeclContext *DC, NamedDecl *ND) const
Definition ASTImporterLookupTable.cpp:177
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
DeclContext * getDeclContext()
The name of a declaration.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
The top declaration context.
ASTContext & getASTContext() const
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
U cast(CodeGen::Address addr)