TextNodeDumper.cpp 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414
  1. //===--- TextNodeDumper.cpp - Printing of AST nodes -----------------------===//
  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 implements AST dumping of components of individual AST nodes.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/AST/TextNodeDumper.h"
  13. #include "clang/AST/APValue.h"
  14. #include "clang/AST/DeclFriend.h"
  15. #include "clang/AST/DeclOpenMP.h"
  16. #include "clang/AST/DeclTemplate.h"
  17. #include "clang/AST/LocInfoType.h"
  18. #include "clang/AST/Type.h"
  19. #include "clang/Basic/Module.h"
  20. #include "clang/Basic/SourceManager.h"
  21. #include "clang/Basic/Specifiers.h"
  22. #include "clang/Basic/TypeTraits.h"
  23. #include "llvm/ADT/StringExtras.h"
  24. #include <algorithm>
  25. #include <utility>
  26. using namespace clang;
  27. static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
  28. template <typename T>
  29. static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
  30. const T *First = D->getFirstDecl();
  31. if (First != D)
  32. OS << " first " << First;
  33. }
  34. template <typename T>
  35. static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
  36. const T *Prev = D->getPreviousDecl();
  37. if (Prev)
  38. OS << " prev " << Prev;
  39. }
  40. /// Dump the previous declaration in the redeclaration chain for a declaration,
  41. /// if any.
  42. static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
  43. switch (D->getKind()) {
  44. #define DECL(DERIVED, BASE) \
  45. case Decl::DERIVED: \
  46. return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
  47. #define ABSTRACT_DECL(DECL)
  48. #include "clang/AST/DeclNodes.inc"
  49. }
  50. llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
  51. }
  52. TextNodeDumper::TextNodeDumper(raw_ostream &OS, const ASTContext &Context,
  53. bool ShowColors)
  54. : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors),
  55. Context(&Context), SM(&Context.getSourceManager()),
  56. PrintPolicy(Context.getPrintingPolicy()),
  57. Traits(&Context.getCommentCommandTraits()) {}
  58. TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors)
  59. : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
  60. void TextNodeDumper::Visit(const comments::Comment *C,
  61. const comments::FullComment *FC) {
  62. if (!C) {
  63. ColorScope Color(OS, ShowColors, NullColor);
  64. OS << "<<<NULL>>>";
  65. return;
  66. }
  67. {
  68. ColorScope Color(OS, ShowColors, CommentColor);
  69. OS << C->getCommentKindName();
  70. }
  71. dumpPointer(C);
  72. dumpSourceRange(C->getSourceRange());
  73. ConstCommentVisitor<TextNodeDumper, void,
  74. const comments::FullComment *>::visit(C, FC);
  75. }
  76. void TextNodeDumper::Visit(const Attr *A) {
  77. {
  78. ColorScope Color(OS, ShowColors, AttrColor);
  79. switch (A->getKind()) {
  80. #define ATTR(X) \
  81. case attr::X: \
  82. OS << #X; \
  83. break;
  84. #include "clang/Basic/AttrList.inc"
  85. }
  86. OS << "Attr";
  87. }
  88. dumpPointer(A);
  89. dumpSourceRange(A->getRange());
  90. if (A->isInherited())
  91. OS << " Inherited";
  92. if (A->isImplicit())
  93. OS << " Implicit";
  94. ConstAttrVisitor<TextNodeDumper>::Visit(A);
  95. }
  96. void TextNodeDumper::Visit(const TemplateArgument &TA, SourceRange R,
  97. const Decl *From, StringRef Label) {
  98. OS << "TemplateArgument";
  99. if (R.isValid())
  100. dumpSourceRange(R);
  101. if (From)
  102. dumpDeclRef(From, Label);
  103. ConstTemplateArgumentVisitor<TextNodeDumper>::Visit(TA);
  104. }
  105. void TextNodeDumper::Visit(const Stmt *Node) {
  106. if (!Node) {
  107. ColorScope Color(OS, ShowColors, NullColor);
  108. OS << "<<<NULL>>>";
  109. return;
  110. }
  111. {
  112. ColorScope Color(OS, ShowColors, StmtColor);
  113. OS << Node->getStmtClassName();
  114. }
  115. dumpPointer(Node);
  116. dumpSourceRange(Node->getSourceRange());
  117. if (const auto *E = dyn_cast<Expr>(Node)) {
  118. dumpType(E->getType());
  119. if (E->containsErrors()) {
  120. ColorScope Color(OS, ShowColors, ErrorsColor);
  121. OS << " contains-errors";
  122. }
  123. {
  124. ColorScope Color(OS, ShowColors, ValueKindColor);
  125. switch (E->getValueKind()) {
  126. case VK_PRValue:
  127. break;
  128. case VK_LValue:
  129. OS << " lvalue";
  130. break;
  131. case VK_XValue:
  132. OS << " xvalue";
  133. break;
  134. }
  135. }
  136. {
  137. ColorScope Color(OS, ShowColors, ObjectKindColor);
  138. switch (E->getObjectKind()) {
  139. case OK_Ordinary:
  140. break;
  141. case OK_BitField:
  142. OS << " bitfield";
  143. break;
  144. case OK_ObjCProperty:
  145. OS << " objcproperty";
  146. break;
  147. case OK_ObjCSubscript:
  148. OS << " objcsubscript";
  149. break;
  150. case OK_VectorComponent:
  151. OS << " vectorcomponent";
  152. break;
  153. case OK_MatrixComponent:
  154. OS << " matrixcomponent";
  155. break;
  156. }
  157. }
  158. }
  159. ConstStmtVisitor<TextNodeDumper>::Visit(Node);
  160. }
  161. void TextNodeDumper::Visit(const Type *T) {
  162. if (!T) {
  163. ColorScope Color(OS, ShowColors, NullColor);
  164. OS << "<<<NULL>>>";
  165. return;
  166. }
  167. if (isa<LocInfoType>(T)) {
  168. {
  169. ColorScope Color(OS, ShowColors, TypeColor);
  170. OS << "LocInfo Type";
  171. }
  172. dumpPointer(T);
  173. return;
  174. }
  175. {
  176. ColorScope Color(OS, ShowColors, TypeColor);
  177. OS << T->getTypeClassName() << "Type";
  178. }
  179. dumpPointer(T);
  180. OS << " ";
  181. dumpBareType(QualType(T, 0), false);
  182. QualType SingleStepDesugar =
  183. T->getLocallyUnqualifiedSingleStepDesugaredType();
  184. if (SingleStepDesugar != QualType(T, 0))
  185. OS << " sugar";
  186. if (T->containsErrors()) {
  187. ColorScope Color(OS, ShowColors, ErrorsColor);
  188. OS << " contains-errors";
  189. }
  190. if (T->isDependentType())
  191. OS << " dependent";
  192. else if (T->isInstantiationDependentType())
  193. OS << " instantiation_dependent";
  194. if (T->isVariablyModifiedType())
  195. OS << " variably_modified";
  196. if (T->containsUnexpandedParameterPack())
  197. OS << " contains_unexpanded_pack";
  198. if (T->isFromAST())
  199. OS << " imported";
  200. TypeVisitor<TextNodeDumper>::Visit(T);
  201. }
  202. void TextNodeDumper::Visit(QualType T) {
  203. OS << "QualType";
  204. dumpPointer(T.getAsOpaquePtr());
  205. OS << " ";
  206. dumpBareType(T, false);
  207. OS << " " << T.split().Quals.getAsString();
  208. }
  209. void TextNodeDumper::Visit(const Decl *D) {
  210. if (!D) {
  211. ColorScope Color(OS, ShowColors, NullColor);
  212. OS << "<<<NULL>>>";
  213. return;
  214. }
  215. {
  216. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  217. OS << D->getDeclKindName() << "Decl";
  218. }
  219. dumpPointer(D);
  220. if (D->getLexicalDeclContext() != D->getDeclContext())
  221. OS << " parent " << cast<Decl>(D->getDeclContext());
  222. dumpPreviousDecl(OS, D);
  223. dumpSourceRange(D->getSourceRange());
  224. OS << ' ';
  225. dumpLocation(D->getLocation());
  226. if (D->isFromASTFile())
  227. OS << " imported";
  228. if (Module *M = D->getOwningModule())
  229. OS << " in " << M->getFullModuleName();
  230. if (auto *ND = dyn_cast<NamedDecl>(D))
  231. for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
  232. const_cast<NamedDecl *>(ND)))
  233. AddChild([=] { OS << "also in " << M->getFullModuleName(); });
  234. if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
  235. if (!ND->isUnconditionallyVisible())
  236. OS << " hidden";
  237. if (D->isImplicit())
  238. OS << " implicit";
  239. if (D->isUsed())
  240. OS << " used";
  241. else if (D->isThisDeclarationReferenced())
  242. OS << " referenced";
  243. if (D->isInvalidDecl())
  244. OS << " invalid";
  245. if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
  246. if (FD->isConstexprSpecified())
  247. OS << " constexpr";
  248. if (FD->isConsteval())
  249. OS << " consteval";
  250. if (FD->isMultiVersion())
  251. OS << " multiversion";
  252. }
  253. if (!isa<FunctionDecl>(*D)) {
  254. const auto *MD = dyn_cast<ObjCMethodDecl>(D);
  255. if (!MD || !MD->isThisDeclarationADefinition()) {
  256. const auto *DC = dyn_cast<DeclContext>(D);
  257. if (DC && DC->hasExternalLexicalStorage()) {
  258. ColorScope Color(OS, ShowColors, UndeserializedColor);
  259. OS << " <undeserialized declarations>";
  260. }
  261. }
  262. }
  263. ConstDeclVisitor<TextNodeDumper>::Visit(D);
  264. }
  265. void TextNodeDumper::Visit(const CXXCtorInitializer *Init) {
  266. OS << "CXXCtorInitializer";
  267. if (Init->isAnyMemberInitializer()) {
  268. OS << ' ';
  269. dumpBareDeclRef(Init->getAnyMember());
  270. } else if (Init->isBaseInitializer()) {
  271. dumpType(QualType(Init->getBaseClass(), 0));
  272. } else if (Init->isDelegatingInitializer()) {
  273. dumpType(Init->getTypeSourceInfo()->getType());
  274. } else {
  275. llvm_unreachable("Unknown initializer type");
  276. }
  277. }
  278. void TextNodeDumper::Visit(const BlockDecl::Capture &C) {
  279. OS << "capture";
  280. if (C.isByRef())
  281. OS << " byref";
  282. if (C.isNested())
  283. OS << " nested";
  284. if (C.getVariable()) {
  285. OS << ' ';
  286. dumpBareDeclRef(C.getVariable());
  287. }
  288. }
  289. void TextNodeDumper::Visit(const OMPClause *C) {
  290. if (!C) {
  291. ColorScope Color(OS, ShowColors, NullColor);
  292. OS << "<<<NULL>>> OMPClause";
  293. return;
  294. }
  295. {
  296. ColorScope Color(OS, ShowColors, AttrColor);
  297. StringRef ClauseName(llvm::omp::getOpenMPClauseName(C->getClauseKind()));
  298. OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
  299. << ClauseName.drop_front() << "Clause";
  300. }
  301. dumpPointer(C);
  302. dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
  303. if (C->isImplicit())
  304. OS << " <implicit>";
  305. }
  306. void TextNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
  307. const TypeSourceInfo *TSI = A.getTypeSourceInfo();
  308. if (TSI) {
  309. OS << "case ";
  310. dumpType(TSI->getType());
  311. } else {
  312. OS << "default";
  313. }
  314. if (A.isSelected())
  315. OS << " selected";
  316. }
  317. void TextNodeDumper::Visit(const concepts::Requirement *R) {
  318. if (!R) {
  319. ColorScope Color(OS, ShowColors, NullColor);
  320. OS << "<<<NULL>>> Requirement";
  321. return;
  322. }
  323. {
  324. ColorScope Color(OS, ShowColors, StmtColor);
  325. switch (R->getKind()) {
  326. case concepts::Requirement::RK_Type:
  327. OS << "TypeRequirement";
  328. break;
  329. case concepts::Requirement::RK_Simple:
  330. OS << "SimpleRequirement";
  331. break;
  332. case concepts::Requirement::RK_Compound:
  333. OS << "CompoundRequirement";
  334. break;
  335. case concepts::Requirement::RK_Nested:
  336. OS << "NestedRequirement";
  337. break;
  338. }
  339. }
  340. dumpPointer(R);
  341. if (auto *ER = dyn_cast<concepts::ExprRequirement>(R)) {
  342. if (ER->hasNoexceptRequirement())
  343. OS << " noexcept";
  344. }
  345. if (R->isDependent())
  346. OS << " dependent";
  347. else
  348. OS << (R->isSatisfied() ? " satisfied" : " unsatisfied");
  349. if (R->containsUnexpandedParameterPack())
  350. OS << " contains_unexpanded_pack";
  351. }
  352. static double GetApproxValue(const llvm::APFloat &F) {
  353. llvm::APFloat V = F;
  354. bool ignored;
  355. V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
  356. &ignored);
  357. return V.convertToDouble();
  358. }
  359. /// True if the \p APValue \p Value can be folded onto the current line.
  360. static bool isSimpleAPValue(const APValue &Value) {
  361. switch (Value.getKind()) {
  362. case APValue::None:
  363. case APValue::Indeterminate:
  364. case APValue::Int:
  365. case APValue::Float:
  366. case APValue::FixedPoint:
  367. case APValue::ComplexInt:
  368. case APValue::ComplexFloat:
  369. case APValue::LValue:
  370. case APValue::MemberPointer:
  371. case APValue::AddrLabelDiff:
  372. return true;
  373. case APValue::Vector:
  374. case APValue::Array:
  375. case APValue::Struct:
  376. return false;
  377. case APValue::Union:
  378. return isSimpleAPValue(Value.getUnionValue());
  379. }
  380. llvm_unreachable("unexpected APValue kind!");
  381. }
  382. /// Dump the children of the \p APValue \p Value.
  383. ///
  384. /// \param[in] Value The \p APValue to visit
  385. /// \param[in] Ty The \p QualType passed to \p Visit
  386. ///
  387. /// \param[in] IdxToChildFun A function mapping an \p APValue and an index
  388. /// to one of the child of the \p APValue
  389. ///
  390. /// \param[in] NumChildren \p IdxToChildFun will be called on \p Value with
  391. /// the indices in the range \p [0,NumChildren(
  392. ///
  393. /// \param[in] LabelSingular The label to use on a line with a single child
  394. /// \param[in] LabelPlurial The label to use on a line with multiple children
  395. void TextNodeDumper::dumpAPValueChildren(
  396. const APValue &Value, QualType Ty,
  397. const APValue &(*IdxToChildFun)(const APValue &, unsigned),
  398. unsigned NumChildren, StringRef LabelSingular, StringRef LabelPlurial) {
  399. // To save some vertical space we print up to MaxChildrenPerLine APValues
  400. // considered to be simple (by isSimpleAPValue) on a single line.
  401. constexpr unsigned MaxChildrenPerLine = 4;
  402. unsigned I = 0;
  403. while (I < NumChildren) {
  404. unsigned J = I;
  405. while (J < NumChildren) {
  406. if (isSimpleAPValue(IdxToChildFun(Value, J)) &&
  407. (J - I < MaxChildrenPerLine)) {
  408. ++J;
  409. continue;
  410. }
  411. break;
  412. }
  413. J = std::max(I + 1, J);
  414. // Print [I,J) on a single line.
  415. AddChild(J - I > 1 ? LabelPlurial : LabelSingular, [=]() {
  416. for (unsigned X = I; X < J; ++X) {
  417. Visit(IdxToChildFun(Value, X), Ty);
  418. if (X + 1 != J)
  419. OS << ", ";
  420. }
  421. });
  422. I = J;
  423. }
  424. }
  425. void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
  426. ColorScope Color(OS, ShowColors, ValueKindColor);
  427. switch (Value.getKind()) {
  428. case APValue::None:
  429. OS << "None";
  430. return;
  431. case APValue::Indeterminate:
  432. OS << "Indeterminate";
  433. return;
  434. case APValue::Int:
  435. OS << "Int ";
  436. {
  437. ColorScope Color(OS, ShowColors, ValueColor);
  438. OS << Value.getInt();
  439. }
  440. return;
  441. case APValue::Float:
  442. OS << "Float ";
  443. {
  444. ColorScope Color(OS, ShowColors, ValueColor);
  445. OS << GetApproxValue(Value.getFloat());
  446. }
  447. return;
  448. case APValue::FixedPoint:
  449. OS << "FixedPoint ";
  450. {
  451. ColorScope Color(OS, ShowColors, ValueColor);
  452. OS << Value.getFixedPoint();
  453. }
  454. return;
  455. case APValue::Vector: {
  456. unsigned VectorLength = Value.getVectorLength();
  457. OS << "Vector length=" << VectorLength;
  458. dumpAPValueChildren(
  459. Value, Ty,
  460. [](const APValue &Value, unsigned Index) -> const APValue & {
  461. return Value.getVectorElt(Index);
  462. },
  463. VectorLength, "element", "elements");
  464. return;
  465. }
  466. case APValue::ComplexInt:
  467. OS << "ComplexInt ";
  468. {
  469. ColorScope Color(OS, ShowColors, ValueColor);
  470. OS << Value.getComplexIntReal() << " + " << Value.getComplexIntImag()
  471. << 'i';
  472. }
  473. return;
  474. case APValue::ComplexFloat:
  475. OS << "ComplexFloat ";
  476. {
  477. ColorScope Color(OS, ShowColors, ValueColor);
  478. OS << GetApproxValue(Value.getComplexFloatReal()) << " + "
  479. << GetApproxValue(Value.getComplexFloatImag()) << 'i';
  480. }
  481. return;
  482. case APValue::LValue:
  483. (void)Context;
  484. OS << "LValue <todo>";
  485. return;
  486. case APValue::Array: {
  487. unsigned ArraySize = Value.getArraySize();
  488. unsigned NumInitializedElements = Value.getArrayInitializedElts();
  489. OS << "Array size=" << ArraySize;
  490. dumpAPValueChildren(
  491. Value, Ty,
  492. [](const APValue &Value, unsigned Index) -> const APValue & {
  493. return Value.getArrayInitializedElt(Index);
  494. },
  495. NumInitializedElements, "element", "elements");
  496. if (Value.hasArrayFiller()) {
  497. AddChild("filler", [=] {
  498. {
  499. ColorScope Color(OS, ShowColors, ValueColor);
  500. OS << ArraySize - NumInitializedElements << " x ";
  501. }
  502. Visit(Value.getArrayFiller(), Ty);
  503. });
  504. }
  505. return;
  506. }
  507. case APValue::Struct: {
  508. OS << "Struct";
  509. dumpAPValueChildren(
  510. Value, Ty,
  511. [](const APValue &Value, unsigned Index) -> const APValue & {
  512. return Value.getStructBase(Index);
  513. },
  514. Value.getStructNumBases(), "base", "bases");
  515. dumpAPValueChildren(
  516. Value, Ty,
  517. [](const APValue &Value, unsigned Index) -> const APValue & {
  518. return Value.getStructField(Index);
  519. },
  520. Value.getStructNumFields(), "field", "fields");
  521. return;
  522. }
  523. case APValue::Union: {
  524. OS << "Union";
  525. {
  526. ColorScope Color(OS, ShowColors, ValueColor);
  527. if (const FieldDecl *FD = Value.getUnionField())
  528. OS << " ." << *cast<NamedDecl>(FD);
  529. }
  530. // If the union value is considered to be simple, fold it into the
  531. // current line to save some vertical space.
  532. const APValue &UnionValue = Value.getUnionValue();
  533. if (isSimpleAPValue(UnionValue)) {
  534. OS << ' ';
  535. Visit(UnionValue, Ty);
  536. } else {
  537. AddChild([=] { Visit(UnionValue, Ty); });
  538. }
  539. return;
  540. }
  541. case APValue::MemberPointer:
  542. OS << "MemberPointer <todo>";
  543. return;
  544. case APValue::AddrLabelDiff:
  545. OS << "AddrLabelDiff <todo>";
  546. return;
  547. }
  548. llvm_unreachable("Unknown APValue kind!");
  549. }
  550. void TextNodeDumper::dumpPointer(const void *Ptr) {
  551. ColorScope Color(OS, ShowColors, AddressColor);
  552. OS << ' ' << Ptr;
  553. }
  554. void TextNodeDumper::dumpLocation(SourceLocation Loc) {
  555. if (!SM)
  556. return;
  557. ColorScope Color(OS, ShowColors, LocationColor);
  558. SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
  559. // The general format we print out is filename:line:col, but we drop pieces
  560. // that haven't changed since the last loc printed.
  561. PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
  562. if (PLoc.isInvalid()) {
  563. OS << "<invalid sloc>";
  564. return;
  565. }
  566. if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
  567. OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
  568. << PLoc.getColumn();
  569. LastLocFilename = PLoc.getFilename();
  570. LastLocLine = PLoc.getLine();
  571. } else if (PLoc.getLine() != LastLocLine) {
  572. OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
  573. LastLocLine = PLoc.getLine();
  574. } else {
  575. OS << "col" << ':' << PLoc.getColumn();
  576. }
  577. }
  578. void TextNodeDumper::dumpSourceRange(SourceRange R) {
  579. // Can't translate locations if a SourceManager isn't available.
  580. if (!SM)
  581. return;
  582. OS << " <";
  583. dumpLocation(R.getBegin());
  584. if (R.getBegin() != R.getEnd()) {
  585. OS << ", ";
  586. dumpLocation(R.getEnd());
  587. }
  588. OS << ">";
  589. // <t2.c:123:421[blah], t2.c:412:321>
  590. }
  591. void TextNodeDumper::dumpBareType(QualType T, bool Desugar) {
  592. ColorScope Color(OS, ShowColors, TypeColor);
  593. SplitQualType T_split = T.split();
  594. OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
  595. if (Desugar && !T.isNull()) {
  596. // If the type is sugared, also dump a (shallow) desugared type.
  597. SplitQualType D_split = T.getSplitDesugaredType();
  598. if (T_split != D_split)
  599. OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
  600. }
  601. }
  602. void TextNodeDumper::dumpType(QualType T) {
  603. OS << ' ';
  604. dumpBareType(T);
  605. }
  606. void TextNodeDumper::dumpBareDeclRef(const Decl *D) {
  607. if (!D) {
  608. ColorScope Color(OS, ShowColors, NullColor);
  609. OS << "<<<NULL>>>";
  610. return;
  611. }
  612. {
  613. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  614. OS << D->getDeclKindName();
  615. }
  616. dumpPointer(D);
  617. if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
  618. ColorScope Color(OS, ShowColors, DeclNameColor);
  619. OS << " '" << ND->getDeclName() << '\'';
  620. }
  621. if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
  622. dumpType(VD->getType());
  623. }
  624. void TextNodeDumper::dumpName(const NamedDecl *ND) {
  625. if (ND->getDeclName()) {
  626. ColorScope Color(OS, ShowColors, DeclNameColor);
  627. OS << ' ' << ND->getDeclName();
  628. }
  629. }
  630. void TextNodeDumper::dumpAccessSpecifier(AccessSpecifier AS) {
  631. const auto AccessSpelling = getAccessSpelling(AS);
  632. if (AccessSpelling.empty())
  633. return;
  634. OS << AccessSpelling;
  635. }
  636. void TextNodeDumper::dumpCleanupObject(
  637. const ExprWithCleanups::CleanupObject &C) {
  638. if (auto *BD = C.dyn_cast<BlockDecl *>())
  639. dumpDeclRef(BD, "cleanup");
  640. else if (auto *CLE = C.dyn_cast<CompoundLiteralExpr *>())
  641. AddChild([=] {
  642. OS << "cleanup ";
  643. {
  644. ColorScope Color(OS, ShowColors, StmtColor);
  645. OS << CLE->getStmtClassName();
  646. }
  647. dumpPointer(CLE);
  648. });
  649. else
  650. llvm_unreachable("unexpected cleanup type");
  651. }
  652. void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) {
  653. if (!D)
  654. return;
  655. AddChild([=] {
  656. if (!Label.empty())
  657. OS << Label << ' ';
  658. dumpBareDeclRef(D);
  659. });
  660. }
  661. const char *TextNodeDumper::getCommandName(unsigned CommandID) {
  662. if (Traits)
  663. return Traits->getCommandInfo(CommandID)->Name;
  664. const comments::CommandInfo *Info =
  665. comments::CommandTraits::getBuiltinCommandInfo(CommandID);
  666. if (Info)
  667. return Info->Name;
  668. return "<not a builtin command>";
  669. }
  670. void TextNodeDumper::printFPOptions(FPOptionsOverride FPO) {
  671. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
  672. if (FPO.has##NAME##Override()) \
  673. OS << " " #NAME "=" << FPO.get##NAME##Override();
  674. #include "clang/Basic/FPOptions.def"
  675. }
  676. void TextNodeDumper::visitTextComment(const comments::TextComment *C,
  677. const comments::FullComment *) {
  678. OS << " Text=\"" << C->getText() << "\"";
  679. }
  680. void TextNodeDumper::visitInlineCommandComment(
  681. const comments::InlineCommandComment *C, const comments::FullComment *) {
  682. OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
  683. switch (C->getRenderKind()) {
  684. case comments::InlineCommandComment::RenderNormal:
  685. OS << " RenderNormal";
  686. break;
  687. case comments::InlineCommandComment::RenderBold:
  688. OS << " RenderBold";
  689. break;
  690. case comments::InlineCommandComment::RenderMonospaced:
  691. OS << " RenderMonospaced";
  692. break;
  693. case comments::InlineCommandComment::RenderEmphasized:
  694. OS << " RenderEmphasized";
  695. break;
  696. case comments::InlineCommandComment::RenderAnchor:
  697. OS << " RenderAnchor";
  698. break;
  699. }
  700. for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
  701. OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
  702. }
  703. void TextNodeDumper::visitHTMLStartTagComment(
  704. const comments::HTMLStartTagComment *C, const comments::FullComment *) {
  705. OS << " Name=\"" << C->getTagName() << "\"";
  706. if (C->getNumAttrs() != 0) {
  707. OS << " Attrs: ";
  708. for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
  709. const comments::HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
  710. OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
  711. }
  712. }
  713. if (C->isSelfClosing())
  714. OS << " SelfClosing";
  715. }
  716. void TextNodeDumper::visitHTMLEndTagComment(
  717. const comments::HTMLEndTagComment *C, const comments::FullComment *) {
  718. OS << " Name=\"" << C->getTagName() << "\"";
  719. }
  720. void TextNodeDumper::visitBlockCommandComment(
  721. const comments::BlockCommandComment *C, const comments::FullComment *) {
  722. OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
  723. for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
  724. OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
  725. }
  726. void TextNodeDumper::visitParamCommandComment(
  727. const comments::ParamCommandComment *C, const comments::FullComment *FC) {
  728. OS << " "
  729. << comments::ParamCommandComment::getDirectionAsString(C->getDirection());
  730. if (C->isDirectionExplicit())
  731. OS << " explicitly";
  732. else
  733. OS << " implicitly";
  734. if (C->hasParamName()) {
  735. if (C->isParamIndexValid())
  736. OS << " Param=\"" << C->getParamName(FC) << "\"";
  737. else
  738. OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
  739. }
  740. if (C->isParamIndexValid() && !C->isVarArgParam())
  741. OS << " ParamIndex=" << C->getParamIndex();
  742. }
  743. void TextNodeDumper::visitTParamCommandComment(
  744. const comments::TParamCommandComment *C, const comments::FullComment *FC) {
  745. if (C->hasParamName()) {
  746. if (C->isPositionValid())
  747. OS << " Param=\"" << C->getParamName(FC) << "\"";
  748. else
  749. OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
  750. }
  751. if (C->isPositionValid()) {
  752. OS << " Position=<";
  753. for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
  754. OS << C->getIndex(i);
  755. if (i != e - 1)
  756. OS << ", ";
  757. }
  758. OS << ">";
  759. }
  760. }
  761. void TextNodeDumper::visitVerbatimBlockComment(
  762. const comments::VerbatimBlockComment *C, const comments::FullComment *) {
  763. OS << " Name=\"" << getCommandName(C->getCommandID())
  764. << "\""
  765. " CloseName=\""
  766. << C->getCloseName() << "\"";
  767. }
  768. void TextNodeDumper::visitVerbatimBlockLineComment(
  769. const comments::VerbatimBlockLineComment *C,
  770. const comments::FullComment *) {
  771. OS << " Text=\"" << C->getText() << "\"";
  772. }
  773. void TextNodeDumper::visitVerbatimLineComment(
  774. const comments::VerbatimLineComment *C, const comments::FullComment *) {
  775. OS << " Text=\"" << C->getText() << "\"";
  776. }
  777. void TextNodeDumper::VisitNullTemplateArgument(const TemplateArgument &) {
  778. OS << " null";
  779. }
  780. void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
  781. OS << " type";
  782. dumpType(TA.getAsType());
  783. }
  784. void TextNodeDumper::VisitDeclarationTemplateArgument(
  785. const TemplateArgument &TA) {
  786. OS << " decl";
  787. dumpDeclRef(TA.getAsDecl());
  788. }
  789. void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
  790. OS << " nullptr";
  791. }
  792. void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
  793. OS << " integral " << TA.getAsIntegral();
  794. }
  795. void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
  796. if (TA.getAsTemplate().getKind() == TemplateName::UsingTemplate)
  797. OS << " using";
  798. OS << " template ";
  799. TA.getAsTemplate().dump(OS);
  800. }
  801. void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
  802. const TemplateArgument &TA) {
  803. if (TA.getAsTemplateOrTemplatePattern().getKind() ==
  804. TemplateName::UsingTemplate)
  805. OS << " using";
  806. OS << " template expansion ";
  807. TA.getAsTemplateOrTemplatePattern().dump(OS);
  808. }
  809. void TextNodeDumper::VisitExpressionTemplateArgument(const TemplateArgument &) {
  810. OS << " expr";
  811. }
  812. void TextNodeDumper::VisitPackTemplateArgument(const TemplateArgument &) {
  813. OS << " pack";
  814. }
  815. static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
  816. if (Node->path_empty())
  817. return;
  818. OS << " (";
  819. bool First = true;
  820. for (CastExpr::path_const_iterator I = Node->path_begin(),
  821. E = Node->path_end();
  822. I != E; ++I) {
  823. const CXXBaseSpecifier *Base = *I;
  824. if (!First)
  825. OS << " -> ";
  826. const auto *RD =
  827. cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
  828. if (Base->isVirtual())
  829. OS << "virtual ";
  830. OS << RD->getName();
  831. First = false;
  832. }
  833. OS << ')';
  834. }
  835. void TextNodeDumper::VisitIfStmt(const IfStmt *Node) {
  836. if (Node->hasInitStorage())
  837. OS << " has_init";
  838. if (Node->hasVarStorage())
  839. OS << " has_var";
  840. if (Node->hasElseStorage())
  841. OS << " has_else";
  842. if (Node->isConstexpr())
  843. OS << " constexpr";
  844. if (Node->isConsteval()) {
  845. OS << " ";
  846. if (Node->isNegatedConsteval())
  847. OS << "!";
  848. OS << "consteval";
  849. }
  850. }
  851. void TextNodeDumper::VisitSwitchStmt(const SwitchStmt *Node) {
  852. if (Node->hasInitStorage())
  853. OS << " has_init";
  854. if (Node->hasVarStorage())
  855. OS << " has_var";
  856. }
  857. void TextNodeDumper::VisitWhileStmt(const WhileStmt *Node) {
  858. if (Node->hasVarStorage())
  859. OS << " has_var";
  860. }
  861. void TextNodeDumper::VisitLabelStmt(const LabelStmt *Node) {
  862. OS << " '" << Node->getName() << "'";
  863. if (Node->isSideEntry())
  864. OS << " side_entry";
  865. }
  866. void TextNodeDumper::VisitGotoStmt(const GotoStmt *Node) {
  867. OS << " '" << Node->getLabel()->getName() << "'";
  868. dumpPointer(Node->getLabel());
  869. }
  870. void TextNodeDumper::VisitCaseStmt(const CaseStmt *Node) {
  871. if (Node->caseStmtIsGNURange())
  872. OS << " gnu_range";
  873. }
  874. void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
  875. if (Node->hasAPValueResult())
  876. AddChild("value",
  877. [=] { Visit(Node->getAPValueResult(), Node->getType()); });
  878. }
  879. void TextNodeDumper::VisitCallExpr(const CallExpr *Node) {
  880. if (Node->usesADL())
  881. OS << " adl";
  882. if (Node->hasStoredFPFeatures())
  883. printFPOptions(Node->getFPFeatures());
  884. }
  885. void TextNodeDumper::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node) {
  886. const char *OperatorSpelling = clang::getOperatorSpelling(Node->getOperator());
  887. if (OperatorSpelling)
  888. OS << " '" << OperatorSpelling << "'";
  889. VisitCallExpr(Node);
  890. }
  891. void TextNodeDumper::VisitCastExpr(const CastExpr *Node) {
  892. OS << " <";
  893. {
  894. ColorScope Color(OS, ShowColors, CastColor);
  895. OS << Node->getCastKindName();
  896. }
  897. dumpBasePath(OS, Node);
  898. OS << ">";
  899. if (Node->hasStoredFPFeatures())
  900. printFPOptions(Node->getFPFeatures());
  901. }
  902. void TextNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
  903. VisitCastExpr(Node);
  904. if (Node->isPartOfExplicitCast())
  905. OS << " part_of_explicit_cast";
  906. }
  907. void TextNodeDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
  908. OS << " ";
  909. dumpBareDeclRef(Node->getDecl());
  910. if (Node->getDecl() != Node->getFoundDecl()) {
  911. OS << " (";
  912. dumpBareDeclRef(Node->getFoundDecl());
  913. OS << ")";
  914. }
  915. switch (Node->isNonOdrUse()) {
  916. case NOUR_None: break;
  917. case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break;
  918. case NOUR_Constant: OS << " non_odr_use_constant"; break;
  919. case NOUR_Discarded: OS << " non_odr_use_discarded"; break;
  920. }
  921. }
  922. void TextNodeDumper::VisitUnresolvedLookupExpr(
  923. const UnresolvedLookupExpr *Node) {
  924. OS << " (";
  925. if (!Node->requiresADL())
  926. OS << "no ";
  927. OS << "ADL) = '" << Node->getName() << '\'';
  928. UnresolvedLookupExpr::decls_iterator I = Node->decls_begin(),
  929. E = Node->decls_end();
  930. if (I == E)
  931. OS << " empty";
  932. for (; I != E; ++I)
  933. dumpPointer(*I);
  934. }
  935. void TextNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
  936. {
  937. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  938. OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
  939. }
  940. OS << "='" << *Node->getDecl() << "'";
  941. dumpPointer(Node->getDecl());
  942. if (Node->isFreeIvar())
  943. OS << " isFreeIvar";
  944. }
  945. void TextNodeDumper::VisitSYCLUniqueStableNameExpr(
  946. const SYCLUniqueStableNameExpr *Node) {
  947. dumpType(Node->getTypeSourceInfo()->getType());
  948. }
  949. void TextNodeDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
  950. OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
  951. }
  952. void TextNodeDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
  953. ColorScope Color(OS, ShowColors, ValueColor);
  954. OS << " " << Node->getValue();
  955. }
  956. void TextNodeDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
  957. bool isSigned = Node->getType()->isSignedIntegerType();
  958. ColorScope Color(OS, ShowColors, ValueColor);
  959. OS << " " << toString(Node->getValue(), 10, isSigned);
  960. }
  961. void TextNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
  962. ColorScope Color(OS, ShowColors, ValueColor);
  963. OS << " " << Node->getValueAsString(/*Radix=*/10);
  964. }
  965. void TextNodeDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
  966. ColorScope Color(OS, ShowColors, ValueColor);
  967. OS << " " << Node->getValueAsApproximateDouble();
  968. }
  969. void TextNodeDumper::VisitStringLiteral(const StringLiteral *Str) {
  970. ColorScope Color(OS, ShowColors, ValueColor);
  971. OS << " ";
  972. Str->outputString(OS);
  973. }
  974. void TextNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
  975. if (auto *Field = ILE->getInitializedFieldInUnion()) {
  976. OS << " field ";
  977. dumpBareDeclRef(Field);
  978. }
  979. }
  980. void TextNodeDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
  981. if (E->isResultDependent())
  982. OS << " result_dependent";
  983. }
  984. void TextNodeDumper::VisitUnaryOperator(const UnaryOperator *Node) {
  985. OS << " " << (Node->isPostfix() ? "postfix" : "prefix") << " '"
  986. << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
  987. if (!Node->canOverflow())
  988. OS << " cannot overflow";
  989. if (Node->hasStoredFPFeatures())
  990. printFPOptions(Node->getStoredFPFeatures());
  991. }
  992. void TextNodeDumper::VisitUnaryExprOrTypeTraitExpr(
  993. const UnaryExprOrTypeTraitExpr *Node) {
  994. OS << " " << getTraitSpelling(Node->getKind());
  995. if (Node->isArgumentType())
  996. dumpType(Node->getArgumentType());
  997. }
  998. void TextNodeDumper::VisitMemberExpr(const MemberExpr *Node) {
  999. OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
  1000. dumpPointer(Node->getMemberDecl());
  1001. switch (Node->isNonOdrUse()) {
  1002. case NOUR_None: break;
  1003. case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break;
  1004. case NOUR_Constant: OS << " non_odr_use_constant"; break;
  1005. case NOUR_Discarded: OS << " non_odr_use_discarded"; break;
  1006. }
  1007. }
  1008. void TextNodeDumper::VisitExtVectorElementExpr(
  1009. const ExtVectorElementExpr *Node) {
  1010. OS << " " << Node->getAccessor().getNameStart();
  1011. }
  1012. void TextNodeDumper::VisitBinaryOperator(const BinaryOperator *Node) {
  1013. OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
  1014. if (Node->hasStoredFPFeatures())
  1015. printFPOptions(Node->getStoredFPFeatures());
  1016. }
  1017. void TextNodeDumper::VisitCompoundAssignOperator(
  1018. const CompoundAssignOperator *Node) {
  1019. OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
  1020. << "' ComputeLHSTy=";
  1021. dumpBareType(Node->getComputationLHSType());
  1022. OS << " ComputeResultTy=";
  1023. dumpBareType(Node->getComputationResultType());
  1024. if (Node->hasStoredFPFeatures())
  1025. printFPOptions(Node->getStoredFPFeatures());
  1026. }
  1027. void TextNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
  1028. OS << " " << Node->getLabel()->getName();
  1029. dumpPointer(Node->getLabel());
  1030. }
  1031. void TextNodeDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
  1032. OS << " " << Node->getCastName() << "<"
  1033. << Node->getTypeAsWritten().getAsString() << ">"
  1034. << " <" << Node->getCastKindName();
  1035. dumpBasePath(OS, Node);
  1036. OS << ">";
  1037. }
  1038. void TextNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
  1039. OS << " " << (Node->getValue() ? "true" : "false");
  1040. }
  1041. void TextNodeDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
  1042. if (Node->isImplicit())
  1043. OS << " implicit";
  1044. OS << " this";
  1045. }
  1046. void TextNodeDumper::VisitCXXFunctionalCastExpr(
  1047. const CXXFunctionalCastExpr *Node) {
  1048. OS << " functional cast to " << Node->getTypeAsWritten().getAsString() << " <"
  1049. << Node->getCastKindName() << ">";
  1050. if (Node->hasStoredFPFeatures())
  1051. printFPOptions(Node->getFPFeatures());
  1052. }
  1053. void TextNodeDumper::VisitCXXStaticCastExpr(const CXXStaticCastExpr *Node) {
  1054. VisitCXXNamedCastExpr(Node);
  1055. if (Node->hasStoredFPFeatures())
  1056. printFPOptions(Node->getFPFeatures());
  1057. }
  1058. void TextNodeDumper::VisitCXXUnresolvedConstructExpr(
  1059. const CXXUnresolvedConstructExpr *Node) {
  1060. dumpType(Node->getTypeAsWritten());
  1061. if (Node->isListInitialization())
  1062. OS << " list";
  1063. }
  1064. void TextNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
  1065. CXXConstructorDecl *Ctor = Node->getConstructor();
  1066. dumpType(Ctor->getType());
  1067. if (Node->isElidable())
  1068. OS << " elidable";
  1069. if (Node->isListInitialization())
  1070. OS << " list";
  1071. if (Node->isStdInitListInitialization())
  1072. OS << " std::initializer_list";
  1073. if (Node->requiresZeroInitialization())
  1074. OS << " zeroing";
  1075. }
  1076. void TextNodeDumper::VisitCXXBindTemporaryExpr(
  1077. const CXXBindTemporaryExpr *Node) {
  1078. OS << " (CXXTemporary";
  1079. dumpPointer(Node);
  1080. OS << ")";
  1081. }
  1082. void TextNodeDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
  1083. if (Node->isGlobalNew())
  1084. OS << " global";
  1085. if (Node->isArray())
  1086. OS << " array";
  1087. if (Node->getOperatorNew()) {
  1088. OS << ' ';
  1089. dumpBareDeclRef(Node->getOperatorNew());
  1090. }
  1091. // We could dump the deallocation function used in case of error, but it's
  1092. // usually not that interesting.
  1093. }
  1094. void TextNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
  1095. if (Node->isGlobalDelete())
  1096. OS << " global";
  1097. if (Node->isArrayForm())
  1098. OS << " array";
  1099. if (Node->getOperatorDelete()) {
  1100. OS << ' ';
  1101. dumpBareDeclRef(Node->getOperatorDelete());
  1102. }
  1103. }
  1104. void TextNodeDumper::VisitTypeTraitExpr(const TypeTraitExpr *Node) {
  1105. OS << " " << getTraitSpelling(Node->getTrait());
  1106. }
  1107. void TextNodeDumper::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node) {
  1108. OS << " " << getTraitSpelling(Node->getTrait());
  1109. }
  1110. void TextNodeDumper::VisitExpressionTraitExpr(const ExpressionTraitExpr *Node) {
  1111. OS << " " << getTraitSpelling(Node->getTrait());
  1112. }
  1113. void TextNodeDumper::VisitMaterializeTemporaryExpr(
  1114. const MaterializeTemporaryExpr *Node) {
  1115. if (const ValueDecl *VD = Node->getExtendingDecl()) {
  1116. OS << " extended by ";
  1117. dumpBareDeclRef(VD);
  1118. }
  1119. }
  1120. void TextNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
  1121. for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
  1122. dumpCleanupObject(Node->getObject(i));
  1123. }
  1124. void TextNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
  1125. dumpPointer(Node->getPack());
  1126. dumpName(Node->getPack());
  1127. }
  1128. void TextNodeDumper::VisitCXXDependentScopeMemberExpr(
  1129. const CXXDependentScopeMemberExpr *Node) {
  1130. OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
  1131. }
  1132. void TextNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
  1133. OS << " selector=";
  1134. Node->getSelector().print(OS);
  1135. switch (Node->getReceiverKind()) {
  1136. case ObjCMessageExpr::Instance:
  1137. break;
  1138. case ObjCMessageExpr::Class:
  1139. OS << " class=";
  1140. dumpBareType(Node->getClassReceiver());
  1141. break;
  1142. case ObjCMessageExpr::SuperInstance:
  1143. OS << " super (instance)";
  1144. break;
  1145. case ObjCMessageExpr::SuperClass:
  1146. OS << " super (class)";
  1147. break;
  1148. }
  1149. }
  1150. void TextNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
  1151. if (auto *BoxingMethod = Node->getBoxingMethod()) {
  1152. OS << " selector=";
  1153. BoxingMethod->getSelector().print(OS);
  1154. }
  1155. }
  1156. void TextNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
  1157. if (!Node->getCatchParamDecl())
  1158. OS << " catch all";
  1159. }
  1160. void TextNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
  1161. dumpType(Node->getEncodedType());
  1162. }
  1163. void TextNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
  1164. OS << " ";
  1165. Node->getSelector().print(OS);
  1166. }
  1167. void TextNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
  1168. OS << ' ' << *Node->getProtocol();
  1169. }
  1170. void TextNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
  1171. if (Node->isImplicitProperty()) {
  1172. OS << " Kind=MethodRef Getter=\"";
  1173. if (Node->getImplicitPropertyGetter())
  1174. Node->getImplicitPropertyGetter()->getSelector().print(OS);
  1175. else
  1176. OS << "(null)";
  1177. OS << "\" Setter=\"";
  1178. if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
  1179. Setter->getSelector().print(OS);
  1180. else
  1181. OS << "(null)";
  1182. OS << "\"";
  1183. } else {
  1184. OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty()
  1185. << '"';
  1186. }
  1187. if (Node->isSuperReceiver())
  1188. OS << " super";
  1189. OS << " Messaging=";
  1190. if (Node->isMessagingGetter() && Node->isMessagingSetter())
  1191. OS << "Getter&Setter";
  1192. else if (Node->isMessagingGetter())
  1193. OS << "Getter";
  1194. else if (Node->isMessagingSetter())
  1195. OS << "Setter";
  1196. }
  1197. void TextNodeDumper::VisitObjCSubscriptRefExpr(
  1198. const ObjCSubscriptRefExpr *Node) {
  1199. if (Node->isArraySubscriptRefExpr())
  1200. OS << " Kind=ArraySubscript GetterForArray=\"";
  1201. else
  1202. OS << " Kind=DictionarySubscript GetterForDictionary=\"";
  1203. if (Node->getAtIndexMethodDecl())
  1204. Node->getAtIndexMethodDecl()->getSelector().print(OS);
  1205. else
  1206. OS << "(null)";
  1207. if (Node->isArraySubscriptRefExpr())
  1208. OS << "\" SetterForArray=\"";
  1209. else
  1210. OS << "\" SetterForDictionary=\"";
  1211. if (Node->setAtIndexMethodDecl())
  1212. Node->setAtIndexMethodDecl()->getSelector().print(OS);
  1213. else
  1214. OS << "(null)";
  1215. }
  1216. void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
  1217. OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
  1218. }
  1219. void TextNodeDumper::VisitOMPIteratorExpr(const OMPIteratorExpr *Node) {
  1220. OS << " ";
  1221. for (unsigned I = 0, E = Node->numOfIterators(); I < E; ++I) {
  1222. Visit(Node->getIteratorDecl(I));
  1223. OS << " = ";
  1224. const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I);
  1225. OS << " begin ";
  1226. Visit(Range.Begin);
  1227. OS << " end ";
  1228. Visit(Range.End);
  1229. if (Range.Step) {
  1230. OS << " step ";
  1231. Visit(Range.Step);
  1232. }
  1233. }
  1234. }
  1235. void TextNodeDumper::VisitConceptSpecializationExpr(
  1236. const ConceptSpecializationExpr *Node) {
  1237. OS << " ";
  1238. dumpBareDeclRef(Node->getFoundDecl());
  1239. }
  1240. void TextNodeDumper::VisitRequiresExpr(
  1241. const RequiresExpr *Node) {
  1242. if (!Node->isValueDependent())
  1243. OS << (Node->isSatisfied() ? " satisfied" : " unsatisfied");
  1244. }
  1245. void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) {
  1246. if (T->isSpelledAsLValue())
  1247. OS << " written as lvalue reference";
  1248. }
  1249. void TextNodeDumper::VisitArrayType(const ArrayType *T) {
  1250. switch (T->getSizeModifier()) {
  1251. case ArrayType::Normal:
  1252. break;
  1253. case ArrayType::Static:
  1254. OS << " static";
  1255. break;
  1256. case ArrayType::Star:
  1257. OS << " *";
  1258. break;
  1259. }
  1260. OS << " " << T->getIndexTypeQualifiers().getAsString();
  1261. }
  1262. void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) {
  1263. OS << " " << T->getSize();
  1264. VisitArrayType(T);
  1265. }
  1266. void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
  1267. OS << " ";
  1268. dumpSourceRange(T->getBracketsRange());
  1269. VisitArrayType(T);
  1270. }
  1271. void TextNodeDumper::VisitDependentSizedArrayType(
  1272. const DependentSizedArrayType *T) {
  1273. VisitArrayType(T);
  1274. OS << " ";
  1275. dumpSourceRange(T->getBracketsRange());
  1276. }
  1277. void TextNodeDumper::VisitDependentSizedExtVectorType(
  1278. const DependentSizedExtVectorType *T) {
  1279. OS << " ";
  1280. dumpLocation(T->getAttributeLoc());
  1281. }
  1282. void TextNodeDumper::VisitVectorType(const VectorType *T) {
  1283. switch (T->getVectorKind()) {
  1284. case VectorType::GenericVector:
  1285. break;
  1286. case VectorType::AltiVecVector:
  1287. OS << " altivec";
  1288. break;
  1289. case VectorType::AltiVecPixel:
  1290. OS << " altivec pixel";
  1291. break;
  1292. case VectorType::AltiVecBool:
  1293. OS << " altivec bool";
  1294. break;
  1295. case VectorType::NeonVector:
  1296. OS << " neon";
  1297. break;
  1298. case VectorType::NeonPolyVector:
  1299. OS << " neon poly";
  1300. break;
  1301. case VectorType::SveFixedLengthDataVector:
  1302. OS << " fixed-length sve data vector";
  1303. break;
  1304. case VectorType::SveFixedLengthPredicateVector:
  1305. OS << " fixed-length sve predicate vector";
  1306. break;
  1307. }
  1308. OS << " " << T->getNumElements();
  1309. }
  1310. void TextNodeDumper::VisitFunctionType(const FunctionType *T) {
  1311. auto EI = T->getExtInfo();
  1312. if (EI.getNoReturn())
  1313. OS << " noreturn";
  1314. if (EI.getProducesResult())
  1315. OS << " produces_result";
  1316. if (EI.getHasRegParm())
  1317. OS << " regparm " << EI.getRegParm();
  1318. OS << " " << FunctionType::getNameForCallConv(EI.getCC());
  1319. }
  1320. void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
  1321. auto EPI = T->getExtProtoInfo();
  1322. if (EPI.HasTrailingReturn)
  1323. OS << " trailing_return";
  1324. if (T->isConst())
  1325. OS << " const";
  1326. if (T->isVolatile())
  1327. OS << " volatile";
  1328. if (T->isRestrict())
  1329. OS << " restrict";
  1330. if (T->getExtProtoInfo().Variadic)
  1331. OS << " variadic";
  1332. switch (EPI.RefQualifier) {
  1333. case RQ_None:
  1334. break;
  1335. case RQ_LValue:
  1336. OS << " &";
  1337. break;
  1338. case RQ_RValue:
  1339. OS << " &&";
  1340. break;
  1341. }
  1342. // FIXME: Exception specification.
  1343. // FIXME: Consumed parameters.
  1344. VisitFunctionType(T);
  1345. }
  1346. void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
  1347. dumpDeclRef(T->getDecl());
  1348. }
  1349. void TextNodeDumper::VisitUsingType(const UsingType *T) {
  1350. dumpDeclRef(T->getFoundDecl());
  1351. if (!T->typeMatchesDecl())
  1352. OS << " divergent";
  1353. }
  1354. void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
  1355. dumpDeclRef(T->getDecl());
  1356. if (!T->typeMatchesDecl())
  1357. OS << " divergent";
  1358. }
  1359. void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
  1360. switch (T->getUTTKind()) {
  1361. #define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
  1362. case UnaryTransformType::Enum: \
  1363. OS << " " #Trait; \
  1364. break;
  1365. #include "clang/Basic/TransformTypeTraits.def"
  1366. }
  1367. }
  1368. void TextNodeDumper::VisitTagType(const TagType *T) {
  1369. dumpDeclRef(T->getDecl());
  1370. }
  1371. void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
  1372. OS << " depth " << T->getDepth() << " index " << T->getIndex();
  1373. if (T->isParameterPack())
  1374. OS << " pack";
  1375. dumpDeclRef(T->getDecl());
  1376. }
  1377. void TextNodeDumper::VisitSubstTemplateTypeParmType(
  1378. const SubstTemplateTypeParmType *T) {
  1379. dumpDeclRef(T->getAssociatedDecl());
  1380. VisitTemplateTypeParmDecl(T->getReplacedParameter());
  1381. if (auto PackIndex = T->getPackIndex())
  1382. OS << " pack_index " << *PackIndex;
  1383. }
  1384. void TextNodeDumper::VisitSubstTemplateTypeParmPackType(
  1385. const SubstTemplateTypeParmPackType *T) {
  1386. dumpDeclRef(T->getAssociatedDecl());
  1387. VisitTemplateTypeParmDecl(T->getReplacedParameter());
  1388. }
  1389. void TextNodeDumper::VisitAutoType(const AutoType *T) {
  1390. if (T->isDecltypeAuto())
  1391. OS << " decltype(auto)";
  1392. if (!T->isDeduced())
  1393. OS << " undeduced";
  1394. if (T->isConstrained()) {
  1395. dumpDeclRef(T->getTypeConstraintConcept());
  1396. for (const auto &Arg : T->getTypeConstraintArguments())
  1397. VisitTemplateArgument(Arg);
  1398. }
  1399. }
  1400. void TextNodeDumper::VisitDeducedTemplateSpecializationType(
  1401. const DeducedTemplateSpecializationType *T) {
  1402. if (T->getTemplateName().getKind() == TemplateName::UsingTemplate)
  1403. OS << " using";
  1404. }
  1405. void TextNodeDumper::VisitTemplateSpecializationType(
  1406. const TemplateSpecializationType *T) {
  1407. if (T->isTypeAlias())
  1408. OS << " alias";
  1409. if (T->getTemplateName().getKind() == TemplateName::UsingTemplate)
  1410. OS << " using";
  1411. OS << " ";
  1412. T->getTemplateName().dump(OS);
  1413. }
  1414. void TextNodeDumper::VisitInjectedClassNameType(
  1415. const InjectedClassNameType *T) {
  1416. dumpDeclRef(T->getDecl());
  1417. }
  1418. void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
  1419. dumpDeclRef(T->getDecl());
  1420. }
  1421. void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) {
  1422. if (auto N = T->getNumExpansions())
  1423. OS << " expansions " << *N;
  1424. }
  1425. void TextNodeDumper::VisitLabelDecl(const LabelDecl *D) { dumpName(D); }
  1426. void TextNodeDumper::VisitTypedefDecl(const TypedefDecl *D) {
  1427. dumpName(D);
  1428. dumpType(D->getUnderlyingType());
  1429. if (D->isModulePrivate())
  1430. OS << " __module_private__";
  1431. }
  1432. void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) {
  1433. if (D->isScoped()) {
  1434. if (D->isScopedUsingClassTag())
  1435. OS << " class";
  1436. else
  1437. OS << " struct";
  1438. }
  1439. dumpName(D);
  1440. if (D->isModulePrivate())
  1441. OS << " __module_private__";
  1442. if (D->isFixed())
  1443. dumpType(D->getIntegerType());
  1444. }
  1445. void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) {
  1446. OS << ' ' << D->getKindName();
  1447. dumpName(D);
  1448. if (D->isModulePrivate())
  1449. OS << " __module_private__";
  1450. if (D->isCompleteDefinition())
  1451. OS << " definition";
  1452. }
  1453. void TextNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
  1454. dumpName(D);
  1455. dumpType(D->getType());
  1456. }
  1457. void TextNodeDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
  1458. dumpName(D);
  1459. dumpType(D->getType());
  1460. for (const auto *Child : D->chain())
  1461. dumpDeclRef(Child);
  1462. }
  1463. void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
  1464. dumpName(D);
  1465. dumpType(D->getType());
  1466. StorageClass SC = D->getStorageClass();
  1467. if (SC != SC_None)
  1468. OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
  1469. if (D->isInlineSpecified())
  1470. OS << " inline";
  1471. if (D->isVirtualAsWritten())
  1472. OS << " virtual";
  1473. if (D->isModulePrivate())
  1474. OS << " __module_private__";
  1475. if (D->isPure())
  1476. OS << " pure";
  1477. if (D->isDefaulted()) {
  1478. OS << " default";
  1479. if (D->isDeleted())
  1480. OS << "_delete";
  1481. }
  1482. if (D->isDeletedAsWritten())
  1483. OS << " delete";
  1484. if (D->isTrivial())
  1485. OS << " trivial";
  1486. if (D->isIneligibleOrNotSelected())
  1487. OS << (isa<CXXDestructorDecl>(D) ? " not_selected" : " ineligible");
  1488. if (const auto *FPT = D->getType()->getAs<FunctionProtoType>()) {
  1489. FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
  1490. switch (EPI.ExceptionSpec.Type) {
  1491. default:
  1492. break;
  1493. case EST_Unevaluated:
  1494. OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
  1495. break;
  1496. case EST_Uninstantiated:
  1497. OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
  1498. break;
  1499. }
  1500. }
  1501. if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
  1502. if (MD->size_overridden_methods() != 0) {
  1503. auto dumpOverride = [=](const CXXMethodDecl *D) {
  1504. SplitQualType T_split = D->getType().split();
  1505. OS << D << " " << D->getParent()->getName() << "::" << D->getDeclName()
  1506. << " '" << QualType::getAsString(T_split, PrintPolicy) << "'";
  1507. };
  1508. AddChild([=] {
  1509. auto Overrides = MD->overridden_methods();
  1510. OS << "Overrides: [ ";
  1511. dumpOverride(*Overrides.begin());
  1512. for (const auto *Override :
  1513. llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
  1514. OS << ", ";
  1515. dumpOverride(Override);
  1516. }
  1517. OS << " ]";
  1518. });
  1519. }
  1520. }
  1521. if (!D->isInlineSpecified() && D->isInlined()) {
  1522. OS << " implicit-inline";
  1523. }
  1524. // Since NumParams comes from the FunctionProtoType of the FunctionDecl and
  1525. // the Params are set later, it is possible for a dump during debugging to
  1526. // encounter a FunctionDecl that has been created but hasn't been assigned
  1527. // ParmVarDecls yet.
  1528. if (!D->param_empty() && !D->param_begin())
  1529. OS << " <<<NULL params x " << D->getNumParams() << ">>>";
  1530. }
  1531. void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
  1532. const LifetimeExtendedTemporaryDecl *D) {
  1533. OS << " extended by ";
  1534. dumpBareDeclRef(D->getExtendingDecl());
  1535. OS << " mangling ";
  1536. {
  1537. ColorScope Color(OS, ShowColors, ValueColor);
  1538. OS << D->getManglingNumber();
  1539. }
  1540. }
  1541. void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
  1542. dumpName(D);
  1543. dumpType(D->getType());
  1544. if (D->isMutable())
  1545. OS << " mutable";
  1546. if (D->isModulePrivate())
  1547. OS << " __module_private__";
  1548. }
  1549. void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
  1550. dumpName(D);
  1551. dumpType(D->getType());
  1552. StorageClass SC = D->getStorageClass();
  1553. if (SC != SC_None)
  1554. OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
  1555. switch (D->getTLSKind()) {
  1556. case VarDecl::TLS_None:
  1557. break;
  1558. case VarDecl::TLS_Static:
  1559. OS << " tls";
  1560. break;
  1561. case VarDecl::TLS_Dynamic:
  1562. OS << " tls_dynamic";
  1563. break;
  1564. }
  1565. if (D->isModulePrivate())
  1566. OS << " __module_private__";
  1567. if (D->isNRVOVariable())
  1568. OS << " nrvo";
  1569. if (D->isInline())
  1570. OS << " inline";
  1571. if (D->isConstexpr())
  1572. OS << " constexpr";
  1573. if (D->hasInit()) {
  1574. switch (D->getInitStyle()) {
  1575. case VarDecl::CInit:
  1576. OS << " cinit";
  1577. break;
  1578. case VarDecl::CallInit:
  1579. OS << " callinit";
  1580. break;
  1581. case VarDecl::ListInit:
  1582. OS << " listinit";
  1583. break;
  1584. case VarDecl::ParenListInit:
  1585. OS << " parenlistinit";
  1586. }
  1587. }
  1588. if (D->needsDestruction(D->getASTContext()))
  1589. OS << " destroyed";
  1590. if (D->isParameterPack())
  1591. OS << " pack";
  1592. if (D->hasInit()) {
  1593. const Expr *E = D->getInit();
  1594. // Only dump the value of constexpr VarDecls for now.
  1595. if (E && !E->isValueDependent() && D->isConstexpr()) {
  1596. const APValue *Value = D->evaluateValue();
  1597. if (Value)
  1598. AddChild("value", [=] { Visit(*Value, E->getType()); });
  1599. }
  1600. }
  1601. }
  1602. void TextNodeDumper::VisitBindingDecl(const BindingDecl *D) {
  1603. dumpName(D);
  1604. dumpType(D->getType());
  1605. }
  1606. void TextNodeDumper::VisitCapturedDecl(const CapturedDecl *D) {
  1607. if (D->isNothrow())
  1608. OS << " nothrow";
  1609. }
  1610. void TextNodeDumper::VisitImportDecl(const ImportDecl *D) {
  1611. OS << ' ' << D->getImportedModule()->getFullModuleName();
  1612. for (Decl *InitD :
  1613. D->getASTContext().getModuleInitializers(D->getImportedModule()))
  1614. dumpDeclRef(InitD, "initializer");
  1615. }
  1616. void TextNodeDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
  1617. OS << ' ';
  1618. switch (D->getCommentKind()) {
  1619. case PCK_Unknown:
  1620. llvm_unreachable("unexpected pragma comment kind");
  1621. case PCK_Compiler:
  1622. OS << "compiler";
  1623. break;
  1624. case PCK_ExeStr:
  1625. OS << "exestr";
  1626. break;
  1627. case PCK_Lib:
  1628. OS << "lib";
  1629. break;
  1630. case PCK_Linker:
  1631. OS << "linker";
  1632. break;
  1633. case PCK_User:
  1634. OS << "user";
  1635. break;
  1636. }
  1637. StringRef Arg = D->getArg();
  1638. if (!Arg.empty())
  1639. OS << " \"" << Arg << "\"";
  1640. }
  1641. void TextNodeDumper::VisitPragmaDetectMismatchDecl(
  1642. const PragmaDetectMismatchDecl *D) {
  1643. OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
  1644. }
  1645. void TextNodeDumper::VisitOMPExecutableDirective(
  1646. const OMPExecutableDirective *D) {
  1647. if (D->isStandaloneDirective())
  1648. OS << " openmp_standalone_directive";
  1649. }
  1650. void TextNodeDumper::VisitOMPDeclareReductionDecl(
  1651. const OMPDeclareReductionDecl *D) {
  1652. dumpName(D);
  1653. dumpType(D->getType());
  1654. OS << " combiner";
  1655. dumpPointer(D->getCombiner());
  1656. if (const auto *Initializer = D->getInitializer()) {
  1657. OS << " initializer";
  1658. dumpPointer(Initializer);
  1659. switch (D->getInitializerKind()) {
  1660. case OMPDeclareReductionDecl::DirectInit:
  1661. OS << " omp_priv = ";
  1662. break;
  1663. case OMPDeclareReductionDecl::CopyInit:
  1664. OS << " omp_priv ()";
  1665. break;
  1666. case OMPDeclareReductionDecl::CallInit:
  1667. break;
  1668. }
  1669. }
  1670. }
  1671. void TextNodeDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
  1672. for (const auto *C : D->clauselists()) {
  1673. AddChild([=] {
  1674. if (!C) {
  1675. ColorScope Color(OS, ShowColors, NullColor);
  1676. OS << "<<<NULL>>> OMPClause";
  1677. return;
  1678. }
  1679. {
  1680. ColorScope Color(OS, ShowColors, AttrColor);
  1681. StringRef ClauseName(
  1682. llvm::omp::getOpenMPClauseName(C->getClauseKind()));
  1683. OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
  1684. << ClauseName.drop_front() << "Clause";
  1685. }
  1686. dumpPointer(C);
  1687. dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
  1688. });
  1689. }
  1690. }
  1691. void TextNodeDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
  1692. dumpName(D);
  1693. dumpType(D->getType());
  1694. }
  1695. void TextNodeDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
  1696. dumpName(D);
  1697. if (D->isInline())
  1698. OS << " inline";
  1699. if (D->isNested())
  1700. OS << " nested";
  1701. if (!D->isOriginalNamespace())
  1702. dumpDeclRef(D->getOriginalNamespace(), "original");
  1703. }
  1704. void TextNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
  1705. OS << ' ';
  1706. dumpBareDeclRef(D->getNominatedNamespace());
  1707. }
  1708. void TextNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
  1709. dumpName(D);
  1710. dumpDeclRef(D->getAliasedNamespace());
  1711. }
  1712. void TextNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
  1713. dumpName(D);
  1714. dumpType(D->getUnderlyingType());
  1715. }
  1716. void TextNodeDumper::VisitTypeAliasTemplateDecl(
  1717. const TypeAliasTemplateDecl *D) {
  1718. dumpName(D);
  1719. }
  1720. void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
  1721. VisitRecordDecl(D);
  1722. if (!D->isCompleteDefinition())
  1723. return;
  1724. AddChild([=] {
  1725. {
  1726. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1727. OS << "DefinitionData";
  1728. }
  1729. #define FLAG(fn, name) \
  1730. if (D->fn()) \
  1731. OS << " " #name;
  1732. FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
  1733. FLAG(isGenericLambda, generic);
  1734. FLAG(isLambda, lambda);
  1735. FLAG(isAnonymousStructOrUnion, is_anonymous);
  1736. FLAG(canPassInRegisters, pass_in_registers);
  1737. FLAG(isEmpty, empty);
  1738. FLAG(isAggregate, aggregate);
  1739. FLAG(isStandardLayout, standard_layout);
  1740. FLAG(isTriviallyCopyable, trivially_copyable);
  1741. FLAG(isPOD, pod);
  1742. FLAG(isTrivial, trivial);
  1743. FLAG(isPolymorphic, polymorphic);
  1744. FLAG(isAbstract, abstract);
  1745. FLAG(isLiteral, literal);
  1746. FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
  1747. FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
  1748. FLAG(hasMutableFields, has_mutable_fields);
  1749. FLAG(hasVariantMembers, has_variant_members);
  1750. FLAG(allowConstDefaultInit, can_const_default_init);
  1751. AddChild([=] {
  1752. {
  1753. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1754. OS << "DefaultConstructor";
  1755. }
  1756. FLAG(hasDefaultConstructor, exists);
  1757. FLAG(hasTrivialDefaultConstructor, trivial);
  1758. FLAG(hasNonTrivialDefaultConstructor, non_trivial);
  1759. FLAG(hasUserProvidedDefaultConstructor, user_provided);
  1760. FLAG(hasConstexprDefaultConstructor, constexpr);
  1761. FLAG(needsImplicitDefaultConstructor, needs_implicit);
  1762. FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
  1763. });
  1764. AddChild([=] {
  1765. {
  1766. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1767. OS << "CopyConstructor";
  1768. }
  1769. FLAG(hasSimpleCopyConstructor, simple);
  1770. FLAG(hasTrivialCopyConstructor, trivial);
  1771. FLAG(hasNonTrivialCopyConstructor, non_trivial);
  1772. FLAG(hasUserDeclaredCopyConstructor, user_declared);
  1773. FLAG(hasCopyConstructorWithConstParam, has_const_param);
  1774. FLAG(needsImplicitCopyConstructor, needs_implicit);
  1775. FLAG(needsOverloadResolutionForCopyConstructor,
  1776. needs_overload_resolution);
  1777. if (!D->needsOverloadResolutionForCopyConstructor())
  1778. FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
  1779. FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
  1780. });
  1781. AddChild([=] {
  1782. {
  1783. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1784. OS << "MoveConstructor";
  1785. }
  1786. FLAG(hasMoveConstructor, exists);
  1787. FLAG(hasSimpleMoveConstructor, simple);
  1788. FLAG(hasTrivialMoveConstructor, trivial);
  1789. FLAG(hasNonTrivialMoveConstructor, non_trivial);
  1790. FLAG(hasUserDeclaredMoveConstructor, user_declared);
  1791. FLAG(needsImplicitMoveConstructor, needs_implicit);
  1792. FLAG(needsOverloadResolutionForMoveConstructor,
  1793. needs_overload_resolution);
  1794. if (!D->needsOverloadResolutionForMoveConstructor())
  1795. FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
  1796. });
  1797. AddChild([=] {
  1798. {
  1799. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1800. OS << "CopyAssignment";
  1801. }
  1802. FLAG(hasSimpleCopyAssignment, simple);
  1803. FLAG(hasTrivialCopyAssignment, trivial);
  1804. FLAG(hasNonTrivialCopyAssignment, non_trivial);
  1805. FLAG(hasCopyAssignmentWithConstParam, has_const_param);
  1806. FLAG(hasUserDeclaredCopyAssignment, user_declared);
  1807. FLAG(needsImplicitCopyAssignment, needs_implicit);
  1808. FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
  1809. FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
  1810. });
  1811. AddChild([=] {
  1812. {
  1813. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1814. OS << "MoveAssignment";
  1815. }
  1816. FLAG(hasMoveAssignment, exists);
  1817. FLAG(hasSimpleMoveAssignment, simple);
  1818. FLAG(hasTrivialMoveAssignment, trivial);
  1819. FLAG(hasNonTrivialMoveAssignment, non_trivial);
  1820. FLAG(hasUserDeclaredMoveAssignment, user_declared);
  1821. FLAG(needsImplicitMoveAssignment, needs_implicit);
  1822. FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
  1823. });
  1824. AddChild([=] {
  1825. {
  1826. ColorScope Color(OS, ShowColors, DeclKindNameColor);
  1827. OS << "Destructor";
  1828. }
  1829. FLAG(hasSimpleDestructor, simple);
  1830. FLAG(hasIrrelevantDestructor, irrelevant);
  1831. FLAG(hasTrivialDestructor, trivial);
  1832. FLAG(hasNonTrivialDestructor, non_trivial);
  1833. FLAG(hasUserDeclaredDestructor, user_declared);
  1834. FLAG(hasConstexprDestructor, constexpr);
  1835. FLAG(needsImplicitDestructor, needs_implicit);
  1836. FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
  1837. if (!D->needsOverloadResolutionForDestructor())
  1838. FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
  1839. });
  1840. });
  1841. for (const auto &I : D->bases()) {
  1842. AddChild([=] {
  1843. if (I.isVirtual())
  1844. OS << "virtual ";
  1845. dumpAccessSpecifier(I.getAccessSpecifier());
  1846. dumpType(I.getType());
  1847. if (I.isPackExpansion())
  1848. OS << "...";
  1849. });
  1850. }
  1851. }
  1852. void TextNodeDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
  1853. dumpName(D);
  1854. }
  1855. void TextNodeDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
  1856. dumpName(D);
  1857. }
  1858. void TextNodeDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
  1859. dumpName(D);
  1860. }
  1861. void TextNodeDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
  1862. dumpName(D);
  1863. }
  1864. void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
  1865. if (const auto *TC = D->getTypeConstraint()) {
  1866. OS << " ";
  1867. dumpBareDeclRef(TC->getNamedConcept());
  1868. if (TC->getNamedConcept() != TC->getFoundDecl()) {
  1869. OS << " (";
  1870. dumpBareDeclRef(TC->getFoundDecl());
  1871. OS << ")";
  1872. }
  1873. } else if (D->wasDeclaredWithTypename())
  1874. OS << " typename";
  1875. else
  1876. OS << " class";
  1877. OS << " depth " << D->getDepth() << " index " << D->getIndex();
  1878. if (D->isParameterPack())
  1879. OS << " ...";
  1880. dumpName(D);
  1881. }
  1882. void TextNodeDumper::VisitNonTypeTemplateParmDecl(
  1883. const NonTypeTemplateParmDecl *D) {
  1884. dumpType(D->getType());
  1885. OS << " depth " << D->getDepth() << " index " << D->getIndex();
  1886. if (D->isParameterPack())
  1887. OS << " ...";
  1888. dumpName(D);
  1889. }
  1890. void TextNodeDumper::VisitTemplateTemplateParmDecl(
  1891. const TemplateTemplateParmDecl *D) {
  1892. OS << " depth " << D->getDepth() << " index " << D->getIndex();
  1893. if (D->isParameterPack())
  1894. OS << " ...";
  1895. dumpName(D);
  1896. }
  1897. void TextNodeDumper::VisitUsingDecl(const UsingDecl *D) {
  1898. OS << ' ';
  1899. if (D->getQualifier())
  1900. D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
  1901. OS << D->getDeclName();
  1902. }
  1903. void TextNodeDumper::VisitUsingEnumDecl(const UsingEnumDecl *D) {
  1904. OS << ' ';
  1905. dumpBareDeclRef(D->getEnumDecl());
  1906. }
  1907. void TextNodeDumper::VisitUnresolvedUsingTypenameDecl(
  1908. const UnresolvedUsingTypenameDecl *D) {
  1909. OS << ' ';
  1910. if (D->getQualifier())
  1911. D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
  1912. OS << D->getDeclName();
  1913. }
  1914. void TextNodeDumper::VisitUnresolvedUsingValueDecl(
  1915. const UnresolvedUsingValueDecl *D) {
  1916. OS << ' ';
  1917. if (D->getQualifier())
  1918. D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
  1919. OS << D->getDeclName();
  1920. dumpType(D->getType());
  1921. }
  1922. void TextNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
  1923. OS << ' ';
  1924. dumpBareDeclRef(D->getTargetDecl());
  1925. }
  1926. void TextNodeDumper::VisitConstructorUsingShadowDecl(
  1927. const ConstructorUsingShadowDecl *D) {
  1928. if (D->constructsVirtualBase())
  1929. OS << " virtual";
  1930. AddChild([=] {
  1931. OS << "target ";
  1932. dumpBareDeclRef(D->getTargetDecl());
  1933. });
  1934. AddChild([=] {
  1935. OS << "nominated ";
  1936. dumpBareDeclRef(D->getNominatedBaseClass());
  1937. OS << ' ';
  1938. dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
  1939. });
  1940. AddChild([=] {
  1941. OS << "constructed ";
  1942. dumpBareDeclRef(D->getConstructedBaseClass());
  1943. OS << ' ';
  1944. dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
  1945. });
  1946. }
  1947. void TextNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
  1948. switch (D->getLanguage()) {
  1949. case LinkageSpecDecl::lang_c:
  1950. OS << " C";
  1951. break;
  1952. case LinkageSpecDecl::lang_cxx:
  1953. OS << " C++";
  1954. break;
  1955. }
  1956. }
  1957. void TextNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
  1958. OS << ' ';
  1959. dumpAccessSpecifier(D->getAccess());
  1960. }
  1961. void TextNodeDumper::VisitFriendDecl(const FriendDecl *D) {
  1962. if (TypeSourceInfo *T = D->getFriendType())
  1963. dumpType(T->getType());
  1964. }
  1965. void TextNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
  1966. dumpName(D);
  1967. dumpType(D->getType());
  1968. if (D->getSynthesize())
  1969. OS << " synthesize";
  1970. switch (D->getAccessControl()) {
  1971. case ObjCIvarDecl::None:
  1972. OS << " none";
  1973. break;
  1974. case ObjCIvarDecl::Private:
  1975. OS << " private";
  1976. break;
  1977. case ObjCIvarDecl::Protected:
  1978. OS << " protected";
  1979. break;
  1980. case ObjCIvarDecl::Public:
  1981. OS << " public";
  1982. break;
  1983. case ObjCIvarDecl::Package:
  1984. OS << " package";
  1985. break;
  1986. }
  1987. }
  1988. void TextNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
  1989. if (D->isInstanceMethod())
  1990. OS << " -";
  1991. else
  1992. OS << " +";
  1993. dumpName(D);
  1994. dumpType(D->getReturnType());
  1995. if (D->isVariadic())
  1996. OS << " variadic";
  1997. }
  1998. void TextNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
  1999. dumpName(D);
  2000. switch (D->getVariance()) {
  2001. case ObjCTypeParamVariance::Invariant:
  2002. break;
  2003. case ObjCTypeParamVariance::Covariant:
  2004. OS << " covariant";
  2005. break;
  2006. case ObjCTypeParamVariance::Contravariant:
  2007. OS << " contravariant";
  2008. break;
  2009. }
  2010. if (D->hasExplicitBound())
  2011. OS << " bounded";
  2012. dumpType(D->getUnderlyingType());
  2013. }
  2014. void TextNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
  2015. dumpName(D);
  2016. dumpDeclRef(D->getClassInterface());
  2017. dumpDeclRef(D->getImplementation());
  2018. for (const auto *P : D->protocols())
  2019. dumpDeclRef(P);
  2020. }
  2021. void TextNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
  2022. dumpName(D);
  2023. dumpDeclRef(D->getClassInterface());
  2024. dumpDeclRef(D->getCategoryDecl());
  2025. }
  2026. void TextNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
  2027. dumpName(D);
  2028. for (const auto *Child : D->protocols())
  2029. dumpDeclRef(Child);
  2030. }
  2031. void TextNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
  2032. dumpName(D);
  2033. dumpDeclRef(D->getSuperClass(), "super");
  2034. dumpDeclRef(D->getImplementation());
  2035. for (const auto *Child : D->protocols())
  2036. dumpDeclRef(Child);
  2037. }
  2038. void TextNodeDumper::VisitObjCImplementationDecl(
  2039. const ObjCImplementationDecl *D) {
  2040. dumpName(D);
  2041. dumpDeclRef(D->getSuperClass(), "super");
  2042. dumpDeclRef(D->getClassInterface());
  2043. }
  2044. void TextNodeDumper::VisitObjCCompatibleAliasDecl(
  2045. const ObjCCompatibleAliasDecl *D) {
  2046. dumpName(D);
  2047. dumpDeclRef(D->getClassInterface());
  2048. }
  2049. void TextNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
  2050. dumpName(D);
  2051. dumpType(D->getType());
  2052. if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
  2053. OS << " required";
  2054. else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
  2055. OS << " optional";
  2056. ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes();
  2057. if (Attrs != ObjCPropertyAttribute::kind_noattr) {
  2058. if (Attrs & ObjCPropertyAttribute::kind_readonly)
  2059. OS << " readonly";
  2060. if (Attrs & ObjCPropertyAttribute::kind_assign)
  2061. OS << " assign";
  2062. if (Attrs & ObjCPropertyAttribute::kind_readwrite)
  2063. OS << " readwrite";
  2064. if (Attrs & ObjCPropertyAttribute::kind_retain)
  2065. OS << " retain";
  2066. if (Attrs & ObjCPropertyAttribute::kind_copy)
  2067. OS << " copy";
  2068. if (Attrs & ObjCPropertyAttribute::kind_nonatomic)
  2069. OS << " nonatomic";
  2070. if (Attrs & ObjCPropertyAttribute::kind_atomic)
  2071. OS << " atomic";
  2072. if (Attrs & ObjCPropertyAttribute::kind_weak)
  2073. OS << " weak";
  2074. if (Attrs & ObjCPropertyAttribute::kind_strong)
  2075. OS << " strong";
  2076. if (Attrs & ObjCPropertyAttribute::kind_unsafe_unretained)
  2077. OS << " unsafe_unretained";
  2078. if (Attrs & ObjCPropertyAttribute::kind_class)
  2079. OS << " class";
  2080. if (Attrs & ObjCPropertyAttribute::kind_direct)
  2081. OS << " direct";
  2082. if (Attrs & ObjCPropertyAttribute::kind_getter)
  2083. dumpDeclRef(D->getGetterMethodDecl(), "getter");
  2084. if (Attrs & ObjCPropertyAttribute::kind_setter)
  2085. dumpDeclRef(D->getSetterMethodDecl(), "setter");
  2086. }
  2087. }
  2088. void TextNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
  2089. dumpName(D->getPropertyDecl());
  2090. if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
  2091. OS << " synthesize";
  2092. else
  2093. OS << " dynamic";
  2094. dumpDeclRef(D->getPropertyDecl());
  2095. dumpDeclRef(D->getPropertyIvarDecl());
  2096. }
  2097. void TextNodeDumper::VisitBlockDecl(const BlockDecl *D) {
  2098. if (D->isVariadic())
  2099. OS << " variadic";
  2100. if (D->capturesCXXThis())
  2101. OS << " captures_this";
  2102. }
  2103. void TextNodeDumper::VisitConceptDecl(const ConceptDecl *D) {
  2104. dumpName(D);
  2105. }
  2106. void TextNodeDumper::VisitCompoundStmt(const CompoundStmt *S) {
  2107. VisitStmt(S);
  2108. if (S->hasStoredFPFeatures())
  2109. printFPOptions(S->getStoredFPFeatures());
  2110. }
  2111. void TextNodeDumper::VisitHLSLBufferDecl(const HLSLBufferDecl *D) {
  2112. if (D->isCBuffer())
  2113. OS << " cbuffer";
  2114. else
  2115. OS << " tbuffer";
  2116. dumpName(D);
  2117. }