ASTReaderStmt.cpp 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930
  1. //===- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Statement/expression deserialization. This implements the
  10. // ASTReader::ReadStmt method.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/ASTConcept.h"
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/AttrIterator.h"
  16. #include "clang/AST/Decl.h"
  17. #include "clang/AST/DeclAccessPair.h"
  18. #include "clang/AST/DeclCXX.h"
  19. #include "clang/AST/DeclGroup.h"
  20. #include "clang/AST/DeclObjC.h"
  21. #include "clang/AST/DeclTemplate.h"
  22. #include "clang/AST/DeclarationName.h"
  23. #include "clang/AST/DependenceFlags.h"
  24. #include "clang/AST/Expr.h"
  25. #include "clang/AST/ExprCXX.h"
  26. #include "clang/AST/ExprObjC.h"
  27. #include "clang/AST/ExprOpenMP.h"
  28. #include "clang/AST/NestedNameSpecifier.h"
  29. #include "clang/AST/OpenMPClause.h"
  30. #include "clang/AST/OperationKinds.h"
  31. #include "clang/AST/Stmt.h"
  32. #include "clang/AST/StmtCXX.h"
  33. #include "clang/AST/StmtObjC.h"
  34. #include "clang/AST/StmtOpenMP.h"
  35. #include "clang/AST/StmtVisitor.h"
  36. #include "clang/AST/TemplateBase.h"
  37. #include "clang/AST/Type.h"
  38. #include "clang/AST/UnresolvedSet.h"
  39. #include "clang/Basic/CapturedStmt.h"
  40. #include "clang/Basic/ExpressionTraits.h"
  41. #include "clang/Basic/LLVM.h"
  42. #include "clang/Basic/Lambda.h"
  43. #include "clang/Basic/LangOptions.h"
  44. #include "clang/Basic/OpenMPKinds.h"
  45. #include "clang/Basic/OperatorKinds.h"
  46. #include "clang/Basic/SourceLocation.h"
  47. #include "clang/Basic/Specifiers.h"
  48. #include "clang/Basic/TypeTraits.h"
  49. #include "clang/Lex/Token.h"
  50. #include "clang/Serialization/ASTBitCodes.h"
  51. #include "clang/Serialization/ASTRecordReader.h"
  52. #include "llvm/ADT/BitmaskEnum.h"
  53. #include "llvm/ADT/DenseMap.h"
  54. #include "llvm/ADT/SmallString.h"
  55. #include "llvm/ADT/SmallVector.h"
  56. #include "llvm/ADT/StringRef.h"
  57. #include "llvm/Bitstream/BitstreamReader.h"
  58. #include "llvm/Support/Casting.h"
  59. #include "llvm/Support/ErrorHandling.h"
  60. #include <algorithm>
  61. #include <cassert>
  62. #include <cstdint>
  63. #include <string>
  64. using namespace clang;
  65. using namespace serialization;
  66. namespace clang {
  67. class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
  68. ASTRecordReader &Record;
  69. llvm::BitstreamCursor &DeclsCursor;
  70. SourceLocation readSourceLocation() {
  71. return Record.readSourceLocation();
  72. }
  73. SourceRange readSourceRange() {
  74. return Record.readSourceRange();
  75. }
  76. std::string readString() {
  77. return Record.readString();
  78. }
  79. TypeSourceInfo *readTypeSourceInfo() {
  80. return Record.readTypeSourceInfo();
  81. }
  82. Decl *readDecl() {
  83. return Record.readDecl();
  84. }
  85. template<typename T>
  86. T *readDeclAs() {
  87. return Record.readDeclAs<T>();
  88. }
  89. public:
  90. ASTStmtReader(ASTRecordReader &Record, llvm::BitstreamCursor &Cursor)
  91. : Record(Record), DeclsCursor(Cursor) {}
  92. /// The number of record fields required for the Stmt class
  93. /// itself.
  94. static const unsigned NumStmtFields = 0;
  95. /// The number of record fields required for the Expr class
  96. /// itself.
  97. static const unsigned NumExprFields =
  98. NumStmtFields + llvm::BitWidth<ExprDependence> + 3;
  99. /// Read and initialize a ExplicitTemplateArgumentList structure.
  100. void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
  101. TemplateArgumentLoc *ArgsLocArray,
  102. unsigned NumTemplateArgs);
  103. /// Read and initialize a ExplicitTemplateArgumentList structure.
  104. void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList,
  105. unsigned NumTemplateArgs);
  106. void VisitStmt(Stmt *S);
  107. #define STMT(Type, Base) \
  108. void Visit##Type(Type *);
  109. #include "clang/AST/StmtNodes.inc"
  110. };
  111. } // namespace clang
  112. void ASTStmtReader::ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
  113. TemplateArgumentLoc *ArgsLocArray,
  114. unsigned NumTemplateArgs) {
  115. SourceLocation TemplateKWLoc = readSourceLocation();
  116. TemplateArgumentListInfo ArgInfo;
  117. ArgInfo.setLAngleLoc(readSourceLocation());
  118. ArgInfo.setRAngleLoc(readSourceLocation());
  119. for (unsigned i = 0; i != NumTemplateArgs; ++i)
  120. ArgInfo.addArgument(Record.readTemplateArgumentLoc());
  121. Args.initializeFrom(TemplateKWLoc, ArgInfo, ArgsLocArray);
  122. }
  123. void ASTStmtReader::VisitStmt(Stmt *S) {
  124. assert(Record.getIdx() == NumStmtFields && "Incorrect statement field count");
  125. }
  126. void ASTStmtReader::VisitNullStmt(NullStmt *S) {
  127. VisitStmt(S);
  128. S->setSemiLoc(readSourceLocation());
  129. S->NullStmtBits.HasLeadingEmptyMacro = Record.readInt();
  130. }
  131. void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
  132. VisitStmt(S);
  133. SmallVector<Stmt *, 16> Stmts;
  134. unsigned NumStmts = Record.readInt();
  135. while (NumStmts--)
  136. Stmts.push_back(Record.readSubStmt());
  137. S->setStmts(Stmts);
  138. S->CompoundStmtBits.LBraceLoc = readSourceLocation();
  139. S->RBraceLoc = readSourceLocation();
  140. }
  141. void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
  142. VisitStmt(S);
  143. Record.recordSwitchCaseID(S, Record.readInt());
  144. S->setKeywordLoc(readSourceLocation());
  145. S->setColonLoc(readSourceLocation());
  146. }
  147. void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
  148. VisitSwitchCase(S);
  149. bool CaseStmtIsGNURange = Record.readInt();
  150. S->setLHS(Record.readSubExpr());
  151. S->setSubStmt(Record.readSubStmt());
  152. if (CaseStmtIsGNURange) {
  153. S->setRHS(Record.readSubExpr());
  154. S->setEllipsisLoc(readSourceLocation());
  155. }
  156. }
  157. void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
  158. VisitSwitchCase(S);
  159. S->setSubStmt(Record.readSubStmt());
  160. }
  161. void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
  162. VisitStmt(S);
  163. bool IsSideEntry = Record.readInt();
  164. auto *LD = readDeclAs<LabelDecl>();
  165. LD->setStmt(S);
  166. S->setDecl(LD);
  167. S->setSubStmt(Record.readSubStmt());
  168. S->setIdentLoc(readSourceLocation());
  169. S->setSideEntry(IsSideEntry);
  170. }
  171. void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
  172. VisitStmt(S);
  173. // NumAttrs in AttributedStmt is set when creating an empty
  174. // AttributedStmt in AttributedStmt::CreateEmpty, since it is needed
  175. // to allocate the right amount of space for the trailing Attr *.
  176. uint64_t NumAttrs = Record.readInt();
  177. AttrVec Attrs;
  178. Record.readAttributes(Attrs);
  179. (void)NumAttrs;
  180. assert(NumAttrs == S->AttributedStmtBits.NumAttrs);
  181. assert(NumAttrs == Attrs.size());
  182. std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr());
  183. S->SubStmt = Record.readSubStmt();
  184. S->AttributedStmtBits.AttrLoc = readSourceLocation();
  185. }
  186. void ASTStmtReader::VisitIfStmt(IfStmt *S) {
  187. VisitStmt(S);
  188. bool HasElse = Record.readInt();
  189. bool HasVar = Record.readInt();
  190. bool HasInit = Record.readInt();
  191. S->setStatementKind(static_cast<IfStatementKind>(Record.readInt()));
  192. S->setCond(Record.readSubExpr());
  193. S->setThen(Record.readSubStmt());
  194. if (HasElse)
  195. S->setElse(Record.readSubStmt());
  196. if (HasVar)
  197. S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
  198. if (HasInit)
  199. S->setInit(Record.readSubStmt());
  200. S->setIfLoc(readSourceLocation());
  201. S->setLParenLoc(readSourceLocation());
  202. S->setRParenLoc(readSourceLocation());
  203. if (HasElse)
  204. S->setElseLoc(readSourceLocation());
  205. }
  206. void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
  207. VisitStmt(S);
  208. bool HasInit = Record.readInt();
  209. bool HasVar = Record.readInt();
  210. bool AllEnumCasesCovered = Record.readInt();
  211. if (AllEnumCasesCovered)
  212. S->setAllEnumCasesCovered();
  213. S->setCond(Record.readSubExpr());
  214. S->setBody(Record.readSubStmt());
  215. if (HasInit)
  216. S->setInit(Record.readSubStmt());
  217. if (HasVar)
  218. S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
  219. S->setSwitchLoc(readSourceLocation());
  220. S->setLParenLoc(readSourceLocation());
  221. S->setRParenLoc(readSourceLocation());
  222. SwitchCase *PrevSC = nullptr;
  223. for (auto E = Record.size(); Record.getIdx() != E; ) {
  224. SwitchCase *SC = Record.getSwitchCaseWithID(Record.readInt());
  225. if (PrevSC)
  226. PrevSC->setNextSwitchCase(SC);
  227. else
  228. S->setSwitchCaseList(SC);
  229. PrevSC = SC;
  230. }
  231. }
  232. void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
  233. VisitStmt(S);
  234. bool HasVar = Record.readInt();
  235. S->setCond(Record.readSubExpr());
  236. S->setBody(Record.readSubStmt());
  237. if (HasVar)
  238. S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
  239. S->setWhileLoc(readSourceLocation());
  240. S->setLParenLoc(readSourceLocation());
  241. S->setRParenLoc(readSourceLocation());
  242. }
  243. void ASTStmtReader::VisitDoStmt(DoStmt *S) {
  244. VisitStmt(S);
  245. S->setCond(Record.readSubExpr());
  246. S->setBody(Record.readSubStmt());
  247. S->setDoLoc(readSourceLocation());
  248. S->setWhileLoc(readSourceLocation());
  249. S->setRParenLoc(readSourceLocation());
  250. }
  251. void ASTStmtReader::VisitForStmt(ForStmt *S) {
  252. VisitStmt(S);
  253. S->setInit(Record.readSubStmt());
  254. S->setCond(Record.readSubExpr());
  255. S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
  256. S->setInc(Record.readSubExpr());
  257. S->setBody(Record.readSubStmt());
  258. S->setForLoc(readSourceLocation());
  259. S->setLParenLoc(readSourceLocation());
  260. S->setRParenLoc(readSourceLocation());
  261. }
  262. void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
  263. VisitStmt(S);
  264. S->setLabel(readDeclAs<LabelDecl>());
  265. S->setGotoLoc(readSourceLocation());
  266. S->setLabelLoc(readSourceLocation());
  267. }
  268. void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
  269. VisitStmt(S);
  270. S->setGotoLoc(readSourceLocation());
  271. S->setStarLoc(readSourceLocation());
  272. S->setTarget(Record.readSubExpr());
  273. }
  274. void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
  275. VisitStmt(S);
  276. S->setContinueLoc(readSourceLocation());
  277. }
  278. void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
  279. VisitStmt(S);
  280. S->setBreakLoc(readSourceLocation());
  281. }
  282. void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
  283. VisitStmt(S);
  284. bool HasNRVOCandidate = Record.readInt();
  285. S->setRetValue(Record.readSubExpr());
  286. if (HasNRVOCandidate)
  287. S->setNRVOCandidate(readDeclAs<VarDecl>());
  288. S->setReturnLoc(readSourceLocation());
  289. }
  290. void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
  291. VisitStmt(S);
  292. S->setStartLoc(readSourceLocation());
  293. S->setEndLoc(readSourceLocation());
  294. if (Record.size() - Record.getIdx() == 1) {
  295. // Single declaration
  296. S->setDeclGroup(DeclGroupRef(readDecl()));
  297. } else {
  298. SmallVector<Decl *, 16> Decls;
  299. int N = Record.size() - Record.getIdx();
  300. Decls.reserve(N);
  301. for (int I = 0; I < N; ++I)
  302. Decls.push_back(readDecl());
  303. S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Record.getContext(),
  304. Decls.data(),
  305. Decls.size())));
  306. }
  307. }
  308. void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
  309. VisitStmt(S);
  310. S->NumOutputs = Record.readInt();
  311. S->NumInputs = Record.readInt();
  312. S->NumClobbers = Record.readInt();
  313. S->setAsmLoc(readSourceLocation());
  314. S->setVolatile(Record.readInt());
  315. S->setSimple(Record.readInt());
  316. }
  317. void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
  318. VisitAsmStmt(S);
  319. S->NumLabels = Record.readInt();
  320. S->setRParenLoc(readSourceLocation());
  321. S->setAsmString(cast_or_null<StringLiteral>(Record.readSubStmt()));
  322. unsigned NumOutputs = S->getNumOutputs();
  323. unsigned NumInputs = S->getNumInputs();
  324. unsigned NumClobbers = S->getNumClobbers();
  325. unsigned NumLabels = S->getNumLabels();
  326. // Outputs and inputs
  327. SmallVector<IdentifierInfo *, 16> Names;
  328. SmallVector<StringLiteral*, 16> Constraints;
  329. SmallVector<Stmt*, 16> Exprs;
  330. for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
  331. Names.push_back(Record.readIdentifier());
  332. Constraints.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
  333. Exprs.push_back(Record.readSubStmt());
  334. }
  335. // Constraints
  336. SmallVector<StringLiteral*, 16> Clobbers;
  337. for (unsigned I = 0; I != NumClobbers; ++I)
  338. Clobbers.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
  339. // Labels
  340. for (unsigned I = 0, N = NumLabels; I != N; ++I)
  341. Exprs.push_back(Record.readSubStmt());
  342. S->setOutputsAndInputsAndClobbers(Record.getContext(),
  343. Names.data(), Constraints.data(),
  344. Exprs.data(), NumOutputs, NumInputs,
  345. NumLabels,
  346. Clobbers.data(), NumClobbers);
  347. }
  348. void ASTStmtReader::VisitMSAsmStmt(MSAsmStmt *S) {
  349. VisitAsmStmt(S);
  350. S->LBraceLoc = readSourceLocation();
  351. S->EndLoc = readSourceLocation();
  352. S->NumAsmToks = Record.readInt();
  353. std::string AsmStr = readString();
  354. // Read the tokens.
  355. SmallVector<Token, 16> AsmToks;
  356. AsmToks.reserve(S->NumAsmToks);
  357. for (unsigned i = 0, e = S->NumAsmToks; i != e; ++i) {
  358. AsmToks.push_back(Record.readToken());
  359. }
  360. // The calls to reserve() for the FooData vectors are mandatory to
  361. // prevent dead StringRefs in the Foo vectors.
  362. // Read the clobbers.
  363. SmallVector<std::string, 16> ClobbersData;
  364. SmallVector<StringRef, 16> Clobbers;
  365. ClobbersData.reserve(S->NumClobbers);
  366. Clobbers.reserve(S->NumClobbers);
  367. for (unsigned i = 0, e = S->NumClobbers; i != e; ++i) {
  368. ClobbersData.push_back(readString());
  369. Clobbers.push_back(ClobbersData.back());
  370. }
  371. // Read the operands.
  372. unsigned NumOperands = S->NumOutputs + S->NumInputs;
  373. SmallVector<Expr*, 16> Exprs;
  374. SmallVector<std::string, 16> ConstraintsData;
  375. SmallVector<StringRef, 16> Constraints;
  376. Exprs.reserve(NumOperands);
  377. ConstraintsData.reserve(NumOperands);
  378. Constraints.reserve(NumOperands);
  379. for (unsigned i = 0; i != NumOperands; ++i) {
  380. Exprs.push_back(cast<Expr>(Record.readSubStmt()));
  381. ConstraintsData.push_back(readString());
  382. Constraints.push_back(ConstraintsData.back());
  383. }
  384. S->initialize(Record.getContext(), AsmStr, AsmToks,
  385. Constraints, Exprs, Clobbers);
  386. }
  387. void ASTStmtReader::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
  388. VisitStmt(S);
  389. assert(Record.peekInt() == S->NumParams);
  390. Record.skipInts(1);
  391. auto *StoredStmts = S->getStoredStmts();
  392. for (unsigned i = 0;
  393. i < CoroutineBodyStmt::SubStmt::FirstParamMove + S->NumParams; ++i)
  394. StoredStmts[i] = Record.readSubStmt();
  395. }
  396. void ASTStmtReader::VisitCoreturnStmt(CoreturnStmt *S) {
  397. VisitStmt(S);
  398. S->CoreturnLoc = Record.readSourceLocation();
  399. for (auto &SubStmt: S->SubStmts)
  400. SubStmt = Record.readSubStmt();
  401. S->IsImplicit = Record.readInt() != 0;
  402. }
  403. void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *E) {
  404. VisitExpr(E);
  405. E->KeywordLoc = readSourceLocation();
  406. for (auto &SubExpr: E->SubExprs)
  407. SubExpr = Record.readSubStmt();
  408. E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
  409. E->setIsImplicit(Record.readInt() != 0);
  410. }
  411. void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *E) {
  412. VisitExpr(E);
  413. E->KeywordLoc = readSourceLocation();
  414. for (auto &SubExpr: E->SubExprs)
  415. SubExpr = Record.readSubStmt();
  416. E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
  417. }
  418. void ASTStmtReader::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
  419. VisitExpr(E);
  420. E->KeywordLoc = readSourceLocation();
  421. for (auto &SubExpr: E->SubExprs)
  422. SubExpr = Record.readSubStmt();
  423. }
  424. void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
  425. VisitStmt(S);
  426. Record.skipInts(1);
  427. S->setCapturedDecl(readDeclAs<CapturedDecl>());
  428. S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record.readInt()));
  429. S->setCapturedRecordDecl(readDeclAs<RecordDecl>());
  430. // Capture inits
  431. for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
  432. E = S->capture_init_end();
  433. I != E; ++I)
  434. *I = Record.readSubExpr();
  435. // Body
  436. S->setCapturedStmt(Record.readSubStmt());
  437. S->getCapturedDecl()->setBody(S->getCapturedStmt());
  438. // Captures
  439. for (auto &I : S->captures()) {
  440. I.VarAndKind.setPointer(readDeclAs<VarDecl>());
  441. I.VarAndKind.setInt(
  442. static_cast<CapturedStmt::VariableCaptureKind>(Record.readInt()));
  443. I.Loc = readSourceLocation();
  444. }
  445. }
  446. void ASTStmtReader::VisitExpr(Expr *E) {
  447. VisitStmt(E);
  448. E->setType(Record.readType());
  449. // FIXME: write and read all DependentFlags with a single call.
  450. bool TypeDependent = Record.readInt();
  451. bool ValueDependent = Record.readInt();
  452. bool InstantiationDependent = Record.readInt();
  453. bool ContainsUnexpandedTemplateParameters = Record.readInt();
  454. bool ContainsErrors = Record.readInt();
  455. auto Deps = ExprDependence::None;
  456. if (TypeDependent)
  457. Deps |= ExprDependence::Type;
  458. if (ValueDependent)
  459. Deps |= ExprDependence::Value;
  460. if (InstantiationDependent)
  461. Deps |= ExprDependence::Instantiation;
  462. if (ContainsUnexpandedTemplateParameters)
  463. Deps |= ExprDependence::UnexpandedPack;
  464. if (ContainsErrors)
  465. Deps |= ExprDependence::Error;
  466. E->setDependence(Deps);
  467. E->setValueKind(static_cast<ExprValueKind>(Record.readInt()));
  468. E->setObjectKind(static_cast<ExprObjectKind>(Record.readInt()));
  469. assert(Record.getIdx() == NumExprFields &&
  470. "Incorrect expression field count");
  471. }
  472. void ASTStmtReader::VisitConstantExpr(ConstantExpr *E) {
  473. VisitExpr(E);
  474. auto StorageKind = Record.readInt();
  475. assert(E->ConstantExprBits.ResultKind == StorageKind && "Wrong ResultKind!");
  476. E->ConstantExprBits.APValueKind = Record.readInt();
  477. E->ConstantExprBits.IsUnsigned = Record.readInt();
  478. E->ConstantExprBits.BitWidth = Record.readInt();
  479. E->ConstantExprBits.HasCleanup = false; // Not serialized, see below.
  480. E->ConstantExprBits.IsImmediateInvocation = Record.readInt();
  481. switch (StorageKind) {
  482. case ConstantExpr::RSK_None:
  483. break;
  484. case ConstantExpr::RSK_Int64:
  485. E->Int64Result() = Record.readInt();
  486. break;
  487. case ConstantExpr::RSK_APValue:
  488. E->APValueResult() = Record.readAPValue();
  489. if (E->APValueResult().needsCleanup()) {
  490. E->ConstantExprBits.HasCleanup = true;
  491. Record.getContext().addDestruction(&E->APValueResult());
  492. }
  493. break;
  494. default:
  495. llvm_unreachable("unexpected ResultKind!");
  496. }
  497. E->setSubExpr(Record.readSubExpr());
  498. }
  499. void ASTStmtReader::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
  500. VisitExpr(E);
  501. E->setLocation(readSourceLocation());
  502. E->setLParenLocation(readSourceLocation());
  503. E->setRParenLocation(readSourceLocation());
  504. E->setTypeSourceInfo(Record.readTypeSourceInfo());
  505. }
  506. void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
  507. VisitExpr(E);
  508. bool HasFunctionName = Record.readInt();
  509. E->PredefinedExprBits.HasFunctionName = HasFunctionName;
  510. E->PredefinedExprBits.Kind = Record.readInt();
  511. E->setLocation(readSourceLocation());
  512. if (HasFunctionName)
  513. E->setFunctionName(cast<StringLiteral>(Record.readSubExpr()));
  514. }
  515. void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
  516. VisitExpr(E);
  517. E->DeclRefExprBits.HasQualifier = Record.readInt();
  518. E->DeclRefExprBits.HasFoundDecl = Record.readInt();
  519. E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record.readInt();
  520. E->DeclRefExprBits.HadMultipleCandidates = Record.readInt();
  521. E->DeclRefExprBits.RefersToEnclosingVariableOrCapture = Record.readInt();
  522. E->DeclRefExprBits.NonOdrUseReason = Record.readInt();
  523. unsigned NumTemplateArgs = 0;
  524. if (E->hasTemplateKWAndArgsInfo())
  525. NumTemplateArgs = Record.readInt();
  526. if (E->hasQualifier())
  527. new (E->getTrailingObjects<NestedNameSpecifierLoc>())
  528. NestedNameSpecifierLoc(Record.readNestedNameSpecifierLoc());
  529. if (E->hasFoundDecl())
  530. *E->getTrailingObjects<NamedDecl *>() = readDeclAs<NamedDecl>();
  531. if (E->hasTemplateKWAndArgsInfo())
  532. ReadTemplateKWAndArgsInfo(
  533. *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
  534. E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
  535. E->D = readDeclAs<ValueDecl>();
  536. E->setLocation(readSourceLocation());
  537. E->DNLoc = Record.readDeclarationNameLoc(E->getDecl()->getDeclName());
  538. }
  539. void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
  540. VisitExpr(E);
  541. E->setLocation(readSourceLocation());
  542. E->setValue(Record.getContext(), Record.readAPInt());
  543. }
  544. void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
  545. VisitExpr(E);
  546. E->setLocation(readSourceLocation());
  547. E->setScale(Record.readInt());
  548. E->setValue(Record.getContext(), Record.readAPInt());
  549. }
  550. void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
  551. VisitExpr(E);
  552. E->setRawSemantics(
  553. static_cast<llvm::APFloatBase::Semantics>(Record.readInt()));
  554. E->setExact(Record.readInt());
  555. E->setValue(Record.getContext(), Record.readAPFloat(E->getSemantics()));
  556. E->setLocation(readSourceLocation());
  557. }
  558. void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
  559. VisitExpr(E);
  560. E->setSubExpr(Record.readSubExpr());
  561. }
  562. void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
  563. VisitExpr(E);
  564. // NumConcatenated, Length and CharByteWidth are set by the empty
  565. // ctor since they are needed to allocate storage for the trailing objects.
  566. unsigned NumConcatenated = Record.readInt();
  567. unsigned Length = Record.readInt();
  568. unsigned CharByteWidth = Record.readInt();
  569. assert((NumConcatenated == E->getNumConcatenated()) &&
  570. "Wrong number of concatenated tokens!");
  571. assert((Length == E->getLength()) && "Wrong Length!");
  572. assert((CharByteWidth == E->getCharByteWidth()) && "Wrong character width!");
  573. E->StringLiteralBits.Kind = Record.readInt();
  574. E->StringLiteralBits.IsPascal = Record.readInt();
  575. // The character width is originally computed via mapCharByteWidth.
  576. // Check that the deserialized character width is consistant with the result
  577. // of calling mapCharByteWidth.
  578. assert((CharByteWidth ==
  579. StringLiteral::mapCharByteWidth(Record.getContext().getTargetInfo(),
  580. E->getKind())) &&
  581. "Wrong character width!");
  582. // Deserialize the trailing array of SourceLocation.
  583. for (unsigned I = 0; I < NumConcatenated; ++I)
  584. E->setStrTokenLoc(I, readSourceLocation());
  585. // Deserialize the trailing array of char holding the string data.
  586. char *StrData = E->getStrDataAsChar();
  587. for (unsigned I = 0; I < Length * CharByteWidth; ++I)
  588. StrData[I] = Record.readInt();
  589. }
  590. void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
  591. VisitExpr(E);
  592. E->setValue(Record.readInt());
  593. E->setLocation(readSourceLocation());
  594. E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record.readInt()));
  595. }
  596. void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
  597. VisitExpr(E);
  598. E->setLParen(readSourceLocation());
  599. E->setRParen(readSourceLocation());
  600. E->setSubExpr(Record.readSubExpr());
  601. }
  602. void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
  603. VisitExpr(E);
  604. unsigned NumExprs = Record.readInt();
  605. assert((NumExprs == E->getNumExprs()) && "Wrong NumExprs!");
  606. for (unsigned I = 0; I != NumExprs; ++I)
  607. E->getTrailingObjects<Stmt *>()[I] = Record.readSubStmt();
  608. E->LParenLoc = readSourceLocation();
  609. E->RParenLoc = readSourceLocation();
  610. }
  611. void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
  612. VisitExpr(E);
  613. bool hasFP_Features = Record.readInt();
  614. assert(hasFP_Features == E->hasStoredFPFeatures());
  615. E->setSubExpr(Record.readSubExpr());
  616. E->setOpcode((UnaryOperator::Opcode)Record.readInt());
  617. E->setOperatorLoc(readSourceLocation());
  618. E->setCanOverflow(Record.readInt());
  619. if (hasFP_Features)
  620. E->setStoredFPFeatures(
  621. FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
  622. }
  623. void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
  624. VisitExpr(E);
  625. assert(E->getNumComponents() == Record.peekInt());
  626. Record.skipInts(1);
  627. assert(E->getNumExpressions() == Record.peekInt());
  628. Record.skipInts(1);
  629. E->setOperatorLoc(readSourceLocation());
  630. E->setRParenLoc(readSourceLocation());
  631. E->setTypeSourceInfo(readTypeSourceInfo());
  632. for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
  633. auto Kind = static_cast<OffsetOfNode::Kind>(Record.readInt());
  634. SourceLocation Start = readSourceLocation();
  635. SourceLocation End = readSourceLocation();
  636. switch (Kind) {
  637. case OffsetOfNode::Array:
  638. E->setComponent(I, OffsetOfNode(Start, Record.readInt(), End));
  639. break;
  640. case OffsetOfNode::Field:
  641. E->setComponent(
  642. I, OffsetOfNode(Start, readDeclAs<FieldDecl>(), End));
  643. break;
  644. case OffsetOfNode::Identifier:
  645. E->setComponent(
  646. I,
  647. OffsetOfNode(Start, Record.readIdentifier(), End));
  648. break;
  649. case OffsetOfNode::Base: {
  650. auto *Base = new (Record.getContext()) CXXBaseSpecifier();
  651. *Base = Record.readCXXBaseSpecifier();
  652. E->setComponent(I, OffsetOfNode(Base));
  653. break;
  654. }
  655. }
  656. }
  657. for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
  658. E->setIndexExpr(I, Record.readSubExpr());
  659. }
  660. void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
  661. VisitExpr(E);
  662. E->setKind(static_cast<UnaryExprOrTypeTrait>(Record.readInt()));
  663. if (Record.peekInt() == 0) {
  664. E->setArgument(Record.readSubExpr());
  665. Record.skipInts(1);
  666. } else {
  667. E->setArgument(readTypeSourceInfo());
  668. }
  669. E->setOperatorLoc(readSourceLocation());
  670. E->setRParenLoc(readSourceLocation());
  671. }
  672. static ConstraintSatisfaction
  673. readConstraintSatisfaction(ASTRecordReader &Record) {
  674. ConstraintSatisfaction Satisfaction;
  675. Satisfaction.IsSatisfied = Record.readInt();
  676. if (!Satisfaction.IsSatisfied) {
  677. unsigned NumDetailRecords = Record.readInt();
  678. for (unsigned i = 0; i != NumDetailRecords; ++i) {
  679. Expr *ConstraintExpr = Record.readExpr();
  680. if (/* IsDiagnostic */Record.readInt()) {
  681. SourceLocation DiagLocation = Record.readSourceLocation();
  682. std::string DiagMessage = Record.readString();
  683. Satisfaction.Details.emplace_back(
  684. ConstraintExpr, new (Record.getContext())
  685. ConstraintSatisfaction::SubstitutionDiagnostic{
  686. DiagLocation, DiagMessage});
  687. } else
  688. Satisfaction.Details.emplace_back(ConstraintExpr, Record.readExpr());
  689. }
  690. }
  691. return Satisfaction;
  692. }
  693. void ASTStmtReader::VisitConceptSpecializationExpr(
  694. ConceptSpecializationExpr *E) {
  695. VisitExpr(E);
  696. unsigned NumTemplateArgs = Record.readInt();
  697. E->NestedNameSpec = Record.readNestedNameSpecifierLoc();
  698. E->TemplateKWLoc = Record.readSourceLocation();
  699. E->ConceptName = Record.readDeclarationNameInfo();
  700. E->NamedConcept = readDeclAs<ConceptDecl>();
  701. E->FoundDecl = Record.readDeclAs<NamedDecl>();
  702. E->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
  703. llvm::SmallVector<TemplateArgument, 4> Args;
  704. for (unsigned I = 0; I < NumTemplateArgs; ++I)
  705. Args.push_back(Record.readTemplateArgument());
  706. E->setTemplateArguments(Args);
  707. E->Satisfaction = E->isValueDependent() ? nullptr :
  708. ASTConstraintSatisfaction::Create(Record.getContext(),
  709. readConstraintSatisfaction(Record));
  710. }
  711. static concepts::Requirement::SubstitutionDiagnostic *
  712. readSubstitutionDiagnostic(ASTRecordReader &Record) {
  713. std::string SubstitutedEntity = Record.readString();
  714. SourceLocation DiagLoc = Record.readSourceLocation();
  715. std::string DiagMessage = Record.readString();
  716. return new (Record.getContext())
  717. concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
  718. DiagMessage};
  719. }
  720. void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
  721. VisitExpr(E);
  722. unsigned NumLocalParameters = Record.readInt();
  723. unsigned NumRequirements = Record.readInt();
  724. E->RequiresExprBits.RequiresKWLoc = Record.readSourceLocation();
  725. E->RequiresExprBits.IsSatisfied = Record.readInt();
  726. E->Body = Record.readDeclAs<RequiresExprBodyDecl>();
  727. llvm::SmallVector<ParmVarDecl *, 4> LocalParameters;
  728. for (unsigned i = 0; i < NumLocalParameters; ++i)
  729. LocalParameters.push_back(cast<ParmVarDecl>(Record.readDecl()));
  730. std::copy(LocalParameters.begin(), LocalParameters.end(),
  731. E->getTrailingObjects<ParmVarDecl *>());
  732. llvm::SmallVector<concepts::Requirement *, 4> Requirements;
  733. for (unsigned i = 0; i < NumRequirements; ++i) {
  734. auto RK =
  735. static_cast<concepts::Requirement::RequirementKind>(Record.readInt());
  736. concepts::Requirement *R = nullptr;
  737. switch (RK) {
  738. case concepts::Requirement::RK_Type: {
  739. auto Status =
  740. static_cast<concepts::TypeRequirement::SatisfactionStatus>(
  741. Record.readInt());
  742. if (Status == concepts::TypeRequirement::SS_SubstitutionFailure)
  743. R = new (Record.getContext())
  744. concepts::TypeRequirement(readSubstitutionDiagnostic(Record));
  745. else
  746. R = new (Record.getContext())
  747. concepts::TypeRequirement(Record.readTypeSourceInfo());
  748. } break;
  749. case concepts::Requirement::RK_Simple:
  750. case concepts::Requirement::RK_Compound: {
  751. auto Status =
  752. static_cast<concepts::ExprRequirement::SatisfactionStatus>(
  753. Record.readInt());
  754. llvm::PointerUnion<concepts::Requirement::SubstitutionDiagnostic *,
  755. Expr *> E;
  756. if (Status == concepts::ExprRequirement::SS_ExprSubstitutionFailure) {
  757. E = readSubstitutionDiagnostic(Record);
  758. } else
  759. E = Record.readExpr();
  760. llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> Req;
  761. ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
  762. SourceLocation NoexceptLoc;
  763. if (RK == concepts::Requirement::RK_Simple) {
  764. Req.emplace();
  765. } else {
  766. NoexceptLoc = Record.readSourceLocation();
  767. switch (/* returnTypeRequirementKind */Record.readInt()) {
  768. case 0:
  769. // No return type requirement.
  770. Req.emplace();
  771. break;
  772. case 1: {
  773. // type-constraint
  774. TemplateParameterList *TPL = Record.readTemplateParameterList();
  775. if (Status >=
  776. concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
  777. SubstitutedConstraintExpr =
  778. cast<ConceptSpecializationExpr>(Record.readExpr());
  779. Req.emplace(TPL);
  780. } break;
  781. case 2:
  782. // Substitution failure
  783. Req.emplace(readSubstitutionDiagnostic(Record));
  784. break;
  785. }
  786. }
  787. if (Expr *Ex = E.dyn_cast<Expr *>())
  788. R = new (Record.getContext()) concepts::ExprRequirement(
  789. Ex, RK == concepts::Requirement::RK_Simple, NoexceptLoc,
  790. std::move(*Req), Status, SubstitutedConstraintExpr);
  791. else
  792. R = new (Record.getContext()) concepts::ExprRequirement(
  793. E.get<concepts::Requirement::SubstitutionDiagnostic *>(),
  794. RK == concepts::Requirement::RK_Simple, NoexceptLoc,
  795. std::move(*Req));
  796. } break;
  797. case concepts::Requirement::RK_Nested: {
  798. if (/* IsSubstitutionDiagnostic */Record.readInt()) {
  799. R = new (Record.getContext()) concepts::NestedRequirement(
  800. readSubstitutionDiagnostic(Record));
  801. break;
  802. }
  803. Expr *E = Record.readExpr();
  804. if (E->isInstantiationDependent())
  805. R = new (Record.getContext()) concepts::NestedRequirement(E);
  806. else
  807. R = new (Record.getContext())
  808. concepts::NestedRequirement(Record.getContext(), E,
  809. readConstraintSatisfaction(Record));
  810. } break;
  811. }
  812. if (!R)
  813. continue;
  814. Requirements.push_back(R);
  815. }
  816. std::copy(Requirements.begin(), Requirements.end(),
  817. E->getTrailingObjects<concepts::Requirement *>());
  818. E->RBraceLoc = Record.readSourceLocation();
  819. }
  820. void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
  821. VisitExpr(E);
  822. E->setLHS(Record.readSubExpr());
  823. E->setRHS(Record.readSubExpr());
  824. E->setRBracketLoc(readSourceLocation());
  825. }
  826. void ASTStmtReader::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
  827. VisitExpr(E);
  828. E->setBase(Record.readSubExpr());
  829. E->setRowIdx(Record.readSubExpr());
  830. E->setColumnIdx(Record.readSubExpr());
  831. E->setRBracketLoc(readSourceLocation());
  832. }
  833. void ASTStmtReader::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
  834. VisitExpr(E);
  835. E->setBase(Record.readSubExpr());
  836. E->setLowerBound(Record.readSubExpr());
  837. E->setLength(Record.readSubExpr());
  838. E->setStride(Record.readSubExpr());
  839. E->setColonLocFirst(readSourceLocation());
  840. E->setColonLocSecond(readSourceLocation());
  841. E->setRBracketLoc(readSourceLocation());
  842. }
  843. void ASTStmtReader::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
  844. VisitExpr(E);
  845. unsigned NumDims = Record.readInt();
  846. E->setBase(Record.readSubExpr());
  847. SmallVector<Expr *, 4> Dims(NumDims);
  848. for (unsigned I = 0; I < NumDims; ++I)
  849. Dims[I] = Record.readSubExpr();
  850. E->setDimensions(Dims);
  851. SmallVector<SourceRange, 4> SRs(NumDims);
  852. for (unsigned I = 0; I < NumDims; ++I)
  853. SRs[I] = readSourceRange();
  854. E->setBracketsRanges(SRs);
  855. E->setLParenLoc(readSourceLocation());
  856. E->setRParenLoc(readSourceLocation());
  857. }
  858. void ASTStmtReader::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
  859. VisitExpr(E);
  860. unsigned NumIters = Record.readInt();
  861. E->setIteratorKwLoc(readSourceLocation());
  862. E->setLParenLoc(readSourceLocation());
  863. E->setRParenLoc(readSourceLocation());
  864. for (unsigned I = 0; I < NumIters; ++I) {
  865. E->setIteratorDeclaration(I, Record.readDeclRef());
  866. E->setAssignmentLoc(I, readSourceLocation());
  867. Expr *Begin = Record.readSubExpr();
  868. Expr *End = Record.readSubExpr();
  869. Expr *Step = Record.readSubExpr();
  870. SourceLocation ColonLoc = readSourceLocation();
  871. SourceLocation SecColonLoc;
  872. if (Step)
  873. SecColonLoc = readSourceLocation();
  874. E->setIteratorRange(I, Begin, ColonLoc, End, SecColonLoc, Step);
  875. // Deserialize helpers
  876. OMPIteratorHelperData HD;
  877. HD.CounterVD = cast_or_null<VarDecl>(Record.readDeclRef());
  878. HD.Upper = Record.readSubExpr();
  879. HD.Update = Record.readSubExpr();
  880. HD.CounterUpdate = Record.readSubExpr();
  881. E->setHelper(I, HD);
  882. }
  883. }
  884. void ASTStmtReader::VisitCallExpr(CallExpr *E) {
  885. VisitExpr(E);
  886. unsigned NumArgs = Record.readInt();
  887. bool HasFPFeatures = Record.readInt();
  888. assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
  889. E->setRParenLoc(readSourceLocation());
  890. E->setCallee(Record.readSubExpr());
  891. for (unsigned I = 0; I != NumArgs; ++I)
  892. E->setArg(I, Record.readSubExpr());
  893. E->setADLCallKind(static_cast<CallExpr::ADLCallKind>(Record.readInt()));
  894. if (HasFPFeatures)
  895. E->setStoredFPFeatures(
  896. FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
  897. }
  898. void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
  899. VisitCallExpr(E);
  900. }
  901. void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
  902. VisitExpr(E);
  903. bool HasQualifier = Record.readInt();
  904. bool HasFoundDecl = Record.readInt();
  905. bool HasTemplateInfo = Record.readInt();
  906. unsigned NumTemplateArgs = Record.readInt();
  907. E->Base = Record.readSubExpr();
  908. E->MemberDecl = Record.readDeclAs<ValueDecl>();
  909. E->MemberDNLoc = Record.readDeclarationNameLoc(E->MemberDecl->getDeclName());
  910. E->MemberLoc = Record.readSourceLocation();
  911. E->MemberExprBits.IsArrow = Record.readInt();
  912. E->MemberExprBits.HasQualifierOrFoundDecl = HasQualifier || HasFoundDecl;
  913. E->MemberExprBits.HasTemplateKWAndArgsInfo = HasTemplateInfo;
  914. E->MemberExprBits.HadMultipleCandidates = Record.readInt();
  915. E->MemberExprBits.NonOdrUseReason = Record.readInt();
  916. E->MemberExprBits.OperatorLoc = Record.readSourceLocation();
  917. if (HasQualifier || HasFoundDecl) {
  918. DeclAccessPair FoundDecl;
  919. if (HasFoundDecl) {
  920. auto *FoundD = Record.readDeclAs<NamedDecl>();
  921. auto AS = (AccessSpecifier)Record.readInt();
  922. FoundDecl = DeclAccessPair::make(FoundD, AS);
  923. } else {
  924. FoundDecl = DeclAccessPair::make(E->MemberDecl,
  925. E->MemberDecl->getAccess());
  926. }
  927. E->getTrailingObjects<MemberExprNameQualifier>()->FoundDecl = FoundDecl;
  928. NestedNameSpecifierLoc QualifierLoc;
  929. if (HasQualifier)
  930. QualifierLoc = Record.readNestedNameSpecifierLoc();
  931. E->getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc =
  932. QualifierLoc;
  933. }
  934. if (HasTemplateInfo)
  935. ReadTemplateKWAndArgsInfo(
  936. *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
  937. E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
  938. }
  939. void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
  940. VisitExpr(E);
  941. E->setBase(Record.readSubExpr());
  942. E->setIsaMemberLoc(readSourceLocation());
  943. E->setOpLoc(readSourceLocation());
  944. E->setArrow(Record.readInt());
  945. }
  946. void ASTStmtReader::
  947. VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
  948. VisitExpr(E);
  949. E->Operand = Record.readSubExpr();
  950. E->setShouldCopy(Record.readInt());
  951. }
  952. void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
  953. VisitExplicitCastExpr(E);
  954. E->LParenLoc = readSourceLocation();
  955. E->BridgeKeywordLoc = readSourceLocation();
  956. E->Kind = Record.readInt();
  957. }
  958. void ASTStmtReader::VisitCastExpr(CastExpr *E) {
  959. VisitExpr(E);
  960. unsigned NumBaseSpecs = Record.readInt();
  961. assert(NumBaseSpecs == E->path_size());
  962. unsigned HasFPFeatures = Record.readInt();
  963. assert(E->hasStoredFPFeatures() == HasFPFeatures);
  964. E->setSubExpr(Record.readSubExpr());
  965. E->setCastKind((CastKind)Record.readInt());
  966. CastExpr::path_iterator BaseI = E->path_begin();
  967. while (NumBaseSpecs--) {
  968. auto *BaseSpec = new (Record.getContext()) CXXBaseSpecifier;
  969. *BaseSpec = Record.readCXXBaseSpecifier();
  970. *BaseI++ = BaseSpec;
  971. }
  972. if (HasFPFeatures)
  973. *E->getTrailingFPFeatures() =
  974. FPOptionsOverride::getFromOpaqueInt(Record.readInt());
  975. }
  976. void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
  977. bool hasFP_Features;
  978. VisitExpr(E);
  979. E->setHasStoredFPFeatures(hasFP_Features = Record.readInt());
  980. E->setOpcode((BinaryOperator::Opcode)Record.readInt());
  981. E->setLHS(Record.readSubExpr());
  982. E->setRHS(Record.readSubExpr());
  983. E->setOperatorLoc(readSourceLocation());
  984. if (hasFP_Features)
  985. E->setStoredFPFeatures(
  986. FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
  987. }
  988. void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
  989. VisitBinaryOperator(E);
  990. E->setComputationLHSType(Record.readType());
  991. E->setComputationResultType(Record.readType());
  992. }
  993. void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
  994. VisitExpr(E);
  995. E->SubExprs[ConditionalOperator::COND] = Record.readSubExpr();
  996. E->SubExprs[ConditionalOperator::LHS] = Record.readSubExpr();
  997. E->SubExprs[ConditionalOperator::RHS] = Record.readSubExpr();
  998. E->QuestionLoc = readSourceLocation();
  999. E->ColonLoc = readSourceLocation();
  1000. }
  1001. void
  1002. ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
  1003. VisitExpr(E);
  1004. E->OpaqueValue = cast<OpaqueValueExpr>(Record.readSubExpr());
  1005. E->SubExprs[BinaryConditionalOperator::COMMON] = Record.readSubExpr();
  1006. E->SubExprs[BinaryConditionalOperator::COND] = Record.readSubExpr();
  1007. E->SubExprs[BinaryConditionalOperator::LHS] = Record.readSubExpr();
  1008. E->SubExprs[BinaryConditionalOperator::RHS] = Record.readSubExpr();
  1009. E->QuestionLoc = readSourceLocation();
  1010. E->ColonLoc = readSourceLocation();
  1011. }
  1012. void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
  1013. VisitCastExpr(E);
  1014. E->setIsPartOfExplicitCast(Record.readInt());
  1015. }
  1016. void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
  1017. VisitCastExpr(E);
  1018. E->setTypeInfoAsWritten(readTypeSourceInfo());
  1019. }
  1020. void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
  1021. VisitExplicitCastExpr(E);
  1022. E->setLParenLoc(readSourceLocation());
  1023. E->setRParenLoc(readSourceLocation());
  1024. }
  1025. void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
  1026. VisitExpr(E);
  1027. E->setLParenLoc(readSourceLocation());
  1028. E->setTypeSourceInfo(readTypeSourceInfo());
  1029. E->setInitializer(Record.readSubExpr());
  1030. E->setFileScope(Record.readInt());
  1031. }
  1032. void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
  1033. VisitExpr(E);
  1034. E->setBase(Record.readSubExpr());
  1035. E->setAccessor(Record.readIdentifier());
  1036. E->setAccessorLoc(readSourceLocation());
  1037. }
  1038. void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
  1039. VisitExpr(E);
  1040. if (auto *SyntForm = cast_or_null<InitListExpr>(Record.readSubStmt()))
  1041. E->setSyntacticForm(SyntForm);
  1042. E->setLBraceLoc(readSourceLocation());
  1043. E->setRBraceLoc(readSourceLocation());
  1044. bool isArrayFiller = Record.readInt();
  1045. Expr *filler = nullptr;
  1046. if (isArrayFiller) {
  1047. filler = Record.readSubExpr();
  1048. E->ArrayFillerOrUnionFieldInit = filler;
  1049. } else
  1050. E->ArrayFillerOrUnionFieldInit = readDeclAs<FieldDecl>();
  1051. E->sawArrayRangeDesignator(Record.readInt());
  1052. unsigned NumInits = Record.readInt();
  1053. E->reserveInits(Record.getContext(), NumInits);
  1054. if (isArrayFiller) {
  1055. for (unsigned I = 0; I != NumInits; ++I) {
  1056. Expr *init = Record.readSubExpr();
  1057. E->updateInit(Record.getContext(), I, init ? init : filler);
  1058. }
  1059. } else {
  1060. for (unsigned I = 0; I != NumInits; ++I)
  1061. E->updateInit(Record.getContext(), I, Record.readSubExpr());
  1062. }
  1063. }
  1064. void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
  1065. using Designator = DesignatedInitExpr::Designator;
  1066. VisitExpr(E);
  1067. unsigned NumSubExprs = Record.readInt();
  1068. assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
  1069. for (unsigned I = 0; I != NumSubExprs; ++I)
  1070. E->setSubExpr(I, Record.readSubExpr());
  1071. E->setEqualOrColonLoc(readSourceLocation());
  1072. E->setGNUSyntax(Record.readInt());
  1073. SmallVector<Designator, 4> Designators;
  1074. while (Record.getIdx() < Record.size()) {
  1075. switch ((DesignatorTypes)Record.readInt()) {
  1076. case DESIG_FIELD_DECL: {
  1077. auto *Field = readDeclAs<FieldDecl>();
  1078. SourceLocation DotLoc = readSourceLocation();
  1079. SourceLocation FieldLoc = readSourceLocation();
  1080. Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
  1081. FieldLoc));
  1082. Designators.back().setField(Field);
  1083. break;
  1084. }
  1085. case DESIG_FIELD_NAME: {
  1086. const IdentifierInfo *Name = Record.readIdentifier();
  1087. SourceLocation DotLoc = readSourceLocation();
  1088. SourceLocation FieldLoc = readSourceLocation();
  1089. Designators.push_back(Designator(Name, DotLoc, FieldLoc));
  1090. break;
  1091. }
  1092. case DESIG_ARRAY: {
  1093. unsigned Index = Record.readInt();
  1094. SourceLocation LBracketLoc = readSourceLocation();
  1095. SourceLocation RBracketLoc = readSourceLocation();
  1096. Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
  1097. break;
  1098. }
  1099. case DESIG_ARRAY_RANGE: {
  1100. unsigned Index = Record.readInt();
  1101. SourceLocation LBracketLoc = readSourceLocation();
  1102. SourceLocation EllipsisLoc = readSourceLocation();
  1103. SourceLocation RBracketLoc = readSourceLocation();
  1104. Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
  1105. RBracketLoc));
  1106. break;
  1107. }
  1108. }
  1109. }
  1110. E->setDesignators(Record.getContext(),
  1111. Designators.data(), Designators.size());
  1112. }
  1113. void ASTStmtReader::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
  1114. VisitExpr(E);
  1115. E->setBase(Record.readSubExpr());
  1116. E->setUpdater(Record.readSubExpr());
  1117. }
  1118. void ASTStmtReader::VisitNoInitExpr(NoInitExpr *E) {
  1119. VisitExpr(E);
  1120. }
  1121. void ASTStmtReader::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
  1122. VisitExpr(E);
  1123. E->SubExprs[0] = Record.readSubExpr();
  1124. E->SubExprs[1] = Record.readSubExpr();
  1125. }
  1126. void ASTStmtReader::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
  1127. VisitExpr(E);
  1128. }
  1129. void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
  1130. VisitExpr(E);
  1131. }
  1132. void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
  1133. VisitExpr(E);
  1134. E->setSubExpr(Record.readSubExpr());
  1135. E->setWrittenTypeInfo(readTypeSourceInfo());
  1136. E->setBuiltinLoc(readSourceLocation());
  1137. E->setRParenLoc(readSourceLocation());
  1138. E->setIsMicrosoftABI(Record.readInt());
  1139. }
  1140. void ASTStmtReader::VisitSourceLocExpr(SourceLocExpr *E) {
  1141. VisitExpr(E);
  1142. E->ParentContext = readDeclAs<DeclContext>();
  1143. E->BuiltinLoc = readSourceLocation();
  1144. E->RParenLoc = readSourceLocation();
  1145. E->SourceLocExprBits.Kind =
  1146. static_cast<SourceLocExpr::IdentKind>(Record.readInt());
  1147. }
  1148. void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
  1149. VisitExpr(E);
  1150. E->setAmpAmpLoc(readSourceLocation());
  1151. E->setLabelLoc(readSourceLocation());
  1152. E->setLabel(readDeclAs<LabelDecl>());
  1153. }
  1154. void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
  1155. VisitExpr(E);
  1156. E->setLParenLoc(readSourceLocation());
  1157. E->setRParenLoc(readSourceLocation());
  1158. E->setSubStmt(cast_or_null<CompoundStmt>(Record.readSubStmt()));
  1159. E->StmtExprBits.TemplateDepth = Record.readInt();
  1160. }
  1161. void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
  1162. VisitExpr(E);
  1163. E->setCond(Record.readSubExpr());
  1164. E->setLHS(Record.readSubExpr());
  1165. E->setRHS(Record.readSubExpr());
  1166. E->setBuiltinLoc(readSourceLocation());
  1167. E->setRParenLoc(readSourceLocation());
  1168. E->setIsConditionTrue(Record.readInt());
  1169. }
  1170. void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
  1171. VisitExpr(E);
  1172. E->setTokenLocation(readSourceLocation());
  1173. }
  1174. void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
  1175. VisitExpr(E);
  1176. SmallVector<Expr *, 16> Exprs;
  1177. unsigned NumExprs = Record.readInt();
  1178. while (NumExprs--)
  1179. Exprs.push_back(Record.readSubExpr());
  1180. E->setExprs(Record.getContext(), Exprs);
  1181. E->setBuiltinLoc(readSourceLocation());
  1182. E->setRParenLoc(readSourceLocation());
  1183. }
  1184. void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) {
  1185. VisitExpr(E);
  1186. E->BuiltinLoc = readSourceLocation();
  1187. E->RParenLoc = readSourceLocation();
  1188. E->TInfo = readTypeSourceInfo();
  1189. E->SrcExpr = Record.readSubExpr();
  1190. }
  1191. void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
  1192. VisitExpr(E);
  1193. E->setBlockDecl(readDeclAs<BlockDecl>());
  1194. }
  1195. void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
  1196. VisitExpr(E);
  1197. unsigned NumAssocs = Record.readInt();
  1198. assert(NumAssocs == E->getNumAssocs() && "Wrong NumAssocs!");
  1199. E->ResultIndex = Record.readInt();
  1200. E->GenericSelectionExprBits.GenericLoc = readSourceLocation();
  1201. E->DefaultLoc = readSourceLocation();
  1202. E->RParenLoc = readSourceLocation();
  1203. Stmt **Stmts = E->getTrailingObjects<Stmt *>();
  1204. // Add 1 to account for the controlling expression which is the first
  1205. // expression in the trailing array of Stmt *. This is not needed for
  1206. // the trailing array of TypeSourceInfo *.
  1207. for (unsigned I = 0, N = NumAssocs + 1; I < N; ++I)
  1208. Stmts[I] = Record.readSubExpr();
  1209. TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
  1210. for (unsigned I = 0, N = NumAssocs; I < N; ++I)
  1211. TSIs[I] = readTypeSourceInfo();
  1212. }
  1213. void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
  1214. VisitExpr(E);
  1215. unsigned numSemanticExprs = Record.readInt();
  1216. assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
  1217. E->PseudoObjectExprBits.ResultIndex = Record.readInt();
  1218. // Read the syntactic expression.
  1219. E->getSubExprsBuffer()[0] = Record.readSubExpr();
  1220. // Read all the semantic expressions.
  1221. for (unsigned i = 0; i != numSemanticExprs; ++i) {
  1222. Expr *subExpr = Record.readSubExpr();
  1223. E->getSubExprsBuffer()[i+1] = subExpr;
  1224. }
  1225. }
  1226. void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) {
  1227. VisitExpr(E);
  1228. E->Op = AtomicExpr::AtomicOp(Record.readInt());
  1229. E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op);
  1230. for (unsigned I = 0; I != E->NumSubExprs; ++I)
  1231. E->SubExprs[I] = Record.readSubExpr();
  1232. E->BuiltinLoc = readSourceLocation();
  1233. E->RParenLoc = readSourceLocation();
  1234. }
  1235. //===----------------------------------------------------------------------===//
  1236. // Objective-C Expressions and Statements
  1237. void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
  1238. VisitExpr(E);
  1239. E->setString(cast<StringLiteral>(Record.readSubStmt()));
  1240. E->setAtLoc(readSourceLocation());
  1241. }
  1242. void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
  1243. VisitExpr(E);
  1244. // could be one of several IntegerLiteral, FloatLiteral, etc.
  1245. E->SubExpr = Record.readSubStmt();
  1246. E->BoxingMethod = readDeclAs<ObjCMethodDecl>();
  1247. E->Range = readSourceRange();
  1248. }
  1249. void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
  1250. VisitExpr(E);
  1251. unsigned NumElements = Record.readInt();
  1252. assert(NumElements == E->getNumElements() && "Wrong number of elements");
  1253. Expr **Elements = E->getElements();
  1254. for (unsigned I = 0, N = NumElements; I != N; ++I)
  1255. Elements[I] = Record.readSubExpr();
  1256. E->ArrayWithObjectsMethod = readDeclAs<ObjCMethodDecl>();
  1257. E->Range = readSourceRange();
  1258. }
  1259. void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
  1260. VisitExpr(E);
  1261. unsigned NumElements = Record.readInt();
  1262. assert(NumElements == E->getNumElements() && "Wrong number of elements");
  1263. bool HasPackExpansions = Record.readInt();
  1264. assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
  1265. auto *KeyValues =
  1266. E->getTrailingObjects<ObjCDictionaryLiteral::KeyValuePair>();
  1267. auto *Expansions =
  1268. E->getTrailingObjects<ObjCDictionaryLiteral::ExpansionData>();
  1269. for (unsigned I = 0; I != NumElements; ++I) {
  1270. KeyValues[I].Key = Record.readSubExpr();
  1271. KeyValues[I].Value = Record.readSubExpr();
  1272. if (HasPackExpansions) {
  1273. Expansions[I].EllipsisLoc = readSourceLocation();
  1274. Expansions[I].NumExpansionsPlusOne = Record.readInt();
  1275. }
  1276. }
  1277. E->DictWithObjectsMethod = readDeclAs<ObjCMethodDecl>();
  1278. E->Range = readSourceRange();
  1279. }
  1280. void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
  1281. VisitExpr(E);
  1282. E->setEncodedTypeSourceInfo(readTypeSourceInfo());
  1283. E->setAtLoc(readSourceLocation());
  1284. E->setRParenLoc(readSourceLocation());
  1285. }
  1286. void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
  1287. VisitExpr(E);
  1288. E->setSelector(Record.readSelector());
  1289. E->setAtLoc(readSourceLocation());
  1290. E->setRParenLoc(readSourceLocation());
  1291. }
  1292. void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
  1293. VisitExpr(E);
  1294. E->setProtocol(readDeclAs<ObjCProtocolDecl>());
  1295. E->setAtLoc(readSourceLocation());
  1296. E->ProtoLoc = readSourceLocation();
  1297. E->setRParenLoc(readSourceLocation());
  1298. }
  1299. void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
  1300. VisitExpr(E);
  1301. E->setDecl(readDeclAs<ObjCIvarDecl>());
  1302. E->setLocation(readSourceLocation());
  1303. E->setOpLoc(readSourceLocation());
  1304. E->setBase(Record.readSubExpr());
  1305. E->setIsArrow(Record.readInt());
  1306. E->setIsFreeIvar(Record.readInt());
  1307. }
  1308. void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
  1309. VisitExpr(E);
  1310. unsigned MethodRefFlags = Record.readInt();
  1311. bool Implicit = Record.readInt() != 0;
  1312. if (Implicit) {
  1313. auto *Getter = readDeclAs<ObjCMethodDecl>();
  1314. auto *Setter = readDeclAs<ObjCMethodDecl>();
  1315. E->setImplicitProperty(Getter, Setter, MethodRefFlags);
  1316. } else {
  1317. E->setExplicitProperty(readDeclAs<ObjCPropertyDecl>(), MethodRefFlags);
  1318. }
  1319. E->setLocation(readSourceLocation());
  1320. E->setReceiverLocation(readSourceLocation());
  1321. switch (Record.readInt()) {
  1322. case 0:
  1323. E->setBase(Record.readSubExpr());
  1324. break;
  1325. case 1:
  1326. E->setSuperReceiver(Record.readType());
  1327. break;
  1328. case 2:
  1329. E->setClassReceiver(readDeclAs<ObjCInterfaceDecl>());
  1330. break;
  1331. }
  1332. }
  1333. void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
  1334. VisitExpr(E);
  1335. E->setRBracket(readSourceLocation());
  1336. E->setBaseExpr(Record.readSubExpr());
  1337. E->setKeyExpr(Record.readSubExpr());
  1338. E->GetAtIndexMethodDecl = readDeclAs<ObjCMethodDecl>();
  1339. E->SetAtIndexMethodDecl = readDeclAs<ObjCMethodDecl>();
  1340. }
  1341. void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
  1342. VisitExpr(E);
  1343. assert(Record.peekInt() == E->getNumArgs());
  1344. Record.skipInts(1);
  1345. unsigned NumStoredSelLocs = Record.readInt();
  1346. E->SelLocsKind = Record.readInt();
  1347. E->setDelegateInitCall(Record.readInt());
  1348. E->IsImplicit = Record.readInt();
  1349. auto Kind = static_cast<ObjCMessageExpr::ReceiverKind>(Record.readInt());
  1350. switch (Kind) {
  1351. case ObjCMessageExpr::Instance:
  1352. E->setInstanceReceiver(Record.readSubExpr());
  1353. break;
  1354. case ObjCMessageExpr::Class:
  1355. E->setClassReceiver(readTypeSourceInfo());
  1356. break;
  1357. case ObjCMessageExpr::SuperClass:
  1358. case ObjCMessageExpr::SuperInstance: {
  1359. QualType T = Record.readType();
  1360. SourceLocation SuperLoc = readSourceLocation();
  1361. E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
  1362. break;
  1363. }
  1364. }
  1365. assert(Kind == E->getReceiverKind());
  1366. if (Record.readInt())
  1367. E->setMethodDecl(readDeclAs<ObjCMethodDecl>());
  1368. else
  1369. E->setSelector(Record.readSelector());
  1370. E->LBracLoc = readSourceLocation();
  1371. E->RBracLoc = readSourceLocation();
  1372. for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
  1373. E->setArg(I, Record.readSubExpr());
  1374. SourceLocation *Locs = E->getStoredSelLocs();
  1375. for (unsigned I = 0; I != NumStoredSelLocs; ++I)
  1376. Locs[I] = readSourceLocation();
  1377. }
  1378. void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
  1379. VisitStmt(S);
  1380. S->setElement(Record.readSubStmt());
  1381. S->setCollection(Record.readSubExpr());
  1382. S->setBody(Record.readSubStmt());
  1383. S->setForLoc(readSourceLocation());
  1384. S->setRParenLoc(readSourceLocation());
  1385. }
  1386. void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
  1387. VisitStmt(S);
  1388. S->setCatchBody(Record.readSubStmt());
  1389. S->setCatchParamDecl(readDeclAs<VarDecl>());
  1390. S->setAtCatchLoc(readSourceLocation());
  1391. S->setRParenLoc(readSourceLocation());
  1392. }
  1393. void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
  1394. VisitStmt(S);
  1395. S->setFinallyBody(Record.readSubStmt());
  1396. S->setAtFinallyLoc(readSourceLocation());
  1397. }
  1398. void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
  1399. VisitStmt(S); // FIXME: no test coverage.
  1400. S->setSubStmt(Record.readSubStmt());
  1401. S->setAtLoc(readSourceLocation());
  1402. }
  1403. void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
  1404. VisitStmt(S);
  1405. assert(Record.peekInt() == S->getNumCatchStmts());
  1406. Record.skipInts(1);
  1407. bool HasFinally = Record.readInt();
  1408. S->setTryBody(Record.readSubStmt());
  1409. for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
  1410. S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Record.readSubStmt()));
  1411. if (HasFinally)
  1412. S->setFinallyStmt(Record.readSubStmt());
  1413. S->setAtTryLoc(readSourceLocation());
  1414. }
  1415. void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
  1416. VisitStmt(S); // FIXME: no test coverage.
  1417. S->setSynchExpr(Record.readSubStmt());
  1418. S->setSynchBody(Record.readSubStmt());
  1419. S->setAtSynchronizedLoc(readSourceLocation());
  1420. }
  1421. void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
  1422. VisitStmt(S); // FIXME: no test coverage.
  1423. S->setThrowExpr(Record.readSubStmt());
  1424. S->setThrowLoc(readSourceLocation());
  1425. }
  1426. void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
  1427. VisitExpr(E);
  1428. E->setValue(Record.readInt());
  1429. E->setLocation(readSourceLocation());
  1430. }
  1431. void ASTStmtReader::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
  1432. VisitExpr(E);
  1433. SourceRange R = Record.readSourceRange();
  1434. E->AtLoc = R.getBegin();
  1435. E->RParen = R.getEnd();
  1436. E->VersionToCheck = Record.readVersionTuple();
  1437. }
  1438. //===----------------------------------------------------------------------===//
  1439. // C++ Expressions and Statements
  1440. //===----------------------------------------------------------------------===//
  1441. void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
  1442. VisitStmt(S);
  1443. S->CatchLoc = readSourceLocation();
  1444. S->ExceptionDecl = readDeclAs<VarDecl>();
  1445. S->HandlerBlock = Record.readSubStmt();
  1446. }
  1447. void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
  1448. VisitStmt(S);
  1449. assert(Record.peekInt() == S->getNumHandlers() && "NumStmtFields is wrong ?");
  1450. Record.skipInts(1);
  1451. S->TryLoc = readSourceLocation();
  1452. S->getStmts()[0] = Record.readSubStmt();
  1453. for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
  1454. S->getStmts()[i + 1] = Record.readSubStmt();
  1455. }
  1456. void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
  1457. VisitStmt(S);
  1458. S->ForLoc = readSourceLocation();
  1459. S->CoawaitLoc = readSourceLocation();
  1460. S->ColonLoc = readSourceLocation();
  1461. S->RParenLoc = readSourceLocation();
  1462. S->setInit(Record.readSubStmt());
  1463. S->setRangeStmt(Record.readSubStmt());
  1464. S->setBeginStmt(Record.readSubStmt());
  1465. S->setEndStmt(Record.readSubStmt());
  1466. S->setCond(Record.readSubExpr());
  1467. S->setInc(Record.readSubExpr());
  1468. S->setLoopVarStmt(Record.readSubStmt());
  1469. S->setBody(Record.readSubStmt());
  1470. }
  1471. void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
  1472. VisitStmt(S);
  1473. S->KeywordLoc = readSourceLocation();
  1474. S->IsIfExists = Record.readInt();
  1475. S->QualifierLoc = Record.readNestedNameSpecifierLoc();
  1476. S->NameInfo = Record.readDeclarationNameInfo();
  1477. S->SubStmt = Record.readSubStmt();
  1478. }
  1479. void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
  1480. VisitCallExpr(E);
  1481. E->CXXOperatorCallExprBits.OperatorKind = Record.readInt();
  1482. E->Range = Record.readSourceRange();
  1483. }
  1484. void ASTStmtReader::VisitCXXRewrittenBinaryOperator(
  1485. CXXRewrittenBinaryOperator *E) {
  1486. VisitExpr(E);
  1487. E->CXXRewrittenBinaryOperatorBits.IsReversed = Record.readInt();
  1488. E->SemanticForm = Record.readSubExpr();
  1489. }
  1490. void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
  1491. VisitExpr(E);
  1492. unsigned NumArgs = Record.readInt();
  1493. assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
  1494. E->CXXConstructExprBits.Elidable = Record.readInt();
  1495. E->CXXConstructExprBits.HadMultipleCandidates = Record.readInt();
  1496. E->CXXConstructExprBits.ListInitialization = Record.readInt();
  1497. E->CXXConstructExprBits.StdInitListInitialization = Record.readInt();
  1498. E->CXXConstructExprBits.ZeroInitialization = Record.readInt();
  1499. E->CXXConstructExprBits.ConstructionKind = Record.readInt();
  1500. E->CXXConstructExprBits.Loc = readSourceLocation();
  1501. E->Constructor = readDeclAs<CXXConstructorDecl>();
  1502. E->ParenOrBraceRange = readSourceRange();
  1503. for (unsigned I = 0; I != NumArgs; ++I)
  1504. E->setArg(I, Record.readSubExpr());
  1505. }
  1506. void ASTStmtReader::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
  1507. VisitExpr(E);
  1508. E->Constructor = readDeclAs<CXXConstructorDecl>();
  1509. E->Loc = readSourceLocation();
  1510. E->ConstructsVirtualBase = Record.readInt();
  1511. E->InheritedFromVirtualBase = Record.readInt();
  1512. }
  1513. void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
  1514. VisitCXXConstructExpr(E);
  1515. E->TSI = readTypeSourceInfo();
  1516. }
  1517. void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) {
  1518. VisitExpr(E);
  1519. unsigned NumCaptures = Record.readInt();
  1520. (void)NumCaptures;
  1521. assert(NumCaptures == E->LambdaExprBits.NumCaptures);
  1522. E->IntroducerRange = readSourceRange();
  1523. E->LambdaExprBits.CaptureDefault = Record.readInt();
  1524. E->CaptureDefaultLoc = readSourceLocation();
  1525. E->LambdaExprBits.ExplicitParams = Record.readInt();
  1526. E->LambdaExprBits.ExplicitResultType = Record.readInt();
  1527. E->ClosingBrace = readSourceLocation();
  1528. // Read capture initializers.
  1529. for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
  1530. CEnd = E->capture_init_end();
  1531. C != CEnd; ++C)
  1532. *C = Record.readSubExpr();
  1533. // The body will be lazily deserialized when needed from the call operator
  1534. // declaration.
  1535. }
  1536. void
  1537. ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
  1538. VisitExpr(E);
  1539. E->SubExpr = Record.readSubExpr();
  1540. }
  1541. void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
  1542. VisitExplicitCastExpr(E);
  1543. SourceRange R = readSourceRange();
  1544. E->Loc = R.getBegin();
  1545. E->RParenLoc = R.getEnd();
  1546. R = readSourceRange();
  1547. E->AngleBrackets = R;
  1548. }
  1549. void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
  1550. return VisitCXXNamedCastExpr(E);
  1551. }
  1552. void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
  1553. return VisitCXXNamedCastExpr(E);
  1554. }
  1555. void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
  1556. return VisitCXXNamedCastExpr(E);
  1557. }
  1558. void ASTStmtReader::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
  1559. return VisitCXXNamedCastExpr(E);
  1560. }
  1561. void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
  1562. return VisitCXXNamedCastExpr(E);
  1563. }
  1564. void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
  1565. VisitExplicitCastExpr(E);
  1566. E->setLParenLoc(readSourceLocation());
  1567. E->setRParenLoc(readSourceLocation());
  1568. }
  1569. void ASTStmtReader::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
  1570. VisitExplicitCastExpr(E);
  1571. E->KWLoc = readSourceLocation();
  1572. E->RParenLoc = readSourceLocation();
  1573. }
  1574. void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
  1575. VisitCallExpr(E);
  1576. E->UDSuffixLoc = readSourceLocation();
  1577. }
  1578. void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
  1579. VisitExpr(E);
  1580. E->setValue(Record.readInt());
  1581. E->setLocation(readSourceLocation());
  1582. }
  1583. void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
  1584. VisitExpr(E);
  1585. E->setLocation(readSourceLocation());
  1586. }
  1587. void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
  1588. VisitExpr(E);
  1589. E->setSourceRange(readSourceRange());
  1590. if (E->isTypeOperand())
  1591. E->Operand = readTypeSourceInfo();
  1592. else
  1593. E->Operand = Record.readSubExpr();
  1594. }
  1595. void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
  1596. VisitExpr(E);
  1597. E->setLocation(readSourceLocation());
  1598. E->setImplicit(Record.readInt());
  1599. }
  1600. void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
  1601. VisitExpr(E);
  1602. E->CXXThrowExprBits.ThrowLoc = readSourceLocation();
  1603. E->Operand = Record.readSubExpr();
  1604. E->CXXThrowExprBits.IsThrownVariableInScope = Record.readInt();
  1605. }
  1606. void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
  1607. VisitExpr(E);
  1608. E->Param = readDeclAs<ParmVarDecl>();
  1609. E->UsedContext = readDeclAs<DeclContext>();
  1610. E->CXXDefaultArgExprBits.Loc = readSourceLocation();
  1611. }
  1612. void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
  1613. VisitExpr(E);
  1614. E->Field = readDeclAs<FieldDecl>();
  1615. E->UsedContext = readDeclAs<DeclContext>();
  1616. E->CXXDefaultInitExprBits.Loc = readSourceLocation();
  1617. }
  1618. void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
  1619. VisitExpr(E);
  1620. E->setTemporary(Record.readCXXTemporary());
  1621. E->setSubExpr(Record.readSubExpr());
  1622. }
  1623. void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
  1624. VisitExpr(E);
  1625. E->TypeInfo = readTypeSourceInfo();
  1626. E->CXXScalarValueInitExprBits.RParenLoc = readSourceLocation();
  1627. }
  1628. void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
  1629. VisitExpr(E);
  1630. bool IsArray = Record.readInt();
  1631. bool HasInit = Record.readInt();
  1632. unsigned NumPlacementArgs = Record.readInt();
  1633. bool IsParenTypeId = Record.readInt();
  1634. E->CXXNewExprBits.IsGlobalNew = Record.readInt();
  1635. E->CXXNewExprBits.ShouldPassAlignment = Record.readInt();
  1636. E->CXXNewExprBits.UsualArrayDeleteWantsSize = Record.readInt();
  1637. E->CXXNewExprBits.StoredInitializationStyle = Record.readInt();
  1638. assert((IsArray == E->isArray()) && "Wrong IsArray!");
  1639. assert((HasInit == E->hasInitializer()) && "Wrong HasInit!");
  1640. assert((NumPlacementArgs == E->getNumPlacementArgs()) &&
  1641. "Wrong NumPlacementArgs!");
  1642. assert((IsParenTypeId == E->isParenTypeId()) && "Wrong IsParenTypeId!");
  1643. (void)IsArray;
  1644. (void)HasInit;
  1645. (void)NumPlacementArgs;
  1646. E->setOperatorNew(readDeclAs<FunctionDecl>());
  1647. E->setOperatorDelete(readDeclAs<FunctionDecl>());
  1648. E->AllocatedTypeInfo = readTypeSourceInfo();
  1649. if (IsParenTypeId)
  1650. E->getTrailingObjects<SourceRange>()[0] = readSourceRange();
  1651. E->Range = readSourceRange();
  1652. E->DirectInitRange = readSourceRange();
  1653. // Install all the subexpressions.
  1654. for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),
  1655. N = E->raw_arg_end();
  1656. I != N; ++I)
  1657. *I = Record.readSubStmt();
  1658. }
  1659. void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
  1660. VisitExpr(E);
  1661. E->CXXDeleteExprBits.GlobalDelete = Record.readInt();
  1662. E->CXXDeleteExprBits.ArrayForm = Record.readInt();
  1663. E->CXXDeleteExprBits.ArrayFormAsWritten = Record.readInt();
  1664. E->CXXDeleteExprBits.UsualArrayDeleteWantsSize = Record.readInt();
  1665. E->OperatorDelete = readDeclAs<FunctionDecl>();
  1666. E->Argument = Record.readSubExpr();
  1667. E->CXXDeleteExprBits.Loc = readSourceLocation();
  1668. }
  1669. void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
  1670. VisitExpr(E);
  1671. E->Base = Record.readSubExpr();
  1672. E->IsArrow = Record.readInt();
  1673. E->OperatorLoc = readSourceLocation();
  1674. E->QualifierLoc = Record.readNestedNameSpecifierLoc();
  1675. E->ScopeType = readTypeSourceInfo();
  1676. E->ColonColonLoc = readSourceLocation();
  1677. E->TildeLoc = readSourceLocation();
  1678. IdentifierInfo *II = Record.readIdentifier();
  1679. if (II)
  1680. E->setDestroyedType(II, readSourceLocation());
  1681. else
  1682. E->setDestroyedType(readTypeSourceInfo());
  1683. }
  1684. void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
  1685. VisitExpr(E);
  1686. unsigned NumObjects = Record.readInt();
  1687. assert(NumObjects == E->getNumObjects());
  1688. for (unsigned i = 0; i != NumObjects; ++i) {
  1689. unsigned CleanupKind = Record.readInt();
  1690. ExprWithCleanups::CleanupObject Obj;
  1691. if (CleanupKind == COK_Block)
  1692. Obj = readDeclAs<BlockDecl>();
  1693. else if (CleanupKind == COK_CompoundLiteral)
  1694. Obj = cast<CompoundLiteralExpr>(Record.readSubExpr());
  1695. else
  1696. llvm_unreachable("unexpected cleanup object type");
  1697. E->getTrailingObjects<ExprWithCleanups::CleanupObject>()[i] = Obj;
  1698. }
  1699. E->ExprWithCleanupsBits.CleanupsHaveSideEffects = Record.readInt();
  1700. E->SubExpr = Record.readSubExpr();
  1701. }
  1702. void ASTStmtReader::VisitCXXDependentScopeMemberExpr(
  1703. CXXDependentScopeMemberExpr *E) {
  1704. VisitExpr(E);
  1705. bool HasTemplateKWAndArgsInfo = Record.readInt();
  1706. unsigned NumTemplateArgs = Record.readInt();
  1707. bool HasFirstQualifierFoundInScope = Record.readInt();
  1708. assert((HasTemplateKWAndArgsInfo == E->hasTemplateKWAndArgsInfo()) &&
  1709. "Wrong HasTemplateKWAndArgsInfo!");
  1710. assert(
  1711. (HasFirstQualifierFoundInScope == E->hasFirstQualifierFoundInScope()) &&
  1712. "Wrong HasFirstQualifierFoundInScope!");
  1713. if (HasTemplateKWAndArgsInfo)
  1714. ReadTemplateKWAndArgsInfo(
  1715. *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
  1716. E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
  1717. assert((NumTemplateArgs == E->getNumTemplateArgs()) &&
  1718. "Wrong NumTemplateArgs!");
  1719. E->CXXDependentScopeMemberExprBits.IsArrow = Record.readInt();
  1720. E->CXXDependentScopeMemberExprBits.OperatorLoc = readSourceLocation();
  1721. E->BaseType = Record.readType();
  1722. E->QualifierLoc = Record.readNestedNameSpecifierLoc();
  1723. E->Base = Record.readSubExpr();
  1724. if (HasFirstQualifierFoundInScope)
  1725. *E->getTrailingObjects<NamedDecl *>() = readDeclAs<NamedDecl>();
  1726. E->MemberNameInfo = Record.readDeclarationNameInfo();
  1727. }
  1728. void
  1729. ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
  1730. VisitExpr(E);
  1731. if (Record.readInt()) // HasTemplateKWAndArgsInfo
  1732. ReadTemplateKWAndArgsInfo(
  1733. *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
  1734. E->getTrailingObjects<TemplateArgumentLoc>(),
  1735. /*NumTemplateArgs=*/Record.readInt());
  1736. E->QualifierLoc = Record.readNestedNameSpecifierLoc();
  1737. E->NameInfo = Record.readDeclarationNameInfo();
  1738. }
  1739. void
  1740. ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
  1741. VisitExpr(E);
  1742. assert(Record.peekInt() == E->getNumArgs() &&
  1743. "Read wrong record during creation ?");
  1744. Record.skipInts(1);
  1745. for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
  1746. E->setArg(I, Record.readSubExpr());
  1747. E->TSI = readTypeSourceInfo();
  1748. E->setLParenLoc(readSourceLocation());
  1749. E->setRParenLoc(readSourceLocation());
  1750. }
  1751. void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
  1752. VisitExpr(E);
  1753. unsigned NumResults = Record.readInt();
  1754. bool HasTemplateKWAndArgsInfo = Record.readInt();
  1755. assert((E->getNumDecls() == NumResults) && "Wrong NumResults!");
  1756. assert((E->hasTemplateKWAndArgsInfo() == HasTemplateKWAndArgsInfo) &&
  1757. "Wrong HasTemplateKWAndArgsInfo!");
  1758. if (HasTemplateKWAndArgsInfo) {
  1759. unsigned NumTemplateArgs = Record.readInt();
  1760. ReadTemplateKWAndArgsInfo(*E->getTrailingASTTemplateKWAndArgsInfo(),
  1761. E->getTrailingTemplateArgumentLoc(),
  1762. NumTemplateArgs);
  1763. assert((E->getNumTemplateArgs() == NumTemplateArgs) &&
  1764. "Wrong NumTemplateArgs!");
  1765. }
  1766. UnresolvedSet<8> Decls;
  1767. for (unsigned I = 0; I != NumResults; ++I) {
  1768. auto *D = readDeclAs<NamedDecl>();
  1769. auto AS = (AccessSpecifier)Record.readInt();
  1770. Decls.addDecl(D, AS);
  1771. }
  1772. DeclAccessPair *Results = E->getTrailingResults();
  1773. UnresolvedSetIterator Iter = Decls.begin();
  1774. for (unsigned I = 0; I != NumResults; ++I) {
  1775. Results[I] = (Iter + I).getPair();
  1776. }
  1777. E->NameInfo = Record.readDeclarationNameInfo();
  1778. E->QualifierLoc = Record.readNestedNameSpecifierLoc();
  1779. }
  1780. void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
  1781. VisitOverloadExpr(E);
  1782. E->UnresolvedMemberExprBits.IsArrow = Record.readInt();
  1783. E->UnresolvedMemberExprBits.HasUnresolvedUsing = Record.readInt();
  1784. E->Base = Record.readSubExpr();
  1785. E->BaseType = Record.readType();
  1786. E->OperatorLoc = readSourceLocation();
  1787. }
  1788. void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
  1789. VisitOverloadExpr(E);
  1790. E->UnresolvedLookupExprBits.RequiresADL = Record.readInt();
  1791. E->UnresolvedLookupExprBits.Overloaded = Record.readInt();
  1792. E->NamingClass = readDeclAs<CXXRecordDecl>();
  1793. }
  1794. void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) {
  1795. VisitExpr(E);
  1796. E->TypeTraitExprBits.NumArgs = Record.readInt();
  1797. E->TypeTraitExprBits.Kind = Record.readInt();
  1798. E->TypeTraitExprBits.Value = Record.readInt();
  1799. SourceRange Range = readSourceRange();
  1800. E->Loc = Range.getBegin();
  1801. E->RParenLoc = Range.getEnd();
  1802. auto **Args = E->getTrailingObjects<TypeSourceInfo *>();
  1803. for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
  1804. Args[I] = readTypeSourceInfo();
  1805. }
  1806. void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
  1807. VisitExpr(E);
  1808. E->ATT = (ArrayTypeTrait)Record.readInt();
  1809. E->Value = (unsigned int)Record.readInt();
  1810. SourceRange Range = readSourceRange();
  1811. E->Loc = Range.getBegin();
  1812. E->RParen = Range.getEnd();
  1813. E->QueriedType = readTypeSourceInfo();
  1814. E->Dimension = Record.readSubExpr();
  1815. }
  1816. void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
  1817. VisitExpr(E);
  1818. E->ET = (ExpressionTrait)Record.readInt();
  1819. E->Value = (bool)Record.readInt();
  1820. SourceRange Range = readSourceRange();
  1821. E->QueriedExpression = Record.readSubExpr();
  1822. E->Loc = Range.getBegin();
  1823. E->RParen = Range.getEnd();
  1824. }
  1825. void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
  1826. VisitExpr(E);
  1827. E->CXXNoexceptExprBits.Value = Record.readInt();
  1828. E->Range = readSourceRange();
  1829. E->Operand = Record.readSubExpr();
  1830. }
  1831. void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
  1832. VisitExpr(E);
  1833. E->EllipsisLoc = readSourceLocation();
  1834. E->NumExpansions = Record.readInt();
  1835. E->Pattern = Record.readSubExpr();
  1836. }
  1837. void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
  1838. VisitExpr(E);
  1839. unsigned NumPartialArgs = Record.readInt();
  1840. E->OperatorLoc = readSourceLocation();
  1841. E->PackLoc = readSourceLocation();
  1842. E->RParenLoc = readSourceLocation();
  1843. E->Pack = Record.readDeclAs<NamedDecl>();
  1844. if (E->isPartiallySubstituted()) {
  1845. assert(E->Length == NumPartialArgs);
  1846. for (auto *I = E->getTrailingObjects<TemplateArgument>(),
  1847. *E = I + NumPartialArgs;
  1848. I != E; ++I)
  1849. new (I) TemplateArgument(Record.readTemplateArgument());
  1850. } else if (!E->isValueDependent()) {
  1851. E->Length = Record.readInt();
  1852. }
  1853. }
  1854. void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
  1855. SubstNonTypeTemplateParmExpr *E) {
  1856. VisitExpr(E);
  1857. E->ParamAndRef.setPointer(readDeclAs<NonTypeTemplateParmDecl>());
  1858. E->ParamAndRef.setInt(Record.readInt());
  1859. E->SubstNonTypeTemplateParmExprBits.NameLoc = readSourceLocation();
  1860. E->Replacement = Record.readSubExpr();
  1861. }
  1862. void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
  1863. SubstNonTypeTemplateParmPackExpr *E) {
  1864. VisitExpr(E);
  1865. E->Param = readDeclAs<NonTypeTemplateParmDecl>();
  1866. TemplateArgument ArgPack = Record.readTemplateArgument();
  1867. if (ArgPack.getKind() != TemplateArgument::Pack)
  1868. return;
  1869. E->Arguments = ArgPack.pack_begin();
  1870. E->NumArguments = ArgPack.pack_size();
  1871. E->NameLoc = readSourceLocation();
  1872. }
  1873. void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
  1874. VisitExpr(E);
  1875. E->NumParameters = Record.readInt();
  1876. E->ParamPack = readDeclAs<ParmVarDecl>();
  1877. E->NameLoc = readSourceLocation();
  1878. auto **Parms = E->getTrailingObjects<VarDecl *>();
  1879. for (unsigned i = 0, n = E->NumParameters; i != n; ++i)
  1880. Parms[i] = readDeclAs<VarDecl>();
  1881. }
  1882. void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
  1883. VisitExpr(E);
  1884. bool HasMaterialzedDecl = Record.readInt();
  1885. if (HasMaterialzedDecl)
  1886. E->State = cast<LifetimeExtendedTemporaryDecl>(Record.readDecl());
  1887. else
  1888. E->State = Record.readSubExpr();
  1889. }
  1890. void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) {
  1891. VisitExpr(E);
  1892. E->LParenLoc = readSourceLocation();
  1893. E->EllipsisLoc = readSourceLocation();
  1894. E->RParenLoc = readSourceLocation();
  1895. E->NumExpansions = Record.readInt();
  1896. E->SubExprs[0] = Record.readSubExpr();
  1897. E->SubExprs[1] = Record.readSubExpr();
  1898. E->SubExprs[2] = Record.readSubExpr();
  1899. E->Opcode = (BinaryOperatorKind)Record.readInt();
  1900. }
  1901. void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
  1902. VisitExpr(E);
  1903. E->SourceExpr = Record.readSubExpr();
  1904. E->OpaqueValueExprBits.Loc = readSourceLocation();
  1905. E->setIsUnique(Record.readInt());
  1906. }
  1907. void ASTStmtReader::VisitTypoExpr(TypoExpr *E) {
  1908. llvm_unreachable("Cannot read TypoExpr nodes");
  1909. }
  1910. void ASTStmtReader::VisitRecoveryExpr(RecoveryExpr *E) {
  1911. VisitExpr(E);
  1912. unsigned NumArgs = Record.readInt();
  1913. E->BeginLoc = readSourceLocation();
  1914. E->EndLoc = readSourceLocation();
  1915. assert((NumArgs + 0LL ==
  1916. std::distance(E->children().begin(), E->children().end())) &&
  1917. "Wrong NumArgs!");
  1918. (void)NumArgs;
  1919. for (Stmt *&Child : E->children())
  1920. Child = Record.readSubStmt();
  1921. }
  1922. //===----------------------------------------------------------------------===//
  1923. // Microsoft Expressions and Statements
  1924. //===----------------------------------------------------------------------===//
  1925. void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
  1926. VisitExpr(E);
  1927. E->IsArrow = (Record.readInt() != 0);
  1928. E->BaseExpr = Record.readSubExpr();
  1929. E->QualifierLoc = Record.readNestedNameSpecifierLoc();
  1930. E->MemberLoc = readSourceLocation();
  1931. E->TheDecl = readDeclAs<MSPropertyDecl>();
  1932. }
  1933. void ASTStmtReader::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
  1934. VisitExpr(E);
  1935. E->setBase(Record.readSubExpr());
  1936. E->setIdx(Record.readSubExpr());
  1937. E->setRBracketLoc(readSourceLocation());
  1938. }
  1939. void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
  1940. VisitExpr(E);
  1941. E->setSourceRange(readSourceRange());
  1942. E->Guid = readDeclAs<MSGuidDecl>();
  1943. if (E->isTypeOperand())
  1944. E->Operand = readTypeSourceInfo();
  1945. else
  1946. E->Operand = Record.readSubExpr();
  1947. }
  1948. void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
  1949. VisitStmt(S);
  1950. S->setLeaveLoc(readSourceLocation());
  1951. }
  1952. void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
  1953. VisitStmt(S);
  1954. S->Loc = readSourceLocation();
  1955. S->Children[SEHExceptStmt::FILTER_EXPR] = Record.readSubStmt();
  1956. S->Children[SEHExceptStmt::BLOCK] = Record.readSubStmt();
  1957. }
  1958. void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
  1959. VisitStmt(S);
  1960. S->Loc = readSourceLocation();
  1961. S->Block = Record.readSubStmt();
  1962. }
  1963. void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
  1964. VisitStmt(S);
  1965. S->IsCXXTry = Record.readInt();
  1966. S->TryLoc = readSourceLocation();
  1967. S->Children[SEHTryStmt::TRY] = Record.readSubStmt();
  1968. S->Children[SEHTryStmt::HANDLER] = Record.readSubStmt();
  1969. }
  1970. //===----------------------------------------------------------------------===//
  1971. // CUDA Expressions and Statements
  1972. //===----------------------------------------------------------------------===//
  1973. void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
  1974. VisitCallExpr(E);
  1975. E->setPreArg(CUDAKernelCallExpr::CONFIG, Record.readSubExpr());
  1976. }
  1977. //===----------------------------------------------------------------------===//
  1978. // OpenCL Expressions and Statements.
  1979. //===----------------------------------------------------------------------===//
  1980. void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
  1981. VisitExpr(E);
  1982. E->BuiltinLoc = readSourceLocation();
  1983. E->RParenLoc = readSourceLocation();
  1984. E->SrcExpr = Record.readSubExpr();
  1985. }
  1986. //===----------------------------------------------------------------------===//
  1987. // OpenMP Directives.
  1988. //===----------------------------------------------------------------------===//
  1989. void ASTStmtReader::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
  1990. VisitStmt(S);
  1991. for (Stmt *&SubStmt : S->SubStmts)
  1992. SubStmt = Record.readSubStmt();
  1993. }
  1994. void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
  1995. Record.readOMPChildren(E->Data);
  1996. E->setLocStart(readSourceLocation());
  1997. E->setLocEnd(readSourceLocation());
  1998. }
  1999. void ASTStmtReader::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
  2000. VisitStmt(D);
  2001. // Field CollapsedNum was read in ReadStmtFromStream.
  2002. Record.skipInts(1);
  2003. VisitOMPExecutableDirective(D);
  2004. }
  2005. void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) {
  2006. VisitOMPLoopBasedDirective(D);
  2007. }
  2008. void ASTStmtReader::VisitOMPMetaDirective(OMPMetaDirective *D) {
  2009. VisitStmt(D);
  2010. // The NumClauses field was read in ReadStmtFromStream.
  2011. Record.skipInts(1);
  2012. VisitOMPExecutableDirective(D);
  2013. }
  2014. void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) {
  2015. VisitStmt(D);
  2016. VisitOMPExecutableDirective(D);
  2017. D->setHasCancel(Record.readBool());
  2018. }
  2019. void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
  2020. VisitOMPLoopDirective(D);
  2021. }
  2022. void ASTStmtReader::VisitOMPLoopTransformationDirective(
  2023. OMPLoopTransformationDirective *D) {
  2024. VisitOMPLoopBasedDirective(D);
  2025. D->setNumGeneratedLoops(Record.readUInt32());
  2026. }
  2027. void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
  2028. VisitOMPLoopTransformationDirective(D);
  2029. }
  2030. void ASTStmtReader::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
  2031. VisitOMPLoopTransformationDirective(D);
  2032. }
  2033. void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
  2034. VisitOMPLoopDirective(D);
  2035. D->setHasCancel(Record.readBool());
  2036. }
  2037. void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
  2038. VisitOMPLoopDirective(D);
  2039. }
  2040. void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
  2041. VisitStmt(D);
  2042. VisitOMPExecutableDirective(D);
  2043. D->setHasCancel(Record.readBool());
  2044. }
  2045. void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
  2046. VisitStmt(D);
  2047. VisitOMPExecutableDirective(D);
  2048. D->setHasCancel(Record.readBool());
  2049. }
  2050. void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
  2051. VisitStmt(D);
  2052. VisitOMPExecutableDirective(D);
  2053. }
  2054. void ASTStmtReader::VisitOMPMasterDirective(OMPMasterDirective *D) {
  2055. VisitStmt(D);
  2056. VisitOMPExecutableDirective(D);
  2057. }
  2058. void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
  2059. VisitStmt(D);
  2060. VisitOMPExecutableDirective(D);
  2061. D->DirName = Record.readDeclarationNameInfo();
  2062. }
  2063. void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
  2064. VisitOMPLoopDirective(D);
  2065. D->setHasCancel(Record.readBool());
  2066. }
  2067. void ASTStmtReader::VisitOMPParallelForSimdDirective(
  2068. OMPParallelForSimdDirective *D) {
  2069. VisitOMPLoopDirective(D);
  2070. }
  2071. void ASTStmtReader::VisitOMPParallelMasterDirective(
  2072. OMPParallelMasterDirective *D) {
  2073. VisitStmt(D);
  2074. VisitOMPExecutableDirective(D);
  2075. }
  2076. void ASTStmtReader::VisitOMPParallelSectionsDirective(
  2077. OMPParallelSectionsDirective *D) {
  2078. VisitStmt(D);
  2079. VisitOMPExecutableDirective(D);
  2080. D->setHasCancel(Record.readBool());
  2081. }
  2082. void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) {
  2083. VisitStmt(D);
  2084. VisitOMPExecutableDirective(D);
  2085. D->setHasCancel(Record.readBool());
  2086. }
  2087. void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
  2088. VisitStmt(D);
  2089. VisitOMPExecutableDirective(D);
  2090. }
  2091. void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
  2092. VisitStmt(D);
  2093. VisitOMPExecutableDirective(D);
  2094. }
  2095. void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
  2096. VisitStmt(D);
  2097. // The NumClauses field was read in ReadStmtFromStream.
  2098. Record.skipInts(1);
  2099. VisitOMPExecutableDirective(D);
  2100. }
  2101. void ASTStmtReader::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
  2102. VisitStmt(D);
  2103. VisitOMPExecutableDirective(D);
  2104. }
  2105. void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) {
  2106. VisitStmt(D);
  2107. VisitOMPExecutableDirective(D);
  2108. }
  2109. void ASTStmtReader::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
  2110. VisitStmt(D);
  2111. VisitOMPExecutableDirective(D);
  2112. }
  2113. void ASTStmtReader::VisitOMPScanDirective(OMPScanDirective *D) {
  2114. VisitStmt(D);
  2115. VisitOMPExecutableDirective(D);
  2116. }
  2117. void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
  2118. VisitStmt(D);
  2119. VisitOMPExecutableDirective(D);
  2120. }
  2121. void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
  2122. VisitStmt(D);
  2123. VisitOMPExecutableDirective(D);
  2124. D->IsXLHSInRHSPart = Record.readBool();
  2125. D->IsPostfixUpdate = Record.readBool();
  2126. }
  2127. void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
  2128. VisitStmt(D);
  2129. VisitOMPExecutableDirective(D);
  2130. }
  2131. void ASTStmtReader::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
  2132. VisitStmt(D);
  2133. VisitOMPExecutableDirective(D);
  2134. }
  2135. void ASTStmtReader::VisitOMPTargetEnterDataDirective(
  2136. OMPTargetEnterDataDirective *D) {
  2137. VisitStmt(D);
  2138. VisitOMPExecutableDirective(D);
  2139. }
  2140. void ASTStmtReader::VisitOMPTargetExitDataDirective(
  2141. OMPTargetExitDataDirective *D) {
  2142. VisitStmt(D);
  2143. VisitOMPExecutableDirective(D);
  2144. }
  2145. void ASTStmtReader::VisitOMPTargetParallelDirective(
  2146. OMPTargetParallelDirective *D) {
  2147. VisitStmt(D);
  2148. VisitOMPExecutableDirective(D);
  2149. D->setHasCancel(Record.readBool());
  2150. }
  2151. void ASTStmtReader::VisitOMPTargetParallelForDirective(
  2152. OMPTargetParallelForDirective *D) {
  2153. VisitOMPLoopDirective(D);
  2154. D->setHasCancel(Record.readBool());
  2155. }
  2156. void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
  2157. VisitStmt(D);
  2158. VisitOMPExecutableDirective(D);
  2159. }
  2160. void ASTStmtReader::VisitOMPCancellationPointDirective(
  2161. OMPCancellationPointDirective *D) {
  2162. VisitStmt(D);
  2163. VisitOMPExecutableDirective(D);
  2164. D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
  2165. }
  2166. void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) {
  2167. VisitStmt(D);
  2168. VisitOMPExecutableDirective(D);
  2169. D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
  2170. }
  2171. void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
  2172. VisitOMPLoopDirective(D);
  2173. D->setHasCancel(Record.readBool());
  2174. }
  2175. void ASTStmtReader::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
  2176. VisitOMPLoopDirective(D);
  2177. }
  2178. void ASTStmtReader::VisitOMPMasterTaskLoopDirective(
  2179. OMPMasterTaskLoopDirective *D) {
  2180. VisitOMPLoopDirective(D);
  2181. D->setHasCancel(Record.readBool());
  2182. }
  2183. void ASTStmtReader::VisitOMPMasterTaskLoopSimdDirective(
  2184. OMPMasterTaskLoopSimdDirective *D) {
  2185. VisitOMPLoopDirective(D);
  2186. }
  2187. void ASTStmtReader::VisitOMPParallelMasterTaskLoopDirective(
  2188. OMPParallelMasterTaskLoopDirective *D) {
  2189. VisitOMPLoopDirective(D);
  2190. D->setHasCancel(Record.readBool());
  2191. }
  2192. void ASTStmtReader::VisitOMPParallelMasterTaskLoopSimdDirective(
  2193. OMPParallelMasterTaskLoopSimdDirective *D) {
  2194. VisitOMPLoopDirective(D);
  2195. }
  2196. void ASTStmtReader::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
  2197. VisitOMPLoopDirective(D);
  2198. }
  2199. void ASTStmtReader::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
  2200. VisitStmt(D);
  2201. VisitOMPExecutableDirective(D);
  2202. }
  2203. void ASTStmtReader::VisitOMPDistributeParallelForDirective(
  2204. OMPDistributeParallelForDirective *D) {
  2205. VisitOMPLoopDirective(D);
  2206. D->setHasCancel(Record.readBool());
  2207. }
  2208. void ASTStmtReader::VisitOMPDistributeParallelForSimdDirective(
  2209. OMPDistributeParallelForSimdDirective *D) {
  2210. VisitOMPLoopDirective(D);
  2211. }
  2212. void ASTStmtReader::VisitOMPDistributeSimdDirective(
  2213. OMPDistributeSimdDirective *D) {
  2214. VisitOMPLoopDirective(D);
  2215. }
  2216. void ASTStmtReader::VisitOMPTargetParallelForSimdDirective(
  2217. OMPTargetParallelForSimdDirective *D) {
  2218. VisitOMPLoopDirective(D);
  2219. }
  2220. void ASTStmtReader::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
  2221. VisitOMPLoopDirective(D);
  2222. }
  2223. void ASTStmtReader::VisitOMPTeamsDistributeDirective(
  2224. OMPTeamsDistributeDirective *D) {
  2225. VisitOMPLoopDirective(D);
  2226. }
  2227. void ASTStmtReader::VisitOMPTeamsDistributeSimdDirective(
  2228. OMPTeamsDistributeSimdDirective *D) {
  2229. VisitOMPLoopDirective(D);
  2230. }
  2231. void ASTStmtReader::VisitOMPTeamsDistributeParallelForSimdDirective(
  2232. OMPTeamsDistributeParallelForSimdDirective *D) {
  2233. VisitOMPLoopDirective(D);
  2234. }
  2235. void ASTStmtReader::VisitOMPTeamsDistributeParallelForDirective(
  2236. OMPTeamsDistributeParallelForDirective *D) {
  2237. VisitOMPLoopDirective(D);
  2238. D->setHasCancel(Record.readBool());
  2239. }
  2240. void ASTStmtReader::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
  2241. VisitStmt(D);
  2242. VisitOMPExecutableDirective(D);
  2243. }
  2244. void ASTStmtReader::VisitOMPTargetTeamsDistributeDirective(
  2245. OMPTargetTeamsDistributeDirective *D) {
  2246. VisitOMPLoopDirective(D);
  2247. }
  2248. void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForDirective(
  2249. OMPTargetTeamsDistributeParallelForDirective *D) {
  2250. VisitOMPLoopDirective(D);
  2251. D->setHasCancel(Record.readBool());
  2252. }
  2253. void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
  2254. OMPTargetTeamsDistributeParallelForSimdDirective *D) {
  2255. VisitOMPLoopDirective(D);
  2256. }
  2257. void ASTStmtReader::VisitOMPTargetTeamsDistributeSimdDirective(
  2258. OMPTargetTeamsDistributeSimdDirective *D) {
  2259. VisitOMPLoopDirective(D);
  2260. }
  2261. void ASTStmtReader::VisitOMPInteropDirective(OMPInteropDirective *D) {
  2262. VisitStmt(D);
  2263. VisitOMPExecutableDirective(D);
  2264. }
  2265. void ASTStmtReader::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
  2266. VisitStmt(D);
  2267. VisitOMPExecutableDirective(D);
  2268. D->setTargetCallLoc(Record.readSourceLocation());
  2269. }
  2270. void ASTStmtReader::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
  2271. VisitStmt(D);
  2272. VisitOMPExecutableDirective(D);
  2273. }
  2274. void ASTStmtReader::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
  2275. VisitOMPLoopDirective(D);
  2276. }
  2277. //===----------------------------------------------------------------------===//
  2278. // ASTReader Implementation
  2279. //===----------------------------------------------------------------------===//
  2280. Stmt *ASTReader::ReadStmt(ModuleFile &F) {
  2281. switch (ReadingKind) {
  2282. case Read_None:
  2283. llvm_unreachable("should not call this when not reading anything");
  2284. case Read_Decl:
  2285. case Read_Type:
  2286. return ReadStmtFromStream(F);
  2287. case Read_Stmt:
  2288. return ReadSubStmt();
  2289. }
  2290. llvm_unreachable("ReadingKind not set ?");
  2291. }
  2292. Expr *ASTReader::ReadExpr(ModuleFile &F) {
  2293. return cast_or_null<Expr>(ReadStmt(F));
  2294. }
  2295. Expr *ASTReader::ReadSubExpr() {
  2296. return cast_or_null<Expr>(ReadSubStmt());
  2297. }
  2298. // Within the bitstream, expressions are stored in Reverse Polish
  2299. // Notation, with each of the subexpressions preceding the
  2300. // expression they are stored in. Subexpressions are stored from last to first.
  2301. // To evaluate expressions, we continue reading expressions and placing them on
  2302. // the stack, with expressions having operands removing those operands from the
  2303. // stack. Evaluation terminates when we see a STMT_STOP record, and
  2304. // the single remaining expression on the stack is our result.
  2305. Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
  2306. ReadingKindTracker ReadingKind(Read_Stmt, *this);
  2307. llvm::BitstreamCursor &Cursor = F.DeclsCursor;
  2308. // Map of offset to previously deserialized stmt. The offset points
  2309. // just after the stmt record.
  2310. llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
  2311. #ifndef NDEBUG
  2312. unsigned PrevNumStmts = StmtStack.size();
  2313. #endif
  2314. ASTRecordReader Record(*this, F);
  2315. ASTStmtReader Reader(Record, Cursor);
  2316. Stmt::EmptyShell Empty;
  2317. while (true) {
  2318. llvm::Expected<llvm::BitstreamEntry> MaybeEntry =
  2319. Cursor.advanceSkippingSubblocks();
  2320. if (!MaybeEntry) {
  2321. Error(toString(MaybeEntry.takeError()));
  2322. return nullptr;
  2323. }
  2324. llvm::BitstreamEntry Entry = MaybeEntry.get();
  2325. switch (Entry.Kind) {
  2326. case llvm::BitstreamEntry::SubBlock: // Handled for us already.
  2327. case llvm::BitstreamEntry::Error:
  2328. Error("malformed block record in AST file");
  2329. return nullptr;
  2330. case llvm::BitstreamEntry::EndBlock:
  2331. goto Done;
  2332. case llvm::BitstreamEntry::Record:
  2333. // The interesting case.
  2334. break;
  2335. }
  2336. ASTContext &Context = getContext();
  2337. Stmt *S = nullptr;
  2338. bool Finished = false;
  2339. bool IsStmtReference = false;
  2340. Expected<unsigned> MaybeStmtCode = Record.readRecord(Cursor, Entry.ID);
  2341. if (!MaybeStmtCode) {
  2342. Error(toString(MaybeStmtCode.takeError()));
  2343. return nullptr;
  2344. }
  2345. switch ((StmtCode)MaybeStmtCode.get()) {
  2346. case STMT_STOP:
  2347. Finished = true;
  2348. break;
  2349. case STMT_REF_PTR:
  2350. IsStmtReference = true;
  2351. assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
  2352. "No stmt was recorded for this offset reference!");
  2353. S = StmtEntries[Record.readInt()];
  2354. break;
  2355. case STMT_NULL_PTR:
  2356. S = nullptr;
  2357. break;
  2358. case STMT_NULL:
  2359. S = new (Context) NullStmt(Empty);
  2360. break;
  2361. case STMT_COMPOUND:
  2362. S = CompoundStmt::CreateEmpty(
  2363. Context, /*NumStmts=*/Record[ASTStmtReader::NumStmtFields]);
  2364. break;
  2365. case STMT_CASE:
  2366. S = CaseStmt::CreateEmpty(
  2367. Context,
  2368. /*CaseStmtIsGNURange*/ Record[ASTStmtReader::NumStmtFields + 3]);
  2369. break;
  2370. case STMT_DEFAULT:
  2371. S = new (Context) DefaultStmt(Empty);
  2372. break;
  2373. case STMT_LABEL:
  2374. S = new (Context) LabelStmt(Empty);
  2375. break;
  2376. case STMT_ATTRIBUTED:
  2377. S = AttributedStmt::CreateEmpty(
  2378. Context,
  2379. /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
  2380. break;
  2381. case STMT_IF:
  2382. S = IfStmt::CreateEmpty(
  2383. Context,
  2384. /* HasElse=*/Record[ASTStmtReader::NumStmtFields],
  2385. /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1],
  2386. /* HasInit=*/Record[ASTStmtReader::NumStmtFields + 2]);
  2387. break;
  2388. case STMT_SWITCH:
  2389. S = SwitchStmt::CreateEmpty(
  2390. Context,
  2391. /* HasInit=*/Record[ASTStmtReader::NumStmtFields],
  2392. /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1]);
  2393. break;
  2394. case STMT_WHILE:
  2395. S = WhileStmt::CreateEmpty(
  2396. Context,
  2397. /* HasVar=*/Record[ASTStmtReader::NumStmtFields]);
  2398. break;
  2399. case STMT_DO:
  2400. S = new (Context) DoStmt(Empty);
  2401. break;
  2402. case STMT_FOR:
  2403. S = new (Context) ForStmt(Empty);
  2404. break;
  2405. case STMT_GOTO:
  2406. S = new (Context) GotoStmt(Empty);
  2407. break;
  2408. case STMT_INDIRECT_GOTO:
  2409. S = new (Context) IndirectGotoStmt(Empty);
  2410. break;
  2411. case STMT_CONTINUE:
  2412. S = new (Context) ContinueStmt(Empty);
  2413. break;
  2414. case STMT_BREAK:
  2415. S = new (Context) BreakStmt(Empty);
  2416. break;
  2417. case STMT_RETURN:
  2418. S = ReturnStmt::CreateEmpty(
  2419. Context, /* HasNRVOCandidate=*/Record[ASTStmtReader::NumStmtFields]);
  2420. break;
  2421. case STMT_DECL:
  2422. S = new (Context) DeclStmt(Empty);
  2423. break;
  2424. case STMT_GCCASM:
  2425. S = new (Context) GCCAsmStmt(Empty);
  2426. break;
  2427. case STMT_MSASM:
  2428. S = new (Context) MSAsmStmt(Empty);
  2429. break;
  2430. case STMT_CAPTURED:
  2431. S = CapturedStmt::CreateDeserialized(
  2432. Context, Record[ASTStmtReader::NumStmtFields]);
  2433. break;
  2434. case EXPR_CONSTANT:
  2435. S = ConstantExpr::CreateEmpty(
  2436. Context, static_cast<ConstantExpr::ResultStorageKind>(
  2437. /*StorageKind=*/Record[ASTStmtReader::NumExprFields]));
  2438. break;
  2439. case EXPR_SYCL_UNIQUE_STABLE_NAME:
  2440. S = SYCLUniqueStableNameExpr::CreateEmpty(Context);
  2441. break;
  2442. case EXPR_PREDEFINED:
  2443. S = PredefinedExpr::CreateEmpty(
  2444. Context,
  2445. /*HasFunctionName*/ Record[ASTStmtReader::NumExprFields]);
  2446. break;
  2447. case EXPR_DECL_REF:
  2448. S = DeclRefExpr::CreateEmpty(
  2449. Context,
  2450. /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
  2451. /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
  2452. /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2],
  2453. /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
  2454. Record[ASTStmtReader::NumExprFields + 6] : 0);
  2455. break;
  2456. case EXPR_INTEGER_LITERAL:
  2457. S = IntegerLiteral::Create(Context, Empty);
  2458. break;
  2459. case EXPR_FIXEDPOINT_LITERAL:
  2460. S = FixedPointLiteral::Create(Context, Empty);
  2461. break;
  2462. case EXPR_FLOATING_LITERAL:
  2463. S = FloatingLiteral::Create(Context, Empty);
  2464. break;
  2465. case EXPR_IMAGINARY_LITERAL:
  2466. S = new (Context) ImaginaryLiteral(Empty);
  2467. break;
  2468. case EXPR_STRING_LITERAL:
  2469. S = StringLiteral::CreateEmpty(
  2470. Context,
  2471. /* NumConcatenated=*/Record[ASTStmtReader::NumExprFields],
  2472. /* Length=*/Record[ASTStmtReader::NumExprFields + 1],
  2473. /* CharByteWidth=*/Record[ASTStmtReader::NumExprFields + 2]);
  2474. break;
  2475. case EXPR_CHARACTER_LITERAL:
  2476. S = new (Context) CharacterLiteral(Empty);
  2477. break;
  2478. case EXPR_PAREN:
  2479. S = new (Context) ParenExpr(Empty);
  2480. break;
  2481. case EXPR_PAREN_LIST:
  2482. S = ParenListExpr::CreateEmpty(
  2483. Context,
  2484. /* NumExprs=*/Record[ASTStmtReader::NumExprFields]);
  2485. break;
  2486. case EXPR_UNARY_OPERATOR:
  2487. S = UnaryOperator::CreateEmpty(Context,
  2488. Record[ASTStmtReader::NumExprFields]);
  2489. break;
  2490. case EXPR_OFFSETOF:
  2491. S = OffsetOfExpr::CreateEmpty(Context,
  2492. Record[ASTStmtReader::NumExprFields],
  2493. Record[ASTStmtReader::NumExprFields + 1]);
  2494. break;
  2495. case EXPR_SIZEOF_ALIGN_OF:
  2496. S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
  2497. break;
  2498. case EXPR_ARRAY_SUBSCRIPT:
  2499. S = new (Context) ArraySubscriptExpr(Empty);
  2500. break;
  2501. case EXPR_MATRIX_SUBSCRIPT:
  2502. S = new (Context) MatrixSubscriptExpr(Empty);
  2503. break;
  2504. case EXPR_OMP_ARRAY_SECTION:
  2505. S = new (Context) OMPArraySectionExpr(Empty);
  2506. break;
  2507. case EXPR_OMP_ARRAY_SHAPING:
  2508. S = OMPArrayShapingExpr::CreateEmpty(
  2509. Context, Record[ASTStmtReader::NumExprFields]);
  2510. break;
  2511. case EXPR_OMP_ITERATOR:
  2512. S = OMPIteratorExpr::CreateEmpty(Context,
  2513. Record[ASTStmtReader::NumExprFields]);
  2514. break;
  2515. case EXPR_CALL:
  2516. S = CallExpr::CreateEmpty(
  2517. Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
  2518. /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
  2519. break;
  2520. case EXPR_RECOVERY:
  2521. S = RecoveryExpr::CreateEmpty(
  2522. Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
  2523. break;
  2524. case EXPR_MEMBER:
  2525. S = MemberExpr::CreateEmpty(Context, Record[ASTStmtReader::NumExprFields],
  2526. Record[ASTStmtReader::NumExprFields + 1],
  2527. Record[ASTStmtReader::NumExprFields + 2],
  2528. Record[ASTStmtReader::NumExprFields + 3]);
  2529. break;
  2530. case EXPR_BINARY_OPERATOR:
  2531. S = BinaryOperator::CreateEmpty(Context,
  2532. Record[ASTStmtReader::NumExprFields]);
  2533. break;
  2534. case EXPR_COMPOUND_ASSIGN_OPERATOR:
  2535. S = CompoundAssignOperator::CreateEmpty(
  2536. Context, Record[ASTStmtReader::NumExprFields]);
  2537. break;
  2538. case EXPR_CONDITIONAL_OPERATOR:
  2539. S = new (Context) ConditionalOperator(Empty);
  2540. break;
  2541. case EXPR_BINARY_CONDITIONAL_OPERATOR:
  2542. S = new (Context) BinaryConditionalOperator(Empty);
  2543. break;
  2544. case EXPR_IMPLICIT_CAST:
  2545. S = ImplicitCastExpr::CreateEmpty(
  2546. Context,
  2547. /*PathSize*/ Record[ASTStmtReader::NumExprFields],
  2548. /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
  2549. break;
  2550. case EXPR_CSTYLE_CAST:
  2551. S = CStyleCastExpr::CreateEmpty(
  2552. Context,
  2553. /*PathSize*/ Record[ASTStmtReader::NumExprFields],
  2554. /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
  2555. break;
  2556. case EXPR_COMPOUND_LITERAL:
  2557. S = new (Context) CompoundLiteralExpr(Empty);
  2558. break;
  2559. case EXPR_EXT_VECTOR_ELEMENT:
  2560. S = new (Context) ExtVectorElementExpr(Empty);
  2561. break;
  2562. case EXPR_INIT_LIST:
  2563. S = new (Context) InitListExpr(Empty);
  2564. break;
  2565. case EXPR_DESIGNATED_INIT:
  2566. S = DesignatedInitExpr::CreateEmpty(Context,
  2567. Record[ASTStmtReader::NumExprFields] - 1);
  2568. break;
  2569. case EXPR_DESIGNATED_INIT_UPDATE:
  2570. S = new (Context) DesignatedInitUpdateExpr(Empty);
  2571. break;
  2572. case EXPR_IMPLICIT_VALUE_INIT:
  2573. S = new (Context) ImplicitValueInitExpr(Empty);
  2574. break;
  2575. case EXPR_NO_INIT:
  2576. S = new (Context) NoInitExpr(Empty);
  2577. break;
  2578. case EXPR_ARRAY_INIT_LOOP:
  2579. S = new (Context) ArrayInitLoopExpr(Empty);
  2580. break;
  2581. case EXPR_ARRAY_INIT_INDEX:
  2582. S = new (Context) ArrayInitIndexExpr(Empty);
  2583. break;
  2584. case EXPR_VA_ARG:
  2585. S = new (Context) VAArgExpr(Empty);
  2586. break;
  2587. case EXPR_SOURCE_LOC:
  2588. S = new (Context) SourceLocExpr(Empty);
  2589. break;
  2590. case EXPR_ADDR_LABEL:
  2591. S = new (Context) AddrLabelExpr(Empty);
  2592. break;
  2593. case EXPR_STMT:
  2594. S = new (Context) StmtExpr(Empty);
  2595. break;
  2596. case EXPR_CHOOSE:
  2597. S = new (Context) ChooseExpr(Empty);
  2598. break;
  2599. case EXPR_GNU_NULL:
  2600. S = new (Context) GNUNullExpr(Empty);
  2601. break;
  2602. case EXPR_SHUFFLE_VECTOR:
  2603. S = new (Context) ShuffleVectorExpr(Empty);
  2604. break;
  2605. case EXPR_CONVERT_VECTOR:
  2606. S = new (Context) ConvertVectorExpr(Empty);
  2607. break;
  2608. case EXPR_BLOCK:
  2609. S = new (Context) BlockExpr(Empty);
  2610. break;
  2611. case EXPR_GENERIC_SELECTION:
  2612. S = GenericSelectionExpr::CreateEmpty(
  2613. Context,
  2614. /*NumAssocs=*/Record[ASTStmtReader::NumExprFields]);
  2615. break;
  2616. case EXPR_OBJC_STRING_LITERAL:
  2617. S = new (Context) ObjCStringLiteral(Empty);
  2618. break;
  2619. case EXPR_OBJC_BOXED_EXPRESSION:
  2620. S = new (Context) ObjCBoxedExpr(Empty);
  2621. break;
  2622. case EXPR_OBJC_ARRAY_LITERAL:
  2623. S = ObjCArrayLiteral::CreateEmpty(Context,
  2624. Record[ASTStmtReader::NumExprFields]);
  2625. break;
  2626. case EXPR_OBJC_DICTIONARY_LITERAL:
  2627. S = ObjCDictionaryLiteral::CreateEmpty(Context,
  2628. Record[ASTStmtReader::NumExprFields],
  2629. Record[ASTStmtReader::NumExprFields + 1]);
  2630. break;
  2631. case EXPR_OBJC_ENCODE:
  2632. S = new (Context) ObjCEncodeExpr(Empty);
  2633. break;
  2634. case EXPR_OBJC_SELECTOR_EXPR:
  2635. S = new (Context) ObjCSelectorExpr(Empty);
  2636. break;
  2637. case EXPR_OBJC_PROTOCOL_EXPR:
  2638. S = new (Context) ObjCProtocolExpr(Empty);
  2639. break;
  2640. case EXPR_OBJC_IVAR_REF_EXPR:
  2641. S = new (Context) ObjCIvarRefExpr(Empty);
  2642. break;
  2643. case EXPR_OBJC_PROPERTY_REF_EXPR:
  2644. S = new (Context) ObjCPropertyRefExpr(Empty);
  2645. break;
  2646. case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
  2647. S = new (Context) ObjCSubscriptRefExpr(Empty);
  2648. break;
  2649. case EXPR_OBJC_KVC_REF_EXPR:
  2650. llvm_unreachable("mismatching AST file");
  2651. case EXPR_OBJC_MESSAGE_EXPR:
  2652. S = ObjCMessageExpr::CreateEmpty(Context,
  2653. Record[ASTStmtReader::NumExprFields],
  2654. Record[ASTStmtReader::NumExprFields + 1]);
  2655. break;
  2656. case EXPR_OBJC_ISA:
  2657. S = new (Context) ObjCIsaExpr(Empty);
  2658. break;
  2659. case EXPR_OBJC_INDIRECT_COPY_RESTORE:
  2660. S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
  2661. break;
  2662. case EXPR_OBJC_BRIDGED_CAST:
  2663. S = new (Context) ObjCBridgedCastExpr(Empty);
  2664. break;
  2665. case STMT_OBJC_FOR_COLLECTION:
  2666. S = new (Context) ObjCForCollectionStmt(Empty);
  2667. break;
  2668. case STMT_OBJC_CATCH:
  2669. S = new (Context) ObjCAtCatchStmt(Empty);
  2670. break;
  2671. case STMT_OBJC_FINALLY:
  2672. S = new (Context) ObjCAtFinallyStmt(Empty);
  2673. break;
  2674. case STMT_OBJC_AT_TRY:
  2675. S = ObjCAtTryStmt::CreateEmpty(Context,
  2676. Record[ASTStmtReader::NumStmtFields],
  2677. Record[ASTStmtReader::NumStmtFields + 1]);
  2678. break;
  2679. case STMT_OBJC_AT_SYNCHRONIZED:
  2680. S = new (Context) ObjCAtSynchronizedStmt(Empty);
  2681. break;
  2682. case STMT_OBJC_AT_THROW:
  2683. S = new (Context) ObjCAtThrowStmt(Empty);
  2684. break;
  2685. case STMT_OBJC_AUTORELEASE_POOL:
  2686. S = new (Context) ObjCAutoreleasePoolStmt(Empty);
  2687. break;
  2688. case EXPR_OBJC_BOOL_LITERAL:
  2689. S = new (Context) ObjCBoolLiteralExpr(Empty);
  2690. break;
  2691. case EXPR_OBJC_AVAILABILITY_CHECK:
  2692. S = new (Context) ObjCAvailabilityCheckExpr(Empty);
  2693. break;
  2694. case STMT_SEH_LEAVE:
  2695. S = new (Context) SEHLeaveStmt(Empty);
  2696. break;
  2697. case STMT_SEH_EXCEPT:
  2698. S = new (Context) SEHExceptStmt(Empty);
  2699. break;
  2700. case STMT_SEH_FINALLY:
  2701. S = new (Context) SEHFinallyStmt(Empty);
  2702. break;
  2703. case STMT_SEH_TRY:
  2704. S = new (Context) SEHTryStmt(Empty);
  2705. break;
  2706. case STMT_CXX_CATCH:
  2707. S = new (Context) CXXCatchStmt(Empty);
  2708. break;
  2709. case STMT_CXX_TRY:
  2710. S = CXXTryStmt::Create(Context, Empty,
  2711. /*numHandlers=*/Record[ASTStmtReader::NumStmtFields]);
  2712. break;
  2713. case STMT_CXX_FOR_RANGE:
  2714. S = new (Context) CXXForRangeStmt(Empty);
  2715. break;
  2716. case STMT_MS_DEPENDENT_EXISTS:
  2717. S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
  2718. NestedNameSpecifierLoc(),
  2719. DeclarationNameInfo(),
  2720. nullptr);
  2721. break;
  2722. case STMT_OMP_CANONICAL_LOOP:
  2723. S = OMPCanonicalLoop::createEmpty(Context);
  2724. break;
  2725. case STMT_OMP_META_DIRECTIVE:
  2726. S = OMPMetaDirective::CreateEmpty(
  2727. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2728. break;
  2729. case STMT_OMP_PARALLEL_DIRECTIVE:
  2730. S =
  2731. OMPParallelDirective::CreateEmpty(Context,
  2732. Record[ASTStmtReader::NumStmtFields],
  2733. Empty);
  2734. break;
  2735. case STMT_OMP_SIMD_DIRECTIVE: {
  2736. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2737. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2738. S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
  2739. CollapsedNum, Empty);
  2740. break;
  2741. }
  2742. case STMT_OMP_TILE_DIRECTIVE: {
  2743. unsigned NumLoops = Record[ASTStmtReader::NumStmtFields];
  2744. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2745. S = OMPTileDirective::CreateEmpty(Context, NumClauses, NumLoops);
  2746. break;
  2747. }
  2748. case STMT_OMP_UNROLL_DIRECTIVE: {
  2749. assert(Record[ASTStmtReader::NumStmtFields] == 1 && "Unroll directive accepts only a single loop");
  2750. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2751. S = OMPUnrollDirective::CreateEmpty(Context, NumClauses);
  2752. break;
  2753. }
  2754. case STMT_OMP_FOR_DIRECTIVE: {
  2755. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2756. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2757. S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
  2758. Empty);
  2759. break;
  2760. }
  2761. case STMT_OMP_FOR_SIMD_DIRECTIVE: {
  2762. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2763. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2764. S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
  2765. Empty);
  2766. break;
  2767. }
  2768. case STMT_OMP_SECTIONS_DIRECTIVE:
  2769. S = OMPSectionsDirective::CreateEmpty(
  2770. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2771. break;
  2772. case STMT_OMP_SECTION_DIRECTIVE:
  2773. S = OMPSectionDirective::CreateEmpty(Context, Empty);
  2774. break;
  2775. case STMT_OMP_SINGLE_DIRECTIVE:
  2776. S = OMPSingleDirective::CreateEmpty(
  2777. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2778. break;
  2779. case STMT_OMP_MASTER_DIRECTIVE:
  2780. S = OMPMasterDirective::CreateEmpty(Context, Empty);
  2781. break;
  2782. case STMT_OMP_CRITICAL_DIRECTIVE:
  2783. S = OMPCriticalDirective::CreateEmpty(
  2784. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2785. break;
  2786. case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
  2787. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2788. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2789. S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
  2790. CollapsedNum, Empty);
  2791. break;
  2792. }
  2793. case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: {
  2794. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2795. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2796. S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses,
  2797. CollapsedNum, Empty);
  2798. break;
  2799. }
  2800. case STMT_OMP_PARALLEL_MASTER_DIRECTIVE:
  2801. S = OMPParallelMasterDirective::CreateEmpty(
  2802. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2803. break;
  2804. case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
  2805. S = OMPParallelSectionsDirective::CreateEmpty(
  2806. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2807. break;
  2808. case STMT_OMP_TASK_DIRECTIVE:
  2809. S = OMPTaskDirective::CreateEmpty(
  2810. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2811. break;
  2812. case STMT_OMP_TASKYIELD_DIRECTIVE:
  2813. S = OMPTaskyieldDirective::CreateEmpty(Context, Empty);
  2814. break;
  2815. case STMT_OMP_BARRIER_DIRECTIVE:
  2816. S = OMPBarrierDirective::CreateEmpty(Context, Empty);
  2817. break;
  2818. case STMT_OMP_TASKWAIT_DIRECTIVE:
  2819. S = OMPTaskwaitDirective::CreateEmpty(
  2820. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2821. break;
  2822. case STMT_OMP_TASKGROUP_DIRECTIVE:
  2823. S = OMPTaskgroupDirective::CreateEmpty(
  2824. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2825. break;
  2826. case STMT_OMP_FLUSH_DIRECTIVE:
  2827. S = OMPFlushDirective::CreateEmpty(
  2828. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2829. break;
  2830. case STMT_OMP_DEPOBJ_DIRECTIVE:
  2831. S = OMPDepobjDirective::CreateEmpty(
  2832. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2833. break;
  2834. case STMT_OMP_SCAN_DIRECTIVE:
  2835. S = OMPScanDirective::CreateEmpty(
  2836. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2837. break;
  2838. case STMT_OMP_ORDERED_DIRECTIVE: {
  2839. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
  2840. bool HasAssociatedStmt = Record[ASTStmtReader::NumStmtFields + 2];
  2841. S = OMPOrderedDirective::CreateEmpty(Context, NumClauses,
  2842. !HasAssociatedStmt, Empty);
  2843. break;
  2844. }
  2845. case STMT_OMP_ATOMIC_DIRECTIVE:
  2846. S = OMPAtomicDirective::CreateEmpty(
  2847. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2848. break;
  2849. case STMT_OMP_TARGET_DIRECTIVE:
  2850. S = OMPTargetDirective::CreateEmpty(
  2851. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2852. break;
  2853. case STMT_OMP_TARGET_DATA_DIRECTIVE:
  2854. S = OMPTargetDataDirective::CreateEmpty(
  2855. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2856. break;
  2857. case STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE:
  2858. S = OMPTargetEnterDataDirective::CreateEmpty(
  2859. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2860. break;
  2861. case STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE:
  2862. S = OMPTargetExitDataDirective::CreateEmpty(
  2863. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2864. break;
  2865. case STMT_OMP_TARGET_PARALLEL_DIRECTIVE:
  2866. S = OMPTargetParallelDirective::CreateEmpty(
  2867. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2868. break;
  2869. case STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE: {
  2870. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2871. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2872. S = OMPTargetParallelForDirective::CreateEmpty(Context, NumClauses,
  2873. CollapsedNum, Empty);
  2874. break;
  2875. }
  2876. case STMT_OMP_TARGET_UPDATE_DIRECTIVE:
  2877. S = OMPTargetUpdateDirective::CreateEmpty(
  2878. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2879. break;
  2880. case STMT_OMP_TEAMS_DIRECTIVE:
  2881. S = OMPTeamsDirective::CreateEmpty(
  2882. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2883. break;
  2884. case STMT_OMP_CANCELLATION_POINT_DIRECTIVE:
  2885. S = OMPCancellationPointDirective::CreateEmpty(Context, Empty);
  2886. break;
  2887. case STMT_OMP_CANCEL_DIRECTIVE:
  2888. S = OMPCancelDirective::CreateEmpty(
  2889. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  2890. break;
  2891. case STMT_OMP_TASKLOOP_DIRECTIVE: {
  2892. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2893. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2894. S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
  2895. Empty);
  2896. break;
  2897. }
  2898. case STMT_OMP_TASKLOOP_SIMD_DIRECTIVE: {
  2899. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2900. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2901. S = OMPTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
  2902. CollapsedNum, Empty);
  2903. break;
  2904. }
  2905. case STMT_OMP_MASTER_TASKLOOP_DIRECTIVE: {
  2906. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2907. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2908. S = OMPMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
  2909. CollapsedNum, Empty);
  2910. break;
  2911. }
  2912. case STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
  2913. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2914. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2915. S = OMPMasterTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
  2916. CollapsedNum, Empty);
  2917. break;
  2918. }
  2919. case STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE: {
  2920. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2921. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2922. S = OMPParallelMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
  2923. CollapsedNum, Empty);
  2924. break;
  2925. }
  2926. case STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
  2927. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2928. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2929. S = OMPParallelMasterTaskLoopSimdDirective::CreateEmpty(
  2930. Context, NumClauses, CollapsedNum, Empty);
  2931. break;
  2932. }
  2933. case STMT_OMP_DISTRIBUTE_DIRECTIVE: {
  2934. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2935. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2936. S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
  2937. Empty);
  2938. break;
  2939. }
  2940. case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
  2941. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2942. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2943. S = OMPDistributeParallelForDirective::CreateEmpty(Context, NumClauses,
  2944. CollapsedNum, Empty);
  2945. break;
  2946. }
  2947. case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
  2948. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2949. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2950. S = OMPDistributeParallelForSimdDirective::CreateEmpty(Context, NumClauses,
  2951. CollapsedNum,
  2952. Empty);
  2953. break;
  2954. }
  2955. case STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE: {
  2956. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2957. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2958. S = OMPDistributeSimdDirective::CreateEmpty(Context, NumClauses,
  2959. CollapsedNum, Empty);
  2960. break;
  2961. }
  2962. case STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE: {
  2963. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2964. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2965. S = OMPTargetParallelForSimdDirective::CreateEmpty(Context, NumClauses,
  2966. CollapsedNum, Empty);
  2967. break;
  2968. }
  2969. case STMT_OMP_TARGET_SIMD_DIRECTIVE: {
  2970. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2971. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2972. S = OMPTargetSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
  2973. Empty);
  2974. break;
  2975. }
  2976. case STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE: {
  2977. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2978. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2979. S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
  2980. CollapsedNum, Empty);
  2981. break;
  2982. }
  2983. case STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
  2984. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2985. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2986. S = OMPTeamsDistributeSimdDirective::CreateEmpty(Context, NumClauses,
  2987. CollapsedNum, Empty);
  2988. break;
  2989. }
  2990. case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
  2991. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2992. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  2993. S = OMPTeamsDistributeParallelForSimdDirective::CreateEmpty(
  2994. Context, NumClauses, CollapsedNum, Empty);
  2995. break;
  2996. }
  2997. case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
  2998. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  2999. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  3000. S = OMPTeamsDistributeParallelForDirective::CreateEmpty(
  3001. Context, NumClauses, CollapsedNum, Empty);
  3002. break;
  3003. }
  3004. case STMT_OMP_TARGET_TEAMS_DIRECTIVE:
  3005. S = OMPTargetTeamsDirective::CreateEmpty(
  3006. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  3007. break;
  3008. case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE: {
  3009. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  3010. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  3011. S = OMPTargetTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
  3012. CollapsedNum, Empty);
  3013. break;
  3014. }
  3015. case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
  3016. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  3017. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  3018. S = OMPTargetTeamsDistributeParallelForDirective::CreateEmpty(
  3019. Context, NumClauses, CollapsedNum, Empty);
  3020. break;
  3021. }
  3022. case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
  3023. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  3024. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  3025. S = OMPTargetTeamsDistributeParallelForSimdDirective::CreateEmpty(
  3026. Context, NumClauses, CollapsedNum, Empty);
  3027. break;
  3028. }
  3029. case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
  3030. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  3031. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  3032. S = OMPTargetTeamsDistributeSimdDirective::CreateEmpty(
  3033. Context, NumClauses, CollapsedNum, Empty);
  3034. break;
  3035. }
  3036. case STMT_OMP_INTEROP_DIRECTIVE:
  3037. S = OMPInteropDirective::CreateEmpty(
  3038. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  3039. break;
  3040. case STMT_OMP_DISPATCH_DIRECTIVE:
  3041. S = OMPDispatchDirective::CreateEmpty(
  3042. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  3043. break;
  3044. case STMT_OMP_MASKED_DIRECTIVE:
  3045. S = OMPMaskedDirective::CreateEmpty(
  3046. Context, Record[ASTStmtReader::NumStmtFields], Empty);
  3047. break;
  3048. case STMT_OMP_GENERIC_LOOP_DIRECTIVE: {
  3049. unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
  3050. unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
  3051. S = OMPGenericLoopDirective::CreateEmpty(Context, NumClauses,
  3052. CollapsedNum, Empty);
  3053. break;
  3054. }
  3055. case EXPR_CXX_OPERATOR_CALL:
  3056. S = CXXOperatorCallExpr::CreateEmpty(
  3057. Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
  3058. /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
  3059. break;
  3060. case EXPR_CXX_MEMBER_CALL:
  3061. S = CXXMemberCallExpr::CreateEmpty(
  3062. Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
  3063. /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
  3064. break;
  3065. case EXPR_CXX_REWRITTEN_BINARY_OPERATOR:
  3066. S = new (Context) CXXRewrittenBinaryOperator(Empty);
  3067. break;
  3068. case EXPR_CXX_CONSTRUCT:
  3069. S = CXXConstructExpr::CreateEmpty(
  3070. Context,
  3071. /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
  3072. break;
  3073. case EXPR_CXX_INHERITED_CTOR_INIT:
  3074. S = new (Context) CXXInheritedCtorInitExpr(Empty);
  3075. break;
  3076. case EXPR_CXX_TEMPORARY_OBJECT:
  3077. S = CXXTemporaryObjectExpr::CreateEmpty(
  3078. Context,
  3079. /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
  3080. break;
  3081. case EXPR_CXX_STATIC_CAST:
  3082. S = CXXStaticCastExpr::CreateEmpty(
  3083. Context,
  3084. /*PathSize*/ Record[ASTStmtReader::NumExprFields],
  3085. /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
  3086. break;
  3087. case EXPR_CXX_DYNAMIC_CAST:
  3088. S = CXXDynamicCastExpr::CreateEmpty(Context,
  3089. /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
  3090. break;
  3091. case EXPR_CXX_REINTERPRET_CAST:
  3092. S = CXXReinterpretCastExpr::CreateEmpty(Context,
  3093. /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
  3094. break;
  3095. case EXPR_CXX_CONST_CAST:
  3096. S = CXXConstCastExpr::CreateEmpty(Context);
  3097. break;
  3098. case EXPR_CXX_ADDRSPACE_CAST:
  3099. S = CXXAddrspaceCastExpr::CreateEmpty(Context);
  3100. break;
  3101. case EXPR_CXX_FUNCTIONAL_CAST:
  3102. S = CXXFunctionalCastExpr::CreateEmpty(
  3103. Context,
  3104. /*PathSize*/ Record[ASTStmtReader::NumExprFields],
  3105. /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
  3106. break;
  3107. case EXPR_BUILTIN_BIT_CAST:
  3108. assert(Record[ASTStmtReader::NumExprFields] == 0 && "Wrong PathSize!");
  3109. S = new (Context) BuiltinBitCastExpr(Empty);
  3110. break;
  3111. case EXPR_USER_DEFINED_LITERAL:
  3112. S = UserDefinedLiteral::CreateEmpty(
  3113. Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
  3114. /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
  3115. break;
  3116. case EXPR_CXX_STD_INITIALIZER_LIST:
  3117. S = new (Context) CXXStdInitializerListExpr(Empty);
  3118. break;
  3119. case EXPR_CXX_BOOL_LITERAL:
  3120. S = new (Context) CXXBoolLiteralExpr(Empty);
  3121. break;
  3122. case EXPR_CXX_NULL_PTR_LITERAL:
  3123. S = new (Context) CXXNullPtrLiteralExpr(Empty);
  3124. break;
  3125. case EXPR_CXX_TYPEID_EXPR:
  3126. S = new (Context) CXXTypeidExpr(Empty, true);
  3127. break;
  3128. case EXPR_CXX_TYPEID_TYPE:
  3129. S = new (Context) CXXTypeidExpr(Empty, false);
  3130. break;
  3131. case EXPR_CXX_UUIDOF_EXPR:
  3132. S = new (Context) CXXUuidofExpr(Empty, true);
  3133. break;
  3134. case EXPR_CXX_PROPERTY_REF_EXPR:
  3135. S = new (Context) MSPropertyRefExpr(Empty);
  3136. break;
  3137. case EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR:
  3138. S = new (Context) MSPropertySubscriptExpr(Empty);
  3139. break;
  3140. case EXPR_CXX_UUIDOF_TYPE:
  3141. S = new (Context) CXXUuidofExpr(Empty, false);
  3142. break;
  3143. case EXPR_CXX_THIS:
  3144. S = new (Context) CXXThisExpr(Empty);
  3145. break;
  3146. case EXPR_CXX_THROW:
  3147. S = new (Context) CXXThrowExpr(Empty);
  3148. break;
  3149. case EXPR_CXX_DEFAULT_ARG:
  3150. S = new (Context) CXXDefaultArgExpr(Empty);
  3151. break;
  3152. case EXPR_CXX_DEFAULT_INIT:
  3153. S = new (Context) CXXDefaultInitExpr(Empty);
  3154. break;
  3155. case EXPR_CXX_BIND_TEMPORARY:
  3156. S = new (Context) CXXBindTemporaryExpr(Empty);
  3157. break;
  3158. case EXPR_CXX_SCALAR_VALUE_INIT:
  3159. S = new (Context) CXXScalarValueInitExpr(Empty);
  3160. break;
  3161. case EXPR_CXX_NEW:
  3162. S = CXXNewExpr::CreateEmpty(
  3163. Context,
  3164. /*IsArray=*/Record[ASTStmtReader::NumExprFields],
  3165. /*HasInit=*/Record[ASTStmtReader::NumExprFields + 1],
  3166. /*NumPlacementArgs=*/Record[ASTStmtReader::NumExprFields + 2],
  3167. /*IsParenTypeId=*/Record[ASTStmtReader::NumExprFields + 3]);
  3168. break;
  3169. case EXPR_CXX_DELETE:
  3170. S = new (Context) CXXDeleteExpr(Empty);
  3171. break;
  3172. case EXPR_CXX_PSEUDO_DESTRUCTOR:
  3173. S = new (Context) CXXPseudoDestructorExpr(Empty);
  3174. break;
  3175. case EXPR_EXPR_WITH_CLEANUPS:
  3176. S = ExprWithCleanups::Create(Context, Empty,
  3177. Record[ASTStmtReader::NumExprFields]);
  3178. break;
  3179. case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
  3180. S = CXXDependentScopeMemberExpr::CreateEmpty(
  3181. Context,
  3182. /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
  3183. /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 1],
  3184. /*HasFirstQualifierFoundInScope=*/
  3185. Record[ASTStmtReader::NumExprFields + 2]);
  3186. break;
  3187. case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
  3188. S = DependentScopeDeclRefExpr::CreateEmpty(Context,
  3189. /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
  3190. /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
  3191. ? Record[ASTStmtReader::NumExprFields + 1]
  3192. : 0);
  3193. break;
  3194. case EXPR_CXX_UNRESOLVED_CONSTRUCT:
  3195. S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
  3196. /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
  3197. break;
  3198. case EXPR_CXX_UNRESOLVED_MEMBER:
  3199. S = UnresolvedMemberExpr::CreateEmpty(
  3200. Context,
  3201. /*NumResults=*/Record[ASTStmtReader::NumExprFields],
  3202. /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 1],
  3203. /*NumTemplateArgs=*/
  3204. Record[ASTStmtReader::NumExprFields + 1]
  3205. ? Record[ASTStmtReader::NumExprFields + 2]
  3206. : 0);
  3207. break;
  3208. case EXPR_CXX_UNRESOLVED_LOOKUP:
  3209. S = UnresolvedLookupExpr::CreateEmpty(
  3210. Context,
  3211. /*NumResults=*/Record[ASTStmtReader::NumExprFields],
  3212. /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 1],
  3213. /*NumTemplateArgs=*/
  3214. Record[ASTStmtReader::NumExprFields + 1]
  3215. ? Record[ASTStmtReader::NumExprFields + 2]
  3216. : 0);
  3217. break;
  3218. case EXPR_TYPE_TRAIT:
  3219. S = TypeTraitExpr::CreateDeserialized(Context,
  3220. Record[ASTStmtReader::NumExprFields]);
  3221. break;
  3222. case EXPR_ARRAY_TYPE_TRAIT:
  3223. S = new (Context) ArrayTypeTraitExpr(Empty);
  3224. break;
  3225. case EXPR_CXX_EXPRESSION_TRAIT:
  3226. S = new (Context) ExpressionTraitExpr(Empty);
  3227. break;
  3228. case EXPR_CXX_NOEXCEPT:
  3229. S = new (Context) CXXNoexceptExpr(Empty);
  3230. break;
  3231. case EXPR_PACK_EXPANSION:
  3232. S = new (Context) PackExpansionExpr(Empty);
  3233. break;
  3234. case EXPR_SIZEOF_PACK:
  3235. S = SizeOfPackExpr::CreateDeserialized(
  3236. Context,
  3237. /*NumPartialArgs=*/Record[ASTStmtReader::NumExprFields]);
  3238. break;
  3239. case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
  3240. S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
  3241. break;
  3242. case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
  3243. S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
  3244. break;
  3245. case EXPR_FUNCTION_PARM_PACK:
  3246. S = FunctionParmPackExpr::CreateEmpty(Context,
  3247. Record[ASTStmtReader::NumExprFields]);
  3248. break;
  3249. case EXPR_MATERIALIZE_TEMPORARY:
  3250. S = new (Context) MaterializeTemporaryExpr(Empty);
  3251. break;
  3252. case EXPR_CXX_FOLD:
  3253. S = new (Context) CXXFoldExpr(Empty);
  3254. break;
  3255. case EXPR_OPAQUE_VALUE:
  3256. S = new (Context) OpaqueValueExpr(Empty);
  3257. break;
  3258. case EXPR_CUDA_KERNEL_CALL:
  3259. S = CUDAKernelCallExpr::CreateEmpty(
  3260. Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
  3261. /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
  3262. break;
  3263. case EXPR_ASTYPE:
  3264. S = new (Context) AsTypeExpr(Empty);
  3265. break;
  3266. case EXPR_PSEUDO_OBJECT: {
  3267. unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
  3268. S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
  3269. break;
  3270. }
  3271. case EXPR_ATOMIC:
  3272. S = new (Context) AtomicExpr(Empty);
  3273. break;
  3274. case EXPR_LAMBDA: {
  3275. unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
  3276. S = LambdaExpr::CreateDeserialized(Context, NumCaptures);
  3277. break;
  3278. }
  3279. case STMT_COROUTINE_BODY: {
  3280. unsigned NumParams = Record[ASTStmtReader::NumStmtFields];
  3281. S = CoroutineBodyStmt::Create(Context, Empty, NumParams);
  3282. break;
  3283. }
  3284. case STMT_CORETURN:
  3285. S = new (Context) CoreturnStmt(Empty);
  3286. break;
  3287. case EXPR_COAWAIT:
  3288. S = new (Context) CoawaitExpr(Empty);
  3289. break;
  3290. case EXPR_COYIELD:
  3291. S = new (Context) CoyieldExpr(Empty);
  3292. break;
  3293. case EXPR_DEPENDENT_COAWAIT:
  3294. S = new (Context) DependentCoawaitExpr(Empty);
  3295. break;
  3296. case EXPR_CONCEPT_SPECIALIZATION: {
  3297. unsigned numTemplateArgs = Record[ASTStmtReader::NumExprFields];
  3298. S = ConceptSpecializationExpr::Create(Context, Empty, numTemplateArgs);
  3299. break;
  3300. }
  3301. case EXPR_REQUIRES:
  3302. unsigned numLocalParameters = Record[ASTStmtReader::NumExprFields];
  3303. unsigned numRequirement = Record[ASTStmtReader::NumExprFields + 1];
  3304. S = RequiresExpr::Create(Context, Empty, numLocalParameters,
  3305. numRequirement);
  3306. break;
  3307. }
  3308. // We hit a STMT_STOP, so we're done with this expression.
  3309. if (Finished)
  3310. break;
  3311. ++NumStatementsRead;
  3312. if (S && !IsStmtReference) {
  3313. Reader.Visit(S);
  3314. StmtEntries[Cursor.GetCurrentBitNo()] = S;
  3315. }
  3316. assert(Record.getIdx() == Record.size() &&
  3317. "Invalid deserialization of statement");
  3318. StmtStack.push_back(S);
  3319. }
  3320. Done:
  3321. assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
  3322. assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
  3323. return StmtStack.pop_back_val();
  3324. }