ASTReaderStmt.cpp 109 KB

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