RecursiveASTVisitor.h 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the RecursiveASTVisitor interface, which recursively
  15. // traverses the entire AST.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
  19. #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
  20. #include "clang/AST/ASTConcept.h"
  21. #include "clang/AST/Attr.h"
  22. #include "clang/AST/Decl.h"
  23. #include "clang/AST/DeclBase.h"
  24. #include "clang/AST/DeclCXX.h"
  25. #include "clang/AST/DeclFriend.h"
  26. #include "clang/AST/DeclObjC.h"
  27. #include "clang/AST/DeclOpenMP.h"
  28. #include "clang/AST/DeclTemplate.h"
  29. #include "clang/AST/DeclarationName.h"
  30. #include "clang/AST/Expr.h"
  31. #include "clang/AST/ExprCXX.h"
  32. #include "clang/AST/ExprConcepts.h"
  33. #include "clang/AST/ExprObjC.h"
  34. #include "clang/AST/ExprOpenMP.h"
  35. #include "clang/AST/LambdaCapture.h"
  36. #include "clang/AST/NestedNameSpecifier.h"
  37. #include "clang/AST/OpenMPClause.h"
  38. #include "clang/AST/Stmt.h"
  39. #include "clang/AST/StmtCXX.h"
  40. #include "clang/AST/StmtObjC.h"
  41. #include "clang/AST/StmtOpenMP.h"
  42. #include "clang/AST/TemplateBase.h"
  43. #include "clang/AST/TemplateName.h"
  44. #include "clang/AST/Type.h"
  45. #include "clang/AST/TypeLoc.h"
  46. #include "clang/Basic/LLVM.h"
  47. #include "clang/Basic/OpenMPKinds.h"
  48. #include "clang/Basic/Specifiers.h"
  49. #include "llvm/ADT/PointerIntPair.h"
  50. #include "llvm/ADT/SmallVector.h"
  51. #include "llvm/Support/Casting.h"
  52. #include <algorithm>
  53. #include <cstddef>
  54. #include <type_traits>
  55. namespace clang {
  56. // A helper macro to implement short-circuiting when recursing. It
  57. // invokes CALL_EXPR, which must be a method call, on the derived
  58. // object (s.t. a user of RecursiveASTVisitor can override the method
  59. // in CALL_EXPR).
  60. #define TRY_TO(CALL_EXPR) \
  61. do { \
  62. if (!getDerived().CALL_EXPR) \
  63. return false; \
  64. } while (false)
  65. namespace detail {
  66. template <typename T, typename U>
  67. struct has_same_member_pointer_type : std::false_type {};
  68. template <typename T, typename U, typename R, typename... P>
  69. struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
  70. : std::true_type {};
  71. /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
  72. /// are pointers to the same non-static member function.
  73. template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
  74. LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto
  75. isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr,
  76. [[maybe_unused]] SecondMethodPtrTy SecondMethodPtr)
  77. -> bool {
  78. if constexpr (has_same_member_pointer_type<FirstMethodPtrTy,
  79. SecondMethodPtrTy>::value)
  80. return FirstMethodPtr == SecondMethodPtr;
  81. return false;
  82. }
  83. } // end namespace detail
  84. /// A class that does preorder or postorder
  85. /// depth-first traversal on the entire Clang AST and visits each node.
  86. ///
  87. /// This class performs three distinct tasks:
  88. /// 1. traverse the AST (i.e. go to each node);
  89. /// 2. at a given node, walk up the class hierarchy, starting from
  90. /// the node's dynamic type, until the top-most class (e.g. Stmt,
  91. /// Decl, or Type) is reached.
  92. /// 3. given a (node, class) combination, where 'class' is some base
  93. /// class of the dynamic type of 'node', call a user-overridable
  94. /// function to actually visit the node.
  95. ///
  96. /// These tasks are done by three groups of methods, respectively:
  97. /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point
  98. /// for traversing an AST rooted at x. This method simply
  99. /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
  100. /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and
  101. /// then recursively visits the child nodes of x.
  102. /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work
  103. /// similarly.
  104. /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit
  105. /// any child node of x. Instead, it first calls WalkUpFromBar(x)
  106. /// where Bar is the direct parent class of Foo (unless Foo has
  107. /// no parent), and then calls VisitFoo(x) (see the next list item).
  108. /// 3. VisitFoo(Foo *x) does task #3.
  109. ///
  110. /// These three method groups are tiered (Traverse* > WalkUpFrom* >
  111. /// Visit*). A method (e.g. Traverse*) may call methods from the same
  112. /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
  113. /// It may not call methods from a higher tier.
  114. ///
  115. /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
  116. /// is Foo's super class) before calling VisitFoo(), the result is
  117. /// that the Visit*() methods for a given node are called in the
  118. /// top-down order (e.g. for a node of type NamespaceDecl, the order will
  119. /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
  120. ///
  121. /// This scheme guarantees that all Visit*() calls for the same AST
  122. /// node are grouped together. In other words, Visit*() methods for
  123. /// different nodes are never interleaved.
  124. ///
  125. /// Clients of this visitor should subclass the visitor (providing
  126. /// themselves as the template argument, using the curiously recurring
  127. /// template pattern) and override any of the Traverse*, WalkUpFrom*,
  128. /// and Visit* methods for declarations, types, statements,
  129. /// expressions, or other AST nodes where the visitor should customize
  130. /// behavior. Most users only need to override Visit*. Advanced
  131. /// users may override Traverse* and WalkUpFrom* to implement custom
  132. /// traversal strategies. Returning false from one of these overridden
  133. /// functions will abort the entire traversal.
  134. ///
  135. /// By default, this visitor tries to visit every part of the explicit
  136. /// source code exactly once. The default policy towards templates
  137. /// is to descend into the 'pattern' class or function body, not any
  138. /// explicit or implicit instantiations. Explicit specializations
  139. /// are still visited, and the patterns of partial specializations
  140. /// are visited separately. This behavior can be changed by
  141. /// overriding shouldVisitTemplateInstantiations() in the derived class
  142. /// to return true, in which case all known implicit and explicit
  143. /// instantiations will be visited at the same time as the pattern
  144. /// from which they were produced.
  145. ///
  146. /// By default, this visitor preorder traverses the AST. If postorder traversal
  147. /// is needed, the \c shouldTraversePostOrder method needs to be overridden
  148. /// to return \c true.
  149. template <typename Derived> class RecursiveASTVisitor {
  150. public:
  151. /// A queue used for performing data recursion over statements.
  152. /// Parameters involving this type are used to implement data
  153. /// recursion over Stmts and Exprs within this class, and should
  154. /// typically not be explicitly specified by derived classes.
  155. /// The bool bit indicates whether the statement has been traversed or not.
  156. typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
  157. DataRecursionQueue;
  158. /// Return a reference to the derived class.
  159. Derived &getDerived() { return *static_cast<Derived *>(this); }
  160. /// Return whether this visitor should recurse into
  161. /// template instantiations.
  162. bool shouldVisitTemplateInstantiations() const { return false; }
  163. /// Return whether this visitor should recurse into the types of
  164. /// TypeLocs.
  165. bool shouldWalkTypesOfTypeLocs() const { return true; }
  166. /// Return whether this visitor should recurse into implicit
  167. /// code, e.g., implicit constructors and destructors.
  168. bool shouldVisitImplicitCode() const { return false; }
  169. /// Return whether this visitor should recurse into lambda body
  170. bool shouldVisitLambdaBody() const { return true; }
  171. /// Return whether this visitor should traverse post-order.
  172. bool shouldTraversePostOrder() const { return false; }
  173. /// Recursively visits an entire AST, starting from the TranslationUnitDecl.
  174. /// \returns false if visitation was terminated early.
  175. bool TraverseAST(ASTContext &AST) {
  176. // Currently just an alias for TraverseDecl(TUDecl), but kept in case
  177. // we change the implementation again.
  178. return getDerived().TraverseDecl(AST.getTranslationUnitDecl());
  179. }
  180. /// Recursively visit a statement or expression, by
  181. /// dispatching to Traverse*() based on the argument's dynamic type.
  182. ///
  183. /// \returns false if the visitation was terminated early, true
  184. /// otherwise (including when the argument is nullptr).
  185. bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
  186. /// Invoked before visiting a statement or expression via data recursion.
  187. ///
  188. /// \returns false to skip visiting the node, true otherwise.
  189. bool dataTraverseStmtPre(Stmt *S) { return true; }
  190. /// Invoked after visiting a statement or expression via data recursion.
  191. /// This is not invoked if the previously invoked \c dataTraverseStmtPre
  192. /// returned false.
  193. ///
  194. /// \returns false if the visitation was terminated early, true otherwise.
  195. bool dataTraverseStmtPost(Stmt *S) { return true; }
  196. /// Recursively visit a type, by dispatching to
  197. /// Traverse*Type() based on the argument's getTypeClass() property.
  198. ///
  199. /// \returns false if the visitation was terminated early, true
  200. /// otherwise (including when the argument is a Null type).
  201. bool TraverseType(QualType T);
  202. /// Recursively visit a type with location, by dispatching to
  203. /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
  204. ///
  205. /// \returns false if the visitation was terminated early, true
  206. /// otherwise (including when the argument is a Null type location).
  207. bool TraverseTypeLoc(TypeLoc TL);
  208. /// Recursively visit an attribute, by dispatching to
  209. /// Traverse*Attr() based on the argument's dynamic type.
  210. ///
  211. /// \returns false if the visitation was terminated early, true
  212. /// otherwise (including when the argument is a Null type location).
  213. bool TraverseAttr(Attr *At);
  214. /// Recursively visit a declaration, by dispatching to
  215. /// Traverse*Decl() based on the argument's dynamic type.
  216. ///
  217. /// \returns false if the visitation was terminated early, true
  218. /// otherwise (including when the argument is NULL).
  219. bool TraverseDecl(Decl *D);
  220. /// Recursively visit a C++ nested-name-specifier.
  221. ///
  222. /// \returns false if the visitation was terminated early, true otherwise.
  223. bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
  224. /// Recursively visit a C++ nested-name-specifier with location
  225. /// information.
  226. ///
  227. /// \returns false if the visitation was terminated early, true otherwise.
  228. bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
  229. /// Recursively visit a name with its location information.
  230. ///
  231. /// \returns false if the visitation was terminated early, true otherwise.
  232. bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
  233. /// Recursively visit a template name and dispatch to the
  234. /// appropriate method.
  235. ///
  236. /// \returns false if the visitation was terminated early, true otherwise.
  237. bool TraverseTemplateName(TemplateName Template);
  238. /// Recursively visit a template argument and dispatch to the
  239. /// appropriate method for the argument type.
  240. ///
  241. /// \returns false if the visitation was terminated early, true otherwise.
  242. // FIXME: migrate callers to TemplateArgumentLoc instead.
  243. bool TraverseTemplateArgument(const TemplateArgument &Arg);
  244. /// Recursively visit a template argument location and dispatch to the
  245. /// appropriate method for the argument type.
  246. ///
  247. /// \returns false if the visitation was terminated early, true otherwise.
  248. bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
  249. /// Recursively visit a set of template arguments.
  250. /// This can be overridden by a subclass, but it's not expected that
  251. /// will be needed -- this visitor always dispatches to another.
  252. ///
  253. /// \returns false if the visitation was terminated early, true otherwise.
  254. // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
  255. bool TraverseTemplateArguments(ArrayRef<TemplateArgument> Args);
  256. /// Recursively visit a base specifier. This can be overridden by a
  257. /// subclass.
  258. ///
  259. /// \returns false if the visitation was terminated early, true otherwise.
  260. bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base);
  261. /// Recursively visit a constructor initializer. This
  262. /// automatically dispatches to another visitor for the initializer
  263. /// expression, but not for the name of the initializer, so may
  264. /// be overridden for clients that need access to the name.
  265. ///
  266. /// \returns false if the visitation was terminated early, true otherwise.
  267. bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
  268. /// Recursively visit a lambda capture. \c Init is the expression that
  269. /// will be used to initialize the capture.
  270. ///
  271. /// \returns false if the visitation was terminated early, true otherwise.
  272. bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
  273. Expr *Init);
  274. /// Recursively visit the syntactic or semantic form of an
  275. /// initialization list.
  276. ///
  277. /// \returns false if the visitation was terminated early, true otherwise.
  278. bool TraverseSynOrSemInitListExpr(InitListExpr *S,
  279. DataRecursionQueue *Queue = nullptr);
  280. /// Recursively visit an Objective-C protocol reference with location
  281. /// information.
  282. ///
  283. /// \returns false if the visitation was terminated early, true otherwise.
  284. bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc);
  285. // ---- Methods on Attrs ----
  286. // Visit an attribute.
  287. bool VisitAttr(Attr *A) { return true; }
  288. // Declare Traverse* and empty Visit* for all Attr classes.
  289. #define ATTR_VISITOR_DECLS_ONLY
  290. #include "clang/AST/AttrVisitor.inc"
  291. #undef ATTR_VISITOR_DECLS_ONLY
  292. // ---- Methods on Stmts ----
  293. Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
  294. private:
  295. // Traverse the given statement. If the most-derived traverse function takes a
  296. // data recursion queue, pass it on; otherwise, discard it. Note that the
  297. // first branch of this conditional must compile whether or not the derived
  298. // class can take a queue, so if we're taking the second arm, make the first
  299. // arm call our function rather than the derived class version.
  300. #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE) \
  301. (::clang::detail::has_same_member_pointer_type< \
  302. decltype(&RecursiveASTVisitor::Traverse##NAME), \
  303. decltype(&Derived::Traverse##NAME)>::value \
  304. ? static_cast<std::conditional_t< \
  305. ::clang::detail::has_same_member_pointer_type< \
  306. decltype(&RecursiveASTVisitor::Traverse##NAME), \
  307. decltype(&Derived::Traverse##NAME)>::value, \
  308. Derived &, RecursiveASTVisitor &>>(*this) \
  309. .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE) \
  310. : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
  311. // Try to traverse the given statement, or enqueue it if we're performing data
  312. // recursion in the middle of traversing another statement. Can only be called
  313. // from within a DEF_TRAVERSE_STMT body or similar context.
  314. #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S) \
  315. do { \
  316. if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue)) \
  317. return false; \
  318. } while (false)
  319. public:
  320. // Declare Traverse*() for all concrete Stmt classes.
  321. #define ABSTRACT_STMT(STMT)
  322. #define STMT(CLASS, PARENT) \
  323. bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
  324. #include "clang/AST/StmtNodes.inc"
  325. // The above header #undefs ABSTRACT_STMT and STMT upon exit.
  326. // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
  327. bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
  328. bool VisitStmt(Stmt *S) { return true; }
  329. #define STMT(CLASS, PARENT) \
  330. bool WalkUpFrom##CLASS(CLASS *S) { \
  331. TRY_TO(WalkUpFrom##PARENT(S)); \
  332. TRY_TO(Visit##CLASS(S)); \
  333. return true; \
  334. } \
  335. bool Visit##CLASS(CLASS *S) { return true; }
  336. #include "clang/AST/StmtNodes.inc"
  337. // ---- Methods on Types ----
  338. // FIXME: revamp to take TypeLoc's rather than Types.
  339. // Declare Traverse*() for all concrete Type classes.
  340. #define ABSTRACT_TYPE(CLASS, BASE)
  341. #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
  342. #include "clang/AST/TypeNodes.inc"
  343. // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
  344. // Define WalkUpFrom*() and empty Visit*() for all Type classes.
  345. bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
  346. bool VisitType(Type *T) { return true; }
  347. #define TYPE(CLASS, BASE) \
  348. bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
  349. TRY_TO(WalkUpFrom##BASE(T)); \
  350. TRY_TO(Visit##CLASS##Type(T)); \
  351. return true; \
  352. } \
  353. bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
  354. #include "clang/AST/TypeNodes.inc"
  355. // ---- Methods on TypeLocs ----
  356. // FIXME: this currently just calls the matching Type methods
  357. // Declare Traverse*() for all concrete TypeLoc classes.
  358. #define ABSTRACT_TYPELOC(CLASS, BASE)
  359. #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
  360. #include "clang/AST/TypeLocNodes.def"
  361. // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
  362. // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
  363. bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
  364. bool VisitTypeLoc(TypeLoc TL) { return true; }
  365. // QualifiedTypeLoc and UnqualTypeLoc are not declared in
  366. // TypeNodes.inc and thus need to be handled specially.
  367. bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
  368. return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
  369. }
  370. bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
  371. bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
  372. return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
  373. }
  374. bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
  375. // Note that BASE includes trailing 'Type' which CLASS doesn't.
  376. #define TYPE(CLASS, BASE) \
  377. bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
  378. TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
  379. TRY_TO(Visit##CLASS##TypeLoc(TL)); \
  380. return true; \
  381. } \
  382. bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
  383. #include "clang/AST/TypeNodes.inc"
  384. // ---- Methods on Decls ----
  385. // Declare Traverse*() for all concrete Decl classes.
  386. #define ABSTRACT_DECL(DECL)
  387. #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
  388. #include "clang/AST/DeclNodes.inc"
  389. // The above header #undefs ABSTRACT_DECL and DECL upon exit.
  390. // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
  391. bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
  392. bool VisitDecl(Decl *D) { return true; }
  393. #define DECL(CLASS, BASE) \
  394. bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
  395. TRY_TO(WalkUpFrom##BASE(D)); \
  396. TRY_TO(Visit##CLASS##Decl(D)); \
  397. return true; \
  398. } \
  399. bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
  400. #include "clang/AST/DeclNodes.inc"
  401. bool canIgnoreChildDeclWhileTraversingDeclContext(const Decl *Child);
  402. #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND) \
  403. bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
  404. DEF_TRAVERSE_TMPL_INST(Class)
  405. DEF_TRAVERSE_TMPL_INST(Var)
  406. DEF_TRAVERSE_TMPL_INST(Function)
  407. #undef DEF_TRAVERSE_TMPL_INST
  408. bool TraverseTypeConstraint(const TypeConstraint *C);
  409. bool TraverseConceptRequirement(concepts::Requirement *R);
  410. bool TraverseConceptTypeRequirement(concepts::TypeRequirement *R);
  411. bool TraverseConceptExprRequirement(concepts::ExprRequirement *R);
  412. bool TraverseConceptNestedRequirement(concepts::NestedRequirement *R);
  413. bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
  414. private:
  415. // These are helper methods used by more than one Traverse* method.
  416. bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
  417. /// Traverses the qualifier, name and template arguments of a concept
  418. /// reference.
  419. bool TraverseConceptReferenceHelper(const ConceptReference &C);
  420. // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
  421. template <typename T>
  422. bool TraverseDeclTemplateParameterLists(T *D);
  423. bool TraverseTemplateTypeParamDeclConstraints(const TemplateTypeParmDecl *D);
  424. bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
  425. unsigned Count);
  426. bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
  427. bool TraverseRecordHelper(RecordDecl *D);
  428. bool TraverseCXXRecordHelper(CXXRecordDecl *D);
  429. bool TraverseDeclaratorHelper(DeclaratorDecl *D);
  430. bool TraverseDeclContextHelper(DeclContext *DC);
  431. bool TraverseFunctionHelper(FunctionDecl *D);
  432. bool TraverseVarHelper(VarDecl *D);
  433. bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
  434. bool TraverseOMPLoopDirective(OMPLoopDirective *S);
  435. bool TraverseOMPClause(OMPClause *C);
  436. #define GEN_CLANG_CLAUSE_CLASS
  437. #define CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
  438. #include "llvm/Frontend/OpenMP/OMP.inc"
  439. /// Process clauses with list of variables.
  440. template <typename T> bool VisitOMPClauseList(T *Node);
  441. /// Process clauses with pre-initis.
  442. bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
  443. bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
  444. bool PostVisitStmt(Stmt *S);
  445. };
  446. template <typename Derived>
  447. bool RecursiveASTVisitor<Derived>::TraverseTypeConstraint(
  448. const TypeConstraint *C) {
  449. if (!getDerived().shouldVisitImplicitCode()) {
  450. TRY_TO(TraverseConceptReferenceHelper(*C));
  451. return true;
  452. }
  453. if (Expr *IDC = C->getImmediatelyDeclaredConstraint()) {
  454. TRY_TO(TraverseStmt(IDC));
  455. } else {
  456. // Avoid traversing the ConceptReference in the TypeConstraint
  457. // if we have an immediately-declared-constraint, otherwise
  458. // we'll end up visiting the concept and the arguments in
  459. // the TC twice.
  460. TRY_TO(TraverseConceptReferenceHelper(*C));
  461. }
  462. return true;
  463. }
  464. template <typename Derived>
  465. bool RecursiveASTVisitor<Derived>::TraverseConceptRequirement(
  466. concepts::Requirement *R) {
  467. switch (R->getKind()) {
  468. case concepts::Requirement::RK_Type:
  469. return getDerived().TraverseConceptTypeRequirement(
  470. cast<concepts::TypeRequirement>(R));
  471. case concepts::Requirement::RK_Simple:
  472. case concepts::Requirement::RK_Compound:
  473. return getDerived().TraverseConceptExprRequirement(
  474. cast<concepts::ExprRequirement>(R));
  475. case concepts::Requirement::RK_Nested:
  476. return getDerived().TraverseConceptNestedRequirement(
  477. cast<concepts::NestedRequirement>(R));
  478. }
  479. llvm_unreachable("unexpected case");
  480. }
  481. template <typename Derived>
  482. bool RecursiveASTVisitor<Derived>::TraverseConceptReferenceHelper(
  483. const ConceptReference &C) {
  484. TRY_TO(TraverseNestedNameSpecifierLoc(C.getNestedNameSpecifierLoc()));
  485. TRY_TO(TraverseDeclarationNameInfo(C.getConceptNameInfo()));
  486. if (C.hasExplicitTemplateArgs())
  487. TRY_TO(TraverseTemplateArgumentLocsHelper(
  488. C.getTemplateArgsAsWritten()->getTemplateArgs(),
  489. C.getTemplateArgsAsWritten()->NumTemplateArgs));
  490. return true;
  491. }
  492. template <typename Derived>
  493. bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
  494. DataRecursionQueue *Queue) {
  495. // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
  496. switch (S->getStmtClass()) {
  497. case Stmt::NoStmtClass:
  498. break;
  499. #define ABSTRACT_STMT(STMT)
  500. #define STMT(CLASS, PARENT) \
  501. case Stmt::CLASS##Class: \
  502. return TRAVERSE_STMT_BASE(CLASS, CLASS, S, Queue);
  503. #include "clang/AST/StmtNodes.inc"
  504. }
  505. return true;
  506. }
  507. #undef DISPATCH_STMT
  508. template <typename Derived>
  509. bool RecursiveASTVisitor<Derived>::TraverseConceptTypeRequirement(
  510. concepts::TypeRequirement *R) {
  511. if (R->isSubstitutionFailure())
  512. return true;
  513. return getDerived().TraverseTypeLoc(R->getType()->getTypeLoc());
  514. }
  515. template <typename Derived>
  516. bool RecursiveASTVisitor<Derived>::TraverseConceptExprRequirement(
  517. concepts::ExprRequirement *R) {
  518. if (!R->isExprSubstitutionFailure())
  519. TRY_TO(TraverseStmt(R->getExpr()));
  520. auto &RetReq = R->getReturnTypeRequirement();
  521. if (RetReq.isTypeConstraint()) {
  522. if (getDerived().shouldVisitImplicitCode()) {
  523. TRY_TO(TraverseTemplateParameterListHelper(
  524. RetReq.getTypeConstraintTemplateParameterList()));
  525. } else {
  526. // Template parameter list is implicit, visit constraint directly.
  527. TRY_TO(TraverseTypeConstraint(RetReq.getTypeConstraint()));
  528. }
  529. }
  530. return true;
  531. }
  532. template <typename Derived>
  533. bool RecursiveASTVisitor<Derived>::TraverseConceptNestedRequirement(
  534. concepts::NestedRequirement *R) {
  535. if (!R->hasInvalidConstraint())
  536. return getDerived().TraverseStmt(R->getConstraintExpr());
  537. return true;
  538. }
  539. template <typename Derived>
  540. bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
  541. // In pre-order traversal mode, each Traverse##STMT method is responsible for
  542. // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
  543. // does not call the default implementation, the WalkUpFrom callback is not
  544. // called. Post-order traversal mode should provide the same behavior
  545. // regarding method overrides.
  546. //
  547. // In post-order traversal mode the Traverse##STMT method, when it receives a
  548. // DataRecursionQueue, can't call WalkUpFrom after traversing children because
  549. // it only enqueues the children and does not traverse them. TraverseStmt
  550. // traverses the enqueued children, and we call WalkUpFrom here.
  551. //
  552. // However, to make pre-order and post-order modes identical with regards to
  553. // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
  554. // user did not override the Traverse##STMT method. We implement the override
  555. // check with isSameMethod calls below.
  556. switch (S->getStmtClass()) {
  557. case Stmt::NoStmtClass:
  558. break;
  559. #define ABSTRACT_STMT(STMT)
  560. #define STMT(CLASS, PARENT) \
  561. case Stmt::CLASS##Class: \
  562. if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS, \
  563. &Derived::Traverse##CLASS)) { \
  564. TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); \
  565. } \
  566. break;
  567. #define INITLISTEXPR(CLASS, PARENT) \
  568. case Stmt::CLASS##Class: \
  569. if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS, \
  570. &Derived::Traverse##CLASS)) { \
  571. auto ILE = static_cast<CLASS *>(S); \
  572. if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \
  573. TRY_TO(WalkUpFrom##CLASS(Syn)); \
  574. if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
  575. TRY_TO(WalkUpFrom##CLASS(Sem)); \
  576. } \
  577. break;
  578. #include "clang/AST/StmtNodes.inc"
  579. }
  580. return true;
  581. }
  582. #undef DISPATCH_STMT
  583. template <typename Derived>
  584. bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
  585. DataRecursionQueue *Queue) {
  586. if (!S)
  587. return true;
  588. if (Queue) {
  589. Queue->push_back({S, false});
  590. return true;
  591. }
  592. SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
  593. LocalQueue.push_back({S, false});
  594. while (!LocalQueue.empty()) {
  595. auto &CurrSAndVisited = LocalQueue.back();
  596. Stmt *CurrS = CurrSAndVisited.getPointer();
  597. bool Visited = CurrSAndVisited.getInt();
  598. if (Visited) {
  599. LocalQueue.pop_back();
  600. TRY_TO(dataTraverseStmtPost(CurrS));
  601. if (getDerived().shouldTraversePostOrder()) {
  602. TRY_TO(PostVisitStmt(CurrS));
  603. }
  604. continue;
  605. }
  606. if (getDerived().dataTraverseStmtPre(CurrS)) {
  607. CurrSAndVisited.setInt(true);
  608. size_t N = LocalQueue.size();
  609. TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
  610. // Process new children in the order they were added.
  611. std::reverse(LocalQueue.begin() + N, LocalQueue.end());
  612. } else {
  613. LocalQueue.pop_back();
  614. }
  615. }
  616. return true;
  617. }
  618. template <typename Derived>
  619. bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
  620. if (T.isNull())
  621. return true;
  622. switch (T->getTypeClass()) {
  623. #define ABSTRACT_TYPE(CLASS, BASE)
  624. #define TYPE(CLASS, BASE) \
  625. case Type::CLASS: \
  626. return getDerived().Traverse##CLASS##Type( \
  627. static_cast<CLASS##Type *>(const_cast<Type *>(T.getTypePtr())));
  628. #include "clang/AST/TypeNodes.inc"
  629. }
  630. return true;
  631. }
  632. template <typename Derived>
  633. bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
  634. if (TL.isNull())
  635. return true;
  636. switch (TL.getTypeLocClass()) {
  637. #define ABSTRACT_TYPELOC(CLASS, BASE)
  638. #define TYPELOC(CLASS, BASE) \
  639. case TypeLoc::CLASS: \
  640. return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
  641. #include "clang/AST/TypeLocNodes.def"
  642. }
  643. return true;
  644. }
  645. // Define the Traverse*Attr(Attr* A) methods
  646. #define VISITORCLASS RecursiveASTVisitor
  647. #include "clang/AST/AttrVisitor.inc"
  648. #undef VISITORCLASS
  649. template <typename Derived>
  650. bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
  651. if (!D)
  652. return true;
  653. // As a syntax visitor, by default we want to ignore declarations for
  654. // implicit declarations (ones not typed explicitly by the user).
  655. if (!getDerived().shouldVisitImplicitCode() && D->isImplicit()) {
  656. // For an implicit template type parameter, its type constraints are not
  657. // implicit and are not represented anywhere else. We still need to visit
  658. // them.
  659. if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(D))
  660. return TraverseTemplateTypeParamDeclConstraints(TTPD);
  661. return true;
  662. }
  663. switch (D->getKind()) {
  664. #define ABSTRACT_DECL(DECL)
  665. #define DECL(CLASS, BASE) \
  666. case Decl::CLASS: \
  667. if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
  668. return false; \
  669. break;
  670. #include "clang/AST/DeclNodes.inc"
  671. }
  672. return true;
  673. }
  674. template <typename Derived>
  675. bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
  676. NestedNameSpecifier *NNS) {
  677. if (!NNS)
  678. return true;
  679. if (NNS->getPrefix())
  680. TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
  681. switch (NNS->getKind()) {
  682. case NestedNameSpecifier::Identifier:
  683. case NestedNameSpecifier::Namespace:
  684. case NestedNameSpecifier::NamespaceAlias:
  685. case NestedNameSpecifier::Global:
  686. case NestedNameSpecifier::Super:
  687. return true;
  688. case NestedNameSpecifier::TypeSpec:
  689. case NestedNameSpecifier::TypeSpecWithTemplate:
  690. TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
  691. }
  692. return true;
  693. }
  694. template <typename Derived>
  695. bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
  696. NestedNameSpecifierLoc NNS) {
  697. if (!NNS)
  698. return true;
  699. if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
  700. TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
  701. switch (NNS.getNestedNameSpecifier()->getKind()) {
  702. case NestedNameSpecifier::Identifier:
  703. case NestedNameSpecifier::Namespace:
  704. case NestedNameSpecifier::NamespaceAlias:
  705. case NestedNameSpecifier::Global:
  706. case NestedNameSpecifier::Super:
  707. return true;
  708. case NestedNameSpecifier::TypeSpec:
  709. case NestedNameSpecifier::TypeSpecWithTemplate:
  710. TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
  711. break;
  712. }
  713. return true;
  714. }
  715. template <typename Derived>
  716. bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
  717. DeclarationNameInfo NameInfo) {
  718. switch (NameInfo.getName().getNameKind()) {
  719. case DeclarationName::CXXConstructorName:
  720. case DeclarationName::CXXDestructorName:
  721. case DeclarationName::CXXConversionFunctionName:
  722. if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
  723. TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
  724. break;
  725. case DeclarationName::CXXDeductionGuideName:
  726. TRY_TO(TraverseTemplateName(
  727. TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
  728. break;
  729. case DeclarationName::Identifier:
  730. case DeclarationName::ObjCZeroArgSelector:
  731. case DeclarationName::ObjCOneArgSelector:
  732. case DeclarationName::ObjCMultiArgSelector:
  733. case DeclarationName::CXXOperatorName:
  734. case DeclarationName::CXXLiteralOperatorName:
  735. case DeclarationName::CXXUsingDirective:
  736. break;
  737. }
  738. return true;
  739. }
  740. template <typename Derived>
  741. bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
  742. if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
  743. TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
  744. else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
  745. TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
  746. return true;
  747. }
  748. template <typename Derived>
  749. bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
  750. const TemplateArgument &Arg) {
  751. switch (Arg.getKind()) {
  752. case TemplateArgument::Null:
  753. case TemplateArgument::Declaration:
  754. case TemplateArgument::Integral:
  755. case TemplateArgument::NullPtr:
  756. return true;
  757. case TemplateArgument::Type:
  758. return getDerived().TraverseType(Arg.getAsType());
  759. case TemplateArgument::Template:
  760. case TemplateArgument::TemplateExpansion:
  761. return getDerived().TraverseTemplateName(
  762. Arg.getAsTemplateOrTemplatePattern());
  763. case TemplateArgument::Expression:
  764. return getDerived().TraverseStmt(Arg.getAsExpr());
  765. case TemplateArgument::Pack:
  766. return getDerived().TraverseTemplateArguments(Arg.pack_elements());
  767. }
  768. return true;
  769. }
  770. // FIXME: no template name location?
  771. // FIXME: no source locations for a template argument pack?
  772. template <typename Derived>
  773. bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
  774. const TemplateArgumentLoc &ArgLoc) {
  775. const TemplateArgument &Arg = ArgLoc.getArgument();
  776. switch (Arg.getKind()) {
  777. case TemplateArgument::Null:
  778. case TemplateArgument::Declaration:
  779. case TemplateArgument::Integral:
  780. case TemplateArgument::NullPtr:
  781. return true;
  782. case TemplateArgument::Type: {
  783. // FIXME: how can TSI ever be NULL?
  784. if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
  785. return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
  786. else
  787. return getDerived().TraverseType(Arg.getAsType());
  788. }
  789. case TemplateArgument::Template:
  790. case TemplateArgument::TemplateExpansion:
  791. if (ArgLoc.getTemplateQualifierLoc())
  792. TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
  793. ArgLoc.getTemplateQualifierLoc()));
  794. return getDerived().TraverseTemplateName(
  795. Arg.getAsTemplateOrTemplatePattern());
  796. case TemplateArgument::Expression:
  797. return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
  798. case TemplateArgument::Pack:
  799. return getDerived().TraverseTemplateArguments(Arg.pack_elements());
  800. }
  801. return true;
  802. }
  803. template <typename Derived>
  804. bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
  805. ArrayRef<TemplateArgument> Args) {
  806. for (const TemplateArgument &Arg : Args)
  807. TRY_TO(TraverseTemplateArgument(Arg));
  808. return true;
  809. }
  810. template <typename Derived>
  811. bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
  812. CXXCtorInitializer *Init) {
  813. if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
  814. TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
  815. if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
  816. TRY_TO(TraverseStmt(Init->getInit()));
  817. return true;
  818. }
  819. template <typename Derived>
  820. bool
  821. RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
  822. const LambdaCapture *C,
  823. Expr *Init) {
  824. if (LE->isInitCapture(C))
  825. TRY_TO(TraverseDecl(C->getCapturedVar()));
  826. else
  827. TRY_TO(TraverseStmt(Init));
  828. return true;
  829. }
  830. // ----------------- Type traversal -----------------
  831. // This macro makes available a variable T, the passed-in type.
  832. #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
  833. template <typename Derived> \
  834. bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
  835. if (!getDerived().shouldTraversePostOrder()) \
  836. TRY_TO(WalkUpFrom##TYPE(T)); \
  837. { CODE; } \
  838. if (getDerived().shouldTraversePostOrder()) \
  839. TRY_TO(WalkUpFrom##TYPE(T)); \
  840. return true; \
  841. }
  842. DEF_TRAVERSE_TYPE(BuiltinType, {})
  843. DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
  844. DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
  845. DEF_TRAVERSE_TYPE(BlockPointerType,
  846. { TRY_TO(TraverseType(T->getPointeeType())); })
  847. DEF_TRAVERSE_TYPE(LValueReferenceType,
  848. { TRY_TO(TraverseType(T->getPointeeType())); })
  849. DEF_TRAVERSE_TYPE(RValueReferenceType,
  850. { TRY_TO(TraverseType(T->getPointeeType())); })
  851. DEF_TRAVERSE_TYPE(MemberPointerType, {
  852. TRY_TO(TraverseType(QualType(T->getClass(), 0)));
  853. TRY_TO(TraverseType(T->getPointeeType()));
  854. })
  855. DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
  856. DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
  857. DEF_TRAVERSE_TYPE(ConstantArrayType, {
  858. TRY_TO(TraverseType(T->getElementType()));
  859. if (T->getSizeExpr())
  860. TRY_TO(TraverseStmt(const_cast<Expr*>(T->getSizeExpr())));
  861. })
  862. DEF_TRAVERSE_TYPE(IncompleteArrayType,
  863. { TRY_TO(TraverseType(T->getElementType())); })
  864. DEF_TRAVERSE_TYPE(VariableArrayType, {
  865. TRY_TO(TraverseType(T->getElementType()));
  866. TRY_TO(TraverseStmt(T->getSizeExpr()));
  867. })
  868. DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
  869. TRY_TO(TraverseType(T->getElementType()));
  870. if (T->getSizeExpr())
  871. TRY_TO(TraverseStmt(T->getSizeExpr()));
  872. })
  873. DEF_TRAVERSE_TYPE(DependentAddressSpaceType, {
  874. TRY_TO(TraverseStmt(T->getAddrSpaceExpr()));
  875. TRY_TO(TraverseType(T->getPointeeType()));
  876. })
  877. DEF_TRAVERSE_TYPE(DependentVectorType, {
  878. if (T->getSizeExpr())
  879. TRY_TO(TraverseStmt(T->getSizeExpr()));
  880. TRY_TO(TraverseType(T->getElementType()));
  881. })
  882. DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
  883. if (T->getSizeExpr())
  884. TRY_TO(TraverseStmt(T->getSizeExpr()));
  885. TRY_TO(TraverseType(T->getElementType()));
  886. })
  887. DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
  888. DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
  889. DEF_TRAVERSE_TYPE(ConstantMatrixType,
  890. { TRY_TO(TraverseType(T->getElementType())); })
  891. DEF_TRAVERSE_TYPE(DependentSizedMatrixType, {
  892. if (T->getRowExpr())
  893. TRY_TO(TraverseStmt(T->getRowExpr()));
  894. if (T->getColumnExpr())
  895. TRY_TO(TraverseStmt(T->getColumnExpr()));
  896. TRY_TO(TraverseType(T->getElementType()));
  897. })
  898. DEF_TRAVERSE_TYPE(FunctionNoProtoType,
  899. { TRY_TO(TraverseType(T->getReturnType())); })
  900. DEF_TRAVERSE_TYPE(FunctionProtoType, {
  901. TRY_TO(TraverseType(T->getReturnType()));
  902. for (const auto &A : T->param_types()) {
  903. TRY_TO(TraverseType(A));
  904. }
  905. for (const auto &E : T->exceptions()) {
  906. TRY_TO(TraverseType(E));
  907. }
  908. if (Expr *NE = T->getNoexceptExpr())
  909. TRY_TO(TraverseStmt(NE));
  910. })
  911. DEF_TRAVERSE_TYPE(UsingType, {})
  912. DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
  913. DEF_TRAVERSE_TYPE(TypedefType, {})
  914. DEF_TRAVERSE_TYPE(TypeOfExprType,
  915. { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
  916. DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnmodifiedType())); })
  917. DEF_TRAVERSE_TYPE(DecltypeType,
  918. { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
  919. DEF_TRAVERSE_TYPE(UnaryTransformType, {
  920. TRY_TO(TraverseType(T->getBaseType()));
  921. TRY_TO(TraverseType(T->getUnderlyingType()));
  922. })
  923. DEF_TRAVERSE_TYPE(AutoType, {
  924. TRY_TO(TraverseType(T->getDeducedType()));
  925. if (T->isConstrained()) {
  926. TRY_TO(TraverseTemplateArguments(T->getTypeConstraintArguments()));
  927. }
  928. })
  929. DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
  930. TRY_TO(TraverseTemplateName(T->getTemplateName()));
  931. TRY_TO(TraverseType(T->getDeducedType()));
  932. })
  933. DEF_TRAVERSE_TYPE(RecordType, {})
  934. DEF_TRAVERSE_TYPE(EnumType, {})
  935. DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
  936. DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
  937. TRY_TO(TraverseType(T->getReplacementType()));
  938. })
  939. DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
  940. TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
  941. })
  942. DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
  943. TRY_TO(TraverseTemplateName(T->getTemplateName()));
  944. TRY_TO(TraverseTemplateArguments(T->template_arguments()));
  945. })
  946. DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
  947. DEF_TRAVERSE_TYPE(AttributedType,
  948. { TRY_TO(TraverseType(T->getModifiedType())); })
  949. DEF_TRAVERSE_TYPE(BTFTagAttributedType,
  950. { TRY_TO(TraverseType(T->getWrappedType())); })
  951. DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
  952. DEF_TRAVERSE_TYPE(MacroQualifiedType,
  953. { TRY_TO(TraverseType(T->getUnderlyingType())); })
  954. DEF_TRAVERSE_TYPE(ElaboratedType, {
  955. if (T->getQualifier()) {
  956. TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
  957. }
  958. TRY_TO(TraverseType(T->getNamedType()));
  959. })
  960. DEF_TRAVERSE_TYPE(DependentNameType,
  961. { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
  962. DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
  963. TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
  964. TRY_TO(TraverseTemplateArguments(T->template_arguments()));
  965. })
  966. DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
  967. DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
  968. DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
  969. DEF_TRAVERSE_TYPE(ObjCObjectType, {
  970. // We have to watch out here because an ObjCInterfaceType's base
  971. // type is itself.
  972. if (T->getBaseType().getTypePtr() != T)
  973. TRY_TO(TraverseType(T->getBaseType()));
  974. for (auto typeArg : T->getTypeArgsAsWritten()) {
  975. TRY_TO(TraverseType(typeArg));
  976. }
  977. })
  978. DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
  979. { TRY_TO(TraverseType(T->getPointeeType())); })
  980. DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
  981. DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
  982. DEF_TRAVERSE_TYPE(BitIntType, {})
  983. DEF_TRAVERSE_TYPE(DependentBitIntType,
  984. { TRY_TO(TraverseStmt(T->getNumBitsExpr())); })
  985. #undef DEF_TRAVERSE_TYPE
  986. // ----------------- TypeLoc traversal -----------------
  987. // This macro makes available a variable TL, the passed-in TypeLoc.
  988. // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
  989. // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
  990. // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
  991. // continue to work.
  992. #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
  993. template <typename Derived> \
  994. bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
  995. if (!getDerived().shouldTraversePostOrder()) { \
  996. TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
  997. if (getDerived().shouldWalkTypesOfTypeLocs()) \
  998. TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
  999. } \
  1000. { CODE; } \
  1001. if (getDerived().shouldTraversePostOrder()) { \
  1002. TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
  1003. if (getDerived().shouldWalkTypesOfTypeLocs()) \
  1004. TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
  1005. } \
  1006. return true; \
  1007. }
  1008. template <typename Derived>
  1009. bool
  1010. RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
  1011. // Move this over to the 'main' typeloc tree. Note that this is a
  1012. // move -- we pretend that we were really looking at the unqualified
  1013. // typeloc all along -- rather than a recursion, so we don't follow
  1014. // the normal CRTP plan of going through
  1015. // getDerived().TraverseTypeLoc. If we did, we'd be traversing
  1016. // twice for the same type (once as a QualifiedTypeLoc version of
  1017. // the type, once as an UnqualifiedTypeLoc version of the type),
  1018. // which in effect means we'd call VisitTypeLoc twice with the
  1019. // 'same' type. This solves that problem, at the cost of never
  1020. // seeing the qualified version of the type (unless the client
  1021. // subclasses TraverseQualifiedTypeLoc themselves). It's not a
  1022. // perfect solution. A perfect solution probably requires making
  1023. // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
  1024. // wrapper around Type* -- rather than being its own class in the
  1025. // type hierarchy.
  1026. return TraverseTypeLoc(TL.getUnqualifiedLoc());
  1027. }
  1028. DEF_TRAVERSE_TYPELOC(BuiltinType, {})
  1029. // FIXME: ComplexTypeLoc is unfinished
  1030. DEF_TRAVERSE_TYPELOC(ComplexType, {
  1031. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1032. })
  1033. DEF_TRAVERSE_TYPELOC(PointerType,
  1034. { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
  1035. DEF_TRAVERSE_TYPELOC(BlockPointerType,
  1036. { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
  1037. DEF_TRAVERSE_TYPELOC(LValueReferenceType,
  1038. { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
  1039. DEF_TRAVERSE_TYPELOC(RValueReferenceType,
  1040. { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
  1041. // We traverse this in the type case as well, but how is it not reached through
  1042. // the pointee type?
  1043. DEF_TRAVERSE_TYPELOC(MemberPointerType, {
  1044. if (auto *TSI = TL.getClassTInfo())
  1045. TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
  1046. else
  1047. TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
  1048. TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
  1049. })
  1050. DEF_TRAVERSE_TYPELOC(AdjustedType,
  1051. { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
  1052. DEF_TRAVERSE_TYPELOC(DecayedType,
  1053. { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
  1054. template <typename Derived>
  1055. bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
  1056. // This isn't available for ArrayType, but is for the ArrayTypeLoc.
  1057. TRY_TO(TraverseStmt(TL.getSizeExpr()));
  1058. return true;
  1059. }
  1060. DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
  1061. TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
  1062. TRY_TO(TraverseArrayTypeLocHelper(TL));
  1063. })
  1064. DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
  1065. TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
  1066. TRY_TO(TraverseArrayTypeLocHelper(TL));
  1067. })
  1068. DEF_TRAVERSE_TYPELOC(VariableArrayType, {
  1069. TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
  1070. TRY_TO(TraverseArrayTypeLocHelper(TL));
  1071. })
  1072. DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
  1073. TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
  1074. TRY_TO(TraverseArrayTypeLocHelper(TL));
  1075. })
  1076. DEF_TRAVERSE_TYPELOC(DependentAddressSpaceType, {
  1077. TRY_TO(TraverseStmt(TL.getTypePtr()->getAddrSpaceExpr()));
  1078. TRY_TO(TraverseType(TL.getTypePtr()->getPointeeType()));
  1079. })
  1080. // FIXME: order? why not size expr first?
  1081. // FIXME: base VectorTypeLoc is unfinished
  1082. DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
  1083. if (TL.getTypePtr()->getSizeExpr())
  1084. TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
  1085. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1086. })
  1087. // FIXME: VectorTypeLoc is unfinished
  1088. DEF_TRAVERSE_TYPELOC(VectorType, {
  1089. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1090. })
  1091. DEF_TRAVERSE_TYPELOC(DependentVectorType, {
  1092. if (TL.getTypePtr()->getSizeExpr())
  1093. TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
  1094. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1095. })
  1096. // FIXME: size and attributes
  1097. // FIXME: base VectorTypeLoc is unfinished
  1098. DEF_TRAVERSE_TYPELOC(ExtVectorType, {
  1099. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1100. })
  1101. DEF_TRAVERSE_TYPELOC(ConstantMatrixType, {
  1102. TRY_TO(TraverseStmt(TL.getAttrRowOperand()));
  1103. TRY_TO(TraverseStmt(TL.getAttrColumnOperand()));
  1104. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1105. })
  1106. DEF_TRAVERSE_TYPELOC(DependentSizedMatrixType, {
  1107. TRY_TO(TraverseStmt(TL.getAttrRowOperand()));
  1108. TRY_TO(TraverseStmt(TL.getAttrColumnOperand()));
  1109. TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
  1110. })
  1111. DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
  1112. { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
  1113. // FIXME: location of exception specifications (attributes?)
  1114. DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
  1115. TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
  1116. const FunctionProtoType *T = TL.getTypePtr();
  1117. for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
  1118. if (TL.getParam(I)) {
  1119. TRY_TO(TraverseDecl(TL.getParam(I)));
  1120. } else if (I < T->getNumParams()) {
  1121. TRY_TO(TraverseType(T->getParamType(I)));
  1122. }
  1123. }
  1124. for (const auto &E : T->exceptions()) {
  1125. TRY_TO(TraverseType(E));
  1126. }
  1127. if (Expr *NE = T->getNoexceptExpr())
  1128. TRY_TO(TraverseStmt(NE));
  1129. })
  1130. DEF_TRAVERSE_TYPELOC(UsingType, {})
  1131. DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
  1132. DEF_TRAVERSE_TYPELOC(TypedefType, {})
  1133. DEF_TRAVERSE_TYPELOC(TypeOfExprType,
  1134. { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
  1135. DEF_TRAVERSE_TYPELOC(TypeOfType, {
  1136. TRY_TO(TraverseTypeLoc(TL.getUnmodifiedTInfo()->getTypeLoc()));
  1137. })
  1138. // FIXME: location of underlying expr
  1139. DEF_TRAVERSE_TYPELOC(DecltypeType, {
  1140. TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
  1141. })
  1142. DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
  1143. TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
  1144. })
  1145. DEF_TRAVERSE_TYPELOC(AutoType, {
  1146. TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
  1147. if (TL.isConstrained()) {
  1148. TRY_TO(TraverseNestedNameSpecifierLoc(TL.getNestedNameSpecifierLoc()));
  1149. TRY_TO(TraverseDeclarationNameInfo(TL.getConceptNameInfo()));
  1150. for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
  1151. TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
  1152. }
  1153. })
  1154. DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
  1155. TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
  1156. TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
  1157. })
  1158. DEF_TRAVERSE_TYPELOC(RecordType, {})
  1159. DEF_TRAVERSE_TYPELOC(EnumType, {})
  1160. DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
  1161. DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
  1162. TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
  1163. })
  1164. DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
  1165. TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
  1166. })
  1167. // FIXME: use the loc for the template name?
  1168. DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
  1169. TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
  1170. for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
  1171. TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
  1172. }
  1173. })
  1174. DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
  1175. DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
  1176. DEF_TRAVERSE_TYPELOC(MacroQualifiedType,
  1177. { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
  1178. DEF_TRAVERSE_TYPELOC(AttributedType,
  1179. { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
  1180. DEF_TRAVERSE_TYPELOC(BTFTagAttributedType,
  1181. { TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })
  1182. DEF_TRAVERSE_TYPELOC(ElaboratedType, {
  1183. if (TL.getQualifierLoc()) {
  1184. TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
  1185. }
  1186. TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
  1187. })
  1188. DEF_TRAVERSE_TYPELOC(DependentNameType, {
  1189. TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
  1190. })
  1191. DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
  1192. if (TL.getQualifierLoc()) {
  1193. TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
  1194. }
  1195. for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
  1196. TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
  1197. }
  1198. })
  1199. DEF_TRAVERSE_TYPELOC(PackExpansionType,
  1200. { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
  1201. DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {
  1202. for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
  1203. ObjCProtocolLoc ProtocolLoc(TL.getProtocol(I), TL.getProtocolLoc(I));
  1204. TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
  1205. }
  1206. })
  1207. DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
  1208. DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
  1209. // We have to watch out here because an ObjCInterfaceType's base
  1210. // type is itself.
  1211. if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
  1212. TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
  1213. for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
  1214. TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
  1215. for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
  1216. ObjCProtocolLoc ProtocolLoc(TL.getProtocol(I), TL.getProtocolLoc(I));
  1217. TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
  1218. }
  1219. })
  1220. DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
  1221. { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
  1222. DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
  1223. DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
  1224. DEF_TRAVERSE_TYPELOC(BitIntType, {})
  1225. DEF_TRAVERSE_TYPELOC(DependentBitIntType, {
  1226. TRY_TO(TraverseStmt(TL.getTypePtr()->getNumBitsExpr()));
  1227. })
  1228. #undef DEF_TRAVERSE_TYPELOC
  1229. // ----------------- Decl traversal -----------------
  1230. //
  1231. // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
  1232. // the children that come from the DeclContext associated with it.
  1233. // Therefore each Traverse* only needs to worry about children other
  1234. // than those.
  1235. template <typename Derived>
  1236. bool RecursiveASTVisitor<Derived>::canIgnoreChildDeclWhileTraversingDeclContext(
  1237. const Decl *Child) {
  1238. // BlockDecls are traversed through BlockExprs,
  1239. // CapturedDecls are traversed through CapturedStmts.
  1240. if (isa<BlockDecl>(Child) || isa<CapturedDecl>(Child))
  1241. return true;
  1242. // Lambda classes are traversed through LambdaExprs.
  1243. if (const CXXRecordDecl* Cls = dyn_cast<CXXRecordDecl>(Child))
  1244. return Cls->isLambda();
  1245. return false;
  1246. }
  1247. template <typename Derived>
  1248. bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
  1249. if (!DC)
  1250. return true;
  1251. for (auto *Child : DC->decls()) {
  1252. if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))
  1253. TRY_TO(TraverseDecl(Child));
  1254. }
  1255. return true;
  1256. }
  1257. // This macro makes available a variable D, the passed-in decl.
  1258. #define DEF_TRAVERSE_DECL(DECL, CODE) \
  1259. template <typename Derived> \
  1260. bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
  1261. bool ShouldVisitChildren = true; \
  1262. bool ReturnValue = true; \
  1263. if (!getDerived().shouldTraversePostOrder()) \
  1264. TRY_TO(WalkUpFrom##DECL(D)); \
  1265. { CODE; } \
  1266. if (ReturnValue && ShouldVisitChildren) \
  1267. TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
  1268. if (ReturnValue) { \
  1269. /* Visit any attributes attached to this declaration. */ \
  1270. for (auto *I : D->attrs()) \
  1271. TRY_TO(getDerived().TraverseAttr(I)); \
  1272. } \
  1273. if (ReturnValue && getDerived().shouldTraversePostOrder()) \
  1274. TRY_TO(WalkUpFrom##DECL(D)); \
  1275. return ReturnValue; \
  1276. }
  1277. DEF_TRAVERSE_DECL(AccessSpecDecl, {})
  1278. DEF_TRAVERSE_DECL(BlockDecl, {
  1279. if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
  1280. TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
  1281. TRY_TO(TraverseStmt(D->getBody()));
  1282. for (const auto &I : D->captures()) {
  1283. if (I.hasCopyExpr()) {
  1284. TRY_TO(TraverseStmt(I.getCopyExpr()));
  1285. }
  1286. }
  1287. ShouldVisitChildren = false;
  1288. })
  1289. DEF_TRAVERSE_DECL(CapturedDecl, {
  1290. TRY_TO(TraverseStmt(D->getBody()));
  1291. ShouldVisitChildren = false;
  1292. })
  1293. DEF_TRAVERSE_DECL(EmptyDecl, {})
  1294. DEF_TRAVERSE_DECL(HLSLBufferDecl, {})
  1295. DEF_TRAVERSE_DECL(LifetimeExtendedTemporaryDecl, {
  1296. TRY_TO(TraverseStmt(D->getTemporaryExpr()));
  1297. })
  1298. DEF_TRAVERSE_DECL(FileScopeAsmDecl,
  1299. { TRY_TO(TraverseStmt(D->getAsmString())); })
  1300. DEF_TRAVERSE_DECL(TopLevelStmtDecl, { TRY_TO(TraverseStmt(D->getStmt())); })
  1301. DEF_TRAVERSE_DECL(ImportDecl, {})
  1302. DEF_TRAVERSE_DECL(FriendDecl, {
  1303. // Friend is either decl or a type.
  1304. if (D->getFriendType()) {
  1305. TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
  1306. // Traverse any CXXRecordDecl owned by this type, since
  1307. // it will not be in the parent context:
  1308. if (auto *ET = D->getFriendType()->getType()->getAs<ElaboratedType>())
  1309. TRY_TO(TraverseDecl(ET->getOwnedTagDecl()));
  1310. } else {
  1311. TRY_TO(TraverseDecl(D->getFriendDecl()));
  1312. }
  1313. })
  1314. DEF_TRAVERSE_DECL(FriendTemplateDecl, {
  1315. if (D->getFriendType())
  1316. TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
  1317. else
  1318. TRY_TO(TraverseDecl(D->getFriendDecl()));
  1319. for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
  1320. TemplateParameterList *TPL = D->getTemplateParameterList(I);
  1321. for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
  1322. ITPL != ETPL; ++ITPL) {
  1323. TRY_TO(TraverseDecl(*ITPL));
  1324. }
  1325. }
  1326. })
  1327. DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
  1328. TRY_TO(TraverseDecl(D->getSpecialization()));
  1329. if (D->hasExplicitTemplateArgs()) {
  1330. TRY_TO(TraverseTemplateArgumentLocsHelper(
  1331. D->getTemplateArgsAsWritten()->getTemplateArgs(),
  1332. D->getTemplateArgsAsWritten()->NumTemplateArgs));
  1333. }
  1334. })
  1335. DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
  1336. DEF_TRAVERSE_DECL(ExportDecl, {})
  1337. DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
  1338. })
  1339. DEF_TRAVERSE_DECL(StaticAssertDecl, {
  1340. TRY_TO(TraverseStmt(D->getAssertExpr()));
  1341. TRY_TO(TraverseStmt(D->getMessage()));
  1342. })
  1343. DEF_TRAVERSE_DECL(TranslationUnitDecl, {
  1344. // Code in an unnamed namespace shows up automatically in
  1345. // decls_begin()/decls_end(). Thus we don't need to recurse on
  1346. // D->getAnonymousNamespace().
  1347. // If the traversal scope is set, then consider them to be the children of
  1348. // the TUDecl, rather than traversing (and loading?) all top-level decls.
  1349. auto Scope = D->getASTContext().getTraversalScope();
  1350. bool HasLimitedScope =
  1351. Scope.size() != 1 || !isa<TranslationUnitDecl>(Scope.front());
  1352. if (HasLimitedScope) {
  1353. ShouldVisitChildren = false; // we'll do that here instead
  1354. for (auto *Child : Scope) {
  1355. if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))
  1356. TRY_TO(TraverseDecl(Child));
  1357. }
  1358. }
  1359. })
  1360. DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
  1361. DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
  1362. DEF_TRAVERSE_DECL(ExternCContextDecl, {})
  1363. DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
  1364. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1365. // We shouldn't traverse an aliased namespace, since it will be
  1366. // defined (and, therefore, traversed) somewhere else.
  1367. ShouldVisitChildren = false;
  1368. })
  1369. DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
  1370. })
  1371. DEF_TRAVERSE_DECL(
  1372. NamespaceDecl,
  1373. {// Code in an unnamed namespace shows up automatically in
  1374. // decls_begin()/decls_end(). Thus we don't need to recurse on
  1375. // D->getAnonymousNamespace().
  1376. })
  1377. DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
  1378. })
  1379. DEF_TRAVERSE_DECL(ObjCCategoryDecl, {
  1380. if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
  1381. for (auto typeParam : *typeParamList) {
  1382. TRY_TO(TraverseObjCTypeParamDecl(typeParam));
  1383. }
  1384. }
  1385. for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) {
  1386. ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It));
  1387. TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
  1388. }
  1389. })
  1390. DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
  1391. })
  1392. DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
  1393. })
  1394. DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {
  1395. if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
  1396. for (auto typeParam : *typeParamList) {
  1397. TRY_TO(TraverseObjCTypeParamDecl(typeParam));
  1398. }
  1399. }
  1400. if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
  1401. TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
  1402. }
  1403. if (D->isThisDeclarationADefinition()) {
  1404. for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) {
  1405. ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It));
  1406. TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
  1407. }
  1408. }
  1409. })
  1410. DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
  1411. if (D->isThisDeclarationADefinition()) {
  1412. for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) {
  1413. ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It));
  1414. TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
  1415. }
  1416. }
  1417. })
  1418. DEF_TRAVERSE_DECL(ObjCMethodDecl, {
  1419. if (D->getReturnTypeSourceInfo()) {
  1420. TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
  1421. }
  1422. for (ParmVarDecl *Parameter : D->parameters()) {
  1423. TRY_TO(TraverseDecl(Parameter));
  1424. }
  1425. if (D->isThisDeclarationADefinition()) {
  1426. TRY_TO(TraverseStmt(D->getBody()));
  1427. }
  1428. ShouldVisitChildren = false;
  1429. })
  1430. DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
  1431. if (D->hasExplicitBound()) {
  1432. TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
  1433. // We shouldn't traverse D->getTypeForDecl(); it's a result of
  1434. // declaring the type alias, not something that was written in the
  1435. // source.
  1436. }
  1437. })
  1438. DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
  1439. if (D->getTypeSourceInfo())
  1440. TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
  1441. else
  1442. TRY_TO(TraverseType(D->getType()));
  1443. ShouldVisitChildren = false;
  1444. })
  1445. DEF_TRAVERSE_DECL(UsingDecl, {
  1446. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1447. TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
  1448. })
  1449. DEF_TRAVERSE_DECL(UsingEnumDecl,
  1450. { TRY_TO(TraverseTypeLoc(D->getEnumTypeLoc())); })
  1451. DEF_TRAVERSE_DECL(UsingPackDecl, {})
  1452. DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
  1453. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1454. })
  1455. DEF_TRAVERSE_DECL(UsingShadowDecl, {})
  1456. DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
  1457. DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
  1458. for (auto *I : D->varlists()) {
  1459. TRY_TO(TraverseStmt(I));
  1460. }
  1461. })
  1462. DEF_TRAVERSE_DECL(OMPRequiresDecl, {
  1463. for (auto *C : D->clauselists()) {
  1464. TRY_TO(TraverseOMPClause(C));
  1465. }
  1466. })
  1467. DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
  1468. TRY_TO(TraverseStmt(D->getCombiner()));
  1469. if (auto *Initializer = D->getInitializer())
  1470. TRY_TO(TraverseStmt(Initializer));
  1471. TRY_TO(TraverseType(D->getType()));
  1472. return true;
  1473. })
  1474. DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, {
  1475. for (auto *C : D->clauselists())
  1476. TRY_TO(TraverseOMPClause(C));
  1477. TRY_TO(TraverseType(D->getType()));
  1478. return true;
  1479. })
  1480. DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
  1481. DEF_TRAVERSE_DECL(OMPAllocateDecl, {
  1482. for (auto *I : D->varlists())
  1483. TRY_TO(TraverseStmt(I));
  1484. for (auto *C : D->clauselists())
  1485. TRY_TO(TraverseOMPClause(C));
  1486. })
  1487. // A helper method for TemplateDecl's children.
  1488. template <typename Derived>
  1489. bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
  1490. TemplateParameterList *TPL) {
  1491. if (TPL) {
  1492. for (NamedDecl *D : *TPL) {
  1493. TRY_TO(TraverseDecl(D));
  1494. }
  1495. if (Expr *RequiresClause = TPL->getRequiresClause()) {
  1496. TRY_TO(TraverseStmt(RequiresClause));
  1497. }
  1498. }
  1499. return true;
  1500. }
  1501. template <typename Derived>
  1502. template <typename T>
  1503. bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
  1504. for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
  1505. TemplateParameterList *TPL = D->getTemplateParameterList(i);
  1506. TraverseTemplateParameterListHelper(TPL);
  1507. }
  1508. return true;
  1509. }
  1510. template <typename Derived>
  1511. bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
  1512. ClassTemplateDecl *D) {
  1513. for (auto *SD : D->specializations()) {
  1514. for (auto *RD : SD->redecls()) {
  1515. assert(!cast<CXXRecordDecl>(RD)->isInjectedClassName());
  1516. switch (
  1517. cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
  1518. // Visit the implicit instantiations with the requested pattern.
  1519. case TSK_Undeclared:
  1520. case TSK_ImplicitInstantiation:
  1521. TRY_TO(TraverseDecl(RD));
  1522. break;
  1523. // We don't need to do anything on an explicit instantiation
  1524. // or explicit specialization because there will be an explicit
  1525. // node for it elsewhere.
  1526. case TSK_ExplicitInstantiationDeclaration:
  1527. case TSK_ExplicitInstantiationDefinition:
  1528. case TSK_ExplicitSpecialization:
  1529. break;
  1530. }
  1531. }
  1532. }
  1533. return true;
  1534. }
  1535. template <typename Derived>
  1536. bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
  1537. VarTemplateDecl *D) {
  1538. for (auto *SD : D->specializations()) {
  1539. for (auto *RD : SD->redecls()) {
  1540. switch (
  1541. cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
  1542. case TSK_Undeclared:
  1543. case TSK_ImplicitInstantiation:
  1544. TRY_TO(TraverseDecl(RD));
  1545. break;
  1546. case TSK_ExplicitInstantiationDeclaration:
  1547. case TSK_ExplicitInstantiationDefinition:
  1548. case TSK_ExplicitSpecialization:
  1549. break;
  1550. }
  1551. }
  1552. }
  1553. return true;
  1554. }
  1555. // A helper method for traversing the instantiations of a
  1556. // function while skipping its specializations.
  1557. template <typename Derived>
  1558. bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
  1559. FunctionTemplateDecl *D) {
  1560. for (auto *FD : D->specializations()) {
  1561. for (auto *RD : FD->redecls()) {
  1562. switch (RD->getTemplateSpecializationKind()) {
  1563. case TSK_Undeclared:
  1564. case TSK_ImplicitInstantiation:
  1565. // We don't know what kind of FunctionDecl this is.
  1566. TRY_TO(TraverseDecl(RD));
  1567. break;
  1568. // FIXME: For now traverse explicit instantiations here. Change that
  1569. // once they are represented as dedicated nodes in the AST.
  1570. case TSK_ExplicitInstantiationDeclaration:
  1571. case TSK_ExplicitInstantiationDefinition:
  1572. TRY_TO(TraverseDecl(RD));
  1573. break;
  1574. case TSK_ExplicitSpecialization:
  1575. break;
  1576. }
  1577. }
  1578. }
  1579. return true;
  1580. }
  1581. // This macro unifies the traversal of class, variable and function
  1582. // template declarations.
  1583. #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \
  1584. DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \
  1585. TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
  1586. TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
  1587. \
  1588. /* By default, we do not traverse the instantiations of \
  1589. class templates since they do not appear in the user code. The \
  1590. following code optionally traverses them. \
  1591. \
  1592. We only traverse the class instantiations when we see the canonical \
  1593. declaration of the template, to ensure we only visit them once. */ \
  1594. if (getDerived().shouldVisitTemplateInstantiations() && \
  1595. D == D->getCanonicalDecl()) \
  1596. TRY_TO(TraverseTemplateInstantiations(D)); \
  1597. \
  1598. /* Note that getInstantiatedFromMemberTemplate() is just a link \
  1599. from a template instantiation back to the template from which \
  1600. it was instantiated, and thus should not be traversed. */ \
  1601. })
  1602. DEF_TRAVERSE_TMPL_DECL(Class)
  1603. DEF_TRAVERSE_TMPL_DECL(Var)
  1604. DEF_TRAVERSE_TMPL_DECL(Function)
  1605. DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
  1606. // D is the "T" in something like
  1607. // template <template <typename> class T> class container { };
  1608. TRY_TO(TraverseDecl(D->getTemplatedDecl()));
  1609. if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
  1610. TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
  1611. TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
  1612. })
  1613. DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
  1614. TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
  1615. })
  1616. template <typename Derived>
  1617. bool RecursiveASTVisitor<Derived>::TraverseTemplateTypeParamDeclConstraints(
  1618. const TemplateTypeParmDecl *D) {
  1619. if (const auto *TC = D->getTypeConstraint())
  1620. TRY_TO(TraverseTypeConstraint(TC));
  1621. return true;
  1622. }
  1623. DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
  1624. // D is the "T" in something like "template<typename T> class vector;"
  1625. if (D->getTypeForDecl())
  1626. TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
  1627. TRY_TO(TraverseTemplateTypeParamDeclConstraints(D));
  1628. if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
  1629. TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
  1630. })
  1631. DEF_TRAVERSE_DECL(TypedefDecl, {
  1632. TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
  1633. // We shouldn't traverse D->getTypeForDecl(); it's a result of
  1634. // declaring the typedef, not something that was written in the
  1635. // source.
  1636. })
  1637. DEF_TRAVERSE_DECL(TypeAliasDecl, {
  1638. TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
  1639. // We shouldn't traverse D->getTypeForDecl(); it's a result of
  1640. // declaring the type alias, not something that was written in the
  1641. // source.
  1642. })
  1643. DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
  1644. TRY_TO(TraverseDecl(D->getTemplatedDecl()));
  1645. TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
  1646. })
  1647. DEF_TRAVERSE_DECL(ConceptDecl, {
  1648. TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
  1649. TRY_TO(TraverseStmt(D->getConstraintExpr()));
  1650. })
  1651. DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
  1652. // A dependent using declaration which was marked with 'typename'.
  1653. // template<class T> class A : public B<T> { using typename B<T>::foo; };
  1654. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1655. // We shouldn't traverse D->getTypeForDecl(); it's a result of
  1656. // declaring the type, not something that was written in the
  1657. // source.
  1658. })
  1659. DEF_TRAVERSE_DECL(UnresolvedUsingIfExistsDecl, {})
  1660. DEF_TRAVERSE_DECL(EnumDecl, {
  1661. TRY_TO(TraverseDeclTemplateParameterLists(D));
  1662. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1663. if (auto *TSI = D->getIntegerTypeSourceInfo())
  1664. TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
  1665. // The enumerators are already traversed by
  1666. // decls_begin()/decls_end().
  1667. })
  1668. // Helper methods for RecordDecl and its children.
  1669. template <typename Derived>
  1670. bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
  1671. // We shouldn't traverse D->getTypeForDecl(); it's a result of
  1672. // declaring the type, not something that was written in the source.
  1673. TRY_TO(TraverseDeclTemplateParameterLists(D));
  1674. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1675. return true;
  1676. }
  1677. template <typename Derived>
  1678. bool RecursiveASTVisitor<Derived>::TraverseCXXBaseSpecifier(
  1679. const CXXBaseSpecifier &Base) {
  1680. TRY_TO(TraverseTypeLoc(Base.getTypeSourceInfo()->getTypeLoc()));
  1681. return true;
  1682. }
  1683. template <typename Derived>
  1684. bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
  1685. if (!TraverseRecordHelper(D))
  1686. return false;
  1687. if (D->isCompleteDefinition()) {
  1688. for (const auto &I : D->bases()) {
  1689. TRY_TO(TraverseCXXBaseSpecifier(I));
  1690. }
  1691. // We don't traverse the friends or the conversions, as they are
  1692. // already in decls_begin()/decls_end().
  1693. }
  1694. return true;
  1695. }
  1696. DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
  1697. DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
  1698. #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND) \
  1699. DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \
  1700. /* For implicit instantiations ("set<int> x;"), we don't want to \
  1701. recurse at all, since the instatiated template isn't written in \
  1702. the source code anywhere. (Note the instatiated *type* -- \
  1703. set<int> -- is written, and will still get a callback of \
  1704. TemplateSpecializationType). For explicit instantiations \
  1705. ("template set<int>;"), we do need a callback, since this \
  1706. is the only callback that's made for this instantiation. \
  1707. We use getTypeAsWritten() to distinguish. */ \
  1708. if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
  1709. TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \
  1710. \
  1711. if (getDerived().shouldVisitTemplateInstantiations() || \
  1712. D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \
  1713. /* Traverse base definition for explicit specializations */ \
  1714. TRY_TO(Traverse##DECLKIND##Helper(D)); \
  1715. } else { \
  1716. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \
  1717. \
  1718. /* Returning from here skips traversing the \
  1719. declaration context of the *TemplateSpecializationDecl \
  1720. (embedded in the DEF_TRAVERSE_DECL() macro) \
  1721. which contains the instantiated members of the template. */ \
  1722. return true; \
  1723. } \
  1724. })
  1725. DEF_TRAVERSE_TMPL_SPEC_DECL(Class, CXXRecord)
  1726. DEF_TRAVERSE_TMPL_SPEC_DECL(Var, Var)
  1727. template <typename Derived>
  1728. bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
  1729. const TemplateArgumentLoc *TAL, unsigned Count) {
  1730. for (unsigned I = 0; I < Count; ++I) {
  1731. TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
  1732. }
  1733. return true;
  1734. }
  1735. #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND) \
  1736. DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, { \
  1737. /* The partial specialization. */ \
  1738. if (TemplateParameterList *TPL = D->getTemplateParameters()) { \
  1739. for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); \
  1740. I != E; ++I) { \
  1741. TRY_TO(TraverseDecl(*I)); \
  1742. } \
  1743. } \
  1744. /* The args that remains unspecialized. */ \
  1745. TRY_TO(TraverseTemplateArgumentLocsHelper( \
  1746. D->getTemplateArgsAsWritten()->getTemplateArgs(), \
  1747. D->getTemplateArgsAsWritten()->NumTemplateArgs)); \
  1748. \
  1749. /* Don't need the *TemplatePartialSpecializationHelper, even \
  1750. though that's our parent class -- we already visit all the \
  1751. template args here. */ \
  1752. TRY_TO(Traverse##DECLKIND##Helper(D)); \
  1753. \
  1754. /* Instantiations will have been visited with the primary template. */ \
  1755. })
  1756. DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
  1757. DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
  1758. DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
  1759. DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
  1760. // Like UnresolvedUsingTypenameDecl, but without the 'typename':
  1761. // template <class T> Class A : public Base<T> { using Base<T>::foo; };
  1762. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1763. TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
  1764. })
  1765. DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
  1766. template <typename Derived>
  1767. bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
  1768. TRY_TO(TraverseDeclTemplateParameterLists(D));
  1769. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1770. if (D->getTypeSourceInfo())
  1771. TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
  1772. else
  1773. TRY_TO(TraverseType(D->getType()));
  1774. return true;
  1775. }
  1776. DEF_TRAVERSE_DECL(DecompositionDecl, {
  1777. TRY_TO(TraverseVarHelper(D));
  1778. for (auto *Binding : D->bindings()) {
  1779. TRY_TO(TraverseDecl(Binding));
  1780. }
  1781. })
  1782. DEF_TRAVERSE_DECL(BindingDecl, {
  1783. if (getDerived().shouldVisitImplicitCode())
  1784. TRY_TO(TraverseStmt(D->getBinding()));
  1785. })
  1786. DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
  1787. DEF_TRAVERSE_DECL(MSGuidDecl, {})
  1788. DEF_TRAVERSE_DECL(UnnamedGlobalConstantDecl, {})
  1789. DEF_TRAVERSE_DECL(TemplateParamObjectDecl, {})
  1790. DEF_TRAVERSE_DECL(FieldDecl, {
  1791. TRY_TO(TraverseDeclaratorHelper(D));
  1792. if (D->isBitField())
  1793. TRY_TO(TraverseStmt(D->getBitWidth()));
  1794. else if (D->hasInClassInitializer())
  1795. TRY_TO(TraverseStmt(D->getInClassInitializer()));
  1796. })
  1797. DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
  1798. TRY_TO(TraverseDeclaratorHelper(D));
  1799. if (D->isBitField())
  1800. TRY_TO(TraverseStmt(D->getBitWidth()));
  1801. // FIXME: implement the rest.
  1802. })
  1803. DEF_TRAVERSE_DECL(ObjCIvarDecl, {
  1804. TRY_TO(TraverseDeclaratorHelper(D));
  1805. if (D->isBitField())
  1806. TRY_TO(TraverseStmt(D->getBitWidth()));
  1807. // FIXME: implement the rest.
  1808. })
  1809. template <typename Derived>
  1810. bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
  1811. TRY_TO(TraverseDeclTemplateParameterLists(D));
  1812. TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
  1813. TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
  1814. // If we're an explicit template specialization, iterate over the
  1815. // template args that were explicitly specified. If we were doing
  1816. // this in typing order, we'd do it between the return type and
  1817. // the function args, but both are handled by the FunctionTypeLoc
  1818. // above, so we have to choose one side. I've decided to do before.
  1819. if (const FunctionTemplateSpecializationInfo *FTSI =
  1820. D->getTemplateSpecializationInfo()) {
  1821. if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
  1822. FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
  1823. // A specialization might not have explicit template arguments if it has
  1824. // a templated return type and concrete arguments.
  1825. if (const ASTTemplateArgumentListInfo *TALI =
  1826. FTSI->TemplateArgumentsAsWritten) {
  1827. TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
  1828. TALI->NumTemplateArgs));
  1829. }
  1830. }
  1831. }
  1832. // Visit the function type itself, which can be either
  1833. // FunctionNoProtoType or FunctionProtoType, or a typedef. This
  1834. // also covers the return type and the function parameters,
  1835. // including exception specifications.
  1836. if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
  1837. TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
  1838. } else if (getDerived().shouldVisitImplicitCode()) {
  1839. // Visit parameter variable declarations of the implicit function
  1840. // if the traverser is visiting implicit code. Parameter variable
  1841. // declarations do not have valid TypeSourceInfo, so to visit them
  1842. // we need to traverse the declarations explicitly.
  1843. for (ParmVarDecl *Parameter : D->parameters()) {
  1844. TRY_TO(TraverseDecl(Parameter));
  1845. }
  1846. }
  1847. // Visit the trailing requires clause, if any.
  1848. if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) {
  1849. TRY_TO(TraverseStmt(TrailingRequiresClause));
  1850. }
  1851. if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
  1852. // Constructor initializers.
  1853. for (auto *I : Ctor->inits()) {
  1854. if (I->isWritten() || getDerived().shouldVisitImplicitCode())
  1855. TRY_TO(TraverseConstructorInitializer(I));
  1856. }
  1857. }
  1858. bool VisitBody =
  1859. D->isThisDeclarationADefinition() &&
  1860. // Don't visit the function body if the function definition is generated
  1861. // by clang.
  1862. (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
  1863. if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
  1864. if (const CXXRecordDecl *RD = MD->getParent()) {
  1865. if (RD->isLambda() &&
  1866. declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
  1867. VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
  1868. }
  1869. }
  1870. }
  1871. if (VisitBody) {
  1872. TRY_TO(TraverseStmt(D->getBody()));
  1873. // Body may contain using declarations whose shadows are parented to the
  1874. // FunctionDecl itself.
  1875. for (auto *Child : D->decls()) {
  1876. if (isa<UsingShadowDecl>(Child))
  1877. TRY_TO(TraverseDecl(Child));
  1878. }
  1879. }
  1880. return true;
  1881. }
  1882. DEF_TRAVERSE_DECL(FunctionDecl, {
  1883. // We skip decls_begin/decls_end, which are already covered by
  1884. // TraverseFunctionHelper().
  1885. ShouldVisitChildren = false;
  1886. ReturnValue = TraverseFunctionHelper(D);
  1887. })
  1888. DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
  1889. // We skip decls_begin/decls_end, which are already covered by
  1890. // TraverseFunctionHelper().
  1891. ShouldVisitChildren = false;
  1892. ReturnValue = TraverseFunctionHelper(D);
  1893. })
  1894. DEF_TRAVERSE_DECL(CXXMethodDecl, {
  1895. // We skip decls_begin/decls_end, which are already covered by
  1896. // TraverseFunctionHelper().
  1897. ShouldVisitChildren = false;
  1898. ReturnValue = TraverseFunctionHelper(D);
  1899. })
  1900. DEF_TRAVERSE_DECL(CXXConstructorDecl, {
  1901. // We skip decls_begin/decls_end, which are already covered by
  1902. // TraverseFunctionHelper().
  1903. ShouldVisitChildren = false;
  1904. ReturnValue = TraverseFunctionHelper(D);
  1905. })
  1906. // CXXConversionDecl is the declaration of a type conversion operator.
  1907. // It's not a cast expression.
  1908. DEF_TRAVERSE_DECL(CXXConversionDecl, {
  1909. // We skip decls_begin/decls_end, which are already covered by
  1910. // TraverseFunctionHelper().
  1911. ShouldVisitChildren = false;
  1912. ReturnValue = TraverseFunctionHelper(D);
  1913. })
  1914. DEF_TRAVERSE_DECL(CXXDestructorDecl, {
  1915. // We skip decls_begin/decls_end, which are already covered by
  1916. // TraverseFunctionHelper().
  1917. ShouldVisitChildren = false;
  1918. ReturnValue = TraverseFunctionHelper(D);
  1919. })
  1920. template <typename Derived>
  1921. bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
  1922. TRY_TO(TraverseDeclaratorHelper(D));
  1923. // Default params are taken care of when we traverse the ParmVarDecl.
  1924. if (!isa<ParmVarDecl>(D) &&
  1925. (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
  1926. TRY_TO(TraverseStmt(D->getInit()));
  1927. return true;
  1928. }
  1929. DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
  1930. DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
  1931. DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
  1932. // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
  1933. TRY_TO(TraverseDeclaratorHelper(D));
  1934. if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
  1935. TRY_TO(TraverseStmt(D->getDefaultArgument()));
  1936. })
  1937. DEF_TRAVERSE_DECL(ParmVarDecl, {
  1938. TRY_TO(TraverseVarHelper(D));
  1939. if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
  1940. !D->hasUnparsedDefaultArg())
  1941. TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
  1942. if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
  1943. !D->hasUnparsedDefaultArg())
  1944. TRY_TO(TraverseStmt(D->getDefaultArg()));
  1945. })
  1946. DEF_TRAVERSE_DECL(RequiresExprBodyDecl, {})
  1947. DEF_TRAVERSE_DECL(ImplicitConceptSpecializationDecl, {
  1948. TRY_TO(TraverseTemplateArguments(D->getTemplateArguments()));
  1949. })
  1950. #undef DEF_TRAVERSE_DECL
  1951. // ----------------- Stmt traversal -----------------
  1952. //
  1953. // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
  1954. // over the children defined in children() (every stmt defines these,
  1955. // though sometimes the range is empty). Each individual Traverse*
  1956. // method only needs to worry about children other than those. To see
  1957. // what children() does for a given class, see, e.g.,
  1958. // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
  1959. // This macro makes available a variable S, the passed-in stmt.
  1960. #define DEF_TRAVERSE_STMT(STMT, CODE) \
  1961. template <typename Derived> \
  1962. bool RecursiveASTVisitor<Derived>::Traverse##STMT( \
  1963. STMT *S, DataRecursionQueue *Queue) { \
  1964. bool ShouldVisitChildren = true; \
  1965. bool ReturnValue = true; \
  1966. if (!getDerived().shouldTraversePostOrder()) \
  1967. TRY_TO(WalkUpFrom##STMT(S)); \
  1968. { CODE; } \
  1969. if (ShouldVisitChildren) { \
  1970. for (Stmt * SubStmt : getDerived().getStmtChildren(S)) { \
  1971. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); \
  1972. } \
  1973. } \
  1974. /* Call WalkUpFrom if TRY_TO_TRAVERSE_OR_ENQUEUE_STMT has traversed the \
  1975. * children already. If TRY_TO_TRAVERSE_OR_ENQUEUE_STMT only enqueued the \
  1976. * children, PostVisitStmt will call WalkUpFrom after we are done visiting \
  1977. * children. */ \
  1978. if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) { \
  1979. TRY_TO(WalkUpFrom##STMT(S)); \
  1980. } \
  1981. return ReturnValue; \
  1982. }
  1983. DEF_TRAVERSE_STMT(GCCAsmStmt, {
  1984. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
  1985. for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
  1986. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
  1987. }
  1988. for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
  1989. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
  1990. }
  1991. for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
  1992. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
  1993. }
  1994. // children() iterates over inputExpr and outputExpr.
  1995. })
  1996. DEF_TRAVERSE_STMT(
  1997. MSAsmStmt,
  1998. {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
  1999. // added this needs to be implemented.
  2000. })
  2001. DEF_TRAVERSE_STMT(CXXCatchStmt, {
  2002. TRY_TO(TraverseDecl(S->getExceptionDecl()));
  2003. // children() iterates over the handler block.
  2004. })
  2005. DEF_TRAVERSE_STMT(DeclStmt, {
  2006. for (auto *I : S->decls()) {
  2007. TRY_TO(TraverseDecl(I));
  2008. }
  2009. // Suppress the default iteration over children() by
  2010. // returning. Here's why: A DeclStmt looks like 'type var [=
  2011. // initializer]'. The decls above already traverse over the
  2012. // initializers, so we don't have to do it again (which
  2013. // children() would do).
  2014. ShouldVisitChildren = false;
  2015. })
  2016. // These non-expr stmts (most of them), do not need any action except
  2017. // iterating over the children.
  2018. DEF_TRAVERSE_STMT(BreakStmt, {})
  2019. DEF_TRAVERSE_STMT(CXXTryStmt, {})
  2020. DEF_TRAVERSE_STMT(CaseStmt, {})
  2021. DEF_TRAVERSE_STMT(CompoundStmt, {})
  2022. DEF_TRAVERSE_STMT(ContinueStmt, {})
  2023. DEF_TRAVERSE_STMT(DefaultStmt, {})
  2024. DEF_TRAVERSE_STMT(DoStmt, {})
  2025. DEF_TRAVERSE_STMT(ForStmt, {})
  2026. DEF_TRAVERSE_STMT(GotoStmt, {})
  2027. DEF_TRAVERSE_STMT(IfStmt, {})
  2028. DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
  2029. DEF_TRAVERSE_STMT(LabelStmt, {})
  2030. DEF_TRAVERSE_STMT(AttributedStmt, {})
  2031. DEF_TRAVERSE_STMT(NullStmt, {})
  2032. DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
  2033. DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
  2034. DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
  2035. DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
  2036. DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
  2037. DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
  2038. DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
  2039. DEF_TRAVERSE_STMT(CXXForRangeStmt, {
  2040. if (!getDerived().shouldVisitImplicitCode()) {
  2041. if (S->getInit())
  2042. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInit());
  2043. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
  2044. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
  2045. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
  2046. // Visit everything else only if shouldVisitImplicitCode().
  2047. ShouldVisitChildren = false;
  2048. }
  2049. })
  2050. DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
  2051. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2052. TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
  2053. })
  2054. DEF_TRAVERSE_STMT(ReturnStmt, {})
  2055. DEF_TRAVERSE_STMT(SwitchStmt, {})
  2056. DEF_TRAVERSE_STMT(WhileStmt, {})
  2057. DEF_TRAVERSE_STMT(ConstantExpr, {})
  2058. DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
  2059. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2060. TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
  2061. if (S->hasExplicitTemplateArgs()) {
  2062. TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
  2063. S->getNumTemplateArgs()));
  2064. }
  2065. })
  2066. DEF_TRAVERSE_STMT(DeclRefExpr, {
  2067. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2068. TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
  2069. TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
  2070. S->getNumTemplateArgs()));
  2071. })
  2072. DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
  2073. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2074. TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
  2075. if (S->hasExplicitTemplateArgs()) {
  2076. TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
  2077. S->getNumTemplateArgs()));
  2078. }
  2079. })
  2080. DEF_TRAVERSE_STMT(MemberExpr, {
  2081. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2082. TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
  2083. TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
  2084. S->getNumTemplateArgs()));
  2085. })
  2086. DEF_TRAVERSE_STMT(
  2087. ImplicitCastExpr,
  2088. {// We don't traverse the cast type, as it's not written in the
  2089. // source code.
  2090. })
  2091. DEF_TRAVERSE_STMT(CStyleCastExpr, {
  2092. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2093. })
  2094. DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
  2095. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2096. })
  2097. DEF_TRAVERSE_STMT(CXXAddrspaceCastExpr, {
  2098. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2099. })
  2100. DEF_TRAVERSE_STMT(CXXConstCastExpr, {
  2101. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2102. })
  2103. DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
  2104. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2105. })
  2106. DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
  2107. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2108. })
  2109. DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
  2110. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2111. })
  2112. DEF_TRAVERSE_STMT(BuiltinBitCastExpr, {
  2113. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2114. })
  2115. template <typename Derived>
  2116. bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
  2117. InitListExpr *S, DataRecursionQueue *Queue) {
  2118. if (S) {
  2119. // Skip this if we traverse postorder. We will visit it later
  2120. // in PostVisitStmt.
  2121. if (!getDerived().shouldTraversePostOrder())
  2122. TRY_TO(WalkUpFromInitListExpr(S));
  2123. // All we need are the default actions. FIXME: use a helper function.
  2124. for (Stmt *SubStmt : S->children()) {
  2125. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
  2126. }
  2127. if (!Queue && getDerived().shouldTraversePostOrder())
  2128. TRY_TO(WalkUpFromInitListExpr(S));
  2129. }
  2130. return true;
  2131. }
  2132. template <typename Derived>
  2133. bool RecursiveASTVisitor<Derived>::TraverseObjCProtocolLoc(
  2134. ObjCProtocolLoc ProtocolLoc) {
  2135. return true;
  2136. }
  2137. // If shouldVisitImplicitCode() returns false, this method traverses only the
  2138. // syntactic form of InitListExpr.
  2139. // If shouldVisitImplicitCode() return true, this method is called once for
  2140. // each pair of syntactic and semantic InitListExpr, and it traverses the
  2141. // subtrees defined by the two forms. This may cause some of the children to be
  2142. // visited twice, if they appear both in the syntactic and the semantic form.
  2143. //
  2144. // There is no guarantee about which form \p S takes when this method is called.
  2145. template <typename Derived>
  2146. bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
  2147. InitListExpr *S, DataRecursionQueue *Queue) {
  2148. if (S->isSemanticForm() && S->isSyntacticForm()) {
  2149. // `S` does not have alternative forms, traverse only once.
  2150. TRY_TO(TraverseSynOrSemInitListExpr(S, Queue));
  2151. return true;
  2152. }
  2153. TRY_TO(TraverseSynOrSemInitListExpr(
  2154. S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
  2155. if (getDerived().shouldVisitImplicitCode()) {
  2156. // Only visit the semantic form if the clients are interested in implicit
  2157. // compiler-generated.
  2158. TRY_TO(TraverseSynOrSemInitListExpr(
  2159. S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
  2160. }
  2161. return true;
  2162. }
  2163. // GenericSelectionExpr is a special case because the types and expressions
  2164. // are interleaved. We also need to watch out for null types (default
  2165. // generic associations).
  2166. DEF_TRAVERSE_STMT(GenericSelectionExpr, {
  2167. TRY_TO(TraverseStmt(S->getControllingExpr()));
  2168. for (const GenericSelectionExpr::Association Assoc : S->associations()) {
  2169. if (TypeSourceInfo *TSI = Assoc.getTypeSourceInfo())
  2170. TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
  2171. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Assoc.getAssociationExpr());
  2172. }
  2173. ShouldVisitChildren = false;
  2174. })
  2175. // PseudoObjectExpr is a special case because of the weirdness with
  2176. // syntactic expressions and opaque values.
  2177. DEF_TRAVERSE_STMT(PseudoObjectExpr, {
  2178. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
  2179. for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
  2180. e = S->semantics_end();
  2181. i != e; ++i) {
  2182. Expr *sub = *i;
  2183. if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
  2184. sub = OVE->getSourceExpr();
  2185. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
  2186. }
  2187. ShouldVisitChildren = false;
  2188. })
  2189. DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
  2190. // This is called for code like 'return T()' where T is a built-in
  2191. // (i.e. non-class) type.
  2192. TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
  2193. })
  2194. DEF_TRAVERSE_STMT(CXXNewExpr, {
  2195. // The child-iterator will pick up the other arguments.
  2196. TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
  2197. })
  2198. DEF_TRAVERSE_STMT(OffsetOfExpr, {
  2199. // The child-iterator will pick up the expression representing
  2200. // the field.
  2201. // FIMXE: for code like offsetof(Foo, a.b.c), should we get
  2202. // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
  2203. TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
  2204. })
  2205. DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
  2206. // The child-iterator will pick up the arg if it's an expression,
  2207. // but not if it's a type.
  2208. if (S->isArgumentType())
  2209. TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
  2210. })
  2211. DEF_TRAVERSE_STMT(CXXTypeidExpr, {
  2212. // The child-iterator will pick up the arg if it's an expression,
  2213. // but not if it's a type.
  2214. if (S->isTypeOperand())
  2215. TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
  2216. })
  2217. DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
  2218. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2219. })
  2220. DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
  2221. DEF_TRAVERSE_STMT(CXXUuidofExpr, {
  2222. // The child-iterator will pick up the arg if it's an expression,
  2223. // but not if it's a type.
  2224. if (S->isTypeOperand())
  2225. TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
  2226. })
  2227. DEF_TRAVERSE_STMT(TypeTraitExpr, {
  2228. for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
  2229. TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
  2230. })
  2231. DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
  2232. TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
  2233. })
  2234. DEF_TRAVERSE_STMT(ExpressionTraitExpr,
  2235. { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
  2236. DEF_TRAVERSE_STMT(VAArgExpr, {
  2237. // The child-iterator will pick up the expression argument.
  2238. TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
  2239. })
  2240. DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
  2241. // This is called for code like 'return T()' where T is a class type.
  2242. TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
  2243. })
  2244. // Walk only the visible parts of lambda expressions.
  2245. DEF_TRAVERSE_STMT(LambdaExpr, {
  2246. // Visit the capture list.
  2247. for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
  2248. const LambdaCapture *C = S->capture_begin() + I;
  2249. if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
  2250. TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
  2251. }
  2252. }
  2253. if (getDerived().shouldVisitImplicitCode()) {
  2254. // The implicit model is simple: everything else is in the lambda class.
  2255. TRY_TO(TraverseDecl(S->getLambdaClass()));
  2256. } else {
  2257. // We need to poke around to find the bits that might be explicitly written.
  2258. TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
  2259. FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
  2260. TRY_TO(TraverseTemplateParameterListHelper(S->getTemplateParameterList()));
  2261. if (S->hasExplicitParameters()) {
  2262. // Visit parameters.
  2263. for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
  2264. TRY_TO(TraverseDecl(Proto.getParam(I)));
  2265. }
  2266. auto *T = Proto.getTypePtr();
  2267. for (const auto &E : T->exceptions())
  2268. TRY_TO(TraverseType(E));
  2269. if (Expr *NE = T->getNoexceptExpr())
  2270. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
  2271. if (S->hasExplicitResultType())
  2272. TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
  2273. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getTrailingRequiresClause());
  2274. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
  2275. }
  2276. ShouldVisitChildren = false;
  2277. })
  2278. DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
  2279. // This is called for code like 'T()', where T is a template argument.
  2280. TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
  2281. })
  2282. // These expressions all might take explicit template arguments.
  2283. // We traverse those if so. FIXME: implement these.
  2284. DEF_TRAVERSE_STMT(CXXConstructExpr, {})
  2285. DEF_TRAVERSE_STMT(CallExpr, {})
  2286. DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
  2287. // These exprs (most of them), do not need any action except iterating
  2288. // over the children.
  2289. DEF_TRAVERSE_STMT(AddrLabelExpr, {})
  2290. DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
  2291. DEF_TRAVERSE_STMT(MatrixSubscriptExpr, {})
  2292. DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
  2293. DEF_TRAVERSE_STMT(OMPArrayShapingExpr, {})
  2294. DEF_TRAVERSE_STMT(OMPIteratorExpr, {})
  2295. DEF_TRAVERSE_STMT(BlockExpr, {
  2296. TRY_TO(TraverseDecl(S->getBlockDecl()));
  2297. return true; // no child statements to loop through.
  2298. })
  2299. DEF_TRAVERSE_STMT(ChooseExpr, {})
  2300. DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
  2301. TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
  2302. })
  2303. DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
  2304. DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
  2305. DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
  2306. if (getDerived().shouldVisitImplicitCode())
  2307. TRY_TO(TraverseStmt(S->getExpr()));
  2308. })
  2309. DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
  2310. DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
  2311. DEF_TRAVERSE_STMT(ExprWithCleanups, {})
  2312. DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
  2313. DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
  2314. DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
  2315. DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
  2316. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2317. if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
  2318. TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
  2319. if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
  2320. TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
  2321. })
  2322. DEF_TRAVERSE_STMT(CXXThisExpr, {})
  2323. DEF_TRAVERSE_STMT(CXXThrowExpr, {})
  2324. DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
  2325. DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
  2326. DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
  2327. DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
  2328. DEF_TRAVERSE_STMT(GNUNullExpr, {})
  2329. DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
  2330. DEF_TRAVERSE_STMT(NoInitExpr, {})
  2331. DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
  2332. // FIXME: The source expression of the OVE should be listed as
  2333. // a child of the ArrayInitLoopExpr.
  2334. if (OpaqueValueExpr *OVE = S->getCommonExpr())
  2335. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
  2336. })
  2337. DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
  2338. DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
  2339. DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
  2340. if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
  2341. TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
  2342. })
  2343. DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
  2344. DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
  2345. DEF_TRAVERSE_STMT(ObjCMessageExpr, {
  2346. if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
  2347. TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
  2348. })
  2349. DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {
  2350. if (S->isClassReceiver()) {
  2351. ObjCInterfaceDecl *IDecl = S->getClassReceiver();
  2352. QualType Type = IDecl->getASTContext().getObjCInterfaceType(IDecl);
  2353. ObjCInterfaceLocInfo Data;
  2354. Data.NameLoc = S->getReceiverLocation();
  2355. Data.NameEndLoc = Data.NameLoc;
  2356. TRY_TO(TraverseTypeLoc(TypeLoc(Type, &Data)));
  2357. }
  2358. })
  2359. DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
  2360. DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
  2361. DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
  2362. DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
  2363. DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
  2364. TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
  2365. })
  2366. DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
  2367. DEF_TRAVERSE_STMT(ParenExpr, {})
  2368. DEF_TRAVERSE_STMT(ParenListExpr, {})
  2369. DEF_TRAVERSE_STMT(SYCLUniqueStableNameExpr, {
  2370. TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
  2371. })
  2372. DEF_TRAVERSE_STMT(PredefinedExpr, {})
  2373. DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
  2374. DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
  2375. DEF_TRAVERSE_STMT(StmtExpr, {})
  2376. DEF_TRAVERSE_STMT(SourceLocExpr, {})
  2377. DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
  2378. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2379. if (S->hasExplicitTemplateArgs()) {
  2380. TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
  2381. S->getNumTemplateArgs()));
  2382. }
  2383. })
  2384. DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
  2385. TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
  2386. if (S->hasExplicitTemplateArgs()) {
  2387. TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
  2388. S->getNumTemplateArgs()));
  2389. }
  2390. })
  2391. DEF_TRAVERSE_STMT(SEHTryStmt, {})
  2392. DEF_TRAVERSE_STMT(SEHExceptStmt, {})
  2393. DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
  2394. DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
  2395. DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
  2396. DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
  2397. DEF_TRAVERSE_STMT(CXXRewrittenBinaryOperator, {
  2398. if (!getDerived().shouldVisitImplicitCode()) {
  2399. CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
  2400. S->getDecomposedForm();
  2401. TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.LHS)));
  2402. TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.RHS)));
  2403. ShouldVisitChildren = false;
  2404. }
  2405. })
  2406. DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
  2407. DEF_TRAVERSE_STMT(TypoExpr, {})
  2408. DEF_TRAVERSE_STMT(RecoveryExpr, {})
  2409. DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
  2410. // These operators (all of them) do not need any action except
  2411. // iterating over the children.
  2412. DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
  2413. DEF_TRAVERSE_STMT(ConditionalOperator, {})
  2414. DEF_TRAVERSE_STMT(UnaryOperator, {})
  2415. DEF_TRAVERSE_STMT(BinaryOperator, {})
  2416. DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
  2417. DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
  2418. DEF_TRAVERSE_STMT(PackExpansionExpr, {})
  2419. DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
  2420. DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
  2421. DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
  2422. DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
  2423. DEF_TRAVERSE_STMT(CXXFoldExpr, {})
  2424. DEF_TRAVERSE_STMT(AtomicExpr, {})
  2425. DEF_TRAVERSE_STMT(CXXParenListInitExpr, {})
  2426. DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {
  2427. if (S->getLifetimeExtendedTemporaryDecl()) {
  2428. TRY_TO(TraverseLifetimeExtendedTemporaryDecl(
  2429. S->getLifetimeExtendedTemporaryDecl()));
  2430. ShouldVisitChildren = false;
  2431. }
  2432. })
  2433. // For coroutines expressions, traverse either the operand
  2434. // as written or the implied calls, depending on what the
  2435. // derived class requests.
  2436. DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
  2437. if (!getDerived().shouldVisitImplicitCode()) {
  2438. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
  2439. ShouldVisitChildren = false;
  2440. }
  2441. })
  2442. DEF_TRAVERSE_STMT(CoreturnStmt, {
  2443. if (!getDerived().shouldVisitImplicitCode()) {
  2444. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
  2445. ShouldVisitChildren = false;
  2446. }
  2447. })
  2448. DEF_TRAVERSE_STMT(CoawaitExpr, {
  2449. if (!getDerived().shouldVisitImplicitCode()) {
  2450. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
  2451. ShouldVisitChildren = false;
  2452. }
  2453. })
  2454. DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
  2455. if (!getDerived().shouldVisitImplicitCode()) {
  2456. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
  2457. ShouldVisitChildren = false;
  2458. }
  2459. })
  2460. DEF_TRAVERSE_STMT(CoyieldExpr, {
  2461. if (!getDerived().shouldVisitImplicitCode()) {
  2462. TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
  2463. ShouldVisitChildren = false;
  2464. }
  2465. })
  2466. DEF_TRAVERSE_STMT(ConceptSpecializationExpr,
  2467. { TRY_TO(TraverseConceptReferenceHelper(*S)); })
  2468. DEF_TRAVERSE_STMT(RequiresExpr, {
  2469. TRY_TO(TraverseDecl(S->getBody()));
  2470. for (ParmVarDecl *Parm : S->getLocalParameters())
  2471. TRY_TO(TraverseDecl(Parm));
  2472. for (concepts::Requirement *Req : S->getRequirements())
  2473. TRY_TO(TraverseConceptRequirement(Req));
  2474. })
  2475. // These literals (all of them) do not need any action.
  2476. DEF_TRAVERSE_STMT(IntegerLiteral, {})
  2477. DEF_TRAVERSE_STMT(FixedPointLiteral, {})
  2478. DEF_TRAVERSE_STMT(CharacterLiteral, {})
  2479. DEF_TRAVERSE_STMT(FloatingLiteral, {})
  2480. DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
  2481. DEF_TRAVERSE_STMT(StringLiteral, {})
  2482. DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
  2483. DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
  2484. DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
  2485. DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
  2486. // Traverse OpenCL: AsType, Convert.
  2487. DEF_TRAVERSE_STMT(AsTypeExpr, {})
  2488. // OpenMP directives.
  2489. template <typename Derived>
  2490. bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
  2491. OMPExecutableDirective *S) {
  2492. for (auto *C : S->clauses()) {
  2493. TRY_TO(TraverseOMPClause(C));
  2494. }
  2495. return true;
  2496. }
  2497. DEF_TRAVERSE_STMT(OMPCanonicalLoop, {
  2498. if (!getDerived().shouldVisitImplicitCode()) {
  2499. // Visit only the syntactical loop.
  2500. TRY_TO(TraverseStmt(S->getLoopStmt()));
  2501. ShouldVisitChildren = false;
  2502. }
  2503. })
  2504. template <typename Derived>
  2505. bool
  2506. RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
  2507. return TraverseOMPExecutableDirective(S);
  2508. }
  2509. DEF_TRAVERSE_STMT(OMPMetaDirective,
  2510. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2511. DEF_TRAVERSE_STMT(OMPParallelDirective,
  2512. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2513. DEF_TRAVERSE_STMT(OMPSimdDirective,
  2514. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2515. DEF_TRAVERSE_STMT(OMPTileDirective,
  2516. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2517. DEF_TRAVERSE_STMT(OMPUnrollDirective,
  2518. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2519. DEF_TRAVERSE_STMT(OMPForDirective,
  2520. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2521. DEF_TRAVERSE_STMT(OMPForSimdDirective,
  2522. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2523. DEF_TRAVERSE_STMT(OMPSectionsDirective,
  2524. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2525. DEF_TRAVERSE_STMT(OMPSectionDirective,
  2526. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2527. DEF_TRAVERSE_STMT(OMPSingleDirective,
  2528. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2529. DEF_TRAVERSE_STMT(OMPMasterDirective,
  2530. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2531. DEF_TRAVERSE_STMT(OMPCriticalDirective, {
  2532. TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
  2533. TRY_TO(TraverseOMPExecutableDirective(S));
  2534. })
  2535. DEF_TRAVERSE_STMT(OMPParallelForDirective,
  2536. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2537. DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
  2538. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2539. DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
  2540. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2541. DEF_TRAVERSE_STMT(OMPParallelMaskedDirective,
  2542. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2543. DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
  2544. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2545. DEF_TRAVERSE_STMT(OMPTaskDirective,
  2546. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2547. DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
  2548. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2549. DEF_TRAVERSE_STMT(OMPBarrierDirective,
  2550. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2551. DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
  2552. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2553. DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
  2554. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2555. DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
  2556. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2557. DEF_TRAVERSE_STMT(OMPCancelDirective,
  2558. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2559. DEF_TRAVERSE_STMT(OMPFlushDirective,
  2560. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2561. DEF_TRAVERSE_STMT(OMPDepobjDirective,
  2562. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2563. DEF_TRAVERSE_STMT(OMPScanDirective,
  2564. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2565. DEF_TRAVERSE_STMT(OMPOrderedDirective,
  2566. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2567. DEF_TRAVERSE_STMT(OMPAtomicDirective,
  2568. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2569. DEF_TRAVERSE_STMT(OMPTargetDirective,
  2570. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2571. DEF_TRAVERSE_STMT(OMPTargetDataDirective,
  2572. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2573. DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
  2574. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2575. DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
  2576. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2577. DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
  2578. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2579. DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
  2580. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2581. DEF_TRAVERSE_STMT(OMPTeamsDirective,
  2582. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2583. DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
  2584. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2585. DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
  2586. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2587. DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
  2588. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2589. DEF_TRAVERSE_STMT(OMPMasterTaskLoopDirective,
  2590. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2591. DEF_TRAVERSE_STMT(OMPMasterTaskLoopSimdDirective,
  2592. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2593. DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopDirective,
  2594. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2595. DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopSimdDirective,
  2596. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2597. DEF_TRAVERSE_STMT(OMPMaskedTaskLoopDirective,
  2598. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2599. DEF_TRAVERSE_STMT(OMPMaskedTaskLoopSimdDirective,
  2600. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2601. DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopDirective,
  2602. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2603. DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopSimdDirective,
  2604. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2605. DEF_TRAVERSE_STMT(OMPDistributeDirective,
  2606. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2607. DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
  2608. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2609. DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
  2610. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2611. DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
  2612. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2613. DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
  2614. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2615. DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
  2616. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2617. DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
  2618. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2619. DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
  2620. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2621. DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
  2622. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2623. DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
  2624. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2625. DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
  2626. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2627. DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
  2628. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2629. DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
  2630. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2631. DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
  2632. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2633. DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
  2634. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2635. DEF_TRAVERSE_STMT(OMPInteropDirective,
  2636. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2637. DEF_TRAVERSE_STMT(OMPDispatchDirective,
  2638. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2639. DEF_TRAVERSE_STMT(OMPMaskedDirective,
  2640. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2641. DEF_TRAVERSE_STMT(OMPGenericLoopDirective,
  2642. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2643. DEF_TRAVERSE_STMT(OMPTeamsGenericLoopDirective,
  2644. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2645. DEF_TRAVERSE_STMT(OMPTargetTeamsGenericLoopDirective,
  2646. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2647. DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
  2648. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2649. DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective,
  2650. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2651. DEF_TRAVERSE_STMT(OMPErrorDirective,
  2652. { TRY_TO(TraverseOMPExecutableDirective(S)); })
  2653. // OpenMP clauses.
  2654. template <typename Derived>
  2655. bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
  2656. if (!C)
  2657. return true;
  2658. switch (C->getClauseKind()) {
  2659. #define GEN_CLANG_CLAUSE_CLASS
  2660. #define CLAUSE_CLASS(Enum, Str, Class) \
  2661. case llvm::omp::Clause::Enum: \
  2662. TRY_TO(Visit##Class(static_cast<Class *>(C))); \
  2663. break;
  2664. #define CLAUSE_NO_CLASS(Enum, Str) \
  2665. case llvm::omp::Clause::Enum: \
  2666. break;
  2667. #include "llvm/Frontend/OpenMP/OMP.inc"
  2668. }
  2669. return true;
  2670. }
  2671. template <typename Derived>
  2672. bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
  2673. OMPClauseWithPreInit *Node) {
  2674. TRY_TO(TraverseStmt(Node->getPreInitStmt()));
  2675. return true;
  2676. }
  2677. template <typename Derived>
  2678. bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
  2679. OMPClauseWithPostUpdate *Node) {
  2680. TRY_TO(VisitOMPClauseWithPreInit(Node));
  2681. TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
  2682. return true;
  2683. }
  2684. template <typename Derived>
  2685. bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause(
  2686. OMPAllocatorClause *C) {
  2687. TRY_TO(TraverseStmt(C->getAllocator()));
  2688. return true;
  2689. }
  2690. template <typename Derived>
  2691. bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) {
  2692. TRY_TO(TraverseStmt(C->getAllocator()));
  2693. TRY_TO(VisitOMPClauseList(C));
  2694. return true;
  2695. }
  2696. template <typename Derived>
  2697. bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
  2698. TRY_TO(VisitOMPClauseWithPreInit(C));
  2699. TRY_TO(TraverseStmt(C->getCondition()));
  2700. return true;
  2701. }
  2702. template <typename Derived>
  2703. bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
  2704. TRY_TO(VisitOMPClauseWithPreInit(C));
  2705. TRY_TO(TraverseStmt(C->getCondition()));
  2706. return true;
  2707. }
  2708. template <typename Derived>
  2709. bool
  2710. RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
  2711. TRY_TO(VisitOMPClauseWithPreInit(C));
  2712. TRY_TO(TraverseStmt(C->getNumThreads()));
  2713. return true;
  2714. }
  2715. template <typename Derived>
  2716. bool RecursiveASTVisitor<Derived>::VisitOMPAlignClause(OMPAlignClause *C) {
  2717. TRY_TO(TraverseStmt(C->getAlignment()));
  2718. return true;
  2719. }
  2720. template <typename Derived>
  2721. bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
  2722. TRY_TO(TraverseStmt(C->getSafelen()));
  2723. return true;
  2724. }
  2725. template <typename Derived>
  2726. bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
  2727. TRY_TO(TraverseStmt(C->getSimdlen()));
  2728. return true;
  2729. }
  2730. template <typename Derived>
  2731. bool RecursiveASTVisitor<Derived>::VisitOMPSizesClause(OMPSizesClause *C) {
  2732. for (Expr *E : C->getSizesRefs())
  2733. TRY_TO(TraverseStmt(E));
  2734. return true;
  2735. }
  2736. template <typename Derived>
  2737. bool RecursiveASTVisitor<Derived>::VisitOMPFullClause(OMPFullClause *C) {
  2738. return true;
  2739. }
  2740. template <typename Derived>
  2741. bool RecursiveASTVisitor<Derived>::VisitOMPPartialClause(OMPPartialClause *C) {
  2742. TRY_TO(TraverseStmt(C->getFactor()));
  2743. return true;
  2744. }
  2745. template <typename Derived>
  2746. bool
  2747. RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
  2748. TRY_TO(TraverseStmt(C->getNumForLoops()));
  2749. return true;
  2750. }
  2751. template <typename Derived>
  2752. bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
  2753. return true;
  2754. }
  2755. template <typename Derived>
  2756. bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
  2757. return true;
  2758. }
  2759. template <typename Derived>
  2760. bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedAddressClause(
  2761. OMPUnifiedAddressClause *) {
  2762. return true;
  2763. }
  2764. template <typename Derived>
  2765. bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedSharedMemoryClause(
  2766. OMPUnifiedSharedMemoryClause *) {
  2767. return true;
  2768. }
  2769. template <typename Derived>
  2770. bool RecursiveASTVisitor<Derived>::VisitOMPReverseOffloadClause(
  2771. OMPReverseOffloadClause *) {
  2772. return true;
  2773. }
  2774. template <typename Derived>
  2775. bool RecursiveASTVisitor<Derived>::VisitOMPDynamicAllocatorsClause(
  2776. OMPDynamicAllocatorsClause *) {
  2777. return true;
  2778. }
  2779. template <typename Derived>
  2780. bool RecursiveASTVisitor<Derived>::VisitOMPAtomicDefaultMemOrderClause(
  2781. OMPAtomicDefaultMemOrderClause *) {
  2782. return true;
  2783. }
  2784. template <typename Derived>
  2785. bool RecursiveASTVisitor<Derived>::VisitOMPAtClause(OMPAtClause *) {
  2786. return true;
  2787. }
  2788. template <typename Derived>
  2789. bool RecursiveASTVisitor<Derived>::VisitOMPSeverityClause(OMPSeverityClause *) {
  2790. return true;
  2791. }
  2792. template <typename Derived>
  2793. bool RecursiveASTVisitor<Derived>::VisitOMPMessageClause(OMPMessageClause *C) {
  2794. TRY_TO(TraverseStmt(C->getMessageString()));
  2795. return true;
  2796. }
  2797. template <typename Derived>
  2798. bool
  2799. RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
  2800. TRY_TO(VisitOMPClauseWithPreInit(C));
  2801. TRY_TO(TraverseStmt(C->getChunkSize()));
  2802. return true;
  2803. }
  2804. template <typename Derived>
  2805. bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
  2806. TRY_TO(TraverseStmt(C->getNumForLoops()));
  2807. return true;
  2808. }
  2809. template <typename Derived>
  2810. bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
  2811. return true;
  2812. }
  2813. template <typename Derived>
  2814. bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
  2815. return true;
  2816. }
  2817. template <typename Derived>
  2818. bool
  2819. RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
  2820. return true;
  2821. }
  2822. template <typename Derived>
  2823. bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
  2824. return true;
  2825. }
  2826. template <typename Derived>
  2827. bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
  2828. return true;
  2829. }
  2830. template <typename Derived>
  2831. bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
  2832. return true;
  2833. }
  2834. template <typename Derived>
  2835. bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
  2836. return true;
  2837. }
  2838. template <typename Derived>
  2839. bool RecursiveASTVisitor<Derived>::VisitOMPCompareClause(OMPCompareClause *) {
  2840. return true;
  2841. }
  2842. template <typename Derived>
  2843. bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
  2844. return true;
  2845. }
  2846. template <typename Derived>
  2847. bool RecursiveASTVisitor<Derived>::VisitOMPAcqRelClause(OMPAcqRelClause *) {
  2848. return true;
  2849. }
  2850. template <typename Derived>
  2851. bool RecursiveASTVisitor<Derived>::VisitOMPAcquireClause(OMPAcquireClause *) {
  2852. return true;
  2853. }
  2854. template <typename Derived>
  2855. bool RecursiveASTVisitor<Derived>::VisitOMPReleaseClause(OMPReleaseClause *) {
  2856. return true;
  2857. }
  2858. template <typename Derived>
  2859. bool RecursiveASTVisitor<Derived>::VisitOMPRelaxedClause(OMPRelaxedClause *) {
  2860. return true;
  2861. }
  2862. template <typename Derived>
  2863. bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
  2864. return true;
  2865. }
  2866. template <typename Derived>
  2867. bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
  2868. return true;
  2869. }
  2870. template <typename Derived>
  2871. bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
  2872. return true;
  2873. }
  2874. template <typename Derived>
  2875. bool RecursiveASTVisitor<Derived>::VisitOMPInitClause(OMPInitClause *C) {
  2876. TRY_TO(VisitOMPClauseList(C));
  2877. return true;
  2878. }
  2879. template <typename Derived>
  2880. bool RecursiveASTVisitor<Derived>::VisitOMPUseClause(OMPUseClause *C) {
  2881. TRY_TO(TraverseStmt(C->getInteropVar()));
  2882. return true;
  2883. }
  2884. template <typename Derived>
  2885. bool RecursiveASTVisitor<Derived>::VisitOMPDestroyClause(OMPDestroyClause *C) {
  2886. TRY_TO(TraverseStmt(C->getInteropVar()));
  2887. return true;
  2888. }
  2889. template <typename Derived>
  2890. bool RecursiveASTVisitor<Derived>::VisitOMPNovariantsClause(
  2891. OMPNovariantsClause *C) {
  2892. TRY_TO(VisitOMPClauseWithPreInit(C));
  2893. TRY_TO(TraverseStmt(C->getCondition()));
  2894. return true;
  2895. }
  2896. template <typename Derived>
  2897. bool RecursiveASTVisitor<Derived>::VisitOMPNocontextClause(
  2898. OMPNocontextClause *C) {
  2899. TRY_TO(VisitOMPClauseWithPreInit(C));
  2900. TRY_TO(TraverseStmt(C->getCondition()));
  2901. return true;
  2902. }
  2903. template <typename Derived>
  2904. template <typename T>
  2905. bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
  2906. for (auto *E : Node->varlists()) {
  2907. TRY_TO(TraverseStmt(E));
  2908. }
  2909. return true;
  2910. }
  2911. template <typename Derived>
  2912. bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause(
  2913. OMPInclusiveClause *C) {
  2914. TRY_TO(VisitOMPClauseList(C));
  2915. return true;
  2916. }
  2917. template <typename Derived>
  2918. bool RecursiveASTVisitor<Derived>::VisitOMPExclusiveClause(
  2919. OMPExclusiveClause *C) {
  2920. TRY_TO(VisitOMPClauseList(C));
  2921. return true;
  2922. }
  2923. template <typename Derived>
  2924. bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
  2925. TRY_TO(VisitOMPClauseList(C));
  2926. for (auto *E : C->private_copies()) {
  2927. TRY_TO(TraverseStmt(E));
  2928. }
  2929. return true;
  2930. }
  2931. template <typename Derived>
  2932. bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
  2933. OMPFirstprivateClause *C) {
  2934. TRY_TO(VisitOMPClauseList(C));
  2935. TRY_TO(VisitOMPClauseWithPreInit(C));
  2936. for (auto *E : C->private_copies()) {
  2937. TRY_TO(TraverseStmt(E));
  2938. }
  2939. for (auto *E : C->inits()) {
  2940. TRY_TO(TraverseStmt(E));
  2941. }
  2942. return true;
  2943. }
  2944. template <typename Derived>
  2945. bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
  2946. OMPLastprivateClause *C) {
  2947. TRY_TO(VisitOMPClauseList(C));
  2948. TRY_TO(VisitOMPClauseWithPostUpdate(C));
  2949. for (auto *E : C->private_copies()) {
  2950. TRY_TO(TraverseStmt(E));
  2951. }
  2952. for (auto *E : C->source_exprs()) {
  2953. TRY_TO(TraverseStmt(E));
  2954. }
  2955. for (auto *E : C->destination_exprs()) {
  2956. TRY_TO(TraverseStmt(E));
  2957. }
  2958. for (auto *E : C->assignment_ops()) {
  2959. TRY_TO(TraverseStmt(E));
  2960. }
  2961. return true;
  2962. }
  2963. template <typename Derived>
  2964. bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
  2965. TRY_TO(VisitOMPClauseList(C));
  2966. return true;
  2967. }
  2968. template <typename Derived>
  2969. bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
  2970. TRY_TO(TraverseStmt(C->getStep()));
  2971. TRY_TO(TraverseStmt(C->getCalcStep()));
  2972. TRY_TO(VisitOMPClauseList(C));
  2973. TRY_TO(VisitOMPClauseWithPostUpdate(C));
  2974. for (auto *E : C->privates()) {
  2975. TRY_TO(TraverseStmt(E));
  2976. }
  2977. for (auto *E : C->inits()) {
  2978. TRY_TO(TraverseStmt(E));
  2979. }
  2980. for (auto *E : C->updates()) {
  2981. TRY_TO(TraverseStmt(E));
  2982. }
  2983. for (auto *E : C->finals()) {
  2984. TRY_TO(TraverseStmt(E));
  2985. }
  2986. return true;
  2987. }
  2988. template <typename Derived>
  2989. bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
  2990. TRY_TO(TraverseStmt(C->getAlignment()));
  2991. TRY_TO(VisitOMPClauseList(C));
  2992. return true;
  2993. }
  2994. template <typename Derived>
  2995. bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
  2996. TRY_TO(VisitOMPClauseList(C));
  2997. for (auto *E : C->source_exprs()) {
  2998. TRY_TO(TraverseStmt(E));
  2999. }
  3000. for (auto *E : C->destination_exprs()) {
  3001. TRY_TO(TraverseStmt(E));
  3002. }
  3003. for (auto *E : C->assignment_ops()) {
  3004. TRY_TO(TraverseStmt(E));
  3005. }
  3006. return true;
  3007. }
  3008. template <typename Derived>
  3009. bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
  3010. OMPCopyprivateClause *C) {
  3011. TRY_TO(VisitOMPClauseList(C));
  3012. for (auto *E : C->source_exprs()) {
  3013. TRY_TO(TraverseStmt(E));
  3014. }
  3015. for (auto *E : C->destination_exprs()) {
  3016. TRY_TO(TraverseStmt(E));
  3017. }
  3018. for (auto *E : C->assignment_ops()) {
  3019. TRY_TO(TraverseStmt(E));
  3020. }
  3021. return true;
  3022. }
  3023. template <typename Derived>
  3024. bool
  3025. RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
  3026. TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
  3027. TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
  3028. TRY_TO(VisitOMPClauseList(C));
  3029. TRY_TO(VisitOMPClauseWithPostUpdate(C));
  3030. for (auto *E : C->privates()) {
  3031. TRY_TO(TraverseStmt(E));
  3032. }
  3033. for (auto *E : C->lhs_exprs()) {
  3034. TRY_TO(TraverseStmt(E));
  3035. }
  3036. for (auto *E : C->rhs_exprs()) {
  3037. TRY_TO(TraverseStmt(E));
  3038. }
  3039. for (auto *E : C->reduction_ops()) {
  3040. TRY_TO(TraverseStmt(E));
  3041. }
  3042. if (C->getModifier() == OMPC_REDUCTION_inscan) {
  3043. for (auto *E : C->copy_ops()) {
  3044. TRY_TO(TraverseStmt(E));
  3045. }
  3046. for (auto *E : C->copy_array_temps()) {
  3047. TRY_TO(TraverseStmt(E));
  3048. }
  3049. for (auto *E : C->copy_array_elems()) {
  3050. TRY_TO(TraverseStmt(E));
  3051. }
  3052. }
  3053. return true;
  3054. }
  3055. template <typename Derived>
  3056. bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
  3057. OMPTaskReductionClause *C) {
  3058. TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
  3059. TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
  3060. TRY_TO(VisitOMPClauseList(C));
  3061. TRY_TO(VisitOMPClauseWithPostUpdate(C));
  3062. for (auto *E : C->privates()) {
  3063. TRY_TO(TraverseStmt(E));
  3064. }
  3065. for (auto *E : C->lhs_exprs()) {
  3066. TRY_TO(TraverseStmt(E));
  3067. }
  3068. for (auto *E : C->rhs_exprs()) {
  3069. TRY_TO(TraverseStmt(E));
  3070. }
  3071. for (auto *E : C->reduction_ops()) {
  3072. TRY_TO(TraverseStmt(E));
  3073. }
  3074. return true;
  3075. }
  3076. template <typename Derived>
  3077. bool RecursiveASTVisitor<Derived>::VisitOMPInReductionClause(
  3078. OMPInReductionClause *C) {
  3079. TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
  3080. TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
  3081. TRY_TO(VisitOMPClauseList(C));
  3082. TRY_TO(VisitOMPClauseWithPostUpdate(C));
  3083. for (auto *E : C->privates()) {
  3084. TRY_TO(TraverseStmt(E));
  3085. }
  3086. for (auto *E : C->lhs_exprs()) {
  3087. TRY_TO(TraverseStmt(E));
  3088. }
  3089. for (auto *E : C->rhs_exprs()) {
  3090. TRY_TO(TraverseStmt(E));
  3091. }
  3092. for (auto *E : C->reduction_ops()) {
  3093. TRY_TO(TraverseStmt(E));
  3094. }
  3095. for (auto *E : C->taskgroup_descriptors())
  3096. TRY_TO(TraverseStmt(E));
  3097. return true;
  3098. }
  3099. template <typename Derived>
  3100. bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
  3101. TRY_TO(VisitOMPClauseList(C));
  3102. return true;
  3103. }
  3104. template <typename Derived>
  3105. bool RecursiveASTVisitor<Derived>::VisitOMPDepobjClause(OMPDepobjClause *C) {
  3106. TRY_TO(TraverseStmt(C->getDepobj()));
  3107. return true;
  3108. }
  3109. template <typename Derived>
  3110. bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
  3111. TRY_TO(VisitOMPClauseList(C));
  3112. return true;
  3113. }
  3114. template <typename Derived>
  3115. bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
  3116. TRY_TO(VisitOMPClauseWithPreInit(C));
  3117. TRY_TO(TraverseStmt(C->getDevice()));
  3118. return true;
  3119. }
  3120. template <typename Derived>
  3121. bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
  3122. TRY_TO(VisitOMPClauseList(C));
  3123. return true;
  3124. }
  3125. template <typename Derived>
  3126. bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
  3127. OMPNumTeamsClause *C) {
  3128. TRY_TO(VisitOMPClauseWithPreInit(C));
  3129. TRY_TO(TraverseStmt(C->getNumTeams()));
  3130. return true;
  3131. }
  3132. template <typename Derived>
  3133. bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
  3134. OMPThreadLimitClause *C) {
  3135. TRY_TO(VisitOMPClauseWithPreInit(C));
  3136. TRY_TO(TraverseStmt(C->getThreadLimit()));
  3137. return true;
  3138. }
  3139. template <typename Derived>
  3140. bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
  3141. OMPPriorityClause *C) {
  3142. TRY_TO(VisitOMPClauseWithPreInit(C));
  3143. TRY_TO(TraverseStmt(C->getPriority()));
  3144. return true;
  3145. }
  3146. template <typename Derived>
  3147. bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
  3148. OMPGrainsizeClause *C) {
  3149. TRY_TO(VisitOMPClauseWithPreInit(C));
  3150. TRY_TO(TraverseStmt(C->getGrainsize()));
  3151. return true;
  3152. }
  3153. template <typename Derived>
  3154. bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
  3155. OMPNumTasksClause *C) {
  3156. TRY_TO(VisitOMPClauseWithPreInit(C));
  3157. TRY_TO(TraverseStmt(C->getNumTasks()));
  3158. return true;
  3159. }
  3160. template <typename Derived>
  3161. bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
  3162. TRY_TO(TraverseStmt(C->getHint()));
  3163. return true;
  3164. }
  3165. template <typename Derived>
  3166. bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
  3167. OMPDistScheduleClause *C) {
  3168. TRY_TO(VisitOMPClauseWithPreInit(C));
  3169. TRY_TO(TraverseStmt(C->getChunkSize()));
  3170. return true;
  3171. }
  3172. template <typename Derived>
  3173. bool
  3174. RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
  3175. return true;
  3176. }
  3177. template <typename Derived>
  3178. bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
  3179. TRY_TO(VisitOMPClauseList(C));
  3180. return true;
  3181. }
  3182. template <typename Derived>
  3183. bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
  3184. TRY_TO(VisitOMPClauseList(C));
  3185. return true;
  3186. }
  3187. template <typename Derived>
  3188. bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
  3189. OMPUseDevicePtrClause *C) {
  3190. TRY_TO(VisitOMPClauseList(C));
  3191. return true;
  3192. }
  3193. template <typename Derived>
  3194. bool RecursiveASTVisitor<Derived>::VisitOMPUseDeviceAddrClause(
  3195. OMPUseDeviceAddrClause *C) {
  3196. TRY_TO(VisitOMPClauseList(C));
  3197. return true;
  3198. }
  3199. template <typename Derived>
  3200. bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
  3201. OMPIsDevicePtrClause *C) {
  3202. TRY_TO(VisitOMPClauseList(C));
  3203. return true;
  3204. }
  3205. template <typename Derived>
  3206. bool RecursiveASTVisitor<Derived>::VisitOMPHasDeviceAddrClause(
  3207. OMPHasDeviceAddrClause *C) {
  3208. TRY_TO(VisitOMPClauseList(C));
  3209. return true;
  3210. }
  3211. template <typename Derived>
  3212. bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause(
  3213. OMPNontemporalClause *C) {
  3214. TRY_TO(VisitOMPClauseList(C));
  3215. for (auto *E : C->private_refs()) {
  3216. TRY_TO(TraverseStmt(E));
  3217. }
  3218. return true;
  3219. }
  3220. template <typename Derived>
  3221. bool RecursiveASTVisitor<Derived>::VisitOMPOrderClause(OMPOrderClause *) {
  3222. return true;
  3223. }
  3224. template <typename Derived>
  3225. bool RecursiveASTVisitor<Derived>::VisitOMPDetachClause(OMPDetachClause *C) {
  3226. TRY_TO(TraverseStmt(C->getEventHandler()));
  3227. return true;
  3228. }
  3229. template <typename Derived>
  3230. bool RecursiveASTVisitor<Derived>::VisitOMPUsesAllocatorsClause(
  3231. OMPUsesAllocatorsClause *C) {
  3232. for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
  3233. const OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I);
  3234. TRY_TO(TraverseStmt(Data.Allocator));
  3235. TRY_TO(TraverseStmt(Data.AllocatorTraits));
  3236. }
  3237. return true;
  3238. }
  3239. template <typename Derived>
  3240. bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause(
  3241. OMPAffinityClause *C) {
  3242. TRY_TO(TraverseStmt(C->getModifier()));
  3243. for (Expr *E : C->varlists())
  3244. TRY_TO(TraverseStmt(E));
  3245. return true;
  3246. }
  3247. template <typename Derived>
  3248. bool RecursiveASTVisitor<Derived>::VisitOMPFilterClause(OMPFilterClause *C) {
  3249. TRY_TO(VisitOMPClauseWithPreInit(C));
  3250. TRY_TO(TraverseStmt(C->getThreadID()));
  3251. return true;
  3252. }
  3253. template <typename Derived>
  3254. bool RecursiveASTVisitor<Derived>::VisitOMPBindClause(OMPBindClause *C) {
  3255. return true;
  3256. }
  3257. template <typename Derived>
  3258. bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause(
  3259. OMPXDynCGroupMemClause *C) {
  3260. TRY_TO(VisitOMPClauseWithPreInit(C));
  3261. TRY_TO(TraverseStmt(C->getSize()));
  3262. return true;
  3263. }
  3264. // FIXME: look at the following tricky-seeming exprs to see if we
  3265. // need to recurse on anything. These are ones that have methods
  3266. // returning decls or qualtypes or nestednamespecifier -- though I'm
  3267. // not sure if they own them -- or just seemed very complicated, or
  3268. // had lots of sub-types to explore.
  3269. //
  3270. // VisitOverloadExpr and its children: recurse on template args? etc?
  3271. // FIXME: go through all the stmts and exprs again, and see which of them
  3272. // create new types, and recurse on the types (TypeLocs?) of those.
  3273. // Candidates:
  3274. //
  3275. // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
  3276. // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
  3277. // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
  3278. // Every class that has getQualifier.
  3279. #undef DEF_TRAVERSE_STMT
  3280. #undef TRAVERSE_STMT
  3281. #undef TRAVERSE_STMT_BASE
  3282. #undef TRY_TO
  3283. } // end namespace clang
  3284. #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
  3285. #ifdef __GNUC__
  3286. #pragma GCC diagnostic pop
  3287. #endif