/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/JSONNodeDumper.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include "clang/AST/JSONNodeDumper.h" |
2 | | #include "clang/Basic/SourceManager.h" |
3 | | #include "clang/Basic/Specifiers.h" |
4 | | #include "clang/Lex/Lexer.h" |
5 | | #include "llvm/ADT/StringSwitch.h" |
6 | | |
7 | | using namespace clang; |
8 | | |
9 | 2.05k | void JSONNodeDumper::addPreviousDeclaration(const Decl *D) { |
10 | 2.05k | switch (D->getKind()) { |
11 | 0 | #define DECL(DERIVED, BASE) \ |
12 | 2.05k | case Decl::DERIVED: \ |
13 | 2.05k | return writePreviousDeclImpl(cast<DERIVED##Decl>(D)); |
14 | 0 | #define ABSTRACT_DECL(DECL) |
15 | 2.05k | #include "clang/AST/DeclNodes.inc"0 |
16 | 2.05k | #undef ABSTRACT_DECL |
17 | 2.05k | #undef DECL |
18 | 2.05k | } |
19 | 0 | llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); |
20 | 0 | } |
21 | | |
22 | 35 | void JSONNodeDumper::Visit(const Attr *A) { |
23 | 35 | const char *AttrName = nullptr; |
24 | 35 | switch (A->getKind()) { |
25 | 0 | #define ATTR(X) \ |
26 | 35 | case attr::X: \ |
27 | 35 | AttrName = #X"Attr"; \ |
28 | 35 | break; |
29 | 35 | #include "clang/Basic/AttrList.inc"0 |
30 | 35 | #undef ATTR |
31 | 35 | } |
32 | 35 | JOS.attribute("id", createPointerRepresentation(A)); |
33 | 35 | JOS.attribute("kind", AttrName); |
34 | 35 | JOS.attributeObject("range", [A, this] { writeSourceRange(A->getRange()); }); |
35 | 35 | attributeOnlyIfTrue("inherited", A->isInherited()); |
36 | 35 | attributeOnlyIfTrue("implicit", A->isImplicit()); |
37 | | |
38 | | // FIXME: it would be useful for us to output the spelling kind as well as |
39 | | // the actual spelling. This would allow us to distinguish between the |
40 | | // various attribute syntaxes, but we don't currently track that information |
41 | | // within the AST. |
42 | | //JOS.attribute("spelling", A->getSpelling()); |
43 | | |
44 | 35 | InnerAttrVisitor::Visit(A); |
45 | 35 | } |
46 | | |
47 | 2.83k | void JSONNodeDumper::Visit(const Stmt *S) { |
48 | 2.83k | if (!S) |
49 | 37 | return; |
50 | | |
51 | 2.79k | JOS.attribute("id", createPointerRepresentation(S)); |
52 | 2.79k | JOS.attribute("kind", S->getStmtClassName()); |
53 | 2.79k | JOS.attributeObject("range", |
54 | 2.79k | [S, this] { writeSourceRange(S->getSourceRange()); }); |
55 | | |
56 | 2.79k | if (const auto *E = dyn_cast<Expr>(S)) { |
57 | 2.14k | JOS.attribute("type", createQualType(E->getType())); |
58 | 2.14k | const char *Category = nullptr; |
59 | 2.14k | switch (E->getValueKind()) { |
60 | 595 | case VK_LValue: Category = "lvalue"; break; |
61 | 4 | case VK_XValue: Category = "xvalue"; break; |
62 | 1.54k | case VK_PRValue: |
63 | 1.54k | Category = "prvalue"; |
64 | 1.54k | break; |
65 | 2.14k | } |
66 | 2.14k | JOS.attribute("valueCategory", Category); |
67 | 2.14k | } |
68 | 2.79k | InnerStmtVisitor::Visit(S); |
69 | 2.79k | } |
70 | | |
71 | 495 | void JSONNodeDumper::Visit(const Type *T) { |
72 | 495 | JOS.attribute("id", createPointerRepresentation(T)); |
73 | | |
74 | 495 | if (!T) |
75 | 1 | return; |
76 | | |
77 | 494 | JOS.attribute("kind", (llvm::Twine(T->getTypeClassName()) + "Type").str()); |
78 | 494 | JOS.attribute("type", createQualType(QualType(T, 0), /*Desugar*/ false)); |
79 | 494 | attributeOnlyIfTrue("containsErrors", T->containsErrors()); |
80 | 494 | attributeOnlyIfTrue("isDependent", T->isDependentType()); |
81 | 494 | attributeOnlyIfTrue("isInstantiationDependent", |
82 | 494 | T->isInstantiationDependentType()); |
83 | 494 | attributeOnlyIfTrue("isVariablyModified", T->isVariablyModifiedType()); |
84 | 494 | attributeOnlyIfTrue("containsUnexpandedPack", |
85 | 494 | T->containsUnexpandedParameterPack()); |
86 | 494 | attributeOnlyIfTrue("isImported", T->isFromAST()); |
87 | 494 | InnerTypeVisitor::Visit(T); |
88 | 494 | } |
89 | | |
90 | 1 | void JSONNodeDumper::Visit(QualType T) { |
91 | 1 | JOS.attribute("id", createPointerRepresentation(T.getAsOpaquePtr())); |
92 | 1 | JOS.attribute("kind", "QualType"); |
93 | 1 | JOS.attribute("type", createQualType(T)); |
94 | 1 | JOS.attribute("qualifiers", T.split().Quals.getAsString()); |
95 | 1 | } |
96 | | |
97 | 2.05k | void JSONNodeDumper::Visit(const Decl *D) { |
98 | 2.05k | JOS.attribute("id", createPointerRepresentation(D)); |
99 | | |
100 | 2.05k | if (!D) |
101 | 1 | return; |
102 | | |
103 | 2.05k | JOS.attribute("kind", (llvm::Twine(D->getDeclKindName()) + "Decl").str()); |
104 | 2.05k | JOS.attributeObject("loc", |
105 | 2.05k | [D, this] { writeSourceLocation(D->getLocation()); }); |
106 | 2.05k | JOS.attributeObject("range", |
107 | 2.05k | [D, this] { writeSourceRange(D->getSourceRange()); }); |
108 | 2.05k | attributeOnlyIfTrue("isImplicit", D->isImplicit()); |
109 | 2.05k | attributeOnlyIfTrue("isInvalid", D->isInvalidDecl()); |
110 | | |
111 | 2.05k | if (D->isUsed()) |
112 | 267 | JOS.attribute("isUsed", true); |
113 | 1.78k | else if (D->isThisDeclarationReferenced()) |
114 | 173 | JOS.attribute("isReferenced", true); |
115 | | |
116 | 2.05k | if (const auto *ND = dyn_cast<NamedDecl>(D)) |
117 | 1.91k | attributeOnlyIfTrue("isHidden", !ND->isUnconditionallyVisible()); |
118 | | |
119 | 2.05k | if (D->getLexicalDeclContext() != D->getDeclContext()) { |
120 | | // Because of multiple inheritance, a DeclContext pointer does not produce |
121 | | // the same pointer representation as a Decl pointer that references the |
122 | | // same AST Node. |
123 | 16 | const auto *ParentDeclContextDecl = dyn_cast<Decl>(D->getDeclContext()); |
124 | 16 | JOS.attribute("parentDeclContextId", |
125 | 16 | createPointerRepresentation(ParentDeclContextDecl)); |
126 | 16 | } |
127 | | |
128 | 2.05k | addPreviousDeclaration(D); |
129 | 2.05k | InnerDeclVisitor::Visit(D); |
130 | 2.05k | } |
131 | | |
132 | | void JSONNodeDumper::Visit(const comments::Comment *C, |
133 | 64 | const comments::FullComment *FC) { |
134 | 64 | if (!C) |
135 | 0 | return; |
136 | | |
137 | 64 | JOS.attribute("id", createPointerRepresentation(C)); |
138 | 64 | JOS.attribute("kind", C->getCommentKindName()); |
139 | 64 | JOS.attributeObject("loc", |
140 | 64 | [C, this] { writeSourceLocation(C->getLocation()); }); |
141 | 64 | JOS.attributeObject("range", |
142 | 64 | [C, this] { writeSourceRange(C->getSourceRange()); }); |
143 | | |
144 | 64 | InnerCommentVisitor::visit(C, FC); |
145 | 64 | } |
146 | | |
147 | | void JSONNodeDumper::Visit(const TemplateArgument &TA, SourceRange R, |
148 | 43 | const Decl *From, StringRef Label) { |
149 | 43 | JOS.attribute("kind", "TemplateArgument"); |
150 | 43 | if (R.isValid()) |
151 | 5 | JOS.attributeObject("range", [R, this] { writeSourceRange(R); }); |
152 | | |
153 | 43 | if (From) |
154 | 0 | JOS.attribute(Label.empty() ? "fromDecl" : Label, createBareDeclRef(From)); |
155 | | |
156 | 43 | InnerTemplateArgVisitor::Visit(TA); |
157 | 43 | } |
158 | | |
159 | 21 | void JSONNodeDumper::Visit(const CXXCtorInitializer *Init) { |
160 | 21 | JOS.attribute("kind", "CXXCtorInitializer"); |
161 | 21 | if (Init->isAnyMemberInitializer()) |
162 | 17 | JOS.attribute("anyInit", createBareDeclRef(Init->getAnyMember())); |
163 | 4 | else if (Init->isBaseInitializer()) |
164 | 4 | JOS.attribute("baseInit", |
165 | 4 | createQualType(QualType(Init->getBaseClass(), 0))); |
166 | 0 | else if (Init->isDelegatingInitializer()) |
167 | 0 | JOS.attribute("delegatingInit", |
168 | 0 | createQualType(Init->getTypeSourceInfo()->getType())); |
169 | 0 | else |
170 | 0 | llvm_unreachable("Unknown initializer type"); |
171 | 21 | } |
172 | | |
173 | 2 | void JSONNodeDumper::Visit(const OMPClause *C) {} |
174 | | |
175 | 3 | void JSONNodeDumper::Visit(const BlockDecl::Capture &C) { |
176 | 3 | JOS.attribute("kind", "Capture"); |
177 | 3 | attributeOnlyIfTrue("byref", C.isByRef()); |
178 | 3 | attributeOnlyIfTrue("nested", C.isNested()); |
179 | 3 | if (C.getVariable()) |
180 | 3 | JOS.attribute("var", createBareDeclRef(C.getVariable())); |
181 | 3 | } |
182 | | |
183 | 12 | void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { |
184 | 12 | JOS.attribute("associationKind", A.getTypeSourceInfo() ? "case"7 : "default"5 ); |
185 | 12 | attributeOnlyIfTrue("selected", A.isSelected()); |
186 | 12 | } |
187 | | |
188 | 4 | void JSONNodeDumper::Visit(const concepts::Requirement *R) { |
189 | 4 | if (!R) |
190 | 0 | return; |
191 | | |
192 | 4 | switch (R->getKind()) { |
193 | 1 | case concepts::Requirement::RK_Type: |
194 | 1 | JOS.attribute("kind", "TypeRequirement"); |
195 | 1 | break; |
196 | 1 | case concepts::Requirement::RK_Simple: |
197 | 1 | JOS.attribute("kind", "SimpleRequirement"); |
198 | 1 | break; |
199 | 1 | case concepts::Requirement::RK_Compound: |
200 | 1 | JOS.attribute("kind", "CompoundRequirement"); |
201 | 1 | break; |
202 | 1 | case concepts::Requirement::RK_Nested: |
203 | 1 | JOS.attribute("kind", "NestedRequirement"); |
204 | 1 | break; |
205 | 4 | } |
206 | | |
207 | 4 | if (auto *ER = dyn_cast<concepts::ExprRequirement>(R)) |
208 | 2 | attributeOnlyIfTrue("noexcept", ER->hasNoexceptRequirement()); |
209 | | |
210 | 4 | attributeOnlyIfTrue("isDependent", R->isDependent()); |
211 | 4 | if (!R->isDependent()) |
212 | 1 | JOS.attribute("satisfied", R->isSatisfied()); |
213 | 4 | attributeOnlyIfTrue("containsUnexpandedPack", |
214 | 4 | R->containsUnexpandedParameterPack()); |
215 | 4 | } |
216 | | |
217 | 11 | void JSONNodeDumper::Visit(const APValue &Value, QualType Ty) { |
218 | 11 | std::string Str; |
219 | 11 | llvm::raw_string_ostream OS(Str); |
220 | 11 | Value.printPretty(OS, Ctx, Ty); |
221 | 11 | JOS.attribute("value", OS.str()); |
222 | 11 | } |
223 | | |
224 | 10.7k | void JSONNodeDumper::writeIncludeStack(PresumedLoc Loc, bool JustFirst) { |
225 | 10.7k | if (Loc.isInvalid()) |
226 | 10.3k | return; |
227 | | |
228 | 346 | JOS.attributeBegin("includedFrom"); |
229 | 346 | JOS.objectBegin(); |
230 | | |
231 | 346 | if (!JustFirst) { |
232 | | // Walk the stack recursively, then print out the presumed location. |
233 | 0 | writeIncludeStack(SM.getPresumedLoc(Loc.getIncludeLoc())); |
234 | 0 | } |
235 | | |
236 | 346 | JOS.attribute("file", Loc.getFilename()); |
237 | 346 | JOS.objectEnd(); |
238 | 346 | JOS.attributeEnd(); |
239 | 346 | } |
240 | | |
241 | | void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc, |
242 | 12.0k | bool IsSpelling) { |
243 | 12.0k | PresumedLoc Presumed = SM.getPresumedLoc(Loc); |
244 | 12.0k | unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc)12.0k |
245 | 12.0k | : SM.getExpansionLineNumber(Loc)7 ; |
246 | 12.0k | StringRef ActualFile = SM.getBufferName(Loc); |
247 | | |
248 | 12.0k | if (Presumed.isValid()) { |
249 | 10.7k | JOS.attribute("offset", SM.getDecomposedLoc(Loc).second); |
250 | 10.7k | if (LastLocFilename != ActualFile) { |
251 | 167 | JOS.attribute("file", ActualFile); |
252 | 167 | JOS.attribute("line", ActualLine); |
253 | 10.5k | } else if (LastLocLine != ActualLine) |
254 | 2.32k | JOS.attribute("line", ActualLine); |
255 | | |
256 | 10.7k | StringRef PresumedFile = Presumed.getFilename(); |
257 | 10.7k | if (PresumedFile != ActualFile && LastLocPresumedFilename != PresumedFile15 ) |
258 | 3 | JOS.attribute("presumedFile", PresumedFile); |
259 | | |
260 | 10.7k | unsigned PresumedLine = Presumed.getLine(); |
261 | 10.7k | if (ActualLine != PresumedLine && LastLocPresumedLine != PresumedLine30 ) |
262 | 11 | JOS.attribute("presumedLine", PresumedLine); |
263 | | |
264 | 10.7k | JOS.attribute("col", Presumed.getColumn()); |
265 | 10.7k | JOS.attribute("tokLen", |
266 | 10.7k | Lexer::MeasureTokenLength(Loc, SM, Ctx.getLangOpts())); |
267 | 10.7k | LastLocFilename = ActualFile; |
268 | 10.7k | LastLocPresumedFilename = PresumedFile; |
269 | 10.7k | LastLocPresumedLine = PresumedLine; |
270 | 10.7k | LastLocLine = ActualLine; |
271 | | |
272 | | // Orthogonal to the file, line, and column de-duplication is whether the |
273 | | // given location was a result of an include. If so, print where the |
274 | | // include location came from. |
275 | 10.7k | writeIncludeStack(SM.getPresumedLoc(Presumed.getIncludeLoc()), |
276 | 10.7k | /*JustFirst*/ true); |
277 | 10.7k | } |
278 | 12.0k | } |
279 | | |
280 | 12.0k | void JSONNodeDumper::writeSourceLocation(SourceLocation Loc) { |
281 | 12.0k | SourceLocation Spelling = SM.getSpellingLoc(Loc); |
282 | 12.0k | SourceLocation Expansion = SM.getExpansionLoc(Loc); |
283 | | |
284 | 12.0k | if (Expansion != Spelling) { |
285 | | // If the expansion and the spelling are different, output subobjects |
286 | | // describing both locations. |
287 | 7 | JOS.attributeObject("spellingLoc", [Spelling, this] { |
288 | 7 | writeBareSourceLocation(Spelling, /*IsSpelling*/ true); |
289 | 7 | }); |
290 | 7 | JOS.attributeObject("expansionLoc", [Expansion, Loc, this] { |
291 | 7 | writeBareSourceLocation(Expansion, /*IsSpelling*/ false); |
292 | | // If there is a macro expansion, add extra information if the interesting |
293 | | // bit is the macro arg expansion. |
294 | 7 | if (SM.isMacroArgExpansion(Loc)) |
295 | 3 | JOS.attribute("isMacroArgExpansion", true); |
296 | 7 | }); |
297 | 7 | } else |
298 | 12.0k | writeBareSourceLocation(Spelling, /*IsSpelling*/ true); |
299 | 12.0k | } |
300 | | |
301 | 4.95k | void JSONNodeDumper::writeSourceRange(SourceRange R) { |
302 | 4.95k | JOS.attributeObject("begin", |
303 | 4.95k | [R, this] { writeSourceLocation(R.getBegin()); }); |
304 | 4.95k | JOS.attributeObject("end", [R, this] { writeSourceLocation(R.getEnd()); }); |
305 | 4.95k | } |
306 | | |
307 | 6.34k | std::string JSONNodeDumper::createPointerRepresentation(const void *Ptr) { |
308 | | // Because JSON stores integer values as signed 64-bit integers, trying to |
309 | | // represent them as such makes for very ugly pointer values in the resulting |
310 | | // output. Instead, we convert the value to hex and treat it as a string. |
311 | 6.34k | return "0x" + llvm::utohexstr(reinterpret_cast<uint64_t>(Ptr), true); |
312 | 6.34k | } |
313 | | |
314 | 4.73k | llvm::json::Object JSONNodeDumper::createQualType(QualType QT, bool Desugar) { |
315 | 4.73k | SplitQualType SQT = QT.split(); |
316 | 4.73k | llvm::json::Object Ret{{"qualType", QualType::getAsString(SQT, PrintPolicy)}}; |
317 | | |
318 | 4.73k | if (Desugar && !QT.isNull()4.23k ) { |
319 | 4.22k | SplitQualType DSQT = QT.getSplitDesugaredType(); |
320 | 4.22k | if (DSQT != SQT) |
321 | 312 | Ret["desugaredQualType"] = QualType::getAsString(DSQT, PrintPolicy); |
322 | 4.22k | if (const auto *TT = QT->getAs<TypedefType>()) |
323 | 68 | Ret["typeAliasDeclId"] = createPointerRepresentation(TT->getDecl()); |
324 | 4.22k | } |
325 | 4.73k | return Ret; |
326 | 4.73k | } |
327 | | |
328 | 21 | void JSONNodeDumper::writeBareDeclRef(const Decl *D) { |
329 | 21 | JOS.attribute("id", createPointerRepresentation(D)); |
330 | 21 | if (!D) |
331 | 0 | return; |
332 | | |
333 | 21 | JOS.attribute("kind", (llvm::Twine(D->getDeclKindName()) + "Decl").str()); |
334 | 21 | if (const auto *ND = dyn_cast<NamedDecl>(D)) |
335 | 21 | JOS.attribute("name", ND->getDeclName().getAsString()); |
336 | 21 | if (const auto *VD = dyn_cast<ValueDecl>(D)) |
337 | 1 | JOS.attribute("type", createQualType(VD->getType())); |
338 | 21 | } |
339 | | |
340 | 698 | llvm::json::Object JSONNodeDumper::createBareDeclRef(const Decl *D) { |
341 | 698 | llvm::json::Object Ret{{"id", createPointerRepresentation(D)}}; |
342 | 698 | if (!D) |
343 | 5 | return Ret; |
344 | | |
345 | 693 | Ret["kind"] = (llvm::Twine(D->getDeclKindName()) + "Decl").str(); |
346 | 693 | if (const auto *ND = dyn_cast<NamedDecl>(D)) |
347 | 690 | Ret["name"] = ND->getDeclName().getAsString(); |
348 | 693 | if (const auto *VD = dyn_cast<ValueDecl>(D)) |
349 | 526 | Ret["type"] = createQualType(VD->getType()); |
350 | 693 | return Ret; |
351 | 698 | } |
352 | | |
353 | 498 | llvm::json::Array JSONNodeDumper::createCastPath(const CastExpr *C) { |
354 | 498 | llvm::json::Array Ret; |
355 | 498 | if (C->path_empty()) |
356 | 497 | return Ret; |
357 | | |
358 | 2 | for (auto I = C->path_begin(), E = C->path_end(); 1 I != E; ++I1 ) { |
359 | 1 | const CXXBaseSpecifier *Base = *I; |
360 | 1 | const auto *RD = |
361 | 1 | cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl()); |
362 | | |
363 | 1 | llvm::json::Object Val{{"name", RD->getName()}}; |
364 | 1 | if (Base->isVirtual()) |
365 | 0 | Val["isVirtual"] = true; |
366 | 1 | Ret.push_back(std::move(Val)); |
367 | 1 | } |
368 | 1 | return Ret; |
369 | 498 | } |
370 | | |
371 | 8.37k | #define FIELD2(Name, Flag) if (RD->Flag()) Ret[Name] = true3.63k |
372 | 2.09k | #define FIELD1(Flag) FIELD2(#Flag, Flag) |
373 | | |
374 | | static llvm::json::Object |
375 | 131 | createDefaultConstructorDefinitionData(const CXXRecordDecl *RD) { |
376 | 131 | llvm::json::Object Ret; |
377 | | |
378 | 131 | FIELD2("exists", hasDefaultConstructor); |
379 | 131 | FIELD2("trivial", hasTrivialDefaultConstructor); |
380 | 131 | FIELD2("nonTrivial", hasNonTrivialDefaultConstructor); |
381 | 131 | FIELD2("userProvided", hasUserProvidedDefaultConstructor); |
382 | 131 | FIELD2("isConstexpr", hasConstexprDefaultConstructor); |
383 | 131 | FIELD2("needsImplicit", needsImplicitDefaultConstructor); |
384 | 131 | FIELD2("defaultedIsConstexpr", defaultedDefaultConstructorIsConstexpr); |
385 | | |
386 | 131 | return Ret; |
387 | 131 | } |
388 | | |
389 | | static llvm::json::Object |
390 | 131 | createCopyConstructorDefinitionData(const CXXRecordDecl *RD) { |
391 | 131 | llvm::json::Object Ret; |
392 | | |
393 | 131 | FIELD2("simple", hasSimpleCopyConstructor); |
394 | 131 | FIELD2("trivial", hasTrivialCopyConstructor); |
395 | 131 | FIELD2("nonTrivial", hasNonTrivialCopyConstructor); |
396 | 131 | FIELD2("userDeclared", hasUserDeclaredCopyConstructor); |
397 | 131 | FIELD2("hasConstParam", hasCopyConstructorWithConstParam); |
398 | 131 | FIELD2("implicitHasConstParam", implicitCopyConstructorHasConstParam); |
399 | 131 | FIELD2("needsImplicit", needsImplicitCopyConstructor); |
400 | 131 | FIELD2("needsOverloadResolution", needsOverloadResolutionForCopyConstructor); |
401 | 131 | if (!RD->needsOverloadResolutionForCopyConstructor()) |
402 | 127 | FIELD2("defaultedIsDeleted", defaultedCopyConstructorIsDeleted); |
403 | | |
404 | 131 | return Ret; |
405 | 131 | } |
406 | | |
407 | | static llvm::json::Object |
408 | 131 | createMoveConstructorDefinitionData(const CXXRecordDecl *RD) { |
409 | 131 | llvm::json::Object Ret; |
410 | | |
411 | 131 | FIELD2("exists", hasMoveConstructor); |
412 | 131 | FIELD2("simple", hasSimpleMoveConstructor); |
413 | 131 | FIELD2("trivial", hasTrivialMoveConstructor); |
414 | 131 | FIELD2("nonTrivial", hasNonTrivialMoveConstructor); |
415 | 131 | FIELD2("userDeclared", hasUserDeclaredMoveConstructor); |
416 | 131 | FIELD2("needsImplicit", needsImplicitMoveConstructor); |
417 | 131 | FIELD2("needsOverloadResolution", needsOverloadResolutionForMoveConstructor); |
418 | 131 | if (!RD->needsOverloadResolutionForMoveConstructor()) |
419 | 127 | FIELD2("defaultedIsDeleted", defaultedMoveConstructorIsDeleted); |
420 | | |
421 | 131 | return Ret; |
422 | 131 | } |
423 | | |
424 | | static llvm::json::Object |
425 | 131 | createCopyAssignmentDefinitionData(const CXXRecordDecl *RD) { |
426 | 131 | llvm::json::Object Ret; |
427 | | |
428 | 131 | FIELD2("simple", hasSimpleCopyAssignment); |
429 | 131 | FIELD2("trivial", hasTrivialCopyAssignment); |
430 | 131 | FIELD2("nonTrivial", hasNonTrivialCopyAssignment); |
431 | 131 | FIELD2("hasConstParam", hasCopyAssignmentWithConstParam); |
432 | 131 | FIELD2("implicitHasConstParam", implicitCopyAssignmentHasConstParam); |
433 | 131 | FIELD2("userDeclared", hasUserDeclaredCopyAssignment); |
434 | 131 | FIELD2("needsImplicit", needsImplicitCopyAssignment); |
435 | 131 | FIELD2("needsOverloadResolution", needsOverloadResolutionForCopyAssignment); |
436 | | |
437 | 131 | return Ret; |
438 | 131 | } |
439 | | |
440 | | static llvm::json::Object |
441 | 131 | createMoveAssignmentDefinitionData(const CXXRecordDecl *RD) { |
442 | 131 | llvm::json::Object Ret; |
443 | | |
444 | 131 | FIELD2("exists", hasMoveAssignment); |
445 | 131 | FIELD2("simple", hasSimpleMoveAssignment); |
446 | 131 | FIELD2("trivial", hasTrivialMoveAssignment); |
447 | 131 | FIELD2("nonTrivial", hasNonTrivialMoveAssignment); |
448 | 131 | FIELD2("userDeclared", hasUserDeclaredMoveAssignment); |
449 | 131 | FIELD2("needsImplicit", needsImplicitMoveAssignment); |
450 | 131 | FIELD2("needsOverloadResolution", needsOverloadResolutionForMoveAssignment); |
451 | | |
452 | 131 | return Ret; |
453 | 131 | } |
454 | | |
455 | | static llvm::json::Object |
456 | 131 | createDestructorDefinitionData(const CXXRecordDecl *RD) { |
457 | 131 | llvm::json::Object Ret; |
458 | | |
459 | 131 | FIELD2("simple", hasSimpleDestructor); |
460 | 131 | FIELD2("irrelevant", hasIrrelevantDestructor); |
461 | 131 | FIELD2("trivial", hasTrivialDestructor); |
462 | 131 | FIELD2("nonTrivial", hasNonTrivialDestructor); |
463 | 131 | FIELD2("userDeclared", hasUserDeclaredDestructor); |
464 | 131 | FIELD2("needsImplicit", needsImplicitDestructor); |
465 | 131 | FIELD2("needsOverloadResolution", needsOverloadResolutionForDestructor); |
466 | 131 | if (!RD->needsOverloadResolutionForDestructor()) |
467 | 127 | FIELD2("defaultedIsDeleted", defaultedDestructorIsDeleted); |
468 | | |
469 | 131 | return Ret; |
470 | 131 | } |
471 | | |
472 | | llvm::json::Object |
473 | 131 | JSONNodeDumper::createCXXRecordDefinitionData(const CXXRecordDecl *RD) { |
474 | 131 | llvm::json::Object Ret; |
475 | | |
476 | | // This data is common to all C++ classes. |
477 | 131 | FIELD1(isGenericLambda); |
478 | 131 | FIELD1(isLambda); |
479 | 131 | FIELD1(isEmpty); |
480 | 131 | FIELD1(isAggregate); |
481 | 131 | FIELD1(isStandardLayout); |
482 | 131 | FIELD1(isTriviallyCopyable); |
483 | 131 | FIELD1(isPOD); |
484 | 131 | FIELD1(isTrivial); |
485 | 131 | FIELD1(isPolymorphic); |
486 | 131 | FIELD1(isAbstract); |
487 | 131 | FIELD1(isLiteral); |
488 | 131 | FIELD1(canPassInRegisters); |
489 | 131 | FIELD1(hasUserDeclaredConstructor); |
490 | 131 | FIELD1(hasConstexprNonCopyMoveConstructor); |
491 | 131 | FIELD1(hasMutableFields); |
492 | 131 | FIELD1(hasVariantMembers); |
493 | 131 | FIELD2("canConstDefaultInit", allowConstDefaultInit); |
494 | | |
495 | 131 | Ret["defaultCtor"] = createDefaultConstructorDefinitionData(RD); |
496 | 131 | Ret["copyCtor"] = createCopyConstructorDefinitionData(RD); |
497 | 131 | Ret["moveCtor"] = createMoveConstructorDefinitionData(RD); |
498 | 131 | Ret["copyAssign"] = createCopyAssignmentDefinitionData(RD); |
499 | 131 | Ret["moveAssign"] = createMoveAssignmentDefinitionData(RD); |
500 | 131 | Ret["dtor"] = createDestructorDefinitionData(RD); |
501 | | |
502 | 131 | return Ret; |
503 | 131 | } |
504 | | |
505 | | #undef FIELD1 |
506 | | #undef FIELD2 |
507 | | |
508 | 77 | std::string JSONNodeDumper::createAccessSpecifier(AccessSpecifier AS) { |
509 | 77 | const auto AccessSpelling = getAccessSpelling(AS); |
510 | 77 | if (AccessSpelling.empty()) |
511 | 9 | return "none"; |
512 | 68 | return AccessSpelling.str(); |
513 | 77 | } |
514 | | |
515 | | llvm::json::Object |
516 | 14 | JSONNodeDumper::createCXXBaseSpecifier(const CXXBaseSpecifier &BS) { |
517 | 14 | llvm::json::Object Ret; |
518 | | |
519 | 14 | Ret["type"] = createQualType(BS.getType()); |
520 | 14 | Ret["access"] = createAccessSpecifier(BS.getAccessSpecifier()); |
521 | 14 | Ret["writtenAccess"] = |
522 | 14 | createAccessSpecifier(BS.getAccessSpecifierAsWritten()); |
523 | 14 | if (BS.isVirtual()) |
524 | 5 | Ret["isVirtual"] = true; |
525 | 14 | if (BS.isPackExpansion()) |
526 | 1 | Ret["isPackExpansion"] = true; |
527 | | |
528 | 14 | return Ret; |
529 | 14 | } |
530 | | |
531 | 0 | void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) { |
532 | 0 | JOS.attribute("decl", createBareDeclRef(TT->getDecl())); |
533 | 0 | } |
534 | | |
535 | 4 | void JSONNodeDumper::VisitFunctionType(const FunctionType *T) { |
536 | 4 | FunctionType::ExtInfo E = T->getExtInfo(); |
537 | 4 | attributeOnlyIfTrue("noreturn", E.getNoReturn()); |
538 | 4 | attributeOnlyIfTrue("producesResult", E.getProducesResult()); |
539 | 4 | if (E.getHasRegParm()) |
540 | 0 | JOS.attribute("regParm", E.getRegParm()); |
541 | 4 | JOS.attribute("cc", FunctionType::getNameForCallConv(E.getCC())); |
542 | 4 | } |
543 | | |
544 | 4 | void JSONNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { |
545 | 4 | FunctionProtoType::ExtProtoInfo E = T->getExtProtoInfo(); |
546 | 4 | attributeOnlyIfTrue("trailingReturn", E.HasTrailingReturn); |
547 | 4 | attributeOnlyIfTrue("const", T->isConst()); |
548 | 4 | attributeOnlyIfTrue("volatile", T->isVolatile()); |
549 | 4 | attributeOnlyIfTrue("restrict", T->isRestrict()); |
550 | 4 | attributeOnlyIfTrue("variadic", E.Variadic); |
551 | 4 | switch (E.RefQualifier) { |
552 | 0 | case RQ_LValue: JOS.attribute("refQualifier", "&"); break; |
553 | 0 | case RQ_RValue: JOS.attribute("refQualifier", "&&"); break; |
554 | 4 | case RQ_None: break; |
555 | 4 | } |
556 | 4 | switch (E.ExceptionSpec.Type) { |
557 | 0 | case EST_DynamicNone: |
558 | 0 | case EST_Dynamic: { |
559 | 0 | JOS.attribute("exceptionSpec", "throw"); |
560 | 0 | llvm::json::Array Types; |
561 | 0 | for (QualType QT : E.ExceptionSpec.Exceptions) |
562 | 0 | Types.push_back(createQualType(QT)); |
563 | 0 | JOS.attribute("exceptionTypes", std::move(Types)); |
564 | 0 | } break; |
565 | 0 | case EST_MSAny: |
566 | 0 | JOS.attribute("exceptionSpec", "throw"); |
567 | 0 | JOS.attribute("throwsAny", true); |
568 | 0 | break; |
569 | 0 | case EST_BasicNoexcept: |
570 | 0 | JOS.attribute("exceptionSpec", "noexcept"); |
571 | 0 | break; |
572 | 0 | case EST_NoexceptTrue: |
573 | 0 | case EST_NoexceptFalse: |
574 | 0 | JOS.attribute("exceptionSpec", "noexcept"); |
575 | 0 | JOS.attribute("conditionEvaluatesTo", |
576 | 0 | E.ExceptionSpec.Type == EST_NoexceptTrue); |
577 | | //JOS.attributeWithCall("exceptionSpecExpr", |
578 | | // [this, E]() { Visit(E.ExceptionSpec.NoexceptExpr); }); |
579 | 0 | break; |
580 | 0 | case EST_NoThrow: |
581 | 0 | JOS.attribute("exceptionSpec", "nothrow"); |
582 | 0 | break; |
583 | | // FIXME: I cannot find a way to trigger these cases while dumping the AST. I |
584 | | // suspect you can only run into them when executing an AST dump from within |
585 | | // the debugger, which is not a use case we worry about for the JSON dumping |
586 | | // feature. |
587 | 0 | case EST_DependentNoexcept: |
588 | 0 | case EST_Unevaluated: |
589 | 0 | case EST_Uninstantiated: |
590 | 0 | case EST_Unparsed: |
591 | 4 | case EST_None: break; |
592 | 4 | } |
593 | 4 | VisitFunctionType(T); |
594 | 4 | } |
595 | | |
596 | 0 | void JSONNodeDumper::VisitRValueReferenceType(const ReferenceType *RT) { |
597 | 0 | attributeOnlyIfTrue("spelledAsLValue", RT->isSpelledAsLValue()); |
598 | 0 | } |
599 | | |
600 | 60 | void JSONNodeDumper::VisitArrayType(const ArrayType *AT) { |
601 | 60 | switch (AT->getSizeModifier()) { |
602 | 0 | case ArrayType::Star: |
603 | 0 | JOS.attribute("sizeModifier", "*"); |
604 | 0 | break; |
605 | 0 | case ArrayType::Static: |
606 | 0 | JOS.attribute("sizeModifier", "static"); |
607 | 0 | break; |
608 | 60 | case ArrayType::Normal: |
609 | 60 | break; |
610 | 60 | } |
611 | | |
612 | 60 | std::string Str = AT->getIndexTypeQualifiers().getAsString(); |
613 | 60 | if (!Str.empty()) |
614 | 0 | JOS.attribute("indexTypeQualifiers", Str); |
615 | 60 | } |
616 | | |
617 | 59 | void JSONNodeDumper::VisitConstantArrayType(const ConstantArrayType *CAT) { |
618 | | // FIXME: this should use ZExt instead of SExt, but JSON doesn't allow a |
619 | | // narrowing conversion to int64_t so it cannot be expressed. |
620 | 59 | JOS.attribute("size", CAT->getSize().getSExtValue()); |
621 | 59 | VisitArrayType(CAT); |
622 | 59 | } |
623 | | |
624 | | void JSONNodeDumper::VisitDependentSizedExtVectorType( |
625 | 0 | const DependentSizedExtVectorType *VT) { |
626 | 0 | JOS.attributeObject( |
627 | 0 | "attrLoc", [VT, this] { writeSourceLocation(VT->getAttributeLoc()); }); |
628 | 0 | } |
629 | | |
630 | 0 | void JSONNodeDumper::VisitVectorType(const VectorType *VT) { |
631 | 0 | JOS.attribute("numElements", VT->getNumElements()); |
632 | 0 | switch (VT->getVectorKind()) { |
633 | 0 | case VectorType::GenericVector: |
634 | 0 | break; |
635 | 0 | case VectorType::AltiVecVector: |
636 | 0 | JOS.attribute("vectorKind", "altivec"); |
637 | 0 | break; |
638 | 0 | case VectorType::AltiVecPixel: |
639 | 0 | JOS.attribute("vectorKind", "altivec pixel"); |
640 | 0 | break; |
641 | 0 | case VectorType::AltiVecBool: |
642 | 0 | JOS.attribute("vectorKind", "altivec bool"); |
643 | 0 | break; |
644 | 0 | case VectorType::NeonVector: |
645 | 0 | JOS.attribute("vectorKind", "neon"); |
646 | 0 | break; |
647 | 0 | case VectorType::NeonPolyVector: |
648 | 0 | JOS.attribute("vectorKind", "neon poly"); |
649 | 0 | break; |
650 | 0 | case VectorType::SveFixedLengthDataVector: |
651 | 0 | JOS.attribute("vectorKind", "fixed-length sve data vector"); |
652 | 0 | break; |
653 | 0 | case VectorType::SveFixedLengthPredicateVector: |
654 | 0 | JOS.attribute("vectorKind", "fixed-length sve predicate vector"); |
655 | 0 | break; |
656 | 0 | } |
657 | 0 | } |
658 | | |
659 | 0 | void JSONNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *UUT) { |
660 | 0 | JOS.attribute("decl", createBareDeclRef(UUT->getDecl())); |
661 | 0 | } |
662 | | |
663 | 0 | void JSONNodeDumper::VisitUnaryTransformType(const UnaryTransformType *UTT) { |
664 | 0 | switch (UTT->getUTTKind()) { |
665 | 0 | case UnaryTransformType::EnumUnderlyingType: |
666 | 0 | JOS.attribute("transformKind", "underlying_type"); |
667 | 0 | break; |
668 | 0 | } |
669 | 0 | } |
670 | | |
671 | 123 | void JSONNodeDumper::VisitTagType(const TagType *TT) { |
672 | 123 | JOS.attribute("decl", createBareDeclRef(TT->getDecl())); |
673 | 123 | } |
674 | | |
675 | | void JSONNodeDumper::VisitTemplateTypeParmType( |
676 | 8 | const TemplateTypeParmType *TTPT) { |
677 | 8 | JOS.attribute("depth", TTPT->getDepth()); |
678 | 8 | JOS.attribute("index", TTPT->getIndex()); |
679 | 8 | attributeOnlyIfTrue("isPack", TTPT->isParameterPack()); |
680 | 8 | JOS.attribute("decl", createBareDeclRef(TTPT->getDecl())); |
681 | 8 | } |
682 | | |
683 | 0 | void JSONNodeDumper::VisitAutoType(const AutoType *AT) { |
684 | 0 | JOS.attribute("undeduced", !AT->isDeduced()); |
685 | 0 | switch (AT->getKeyword()) { |
686 | 0 | case AutoTypeKeyword::Auto: |
687 | 0 | JOS.attribute("typeKeyword", "auto"); |
688 | 0 | break; |
689 | 0 | case AutoTypeKeyword::DecltypeAuto: |
690 | 0 | JOS.attribute("typeKeyword", "decltype(auto)"); |
691 | 0 | break; |
692 | 0 | case AutoTypeKeyword::GNUAutoType: |
693 | 0 | JOS.attribute("typeKeyword", "__auto_type"); |
694 | 0 | break; |
695 | 0 | } |
696 | 0 | } |
697 | | |
698 | | void JSONNodeDumper::VisitTemplateSpecializationType( |
699 | 0 | const TemplateSpecializationType *TST) { |
700 | 0 | attributeOnlyIfTrue("isAlias", TST->isTypeAlias()); |
701 | |
|
702 | 0 | std::string Str; |
703 | 0 | llvm::raw_string_ostream OS(Str); |
704 | 0 | TST->getTemplateName().print(OS, PrintPolicy); |
705 | 0 | JOS.attribute("templateName", OS.str()); |
706 | 0 | } |
707 | | |
708 | | void JSONNodeDumper::VisitInjectedClassNameType( |
709 | 0 | const InjectedClassNameType *ICNT) { |
710 | 0 | JOS.attribute("decl", createBareDeclRef(ICNT->getDecl())); |
711 | 0 | } |
712 | | |
713 | 0 | void JSONNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *OIT) { |
714 | 0 | JOS.attribute("decl", createBareDeclRef(OIT->getDecl())); |
715 | 0 | } |
716 | | |
717 | 0 | void JSONNodeDumper::VisitPackExpansionType(const PackExpansionType *PET) { |
718 | 0 | if (llvm::Optional<unsigned> N = PET->getNumExpansions()) |
719 | 0 | JOS.attribute("numExpansions", *N); |
720 | 0 | } |
721 | | |
722 | 2 | void JSONNodeDumper::VisitElaboratedType(const ElaboratedType *ET) { |
723 | 2 | if (const NestedNameSpecifier *NNS = ET->getQualifier()) { |
724 | 1 | std::string Str; |
725 | 1 | llvm::raw_string_ostream OS(Str); |
726 | 1 | NNS->print(OS, PrintPolicy, /*ResolveTemplateArgs*/ true); |
727 | 1 | JOS.attribute("qualifier", OS.str()); |
728 | 1 | } |
729 | 2 | if (const TagDecl *TD = ET->getOwnedTagDecl()) |
730 | 0 | JOS.attribute("ownedTagDecl", createBareDeclRef(TD)); |
731 | 2 | } |
732 | | |
733 | 1 | void JSONNodeDumper::VisitMacroQualifiedType(const MacroQualifiedType *MQT) { |
734 | 1 | JOS.attribute("macroName", MQT->getMacroIdentifier()->getName()); |
735 | 1 | } |
736 | | |
737 | 2 | void JSONNodeDumper::VisitMemberPointerType(const MemberPointerType *MPT) { |
738 | 2 | attributeOnlyIfTrue("isData", MPT->isMemberDataPointer()); |
739 | 2 | attributeOnlyIfTrue("isFunction", MPT->isMemberFunctionPointer()); |
740 | 2 | } |
741 | | |
742 | 1.90k | void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) { |
743 | 1.90k | if (ND && ND->getDeclName()) { |
744 | 1.76k | JOS.attribute("name", ND->getNameAsString()); |
745 | | // FIXME: There are likely other contexts in which it makes no sense to ask |
746 | | // for a mangled name. |
747 | 1.76k | if (isa<RequiresExprBodyDecl>(ND->getDeclContext())) |
748 | 1 | return; |
749 | | |
750 | | // Mangled names are not meaningful for locals, and may not be well-defined |
751 | | // in the case of VLAs. |
752 | 1.76k | auto *VD = dyn_cast<VarDecl>(ND); |
753 | 1.76k | if (VD && VD->hasLocalStorage()384 ) |
754 | 320 | return; |
755 | | |
756 | 1.44k | std::string MangledName = ASTNameGen.getName(ND); |
757 | 1.44k | if (!MangledName.empty()) |
758 | 500 | JOS.attribute("mangledName", MangledName); |
759 | 1.44k | } |
760 | 1.90k | } |
761 | | |
762 | 309 | void JSONNodeDumper::VisitTypedefDecl(const TypedefDecl *TD) { |
763 | 309 | VisitNamedDecl(TD); |
764 | 309 | JOS.attribute("type", createQualType(TD->getUnderlyingType())); |
765 | 309 | } |
766 | | |
767 | 5 | void JSONNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *TAD) { |
768 | 5 | VisitNamedDecl(TAD); |
769 | 5 | JOS.attribute("type", createQualType(TAD->getUnderlyingType())); |
770 | 5 | } |
771 | | |
772 | 16 | void JSONNodeDumper::VisitNamespaceDecl(const NamespaceDecl *ND) { |
773 | 16 | VisitNamedDecl(ND); |
774 | 16 | attributeOnlyIfTrue("isInline", ND->isInline()); |
775 | 16 | if (!ND->isOriginalNamespace()) |
776 | 0 | JOS.attribute("originalNamespace", |
777 | 0 | createBareDeclRef(ND->getOriginalNamespace())); |
778 | 16 | } |
779 | | |
780 | 3 | void JSONNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD) { |
781 | 3 | JOS.attribute("nominatedNamespace", |
782 | 3 | createBareDeclRef(UDD->getNominatedNamespace())); |
783 | 3 | } |
784 | | |
785 | 1 | void JSONNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD) { |
786 | 1 | VisitNamedDecl(NAD); |
787 | 1 | JOS.attribute("aliasedNamespace", |
788 | 1 | createBareDeclRef(NAD->getAliasedNamespace())); |
789 | 1 | } |
790 | | |
791 | 5 | void JSONNodeDumper::VisitUsingDecl(const UsingDecl *UD) { |
792 | 5 | std::string Name; |
793 | 5 | if (const NestedNameSpecifier *NNS = UD->getQualifier()) { |
794 | 5 | llvm::raw_string_ostream SOS(Name); |
795 | 5 | NNS->print(SOS, UD->getASTContext().getPrintingPolicy()); |
796 | 5 | } |
797 | 5 | Name += UD->getNameAsString(); |
798 | 5 | JOS.attribute("name", Name); |
799 | 5 | } |
800 | | |
801 | 0 | void JSONNodeDumper::VisitUsingEnumDecl(const UsingEnumDecl *UED) { |
802 | 0 | JOS.attribute("target", createBareDeclRef(UED->getEnumDecl())); |
803 | 0 | } |
804 | | |
805 | 4 | void JSONNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *USD) { |
806 | 4 | JOS.attribute("target", createBareDeclRef(USD->getTargetDecl())); |
807 | 4 | } |
808 | | |
809 | 468 | void JSONNodeDumper::VisitVarDecl(const VarDecl *VD) { |
810 | 468 | VisitNamedDecl(VD); |
811 | 468 | JOS.attribute("type", createQualType(VD->getType())); |
812 | | |
813 | 468 | StorageClass SC = VD->getStorageClass(); |
814 | 468 | if (SC != SC_None) |
815 | 26 | JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC)); |
816 | 468 | switch (VD->getTLSKind()) { |
817 | 0 | case VarDecl::TLS_Dynamic: JOS.attribute("tls", "dynamic"); break; |
818 | 1 | case VarDecl::TLS_Static: JOS.attribute("tls", "static"); break; |
819 | 467 | case VarDecl::TLS_None: break; |
820 | 468 | } |
821 | 468 | attributeOnlyIfTrue("nrvo", VD->isNRVOVariable()); |
822 | 468 | attributeOnlyIfTrue("inline", VD->isInline()); |
823 | 468 | attributeOnlyIfTrue("constexpr", VD->isConstexpr()); |
824 | 468 | attributeOnlyIfTrue("modulePrivate", VD->isModulePrivate()); |
825 | 468 | if (VD->hasInit()) { |
826 | 84 | switch (VD->getInitStyle()) { |
827 | 76 | case VarDecl::CInit: JOS.attribute("init", "c"); break; |
828 | 8 | case VarDecl::CallInit: JOS.attribute("init", "call"); break; |
829 | 0 | case VarDecl::ListInit: JOS.attribute("init", "list"); break; |
830 | 84 | } |
831 | 84 | } |
832 | 468 | attributeOnlyIfTrue("isParameterPack", VD->isParameterPack()); |
833 | 468 | } |
834 | | |
835 | 103 | void JSONNodeDumper::VisitFieldDecl(const FieldDecl *FD) { |
836 | 103 | VisitNamedDecl(FD); |
837 | 103 | JOS.attribute("type", createQualType(FD->getType())); |
838 | 103 | attributeOnlyIfTrue("mutable", FD->isMutable()); |
839 | 103 | attributeOnlyIfTrue("modulePrivate", FD->isModulePrivate()); |
840 | 103 | attributeOnlyIfTrue("isBitfield", FD->isBitField()); |
841 | 103 | attributeOnlyIfTrue("hasInClassInitializer", FD->hasInClassInitializer()); |
842 | 103 | } |
843 | | |
844 | 501 | void JSONNodeDumper::VisitFunctionDecl(const FunctionDecl *FD) { |
845 | 501 | VisitNamedDecl(FD); |
846 | 501 | JOS.attribute("type", createQualType(FD->getType())); |
847 | 501 | StorageClass SC = FD->getStorageClass(); |
848 | 501 | if (SC != SC_None) |
849 | 11 | JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC)); |
850 | 501 | attributeOnlyIfTrue("inline", FD->isInlineSpecified()); |
851 | 501 | attributeOnlyIfTrue("virtual", FD->isVirtualAsWritten()); |
852 | 501 | attributeOnlyIfTrue("pure", FD->isPure()); |
853 | 501 | attributeOnlyIfTrue("explicitlyDeleted", FD->isDeletedAsWritten()); |
854 | 501 | attributeOnlyIfTrue("constexpr", FD->isConstexpr()); |
855 | 501 | attributeOnlyIfTrue("variadic", FD->isVariadic()); |
856 | | |
857 | 501 | if (FD->isDefaulted()) |
858 | 91 | JOS.attribute("explicitlyDefaulted", |
859 | 91 | FD->isDeleted() ? "deleted"0 : "default"); |
860 | 501 | } |
861 | | |
862 | 11 | void JSONNodeDumper::VisitEnumDecl(const EnumDecl *ED) { |
863 | 11 | VisitNamedDecl(ED); |
864 | 11 | if (ED->isFixed()) |
865 | 4 | JOS.attribute("fixedUnderlyingType", createQualType(ED->getIntegerType())); |
866 | 11 | if (ED->isScoped()) |
867 | 3 | JOS.attribute("scopedEnumTag", |
868 | 3 | ED->isScopedUsingClassTag() ? "class"2 : "struct"1 ); |
869 | 11 | } |
870 | 18 | void JSONNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *ECD) { |
871 | 18 | VisitNamedDecl(ECD); |
872 | 18 | JOS.attribute("type", createQualType(ECD->getType())); |
873 | 18 | } |
874 | | |
875 | 263 | void JSONNodeDumper::VisitRecordDecl(const RecordDecl *RD) { |
876 | 263 | VisitNamedDecl(RD); |
877 | 263 | JOS.attribute("tagUsed", RD->getKindName()); |
878 | 263 | attributeOnlyIfTrue("completeDefinition", RD->isCompleteDefinition()); |
879 | 263 | } |
880 | 245 | void JSONNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *RD) { |
881 | 245 | VisitRecordDecl(RD); |
882 | | |
883 | | // All other information requires a complete definition. |
884 | 245 | if (!RD->isCompleteDefinition()) |
885 | 114 | return; |
886 | | |
887 | 131 | JOS.attribute("definitionData", createCXXRecordDefinitionData(RD)); |
888 | 131 | if (RD->getNumBases()) { |
889 | 11 | JOS.attributeArray("bases", [this, RD] { |
890 | 11 | for (const auto &Spec : RD->bases()) |
891 | 14 | JOS.value(createCXXBaseSpecifier(Spec)); |
892 | 11 | }); |
893 | 11 | } |
894 | 131 | } |
895 | | |
896 | 48 | void JSONNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { |
897 | 48 | VisitNamedDecl(D); |
898 | 48 | JOS.attribute("tagUsed", D->wasDeclaredWithTypename() ? "typename"40 : "class"8 ); |
899 | 48 | JOS.attribute("depth", D->getDepth()); |
900 | 48 | JOS.attribute("index", D->getIndex()); |
901 | 48 | attributeOnlyIfTrue("isParameterPack", D->isParameterPack()); |
902 | | |
903 | 48 | if (D->hasDefaultArgument()) |
904 | 2 | JOS.attributeObject("defaultArg", [=] { |
905 | 2 | Visit(D->getDefaultArgument(), SourceRange(), |
906 | 2 | D->getDefaultArgStorage().getInheritedFrom(), |
907 | 2 | D->defaultArgumentWasInherited() ? "inherited from"0 : "previous"); |
908 | 2 | }); |
909 | 48 | } |
910 | | |
911 | | void JSONNodeDumper::VisitNonTypeTemplateParmDecl( |
912 | 58 | const NonTypeTemplateParmDecl *D) { |
913 | 58 | VisitNamedDecl(D); |
914 | 58 | JOS.attribute("type", createQualType(D->getType())); |
915 | 58 | JOS.attribute("depth", D->getDepth()); |
916 | 58 | JOS.attribute("index", D->getIndex()); |
917 | 58 | attributeOnlyIfTrue("isParameterPack", D->isParameterPack()); |
918 | | |
919 | 58 | if (D->hasDefaultArgument()) |
920 | 0 | JOS.attributeObject("defaultArg", [=] { |
921 | 0 | Visit(D->getDefaultArgument(), SourceRange(), |
922 | 0 | D->getDefaultArgStorage().getInheritedFrom(), |
923 | 0 | D->defaultArgumentWasInherited() ? "inherited from" : "previous"); |
924 | 0 | }); |
925 | 58 | } |
926 | | |
927 | | void JSONNodeDumper::VisitTemplateTemplateParmDecl( |
928 | 2 | const TemplateTemplateParmDecl *D) { |
929 | 2 | VisitNamedDecl(D); |
930 | 2 | JOS.attribute("depth", D->getDepth()); |
931 | 2 | JOS.attribute("index", D->getIndex()); |
932 | 2 | attributeOnlyIfTrue("isParameterPack", D->isParameterPack()); |
933 | | |
934 | 2 | if (D->hasDefaultArgument()) |
935 | 1 | JOS.attributeObject("defaultArg", [=] { |
936 | 1 | const auto *InheritedFrom = D->getDefaultArgStorage().getInheritedFrom(); |
937 | 1 | Visit(D->getDefaultArgument().getArgument(), |
938 | 1 | InheritedFrom ? InheritedFrom->getSourceRange()0 : SourceLocation{}, |
939 | 1 | InheritedFrom, |
940 | 1 | D->defaultArgumentWasInherited() ? "inherited from"0 : "previous"); |
941 | 1 | }); |
942 | 2 | } |
943 | | |
944 | 0 | void JSONNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *LSD) { |
945 | 0 | StringRef Lang; |
946 | 0 | switch (LSD->getLanguage()) { |
947 | 0 | case LinkageSpecDecl::lang_c: Lang = "C"; break; |
948 | 0 | case LinkageSpecDecl::lang_cxx: Lang = "C++"; break; |
949 | 0 | } |
950 | 0 | JOS.attribute("language", Lang); |
951 | 0 | attributeOnlyIfTrue("hasBraces", LSD->hasBraces()); |
952 | 0 | } |
953 | | |
954 | 49 | void JSONNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *ASD) { |
955 | 49 | JOS.attribute("access", createAccessSpecifier(ASD->getAccess())); |
956 | 49 | } |
957 | | |
958 | 2 | void JSONNodeDumper::VisitFriendDecl(const FriendDecl *FD) { |
959 | 2 | if (const TypeSourceInfo *T = FD->getFriendType()) |
960 | 1 | JOS.attribute("type", createQualType(T->getType())); |
961 | 2 | } |
962 | | |
963 | 8 | void JSONNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) { |
964 | 8 | VisitNamedDecl(D); |
965 | 8 | JOS.attribute("type", createQualType(D->getType())); |
966 | 8 | attributeOnlyIfTrue("synthesized", D->getSynthesize()); |
967 | 8 | switch (D->getAccessControl()) { |
968 | 0 | case ObjCIvarDecl::None: JOS.attribute("access", "none"); break; |
969 | 5 | case ObjCIvarDecl::Private: JOS.attribute("access", "private"); break; |
970 | 1 | case ObjCIvarDecl::Protected: JOS.attribute("access", "protected"); break; |
971 | 1 | case ObjCIvarDecl::Public: JOS.attribute("access", "public"); break; |
972 | 1 | case ObjCIvarDecl::Package: JOS.attribute("access", "package"); break; |
973 | 8 | } |
974 | 8 | } |
975 | | |
976 | 15 | void JSONNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) { |
977 | 15 | VisitNamedDecl(D); |
978 | 15 | JOS.attribute("returnType", createQualType(D->getReturnType())); |
979 | 15 | JOS.attribute("instance", D->isInstanceMethod()); |
980 | 15 | attributeOnlyIfTrue("variadic", D->isVariadic()); |
981 | 15 | } |
982 | | |
983 | 1 | void JSONNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) { |
984 | 1 | VisitNamedDecl(D); |
985 | 1 | JOS.attribute("type", createQualType(D->getUnderlyingType())); |
986 | 1 | attributeOnlyIfTrue("bounded", D->hasExplicitBound()); |
987 | 1 | switch (D->getVariance()) { |
988 | 1 | case ObjCTypeParamVariance::Invariant: |
989 | 1 | break; |
990 | 0 | case ObjCTypeParamVariance::Covariant: |
991 | 0 | JOS.attribute("variance", "covariant"); |
992 | 0 | break; |
993 | 0 | case ObjCTypeParamVariance::Contravariant: |
994 | 0 | JOS.attribute("variance", "contravariant"); |
995 | 0 | break; |
996 | 1 | } |
997 | 1 | } |
998 | | |
999 | 1 | void JSONNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { |
1000 | 1 | VisitNamedDecl(D); |
1001 | 1 | JOS.attribute("interface", createBareDeclRef(D->getClassInterface())); |
1002 | 1 | JOS.attribute("implementation", createBareDeclRef(D->getImplementation())); |
1003 | | |
1004 | 1 | llvm::json::Array Protocols; |
1005 | 1 | for (const auto* P : D->protocols()) |
1006 | 1 | Protocols.push_back(createBareDeclRef(P)); |
1007 | 1 | if (!Protocols.empty()) |
1008 | 1 | JOS.attribute("protocols", std::move(Protocols)); |
1009 | 1 | } |
1010 | | |
1011 | 1 | void JSONNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { |
1012 | 1 | VisitNamedDecl(D); |
1013 | 1 | JOS.attribute("interface", createBareDeclRef(D->getClassInterface())); |
1014 | 1 | JOS.attribute("categoryDecl", createBareDeclRef(D->getCategoryDecl())); |
1015 | 1 | } |
1016 | | |
1017 | 1 | void JSONNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { |
1018 | 1 | VisitNamedDecl(D); |
1019 | | |
1020 | 1 | llvm::json::Array Protocols; |
1021 | 1 | for (const auto *P : D->protocols()) |
1022 | 0 | Protocols.push_back(createBareDeclRef(P)); |
1023 | 1 | if (!Protocols.empty()) |
1024 | 0 | JOS.attribute("protocols", std::move(Protocols)); |
1025 | 1 | } |
1026 | | |
1027 | 4 | void JSONNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { |
1028 | 4 | VisitNamedDecl(D); |
1029 | 4 | JOS.attribute("super", createBareDeclRef(D->getSuperClass())); |
1030 | 4 | JOS.attribute("implementation", createBareDeclRef(D->getImplementation())); |
1031 | | |
1032 | 4 | llvm::json::Array Protocols; |
1033 | 4 | for (const auto* P : D->protocols()) |
1034 | 2 | Protocols.push_back(createBareDeclRef(P)); |
1035 | 4 | if (!Protocols.empty()) |
1036 | 2 | JOS.attribute("protocols", std::move(Protocols)); |
1037 | 4 | } |
1038 | | |
1039 | | void JSONNodeDumper::VisitObjCImplementationDecl( |
1040 | 3 | const ObjCImplementationDecl *D) { |
1041 | 3 | VisitNamedDecl(D); |
1042 | 3 | JOS.attribute("super", createBareDeclRef(D->getSuperClass())); |
1043 | 3 | JOS.attribute("interface", createBareDeclRef(D->getClassInterface())); |
1044 | 3 | } |
1045 | | |
1046 | | void JSONNodeDumper::VisitObjCCompatibleAliasDecl( |
1047 | 1 | const ObjCCompatibleAliasDecl *D) { |
1048 | 1 | VisitNamedDecl(D); |
1049 | 1 | JOS.attribute("interface", createBareDeclRef(D->getClassInterface())); |
1050 | 1 | } |
1051 | | |
1052 | 2 | void JSONNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { |
1053 | 2 | VisitNamedDecl(D); |
1054 | 2 | JOS.attribute("type", createQualType(D->getType())); |
1055 | | |
1056 | 2 | switch (D->getPropertyImplementation()) { |
1057 | 2 | case ObjCPropertyDecl::None: break; |
1058 | 0 | case ObjCPropertyDecl::Required: JOS.attribute("control", "required"); break; |
1059 | 0 | case ObjCPropertyDecl::Optional: JOS.attribute("control", "optional"); break; |
1060 | 2 | } |
1061 | | |
1062 | 2 | ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes(); |
1063 | 2 | if (Attrs != ObjCPropertyAttribute::kind_noattr) { |
1064 | 2 | if (Attrs & ObjCPropertyAttribute::kind_getter) |
1065 | 1 | JOS.attribute("getter", createBareDeclRef(D->getGetterMethodDecl())); |
1066 | 2 | if (Attrs & ObjCPropertyAttribute::kind_setter) |
1067 | 1 | JOS.attribute("setter", createBareDeclRef(D->getSetterMethodDecl())); |
1068 | 2 | attributeOnlyIfTrue("readonly", |
1069 | 2 | Attrs & ObjCPropertyAttribute::kind_readonly); |
1070 | 2 | attributeOnlyIfTrue("assign", Attrs & ObjCPropertyAttribute::kind_assign); |
1071 | 2 | attributeOnlyIfTrue("readwrite", |
1072 | 2 | Attrs & ObjCPropertyAttribute::kind_readwrite); |
1073 | 2 | attributeOnlyIfTrue("retain", Attrs & ObjCPropertyAttribute::kind_retain); |
1074 | 2 | attributeOnlyIfTrue("copy", Attrs & ObjCPropertyAttribute::kind_copy); |
1075 | 2 | attributeOnlyIfTrue("nonatomic", |
1076 | 2 | Attrs & ObjCPropertyAttribute::kind_nonatomic); |
1077 | 2 | attributeOnlyIfTrue("atomic", Attrs & ObjCPropertyAttribute::kind_atomic); |
1078 | 2 | attributeOnlyIfTrue("weak", Attrs & ObjCPropertyAttribute::kind_weak); |
1079 | 2 | attributeOnlyIfTrue("strong", Attrs & ObjCPropertyAttribute::kind_strong); |
1080 | 2 | attributeOnlyIfTrue("unsafe_unretained", |
1081 | 2 | Attrs & ObjCPropertyAttribute::kind_unsafe_unretained); |
1082 | 2 | attributeOnlyIfTrue("class", Attrs & ObjCPropertyAttribute::kind_class); |
1083 | 2 | attributeOnlyIfTrue("direct", Attrs & ObjCPropertyAttribute::kind_direct); |
1084 | 2 | attributeOnlyIfTrue("nullability", |
1085 | 2 | Attrs & ObjCPropertyAttribute::kind_nullability); |
1086 | 2 | attributeOnlyIfTrue("null_resettable", |
1087 | 2 | Attrs & ObjCPropertyAttribute::kind_null_resettable); |
1088 | 2 | } |
1089 | 2 | } |
1090 | | |
1091 | 2 | void JSONNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { |
1092 | 2 | VisitNamedDecl(D->getPropertyDecl()); |
1093 | 2 | JOS.attribute("implKind", D->getPropertyImplementation() == |
1094 | 2 | ObjCPropertyImplDecl::Synthesize |
1095 | 2 | ? "synthesize" |
1096 | 2 | : "dynamic"0 ); |
1097 | 2 | JOS.attribute("propertyDecl", createBareDeclRef(D->getPropertyDecl())); |
1098 | 2 | JOS.attribute("ivarDecl", createBareDeclRef(D->getPropertyIvarDecl())); |
1099 | 2 | } |
1100 | | |
1101 | 3 | void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) { |
1102 | 3 | attributeOnlyIfTrue("variadic", D->isVariadic()); |
1103 | 3 | attributeOnlyIfTrue("capturesThis", D->capturesCXXThis()); |
1104 | 3 | } |
1105 | | |
1106 | 2 | void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) { |
1107 | 2 | JOS.attribute("encodedType", createQualType(OEE->getEncodedType())); |
1108 | 2 | } |
1109 | | |
1110 | 9 | void JSONNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *OME) { |
1111 | 9 | std::string Str; |
1112 | 9 | llvm::raw_string_ostream OS(Str); |
1113 | | |
1114 | 9 | OME->getSelector().print(OS); |
1115 | 9 | JOS.attribute("selector", OS.str()); |
1116 | | |
1117 | 9 | switch (OME->getReceiverKind()) { |
1118 | 8 | case ObjCMessageExpr::Instance: |
1119 | 8 | JOS.attribute("receiverKind", "instance"); |
1120 | 8 | break; |
1121 | 1 | case ObjCMessageExpr::Class: |
1122 | 1 | JOS.attribute("receiverKind", "class"); |
1123 | 1 | JOS.attribute("classType", createQualType(OME->getClassReceiver())); |
1124 | 1 | break; |
1125 | 0 | case ObjCMessageExpr::SuperInstance: |
1126 | 0 | JOS.attribute("receiverKind", "super (instance)"); |
1127 | 0 | JOS.attribute("superType", createQualType(OME->getSuperType())); |
1128 | 0 | break; |
1129 | 0 | case ObjCMessageExpr::SuperClass: |
1130 | 0 | JOS.attribute("receiverKind", "super (class)"); |
1131 | 0 | JOS.attribute("superType", createQualType(OME->getSuperType())); |
1132 | 0 | break; |
1133 | 9 | } |
1134 | | |
1135 | 9 | QualType CallReturnTy = OME->getCallReturnType(Ctx); |
1136 | 9 | if (OME->getType() != CallReturnTy) |
1137 | 0 | JOS.attribute("callReturnType", createQualType(CallReturnTy)); |
1138 | 9 | } |
1139 | | |
1140 | 1 | void JSONNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE) { |
1141 | 1 | if (const ObjCMethodDecl *MD = OBE->getBoxingMethod()) { |
1142 | 1 | std::string Str; |
1143 | 1 | llvm::raw_string_ostream OS(Str); |
1144 | | |
1145 | 1 | MD->getSelector().print(OS); |
1146 | 1 | JOS.attribute("selector", OS.str()); |
1147 | 1 | } |
1148 | 1 | } |
1149 | | |
1150 | 1 | void JSONNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE) { |
1151 | 1 | std::string Str; |
1152 | 1 | llvm::raw_string_ostream OS(Str); |
1153 | | |
1154 | 1 | OSE->getSelector().print(OS); |
1155 | 1 | JOS.attribute("selector", OS.str()); |
1156 | 1 | } |
1157 | | |
1158 | 1 | void JSONNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) { |
1159 | 1 | JOS.attribute("protocol", createBareDeclRef(OPE->getProtocol())); |
1160 | 1 | } |
1161 | | |
1162 | 2 | void JSONNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) { |
1163 | 2 | if (OPRE->isImplicitProperty()) { |
1164 | 0 | JOS.attribute("propertyKind", "implicit"); |
1165 | 0 | if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertyGetter()) |
1166 | 0 | JOS.attribute("getter", createBareDeclRef(MD)); |
1167 | 0 | if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertySetter()) |
1168 | 0 | JOS.attribute("setter", createBareDeclRef(MD)); |
1169 | 2 | } else { |
1170 | 2 | JOS.attribute("propertyKind", "explicit"); |
1171 | 2 | JOS.attribute("property", createBareDeclRef(OPRE->getExplicitProperty())); |
1172 | 2 | } |
1173 | | |
1174 | 2 | attributeOnlyIfTrue("isSuperReceiver", OPRE->isSuperReceiver()); |
1175 | 2 | attributeOnlyIfTrue("isMessagingGetter", OPRE->isMessagingGetter()); |
1176 | 2 | attributeOnlyIfTrue("isMessagingSetter", OPRE->isMessagingSetter()); |
1177 | 2 | } |
1178 | | |
1179 | | void JSONNodeDumper::VisitObjCSubscriptRefExpr( |
1180 | 4 | const ObjCSubscriptRefExpr *OSRE) { |
1181 | 4 | JOS.attribute("subscriptKind", |
1182 | 4 | OSRE->isArraySubscriptRefExpr() ? "array"2 : "dictionary"2 ); |
1183 | | |
1184 | 4 | if (const ObjCMethodDecl *MD = OSRE->getAtIndexMethodDecl()) |
1185 | 0 | JOS.attribute("getter", createBareDeclRef(MD)); |
1186 | 4 | if (const ObjCMethodDecl *MD = OSRE->setAtIndexMethodDecl()) |
1187 | 0 | JOS.attribute("setter", createBareDeclRef(MD)); |
1188 | 4 | } |
1189 | | |
1190 | 1 | void JSONNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE) { |
1191 | 1 | JOS.attribute("decl", createBareDeclRef(OIRE->getDecl())); |
1192 | 1 | attributeOnlyIfTrue("isFreeIvar", OIRE->isFreeIvar()); |
1193 | 1 | JOS.attribute("isArrow", OIRE->isArrow()); |
1194 | 1 | } |
1195 | | |
1196 | 2 | void JSONNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE) { |
1197 | 2 | JOS.attribute("value", OBLE->getValue() ? "__objc_yes"1 : "__objc_no"1 ); |
1198 | 2 | } |
1199 | | |
1200 | 478 | void JSONNodeDumper::VisitDeclRefExpr(const DeclRefExpr *DRE) { |
1201 | 478 | JOS.attribute("referencedDecl", createBareDeclRef(DRE->getDecl())); |
1202 | 478 | if (DRE->getDecl() != DRE->getFoundDecl()) |
1203 | 4 | JOS.attribute("foundReferencedDecl", |
1204 | 4 | createBareDeclRef(DRE->getFoundDecl())); |
1205 | 478 | switch (DRE->isNonOdrUse()) { |
1206 | 453 | case NOUR_None: break; |
1207 | 24 | case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break; |
1208 | 1 | case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break; |
1209 | 0 | case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break; |
1210 | 478 | } |
1211 | 478 | } |
1212 | | |
1213 | | void JSONNodeDumper::VisitSYCLUniqueStableNameExpr( |
1214 | 0 | const SYCLUniqueStableNameExpr *E) { |
1215 | 0 | JOS.attribute("typeSourceInfo", |
1216 | 0 | createQualType(E->getTypeSourceInfo()->getType())); |
1217 | 0 | } |
1218 | | |
1219 | 0 | void JSONNodeDumper::VisitPredefinedExpr(const PredefinedExpr *PE) { |
1220 | 0 | JOS.attribute("name", PredefinedExpr::getIdentKindName(PE->getIdentKind())); |
1221 | 0 | } |
1222 | | |
1223 | 46 | void JSONNodeDumper::VisitUnaryOperator(const UnaryOperator *UO) { |
1224 | 46 | JOS.attribute("isPostfix", UO->isPostfix()); |
1225 | 46 | JOS.attribute("opcode", UnaryOperator::getOpcodeStr(UO->getOpcode())); |
1226 | 46 | if (!UO->canOverflow()) |
1227 | 20 | JOS.attribute("canOverflow", false); |
1228 | 46 | } |
1229 | | |
1230 | 214 | void JSONNodeDumper::VisitBinaryOperator(const BinaryOperator *BO) { |
1231 | 214 | JOS.attribute("opcode", BinaryOperator::getOpcodeStr(BO->getOpcode())); |
1232 | 214 | } |
1233 | | |
1234 | | void JSONNodeDumper::VisitCompoundAssignOperator( |
1235 | 1 | const CompoundAssignOperator *CAO) { |
1236 | 1 | VisitBinaryOperator(CAO); |
1237 | 1 | JOS.attribute("computeLHSType", createQualType(CAO->getComputationLHSType())); |
1238 | 1 | JOS.attribute("computeResultType", |
1239 | 1 | createQualType(CAO->getComputationResultType())); |
1240 | 1 | } |
1241 | | |
1242 | 60 | void JSONNodeDumper::VisitMemberExpr(const MemberExpr *ME) { |
1243 | | // Note, we always write this Boolean field because the information it conveys |
1244 | | // is critical to understanding the AST node. |
1245 | 60 | ValueDecl *VD = ME->getMemberDecl(); |
1246 | 60 | JOS.attribute("name", VD && VD->getDeclName() ? VD->getNameAsString() : ""0 ); |
1247 | 60 | JOS.attribute("isArrow", ME->isArrow()); |
1248 | 60 | JOS.attribute("referencedMemberDecl", createPointerRepresentation(VD)); |
1249 | 60 | switch (ME->isNonOdrUse()) { |
1250 | 60 | case NOUR_None: break; |
1251 | 0 | case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break; |
1252 | 0 | case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break; |
1253 | 0 | case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break; |
1254 | 60 | } |
1255 | 60 | } |
1256 | | |
1257 | 11 | void JSONNodeDumper::VisitCXXNewExpr(const CXXNewExpr *NE) { |
1258 | 11 | attributeOnlyIfTrue("isGlobal", NE->isGlobalNew()); |
1259 | 11 | attributeOnlyIfTrue("isArray", NE->isArray()); |
1260 | 11 | attributeOnlyIfTrue("isPlacement", NE->getNumPlacementArgs() != 0); |
1261 | 11 | switch (NE->getInitializationStyle()) { |
1262 | 8 | case CXXNewExpr::NoInit: break; |
1263 | 0 | case CXXNewExpr::CallInit: JOS.attribute("initStyle", "call"); break; |
1264 | 3 | case CXXNewExpr::ListInit: JOS.attribute("initStyle", "list"); break; |
1265 | 11 | } |
1266 | 11 | if (const FunctionDecl *FD = NE->getOperatorNew()) |
1267 | 10 | JOS.attribute("operatorNewDecl", createBareDeclRef(FD)); |
1268 | 11 | if (const FunctionDecl *FD = NE->getOperatorDelete()) |
1269 | 0 | JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD)); |
1270 | 11 | } |
1271 | 6 | void JSONNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *DE) { |
1272 | 6 | attributeOnlyIfTrue("isGlobal", DE->isGlobalDelete()); |
1273 | 6 | attributeOnlyIfTrue("isArray", DE->isArrayForm()); |
1274 | 6 | attributeOnlyIfTrue("isArrayAsWritten", DE->isArrayFormAsWritten()); |
1275 | 6 | if (const FunctionDecl *FD = DE->getOperatorDelete()) |
1276 | 5 | JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD)); |
1277 | 6 | } |
1278 | | |
1279 | 33 | void JSONNodeDumper::VisitCXXThisExpr(const CXXThisExpr *TE) { |
1280 | 33 | attributeOnlyIfTrue("implicit", TE->isImplicit()); |
1281 | 33 | } |
1282 | | |
1283 | 498 | void JSONNodeDumper::VisitCastExpr(const CastExpr *CE) { |
1284 | 498 | JOS.attribute("castKind", CE->getCastKindName()); |
1285 | 498 | llvm::json::Array Path = createCastPath(CE); |
1286 | 498 | if (!Path.empty()) |
1287 | 1 | JOS.attribute("path", std::move(Path)); |
1288 | | // FIXME: This may not be useful information as it can be obtusely gleaned |
1289 | | // from the inner[] array. |
1290 | 498 | if (const NamedDecl *ND = CE->getConversionFunction()) |
1291 | 0 | JOS.attribute("conversionFunc", createBareDeclRef(ND)); |
1292 | 498 | } |
1293 | | |
1294 | 469 | void JSONNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *ICE) { |
1295 | 469 | VisitCastExpr(ICE); |
1296 | 469 | attributeOnlyIfTrue("isPartOfExplicitCast", ICE->isPartOfExplicitCast()); |
1297 | 469 | } |
1298 | | |
1299 | 56 | void JSONNodeDumper::VisitCallExpr(const CallExpr *CE) { |
1300 | 56 | attributeOnlyIfTrue("adl", CE->usesADL()); |
1301 | 56 | } |
1302 | | |
1303 | | void JSONNodeDumper::VisitUnaryExprOrTypeTraitExpr( |
1304 | 6 | const UnaryExprOrTypeTraitExpr *TTE) { |
1305 | 6 | JOS.attribute("name", getTraitSpelling(TTE->getKind())); |
1306 | 6 | if (TTE->isArgumentType()) |
1307 | 2 | JOS.attribute("argType", createQualType(TTE->getArgumentType())); |
1308 | 6 | } |
1309 | | |
1310 | 1 | void JSONNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE) { |
1311 | 1 | VisitNamedDecl(SOPE->getPack()); |
1312 | 1 | } |
1313 | | |
1314 | | void JSONNodeDumper::VisitUnresolvedLookupExpr( |
1315 | 1 | const UnresolvedLookupExpr *ULE) { |
1316 | 1 | JOS.attribute("usesADL", ULE->requiresADL()); |
1317 | 1 | JOS.attribute("name", ULE->getName().getAsString()); |
1318 | | |
1319 | 1 | JOS.attributeArray("lookups", [this, ULE] { |
1320 | 1 | for (const NamedDecl *D : ULE->decls()) |
1321 | 0 | JOS.value(createBareDeclRef(D)); |
1322 | 1 | }); |
1323 | 1 | } |
1324 | | |
1325 | 1 | void JSONNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *ALE) { |
1326 | 1 | JOS.attribute("name", ALE->getLabel()->getName()); |
1327 | 1 | JOS.attribute("labelDeclId", createPointerRepresentation(ALE->getLabel())); |
1328 | 1 | } |
1329 | | |
1330 | 3 | void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) { |
1331 | 3 | if (CTE->isTypeOperand()) { |
1332 | 2 | QualType Adjusted = CTE->getTypeOperand(Ctx); |
1333 | 2 | QualType Unadjusted = CTE->getTypeOperandSourceInfo()->getType(); |
1334 | 2 | JOS.attribute("typeArg", createQualType(Unadjusted)); |
1335 | 2 | if (Adjusted != Unadjusted) |
1336 | 1 | JOS.attribute("adjustedTypeArg", createQualType(Adjusted)); |
1337 | 2 | } |
1338 | 3 | } |
1339 | | |
1340 | 16 | void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) { |
1341 | 16 | if (CE->getResultAPValueKind() != APValue::None) |
1342 | 11 | Visit(CE->getAPValueResult(), CE->getType()); |
1343 | 16 | } |
1344 | | |
1345 | 10 | void JSONNodeDumper::VisitInitListExpr(const InitListExpr *ILE) { |
1346 | 10 | if (const FieldDecl *FD = ILE->getInitializedFieldInUnion()) |
1347 | 2 | JOS.attribute("field", createBareDeclRef(FD)); |
1348 | 10 | } |
1349 | | |
1350 | | void JSONNodeDumper::VisitGenericSelectionExpr( |
1351 | 7 | const GenericSelectionExpr *GSE) { |
1352 | 7 | attributeOnlyIfTrue("resultDependent", GSE->isResultDependent()); |
1353 | 7 | } |
1354 | | |
1355 | | void JSONNodeDumper::VisitCXXUnresolvedConstructExpr( |
1356 | 4 | const CXXUnresolvedConstructExpr *UCE) { |
1357 | 4 | if (UCE->getType() != UCE->getTypeAsWritten()) |
1358 | 0 | JOS.attribute("typeAsWritten", createQualType(UCE->getTypeAsWritten())); |
1359 | 4 | attributeOnlyIfTrue("list", UCE->isListInitialization()); |
1360 | 4 | } |
1361 | | |
1362 | 20 | void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) { |
1363 | 20 | CXXConstructorDecl *Ctor = CE->getConstructor(); |
1364 | 20 | JOS.attribute("ctorType", createQualType(Ctor->getType())); |
1365 | 20 | attributeOnlyIfTrue("elidable", CE->isElidable()); |
1366 | 20 | attributeOnlyIfTrue("list", CE->isListInitialization()); |
1367 | 20 | attributeOnlyIfTrue("initializer_list", CE->isStdInitListInitialization()); |
1368 | 20 | attributeOnlyIfTrue("zeroing", CE->requiresZeroInitialization()); |
1369 | 20 | attributeOnlyIfTrue("hadMultipleCandidates", CE->hadMultipleCandidates()); |
1370 | | |
1371 | 20 | switch (CE->getConstructionKind()) { |
1372 | 18 | case CXXConstructExpr::CK_Complete: |
1373 | 18 | JOS.attribute("constructionKind", "complete"); |
1374 | 18 | break; |
1375 | 0 | case CXXConstructExpr::CK_Delegating: |
1376 | 0 | JOS.attribute("constructionKind", "delegating"); |
1377 | 0 | break; |
1378 | 2 | case CXXConstructExpr::CK_NonVirtualBase: |
1379 | 2 | JOS.attribute("constructionKind", "non-virtual base"); |
1380 | 2 | break; |
1381 | 0 | case CXXConstructExpr::CK_VirtualBase: |
1382 | 0 | JOS.attribute("constructionKind", "virtual base"); |
1383 | 0 | break; |
1384 | 20 | } |
1385 | 20 | } |
1386 | | |
1387 | 9 | void JSONNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *EWC) { |
1388 | 9 | attributeOnlyIfTrue("cleanupsHaveSideEffects", |
1389 | 9 | EWC->cleanupsHaveSideEffects()); |
1390 | 9 | if (EWC->getNumObjects()) { |
1391 | 4 | JOS.attributeArray("cleanups", [this, EWC] { |
1392 | 4 | for (const ExprWithCleanups::CleanupObject &CO : EWC->getObjects()) |
1393 | 4 | if (auto *BD = CO.dyn_cast<BlockDecl *>()) { |
1394 | 3 | JOS.value(createBareDeclRef(BD)); |
1395 | 3 | } else if (auto *1 CLE1 = CO.dyn_cast<CompoundLiteralExpr *>()) { |
1396 | 1 | llvm::json::Object Obj; |
1397 | 1 | Obj["id"] = createPointerRepresentation(CLE); |
1398 | 1 | Obj["kind"] = CLE->getStmtClassName(); |
1399 | 1 | JOS.value(std::move(Obj)); |
1400 | 1 | } else { |
1401 | 0 | llvm_unreachable("unexpected cleanup object type"); |
1402 | 0 | } |
1403 | 4 | }); |
1404 | 4 | } |
1405 | 9 | } |
1406 | | |
1407 | | void JSONNodeDumper::VisitCXXBindTemporaryExpr( |
1408 | 1 | const CXXBindTemporaryExpr *BTE) { |
1409 | 1 | const CXXTemporary *Temp = BTE->getTemporary(); |
1410 | 1 | JOS.attribute("temp", createPointerRepresentation(Temp)); |
1411 | 1 | if (const CXXDestructorDecl *Dtor = Temp->getDestructor()) |
1412 | 1 | JOS.attribute("dtor", createBareDeclRef(Dtor)); |
1413 | 1 | } |
1414 | | |
1415 | | void JSONNodeDumper::VisitMaterializeTemporaryExpr( |
1416 | 5 | const MaterializeTemporaryExpr *MTE) { |
1417 | 5 | if (const ValueDecl *VD = MTE->getExtendingDecl()) |
1418 | 4 | JOS.attribute("extendingDecl", createBareDeclRef(VD)); |
1419 | | |
1420 | 5 | switch (MTE->getStorageDuration()) { |
1421 | 4 | case SD_Automatic: |
1422 | 4 | JOS.attribute("storageDuration", "automatic"); |
1423 | 4 | break; |
1424 | 0 | case SD_Dynamic: |
1425 | 0 | JOS.attribute("storageDuration", "dynamic"); |
1426 | 0 | break; |
1427 | 1 | case SD_FullExpression: |
1428 | 1 | JOS.attribute("storageDuration", "full expression"); |
1429 | 1 | break; |
1430 | 0 | case SD_Static: |
1431 | 0 | JOS.attribute("storageDuration", "static"); |
1432 | 0 | break; |
1433 | 0 | case SD_Thread: |
1434 | 0 | JOS.attribute("storageDuration", "thread"); |
1435 | 0 | break; |
1436 | 5 | } |
1437 | | |
1438 | 5 | attributeOnlyIfTrue("boundToLValueRef", MTE->isBoundToLvalueReference()); |
1439 | 5 | } |
1440 | | |
1441 | | void JSONNodeDumper::VisitCXXDependentScopeMemberExpr( |
1442 | 8 | const CXXDependentScopeMemberExpr *DSME) { |
1443 | 8 | JOS.attribute("isArrow", DSME->isArrow()); |
1444 | 8 | JOS.attribute("member", DSME->getMember().getAsString()); |
1445 | 8 | attributeOnlyIfTrue("hasTemplateKeyword", DSME->hasTemplateKeyword()); |
1446 | 8 | attributeOnlyIfTrue("hasExplicitTemplateArgs", |
1447 | 8 | DSME->hasExplicitTemplateArgs()); |
1448 | | |
1449 | 8 | if (DSME->getNumTemplateArgs()) { |
1450 | 1 | JOS.attributeArray("explicitTemplateArgs", [DSME, this] { |
1451 | 1 | for (const TemplateArgumentLoc &TAL : DSME->template_arguments()) |
1452 | 1 | JOS.object( |
1453 | 1 | [&TAL, this] { Visit(TAL.getArgument(), TAL.getSourceRange()); }); |
1454 | 1 | }); |
1455 | 1 | } |
1456 | 8 | } |
1457 | | |
1458 | 1 | void JSONNodeDumper::VisitRequiresExpr(const RequiresExpr *RE) { |
1459 | 1 | if (!RE->isValueDependent()) |
1460 | 0 | JOS.attribute("satisfied", RE->isSatisfied()); |
1461 | 1 | } |
1462 | | |
1463 | 322 | void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) { |
1464 | 322 | llvm::SmallString<16> Buffer; |
1465 | 322 | IL->getValue().toString(Buffer, |
1466 | 322 | /*Radix=*/10, IL->getType()->isSignedIntegerType()); |
1467 | 322 | JOS.attribute("value", Buffer); |
1468 | 322 | } |
1469 | 2 | void JSONNodeDumper::VisitCharacterLiteral(const CharacterLiteral *CL) { |
1470 | | // FIXME: This should probably print the character literal as a string, |
1471 | | // rather than as a numerical value. It would be nice if the behavior matched |
1472 | | // what we do to print a string literal; right now, it is impossible to tell |
1473 | | // the difference between 'a' and L'a' in C from the JSON output. |
1474 | 2 | JOS.attribute("value", CL->getValue()); |
1475 | 2 | } |
1476 | 0 | void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) { |
1477 | 0 | JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10)); |
1478 | 0 | } |
1479 | 22 | void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) { |
1480 | 22 | llvm::SmallString<16> Buffer; |
1481 | 22 | FL->getValue().toString(Buffer); |
1482 | 22 | JOS.attribute("value", Buffer); |
1483 | 22 | } |
1484 | 12 | void JSONNodeDumper::VisitStringLiteral(const StringLiteral *SL) { |
1485 | 12 | std::string Buffer; |
1486 | 12 | llvm::raw_string_ostream SS(Buffer); |
1487 | 12 | SL->outputString(SS); |
1488 | 12 | JOS.attribute("value", SS.str()); |
1489 | 12 | } |
1490 | 5 | void JSONNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE) { |
1491 | 5 | JOS.attribute("value", BLE->getValue()); |
1492 | 5 | } |
1493 | | |
1494 | 23 | void JSONNodeDumper::VisitIfStmt(const IfStmt *IS) { |
1495 | 23 | attributeOnlyIfTrue("hasInit", IS->hasInitStorage()); |
1496 | 23 | attributeOnlyIfTrue("hasVar", IS->hasVarStorage()); |
1497 | 23 | attributeOnlyIfTrue("hasElse", IS->hasElseStorage()); |
1498 | 23 | attributeOnlyIfTrue("isConstexpr", IS->isConstexpr()); |
1499 | 23 | attributeOnlyIfTrue("isConsteval", IS->isConsteval()); |
1500 | 23 | attributeOnlyIfTrue("constevalIsNegated", IS->isNegatedConsteval()); |
1501 | 23 | } |
1502 | | |
1503 | 2 | void JSONNodeDumper::VisitSwitchStmt(const SwitchStmt *SS) { |
1504 | 2 | attributeOnlyIfTrue("hasInit", SS->hasInitStorage()); |
1505 | 2 | attributeOnlyIfTrue("hasVar", SS->hasVarStorage()); |
1506 | 2 | } |
1507 | 4 | void JSONNodeDumper::VisitCaseStmt(const CaseStmt *CS) { |
1508 | 4 | attributeOnlyIfTrue("isGNURange", CS->caseStmtIsGNURange()); |
1509 | 4 | } |
1510 | | |
1511 | 2 | void JSONNodeDumper::VisitLabelStmt(const LabelStmt *LS) { |
1512 | 2 | JOS.attribute("name", LS->getName()); |
1513 | 2 | JOS.attribute("declId", createPointerRepresentation(LS->getDecl())); |
1514 | 2 | attributeOnlyIfTrue("sideEntry", LS->isSideEntry()); |
1515 | 2 | } |
1516 | 1 | void JSONNodeDumper::VisitGotoStmt(const GotoStmt *GS) { |
1517 | 1 | JOS.attribute("targetLabelDeclId", |
1518 | 1 | createPointerRepresentation(GS->getLabel())); |
1519 | 1 | } |
1520 | | |
1521 | 2 | void JSONNodeDumper::VisitWhileStmt(const WhileStmt *WS) { |
1522 | 2 | attributeOnlyIfTrue("hasVar", WS->hasVarStorage()); |
1523 | 2 | } |
1524 | | |
1525 | 2 | void JSONNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt* OACS) { |
1526 | | // FIXME: it would be nice for the ASTNodeTraverser would handle the catch |
1527 | | // parameter the same way for C++ and ObjC rather. In this case, C++ gets a |
1528 | | // null child node and ObjC gets no child node. |
1529 | 2 | attributeOnlyIfTrue("isCatchAll", OACS->getCatchParamDecl() == nullptr); |
1530 | 2 | } |
1531 | | |
1532 | 0 | void JSONNodeDumper::VisitNullTemplateArgument(const TemplateArgument &TA) { |
1533 | 0 | JOS.attribute("isNull", true); |
1534 | 0 | } |
1535 | 28 | void JSONNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) { |
1536 | 28 | JOS.attribute("type", createQualType(TA.getAsType())); |
1537 | 28 | } |
1538 | | void JSONNodeDumper::VisitDeclarationTemplateArgument( |
1539 | 0 | const TemplateArgument &TA) { |
1540 | 0 | JOS.attribute("decl", createBareDeclRef(TA.getAsDecl())); |
1541 | 0 | } |
1542 | 0 | void JSONNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) { |
1543 | 0 | JOS.attribute("isNullptr", true); |
1544 | 0 | } |
1545 | 13 | void JSONNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) { |
1546 | 13 | JOS.attribute("value", TA.getAsIntegral().getSExtValue()); |
1547 | 13 | } |
1548 | 2 | void JSONNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) { |
1549 | | // FIXME: cannot just call dump() on the argument, as that doesn't specify |
1550 | | // the output format. |
1551 | 2 | } |
1552 | | void JSONNodeDumper::VisitTemplateExpansionTemplateArgument( |
1553 | 0 | const TemplateArgument &TA) { |
1554 | | // FIXME: cannot just call dump() on the argument, as that doesn't specify |
1555 | | // the output format. |
1556 | 0 | } |
1557 | | void JSONNodeDumper::VisitExpressionTemplateArgument( |
1558 | 0 | const TemplateArgument &TA) { |
1559 | 0 | JOS.attribute("isExpr", true); |
1560 | 0 | } |
1561 | 0 | void JSONNodeDumper::VisitPackTemplateArgument(const TemplateArgument &TA) { |
1562 | 0 | JOS.attribute("isPack", true); |
1563 | 0 | } |
1564 | | |
1565 | 3 | StringRef JSONNodeDumper::getCommentCommandName(unsigned CommandID) const { |
1566 | 3 | if (Traits) |
1567 | 3 | return Traits->getCommandInfo(CommandID)->Name; |
1568 | 0 | if (const comments::CommandInfo *Info = |
1569 | 0 | comments::CommandTraits::getBuiltinCommandInfo(CommandID)) |
1570 | 0 | return Info->Name; |
1571 | 0 | return "<invalid>"; |
1572 | 0 | } |
1573 | | |
1574 | | void JSONNodeDumper::visitTextComment(const comments::TextComment *C, |
1575 | 21 | const comments::FullComment *) { |
1576 | 21 | JOS.attribute("text", C->getText()); |
1577 | 21 | } |
1578 | | |
1579 | | void JSONNodeDumper::visitInlineCommandComment( |
1580 | 1 | const comments::InlineCommandComment *C, const comments::FullComment *) { |
1581 | 1 | JOS.attribute("name", getCommentCommandName(C->getCommandID())); |
1582 | | |
1583 | 1 | switch (C->getRenderKind()) { |
1584 | 0 | case comments::InlineCommandComment::RenderNormal: |
1585 | 0 | JOS.attribute("renderKind", "normal"); |
1586 | 0 | break; |
1587 | 0 | case comments::InlineCommandComment::RenderBold: |
1588 | 0 | JOS.attribute("renderKind", "bold"); |
1589 | 0 | break; |
1590 | 0 | case comments::InlineCommandComment::RenderEmphasized: |
1591 | 0 | JOS.attribute("renderKind", "emphasized"); |
1592 | 0 | break; |
1593 | 1 | case comments::InlineCommandComment::RenderMonospaced: |
1594 | 1 | JOS.attribute("renderKind", "monospaced"); |
1595 | 1 | break; |
1596 | 0 | case comments::InlineCommandComment::RenderAnchor: |
1597 | 0 | JOS.attribute("renderKind", "anchor"); |
1598 | 0 | break; |
1599 | 1 | } |
1600 | | |
1601 | 1 | llvm::json::Array Args; |
1602 | 2 | for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I1 ) |
1603 | 1 | Args.push_back(C->getArgText(I)); |
1604 | | |
1605 | 1 | if (!Args.empty()) |
1606 | 1 | JOS.attribute("args", std::move(Args)); |
1607 | 1 | } |
1608 | | |
1609 | | void JSONNodeDumper::visitHTMLStartTagComment( |
1610 | 2 | const comments::HTMLStartTagComment *C, const comments::FullComment *) { |
1611 | 2 | JOS.attribute("name", C->getTagName()); |
1612 | 2 | attributeOnlyIfTrue("selfClosing", C->isSelfClosing()); |
1613 | 2 | attributeOnlyIfTrue("malformed", C->isMalformed()); |
1614 | | |
1615 | 2 | llvm::json::Array Attrs; |
1616 | 2 | for (unsigned I = 0, E = C->getNumAttrs(); I < E; ++I0 ) |
1617 | 0 | Attrs.push_back( |
1618 | 0 | {{"name", C->getAttr(I).Name}, {"value", C->getAttr(I).Value}}); |
1619 | | |
1620 | 2 | if (!Attrs.empty()) |
1621 | 0 | JOS.attribute("attrs", std::move(Attrs)); |
1622 | 2 | } |
1623 | | |
1624 | | void JSONNodeDumper::visitHTMLEndTagComment( |
1625 | 1 | const comments::HTMLEndTagComment *C, const comments::FullComment *) { |
1626 | 1 | JOS.attribute("name", C->getTagName()); |
1627 | 1 | } |
1628 | | |
1629 | | void JSONNodeDumper::visitBlockCommandComment( |
1630 | 1 | const comments::BlockCommandComment *C, const comments::FullComment *) { |
1631 | 1 | JOS.attribute("name", getCommentCommandName(C->getCommandID())); |
1632 | | |
1633 | 1 | llvm::json::Array Args; |
1634 | 1 | for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I0 ) |
1635 | 0 | Args.push_back(C->getArgText(I)); |
1636 | | |
1637 | 1 | if (!Args.empty()) |
1638 | 0 | JOS.attribute("args", std::move(Args)); |
1639 | 1 | } |
1640 | | |
1641 | | void JSONNodeDumper::visitParamCommandComment( |
1642 | 4 | const comments::ParamCommandComment *C, const comments::FullComment *FC) { |
1643 | 4 | switch (C->getDirection()) { |
1644 | 3 | case comments::ParamCommandComment::In: |
1645 | 3 | JOS.attribute("direction", "in"); |
1646 | 3 | break; |
1647 | 0 | case comments::ParamCommandComment::Out: |
1648 | 0 | JOS.attribute("direction", "out"); |
1649 | 0 | break; |
1650 | 1 | case comments::ParamCommandComment::InOut: |
1651 | 1 | JOS.attribute("direction", "in,out"); |
1652 | 1 | break; |
1653 | 4 | } |
1654 | 4 | attributeOnlyIfTrue("explicit", C->isDirectionExplicit()); |
1655 | | |
1656 | 4 | if (C->hasParamName()) |
1657 | 4 | JOS.attribute("param", C->isParamIndexValid() ? C->getParamName(FC) |
1658 | 4 | : C->getParamNameAsWritten()0 ); |
1659 | | |
1660 | 4 | if (C->isParamIndexValid() && !C->isVarArgParam()) |
1661 | 2 | JOS.attribute("paramIdx", C->getParamIndex()); |
1662 | 4 | } |
1663 | | |
1664 | | void JSONNodeDumper::visitTParamCommandComment( |
1665 | 2 | const comments::TParamCommandComment *C, const comments::FullComment *FC) { |
1666 | 2 | if (C->hasParamName()) |
1667 | 2 | JOS.attribute("param", C->isPositionValid() ? C->getParamName(FC)1 |
1668 | 2 | : C->getParamNameAsWritten()1 ); |
1669 | 2 | if (C->isPositionValid()) { |
1670 | 1 | llvm::json::Array Positions; |
1671 | 2 | for (unsigned I = 0, E = C->getDepth(); I < E; ++I1 ) |
1672 | 1 | Positions.push_back(C->getIndex(I)); |
1673 | | |
1674 | 1 | if (!Positions.empty()) |
1675 | 1 | JOS.attribute("positions", std::move(Positions)); |
1676 | 1 | } |
1677 | 2 | } |
1678 | | |
1679 | | void JSONNodeDumper::visitVerbatimBlockComment( |
1680 | 1 | const comments::VerbatimBlockComment *C, const comments::FullComment *) { |
1681 | 1 | JOS.attribute("name", getCommentCommandName(C->getCommandID())); |
1682 | 1 | JOS.attribute("closeName", C->getCloseName()); |
1683 | 1 | } |
1684 | | |
1685 | | void JSONNodeDumper::visitVerbatimBlockLineComment( |
1686 | | const comments::VerbatimBlockLineComment *C, |
1687 | 1 | const comments::FullComment *) { |
1688 | 1 | JOS.attribute("text", C->getText()); |
1689 | 1 | } |
1690 | | |
1691 | | void JSONNodeDumper::visitVerbatimLineComment( |
1692 | 0 | const comments::VerbatimLineComment *C, const comments::FullComment *) { |
1693 | 0 | JOS.attribute("text", C->getText()); |
1694 | 0 | } |
1695 | | |
1696 | 2 | llvm::json::Object JSONNodeDumper::createFPOptions(FPOptionsOverride FPO) { |
1697 | 2 | llvm::json::Object Ret; |
1698 | 2 | #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ |
1699 | 24 | if (FPO.has##NAME##Override()) \ |
1700 | 24 | Ret.try_emplace(#NAME, static_cast<unsigned>(FPO.get##NAME##Override()))2 ; |
1701 | 2 | #include "clang/Basic/FPOptions.def" |
1702 | 2 | return Ret; |
1703 | 2 | } |
1704 | | |
1705 | 321 | void JSONNodeDumper::VisitCompoundStmt(const CompoundStmt *S) { |
1706 | 321 | VisitStmt(S); |
1707 | 321 | if (S->hasStoredFPFeatures()) |
1708 | 2 | JOS.attribute("fpoptions", createFPOptions(S->getStoredFPFeatures())); |
1709 | 321 | } |