ExprCXX.h 173 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ExprCXX.h - Classes for representing expressions ---------*- 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. /// \file
  15. /// Defines the clang::Expr interface and subclasses for C++ expressions.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_AST_EXPRCXX_H
  19. #define LLVM_CLANG_AST_EXPRCXX_H
  20. #include "clang/AST/ASTConcept.h"
  21. #include "clang/AST/ComputeDependence.h"
  22. #include "clang/AST/Decl.h"
  23. #include "clang/AST/DeclBase.h"
  24. #include "clang/AST/DeclCXX.h"
  25. #include "clang/AST/DeclTemplate.h"
  26. #include "clang/AST/DeclarationName.h"
  27. #include "clang/AST/DependenceFlags.h"
  28. #include "clang/AST/Expr.h"
  29. #include "clang/AST/NestedNameSpecifier.h"
  30. #include "clang/AST/OperationKinds.h"
  31. #include "clang/AST/Stmt.h"
  32. #include "clang/AST/StmtCXX.h"
  33. #include "clang/AST/TemplateBase.h"
  34. #include "clang/AST/Type.h"
  35. #include "clang/AST/UnresolvedSet.h"
  36. #include "clang/Basic/ExceptionSpecificationType.h"
  37. #include "clang/Basic/ExpressionTraits.h"
  38. #include "clang/Basic/LLVM.h"
  39. #include "clang/Basic/Lambda.h"
  40. #include "clang/Basic/LangOptions.h"
  41. #include "clang/Basic/OperatorKinds.h"
  42. #include "clang/Basic/SourceLocation.h"
  43. #include "clang/Basic/Specifiers.h"
  44. #include "clang/Basic/TypeTraits.h"
  45. #include "llvm/ADT/ArrayRef.h"
  46. #include "llvm/ADT/None.h"
  47. #include "llvm/ADT/Optional.h"
  48. #include "llvm/ADT/PointerUnion.h"
  49. #include "llvm/ADT/StringRef.h"
  50. #include "llvm/ADT/iterator_range.h"
  51. #include "llvm/Support/Casting.h"
  52. #include "llvm/Support/Compiler.h"
  53. #include "llvm/Support/TrailingObjects.h"
  54. #include <cassert>
  55. #include <cstddef>
  56. #include <cstdint>
  57. #include <memory>
  58. namespace clang {
  59. class ASTContext;
  60. class DeclAccessPair;
  61. class IdentifierInfo;
  62. class LambdaCapture;
  63. class NonTypeTemplateParmDecl;
  64. class TemplateParameterList;
  65. //===--------------------------------------------------------------------===//
  66. // C++ Expressions.
  67. //===--------------------------------------------------------------------===//
  68. /// A call to an overloaded operator written using operator
  69. /// syntax.
  70. ///
  71. /// Represents a call to an overloaded operator written using operator
  72. /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
  73. /// normal call, this AST node provides better information about the
  74. /// syntactic representation of the call.
  75. ///
  76. /// In a C++ template, this expression node kind will be used whenever
  77. /// any of the arguments are type-dependent. In this case, the
  78. /// function itself will be a (possibly empty) set of functions and
  79. /// function templates that were found by name lookup at template
  80. /// definition time.
  81. class CXXOperatorCallExpr final : public CallExpr {
  82. friend class ASTStmtReader;
  83. friend class ASTStmtWriter;
  84. SourceRange Range;
  85. // CXXOperatorCallExpr has some trailing objects belonging
  86. // to CallExpr. See CallExpr for the details.
  87. SourceRange getSourceRangeImpl() const LLVM_READONLY;
  88. CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn,
  89. ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
  90. SourceLocation OperatorLoc, FPOptionsOverride FPFeatures,
  91. ADLCallKind UsesADL);
  92. CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty);
  93. public:
  94. static CXXOperatorCallExpr *
  95. Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
  96. ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
  97. SourceLocation OperatorLoc, FPOptionsOverride FPFeatures,
  98. ADLCallKind UsesADL = NotADL);
  99. static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx,
  100. unsigned NumArgs, bool HasFPFeatures,
  101. EmptyShell Empty);
  102. /// Returns the kind of overloaded operator that this expression refers to.
  103. OverloadedOperatorKind getOperator() const {
  104. return static_cast<OverloadedOperatorKind>(
  105. CXXOperatorCallExprBits.OperatorKind);
  106. }
  107. static bool isAssignmentOp(OverloadedOperatorKind Opc) {
  108. return Opc == OO_Equal || Opc == OO_StarEqual || Opc == OO_SlashEqual ||
  109. Opc == OO_PercentEqual || Opc == OO_PlusEqual ||
  110. Opc == OO_MinusEqual || Opc == OO_LessLessEqual ||
  111. Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual ||
  112. Opc == OO_CaretEqual || Opc == OO_PipeEqual;
  113. }
  114. bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
  115. static bool isComparisonOp(OverloadedOperatorKind Opc) {
  116. switch (Opc) {
  117. case OO_EqualEqual:
  118. case OO_ExclaimEqual:
  119. case OO_Greater:
  120. case OO_GreaterEqual:
  121. case OO_Less:
  122. case OO_LessEqual:
  123. case OO_Spaceship:
  124. return true;
  125. default:
  126. return false;
  127. }
  128. }
  129. bool isComparisonOp() const { return isComparisonOp(getOperator()); }
  130. /// Is this written as an infix binary operator?
  131. bool isInfixBinaryOp() const;
  132. /// Returns the location of the operator symbol in the expression.
  133. ///
  134. /// When \c getOperator()==OO_Call, this is the location of the right
  135. /// parentheses; when \c getOperator()==OO_Subscript, this is the location
  136. /// of the right bracket.
  137. SourceLocation getOperatorLoc() const { return getRParenLoc(); }
  138. SourceLocation getExprLoc() const LLVM_READONLY {
  139. OverloadedOperatorKind Operator = getOperator();
  140. return (Operator < OO_Plus || Operator >= OO_Arrow ||
  141. Operator == OO_PlusPlus || Operator == OO_MinusMinus)
  142. ? getBeginLoc()
  143. : getOperatorLoc();
  144. }
  145. SourceLocation getBeginLoc() const { return Range.getBegin(); }
  146. SourceLocation getEndLoc() const { return Range.getEnd(); }
  147. SourceRange getSourceRange() const { return Range; }
  148. static bool classof(const Stmt *T) {
  149. return T->getStmtClass() == CXXOperatorCallExprClass;
  150. }
  151. };
  152. /// Represents a call to a member function that
  153. /// may be written either with member call syntax (e.g., "obj.func()"
  154. /// or "objptr->func()") or with normal function-call syntax
  155. /// ("func()") within a member function that ends up calling a member
  156. /// function. The callee in either case is a MemberExpr that contains
  157. /// both the object argument and the member function, while the
  158. /// arguments are the arguments within the parentheses (not including
  159. /// the object argument).
  160. class CXXMemberCallExpr final : public CallExpr {
  161. // CXXMemberCallExpr has some trailing objects belonging
  162. // to CallExpr. See CallExpr for the details.
  163. CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty,
  164. ExprValueKind VK, SourceLocation RP,
  165. FPOptionsOverride FPOptions, unsigned MinNumArgs);
  166. CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty);
  167. public:
  168. static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn,
  169. ArrayRef<Expr *> Args, QualType Ty,
  170. ExprValueKind VK, SourceLocation RP,
  171. FPOptionsOverride FPFeatures,
  172. unsigned MinNumArgs = 0);
  173. static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
  174. bool HasFPFeatures, EmptyShell Empty);
  175. /// Retrieve the implicit object argument for the member call.
  176. ///
  177. /// For example, in "x.f(5)", this returns the sub-expression "x".
  178. Expr *getImplicitObjectArgument() const;
  179. /// Retrieve the type of the object argument.
  180. ///
  181. /// Note that this always returns a non-pointer type.
  182. QualType getObjectType() const;
  183. /// Retrieve the declaration of the called method.
  184. CXXMethodDecl *getMethodDecl() const;
  185. /// Retrieve the CXXRecordDecl for the underlying type of
  186. /// the implicit object argument.
  187. ///
  188. /// Note that this is may not be the same declaration as that of the class
  189. /// context of the CXXMethodDecl which this function is calling.
  190. /// FIXME: Returns 0 for member pointer call exprs.
  191. CXXRecordDecl *getRecordDecl() const;
  192. SourceLocation getExprLoc() const LLVM_READONLY {
  193. SourceLocation CLoc = getCallee()->getExprLoc();
  194. if (CLoc.isValid())
  195. return CLoc;
  196. return getBeginLoc();
  197. }
  198. static bool classof(const Stmt *T) {
  199. return T->getStmtClass() == CXXMemberCallExprClass;
  200. }
  201. };
  202. /// Represents a call to a CUDA kernel function.
  203. class CUDAKernelCallExpr final : public CallExpr {
  204. friend class ASTStmtReader;
  205. enum { CONFIG, END_PREARG };
  206. // CUDAKernelCallExpr has some trailing objects belonging
  207. // to CallExpr. See CallExpr for the details.
  208. CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args,
  209. QualType Ty, ExprValueKind VK, SourceLocation RP,
  210. FPOptionsOverride FPFeatures, unsigned MinNumArgs);
  211. CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty);
  212. public:
  213. static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn,
  214. CallExpr *Config, ArrayRef<Expr *> Args,
  215. QualType Ty, ExprValueKind VK,
  216. SourceLocation RP,
  217. FPOptionsOverride FPFeatures,
  218. unsigned MinNumArgs = 0);
  219. static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx,
  220. unsigned NumArgs, bool HasFPFeatures,
  221. EmptyShell Empty);
  222. const CallExpr *getConfig() const {
  223. return cast_or_null<CallExpr>(getPreArg(CONFIG));
  224. }
  225. CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
  226. static bool classof(const Stmt *T) {
  227. return T->getStmtClass() == CUDAKernelCallExprClass;
  228. }
  229. };
  230. /// A rewritten comparison expression that was originally written using
  231. /// operator syntax.
  232. ///
  233. /// In C++20, the following rewrites are performed:
  234. /// - <tt>a == b</tt> -> <tt>b == a</tt>
  235. /// - <tt>a != b</tt> -> <tt>!(a == b)</tt>
  236. /// - <tt>a != b</tt> -> <tt>!(b == a)</tt>
  237. /// - For \c \@ in \c <, \c <=, \c >, \c >=, \c <=>:
  238. /// - <tt>a @ b</tt> -> <tt>(a <=> b) @ 0</tt>
  239. /// - <tt>a @ b</tt> -> <tt>0 @ (b <=> a)</tt>
  240. ///
  241. /// This expression provides access to both the original syntax and the
  242. /// rewritten expression.
  243. ///
  244. /// Note that the rewritten calls to \c ==, \c <=>, and \c \@ are typically
  245. /// \c CXXOperatorCallExprs, but could theoretically be \c BinaryOperators.
  246. class CXXRewrittenBinaryOperator : public Expr {
  247. friend class ASTStmtReader;
  248. /// The rewritten semantic form.
  249. Stmt *SemanticForm;
  250. public:
  251. CXXRewrittenBinaryOperator(Expr *SemanticForm, bool IsReversed)
  252. : Expr(CXXRewrittenBinaryOperatorClass, SemanticForm->getType(),
  253. SemanticForm->getValueKind(), SemanticForm->getObjectKind()),
  254. SemanticForm(SemanticForm) {
  255. CXXRewrittenBinaryOperatorBits.IsReversed = IsReversed;
  256. setDependence(computeDependence(this));
  257. }
  258. CXXRewrittenBinaryOperator(EmptyShell Empty)
  259. : Expr(CXXRewrittenBinaryOperatorClass, Empty), SemanticForm() {}
  260. /// Get an equivalent semantic form for this expression.
  261. Expr *getSemanticForm() { return cast<Expr>(SemanticForm); }
  262. const Expr *getSemanticForm() const { return cast<Expr>(SemanticForm); }
  263. struct DecomposedForm {
  264. /// The original opcode, prior to rewriting.
  265. BinaryOperatorKind Opcode;
  266. /// The original left-hand side.
  267. const Expr *LHS;
  268. /// The original right-hand side.
  269. const Expr *RHS;
  270. /// The inner \c == or \c <=> operator expression.
  271. const Expr *InnerBinOp;
  272. };
  273. /// Decompose this operator into its syntactic form.
  274. DecomposedForm getDecomposedForm() const LLVM_READONLY;
  275. /// Determine whether this expression was rewritten in reverse form.
  276. bool isReversed() const { return CXXRewrittenBinaryOperatorBits.IsReversed; }
  277. BinaryOperatorKind getOperator() const { return getDecomposedForm().Opcode; }
  278. BinaryOperatorKind getOpcode() const { return getOperator(); }
  279. static StringRef getOpcodeStr(BinaryOperatorKind Op) {
  280. return BinaryOperator::getOpcodeStr(Op);
  281. }
  282. StringRef getOpcodeStr() const {
  283. return BinaryOperator::getOpcodeStr(getOpcode());
  284. }
  285. bool isComparisonOp() const { return true; }
  286. bool isAssignmentOp() const { return false; }
  287. const Expr *getLHS() const { return getDecomposedForm().LHS; }
  288. const Expr *getRHS() const { return getDecomposedForm().RHS; }
  289. SourceLocation getOperatorLoc() const LLVM_READONLY {
  290. return getDecomposedForm().InnerBinOp->getExprLoc();
  291. }
  292. SourceLocation getExprLoc() const LLVM_READONLY { return getOperatorLoc(); }
  293. /// Compute the begin and end locations from the decomposed form.
  294. /// The locations of the semantic form are not reliable if this is
  295. /// a reversed expression.
  296. //@{
  297. SourceLocation getBeginLoc() const LLVM_READONLY {
  298. return getDecomposedForm().LHS->getBeginLoc();
  299. }
  300. SourceLocation getEndLoc() const LLVM_READONLY {
  301. return getDecomposedForm().RHS->getEndLoc();
  302. }
  303. SourceRange getSourceRange() const LLVM_READONLY {
  304. DecomposedForm DF = getDecomposedForm();
  305. return SourceRange(DF.LHS->getBeginLoc(), DF.RHS->getEndLoc());
  306. }
  307. //@}
  308. child_range children() {
  309. return child_range(&SemanticForm, &SemanticForm + 1);
  310. }
  311. static bool classof(const Stmt *T) {
  312. return T->getStmtClass() == CXXRewrittenBinaryOperatorClass;
  313. }
  314. };
  315. /// Abstract class common to all of the C++ "named"/"keyword" casts.
  316. ///
  317. /// This abstract class is inherited by all of the classes
  318. /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
  319. /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
  320. /// reinterpret_cast, CXXConstCastExpr for \c const_cast and
  321. /// CXXAddrspaceCastExpr for addrspace_cast (in OpenCL).
  322. class CXXNamedCastExpr : public ExplicitCastExpr {
  323. private:
  324. // the location of the casting op
  325. SourceLocation Loc;
  326. // the location of the right parenthesis
  327. SourceLocation RParenLoc;
  328. // range for '<' '>'
  329. SourceRange AngleBrackets;
  330. protected:
  331. friend class ASTStmtReader;
  332. CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, CastKind kind,
  333. Expr *op, unsigned PathSize, bool HasFPFeatures,
  334. TypeSourceInfo *writtenTy, SourceLocation l,
  335. SourceLocation RParenLoc, SourceRange AngleBrackets)
  336. : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, HasFPFeatures,
  337. writtenTy),
  338. Loc(l), RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
  339. explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize,
  340. bool HasFPFeatures)
  341. : ExplicitCastExpr(SC, Shell, PathSize, HasFPFeatures) {}
  342. public:
  343. const char *getCastName() const;
  344. /// Retrieve the location of the cast operator keyword, e.g.,
  345. /// \c static_cast.
  346. SourceLocation getOperatorLoc() const { return Loc; }
  347. /// Retrieve the location of the closing parenthesis.
  348. SourceLocation getRParenLoc() const { return RParenLoc; }
  349. SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
  350. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  351. SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
  352. static bool classof(const Stmt *T) {
  353. switch (T->getStmtClass()) {
  354. case CXXStaticCastExprClass:
  355. case CXXDynamicCastExprClass:
  356. case CXXReinterpretCastExprClass:
  357. case CXXConstCastExprClass:
  358. case CXXAddrspaceCastExprClass:
  359. return true;
  360. default:
  361. return false;
  362. }
  363. }
  364. };
  365. /// A C++ \c static_cast expression (C++ [expr.static.cast]).
  366. ///
  367. /// This expression node represents a C++ static cast, e.g.,
  368. /// \c static_cast<int>(1.0).
  369. class CXXStaticCastExpr final
  370. : public CXXNamedCastExpr,
  371. private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *,
  372. FPOptionsOverride> {
  373. CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
  374. unsigned pathSize, TypeSourceInfo *writtenTy,
  375. FPOptionsOverride FPO, SourceLocation l,
  376. SourceLocation RParenLoc, SourceRange AngleBrackets)
  377. : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
  378. FPO.requiresTrailingStorage(), writtenTy, l, RParenLoc,
  379. AngleBrackets) {
  380. if (hasStoredFPFeatures())
  381. *getTrailingFPFeatures() = FPO;
  382. }
  383. explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize,
  384. bool HasFPFeatures)
  385. : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize,
  386. HasFPFeatures) {}
  387. unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
  388. return path_size();
  389. }
  390. public:
  391. friend class CastExpr;
  392. friend TrailingObjects;
  393. static CXXStaticCastExpr *
  394. Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K,
  395. Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written,
  396. FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc,
  397. SourceRange AngleBrackets);
  398. static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
  399. unsigned PathSize, bool hasFPFeatures);
  400. static bool classof(const Stmt *T) {
  401. return T->getStmtClass() == CXXStaticCastExprClass;
  402. }
  403. };
  404. /// A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
  405. ///
  406. /// This expression node represents a dynamic cast, e.g.,
  407. /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
  408. /// check to determine how to perform the type conversion.
  409. class CXXDynamicCastExpr final
  410. : public CXXNamedCastExpr,
  411. private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
  412. CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, Expr *op,
  413. unsigned pathSize, TypeSourceInfo *writtenTy,
  414. SourceLocation l, SourceLocation RParenLoc,
  415. SourceRange AngleBrackets)
  416. : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
  417. /*HasFPFeatures*/ false, writtenTy, l, RParenLoc,
  418. AngleBrackets) {}
  419. explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
  420. : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize,
  421. /*HasFPFeatures*/ false) {}
  422. public:
  423. friend class CastExpr;
  424. friend TrailingObjects;
  425. static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
  426. ExprValueKind VK, CastKind Kind, Expr *Op,
  427. const CXXCastPath *Path,
  428. TypeSourceInfo *Written, SourceLocation L,
  429. SourceLocation RParenLoc,
  430. SourceRange AngleBrackets);
  431. static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
  432. unsigned pathSize);
  433. bool isAlwaysNull() const;
  434. static bool classof(const Stmt *T) {
  435. return T->getStmtClass() == CXXDynamicCastExprClass;
  436. }
  437. };
  438. /// A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
  439. ///
  440. /// This expression node represents a reinterpret cast, e.g.,
  441. /// @c reinterpret_cast<int>(VoidPtr).
  442. ///
  443. /// A reinterpret_cast provides a differently-typed view of a value but
  444. /// (in Clang, as in most C++ implementations) performs no actual work at
  445. /// run time.
  446. class CXXReinterpretCastExpr final
  447. : public CXXNamedCastExpr,
  448. private llvm::TrailingObjects<CXXReinterpretCastExpr,
  449. CXXBaseSpecifier *> {
  450. CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
  451. unsigned pathSize, TypeSourceInfo *writtenTy,
  452. SourceLocation l, SourceLocation RParenLoc,
  453. SourceRange AngleBrackets)
  454. : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
  455. pathSize, /*HasFPFeatures*/ false, writtenTy, l,
  456. RParenLoc, AngleBrackets) {}
  457. CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
  458. : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize,
  459. /*HasFPFeatures*/ false) {}
  460. public:
  461. friend class CastExpr;
  462. friend TrailingObjects;
  463. static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
  464. ExprValueKind VK, CastKind Kind,
  465. Expr *Op, const CXXCastPath *Path,
  466. TypeSourceInfo *WrittenTy, SourceLocation L,
  467. SourceLocation RParenLoc,
  468. SourceRange AngleBrackets);
  469. static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
  470. unsigned pathSize);
  471. static bool classof(const Stmt *T) {
  472. return T->getStmtClass() == CXXReinterpretCastExprClass;
  473. }
  474. };
  475. /// A C++ \c const_cast expression (C++ [expr.const.cast]).
  476. ///
  477. /// This expression node represents a const cast, e.g.,
  478. /// \c const_cast<char*>(PtrToConstChar).
  479. ///
  480. /// A const_cast can remove type qualifiers but does not change the underlying
  481. /// value.
  482. class CXXConstCastExpr final
  483. : public CXXNamedCastExpr,
  484. private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
  485. CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
  486. TypeSourceInfo *writtenTy, SourceLocation l,
  487. SourceLocation RParenLoc, SourceRange AngleBrackets)
  488. : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 0,
  489. /*HasFPFeatures*/ false, writtenTy, l, RParenLoc,
  490. AngleBrackets) {}
  491. explicit CXXConstCastExpr(EmptyShell Empty)
  492. : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0,
  493. /*HasFPFeatures*/ false) {}
  494. public:
  495. friend class CastExpr;
  496. friend TrailingObjects;
  497. static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
  498. ExprValueKind VK, Expr *Op,
  499. TypeSourceInfo *WrittenTy, SourceLocation L,
  500. SourceLocation RParenLoc,
  501. SourceRange AngleBrackets);
  502. static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
  503. static bool classof(const Stmt *T) {
  504. return T->getStmtClass() == CXXConstCastExprClass;
  505. }
  506. };
  507. /// A C++ addrspace_cast expression (currently only enabled for OpenCL).
  508. ///
  509. /// This expression node represents a cast between pointers to objects in
  510. /// different address spaces e.g.,
  511. /// \c addrspace_cast<global int*>(PtrToGenericInt).
  512. ///
  513. /// A addrspace_cast can cast address space type qualifiers but does not change
  514. /// the underlying value.
  515. class CXXAddrspaceCastExpr final
  516. : public CXXNamedCastExpr,
  517. private llvm::TrailingObjects<CXXAddrspaceCastExpr, CXXBaseSpecifier *> {
  518. CXXAddrspaceCastExpr(QualType ty, ExprValueKind VK, CastKind Kind, Expr *op,
  519. TypeSourceInfo *writtenTy, SourceLocation l,
  520. SourceLocation RParenLoc, SourceRange AngleBrackets)
  521. : CXXNamedCastExpr(CXXAddrspaceCastExprClass, ty, VK, Kind, op, 0,
  522. /*HasFPFeatures*/ false, writtenTy, l, RParenLoc,
  523. AngleBrackets) {}
  524. explicit CXXAddrspaceCastExpr(EmptyShell Empty)
  525. : CXXNamedCastExpr(CXXAddrspaceCastExprClass, Empty, 0,
  526. /*HasFPFeatures*/ false) {}
  527. public:
  528. friend class CastExpr;
  529. friend TrailingObjects;
  530. static CXXAddrspaceCastExpr *
  531. Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind,
  532. Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L,
  533. SourceLocation RParenLoc, SourceRange AngleBrackets);
  534. static CXXAddrspaceCastExpr *CreateEmpty(const ASTContext &Context);
  535. static bool classof(const Stmt *T) {
  536. return T->getStmtClass() == CXXAddrspaceCastExprClass;
  537. }
  538. };
  539. /// A call to a literal operator (C++11 [over.literal])
  540. /// written as a user-defined literal (C++11 [lit.ext]).
  541. ///
  542. /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
  543. /// is semantically equivalent to a normal call, this AST node provides better
  544. /// information about the syntactic representation of the literal.
  545. ///
  546. /// Since literal operators are never found by ADL and can only be declared at
  547. /// namespace scope, a user-defined literal is never dependent.
  548. class UserDefinedLiteral final : public CallExpr {
  549. friend class ASTStmtReader;
  550. friend class ASTStmtWriter;
  551. /// The location of a ud-suffix within the literal.
  552. SourceLocation UDSuffixLoc;
  553. // UserDefinedLiteral has some trailing objects belonging
  554. // to CallExpr. See CallExpr for the details.
  555. UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty,
  556. ExprValueKind VK, SourceLocation LitEndLoc,
  557. SourceLocation SuffixLoc, FPOptionsOverride FPFeatures);
  558. UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty);
  559. public:
  560. static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn,
  561. ArrayRef<Expr *> Args, QualType Ty,
  562. ExprValueKind VK, SourceLocation LitEndLoc,
  563. SourceLocation SuffixLoc,
  564. FPOptionsOverride FPFeatures);
  565. static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx,
  566. unsigned NumArgs, bool HasFPOptions,
  567. EmptyShell Empty);
  568. /// The kind of literal operator which is invoked.
  569. enum LiteralOperatorKind {
  570. /// Raw form: operator "" X (const char *)
  571. LOK_Raw,
  572. /// Raw form: operator "" X<cs...> ()
  573. LOK_Template,
  574. /// operator "" X (unsigned long long)
  575. LOK_Integer,
  576. /// operator "" X (long double)
  577. LOK_Floating,
  578. /// operator "" X (const CharT *, size_t)
  579. LOK_String,
  580. /// operator "" X (CharT)
  581. LOK_Character
  582. };
  583. /// Returns the kind of literal operator invocation
  584. /// which this expression represents.
  585. LiteralOperatorKind getLiteralOperatorKind() const;
  586. /// If this is not a raw user-defined literal, get the
  587. /// underlying cooked literal (representing the literal with the suffix
  588. /// removed).
  589. Expr *getCookedLiteral();
  590. const Expr *getCookedLiteral() const {
  591. return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
  592. }
  593. SourceLocation getBeginLoc() const {
  594. if (getLiteralOperatorKind() == LOK_Template)
  595. return getRParenLoc();
  596. return getArg(0)->getBeginLoc();
  597. }
  598. SourceLocation getEndLoc() const { return getRParenLoc(); }
  599. /// Returns the location of a ud-suffix in the expression.
  600. ///
  601. /// For a string literal, there may be multiple identical suffixes. This
  602. /// returns the first.
  603. SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
  604. /// Returns the ud-suffix specified for this literal.
  605. const IdentifierInfo *getUDSuffix() const;
  606. static bool classof(const Stmt *S) {
  607. return S->getStmtClass() == UserDefinedLiteralClass;
  608. }
  609. };
  610. /// A boolean literal, per ([C++ lex.bool] Boolean literals).
  611. class CXXBoolLiteralExpr : public Expr {
  612. public:
  613. CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc)
  614. : Expr(CXXBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) {
  615. CXXBoolLiteralExprBits.Value = Val;
  616. CXXBoolLiteralExprBits.Loc = Loc;
  617. setDependence(ExprDependence::None);
  618. }
  619. explicit CXXBoolLiteralExpr(EmptyShell Empty)
  620. : Expr(CXXBoolLiteralExprClass, Empty) {}
  621. bool getValue() const { return CXXBoolLiteralExprBits.Value; }
  622. void setValue(bool V) { CXXBoolLiteralExprBits.Value = V; }
  623. SourceLocation getBeginLoc() const { return getLocation(); }
  624. SourceLocation getEndLoc() const { return getLocation(); }
  625. SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; }
  626. void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; }
  627. static bool classof(const Stmt *T) {
  628. return T->getStmtClass() == CXXBoolLiteralExprClass;
  629. }
  630. // Iterators
  631. child_range children() {
  632. return child_range(child_iterator(), child_iterator());
  633. }
  634. const_child_range children() const {
  635. return const_child_range(const_child_iterator(), const_child_iterator());
  636. }
  637. };
  638. /// The null pointer literal (C++11 [lex.nullptr])
  639. ///
  640. /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
  641. class CXXNullPtrLiteralExpr : public Expr {
  642. public:
  643. CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc)
  644. : Expr(CXXNullPtrLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) {
  645. CXXNullPtrLiteralExprBits.Loc = Loc;
  646. setDependence(ExprDependence::None);
  647. }
  648. explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
  649. : Expr(CXXNullPtrLiteralExprClass, Empty) {}
  650. SourceLocation getBeginLoc() const { return getLocation(); }
  651. SourceLocation getEndLoc() const { return getLocation(); }
  652. SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; }
  653. void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; }
  654. static bool classof(const Stmt *T) {
  655. return T->getStmtClass() == CXXNullPtrLiteralExprClass;
  656. }
  657. child_range children() {
  658. return child_range(child_iterator(), child_iterator());
  659. }
  660. const_child_range children() const {
  661. return const_child_range(const_child_iterator(), const_child_iterator());
  662. }
  663. };
  664. /// Implicit construction of a std::initializer_list<T> object from an
  665. /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
  666. class CXXStdInitializerListExpr : public Expr {
  667. Stmt *SubExpr = nullptr;
  668. CXXStdInitializerListExpr(EmptyShell Empty)
  669. : Expr(CXXStdInitializerListExprClass, Empty) {}
  670. public:
  671. friend class ASTReader;
  672. friend class ASTStmtReader;
  673. CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
  674. : Expr(CXXStdInitializerListExprClass, Ty, VK_PRValue, OK_Ordinary),
  675. SubExpr(SubExpr) {
  676. setDependence(computeDependence(this));
  677. }
  678. Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
  679. const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
  680. SourceLocation getBeginLoc() const LLVM_READONLY {
  681. return SubExpr->getBeginLoc();
  682. }
  683. SourceLocation getEndLoc() const LLVM_READONLY {
  684. return SubExpr->getEndLoc();
  685. }
  686. /// Retrieve the source range of the expression.
  687. SourceRange getSourceRange() const LLVM_READONLY {
  688. return SubExpr->getSourceRange();
  689. }
  690. static bool classof(const Stmt *S) {
  691. return S->getStmtClass() == CXXStdInitializerListExprClass;
  692. }
  693. child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
  694. const_child_range children() const {
  695. return const_child_range(&SubExpr, &SubExpr + 1);
  696. }
  697. };
  698. /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
  699. /// the \c type_info that corresponds to the supplied type, or the (possibly
  700. /// dynamic) type of the supplied expression.
  701. ///
  702. /// This represents code like \c typeid(int) or \c typeid(*objPtr)
  703. class CXXTypeidExpr : public Expr {
  704. friend class ASTStmtReader;
  705. private:
  706. llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
  707. SourceRange Range;
  708. public:
  709. CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
  710. : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand),
  711. Range(R) {
  712. setDependence(computeDependence(this));
  713. }
  714. CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
  715. : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand),
  716. Range(R) {
  717. setDependence(computeDependence(this));
  718. }
  719. CXXTypeidExpr(EmptyShell Empty, bool isExpr)
  720. : Expr(CXXTypeidExprClass, Empty) {
  721. if (isExpr)
  722. Operand = (Expr*)nullptr;
  723. else
  724. Operand = (TypeSourceInfo*)nullptr;
  725. }
  726. /// Determine whether this typeid has a type operand which is potentially
  727. /// evaluated, per C++11 [expr.typeid]p3.
  728. bool isPotentiallyEvaluated() const;
  729. /// Best-effort check if the expression operand refers to a most derived
  730. /// object. This is not a strong guarantee.
  731. bool isMostDerived(ASTContext &Context) const;
  732. bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
  733. /// Retrieves the type operand of this typeid() expression after
  734. /// various required adjustments (removing reference types, cv-qualifiers).
  735. QualType getTypeOperand(ASTContext &Context) const;
  736. /// Retrieve source information for the type operand.
  737. TypeSourceInfo *getTypeOperandSourceInfo() const {
  738. assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
  739. return Operand.get<TypeSourceInfo *>();
  740. }
  741. Expr *getExprOperand() const {
  742. assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
  743. return static_cast<Expr*>(Operand.get<Stmt *>());
  744. }
  745. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  746. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  747. SourceRange getSourceRange() const LLVM_READONLY { return Range; }
  748. void setSourceRange(SourceRange R) { Range = R; }
  749. static bool classof(const Stmt *T) {
  750. return T->getStmtClass() == CXXTypeidExprClass;
  751. }
  752. // Iterators
  753. child_range children() {
  754. if (isTypeOperand())
  755. return child_range(child_iterator(), child_iterator());
  756. auto **begin = reinterpret_cast<Stmt **>(&Operand);
  757. return child_range(begin, begin + 1);
  758. }
  759. const_child_range children() const {
  760. if (isTypeOperand())
  761. return const_child_range(const_child_iterator(), const_child_iterator());
  762. auto **begin =
  763. reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand);
  764. return const_child_range(begin, begin + 1);
  765. }
  766. };
  767. /// A member reference to an MSPropertyDecl.
  768. ///
  769. /// This expression always has pseudo-object type, and therefore it is
  770. /// typically not encountered in a fully-typechecked expression except
  771. /// within the syntactic form of a PseudoObjectExpr.
  772. class MSPropertyRefExpr : public Expr {
  773. Expr *BaseExpr;
  774. MSPropertyDecl *TheDecl;
  775. SourceLocation MemberLoc;
  776. bool IsArrow;
  777. NestedNameSpecifierLoc QualifierLoc;
  778. public:
  779. friend class ASTStmtReader;
  780. MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
  781. QualType ty, ExprValueKind VK,
  782. NestedNameSpecifierLoc qualifierLoc, SourceLocation nameLoc)
  783. : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary), BaseExpr(baseExpr),
  784. TheDecl(decl), MemberLoc(nameLoc), IsArrow(isArrow),
  785. QualifierLoc(qualifierLoc) {
  786. setDependence(computeDependence(this));
  787. }
  788. MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
  789. SourceRange getSourceRange() const LLVM_READONLY {
  790. return SourceRange(getBeginLoc(), getEndLoc());
  791. }
  792. bool isImplicitAccess() const {
  793. return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
  794. }
  795. SourceLocation getBeginLoc() const {
  796. if (!isImplicitAccess())
  797. return BaseExpr->getBeginLoc();
  798. else if (QualifierLoc)
  799. return QualifierLoc.getBeginLoc();
  800. else
  801. return MemberLoc;
  802. }
  803. SourceLocation getEndLoc() const { return getMemberLoc(); }
  804. child_range children() {
  805. return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
  806. }
  807. const_child_range children() const {
  808. auto Children = const_cast<MSPropertyRefExpr *>(this)->children();
  809. return const_child_range(Children.begin(), Children.end());
  810. }
  811. static bool classof(const Stmt *T) {
  812. return T->getStmtClass() == MSPropertyRefExprClass;
  813. }
  814. Expr *getBaseExpr() const { return BaseExpr; }
  815. MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
  816. bool isArrow() const { return IsArrow; }
  817. SourceLocation getMemberLoc() const { return MemberLoc; }
  818. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  819. };
  820. /// MS property subscript expression.
  821. /// MSVC supports 'property' attribute and allows to apply it to the
  822. /// declaration of an empty array in a class or structure definition.
  823. /// For example:
  824. /// \code
  825. /// __declspec(property(get=GetX, put=PutX)) int x[];
  826. /// \endcode
  827. /// The above statement indicates that x[] can be used with one or more array
  828. /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
  829. /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
  830. /// This is a syntactic pseudo-object expression.
  831. class MSPropertySubscriptExpr : public Expr {
  832. friend class ASTStmtReader;
  833. enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
  834. Stmt *SubExprs[NUM_SUBEXPRS];
  835. SourceLocation RBracketLoc;
  836. void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
  837. void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
  838. public:
  839. MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
  840. ExprObjectKind OK, SourceLocation RBracketLoc)
  841. : Expr(MSPropertySubscriptExprClass, Ty, VK, OK),
  842. RBracketLoc(RBracketLoc) {
  843. SubExprs[BASE_EXPR] = Base;
  844. SubExprs[IDX_EXPR] = Idx;
  845. setDependence(computeDependence(this));
  846. }
  847. /// Create an empty array subscript expression.
  848. explicit MSPropertySubscriptExpr(EmptyShell Shell)
  849. : Expr(MSPropertySubscriptExprClass, Shell) {}
  850. Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
  851. const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
  852. Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
  853. const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
  854. SourceLocation getBeginLoc() const LLVM_READONLY {
  855. return getBase()->getBeginLoc();
  856. }
  857. SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
  858. SourceLocation getRBracketLoc() const { return RBracketLoc; }
  859. void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
  860. SourceLocation getExprLoc() const LLVM_READONLY {
  861. return getBase()->getExprLoc();
  862. }
  863. static bool classof(const Stmt *T) {
  864. return T->getStmtClass() == MSPropertySubscriptExprClass;
  865. }
  866. // Iterators
  867. child_range children() {
  868. return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
  869. }
  870. const_child_range children() const {
  871. return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
  872. }
  873. };
  874. /// A Microsoft C++ @c __uuidof expression, which gets
  875. /// the _GUID that corresponds to the supplied type or expression.
  876. ///
  877. /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
  878. class CXXUuidofExpr : public Expr {
  879. friend class ASTStmtReader;
  880. private:
  881. llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
  882. MSGuidDecl *Guid;
  883. SourceRange Range;
  884. public:
  885. CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, MSGuidDecl *Guid,
  886. SourceRange R)
  887. : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand),
  888. Guid(Guid), Range(R) {
  889. setDependence(computeDependence(this));
  890. }
  891. CXXUuidofExpr(QualType Ty, Expr *Operand, MSGuidDecl *Guid, SourceRange R)
  892. : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand),
  893. Guid(Guid), Range(R) {
  894. setDependence(computeDependence(this));
  895. }
  896. CXXUuidofExpr(EmptyShell Empty, bool isExpr)
  897. : Expr(CXXUuidofExprClass, Empty) {
  898. if (isExpr)
  899. Operand = (Expr*)nullptr;
  900. else
  901. Operand = (TypeSourceInfo*)nullptr;
  902. }
  903. bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
  904. /// Retrieves the type operand of this __uuidof() expression after
  905. /// various required adjustments (removing reference types, cv-qualifiers).
  906. QualType getTypeOperand(ASTContext &Context) const;
  907. /// Retrieve source information for the type operand.
  908. TypeSourceInfo *getTypeOperandSourceInfo() const {
  909. assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
  910. return Operand.get<TypeSourceInfo *>();
  911. }
  912. Expr *getExprOperand() const {
  913. assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
  914. return static_cast<Expr*>(Operand.get<Stmt *>());
  915. }
  916. MSGuidDecl *getGuidDecl() const { return Guid; }
  917. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  918. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  919. SourceRange getSourceRange() const LLVM_READONLY { return Range; }
  920. void setSourceRange(SourceRange R) { Range = R; }
  921. static bool classof(const Stmt *T) {
  922. return T->getStmtClass() == CXXUuidofExprClass;
  923. }
  924. // Iterators
  925. child_range children() {
  926. if (isTypeOperand())
  927. return child_range(child_iterator(), child_iterator());
  928. auto **begin = reinterpret_cast<Stmt **>(&Operand);
  929. return child_range(begin, begin + 1);
  930. }
  931. const_child_range children() const {
  932. if (isTypeOperand())
  933. return const_child_range(const_child_iterator(), const_child_iterator());
  934. auto **begin =
  935. reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand);
  936. return const_child_range(begin, begin + 1);
  937. }
  938. };
  939. /// Represents the \c this expression in C++.
  940. ///
  941. /// This is a pointer to the object on which the current member function is
  942. /// executing (C++ [expr.prim]p3). Example:
  943. ///
  944. /// \code
  945. /// class Foo {
  946. /// public:
  947. /// void bar();
  948. /// void test() { this->bar(); }
  949. /// };
  950. /// \endcode
  951. class CXXThisExpr : public Expr {
  952. public:
  953. CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit)
  954. : Expr(CXXThisExprClass, Ty, VK_PRValue, OK_Ordinary) {
  955. CXXThisExprBits.IsImplicit = IsImplicit;
  956. CXXThisExprBits.Loc = L;
  957. setDependence(computeDependence(this));
  958. }
  959. CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
  960. SourceLocation getLocation() const { return CXXThisExprBits.Loc; }
  961. void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; }
  962. SourceLocation getBeginLoc() const { return getLocation(); }
  963. SourceLocation getEndLoc() const { return getLocation(); }
  964. bool isImplicit() const { return CXXThisExprBits.IsImplicit; }
  965. void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; }
  966. static bool classof(const Stmt *T) {
  967. return T->getStmtClass() == CXXThisExprClass;
  968. }
  969. // Iterators
  970. child_range children() {
  971. return child_range(child_iterator(), child_iterator());
  972. }
  973. const_child_range children() const {
  974. return const_child_range(const_child_iterator(), const_child_iterator());
  975. }
  976. };
  977. /// A C++ throw-expression (C++ [except.throw]).
  978. ///
  979. /// This handles 'throw' (for re-throwing the current exception) and
  980. /// 'throw' assignment-expression. When assignment-expression isn't
  981. /// present, Op will be null.
  982. class CXXThrowExpr : public Expr {
  983. friend class ASTStmtReader;
  984. /// The optional expression in the throw statement.
  985. Stmt *Operand;
  986. public:
  987. // \p Ty is the void type which is used as the result type of the
  988. // expression. The \p Loc is the location of the throw keyword.
  989. // \p Operand is the expression in the throw statement, and can be
  990. // null if not present.
  991. CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc,
  992. bool IsThrownVariableInScope)
  993. : Expr(CXXThrowExprClass, Ty, VK_PRValue, OK_Ordinary), Operand(Operand) {
  994. CXXThrowExprBits.ThrowLoc = Loc;
  995. CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope;
  996. setDependence(computeDependence(this));
  997. }
  998. CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
  999. const Expr *getSubExpr() const { return cast_or_null<Expr>(Operand); }
  1000. Expr *getSubExpr() { return cast_or_null<Expr>(Operand); }
  1001. SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; }
  1002. /// Determines whether the variable thrown by this expression (if any!)
  1003. /// is within the innermost try block.
  1004. ///
  1005. /// This information is required to determine whether the NRVO can apply to
  1006. /// this variable.
  1007. bool isThrownVariableInScope() const {
  1008. return CXXThrowExprBits.IsThrownVariableInScope;
  1009. }
  1010. SourceLocation getBeginLoc() const { return getThrowLoc(); }
  1011. SourceLocation getEndLoc() const LLVM_READONLY {
  1012. if (!getSubExpr())
  1013. return getThrowLoc();
  1014. return getSubExpr()->getEndLoc();
  1015. }
  1016. static bool classof(const Stmt *T) {
  1017. return T->getStmtClass() == CXXThrowExprClass;
  1018. }
  1019. // Iterators
  1020. child_range children() {
  1021. return child_range(&Operand, Operand ? &Operand + 1 : &Operand);
  1022. }
  1023. const_child_range children() const {
  1024. return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand);
  1025. }
  1026. };
  1027. /// A default argument (C++ [dcl.fct.default]).
  1028. ///
  1029. /// This wraps up a function call argument that was created from the
  1030. /// corresponding parameter's default argument, when the call did not
  1031. /// explicitly supply arguments for all of the parameters.
  1032. class CXXDefaultArgExpr final : public Expr {
  1033. friend class ASTStmtReader;
  1034. /// The parameter whose default is being used.
  1035. ParmVarDecl *Param;
  1036. /// The context where the default argument expression was used.
  1037. DeclContext *UsedContext;
  1038. CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
  1039. DeclContext *UsedContext)
  1040. : Expr(SC,
  1041. Param->hasUnparsedDefaultArg()
  1042. ? Param->getType().getNonReferenceType()
  1043. : Param->getDefaultArg()->getType(),
  1044. Param->getDefaultArg()->getValueKind(),
  1045. Param->getDefaultArg()->getObjectKind()),
  1046. Param(Param), UsedContext(UsedContext) {
  1047. CXXDefaultArgExprBits.Loc = Loc;
  1048. setDependence(computeDependence(this));
  1049. }
  1050. public:
  1051. CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
  1052. // \p Param is the parameter whose default argument is used by this
  1053. // expression.
  1054. static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
  1055. ParmVarDecl *Param,
  1056. DeclContext *UsedContext) {
  1057. return new (C)
  1058. CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext);
  1059. }
  1060. // Retrieve the parameter that the argument was created from.
  1061. const ParmVarDecl *getParam() const { return Param; }
  1062. ParmVarDecl *getParam() { return Param; }
  1063. // Retrieve the actual argument to the function call.
  1064. const Expr *getExpr() const { return getParam()->getDefaultArg(); }
  1065. Expr *getExpr() { return getParam()->getDefaultArg(); }
  1066. const DeclContext *getUsedContext() const { return UsedContext; }
  1067. DeclContext *getUsedContext() { return UsedContext; }
  1068. /// Retrieve the location where this default argument was actually used.
  1069. SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; }
  1070. /// Default argument expressions have no representation in the
  1071. /// source, so they have an empty source range.
  1072. SourceLocation getBeginLoc() const { return SourceLocation(); }
  1073. SourceLocation getEndLoc() const { return SourceLocation(); }
  1074. SourceLocation getExprLoc() const { return getUsedLocation(); }
  1075. static bool classof(const Stmt *T) {
  1076. return T->getStmtClass() == CXXDefaultArgExprClass;
  1077. }
  1078. // Iterators
  1079. child_range children() {
  1080. return child_range(child_iterator(), child_iterator());
  1081. }
  1082. const_child_range children() const {
  1083. return const_child_range(const_child_iterator(), const_child_iterator());
  1084. }
  1085. };
  1086. /// A use of a default initializer in a constructor or in aggregate
  1087. /// initialization.
  1088. ///
  1089. /// This wraps a use of a C++ default initializer (technically,
  1090. /// a brace-or-equal-initializer for a non-static data member) when it
  1091. /// is implicitly used in a mem-initializer-list in a constructor
  1092. /// (C++11 [class.base.init]p8) or in aggregate initialization
  1093. /// (C++1y [dcl.init.aggr]p7).
  1094. class CXXDefaultInitExpr : public Expr {
  1095. friend class ASTReader;
  1096. friend class ASTStmtReader;
  1097. /// The field whose default is being used.
  1098. FieldDecl *Field;
  1099. /// The context where the default initializer expression was used.
  1100. DeclContext *UsedContext;
  1101. CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
  1102. FieldDecl *Field, QualType Ty, DeclContext *UsedContext);
  1103. CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
  1104. public:
  1105. /// \p Field is the non-static data member whose default initializer is used
  1106. /// by this expression.
  1107. static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc,
  1108. FieldDecl *Field, DeclContext *UsedContext) {
  1109. return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext);
  1110. }
  1111. /// Get the field whose initializer will be used.
  1112. FieldDecl *getField() { return Field; }
  1113. const FieldDecl *getField() const { return Field; }
  1114. /// Get the initialization expression that will be used.
  1115. const Expr *getExpr() const {
  1116. assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
  1117. return Field->getInClassInitializer();
  1118. }
  1119. Expr *getExpr() {
  1120. assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
  1121. return Field->getInClassInitializer();
  1122. }
  1123. const DeclContext *getUsedContext() const { return UsedContext; }
  1124. DeclContext *getUsedContext() { return UsedContext; }
  1125. /// Retrieve the location where this default initializer expression was
  1126. /// actually used.
  1127. SourceLocation getUsedLocation() const { return getBeginLoc(); }
  1128. SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; }
  1129. SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; }
  1130. static bool classof(const Stmt *T) {
  1131. return T->getStmtClass() == CXXDefaultInitExprClass;
  1132. }
  1133. // Iterators
  1134. child_range children() {
  1135. return child_range(child_iterator(), child_iterator());
  1136. }
  1137. const_child_range children() const {
  1138. return const_child_range(const_child_iterator(), const_child_iterator());
  1139. }
  1140. };
  1141. /// Represents a C++ temporary.
  1142. class CXXTemporary {
  1143. /// The destructor that needs to be called.
  1144. const CXXDestructorDecl *Destructor;
  1145. explicit CXXTemporary(const CXXDestructorDecl *destructor)
  1146. : Destructor(destructor) {}
  1147. public:
  1148. static CXXTemporary *Create(const ASTContext &C,
  1149. const CXXDestructorDecl *Destructor);
  1150. const CXXDestructorDecl *getDestructor() const { return Destructor; }
  1151. void setDestructor(const CXXDestructorDecl *Dtor) {
  1152. Destructor = Dtor;
  1153. }
  1154. };
  1155. /// Represents binding an expression to a temporary.
  1156. ///
  1157. /// This ensures the destructor is called for the temporary. It should only be
  1158. /// needed for non-POD, non-trivially destructable class types. For example:
  1159. ///
  1160. /// \code
  1161. /// struct S {
  1162. /// S() { } // User defined constructor makes S non-POD.
  1163. /// ~S() { } // User defined destructor makes it non-trivial.
  1164. /// };
  1165. /// void test() {
  1166. /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
  1167. /// }
  1168. /// \endcode
  1169. class CXXBindTemporaryExpr : public Expr {
  1170. CXXTemporary *Temp = nullptr;
  1171. Stmt *SubExpr = nullptr;
  1172. CXXBindTemporaryExpr(CXXTemporary *temp, Expr *SubExpr)
  1173. : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), VK_PRValue,
  1174. OK_Ordinary),
  1175. Temp(temp), SubExpr(SubExpr) {
  1176. setDependence(computeDependence(this));
  1177. }
  1178. public:
  1179. CXXBindTemporaryExpr(EmptyShell Empty)
  1180. : Expr(CXXBindTemporaryExprClass, Empty) {}
  1181. static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
  1182. Expr* SubExpr);
  1183. CXXTemporary *getTemporary() { return Temp; }
  1184. const CXXTemporary *getTemporary() const { return Temp; }
  1185. void setTemporary(CXXTemporary *T) { Temp = T; }
  1186. const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
  1187. Expr *getSubExpr() { return cast<Expr>(SubExpr); }
  1188. void setSubExpr(Expr *E) { SubExpr = E; }
  1189. SourceLocation getBeginLoc() const LLVM_READONLY {
  1190. return SubExpr->getBeginLoc();
  1191. }
  1192. SourceLocation getEndLoc() const LLVM_READONLY {
  1193. return SubExpr->getEndLoc();
  1194. }
  1195. // Implement isa/cast/dyncast/etc.
  1196. static bool classof(const Stmt *T) {
  1197. return T->getStmtClass() == CXXBindTemporaryExprClass;
  1198. }
  1199. // Iterators
  1200. child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
  1201. const_child_range children() const {
  1202. return const_child_range(&SubExpr, &SubExpr + 1);
  1203. }
  1204. };
  1205. /// Represents a call to a C++ constructor.
  1206. class CXXConstructExpr : public Expr {
  1207. friend class ASTStmtReader;
  1208. public:
  1209. enum ConstructionKind {
  1210. CK_Complete,
  1211. CK_NonVirtualBase,
  1212. CK_VirtualBase,
  1213. CK_Delegating
  1214. };
  1215. private:
  1216. /// A pointer to the constructor which will be ultimately called.
  1217. CXXConstructorDecl *Constructor;
  1218. SourceRange ParenOrBraceRange;
  1219. /// The number of arguments.
  1220. unsigned NumArgs;
  1221. // We would like to stash the arguments of the constructor call after
  1222. // CXXConstructExpr. However CXXConstructExpr is used as a base class of
  1223. // CXXTemporaryObjectExpr which makes the use of llvm::TrailingObjects
  1224. // impossible.
  1225. //
  1226. // Instead we manually stash the trailing object after the full object
  1227. // containing CXXConstructExpr (that is either CXXConstructExpr or
  1228. // CXXTemporaryObjectExpr).
  1229. //
  1230. // The trailing objects are:
  1231. //
  1232. // * An array of getNumArgs() "Stmt *" for the arguments of the
  1233. // constructor call.
  1234. /// Return a pointer to the start of the trailing arguments.
  1235. /// Defined just after CXXTemporaryObjectExpr.
  1236. inline Stmt **getTrailingArgs();
  1237. const Stmt *const *getTrailingArgs() const {
  1238. return const_cast<CXXConstructExpr *>(this)->getTrailingArgs();
  1239. }
  1240. protected:
  1241. /// Build a C++ construction expression.
  1242. CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc,
  1243. CXXConstructorDecl *Ctor, bool Elidable,
  1244. ArrayRef<Expr *> Args, bool HadMultipleCandidates,
  1245. bool ListInitialization, bool StdInitListInitialization,
  1246. bool ZeroInitialization, ConstructionKind ConstructKind,
  1247. SourceRange ParenOrBraceRange);
  1248. /// Build an empty C++ construction expression.
  1249. CXXConstructExpr(StmtClass SC, EmptyShell Empty, unsigned NumArgs);
  1250. /// Return the size in bytes of the trailing objects. Used by
  1251. /// CXXTemporaryObjectExpr to allocate the right amount of storage.
  1252. static unsigned sizeOfTrailingObjects(unsigned NumArgs) {
  1253. return NumArgs * sizeof(Stmt *);
  1254. }
  1255. public:
  1256. /// Create a C++ construction expression.
  1257. static CXXConstructExpr *
  1258. Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
  1259. CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
  1260. bool HadMultipleCandidates, bool ListInitialization,
  1261. bool StdInitListInitialization, bool ZeroInitialization,
  1262. ConstructionKind ConstructKind, SourceRange ParenOrBraceRange);
  1263. /// Create an empty C++ construction expression.
  1264. static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs);
  1265. /// Get the constructor that this expression will (ultimately) call.
  1266. CXXConstructorDecl *getConstructor() const { return Constructor; }
  1267. SourceLocation getLocation() const { return CXXConstructExprBits.Loc; }
  1268. void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; }
  1269. /// Whether this construction is elidable.
  1270. bool isElidable() const { return CXXConstructExprBits.Elidable; }
  1271. void setElidable(bool E) { CXXConstructExprBits.Elidable = E; }
  1272. /// Whether the referred constructor was resolved from
  1273. /// an overloaded set having size greater than 1.
  1274. bool hadMultipleCandidates() const {
  1275. return CXXConstructExprBits.HadMultipleCandidates;
  1276. }
  1277. void setHadMultipleCandidates(bool V) {
  1278. CXXConstructExprBits.HadMultipleCandidates = V;
  1279. }
  1280. /// Whether this constructor call was written as list-initialization.
  1281. bool isListInitialization() const {
  1282. return CXXConstructExprBits.ListInitialization;
  1283. }
  1284. void setListInitialization(bool V) {
  1285. CXXConstructExprBits.ListInitialization = V;
  1286. }
  1287. /// Whether this constructor call was written as list-initialization,
  1288. /// but was interpreted as forming a std::initializer_list<T> from the list
  1289. /// and passing that as a single constructor argument.
  1290. /// See C++11 [over.match.list]p1 bullet 1.
  1291. bool isStdInitListInitialization() const {
  1292. return CXXConstructExprBits.StdInitListInitialization;
  1293. }
  1294. void setStdInitListInitialization(bool V) {
  1295. CXXConstructExprBits.StdInitListInitialization = V;
  1296. }
  1297. /// Whether this construction first requires
  1298. /// zero-initialization before the initializer is called.
  1299. bool requiresZeroInitialization() const {
  1300. return CXXConstructExprBits.ZeroInitialization;
  1301. }
  1302. void setRequiresZeroInitialization(bool ZeroInit) {
  1303. CXXConstructExprBits.ZeroInitialization = ZeroInit;
  1304. }
  1305. /// Determine whether this constructor is actually constructing
  1306. /// a base class (rather than a complete object).
  1307. ConstructionKind getConstructionKind() const {
  1308. return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind);
  1309. }
  1310. void setConstructionKind(ConstructionKind CK) {
  1311. CXXConstructExprBits.ConstructionKind = CK;
  1312. }
  1313. using arg_iterator = ExprIterator;
  1314. using const_arg_iterator = ConstExprIterator;
  1315. using arg_range = llvm::iterator_range<arg_iterator>;
  1316. using const_arg_range = llvm::iterator_range<const_arg_iterator>;
  1317. arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
  1318. const_arg_range arguments() const {
  1319. return const_arg_range(arg_begin(), arg_end());
  1320. }
  1321. arg_iterator arg_begin() { return getTrailingArgs(); }
  1322. arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
  1323. const_arg_iterator arg_begin() const { return getTrailingArgs(); }
  1324. const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
  1325. Expr **getArgs() { return reinterpret_cast<Expr **>(getTrailingArgs()); }
  1326. const Expr *const *getArgs() const {
  1327. return reinterpret_cast<const Expr *const *>(getTrailingArgs());
  1328. }
  1329. /// Return the number of arguments to the constructor call.
  1330. unsigned getNumArgs() const { return NumArgs; }
  1331. /// Return the specified argument.
  1332. Expr *getArg(unsigned Arg) {
  1333. assert(Arg < getNumArgs() && "Arg access out of range!");
  1334. return getArgs()[Arg];
  1335. }
  1336. const Expr *getArg(unsigned Arg) const {
  1337. assert(Arg < getNumArgs() && "Arg access out of range!");
  1338. return getArgs()[Arg];
  1339. }
  1340. /// Set the specified argument.
  1341. void setArg(unsigned Arg, Expr *ArgExpr) {
  1342. assert(Arg < getNumArgs() && "Arg access out of range!");
  1343. getArgs()[Arg] = ArgExpr;
  1344. }
  1345. SourceLocation getBeginLoc() const LLVM_READONLY;
  1346. SourceLocation getEndLoc() const LLVM_READONLY;
  1347. SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
  1348. void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
  1349. static bool classof(const Stmt *T) {
  1350. return T->getStmtClass() == CXXConstructExprClass ||
  1351. T->getStmtClass() == CXXTemporaryObjectExprClass;
  1352. }
  1353. // Iterators
  1354. child_range children() {
  1355. return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs());
  1356. }
  1357. const_child_range children() const {
  1358. auto Children = const_cast<CXXConstructExpr *>(this)->children();
  1359. return const_child_range(Children.begin(), Children.end());
  1360. }
  1361. };
  1362. /// Represents a call to an inherited base class constructor from an
  1363. /// inheriting constructor. This call implicitly forwards the arguments from
  1364. /// the enclosing context (an inheriting constructor) to the specified inherited
  1365. /// base class constructor.
  1366. class CXXInheritedCtorInitExpr : public Expr {
  1367. private:
  1368. CXXConstructorDecl *Constructor = nullptr;
  1369. /// The location of the using declaration.
  1370. SourceLocation Loc;
  1371. /// Whether this is the construction of a virtual base.
  1372. unsigned ConstructsVirtualBase : 1;
  1373. /// Whether the constructor is inherited from a virtual base class of the
  1374. /// class that we construct.
  1375. unsigned InheritedFromVirtualBase : 1;
  1376. public:
  1377. friend class ASTStmtReader;
  1378. /// Construct a C++ inheriting construction expression.
  1379. CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
  1380. CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
  1381. bool InheritedFromVirtualBase)
  1382. : Expr(CXXInheritedCtorInitExprClass, T, VK_PRValue, OK_Ordinary),
  1383. Constructor(Ctor), Loc(Loc),
  1384. ConstructsVirtualBase(ConstructsVirtualBase),
  1385. InheritedFromVirtualBase(InheritedFromVirtualBase) {
  1386. assert(!T->isDependentType());
  1387. setDependence(ExprDependence::None);
  1388. }
  1389. /// Construct an empty C++ inheriting construction expression.
  1390. explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
  1391. : Expr(CXXInheritedCtorInitExprClass, Empty),
  1392. ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
  1393. /// Get the constructor that this expression will call.
  1394. CXXConstructorDecl *getConstructor() const { return Constructor; }
  1395. /// Determine whether this constructor is actually constructing
  1396. /// a base class (rather than a complete object).
  1397. bool constructsVBase() const { return ConstructsVirtualBase; }
  1398. CXXConstructExpr::ConstructionKind getConstructionKind() const {
  1399. return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
  1400. : CXXConstructExpr::CK_NonVirtualBase;
  1401. }
  1402. /// Determine whether the inherited constructor is inherited from a
  1403. /// virtual base of the object we construct. If so, we are not responsible
  1404. /// for calling the inherited constructor (the complete object constructor
  1405. /// does that), and so we don't need to pass any arguments.
  1406. bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
  1407. SourceLocation getLocation() const LLVM_READONLY { return Loc; }
  1408. SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
  1409. SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
  1410. static bool classof(const Stmt *T) {
  1411. return T->getStmtClass() == CXXInheritedCtorInitExprClass;
  1412. }
  1413. child_range children() {
  1414. return child_range(child_iterator(), child_iterator());
  1415. }
  1416. const_child_range children() const {
  1417. return const_child_range(const_child_iterator(), const_child_iterator());
  1418. }
  1419. };
  1420. /// Represents an explicit C++ type conversion that uses "functional"
  1421. /// notation (C++ [expr.type.conv]).
  1422. ///
  1423. /// Example:
  1424. /// \code
  1425. /// x = int(0.5);
  1426. /// \endcode
  1427. class CXXFunctionalCastExpr final
  1428. : public ExplicitCastExpr,
  1429. private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *,
  1430. FPOptionsOverride> {
  1431. SourceLocation LParenLoc;
  1432. SourceLocation RParenLoc;
  1433. CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
  1434. TypeSourceInfo *writtenTy, CastKind kind,
  1435. Expr *castExpr, unsigned pathSize,
  1436. FPOptionsOverride FPO, SourceLocation lParenLoc,
  1437. SourceLocation rParenLoc)
  1438. : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, castExpr,
  1439. pathSize, FPO.requiresTrailingStorage(), writtenTy),
  1440. LParenLoc(lParenLoc), RParenLoc(rParenLoc) {
  1441. if (hasStoredFPFeatures())
  1442. *getTrailingFPFeatures() = FPO;
  1443. }
  1444. explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize,
  1445. bool HasFPFeatures)
  1446. : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize,
  1447. HasFPFeatures) {}
  1448. unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
  1449. return path_size();
  1450. }
  1451. public:
  1452. friend class CastExpr;
  1453. friend TrailingObjects;
  1454. static CXXFunctionalCastExpr *
  1455. Create(const ASTContext &Context, QualType T, ExprValueKind VK,
  1456. TypeSourceInfo *Written, CastKind Kind, Expr *Op,
  1457. const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc,
  1458. SourceLocation RPLoc);
  1459. static CXXFunctionalCastExpr *
  1460. CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures);
  1461. SourceLocation getLParenLoc() const { return LParenLoc; }
  1462. void setLParenLoc(SourceLocation L) { LParenLoc = L; }
  1463. SourceLocation getRParenLoc() const { return RParenLoc; }
  1464. void setRParenLoc(SourceLocation L) { RParenLoc = L; }
  1465. /// Determine whether this expression models list-initialization.
  1466. bool isListInitialization() const { return LParenLoc.isInvalid(); }
  1467. SourceLocation getBeginLoc() const LLVM_READONLY;
  1468. SourceLocation getEndLoc() const LLVM_READONLY;
  1469. static bool classof(const Stmt *T) {
  1470. return T->getStmtClass() == CXXFunctionalCastExprClass;
  1471. }
  1472. };
  1473. /// Represents a C++ functional cast expression that builds a
  1474. /// temporary object.
  1475. ///
  1476. /// This expression type represents a C++ "functional" cast
  1477. /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
  1478. /// constructor to build a temporary object. With N == 1 arguments the
  1479. /// functional cast expression will be represented by CXXFunctionalCastExpr.
  1480. /// Example:
  1481. /// \code
  1482. /// struct X { X(int, float); }
  1483. ///
  1484. /// X create_X() {
  1485. /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
  1486. /// };
  1487. /// \endcode
  1488. class CXXTemporaryObjectExpr final : public CXXConstructExpr {
  1489. friend class ASTStmtReader;
  1490. // CXXTemporaryObjectExpr has some trailing objects belonging
  1491. // to CXXConstructExpr. See the comment inside CXXConstructExpr
  1492. // for more details.
  1493. TypeSourceInfo *TSI;
  1494. CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType Ty,
  1495. TypeSourceInfo *TSI, ArrayRef<Expr *> Args,
  1496. SourceRange ParenOrBraceRange,
  1497. bool HadMultipleCandidates, bool ListInitialization,
  1498. bool StdInitListInitialization,
  1499. bool ZeroInitialization);
  1500. CXXTemporaryObjectExpr(EmptyShell Empty, unsigned NumArgs);
  1501. public:
  1502. static CXXTemporaryObjectExpr *
  1503. Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
  1504. TypeSourceInfo *TSI, ArrayRef<Expr *> Args,
  1505. SourceRange ParenOrBraceRange, bool HadMultipleCandidates,
  1506. bool ListInitialization, bool StdInitListInitialization,
  1507. bool ZeroInitialization);
  1508. static CXXTemporaryObjectExpr *CreateEmpty(const ASTContext &Ctx,
  1509. unsigned NumArgs);
  1510. TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
  1511. SourceLocation getBeginLoc() const LLVM_READONLY;
  1512. SourceLocation getEndLoc() const LLVM_READONLY;
  1513. static bool classof(const Stmt *T) {
  1514. return T->getStmtClass() == CXXTemporaryObjectExprClass;
  1515. }
  1516. };
  1517. Stmt **CXXConstructExpr::getTrailingArgs() {
  1518. if (auto *E = dyn_cast<CXXTemporaryObjectExpr>(this))
  1519. return reinterpret_cast<Stmt **>(E + 1);
  1520. assert((getStmtClass() == CXXConstructExprClass) &&
  1521. "Unexpected class deriving from CXXConstructExpr!");
  1522. return reinterpret_cast<Stmt **>(this + 1);
  1523. }
  1524. /// A C++ lambda expression, which produces a function object
  1525. /// (of unspecified type) that can be invoked later.
  1526. ///
  1527. /// Example:
  1528. /// \code
  1529. /// void low_pass_filter(std::vector<double> &values, double cutoff) {
  1530. /// values.erase(std::remove_if(values.begin(), values.end(),
  1531. /// [=](double value) { return value > cutoff; });
  1532. /// }
  1533. /// \endcode
  1534. ///
  1535. /// C++11 lambda expressions can capture local variables, either by copying
  1536. /// the values of those local variables at the time the function
  1537. /// object is constructed (not when it is called!) or by holding a
  1538. /// reference to the local variable. These captures can occur either
  1539. /// implicitly or can be written explicitly between the square
  1540. /// brackets ([...]) that start the lambda expression.
  1541. ///
  1542. /// C++1y introduces a new form of "capture" called an init-capture that
  1543. /// includes an initializing expression (rather than capturing a variable),
  1544. /// and which can never occur implicitly.
  1545. class LambdaExpr final : public Expr,
  1546. private llvm::TrailingObjects<LambdaExpr, Stmt *> {
  1547. // LambdaExpr has some data stored in LambdaExprBits.
  1548. /// The source range that covers the lambda introducer ([...]).
  1549. SourceRange IntroducerRange;
  1550. /// The source location of this lambda's capture-default ('=' or '&').
  1551. SourceLocation CaptureDefaultLoc;
  1552. /// The location of the closing brace ('}') that completes
  1553. /// the lambda.
  1554. ///
  1555. /// The location of the brace is also available by looking up the
  1556. /// function call operator in the lambda class. However, it is
  1557. /// stored here to improve the performance of getSourceRange(), and
  1558. /// to avoid having to deserialize the function call operator from a
  1559. /// module file just to determine the source range.
  1560. SourceLocation ClosingBrace;
  1561. /// Construct a lambda expression.
  1562. LambdaExpr(QualType T, SourceRange IntroducerRange,
  1563. LambdaCaptureDefault CaptureDefault,
  1564. SourceLocation CaptureDefaultLoc, bool ExplicitParams,
  1565. bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
  1566. SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
  1567. /// Construct an empty lambda expression.
  1568. LambdaExpr(EmptyShell Empty, unsigned NumCaptures);
  1569. Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
  1570. Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
  1571. void initBodyIfNeeded() const;
  1572. public:
  1573. friend class ASTStmtReader;
  1574. friend class ASTStmtWriter;
  1575. friend TrailingObjects;
  1576. /// Construct a new lambda expression.
  1577. static LambdaExpr *
  1578. Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
  1579. LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
  1580. bool ExplicitParams, bool ExplicitResultType,
  1581. ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
  1582. bool ContainsUnexpandedParameterPack);
  1583. /// Construct a new lambda expression that will be deserialized from
  1584. /// an external source.
  1585. static LambdaExpr *CreateDeserialized(const ASTContext &C,
  1586. unsigned NumCaptures);
  1587. /// Determine the default capture kind for this lambda.
  1588. LambdaCaptureDefault getCaptureDefault() const {
  1589. return static_cast<LambdaCaptureDefault>(LambdaExprBits.CaptureDefault);
  1590. }
  1591. /// Retrieve the location of this lambda's capture-default, if any.
  1592. SourceLocation getCaptureDefaultLoc() const { return CaptureDefaultLoc; }
  1593. /// Determine whether one of this lambda's captures is an init-capture.
  1594. bool isInitCapture(const LambdaCapture *Capture) const;
  1595. /// An iterator that walks over the captures of the lambda,
  1596. /// both implicit and explicit.
  1597. using capture_iterator = const LambdaCapture *;
  1598. /// An iterator over a range of lambda captures.
  1599. using capture_range = llvm::iterator_range<capture_iterator>;
  1600. /// Retrieve this lambda's captures.
  1601. capture_range captures() const;
  1602. /// Retrieve an iterator pointing to the first lambda capture.
  1603. capture_iterator capture_begin() const;
  1604. /// Retrieve an iterator pointing past the end of the
  1605. /// sequence of lambda captures.
  1606. capture_iterator capture_end() const;
  1607. /// Determine the number of captures in this lambda.
  1608. unsigned capture_size() const { return LambdaExprBits.NumCaptures; }
  1609. /// Retrieve this lambda's explicit captures.
  1610. capture_range explicit_captures() const;
  1611. /// Retrieve an iterator pointing to the first explicit
  1612. /// lambda capture.
  1613. capture_iterator explicit_capture_begin() const;
  1614. /// Retrieve an iterator pointing past the end of the sequence of
  1615. /// explicit lambda captures.
  1616. capture_iterator explicit_capture_end() const;
  1617. /// Retrieve this lambda's implicit captures.
  1618. capture_range implicit_captures() const;
  1619. /// Retrieve an iterator pointing to the first implicit
  1620. /// lambda capture.
  1621. capture_iterator implicit_capture_begin() const;
  1622. /// Retrieve an iterator pointing past the end of the sequence of
  1623. /// implicit lambda captures.
  1624. capture_iterator implicit_capture_end() const;
  1625. /// Iterator that walks over the capture initialization
  1626. /// arguments.
  1627. using capture_init_iterator = Expr **;
  1628. /// Const iterator that walks over the capture initialization
  1629. /// arguments.
  1630. /// FIXME: This interface is prone to being used incorrectly.
  1631. using const_capture_init_iterator = Expr *const *;
  1632. /// Retrieve the initialization expressions for this lambda's captures.
  1633. llvm::iterator_range<capture_init_iterator> capture_inits() {
  1634. return llvm::make_range(capture_init_begin(), capture_init_end());
  1635. }
  1636. /// Retrieve the initialization expressions for this lambda's captures.
  1637. llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
  1638. return llvm::make_range(capture_init_begin(), capture_init_end());
  1639. }
  1640. /// Retrieve the first initialization argument for this
  1641. /// lambda expression (which initializes the first capture field).
  1642. capture_init_iterator capture_init_begin() {
  1643. return reinterpret_cast<Expr **>(getStoredStmts());
  1644. }
  1645. /// Retrieve the first initialization argument for this
  1646. /// lambda expression (which initializes the first capture field).
  1647. const_capture_init_iterator capture_init_begin() const {
  1648. return reinterpret_cast<Expr *const *>(getStoredStmts());
  1649. }
  1650. /// Retrieve the iterator pointing one past the last
  1651. /// initialization argument for this lambda expression.
  1652. capture_init_iterator capture_init_end() {
  1653. return capture_init_begin() + capture_size();
  1654. }
  1655. /// Retrieve the iterator pointing one past the last
  1656. /// initialization argument for this lambda expression.
  1657. const_capture_init_iterator capture_init_end() const {
  1658. return capture_init_begin() + capture_size();
  1659. }
  1660. /// Retrieve the source range covering the lambda introducer,
  1661. /// which contains the explicit capture list surrounded by square
  1662. /// brackets ([...]).
  1663. SourceRange getIntroducerRange() const { return IntroducerRange; }
  1664. /// Retrieve the class that corresponds to the lambda.
  1665. ///
  1666. /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
  1667. /// captures in its fields and provides the various operations permitted
  1668. /// on a lambda (copying, calling).
  1669. CXXRecordDecl *getLambdaClass() const;
  1670. /// Retrieve the function call operator associated with this
  1671. /// lambda expression.
  1672. CXXMethodDecl *getCallOperator() const;
  1673. /// Retrieve the function template call operator associated with this
  1674. /// lambda expression.
  1675. FunctionTemplateDecl *getDependentCallOperator() const;
  1676. /// If this is a generic lambda expression, retrieve the template
  1677. /// parameter list associated with it, or else return null.
  1678. TemplateParameterList *getTemplateParameterList() const;
  1679. /// Get the template parameters were explicitly specified (as opposed to being
  1680. /// invented by use of an auto parameter).
  1681. ArrayRef<NamedDecl *> getExplicitTemplateParameters() const;
  1682. /// Get the trailing requires clause, if any.
  1683. Expr *getTrailingRequiresClause() const;
  1684. /// Whether this is a generic lambda.
  1685. bool isGenericLambda() const { return getTemplateParameterList(); }
  1686. /// Retrieve the body of the lambda. This will be most of the time
  1687. /// a \p CompoundStmt, but can also be \p CoroutineBodyStmt wrapping
  1688. /// a \p CompoundStmt. Note that unlike functions, lambda-expressions
  1689. /// cannot have a function-try-block.
  1690. Stmt *getBody() const;
  1691. /// Retrieve the \p CompoundStmt representing the body of the lambda.
  1692. /// This is a convenience function for callers who do not need
  1693. /// to handle node(s) which may wrap a \p CompoundStmt.
  1694. const CompoundStmt *getCompoundStmtBody() const;
  1695. CompoundStmt *getCompoundStmtBody() {
  1696. const auto *ConstThis = this;
  1697. return const_cast<CompoundStmt *>(ConstThis->getCompoundStmtBody());
  1698. }
  1699. /// Determine whether the lambda is mutable, meaning that any
  1700. /// captures values can be modified.
  1701. bool isMutable() const;
  1702. /// Determine whether this lambda has an explicit parameter
  1703. /// list vs. an implicit (empty) parameter list.
  1704. bool hasExplicitParameters() const { return LambdaExprBits.ExplicitParams; }
  1705. /// Whether this lambda had its result type explicitly specified.
  1706. bool hasExplicitResultType() const {
  1707. return LambdaExprBits.ExplicitResultType;
  1708. }
  1709. static bool classof(const Stmt *T) {
  1710. return T->getStmtClass() == LambdaExprClass;
  1711. }
  1712. SourceLocation getBeginLoc() const LLVM_READONLY {
  1713. return IntroducerRange.getBegin();
  1714. }
  1715. SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; }
  1716. /// Includes the captures and the body of the lambda.
  1717. child_range children();
  1718. const_child_range children() const;
  1719. };
  1720. /// An expression "T()" which creates a value-initialized rvalue of type
  1721. /// T, which is a non-class type. See (C++98 [5.2.3p2]).
  1722. class CXXScalarValueInitExpr : public Expr {
  1723. friend class ASTStmtReader;
  1724. TypeSourceInfo *TypeInfo;
  1725. public:
  1726. /// Create an explicitly-written scalar-value initialization
  1727. /// expression.
  1728. CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
  1729. SourceLocation RParenLoc)
  1730. : Expr(CXXScalarValueInitExprClass, Type, VK_PRValue, OK_Ordinary),
  1731. TypeInfo(TypeInfo) {
  1732. CXXScalarValueInitExprBits.RParenLoc = RParenLoc;
  1733. setDependence(computeDependence(this));
  1734. }
  1735. explicit CXXScalarValueInitExpr(EmptyShell Shell)
  1736. : Expr(CXXScalarValueInitExprClass, Shell) {}
  1737. TypeSourceInfo *getTypeSourceInfo() const {
  1738. return TypeInfo;
  1739. }
  1740. SourceLocation getRParenLoc() const {
  1741. return CXXScalarValueInitExprBits.RParenLoc;
  1742. }
  1743. SourceLocation getBeginLoc() const LLVM_READONLY;
  1744. SourceLocation getEndLoc() const { return getRParenLoc(); }
  1745. static bool classof(const Stmt *T) {
  1746. return T->getStmtClass() == CXXScalarValueInitExprClass;
  1747. }
  1748. // Iterators
  1749. child_range children() {
  1750. return child_range(child_iterator(), child_iterator());
  1751. }
  1752. const_child_range children() const {
  1753. return const_child_range(const_child_iterator(), const_child_iterator());
  1754. }
  1755. };
  1756. /// Represents a new-expression for memory allocation and constructor
  1757. /// calls, e.g: "new CXXNewExpr(foo)".
  1758. class CXXNewExpr final
  1759. : public Expr,
  1760. private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> {
  1761. friend class ASTStmtReader;
  1762. friend class ASTStmtWriter;
  1763. friend TrailingObjects;
  1764. /// Points to the allocation function used.
  1765. FunctionDecl *OperatorNew;
  1766. /// Points to the deallocation function used in case of error. May be null.
  1767. FunctionDecl *OperatorDelete;
  1768. /// The allocated type-source information, as written in the source.
  1769. TypeSourceInfo *AllocatedTypeInfo;
  1770. /// Range of the entire new expression.
  1771. SourceRange Range;
  1772. /// Source-range of a paren-delimited initializer.
  1773. SourceRange DirectInitRange;
  1774. // CXXNewExpr is followed by several optional trailing objects.
  1775. // They are in order:
  1776. //
  1777. // * An optional "Stmt *" for the array size expression.
  1778. // Present if and ony if isArray().
  1779. //
  1780. // * An optional "Stmt *" for the init expression.
  1781. // Present if and only if hasInitializer().
  1782. //
  1783. // * An array of getNumPlacementArgs() "Stmt *" for the placement new
  1784. // arguments, if any.
  1785. //
  1786. // * An optional SourceRange for the range covering the parenthesized type-id
  1787. // if the allocated type was expressed as a parenthesized type-id.
  1788. // Present if and only if isParenTypeId().
  1789. unsigned arraySizeOffset() const { return 0; }
  1790. unsigned initExprOffset() const { return arraySizeOffset() + isArray(); }
  1791. unsigned placementNewArgsOffset() const {
  1792. return initExprOffset() + hasInitializer();
  1793. }
  1794. unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
  1795. return isArray() + hasInitializer() + getNumPlacementArgs();
  1796. }
  1797. unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
  1798. return isParenTypeId();
  1799. }
  1800. public:
  1801. enum InitializationStyle {
  1802. /// New-expression has no initializer as written.
  1803. NoInit,
  1804. /// New-expression has a C++98 paren-delimited initializer.
  1805. CallInit,
  1806. /// New-expression has a C++11 list-initializer.
  1807. ListInit
  1808. };
  1809. private:
  1810. /// Build a c++ new expression.
  1811. CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  1812. FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  1813. bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
  1814. SourceRange TypeIdParens, Optional<Expr *> ArraySize,
  1815. InitializationStyle InitializationStyle, Expr *Initializer,
  1816. QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  1817. SourceRange DirectInitRange);
  1818. /// Build an empty c++ new expression.
  1819. CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
  1820. bool IsParenTypeId);
  1821. public:
  1822. /// Create a c++ new expression.
  1823. static CXXNewExpr *
  1824. Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew,
  1825. FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  1826. bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
  1827. SourceRange TypeIdParens, Optional<Expr *> ArraySize,
  1828. InitializationStyle InitializationStyle, Expr *Initializer,
  1829. QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  1830. SourceRange DirectInitRange);
  1831. /// Create an empty c++ new expression.
  1832. static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
  1833. bool HasInit, unsigned NumPlacementArgs,
  1834. bool IsParenTypeId);
  1835. QualType getAllocatedType() const {
  1836. return getType()->castAs<PointerType>()->getPointeeType();
  1837. }
  1838. TypeSourceInfo *getAllocatedTypeSourceInfo() const {
  1839. return AllocatedTypeInfo;
  1840. }
  1841. /// True if the allocation result needs to be null-checked.
  1842. ///
  1843. /// C++11 [expr.new]p13:
  1844. /// If the allocation function returns null, initialization shall
  1845. /// not be done, the deallocation function shall not be called,
  1846. /// and the value of the new-expression shall be null.
  1847. ///
  1848. /// C++ DR1748:
  1849. /// If the allocation function is a reserved placement allocation
  1850. /// function that returns null, the behavior is undefined.
  1851. ///
  1852. /// An allocation function is not allowed to return null unless it
  1853. /// has a non-throwing exception-specification. The '03 rule is
  1854. /// identical except that the definition of a non-throwing
  1855. /// exception specification is just "is it throw()?".
  1856. bool shouldNullCheckAllocation() const;
  1857. FunctionDecl *getOperatorNew() const { return OperatorNew; }
  1858. void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
  1859. FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
  1860. void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
  1861. bool isArray() const { return CXXNewExprBits.IsArray; }
  1862. Optional<Expr *> getArraySize() {
  1863. if (!isArray())
  1864. return None;
  1865. return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
  1866. }
  1867. Optional<const Expr *> getArraySize() const {
  1868. if (!isArray())
  1869. return None;
  1870. return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
  1871. }
  1872. unsigned getNumPlacementArgs() const {
  1873. return CXXNewExprBits.NumPlacementArgs;
  1874. }
  1875. Expr **getPlacementArgs() {
  1876. return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() +
  1877. placementNewArgsOffset());
  1878. }
  1879. Expr *getPlacementArg(unsigned I) {
  1880. assert((I < getNumPlacementArgs()) && "Index out of range!");
  1881. return getPlacementArgs()[I];
  1882. }
  1883. const Expr *getPlacementArg(unsigned I) const {
  1884. return const_cast<CXXNewExpr *>(this)->getPlacementArg(I);
  1885. }
  1886. bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; }
  1887. SourceRange getTypeIdParens() const {
  1888. return isParenTypeId() ? getTrailingObjects<SourceRange>()[0]
  1889. : SourceRange();
  1890. }
  1891. bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
  1892. /// Whether this new-expression has any initializer at all.
  1893. bool hasInitializer() const {
  1894. return CXXNewExprBits.StoredInitializationStyle > 0;
  1895. }
  1896. /// The kind of initializer this new-expression has.
  1897. InitializationStyle getInitializationStyle() const {
  1898. if (CXXNewExprBits.StoredInitializationStyle == 0)
  1899. return NoInit;
  1900. return static_cast<InitializationStyle>(
  1901. CXXNewExprBits.StoredInitializationStyle - 1);
  1902. }
  1903. /// The initializer of this new-expression.
  1904. Expr *getInitializer() {
  1905. return hasInitializer()
  1906. ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
  1907. : nullptr;
  1908. }
  1909. const Expr *getInitializer() const {
  1910. return hasInitializer()
  1911. ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
  1912. : nullptr;
  1913. }
  1914. /// Returns the CXXConstructExpr from this new-expression, or null.
  1915. const CXXConstructExpr *getConstructExpr() const {
  1916. return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
  1917. }
  1918. /// Indicates whether the required alignment should be implicitly passed to
  1919. /// the allocation function.
  1920. bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; }
  1921. /// Answers whether the usual array deallocation function for the
  1922. /// allocated type expects the size of the allocation as a
  1923. /// parameter.
  1924. bool doesUsualArrayDeleteWantSize() const {
  1925. return CXXNewExprBits.UsualArrayDeleteWantsSize;
  1926. }
  1927. using arg_iterator = ExprIterator;
  1928. using const_arg_iterator = ConstExprIterator;
  1929. llvm::iterator_range<arg_iterator> placement_arguments() {
  1930. return llvm::make_range(placement_arg_begin(), placement_arg_end());
  1931. }
  1932. llvm::iterator_range<const_arg_iterator> placement_arguments() const {
  1933. return llvm::make_range(placement_arg_begin(), placement_arg_end());
  1934. }
  1935. arg_iterator placement_arg_begin() {
  1936. return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
  1937. }
  1938. arg_iterator placement_arg_end() {
  1939. return placement_arg_begin() + getNumPlacementArgs();
  1940. }
  1941. const_arg_iterator placement_arg_begin() const {
  1942. return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
  1943. }
  1944. const_arg_iterator placement_arg_end() const {
  1945. return placement_arg_begin() + getNumPlacementArgs();
  1946. }
  1947. using raw_arg_iterator = Stmt **;
  1948. raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); }
  1949. raw_arg_iterator raw_arg_end() {
  1950. return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
  1951. }
  1952. const_arg_iterator raw_arg_begin() const {
  1953. return getTrailingObjects<Stmt *>();
  1954. }
  1955. const_arg_iterator raw_arg_end() const {
  1956. return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
  1957. }
  1958. SourceLocation getBeginLoc() const { return Range.getBegin(); }
  1959. SourceLocation getEndLoc() const { return Range.getEnd(); }
  1960. SourceRange getDirectInitRange() const { return DirectInitRange; }
  1961. SourceRange getSourceRange() const { return Range; }
  1962. static bool classof(const Stmt *T) {
  1963. return T->getStmtClass() == CXXNewExprClass;
  1964. }
  1965. // Iterators
  1966. child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); }
  1967. const_child_range children() const {
  1968. return const_child_range(const_cast<CXXNewExpr *>(this)->children());
  1969. }
  1970. };
  1971. /// Represents a \c delete expression for memory deallocation and
  1972. /// destructor calls, e.g. "delete[] pArray".
  1973. class CXXDeleteExpr : public Expr {
  1974. friend class ASTStmtReader;
  1975. /// Points to the operator delete overload that is used. Could be a member.
  1976. FunctionDecl *OperatorDelete = nullptr;
  1977. /// The pointer expression to be deleted.
  1978. Stmt *Argument = nullptr;
  1979. public:
  1980. CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm,
  1981. bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize,
  1982. FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc)
  1983. : Expr(CXXDeleteExprClass, Ty, VK_PRValue, OK_Ordinary),
  1984. OperatorDelete(OperatorDelete), Argument(Arg) {
  1985. CXXDeleteExprBits.GlobalDelete = GlobalDelete;
  1986. CXXDeleteExprBits.ArrayForm = ArrayForm;
  1987. CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten;
  1988. CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
  1989. CXXDeleteExprBits.Loc = Loc;
  1990. setDependence(computeDependence(this));
  1991. }
  1992. explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {}
  1993. bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; }
  1994. bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; }
  1995. bool isArrayFormAsWritten() const {
  1996. return CXXDeleteExprBits.ArrayFormAsWritten;
  1997. }
  1998. /// Answers whether the usual array deallocation function for the
  1999. /// allocated type expects the size of the allocation as a
  2000. /// parameter. This can be true even if the actual deallocation
  2001. /// function that we're using doesn't want a size.
  2002. bool doesUsualArrayDeleteWantSize() const {
  2003. return CXXDeleteExprBits.UsualArrayDeleteWantsSize;
  2004. }
  2005. FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
  2006. Expr *getArgument() { return cast<Expr>(Argument); }
  2007. const Expr *getArgument() const { return cast<Expr>(Argument); }
  2008. /// Retrieve the type being destroyed.
  2009. ///
  2010. /// If the type being destroyed is a dependent type which may or may not
  2011. /// be a pointer, return an invalid type.
  2012. QualType getDestroyedType() const;
  2013. SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; }
  2014. SourceLocation getEndLoc() const LLVM_READONLY {
  2015. return Argument->getEndLoc();
  2016. }
  2017. static bool classof(const Stmt *T) {
  2018. return T->getStmtClass() == CXXDeleteExprClass;
  2019. }
  2020. // Iterators
  2021. child_range children() { return child_range(&Argument, &Argument + 1); }
  2022. const_child_range children() const {
  2023. return const_child_range(&Argument, &Argument + 1);
  2024. }
  2025. };
  2026. /// Stores the type being destroyed by a pseudo-destructor expression.
  2027. class PseudoDestructorTypeStorage {
  2028. /// Either the type source information or the name of the type, if
  2029. /// it couldn't be resolved due to type-dependence.
  2030. llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
  2031. /// The starting source location of the pseudo-destructor type.
  2032. SourceLocation Location;
  2033. public:
  2034. PseudoDestructorTypeStorage() = default;
  2035. PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
  2036. : Type(II), Location(Loc) {}
  2037. PseudoDestructorTypeStorage(TypeSourceInfo *Info);
  2038. TypeSourceInfo *getTypeSourceInfo() const {
  2039. return Type.dyn_cast<TypeSourceInfo *>();
  2040. }
  2041. IdentifierInfo *getIdentifier() const {
  2042. return Type.dyn_cast<IdentifierInfo *>();
  2043. }
  2044. SourceLocation getLocation() const { return Location; }
  2045. };
  2046. /// Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
  2047. ///
  2048. /// A pseudo-destructor is an expression that looks like a member access to a
  2049. /// destructor of a scalar type, except that scalar types don't have
  2050. /// destructors. For example:
  2051. ///
  2052. /// \code
  2053. /// typedef int T;
  2054. /// void f(int *p) {
  2055. /// p->T::~T();
  2056. /// }
  2057. /// \endcode
  2058. ///
  2059. /// Pseudo-destructors typically occur when instantiating templates such as:
  2060. ///
  2061. /// \code
  2062. /// template<typename T>
  2063. /// void destroy(T* ptr) {
  2064. /// ptr->T::~T();
  2065. /// }
  2066. /// \endcode
  2067. ///
  2068. /// for scalar types. A pseudo-destructor expression has no run-time semantics
  2069. /// beyond evaluating the base expression.
  2070. class CXXPseudoDestructorExpr : public Expr {
  2071. friend class ASTStmtReader;
  2072. /// The base expression (that is being destroyed).
  2073. Stmt *Base = nullptr;
  2074. /// Whether the operator was an arrow ('->'); otherwise, it was a
  2075. /// period ('.').
  2076. bool IsArrow : 1;
  2077. /// The location of the '.' or '->' operator.
  2078. SourceLocation OperatorLoc;
  2079. /// The nested-name-specifier that follows the operator, if present.
  2080. NestedNameSpecifierLoc QualifierLoc;
  2081. /// The type that precedes the '::' in a qualified pseudo-destructor
  2082. /// expression.
  2083. TypeSourceInfo *ScopeType = nullptr;
  2084. /// The location of the '::' in a qualified pseudo-destructor
  2085. /// expression.
  2086. SourceLocation ColonColonLoc;
  2087. /// The location of the '~'.
  2088. SourceLocation TildeLoc;
  2089. /// The type being destroyed, or its name if we were unable to
  2090. /// resolve the name.
  2091. PseudoDestructorTypeStorage DestroyedType;
  2092. public:
  2093. CXXPseudoDestructorExpr(const ASTContext &Context,
  2094. Expr *Base, bool isArrow, SourceLocation OperatorLoc,
  2095. NestedNameSpecifierLoc QualifierLoc,
  2096. TypeSourceInfo *ScopeType,
  2097. SourceLocation ColonColonLoc,
  2098. SourceLocation TildeLoc,
  2099. PseudoDestructorTypeStorage DestroyedType);
  2100. explicit CXXPseudoDestructorExpr(EmptyShell Shell)
  2101. : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {}
  2102. Expr *getBase() const { return cast<Expr>(Base); }
  2103. /// Determines whether this member expression actually had
  2104. /// a C++ nested-name-specifier prior to the name of the member, e.g.,
  2105. /// x->Base::foo.
  2106. bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
  2107. /// Retrieves the nested-name-specifier that qualifies the type name,
  2108. /// with source-location information.
  2109. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  2110. /// If the member name was qualified, retrieves the
  2111. /// nested-name-specifier that precedes the member name. Otherwise, returns
  2112. /// null.
  2113. NestedNameSpecifier *getQualifier() const {
  2114. return QualifierLoc.getNestedNameSpecifier();
  2115. }
  2116. /// Determine whether this pseudo-destructor expression was written
  2117. /// using an '->' (otherwise, it used a '.').
  2118. bool isArrow() const { return IsArrow; }
  2119. /// Retrieve the location of the '.' or '->' operator.
  2120. SourceLocation getOperatorLoc() const { return OperatorLoc; }
  2121. /// Retrieve the scope type in a qualified pseudo-destructor
  2122. /// expression.
  2123. ///
  2124. /// Pseudo-destructor expressions can have extra qualification within them
  2125. /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
  2126. /// Here, if the object type of the expression is (or may be) a scalar type,
  2127. /// \p T may also be a scalar type and, therefore, cannot be part of a
  2128. /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
  2129. /// destructor expression.
  2130. TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
  2131. /// Retrieve the location of the '::' in a qualified pseudo-destructor
  2132. /// expression.
  2133. SourceLocation getColonColonLoc() const { return ColonColonLoc; }
  2134. /// Retrieve the location of the '~'.
  2135. SourceLocation getTildeLoc() const { return TildeLoc; }
  2136. /// Retrieve the source location information for the type
  2137. /// being destroyed.
  2138. ///
  2139. /// This type-source information is available for non-dependent
  2140. /// pseudo-destructor expressions and some dependent pseudo-destructor
  2141. /// expressions. Returns null if we only have the identifier for a
  2142. /// dependent pseudo-destructor expression.
  2143. TypeSourceInfo *getDestroyedTypeInfo() const {
  2144. return DestroyedType.getTypeSourceInfo();
  2145. }
  2146. /// In a dependent pseudo-destructor expression for which we do not
  2147. /// have full type information on the destroyed type, provides the name
  2148. /// of the destroyed type.
  2149. IdentifierInfo *getDestroyedTypeIdentifier() const {
  2150. return DestroyedType.getIdentifier();
  2151. }
  2152. /// Retrieve the type being destroyed.
  2153. QualType getDestroyedType() const;
  2154. /// Retrieve the starting location of the type being destroyed.
  2155. SourceLocation getDestroyedTypeLoc() const {
  2156. return DestroyedType.getLocation();
  2157. }
  2158. /// Set the name of destroyed type for a dependent pseudo-destructor
  2159. /// expression.
  2160. void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
  2161. DestroyedType = PseudoDestructorTypeStorage(II, Loc);
  2162. }
  2163. /// Set the destroyed type.
  2164. void setDestroyedType(TypeSourceInfo *Info) {
  2165. DestroyedType = PseudoDestructorTypeStorage(Info);
  2166. }
  2167. SourceLocation getBeginLoc() const LLVM_READONLY {
  2168. return Base->getBeginLoc();
  2169. }
  2170. SourceLocation getEndLoc() const LLVM_READONLY;
  2171. static bool classof(const Stmt *T) {
  2172. return T->getStmtClass() == CXXPseudoDestructorExprClass;
  2173. }
  2174. // Iterators
  2175. child_range children() { return child_range(&Base, &Base + 1); }
  2176. const_child_range children() const {
  2177. return const_child_range(&Base, &Base + 1);
  2178. }
  2179. };
  2180. /// A type trait used in the implementation of various C++11 and
  2181. /// Library TR1 trait templates.
  2182. ///
  2183. /// \code
  2184. /// __is_pod(int) == true
  2185. /// __is_enum(std::string) == false
  2186. /// __is_trivially_constructible(vector<int>, int*, int*)
  2187. /// \endcode
  2188. class TypeTraitExpr final
  2189. : public Expr,
  2190. private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
  2191. /// The location of the type trait keyword.
  2192. SourceLocation Loc;
  2193. /// The location of the closing parenthesis.
  2194. SourceLocation RParenLoc;
  2195. // Note: The TypeSourceInfos for the arguments are allocated after the
  2196. // TypeTraitExpr.
  2197. TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
  2198. ArrayRef<TypeSourceInfo *> Args,
  2199. SourceLocation RParenLoc,
  2200. bool Value);
  2201. TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
  2202. size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
  2203. return getNumArgs();
  2204. }
  2205. public:
  2206. friend class ASTStmtReader;
  2207. friend class ASTStmtWriter;
  2208. friend TrailingObjects;
  2209. /// Create a new type trait expression.
  2210. static TypeTraitExpr *Create(const ASTContext &C, QualType T,
  2211. SourceLocation Loc, TypeTrait Kind,
  2212. ArrayRef<TypeSourceInfo *> Args,
  2213. SourceLocation RParenLoc,
  2214. bool Value);
  2215. static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
  2216. unsigned NumArgs);
  2217. /// Determine which type trait this expression uses.
  2218. TypeTrait getTrait() const {
  2219. return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
  2220. }
  2221. bool getValue() const {
  2222. assert(!isValueDependent());
  2223. return TypeTraitExprBits.Value;
  2224. }
  2225. /// Determine the number of arguments to this type trait.
  2226. unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
  2227. /// Retrieve the Ith argument.
  2228. TypeSourceInfo *getArg(unsigned I) const {
  2229. assert(I < getNumArgs() && "Argument out-of-range");
  2230. return getArgs()[I];
  2231. }
  2232. /// Retrieve the argument types.
  2233. ArrayRef<TypeSourceInfo *> getArgs() const {
  2234. return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
  2235. getNumArgs());
  2236. }
  2237. SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
  2238. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  2239. static bool classof(const Stmt *T) {
  2240. return T->getStmtClass() == TypeTraitExprClass;
  2241. }
  2242. // Iterators
  2243. child_range children() {
  2244. return child_range(child_iterator(), child_iterator());
  2245. }
  2246. const_child_range children() const {
  2247. return const_child_range(const_child_iterator(), const_child_iterator());
  2248. }
  2249. };
  2250. /// An Embarcadero array type trait, as used in the implementation of
  2251. /// __array_rank and __array_extent.
  2252. ///
  2253. /// Example:
  2254. /// \code
  2255. /// __array_rank(int[10][20]) == 2
  2256. /// __array_extent(int, 1) == 20
  2257. /// \endcode
  2258. class ArrayTypeTraitExpr : public Expr {
  2259. /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
  2260. unsigned ATT : 2;
  2261. /// The value of the type trait. Unspecified if dependent.
  2262. uint64_t Value = 0;
  2263. /// The array dimension being queried, or -1 if not used.
  2264. Expr *Dimension;
  2265. /// The location of the type trait keyword.
  2266. SourceLocation Loc;
  2267. /// The location of the closing paren.
  2268. SourceLocation RParen;
  2269. /// The type being queried.
  2270. TypeSourceInfo *QueriedType = nullptr;
  2271. public:
  2272. friend class ASTStmtReader;
  2273. ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
  2274. TypeSourceInfo *queried, uint64_t value, Expr *dimension,
  2275. SourceLocation rparen, QualType ty)
  2276. : Expr(ArrayTypeTraitExprClass, ty, VK_PRValue, OK_Ordinary), ATT(att),
  2277. Value(value), Dimension(dimension), Loc(loc), RParen(rparen),
  2278. QueriedType(queried) {
  2279. assert(att <= ATT_Last && "invalid enum value!");
  2280. assert(static_cast<unsigned>(att) == ATT && "ATT overflow!");
  2281. setDependence(computeDependence(this));
  2282. }
  2283. explicit ArrayTypeTraitExpr(EmptyShell Empty)
  2284. : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {}
  2285. SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
  2286. SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
  2287. ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
  2288. QualType getQueriedType() const { return QueriedType->getType(); }
  2289. TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
  2290. uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
  2291. Expr *getDimensionExpression() const { return Dimension; }
  2292. static bool classof(const Stmt *T) {
  2293. return T->getStmtClass() == ArrayTypeTraitExprClass;
  2294. }
  2295. // Iterators
  2296. child_range children() {
  2297. return child_range(child_iterator(), child_iterator());
  2298. }
  2299. const_child_range children() const {
  2300. return const_child_range(const_child_iterator(), const_child_iterator());
  2301. }
  2302. };
  2303. /// An expression trait intrinsic.
  2304. ///
  2305. /// Example:
  2306. /// \code
  2307. /// __is_lvalue_expr(std::cout) == true
  2308. /// __is_lvalue_expr(1) == false
  2309. /// \endcode
  2310. class ExpressionTraitExpr : public Expr {
  2311. /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
  2312. unsigned ET : 31;
  2313. /// The value of the type trait. Unspecified if dependent.
  2314. unsigned Value : 1;
  2315. /// The location of the type trait keyword.
  2316. SourceLocation Loc;
  2317. /// The location of the closing paren.
  2318. SourceLocation RParen;
  2319. /// The expression being queried.
  2320. Expr* QueriedExpression = nullptr;
  2321. public:
  2322. friend class ASTStmtReader;
  2323. ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, Expr *queried,
  2324. bool value, SourceLocation rparen, QualType resultType)
  2325. : Expr(ExpressionTraitExprClass, resultType, VK_PRValue, OK_Ordinary),
  2326. ET(et), Value(value), Loc(loc), RParen(rparen),
  2327. QueriedExpression(queried) {
  2328. assert(et <= ET_Last && "invalid enum value!");
  2329. assert(static_cast<unsigned>(et) == ET && "ET overflow!");
  2330. setDependence(computeDependence(this));
  2331. }
  2332. explicit ExpressionTraitExpr(EmptyShell Empty)
  2333. : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {}
  2334. SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
  2335. SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
  2336. ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
  2337. Expr *getQueriedExpression() const { return QueriedExpression; }
  2338. bool getValue() const { return Value; }
  2339. static bool classof(const Stmt *T) {
  2340. return T->getStmtClass() == ExpressionTraitExprClass;
  2341. }
  2342. // Iterators
  2343. child_range children() {
  2344. return child_range(child_iterator(), child_iterator());
  2345. }
  2346. const_child_range children() const {
  2347. return const_child_range(const_child_iterator(), const_child_iterator());
  2348. }
  2349. };
  2350. /// A reference to an overloaded function set, either an
  2351. /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
  2352. class OverloadExpr : public Expr {
  2353. friend class ASTStmtReader;
  2354. friend class ASTStmtWriter;
  2355. /// The common name of these declarations.
  2356. DeclarationNameInfo NameInfo;
  2357. /// The nested-name-specifier that qualifies the name, if any.
  2358. NestedNameSpecifierLoc QualifierLoc;
  2359. protected:
  2360. OverloadExpr(StmtClass SC, const ASTContext &Context,
  2361. NestedNameSpecifierLoc QualifierLoc,
  2362. SourceLocation TemplateKWLoc,
  2363. const DeclarationNameInfo &NameInfo,
  2364. const TemplateArgumentListInfo *TemplateArgs,
  2365. UnresolvedSetIterator Begin, UnresolvedSetIterator End,
  2366. bool KnownDependent, bool KnownInstantiationDependent,
  2367. bool KnownContainsUnexpandedParameterPack);
  2368. OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
  2369. bool HasTemplateKWAndArgsInfo);
  2370. /// Return the results. Defined after UnresolvedMemberExpr.
  2371. inline DeclAccessPair *getTrailingResults();
  2372. const DeclAccessPair *getTrailingResults() const {
  2373. return const_cast<OverloadExpr *>(this)->getTrailingResults();
  2374. }
  2375. /// Return the optional template keyword and arguments info.
  2376. /// Defined after UnresolvedMemberExpr.
  2377. inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo();
  2378. const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
  2379. return const_cast<OverloadExpr *>(this)
  2380. ->getTrailingASTTemplateKWAndArgsInfo();
  2381. }
  2382. /// Return the optional template arguments. Defined after
  2383. /// UnresolvedMemberExpr.
  2384. inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc();
  2385. const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const {
  2386. return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
  2387. }
  2388. bool hasTemplateKWAndArgsInfo() const {
  2389. return OverloadExprBits.HasTemplateKWAndArgsInfo;
  2390. }
  2391. public:
  2392. struct FindResult {
  2393. OverloadExpr *Expression;
  2394. bool IsAddressOfOperand;
  2395. bool HasFormOfMemberPointer;
  2396. };
  2397. /// Finds the overloaded expression in the given expression \p E of
  2398. /// OverloadTy.
  2399. ///
  2400. /// \return the expression (which must be there) and true if it has
  2401. /// the particular form of a member pointer expression
  2402. static FindResult find(Expr *E) {
  2403. assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
  2404. FindResult Result;
  2405. E = E->IgnoreParens();
  2406. if (isa<UnaryOperator>(E)) {
  2407. assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
  2408. E = cast<UnaryOperator>(E)->getSubExpr();
  2409. auto *Ovl = cast<OverloadExpr>(E->IgnoreParens());
  2410. Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
  2411. Result.IsAddressOfOperand = true;
  2412. Result.Expression = Ovl;
  2413. } else {
  2414. Result.HasFormOfMemberPointer = false;
  2415. Result.IsAddressOfOperand = false;
  2416. Result.Expression = cast<OverloadExpr>(E);
  2417. }
  2418. return Result;
  2419. }
  2420. /// Gets the naming class of this lookup, if any.
  2421. /// Defined after UnresolvedMemberExpr.
  2422. inline CXXRecordDecl *getNamingClass();
  2423. const CXXRecordDecl *getNamingClass() const {
  2424. return const_cast<OverloadExpr *>(this)->getNamingClass();
  2425. }
  2426. using decls_iterator = UnresolvedSetImpl::iterator;
  2427. decls_iterator decls_begin() const {
  2428. return UnresolvedSetIterator(getTrailingResults());
  2429. }
  2430. decls_iterator decls_end() const {
  2431. return UnresolvedSetIterator(getTrailingResults() + getNumDecls());
  2432. }
  2433. llvm::iterator_range<decls_iterator> decls() const {
  2434. return llvm::make_range(decls_begin(), decls_end());
  2435. }
  2436. /// Gets the number of declarations in the unresolved set.
  2437. unsigned getNumDecls() const { return OverloadExprBits.NumResults; }
  2438. /// Gets the full name info.
  2439. const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
  2440. /// Gets the name looked up.
  2441. DeclarationName getName() const { return NameInfo.getName(); }
  2442. /// Gets the location of the name.
  2443. SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
  2444. /// Fetches the nested-name qualifier, if one was given.
  2445. NestedNameSpecifier *getQualifier() const {
  2446. return QualifierLoc.getNestedNameSpecifier();
  2447. }
  2448. /// Fetches the nested-name qualifier with source-location
  2449. /// information, if one was given.
  2450. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  2451. /// Retrieve the location of the template keyword preceding
  2452. /// this name, if any.
  2453. SourceLocation getTemplateKeywordLoc() const {
  2454. if (!hasTemplateKWAndArgsInfo())
  2455. return SourceLocation();
  2456. return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
  2457. }
  2458. /// Retrieve the location of the left angle bracket starting the
  2459. /// explicit template argument list following the name, if any.
  2460. SourceLocation getLAngleLoc() const {
  2461. if (!hasTemplateKWAndArgsInfo())
  2462. return SourceLocation();
  2463. return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
  2464. }
  2465. /// Retrieve the location of the right angle bracket ending the
  2466. /// explicit template argument list following the name, if any.
  2467. SourceLocation getRAngleLoc() const {
  2468. if (!hasTemplateKWAndArgsInfo())
  2469. return SourceLocation();
  2470. return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
  2471. }
  2472. /// Determines whether the name was preceded by the template keyword.
  2473. bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
  2474. /// Determines whether this expression had explicit template arguments.
  2475. bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
  2476. TemplateArgumentLoc const *getTemplateArgs() const {
  2477. if (!hasExplicitTemplateArgs())
  2478. return nullptr;
  2479. return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
  2480. }
  2481. unsigned getNumTemplateArgs() const {
  2482. if (!hasExplicitTemplateArgs())
  2483. return 0;
  2484. return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
  2485. }
  2486. ArrayRef<TemplateArgumentLoc> template_arguments() const {
  2487. return {getTemplateArgs(), getNumTemplateArgs()};
  2488. }
  2489. /// Copies the template arguments into the given structure.
  2490. void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
  2491. if (hasExplicitTemplateArgs())
  2492. getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
  2493. }
  2494. static bool classof(const Stmt *T) {
  2495. return T->getStmtClass() == UnresolvedLookupExprClass ||
  2496. T->getStmtClass() == UnresolvedMemberExprClass;
  2497. }
  2498. };
  2499. /// A reference to a name which we were able to look up during
  2500. /// parsing but could not resolve to a specific declaration.
  2501. ///
  2502. /// This arises in several ways:
  2503. /// * we might be waiting for argument-dependent lookup;
  2504. /// * the name might resolve to an overloaded function;
  2505. /// and eventually:
  2506. /// * the lookup might have included a function template.
  2507. ///
  2508. /// These never include UnresolvedUsingValueDecls, which are always class
  2509. /// members and therefore appear only in UnresolvedMemberLookupExprs.
  2510. class UnresolvedLookupExpr final
  2511. : public OverloadExpr,
  2512. private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair,
  2513. ASTTemplateKWAndArgsInfo,
  2514. TemplateArgumentLoc> {
  2515. friend class ASTStmtReader;
  2516. friend class OverloadExpr;
  2517. friend TrailingObjects;
  2518. /// The naming class (C++ [class.access.base]p5) of the lookup, if
  2519. /// any. This can generally be recalculated from the context chain,
  2520. /// but that can be fairly expensive for unqualified lookups.
  2521. CXXRecordDecl *NamingClass;
  2522. // UnresolvedLookupExpr is followed by several trailing objects.
  2523. // They are in order:
  2524. //
  2525. // * An array of getNumResults() DeclAccessPair for the results. These are
  2526. // undesugared, which is to say, they may include UsingShadowDecls.
  2527. // Access is relative to the naming class.
  2528. //
  2529. // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
  2530. // template keyword and arguments. Present if and only if
  2531. // hasTemplateKWAndArgsInfo().
  2532. //
  2533. // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
  2534. // location information for the explicitly specified template arguments.
  2535. UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass,
  2536. NestedNameSpecifierLoc QualifierLoc,
  2537. SourceLocation TemplateKWLoc,
  2538. const DeclarationNameInfo &NameInfo, bool RequiresADL,
  2539. bool Overloaded,
  2540. const TemplateArgumentListInfo *TemplateArgs,
  2541. UnresolvedSetIterator Begin, UnresolvedSetIterator End);
  2542. UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
  2543. bool HasTemplateKWAndArgsInfo);
  2544. unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
  2545. return getNumDecls();
  2546. }
  2547. unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
  2548. return hasTemplateKWAndArgsInfo();
  2549. }
  2550. public:
  2551. static UnresolvedLookupExpr *
  2552. Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  2553. NestedNameSpecifierLoc QualifierLoc,
  2554. const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
  2555. UnresolvedSetIterator Begin, UnresolvedSetIterator End);
  2556. static UnresolvedLookupExpr *
  2557. Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  2558. NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  2559. const DeclarationNameInfo &NameInfo, bool RequiresADL,
  2560. const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
  2561. UnresolvedSetIterator End);
  2562. static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
  2563. unsigned NumResults,
  2564. bool HasTemplateKWAndArgsInfo,
  2565. unsigned NumTemplateArgs);
  2566. /// True if this declaration should be extended by
  2567. /// argument-dependent lookup.
  2568. bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; }
  2569. /// True if this lookup is overloaded.
  2570. bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; }
  2571. /// Gets the 'naming class' (in the sense of C++0x
  2572. /// [class.access.base]p5) of the lookup. This is the scope
  2573. /// that was looked in to find these results.
  2574. CXXRecordDecl *getNamingClass() { return NamingClass; }
  2575. const CXXRecordDecl *getNamingClass() const { return NamingClass; }
  2576. SourceLocation getBeginLoc() const LLVM_READONLY {
  2577. if (NestedNameSpecifierLoc l = getQualifierLoc())
  2578. return l.getBeginLoc();
  2579. return getNameInfo().getBeginLoc();
  2580. }
  2581. SourceLocation getEndLoc() const LLVM_READONLY {
  2582. if (hasExplicitTemplateArgs())
  2583. return getRAngleLoc();
  2584. return getNameInfo().getEndLoc();
  2585. }
  2586. child_range children() {
  2587. return child_range(child_iterator(), child_iterator());
  2588. }
  2589. const_child_range children() const {
  2590. return const_child_range(const_child_iterator(), const_child_iterator());
  2591. }
  2592. static bool classof(const Stmt *T) {
  2593. return T->getStmtClass() == UnresolvedLookupExprClass;
  2594. }
  2595. };
  2596. /// A qualified reference to a name whose declaration cannot
  2597. /// yet be resolved.
  2598. ///
  2599. /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
  2600. /// it expresses a reference to a declaration such as
  2601. /// X<T>::value. The difference, however, is that an
  2602. /// DependentScopeDeclRefExpr node is used only within C++ templates when
  2603. /// the qualification (e.g., X<T>::) refers to a dependent type. In
  2604. /// this case, X<T>::value cannot resolve to a declaration because the
  2605. /// declaration will differ from one instantiation of X<T> to the
  2606. /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
  2607. /// qualifier (X<T>::) and the name of the entity being referenced
  2608. /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
  2609. /// declaration can be found.
  2610. class DependentScopeDeclRefExpr final
  2611. : public Expr,
  2612. private llvm::TrailingObjects<DependentScopeDeclRefExpr,
  2613. ASTTemplateKWAndArgsInfo,
  2614. TemplateArgumentLoc> {
  2615. friend class ASTStmtReader;
  2616. friend class ASTStmtWriter;
  2617. friend TrailingObjects;
  2618. /// The nested-name-specifier that qualifies this unresolved
  2619. /// declaration name.
  2620. NestedNameSpecifierLoc QualifierLoc;
  2621. /// The name of the entity we will be referencing.
  2622. DeclarationNameInfo NameInfo;
  2623. DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc,
  2624. SourceLocation TemplateKWLoc,
  2625. const DeclarationNameInfo &NameInfo,
  2626. const TemplateArgumentListInfo *Args);
  2627. size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
  2628. return hasTemplateKWAndArgsInfo();
  2629. }
  2630. bool hasTemplateKWAndArgsInfo() const {
  2631. return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo;
  2632. }
  2633. public:
  2634. static DependentScopeDeclRefExpr *
  2635. Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
  2636. SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
  2637. const TemplateArgumentListInfo *TemplateArgs);
  2638. static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context,
  2639. bool HasTemplateKWAndArgsInfo,
  2640. unsigned NumTemplateArgs);
  2641. /// Retrieve the name that this expression refers to.
  2642. const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
  2643. /// Retrieve the name that this expression refers to.
  2644. DeclarationName getDeclName() const { return NameInfo.getName(); }
  2645. /// Retrieve the location of the name within the expression.
  2646. ///
  2647. /// For example, in "X<T>::value" this is the location of "value".
  2648. SourceLocation getLocation() const { return NameInfo.getLoc(); }
  2649. /// Retrieve the nested-name-specifier that qualifies the
  2650. /// name, with source location information.
  2651. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  2652. /// Retrieve the nested-name-specifier that qualifies this
  2653. /// declaration.
  2654. NestedNameSpecifier *getQualifier() const {
  2655. return QualifierLoc.getNestedNameSpecifier();
  2656. }
  2657. /// Retrieve the location of the template keyword preceding
  2658. /// this name, if any.
  2659. SourceLocation getTemplateKeywordLoc() const {
  2660. if (!hasTemplateKWAndArgsInfo())
  2661. return SourceLocation();
  2662. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
  2663. }
  2664. /// Retrieve the location of the left angle bracket starting the
  2665. /// explicit template argument list following the name, if any.
  2666. SourceLocation getLAngleLoc() const {
  2667. if (!hasTemplateKWAndArgsInfo())
  2668. return SourceLocation();
  2669. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
  2670. }
  2671. /// Retrieve the location of the right angle bracket ending the
  2672. /// explicit template argument list following the name, if any.
  2673. SourceLocation getRAngleLoc() const {
  2674. if (!hasTemplateKWAndArgsInfo())
  2675. return SourceLocation();
  2676. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
  2677. }
  2678. /// Determines whether the name was preceded by the template keyword.
  2679. bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
  2680. /// Determines whether this lookup had explicit template arguments.
  2681. bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
  2682. /// Copies the template arguments (if present) into the given
  2683. /// structure.
  2684. void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
  2685. if (hasExplicitTemplateArgs())
  2686. getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
  2687. getTrailingObjects<TemplateArgumentLoc>(), List);
  2688. }
  2689. TemplateArgumentLoc const *getTemplateArgs() const {
  2690. if (!hasExplicitTemplateArgs())
  2691. return nullptr;
  2692. return getTrailingObjects<TemplateArgumentLoc>();
  2693. }
  2694. unsigned getNumTemplateArgs() const {
  2695. if (!hasExplicitTemplateArgs())
  2696. return 0;
  2697. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
  2698. }
  2699. ArrayRef<TemplateArgumentLoc> template_arguments() const {
  2700. return {getTemplateArgs(), getNumTemplateArgs()};
  2701. }
  2702. /// Note: getBeginLoc() is the start of the whole DependentScopeDeclRefExpr,
  2703. /// and differs from getLocation().getStart().
  2704. SourceLocation getBeginLoc() const LLVM_READONLY {
  2705. return QualifierLoc.getBeginLoc();
  2706. }
  2707. SourceLocation getEndLoc() const LLVM_READONLY {
  2708. if (hasExplicitTemplateArgs())
  2709. return getRAngleLoc();
  2710. return getLocation();
  2711. }
  2712. static bool classof(const Stmt *T) {
  2713. return T->getStmtClass() == DependentScopeDeclRefExprClass;
  2714. }
  2715. child_range children() {
  2716. return child_range(child_iterator(), child_iterator());
  2717. }
  2718. const_child_range children() const {
  2719. return const_child_range(const_child_iterator(), const_child_iterator());
  2720. }
  2721. };
  2722. /// Represents an expression -- generally a full-expression -- that
  2723. /// introduces cleanups to be run at the end of the sub-expression's
  2724. /// evaluation. The most common source of expression-introduced
  2725. /// cleanups is temporary objects in C++, but several other kinds of
  2726. /// expressions can create cleanups, including basically every
  2727. /// call in ARC that returns an Objective-C pointer.
  2728. ///
  2729. /// This expression also tracks whether the sub-expression contains a
  2730. /// potentially-evaluated block literal. The lifetime of a block
  2731. /// literal is the extent of the enclosing scope.
  2732. class ExprWithCleanups final
  2733. : public FullExpr,
  2734. private llvm::TrailingObjects<
  2735. ExprWithCleanups,
  2736. llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>> {
  2737. public:
  2738. /// The type of objects that are kept in the cleanup.
  2739. /// It's useful to remember the set of blocks and block-scoped compound
  2740. /// literals; we could also remember the set of temporaries, but there's
  2741. /// currently no need.
  2742. using CleanupObject = llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>;
  2743. private:
  2744. friend class ASTStmtReader;
  2745. friend TrailingObjects;
  2746. ExprWithCleanups(EmptyShell, unsigned NumObjects);
  2747. ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
  2748. ArrayRef<CleanupObject> Objects);
  2749. public:
  2750. static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
  2751. unsigned numObjects);
  2752. static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
  2753. bool CleanupsHaveSideEffects,
  2754. ArrayRef<CleanupObject> objects);
  2755. ArrayRef<CleanupObject> getObjects() const {
  2756. return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
  2757. getNumObjects());
  2758. }
  2759. unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
  2760. CleanupObject getObject(unsigned i) const {
  2761. assert(i < getNumObjects() && "Index out of range");
  2762. return getObjects()[i];
  2763. }
  2764. bool cleanupsHaveSideEffects() const {
  2765. return ExprWithCleanupsBits.CleanupsHaveSideEffects;
  2766. }
  2767. SourceLocation getBeginLoc() const LLVM_READONLY {
  2768. return SubExpr->getBeginLoc();
  2769. }
  2770. SourceLocation getEndLoc() const LLVM_READONLY {
  2771. return SubExpr->getEndLoc();
  2772. }
  2773. // Implement isa/cast/dyncast/etc.
  2774. static bool classof(const Stmt *T) {
  2775. return T->getStmtClass() == ExprWithCleanupsClass;
  2776. }
  2777. // Iterators
  2778. child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
  2779. const_child_range children() const {
  2780. return const_child_range(&SubExpr, &SubExpr + 1);
  2781. }
  2782. };
  2783. /// Describes an explicit type conversion that uses functional
  2784. /// notion but could not be resolved because one or more arguments are
  2785. /// type-dependent.
  2786. ///
  2787. /// The explicit type conversions expressed by
  2788. /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
  2789. /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
  2790. /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
  2791. /// type-dependent. For example, this would occur in a template such
  2792. /// as:
  2793. ///
  2794. /// \code
  2795. /// template<typename T, typename A1>
  2796. /// inline T make_a(const A1& a1) {
  2797. /// return T(a1);
  2798. /// }
  2799. /// \endcode
  2800. ///
  2801. /// When the returned expression is instantiated, it may resolve to a
  2802. /// constructor call, conversion function call, or some kind of type
  2803. /// conversion.
  2804. class CXXUnresolvedConstructExpr final
  2805. : public Expr,
  2806. private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
  2807. friend class ASTStmtReader;
  2808. friend TrailingObjects;
  2809. /// The type being constructed.
  2810. TypeSourceInfo *TSI;
  2811. /// The location of the left parentheses ('(').
  2812. SourceLocation LParenLoc;
  2813. /// The location of the right parentheses (')').
  2814. SourceLocation RParenLoc;
  2815. CXXUnresolvedConstructExpr(QualType T, TypeSourceInfo *TSI,
  2816. SourceLocation LParenLoc, ArrayRef<Expr *> Args,
  2817. SourceLocation RParenLoc);
  2818. CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
  2819. : Expr(CXXUnresolvedConstructExprClass, Empty), TSI(nullptr) {
  2820. CXXUnresolvedConstructExprBits.NumArgs = NumArgs;
  2821. }
  2822. public:
  2823. static CXXUnresolvedConstructExpr *Create(const ASTContext &Context,
  2824. QualType T, TypeSourceInfo *TSI,
  2825. SourceLocation LParenLoc,
  2826. ArrayRef<Expr *> Args,
  2827. SourceLocation RParenLoc);
  2828. static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context,
  2829. unsigned NumArgs);
  2830. /// Retrieve the type that is being constructed, as specified
  2831. /// in the source code.
  2832. QualType getTypeAsWritten() const { return TSI->getType(); }
  2833. /// Retrieve the type source information for the type being
  2834. /// constructed.
  2835. TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
  2836. /// Retrieve the location of the left parentheses ('(') that
  2837. /// precedes the argument list.
  2838. SourceLocation getLParenLoc() const { return LParenLoc; }
  2839. void setLParenLoc(SourceLocation L) { LParenLoc = L; }
  2840. /// Retrieve the location of the right parentheses (')') that
  2841. /// follows the argument list.
  2842. SourceLocation getRParenLoc() const { return RParenLoc; }
  2843. void setRParenLoc(SourceLocation L) { RParenLoc = L; }
  2844. /// Determine whether this expression models list-initialization.
  2845. /// If so, there will be exactly one subexpression, which will be
  2846. /// an InitListExpr.
  2847. bool isListInitialization() const { return LParenLoc.isInvalid(); }
  2848. /// Retrieve the number of arguments.
  2849. unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; }
  2850. using arg_iterator = Expr **;
  2851. using arg_range = llvm::iterator_range<arg_iterator>;
  2852. arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
  2853. arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
  2854. arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
  2855. using const_arg_iterator = const Expr* const *;
  2856. using const_arg_range = llvm::iterator_range<const_arg_iterator>;
  2857. const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
  2858. const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
  2859. const_arg_range arguments() const {
  2860. return const_arg_range(arg_begin(), arg_end());
  2861. }
  2862. Expr *getArg(unsigned I) {
  2863. assert(I < getNumArgs() && "Argument index out-of-range");
  2864. return arg_begin()[I];
  2865. }
  2866. const Expr *getArg(unsigned I) const {
  2867. assert(I < getNumArgs() && "Argument index out-of-range");
  2868. return arg_begin()[I];
  2869. }
  2870. void setArg(unsigned I, Expr *E) {
  2871. assert(I < getNumArgs() && "Argument index out-of-range");
  2872. arg_begin()[I] = E;
  2873. }
  2874. SourceLocation getBeginLoc() const LLVM_READONLY;
  2875. SourceLocation getEndLoc() const LLVM_READONLY {
  2876. if (!RParenLoc.isValid() && getNumArgs() > 0)
  2877. return getArg(getNumArgs() - 1)->getEndLoc();
  2878. return RParenLoc;
  2879. }
  2880. static bool classof(const Stmt *T) {
  2881. return T->getStmtClass() == CXXUnresolvedConstructExprClass;
  2882. }
  2883. // Iterators
  2884. child_range children() {
  2885. auto **begin = reinterpret_cast<Stmt **>(arg_begin());
  2886. return child_range(begin, begin + getNumArgs());
  2887. }
  2888. const_child_range children() const {
  2889. auto **begin = reinterpret_cast<Stmt **>(
  2890. const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin());
  2891. return const_child_range(begin, begin + getNumArgs());
  2892. }
  2893. };
  2894. /// Represents a C++ member access expression where the actual
  2895. /// member referenced could not be resolved because the base
  2896. /// expression or the member name was dependent.
  2897. ///
  2898. /// Like UnresolvedMemberExprs, these can be either implicit or
  2899. /// explicit accesses. It is only possible to get one of these with
  2900. /// an implicit access if a qualifier is provided.
  2901. class CXXDependentScopeMemberExpr final
  2902. : public Expr,
  2903. private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
  2904. ASTTemplateKWAndArgsInfo,
  2905. TemplateArgumentLoc, NamedDecl *> {
  2906. friend class ASTStmtReader;
  2907. friend class ASTStmtWriter;
  2908. friend TrailingObjects;
  2909. /// The expression for the base pointer or class reference,
  2910. /// e.g., the \c x in x.f. Can be null in implicit accesses.
  2911. Stmt *Base;
  2912. /// The type of the base expression. Never null, even for
  2913. /// implicit accesses.
  2914. QualType BaseType;
  2915. /// The nested-name-specifier that precedes the member name, if any.
  2916. /// FIXME: This could be in principle store as a trailing object.
  2917. /// However the performance impact of doing so should be investigated first.
  2918. NestedNameSpecifierLoc QualifierLoc;
  2919. /// The member to which this member expression refers, which
  2920. /// can be name, overloaded operator, or destructor.
  2921. ///
  2922. /// FIXME: could also be a template-id
  2923. DeclarationNameInfo MemberNameInfo;
  2924. // CXXDependentScopeMemberExpr is followed by several trailing objects,
  2925. // some of which optional. They are in order:
  2926. //
  2927. // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
  2928. // template keyword and arguments. Present if and only if
  2929. // hasTemplateKWAndArgsInfo().
  2930. //
  2931. // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location
  2932. // information for the explicitly specified template arguments.
  2933. //
  2934. // * An optional NamedDecl *. In a qualified member access expression such
  2935. // as t->Base::f, this member stores the resolves of name lookup in the
  2936. // context of the member access expression, to be used at instantiation
  2937. // time. Present if and only if hasFirstQualifierFoundInScope().
  2938. bool hasTemplateKWAndArgsInfo() const {
  2939. return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo;
  2940. }
  2941. bool hasFirstQualifierFoundInScope() const {
  2942. return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope;
  2943. }
  2944. unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
  2945. return hasTemplateKWAndArgsInfo();
  2946. }
  2947. unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const {
  2948. return getNumTemplateArgs();
  2949. }
  2950. unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const {
  2951. return hasFirstQualifierFoundInScope();
  2952. }
  2953. CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base,
  2954. QualType BaseType, bool IsArrow,
  2955. SourceLocation OperatorLoc,
  2956. NestedNameSpecifierLoc QualifierLoc,
  2957. SourceLocation TemplateKWLoc,
  2958. NamedDecl *FirstQualifierFoundInScope,
  2959. DeclarationNameInfo MemberNameInfo,
  2960. const TemplateArgumentListInfo *TemplateArgs);
  2961. CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
  2962. bool HasFirstQualifierFoundInScope);
  2963. public:
  2964. static CXXDependentScopeMemberExpr *
  2965. Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
  2966. SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
  2967. SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
  2968. DeclarationNameInfo MemberNameInfo,
  2969. const TemplateArgumentListInfo *TemplateArgs);
  2970. static CXXDependentScopeMemberExpr *
  2971. CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
  2972. unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope);
  2973. /// True if this is an implicit access, i.e. one in which the
  2974. /// member being accessed was not written in the source. The source
  2975. /// location of the operator is invalid in this case.
  2976. bool isImplicitAccess() const {
  2977. if (!Base)
  2978. return true;
  2979. return cast<Expr>(Base)->isImplicitCXXThis();
  2980. }
  2981. /// Retrieve the base object of this member expressions,
  2982. /// e.g., the \c x in \c x.m.
  2983. Expr *getBase() const {
  2984. assert(!isImplicitAccess());
  2985. return cast<Expr>(Base);
  2986. }
  2987. QualType getBaseType() const { return BaseType; }
  2988. /// Determine whether this member expression used the '->'
  2989. /// operator; otherwise, it used the '.' operator.
  2990. bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; }
  2991. /// Retrieve the location of the '->' or '.' operator.
  2992. SourceLocation getOperatorLoc() const {
  2993. return CXXDependentScopeMemberExprBits.OperatorLoc;
  2994. }
  2995. /// Retrieve the nested-name-specifier that qualifies the member name.
  2996. NestedNameSpecifier *getQualifier() const {
  2997. return QualifierLoc.getNestedNameSpecifier();
  2998. }
  2999. /// Retrieve the nested-name-specifier that qualifies the member
  3000. /// name, with source location information.
  3001. NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
  3002. /// Retrieve the first part of the nested-name-specifier that was
  3003. /// found in the scope of the member access expression when the member access
  3004. /// was initially parsed.
  3005. ///
  3006. /// This function only returns a useful result when member access expression
  3007. /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
  3008. /// returned by this function describes what was found by unqualified name
  3009. /// lookup for the identifier "Base" within the scope of the member access
  3010. /// expression itself. At template instantiation time, this information is
  3011. /// combined with the results of name lookup into the type of the object
  3012. /// expression itself (the class type of x).
  3013. NamedDecl *getFirstQualifierFoundInScope() const {
  3014. if (!hasFirstQualifierFoundInScope())
  3015. return nullptr;
  3016. return *getTrailingObjects<NamedDecl *>();
  3017. }
  3018. /// Retrieve the name of the member that this expression refers to.
  3019. const DeclarationNameInfo &getMemberNameInfo() const {
  3020. return MemberNameInfo;
  3021. }
  3022. /// Retrieve the name of the member that this expression refers to.
  3023. DeclarationName getMember() const { return MemberNameInfo.getName(); }
  3024. // Retrieve the location of the name of the member that this
  3025. // expression refers to.
  3026. SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
  3027. /// Retrieve the location of the template keyword preceding the
  3028. /// member name, if any.
  3029. SourceLocation getTemplateKeywordLoc() const {
  3030. if (!hasTemplateKWAndArgsInfo())
  3031. return SourceLocation();
  3032. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
  3033. }
  3034. /// Retrieve the location of the left angle bracket starting the
  3035. /// explicit template argument list following the member name, if any.
  3036. SourceLocation getLAngleLoc() const {
  3037. if (!hasTemplateKWAndArgsInfo())
  3038. return SourceLocation();
  3039. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
  3040. }
  3041. /// Retrieve the location of the right angle bracket ending the
  3042. /// explicit template argument list following the member name, if any.
  3043. SourceLocation getRAngleLoc() const {
  3044. if (!hasTemplateKWAndArgsInfo())
  3045. return SourceLocation();
  3046. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
  3047. }
  3048. /// Determines whether the member name was preceded by the template keyword.
  3049. bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
  3050. /// Determines whether this member expression actually had a C++
  3051. /// template argument list explicitly specified, e.g., x.f<int>.
  3052. bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
  3053. /// Copies the template arguments (if present) into the given
  3054. /// structure.
  3055. void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
  3056. if (hasExplicitTemplateArgs())
  3057. getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
  3058. getTrailingObjects<TemplateArgumentLoc>(), List);
  3059. }
  3060. /// Retrieve the template arguments provided as part of this
  3061. /// template-id.
  3062. const TemplateArgumentLoc *getTemplateArgs() const {
  3063. if (!hasExplicitTemplateArgs())
  3064. return nullptr;
  3065. return getTrailingObjects<TemplateArgumentLoc>();
  3066. }
  3067. /// Retrieve the number of template arguments provided as part of this
  3068. /// template-id.
  3069. unsigned getNumTemplateArgs() const {
  3070. if (!hasExplicitTemplateArgs())
  3071. return 0;
  3072. return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
  3073. }
  3074. ArrayRef<TemplateArgumentLoc> template_arguments() const {
  3075. return {getTemplateArgs(), getNumTemplateArgs()};
  3076. }
  3077. SourceLocation getBeginLoc() const LLVM_READONLY {
  3078. if (!isImplicitAccess())
  3079. return Base->getBeginLoc();
  3080. if (getQualifier())
  3081. return getQualifierLoc().getBeginLoc();
  3082. return MemberNameInfo.getBeginLoc();
  3083. }
  3084. SourceLocation getEndLoc() const LLVM_READONLY {
  3085. if (hasExplicitTemplateArgs())
  3086. return getRAngleLoc();
  3087. return MemberNameInfo.getEndLoc();
  3088. }
  3089. static bool classof(const Stmt *T) {
  3090. return T->getStmtClass() == CXXDependentScopeMemberExprClass;
  3091. }
  3092. // Iterators
  3093. child_range children() {
  3094. if (isImplicitAccess())
  3095. return child_range(child_iterator(), child_iterator());
  3096. return child_range(&Base, &Base + 1);
  3097. }
  3098. const_child_range children() const {
  3099. if (isImplicitAccess())
  3100. return const_child_range(const_child_iterator(), const_child_iterator());
  3101. return const_child_range(&Base, &Base + 1);
  3102. }
  3103. };
  3104. /// Represents a C++ member access expression for which lookup
  3105. /// produced a set of overloaded functions.
  3106. ///
  3107. /// The member access may be explicit or implicit:
  3108. /// \code
  3109. /// struct A {
  3110. /// int a, b;
  3111. /// int explicitAccess() { return this->a + this->A::b; }
  3112. /// int implicitAccess() { return a + A::b; }
  3113. /// };
  3114. /// \endcode
  3115. ///
  3116. /// In the final AST, an explicit access always becomes a MemberExpr.
  3117. /// An implicit access may become either a MemberExpr or a
  3118. /// DeclRefExpr, depending on whether the member is static.
  3119. class UnresolvedMemberExpr final
  3120. : public OverloadExpr,
  3121. private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair,
  3122. ASTTemplateKWAndArgsInfo,
  3123. TemplateArgumentLoc> {
  3124. friend class ASTStmtReader;
  3125. friend class OverloadExpr;
  3126. friend TrailingObjects;
  3127. /// The expression for the base pointer or class reference,
  3128. /// e.g., the \c x in x.f.
  3129. ///
  3130. /// This can be null if this is an 'unbased' member expression.
  3131. Stmt *Base;
  3132. /// The type of the base expression; never null.
  3133. QualType BaseType;
  3134. /// The location of the '->' or '.' operator.
  3135. SourceLocation OperatorLoc;
  3136. // UnresolvedMemberExpr is followed by several trailing objects.
  3137. // They are in order:
  3138. //
  3139. // * An array of getNumResults() DeclAccessPair for the results. These are
  3140. // undesugared, which is to say, they may include UsingShadowDecls.
  3141. // Access is relative to the naming class.
  3142. //
  3143. // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
  3144. // template keyword and arguments. Present if and only if
  3145. // hasTemplateKWAndArgsInfo().
  3146. //
  3147. // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
  3148. // location information for the explicitly specified template arguments.
  3149. UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing,
  3150. Expr *Base, QualType BaseType, bool IsArrow,
  3151. SourceLocation OperatorLoc,
  3152. NestedNameSpecifierLoc QualifierLoc,
  3153. SourceLocation TemplateKWLoc,
  3154. const DeclarationNameInfo &MemberNameInfo,
  3155. const TemplateArgumentListInfo *TemplateArgs,
  3156. UnresolvedSetIterator Begin, UnresolvedSetIterator End);
  3157. UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults,
  3158. bool HasTemplateKWAndArgsInfo);
  3159. unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
  3160. return getNumDecls();
  3161. }
  3162. unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
  3163. return hasTemplateKWAndArgsInfo();
  3164. }
  3165. public:
  3166. static UnresolvedMemberExpr *
  3167. Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
  3168. QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
  3169. NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  3170. const DeclarationNameInfo &MemberNameInfo,
  3171. const TemplateArgumentListInfo *TemplateArgs,
  3172. UnresolvedSetIterator Begin, UnresolvedSetIterator End);
  3173. static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context,
  3174. unsigned NumResults,
  3175. bool HasTemplateKWAndArgsInfo,
  3176. unsigned NumTemplateArgs);
  3177. /// True if this is an implicit access, i.e., one in which the
  3178. /// member being accessed was not written in the source.
  3179. ///
  3180. /// The source location of the operator is invalid in this case.
  3181. bool isImplicitAccess() const;
  3182. /// Retrieve the base object of this member expressions,
  3183. /// e.g., the \c x in \c x.m.
  3184. Expr *getBase() {
  3185. assert(!isImplicitAccess());
  3186. return cast<Expr>(Base);
  3187. }
  3188. const Expr *getBase() const {
  3189. assert(!isImplicitAccess());
  3190. return cast<Expr>(Base);
  3191. }
  3192. QualType getBaseType() const { return BaseType; }
  3193. /// Determine whether the lookup results contain an unresolved using
  3194. /// declaration.
  3195. bool hasUnresolvedUsing() const {
  3196. return UnresolvedMemberExprBits.HasUnresolvedUsing;
  3197. }
  3198. /// Determine whether this member expression used the '->'
  3199. /// operator; otherwise, it used the '.' operator.
  3200. bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; }
  3201. /// Retrieve the location of the '->' or '.' operator.
  3202. SourceLocation getOperatorLoc() const { return OperatorLoc; }
  3203. /// Retrieve the naming class of this lookup.
  3204. CXXRecordDecl *getNamingClass();
  3205. const CXXRecordDecl *getNamingClass() const {
  3206. return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass();
  3207. }
  3208. /// Retrieve the full name info for the member that this expression
  3209. /// refers to.
  3210. const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
  3211. /// Retrieve the name of the member that this expression refers to.
  3212. DeclarationName getMemberName() const { return getName(); }
  3213. /// Retrieve the location of the name of the member that this
  3214. /// expression refers to.
  3215. SourceLocation getMemberLoc() const { return getNameLoc(); }
  3216. /// Return the preferred location (the member name) for the arrow when
  3217. /// diagnosing a problem with this expression.
  3218. SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
  3219. SourceLocation getBeginLoc() const LLVM_READONLY {
  3220. if (!isImplicitAccess())
  3221. return Base->getBeginLoc();
  3222. if (NestedNameSpecifierLoc l = getQualifierLoc())
  3223. return l.getBeginLoc();
  3224. return getMemberNameInfo().getBeginLoc();
  3225. }
  3226. SourceLocation getEndLoc() const LLVM_READONLY {
  3227. if (hasExplicitTemplateArgs())
  3228. return getRAngleLoc();
  3229. return getMemberNameInfo().getEndLoc();
  3230. }
  3231. static bool classof(const Stmt *T) {
  3232. return T->getStmtClass() == UnresolvedMemberExprClass;
  3233. }
  3234. // Iterators
  3235. child_range children() {
  3236. if (isImplicitAccess())
  3237. return child_range(child_iterator(), child_iterator());
  3238. return child_range(&Base, &Base + 1);
  3239. }
  3240. const_child_range children() const {
  3241. if (isImplicitAccess())
  3242. return const_child_range(const_child_iterator(), const_child_iterator());
  3243. return const_child_range(&Base, &Base + 1);
  3244. }
  3245. };
  3246. DeclAccessPair *OverloadExpr::getTrailingResults() {
  3247. if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
  3248. return ULE->getTrailingObjects<DeclAccessPair>();
  3249. return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>();
  3250. }
  3251. ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
  3252. if (!hasTemplateKWAndArgsInfo())
  3253. return nullptr;
  3254. if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
  3255. return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
  3256. return cast<UnresolvedMemberExpr>(this)
  3257. ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
  3258. }
  3259. TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
  3260. if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
  3261. return ULE->getTrailingObjects<TemplateArgumentLoc>();
  3262. return cast<UnresolvedMemberExpr>(this)
  3263. ->getTrailingObjects<TemplateArgumentLoc>();
  3264. }
  3265. CXXRecordDecl *OverloadExpr::getNamingClass() {
  3266. if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
  3267. return ULE->getNamingClass();
  3268. return cast<UnresolvedMemberExpr>(this)->getNamingClass();
  3269. }
  3270. /// Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
  3271. ///
  3272. /// The noexcept expression tests whether a given expression might throw. Its
  3273. /// result is a boolean constant.
  3274. class CXXNoexceptExpr : public Expr {
  3275. friend class ASTStmtReader;
  3276. Stmt *Operand;
  3277. SourceRange Range;
  3278. public:
  3279. CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
  3280. SourceLocation Keyword, SourceLocation RParen)
  3281. : Expr(CXXNoexceptExprClass, Ty, VK_PRValue, OK_Ordinary),
  3282. Operand(Operand), Range(Keyword, RParen) {
  3283. CXXNoexceptExprBits.Value = Val == CT_Cannot;
  3284. setDependence(computeDependence(this, Val));
  3285. }
  3286. CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {}
  3287. Expr *getOperand() const { return static_cast<Expr *>(Operand); }
  3288. SourceLocation getBeginLoc() const { return Range.getBegin(); }
  3289. SourceLocation getEndLoc() const { return Range.getEnd(); }
  3290. SourceRange getSourceRange() const { return Range; }
  3291. bool getValue() const { return CXXNoexceptExprBits.Value; }
  3292. static bool classof(const Stmt *T) {
  3293. return T->getStmtClass() == CXXNoexceptExprClass;
  3294. }
  3295. // Iterators
  3296. child_range children() { return child_range(&Operand, &Operand + 1); }
  3297. const_child_range children() const {
  3298. return const_child_range(&Operand, &Operand + 1);
  3299. }
  3300. };
  3301. /// Represents a C++11 pack expansion that produces a sequence of
  3302. /// expressions.
  3303. ///
  3304. /// A pack expansion expression contains a pattern (which itself is an
  3305. /// expression) followed by an ellipsis. For example:
  3306. ///
  3307. /// \code
  3308. /// template<typename F, typename ...Types>
  3309. /// void forward(F f, Types &&...args) {
  3310. /// f(static_cast<Types&&>(args)...);
  3311. /// }
  3312. /// \endcode
  3313. ///
  3314. /// Here, the argument to the function object \c f is a pack expansion whose
  3315. /// pattern is \c static_cast<Types&&>(args). When the \c forward function
  3316. /// template is instantiated, the pack expansion will instantiate to zero or
  3317. /// or more function arguments to the function object \c f.
  3318. class PackExpansionExpr : public Expr {
  3319. friend class ASTStmtReader;
  3320. friend class ASTStmtWriter;
  3321. SourceLocation EllipsisLoc;
  3322. /// The number of expansions that will be produced by this pack
  3323. /// expansion expression, if known.
  3324. ///
  3325. /// When zero, the number of expansions is not known. Otherwise, this value
  3326. /// is the number of expansions + 1.
  3327. unsigned NumExpansions;
  3328. Stmt *Pattern;
  3329. public:
  3330. PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
  3331. Optional<unsigned> NumExpansions)
  3332. : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
  3333. Pattern->getObjectKind()),
  3334. EllipsisLoc(EllipsisLoc),
  3335. NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
  3336. Pattern(Pattern) {
  3337. setDependence(computeDependence(this));
  3338. }
  3339. PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {}
  3340. /// Retrieve the pattern of the pack expansion.
  3341. Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
  3342. /// Retrieve the pattern of the pack expansion.
  3343. const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
  3344. /// Retrieve the location of the ellipsis that describes this pack
  3345. /// expansion.
  3346. SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
  3347. /// Determine the number of expansions that will be produced when
  3348. /// this pack expansion is instantiated, if already known.
  3349. Optional<unsigned> getNumExpansions() const {
  3350. if (NumExpansions)
  3351. return NumExpansions - 1;
  3352. return None;
  3353. }
  3354. SourceLocation getBeginLoc() const LLVM_READONLY {
  3355. return Pattern->getBeginLoc();
  3356. }
  3357. SourceLocation getEndLoc() const LLVM_READONLY { return EllipsisLoc; }
  3358. static bool classof(const Stmt *T) {
  3359. return T->getStmtClass() == PackExpansionExprClass;
  3360. }
  3361. // Iterators
  3362. child_range children() {
  3363. return child_range(&Pattern, &Pattern + 1);
  3364. }
  3365. const_child_range children() const {
  3366. return const_child_range(&Pattern, &Pattern + 1);
  3367. }
  3368. };
  3369. /// Represents an expression that computes the length of a parameter
  3370. /// pack.
  3371. ///
  3372. /// \code
  3373. /// template<typename ...Types>
  3374. /// struct count {
  3375. /// static const unsigned value = sizeof...(Types);
  3376. /// };
  3377. /// \endcode
  3378. class SizeOfPackExpr final
  3379. : public Expr,
  3380. private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
  3381. friend class ASTStmtReader;
  3382. friend class ASTStmtWriter;
  3383. friend TrailingObjects;
  3384. /// The location of the \c sizeof keyword.
  3385. SourceLocation OperatorLoc;
  3386. /// The location of the name of the parameter pack.
  3387. SourceLocation PackLoc;
  3388. /// The location of the closing parenthesis.
  3389. SourceLocation RParenLoc;
  3390. /// The length of the parameter pack, if known.
  3391. ///
  3392. /// When this expression is not value-dependent, this is the length of
  3393. /// the pack. When the expression was parsed rather than instantiated
  3394. /// (and thus is value-dependent), this is zero.
  3395. ///
  3396. /// After partial substitution into a sizeof...(X) expression (for instance,
  3397. /// within an alias template or during function template argument deduction),
  3398. /// we store a trailing array of partially-substituted TemplateArguments,
  3399. /// and this is the length of that array.
  3400. unsigned Length;
  3401. /// The parameter pack.
  3402. NamedDecl *Pack = nullptr;
  3403. /// Create an expression that computes the length of
  3404. /// the given parameter pack.
  3405. SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
  3406. SourceLocation PackLoc, SourceLocation RParenLoc,
  3407. Optional<unsigned> Length,
  3408. ArrayRef<TemplateArgument> PartialArgs)
  3409. : Expr(SizeOfPackExprClass, SizeType, VK_PRValue, OK_Ordinary),
  3410. OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
  3411. Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
  3412. assert((!Length || PartialArgs.empty()) &&
  3413. "have partial args for non-dependent sizeof... expression");
  3414. auto *Args = getTrailingObjects<TemplateArgument>();
  3415. std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
  3416. setDependence(Length ? ExprDependence::None
  3417. : ExprDependence::ValueInstantiation);
  3418. }
  3419. /// Create an empty expression.
  3420. SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
  3421. : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
  3422. public:
  3423. static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
  3424. NamedDecl *Pack, SourceLocation PackLoc,
  3425. SourceLocation RParenLoc,
  3426. Optional<unsigned> Length = None,
  3427. ArrayRef<TemplateArgument> PartialArgs = None);
  3428. static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
  3429. unsigned NumPartialArgs);
  3430. /// Determine the location of the 'sizeof' keyword.
  3431. SourceLocation getOperatorLoc() const { return OperatorLoc; }
  3432. /// Determine the location of the parameter pack.
  3433. SourceLocation getPackLoc() const { return PackLoc; }
  3434. /// Determine the location of the right parenthesis.
  3435. SourceLocation getRParenLoc() const { return RParenLoc; }
  3436. /// Retrieve the parameter pack.
  3437. NamedDecl *getPack() const { return Pack; }
  3438. /// Retrieve the length of the parameter pack.
  3439. ///
  3440. /// This routine may only be invoked when the expression is not
  3441. /// value-dependent.
  3442. unsigned getPackLength() const {
  3443. assert(!isValueDependent() &&
  3444. "Cannot get the length of a value-dependent pack size expression");
  3445. return Length;
  3446. }
  3447. /// Determine whether this represents a partially-substituted sizeof...
  3448. /// expression, such as is produced for:
  3449. ///
  3450. /// template<typename ...Ts> using X = int[sizeof...(Ts)];
  3451. /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
  3452. bool isPartiallySubstituted() const {
  3453. return isValueDependent() && Length;
  3454. }
  3455. /// Get
  3456. ArrayRef<TemplateArgument> getPartialArguments() const {
  3457. assert(isPartiallySubstituted());
  3458. const auto *Args = getTrailingObjects<TemplateArgument>();
  3459. return llvm::makeArrayRef(Args, Args + Length);
  3460. }
  3461. SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
  3462. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  3463. static bool classof(const Stmt *T) {
  3464. return T->getStmtClass() == SizeOfPackExprClass;
  3465. }
  3466. // Iterators
  3467. child_range children() {
  3468. return child_range(child_iterator(), child_iterator());
  3469. }
  3470. const_child_range children() const {
  3471. return const_child_range(const_child_iterator(), const_child_iterator());
  3472. }
  3473. };
  3474. /// Represents a reference to a non-type template parameter
  3475. /// that has been substituted with a template argument.
  3476. class SubstNonTypeTemplateParmExpr : public Expr {
  3477. friend class ASTReader;
  3478. friend class ASTStmtReader;
  3479. /// The replaced parameter and a flag indicating if it was a reference
  3480. /// parameter. For class NTTPs, we can't determine that based on the value
  3481. /// category alone.
  3482. llvm::PointerIntPair<NonTypeTemplateParmDecl*, 1, bool> ParamAndRef;
  3483. /// The replacement expression.
  3484. Stmt *Replacement;
  3485. explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
  3486. : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
  3487. public:
  3488. SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
  3489. SourceLocation Loc,
  3490. NonTypeTemplateParmDecl *Param, bool RefParam,
  3491. Expr *Replacement)
  3492. : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary),
  3493. ParamAndRef(Param, RefParam), Replacement(Replacement) {
  3494. SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
  3495. setDependence(computeDependence(this));
  3496. }
  3497. SourceLocation getNameLoc() const {
  3498. return SubstNonTypeTemplateParmExprBits.NameLoc;
  3499. }
  3500. SourceLocation getBeginLoc() const { return getNameLoc(); }
  3501. SourceLocation getEndLoc() const { return getNameLoc(); }
  3502. Expr *getReplacement() const { return cast<Expr>(Replacement); }
  3503. NonTypeTemplateParmDecl *getParameter() const {
  3504. return ParamAndRef.getPointer();
  3505. }
  3506. bool isReferenceParameter() const { return ParamAndRef.getInt(); }
  3507. /// Determine the substituted type of the template parameter.
  3508. QualType getParameterType(const ASTContext &Ctx) const;
  3509. static bool classof(const Stmt *s) {
  3510. return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
  3511. }
  3512. // Iterators
  3513. child_range children() { return child_range(&Replacement, &Replacement + 1); }
  3514. const_child_range children() const {
  3515. return const_child_range(&Replacement, &Replacement + 1);
  3516. }
  3517. };
  3518. /// Represents a reference to a non-type template parameter pack that
  3519. /// has been substituted with a non-template argument pack.
  3520. ///
  3521. /// When a pack expansion in the source code contains multiple parameter packs
  3522. /// and those parameter packs correspond to different levels of template
  3523. /// parameter lists, this node is used to represent a non-type template
  3524. /// parameter pack from an outer level, which has already had its argument pack
  3525. /// substituted but that still lives within a pack expansion that itself
  3526. /// could not be instantiated. When actually performing a substitution into
  3527. /// that pack expansion (e.g., when all template parameters have corresponding
  3528. /// arguments), this type will be replaced with the appropriate underlying
  3529. /// expression at the current pack substitution index.
  3530. class SubstNonTypeTemplateParmPackExpr : public Expr {
  3531. friend class ASTReader;
  3532. friend class ASTStmtReader;
  3533. /// The non-type template parameter pack itself.
  3534. NonTypeTemplateParmDecl *Param;
  3535. /// A pointer to the set of template arguments that this
  3536. /// parameter pack is instantiated with.
  3537. const TemplateArgument *Arguments;
  3538. /// The number of template arguments in \c Arguments.
  3539. unsigned NumArguments;
  3540. /// The location of the non-type template parameter pack reference.
  3541. SourceLocation NameLoc;
  3542. explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
  3543. : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {}
  3544. public:
  3545. SubstNonTypeTemplateParmPackExpr(QualType T,
  3546. ExprValueKind ValueKind,
  3547. NonTypeTemplateParmDecl *Param,
  3548. SourceLocation NameLoc,
  3549. const TemplateArgument &ArgPack);
  3550. /// Retrieve the non-type template parameter pack being substituted.
  3551. NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
  3552. /// Retrieve the location of the parameter pack name.
  3553. SourceLocation getParameterPackLocation() const { return NameLoc; }
  3554. /// Retrieve the template argument pack containing the substituted
  3555. /// template arguments.
  3556. TemplateArgument getArgumentPack() const;
  3557. SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
  3558. SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
  3559. static bool classof(const Stmt *T) {
  3560. return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
  3561. }
  3562. // Iterators
  3563. child_range children() {
  3564. return child_range(child_iterator(), child_iterator());
  3565. }
  3566. const_child_range children() const {
  3567. return const_child_range(const_child_iterator(), const_child_iterator());
  3568. }
  3569. };
  3570. /// Represents a reference to a function parameter pack or init-capture pack
  3571. /// that has been substituted but not yet expanded.
  3572. ///
  3573. /// When a pack expansion contains multiple parameter packs at different levels,
  3574. /// this node is used to represent a function parameter pack at an outer level
  3575. /// which we have already substituted to refer to expanded parameters, but where
  3576. /// the containing pack expansion cannot yet be expanded.
  3577. ///
  3578. /// \code
  3579. /// template<typename...Ts> struct S {
  3580. /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
  3581. /// };
  3582. /// template struct S<int, int>;
  3583. /// \endcode
  3584. class FunctionParmPackExpr final
  3585. : public Expr,
  3586. private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> {
  3587. friend class ASTReader;
  3588. friend class ASTStmtReader;
  3589. friend TrailingObjects;
  3590. /// The function parameter pack which was referenced.
  3591. VarDecl *ParamPack;
  3592. /// The location of the function parameter pack reference.
  3593. SourceLocation NameLoc;
  3594. /// The number of expansions of this pack.
  3595. unsigned NumParameters;
  3596. FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
  3597. SourceLocation NameLoc, unsigned NumParams,
  3598. VarDecl *const *Params);
  3599. public:
  3600. static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
  3601. VarDecl *ParamPack,
  3602. SourceLocation NameLoc,
  3603. ArrayRef<VarDecl *> Params);
  3604. static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
  3605. unsigned NumParams);
  3606. /// Get the parameter pack which this expression refers to.
  3607. VarDecl *getParameterPack() const { return ParamPack; }
  3608. /// Get the location of the parameter pack.
  3609. SourceLocation getParameterPackLocation() const { return NameLoc; }
  3610. /// Iterators over the parameters which the parameter pack expanded
  3611. /// into.
  3612. using iterator = VarDecl * const *;
  3613. iterator begin() const { return getTrailingObjects<VarDecl *>(); }
  3614. iterator end() const { return begin() + NumParameters; }
  3615. /// Get the number of parameters in this parameter pack.
  3616. unsigned getNumExpansions() const { return NumParameters; }
  3617. /// Get an expansion of the parameter pack by index.
  3618. VarDecl *getExpansion(unsigned I) const { return begin()[I]; }
  3619. SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
  3620. SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
  3621. static bool classof(const Stmt *T) {
  3622. return T->getStmtClass() == FunctionParmPackExprClass;
  3623. }
  3624. child_range children() {
  3625. return child_range(child_iterator(), child_iterator());
  3626. }
  3627. const_child_range children() const {
  3628. return const_child_range(const_child_iterator(), const_child_iterator());
  3629. }
  3630. };
  3631. /// Represents a prvalue temporary that is written into memory so that
  3632. /// a reference can bind to it.
  3633. ///
  3634. /// Prvalue expressions are materialized when they need to have an address
  3635. /// in memory for a reference to bind to. This happens when binding a
  3636. /// reference to the result of a conversion, e.g.,
  3637. ///
  3638. /// \code
  3639. /// const int &r = 1.0;
  3640. /// \endcode
  3641. ///
  3642. /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
  3643. /// then materialized via a \c MaterializeTemporaryExpr, and the reference
  3644. /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
  3645. /// (either an lvalue or an xvalue, depending on the kind of reference binding
  3646. /// to it), maintaining the invariant that references always bind to glvalues.
  3647. ///
  3648. /// Reference binding and copy-elision can both extend the lifetime of a
  3649. /// temporary. When either happens, the expression will also track the
  3650. /// declaration which is responsible for the lifetime extension.
  3651. class MaterializeTemporaryExpr : public Expr {
  3652. private:
  3653. friend class ASTStmtReader;
  3654. friend class ASTStmtWriter;
  3655. llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State;
  3656. public:
  3657. MaterializeTemporaryExpr(QualType T, Expr *Temporary,
  3658. bool BoundToLvalueReference,
  3659. LifetimeExtendedTemporaryDecl *MTD = nullptr);
  3660. MaterializeTemporaryExpr(EmptyShell Empty)
  3661. : Expr(MaterializeTemporaryExprClass, Empty) {}
  3662. /// Retrieve the temporary-generating subexpression whose value will
  3663. /// be materialized into a glvalue.
  3664. Expr *getSubExpr() const {
  3665. return cast<Expr>(
  3666. State.is<Stmt *>()
  3667. ? State.get<Stmt *>()
  3668. : State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr());
  3669. }
  3670. /// Retrieve the storage duration for the materialized temporary.
  3671. StorageDuration getStorageDuration() const {
  3672. return State.is<Stmt *>() ? SD_FullExpression
  3673. : State.get<LifetimeExtendedTemporaryDecl *>()
  3674. ->getStorageDuration();
  3675. }
  3676. /// Get the storage for the constant value of a materialized temporary
  3677. /// of static storage duration.
  3678. APValue *getOrCreateValue(bool MayCreate) const {
  3679. assert(State.is<LifetimeExtendedTemporaryDecl *>() &&
  3680. "the temporary has not been lifetime extended");
  3681. return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue(
  3682. MayCreate);
  3683. }
  3684. LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl() {
  3685. return State.dyn_cast<LifetimeExtendedTemporaryDecl *>();
  3686. }
  3687. const LifetimeExtendedTemporaryDecl *
  3688. getLifetimeExtendedTemporaryDecl() const {
  3689. return State.dyn_cast<LifetimeExtendedTemporaryDecl *>();
  3690. }
  3691. /// Get the declaration which triggered the lifetime-extension of this
  3692. /// temporary, if any.
  3693. ValueDecl *getExtendingDecl() {
  3694. return State.is<Stmt *>() ? nullptr
  3695. : State.get<LifetimeExtendedTemporaryDecl *>()
  3696. ->getExtendingDecl();
  3697. }
  3698. const ValueDecl *getExtendingDecl() const {
  3699. return const_cast<MaterializeTemporaryExpr *>(this)->getExtendingDecl();
  3700. }
  3701. void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber);
  3702. unsigned getManglingNumber() const {
  3703. return State.is<Stmt *>() ? 0
  3704. : State.get<LifetimeExtendedTemporaryDecl *>()
  3705. ->getManglingNumber();
  3706. }
  3707. /// Determine whether this materialized temporary is bound to an
  3708. /// lvalue reference; otherwise, it's bound to an rvalue reference.
  3709. bool isBoundToLvalueReference() const { return isLValue(); }
  3710. /// Determine whether this temporary object is usable in constant
  3711. /// expressions, as specified in C++20 [expr.const]p4.
  3712. bool isUsableInConstantExpressions(const ASTContext &Context) const;
  3713. SourceLocation getBeginLoc() const LLVM_READONLY {
  3714. return getSubExpr()->getBeginLoc();
  3715. }
  3716. SourceLocation getEndLoc() const LLVM_READONLY {
  3717. return getSubExpr()->getEndLoc();
  3718. }
  3719. static bool classof(const Stmt *T) {
  3720. return T->getStmtClass() == MaterializeTemporaryExprClass;
  3721. }
  3722. // Iterators
  3723. child_range children() {
  3724. return State.is<Stmt *>()
  3725. ? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1)
  3726. : State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr();
  3727. }
  3728. const_child_range children() const {
  3729. return State.is<Stmt *>()
  3730. ? const_child_range(State.getAddrOfPtr1(),
  3731. State.getAddrOfPtr1() + 1)
  3732. : const_cast<const LifetimeExtendedTemporaryDecl *>(
  3733. State.get<LifetimeExtendedTemporaryDecl *>())
  3734. ->childrenExpr();
  3735. }
  3736. };
  3737. /// Represents a folding of a pack over an operator.
  3738. ///
  3739. /// This expression is always dependent and represents a pack expansion of the
  3740. /// forms:
  3741. ///
  3742. /// ( expr op ... )
  3743. /// ( ... op expr )
  3744. /// ( expr op ... op expr )
  3745. class CXXFoldExpr : public Expr {
  3746. friend class ASTStmtReader;
  3747. friend class ASTStmtWriter;
  3748. enum SubExpr { Callee, LHS, RHS, Count };
  3749. SourceLocation LParenLoc;
  3750. SourceLocation EllipsisLoc;
  3751. SourceLocation RParenLoc;
  3752. // When 0, the number of expansions is not known. Otherwise, this is one more
  3753. // than the number of expansions.
  3754. unsigned NumExpansions;
  3755. Stmt *SubExprs[SubExpr::Count];
  3756. BinaryOperatorKind Opcode;
  3757. public:
  3758. CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee,
  3759. SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode,
  3760. SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc,
  3761. Optional<unsigned> NumExpansions)
  3762. : Expr(CXXFoldExprClass, T, VK_PRValue, OK_Ordinary),
  3763. LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
  3764. NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) {
  3765. SubExprs[SubExpr::Callee] = Callee;
  3766. SubExprs[SubExpr::LHS] = LHS;
  3767. SubExprs[SubExpr::RHS] = RHS;
  3768. setDependence(computeDependence(this));
  3769. }
  3770. CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
  3771. UnresolvedLookupExpr *getCallee() const {
  3772. return static_cast<UnresolvedLookupExpr *>(SubExprs[SubExpr::Callee]);
  3773. }
  3774. Expr *getLHS() const { return static_cast<Expr*>(SubExprs[SubExpr::LHS]); }
  3775. Expr *getRHS() const { return static_cast<Expr*>(SubExprs[SubExpr::RHS]); }
  3776. /// Does this produce a right-associated sequence of operators?
  3777. bool isRightFold() const {
  3778. return getLHS() && getLHS()->containsUnexpandedParameterPack();
  3779. }
  3780. /// Does this produce a left-associated sequence of operators?
  3781. bool isLeftFold() const { return !isRightFold(); }
  3782. /// Get the pattern, that is, the operand that contains an unexpanded pack.
  3783. Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
  3784. /// Get the operand that doesn't contain a pack, for a binary fold.
  3785. Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
  3786. SourceLocation getLParenLoc() const { return LParenLoc; }
  3787. SourceLocation getRParenLoc() const { return RParenLoc; }
  3788. SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
  3789. BinaryOperatorKind getOperator() const { return Opcode; }
  3790. Optional<unsigned> getNumExpansions() const {
  3791. if (NumExpansions)
  3792. return NumExpansions - 1;
  3793. return None;
  3794. }
  3795. SourceLocation getBeginLoc() const LLVM_READONLY {
  3796. if (LParenLoc.isValid())
  3797. return LParenLoc;
  3798. if (isLeftFold())
  3799. return getEllipsisLoc();
  3800. return getLHS()->getBeginLoc();
  3801. }
  3802. SourceLocation getEndLoc() const LLVM_READONLY {
  3803. if (RParenLoc.isValid())
  3804. return RParenLoc;
  3805. if (isRightFold())
  3806. return getEllipsisLoc();
  3807. return getRHS()->getEndLoc();
  3808. }
  3809. static bool classof(const Stmt *T) {
  3810. return T->getStmtClass() == CXXFoldExprClass;
  3811. }
  3812. // Iterators
  3813. child_range children() {
  3814. return child_range(SubExprs, SubExprs + SubExpr::Count);
  3815. }
  3816. const_child_range children() const {
  3817. return const_child_range(SubExprs, SubExprs + SubExpr::Count);
  3818. }
  3819. };
  3820. /// Represents an expression that might suspend coroutine execution;
  3821. /// either a co_await or co_yield expression.
  3822. ///
  3823. /// Evaluation of this expression first evaluates its 'ready' expression. If
  3824. /// that returns 'false':
  3825. /// -- execution of the coroutine is suspended
  3826. /// -- the 'suspend' expression is evaluated
  3827. /// -- if the 'suspend' expression returns 'false', the coroutine is
  3828. /// resumed
  3829. /// -- otherwise, control passes back to the resumer.
  3830. /// If the coroutine is not suspended, or when it is resumed, the 'resume'
  3831. /// expression is evaluated, and its result is the result of the overall
  3832. /// expression.
  3833. class CoroutineSuspendExpr : public Expr {
  3834. friend class ASTStmtReader;
  3835. SourceLocation KeywordLoc;
  3836. enum SubExpr { Common, Ready, Suspend, Resume, Count };
  3837. Stmt *SubExprs[SubExpr::Count];
  3838. OpaqueValueExpr *OpaqueValue = nullptr;
  3839. public:
  3840. CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
  3841. Expr *Ready, Expr *Suspend, Expr *Resume,
  3842. OpaqueValueExpr *OpaqueValue)
  3843. : Expr(SC, Resume->getType(), Resume->getValueKind(),
  3844. Resume->getObjectKind()),
  3845. KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
  3846. SubExprs[SubExpr::Common] = Common;
  3847. SubExprs[SubExpr::Ready] = Ready;
  3848. SubExprs[SubExpr::Suspend] = Suspend;
  3849. SubExprs[SubExpr::Resume] = Resume;
  3850. setDependence(computeDependence(this));
  3851. }
  3852. CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
  3853. Expr *Common)
  3854. : Expr(SC, Ty, VK_PRValue, OK_Ordinary), KeywordLoc(KeywordLoc) {
  3855. assert(Common->isTypeDependent() && Ty->isDependentType() &&
  3856. "wrong constructor for non-dependent co_await/co_yield expression");
  3857. SubExprs[SubExpr::Common] = Common;
  3858. SubExprs[SubExpr::Ready] = nullptr;
  3859. SubExprs[SubExpr::Suspend] = nullptr;
  3860. SubExprs[SubExpr::Resume] = nullptr;
  3861. setDependence(computeDependence(this));
  3862. }
  3863. CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
  3864. SubExprs[SubExpr::Common] = nullptr;
  3865. SubExprs[SubExpr::Ready] = nullptr;
  3866. SubExprs[SubExpr::Suspend] = nullptr;
  3867. SubExprs[SubExpr::Resume] = nullptr;
  3868. }
  3869. SourceLocation getKeywordLoc() const { return KeywordLoc; }
  3870. Expr *getCommonExpr() const {
  3871. return static_cast<Expr*>(SubExprs[SubExpr::Common]);
  3872. }
  3873. /// getOpaqueValue - Return the opaque value placeholder.
  3874. OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
  3875. Expr *getReadyExpr() const {
  3876. return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
  3877. }
  3878. Expr *getSuspendExpr() const {
  3879. return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
  3880. }
  3881. Expr *getResumeExpr() const {
  3882. return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
  3883. }
  3884. SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
  3885. SourceLocation getEndLoc() const LLVM_READONLY {
  3886. return getCommonExpr()->getEndLoc();
  3887. }
  3888. child_range children() {
  3889. return child_range(SubExprs, SubExprs + SubExpr::Count);
  3890. }
  3891. const_child_range children() const {
  3892. return const_child_range(SubExprs, SubExprs + SubExpr::Count);
  3893. }
  3894. static bool classof(const Stmt *T) {
  3895. return T->getStmtClass() == CoawaitExprClass ||
  3896. T->getStmtClass() == CoyieldExprClass;
  3897. }
  3898. };
  3899. /// Represents a 'co_await' expression.
  3900. class CoawaitExpr : public CoroutineSuspendExpr {
  3901. friend class ASTStmtReader;
  3902. public:
  3903. CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
  3904. Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue,
  3905. bool IsImplicit = false)
  3906. : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
  3907. Suspend, Resume, OpaqueValue) {
  3908. CoawaitBits.IsImplicit = IsImplicit;
  3909. }
  3910. CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand,
  3911. bool IsImplicit = false)
  3912. : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {
  3913. CoawaitBits.IsImplicit = IsImplicit;
  3914. }
  3915. CoawaitExpr(EmptyShell Empty)
  3916. : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
  3917. Expr *getOperand() const {
  3918. // FIXME: Dig out the actual operand or store it.
  3919. return getCommonExpr();
  3920. }
  3921. bool isImplicit() const { return CoawaitBits.IsImplicit; }
  3922. void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; }
  3923. static bool classof(const Stmt *T) {
  3924. return T->getStmtClass() == CoawaitExprClass;
  3925. }
  3926. };
  3927. /// Represents a 'co_await' expression while the type of the promise
  3928. /// is dependent.
  3929. class DependentCoawaitExpr : public Expr {
  3930. friend class ASTStmtReader;
  3931. SourceLocation KeywordLoc;
  3932. Stmt *SubExprs[2];
  3933. public:
  3934. DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op,
  3935. UnresolvedLookupExpr *OpCoawait)
  3936. : Expr(DependentCoawaitExprClass, Ty, VK_PRValue, OK_Ordinary),
  3937. KeywordLoc(KeywordLoc) {
  3938. // NOTE: A co_await expression is dependent on the coroutines promise
  3939. // type and may be dependent even when the `Op` expression is not.
  3940. assert(Ty->isDependentType() &&
  3941. "wrong constructor for non-dependent co_await/co_yield expression");
  3942. SubExprs[0] = Op;
  3943. SubExprs[1] = OpCoawait;
  3944. setDependence(computeDependence(this));
  3945. }
  3946. DependentCoawaitExpr(EmptyShell Empty)
  3947. : Expr(DependentCoawaitExprClass, Empty) {}
  3948. Expr *getOperand() const { return cast<Expr>(SubExprs[0]); }
  3949. UnresolvedLookupExpr *getOperatorCoawaitLookup() const {
  3950. return cast<UnresolvedLookupExpr>(SubExprs[1]);
  3951. }
  3952. SourceLocation getKeywordLoc() const { return KeywordLoc; }
  3953. SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
  3954. SourceLocation getEndLoc() const LLVM_READONLY {
  3955. return getOperand()->getEndLoc();
  3956. }
  3957. child_range children() { return child_range(SubExprs, SubExprs + 2); }
  3958. const_child_range children() const {
  3959. return const_child_range(SubExprs, SubExprs + 2);
  3960. }
  3961. static bool classof(const Stmt *T) {
  3962. return T->getStmtClass() == DependentCoawaitExprClass;
  3963. }
  3964. };
  3965. /// Represents a 'co_yield' expression.
  3966. class CoyieldExpr : public CoroutineSuspendExpr {
  3967. friend class ASTStmtReader;
  3968. public:
  3969. CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
  3970. Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue)
  3971. : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
  3972. Suspend, Resume, OpaqueValue) {}
  3973. CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
  3974. : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
  3975. CoyieldExpr(EmptyShell Empty)
  3976. : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
  3977. Expr *getOperand() const {
  3978. // FIXME: Dig out the actual operand or store it.
  3979. return getCommonExpr();
  3980. }
  3981. static bool classof(const Stmt *T) {
  3982. return T->getStmtClass() == CoyieldExprClass;
  3983. }
  3984. };
  3985. /// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement
  3986. /// std::bit_cast. These can sometimes be evaluated as part of a constant
  3987. /// expression, but otherwise CodeGen to a simple memcpy in general.
  3988. class BuiltinBitCastExpr final
  3989. : public ExplicitCastExpr,
  3990. private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> {
  3991. friend class ASTStmtReader;
  3992. friend class CastExpr;
  3993. friend TrailingObjects;
  3994. SourceLocation KWLoc;
  3995. SourceLocation RParenLoc;
  3996. public:
  3997. BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
  3998. TypeSourceInfo *DstType, SourceLocation KWLoc,
  3999. SourceLocation RParenLoc)
  4000. : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, false,
  4001. DstType),
  4002. KWLoc(KWLoc), RParenLoc(RParenLoc) {}
  4003. BuiltinBitCastExpr(EmptyShell Empty)
  4004. : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {}
  4005. SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; }
  4006. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  4007. static bool classof(const Stmt *T) {
  4008. return T->getStmtClass() == BuiltinBitCastExprClass;
  4009. }
  4010. };
  4011. } // namespace clang
  4012. #endif // LLVM_CLANG_AST_EXPRCXX_H
  4013. #ifdef __GNUC__
  4014. #pragma GCC diagnostic pop
  4015. #endif