ASTWriterStmt.cpp 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699
  1. //===--- ASTWriterStmt.cpp - Statement and Expression Serialization -------===//
  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. /// \file
  10. /// Implements serialization for Statements and Expressions.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/ExprOpenMP.h"
  14. #include "clang/Serialization/ASTRecordWriter.h"
  15. #include "clang/Sema/DeclSpec.h"
  16. #include "clang/AST/ASTContext.h"
  17. #include "clang/AST/DeclCXX.h"
  18. #include "clang/AST/DeclObjC.h"
  19. #include "clang/AST/DeclTemplate.h"
  20. #include "clang/AST/StmtVisitor.h"
  21. #include "clang/Lex/Token.h"
  22. #include "llvm/Bitstream/BitstreamWriter.h"
  23. using namespace clang;
  24. //===----------------------------------------------------------------------===//
  25. // Statement/expression serialization
  26. //===----------------------------------------------------------------------===//
  27. namespace clang {
  28. class ASTStmtWriter : public StmtVisitor<ASTStmtWriter, void> {
  29. ASTWriter &Writer;
  30. ASTRecordWriter Record;
  31. serialization::StmtCode Code;
  32. unsigned AbbrevToUse;
  33. public:
  34. ASTStmtWriter(ASTWriter &Writer, ASTWriter::RecordData &Record)
  35. : Writer(Writer), Record(Writer, Record),
  36. Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
  37. ASTStmtWriter(const ASTStmtWriter&) = delete;
  38. uint64_t Emit() {
  39. assert(Code != serialization::STMT_NULL_PTR &&
  40. "unhandled sub-statement writing AST file");
  41. return Record.EmitStmt(Code, AbbrevToUse);
  42. }
  43. void AddTemplateKWAndArgsInfo(const ASTTemplateKWAndArgsInfo &ArgInfo,
  44. const TemplateArgumentLoc *Args);
  45. void VisitStmt(Stmt *S);
  46. #define STMT(Type, Base) \
  47. void Visit##Type(Type *);
  48. #include "clang/AST/StmtNodes.inc"
  49. };
  50. }
  51. void ASTStmtWriter::AddTemplateKWAndArgsInfo(
  52. const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) {
  53. Record.AddSourceLocation(ArgInfo.TemplateKWLoc);
  54. Record.AddSourceLocation(ArgInfo.LAngleLoc);
  55. Record.AddSourceLocation(ArgInfo.RAngleLoc);
  56. for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i)
  57. Record.AddTemplateArgumentLoc(Args[i]);
  58. }
  59. void ASTStmtWriter::VisitStmt(Stmt *S) {
  60. }
  61. void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
  62. VisitStmt(S);
  63. Record.AddSourceLocation(S->getSemiLoc());
  64. Record.push_back(S->NullStmtBits.HasLeadingEmptyMacro);
  65. Code = serialization::STMT_NULL;
  66. }
  67. void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
  68. VisitStmt(S);
  69. Record.push_back(S->size());
  70. for (auto *CS : S->body())
  71. Record.AddStmt(CS);
  72. Record.AddSourceLocation(S->getLBracLoc());
  73. Record.AddSourceLocation(S->getRBracLoc());
  74. Code = serialization::STMT_COMPOUND;
  75. }
  76. void ASTStmtWriter::VisitSwitchCase(SwitchCase *S) {
  77. VisitStmt(S);
  78. Record.push_back(Writer.getSwitchCaseID(S));
  79. Record.AddSourceLocation(S->getKeywordLoc());
  80. Record.AddSourceLocation(S->getColonLoc());
  81. }
  82. void ASTStmtWriter::VisitCaseStmt(CaseStmt *S) {
  83. VisitSwitchCase(S);
  84. Record.push_back(S->caseStmtIsGNURange());
  85. Record.AddStmt(S->getLHS());
  86. Record.AddStmt(S->getSubStmt());
  87. if (S->caseStmtIsGNURange()) {
  88. Record.AddStmt(S->getRHS());
  89. Record.AddSourceLocation(S->getEllipsisLoc());
  90. }
  91. Code = serialization::STMT_CASE;
  92. }
  93. void ASTStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
  94. VisitSwitchCase(S);
  95. Record.AddStmt(S->getSubStmt());
  96. Code = serialization::STMT_DEFAULT;
  97. }
  98. void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
  99. VisitStmt(S);
  100. Record.push_back(S->isSideEntry());
  101. Record.AddDeclRef(S->getDecl());
  102. Record.AddStmt(S->getSubStmt());
  103. Record.AddSourceLocation(S->getIdentLoc());
  104. Code = serialization::STMT_LABEL;
  105. }
  106. void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
  107. VisitStmt(S);
  108. Record.push_back(S->getAttrs().size());
  109. Record.AddAttributes(S->getAttrs());
  110. Record.AddStmt(S->getSubStmt());
  111. Record.AddSourceLocation(S->getAttrLoc());
  112. Code = serialization::STMT_ATTRIBUTED;
  113. }
  114. void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
  115. VisitStmt(S);
  116. bool HasElse = S->getElse() != nullptr;
  117. bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
  118. bool HasInit = S->getInit() != nullptr;
  119. Record.push_back(HasElse);
  120. Record.push_back(HasVar);
  121. Record.push_back(HasInit);
  122. Record.push_back(static_cast<uint64_t>(S->getStatementKind()));
  123. Record.AddStmt(S->getCond());
  124. Record.AddStmt(S->getThen());
  125. if (HasElse)
  126. Record.AddStmt(S->getElse());
  127. if (HasVar)
  128. Record.AddDeclRef(S->getConditionVariable());
  129. if (HasInit)
  130. Record.AddStmt(S->getInit());
  131. Record.AddSourceLocation(S->getIfLoc());
  132. Record.AddSourceLocation(S->getLParenLoc());
  133. Record.AddSourceLocation(S->getRParenLoc());
  134. if (HasElse)
  135. Record.AddSourceLocation(S->getElseLoc());
  136. Code = serialization::STMT_IF;
  137. }
  138. void ASTStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
  139. VisitStmt(S);
  140. bool HasInit = S->getInit() != nullptr;
  141. bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
  142. Record.push_back(HasInit);
  143. Record.push_back(HasVar);
  144. Record.push_back(S->isAllEnumCasesCovered());
  145. Record.AddStmt(S->getCond());
  146. Record.AddStmt(S->getBody());
  147. if (HasInit)
  148. Record.AddStmt(S->getInit());
  149. if (HasVar)
  150. Record.AddDeclRef(S->getConditionVariable());
  151. Record.AddSourceLocation(S->getSwitchLoc());
  152. Record.AddSourceLocation(S->getLParenLoc());
  153. Record.AddSourceLocation(S->getRParenLoc());
  154. for (SwitchCase *SC = S->getSwitchCaseList(); SC;
  155. SC = SC->getNextSwitchCase())
  156. Record.push_back(Writer.RecordSwitchCaseID(SC));
  157. Code = serialization::STMT_SWITCH;
  158. }
  159. void ASTStmtWriter::VisitWhileStmt(WhileStmt *S) {
  160. VisitStmt(S);
  161. bool HasVar = S->getConditionVariableDeclStmt() != nullptr;
  162. Record.push_back(HasVar);
  163. Record.AddStmt(S->getCond());
  164. Record.AddStmt(S->getBody());
  165. if (HasVar)
  166. Record.AddDeclRef(S->getConditionVariable());
  167. Record.AddSourceLocation(S->getWhileLoc());
  168. Record.AddSourceLocation(S->getLParenLoc());
  169. Record.AddSourceLocation(S->getRParenLoc());
  170. Code = serialization::STMT_WHILE;
  171. }
  172. void ASTStmtWriter::VisitDoStmt(DoStmt *S) {
  173. VisitStmt(S);
  174. Record.AddStmt(S->getCond());
  175. Record.AddStmt(S->getBody());
  176. Record.AddSourceLocation(S->getDoLoc());
  177. Record.AddSourceLocation(S->getWhileLoc());
  178. Record.AddSourceLocation(S->getRParenLoc());
  179. Code = serialization::STMT_DO;
  180. }
  181. void ASTStmtWriter::VisitForStmt(ForStmt *S) {
  182. VisitStmt(S);
  183. Record.AddStmt(S->getInit());
  184. Record.AddStmt(S->getCond());
  185. Record.AddDeclRef(S->getConditionVariable());
  186. Record.AddStmt(S->getInc());
  187. Record.AddStmt(S->getBody());
  188. Record.AddSourceLocation(S->getForLoc());
  189. Record.AddSourceLocation(S->getLParenLoc());
  190. Record.AddSourceLocation(S->getRParenLoc());
  191. Code = serialization::STMT_FOR;
  192. }
  193. void ASTStmtWriter::VisitGotoStmt(GotoStmt *S) {
  194. VisitStmt(S);
  195. Record.AddDeclRef(S->getLabel());
  196. Record.AddSourceLocation(S->getGotoLoc());
  197. Record.AddSourceLocation(S->getLabelLoc());
  198. Code = serialization::STMT_GOTO;
  199. }
  200. void ASTStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
  201. VisitStmt(S);
  202. Record.AddSourceLocation(S->getGotoLoc());
  203. Record.AddSourceLocation(S->getStarLoc());
  204. Record.AddStmt(S->getTarget());
  205. Code = serialization::STMT_INDIRECT_GOTO;
  206. }
  207. void ASTStmtWriter::VisitContinueStmt(ContinueStmt *S) {
  208. VisitStmt(S);
  209. Record.AddSourceLocation(S->getContinueLoc());
  210. Code = serialization::STMT_CONTINUE;
  211. }
  212. void ASTStmtWriter::VisitBreakStmt(BreakStmt *S) {
  213. VisitStmt(S);
  214. Record.AddSourceLocation(S->getBreakLoc());
  215. Code = serialization::STMT_BREAK;
  216. }
  217. void ASTStmtWriter::VisitReturnStmt(ReturnStmt *S) {
  218. VisitStmt(S);
  219. bool HasNRVOCandidate = S->getNRVOCandidate() != nullptr;
  220. Record.push_back(HasNRVOCandidate);
  221. Record.AddStmt(S->getRetValue());
  222. if (HasNRVOCandidate)
  223. Record.AddDeclRef(S->getNRVOCandidate());
  224. Record.AddSourceLocation(S->getReturnLoc());
  225. Code = serialization::STMT_RETURN;
  226. }
  227. void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
  228. VisitStmt(S);
  229. Record.AddSourceLocation(S->getBeginLoc());
  230. Record.AddSourceLocation(S->getEndLoc());
  231. DeclGroupRef DG = S->getDeclGroup();
  232. for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
  233. Record.AddDeclRef(*D);
  234. Code = serialization::STMT_DECL;
  235. }
  236. void ASTStmtWriter::VisitAsmStmt(AsmStmt *S) {
  237. VisitStmt(S);
  238. Record.push_back(S->getNumOutputs());
  239. Record.push_back(S->getNumInputs());
  240. Record.push_back(S->getNumClobbers());
  241. Record.AddSourceLocation(S->getAsmLoc());
  242. Record.push_back(S->isVolatile());
  243. Record.push_back(S->isSimple());
  244. }
  245. void ASTStmtWriter::VisitGCCAsmStmt(GCCAsmStmt *S) {
  246. VisitAsmStmt(S);
  247. Record.push_back(S->getNumLabels());
  248. Record.AddSourceLocation(S->getRParenLoc());
  249. Record.AddStmt(S->getAsmString());
  250. // Outputs
  251. for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
  252. Record.AddIdentifierRef(S->getOutputIdentifier(I));
  253. Record.AddStmt(S->getOutputConstraintLiteral(I));
  254. Record.AddStmt(S->getOutputExpr(I));
  255. }
  256. // Inputs
  257. for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
  258. Record.AddIdentifierRef(S->getInputIdentifier(I));
  259. Record.AddStmt(S->getInputConstraintLiteral(I));
  260. Record.AddStmt(S->getInputExpr(I));
  261. }
  262. // Clobbers
  263. for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
  264. Record.AddStmt(S->getClobberStringLiteral(I));
  265. // Labels
  266. for (auto *E : S->labels()) Record.AddStmt(E);
  267. Code = serialization::STMT_GCCASM;
  268. }
  269. void ASTStmtWriter::VisitMSAsmStmt(MSAsmStmt *S) {
  270. VisitAsmStmt(S);
  271. Record.AddSourceLocation(S->getLBraceLoc());
  272. Record.AddSourceLocation(S->getEndLoc());
  273. Record.push_back(S->getNumAsmToks());
  274. Record.AddString(S->getAsmString());
  275. // Tokens
  276. for (unsigned I = 0, N = S->getNumAsmToks(); I != N; ++I) {
  277. // FIXME: Move this to ASTRecordWriter?
  278. Writer.AddToken(S->getAsmToks()[I], Record.getRecordData());
  279. }
  280. // Clobbers
  281. for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) {
  282. Record.AddString(S->getClobber(I));
  283. }
  284. // Outputs
  285. for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
  286. Record.AddStmt(S->getOutputExpr(I));
  287. Record.AddString(S->getOutputConstraint(I));
  288. }
  289. // Inputs
  290. for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
  291. Record.AddStmt(S->getInputExpr(I));
  292. Record.AddString(S->getInputConstraint(I));
  293. }
  294. Code = serialization::STMT_MSASM;
  295. }
  296. void ASTStmtWriter::VisitCoroutineBodyStmt(CoroutineBodyStmt *CoroStmt) {
  297. VisitStmt(CoroStmt);
  298. Record.push_back(CoroStmt->getParamMoves().size());
  299. for (Stmt *S : CoroStmt->children())
  300. Record.AddStmt(S);
  301. Code = serialization::STMT_COROUTINE_BODY;
  302. }
  303. void ASTStmtWriter::VisitCoreturnStmt(CoreturnStmt *S) {
  304. VisitStmt(S);
  305. Record.AddSourceLocation(S->getKeywordLoc());
  306. Record.AddStmt(S->getOperand());
  307. Record.AddStmt(S->getPromiseCall());
  308. Record.push_back(S->isImplicit());
  309. Code = serialization::STMT_CORETURN;
  310. }
  311. void ASTStmtWriter::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) {
  312. VisitExpr(E);
  313. Record.AddSourceLocation(E->getKeywordLoc());
  314. for (Stmt *S : E->children())
  315. Record.AddStmt(S);
  316. Record.AddStmt(E->getOpaqueValue());
  317. }
  318. void ASTStmtWriter::VisitCoawaitExpr(CoawaitExpr *E) {
  319. VisitCoroutineSuspendExpr(E);
  320. Record.push_back(E->isImplicit());
  321. Code = serialization::EXPR_COAWAIT;
  322. }
  323. void ASTStmtWriter::VisitCoyieldExpr(CoyieldExpr *E) {
  324. VisitCoroutineSuspendExpr(E);
  325. Code = serialization::EXPR_COYIELD;
  326. }
  327. void ASTStmtWriter::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
  328. VisitExpr(E);
  329. Record.AddSourceLocation(E->getKeywordLoc());
  330. for (Stmt *S : E->children())
  331. Record.AddStmt(S);
  332. Code = serialization::EXPR_DEPENDENT_COAWAIT;
  333. }
  334. static void
  335. addConstraintSatisfaction(ASTRecordWriter &Record,
  336. const ASTConstraintSatisfaction &Satisfaction) {
  337. Record.push_back(Satisfaction.IsSatisfied);
  338. if (!Satisfaction.IsSatisfied) {
  339. Record.push_back(Satisfaction.NumRecords);
  340. for (const auto &DetailRecord : Satisfaction) {
  341. Record.AddStmt(const_cast<Expr *>(DetailRecord.first));
  342. auto *E = DetailRecord.second.dyn_cast<Expr *>();
  343. Record.push_back(E == nullptr);
  344. if (E)
  345. Record.AddStmt(E);
  346. else {
  347. auto *Diag = DetailRecord.second.get<std::pair<SourceLocation,
  348. StringRef> *>();
  349. Record.AddSourceLocation(Diag->first);
  350. Record.AddString(Diag->second);
  351. }
  352. }
  353. }
  354. }
  355. static void
  356. addSubstitutionDiagnostic(
  357. ASTRecordWriter &Record,
  358. const concepts::Requirement::SubstitutionDiagnostic *D) {
  359. Record.AddString(D->SubstitutedEntity);
  360. Record.AddSourceLocation(D->DiagLoc);
  361. Record.AddString(D->DiagMessage);
  362. }
  363. void ASTStmtWriter::VisitConceptSpecializationExpr(
  364. ConceptSpecializationExpr *E) {
  365. VisitExpr(E);
  366. ArrayRef<TemplateArgument> TemplateArgs = E->getTemplateArguments();
  367. Record.push_back(TemplateArgs.size());
  368. Record.AddNestedNameSpecifierLoc(E->getNestedNameSpecifierLoc());
  369. Record.AddSourceLocation(E->getTemplateKWLoc());
  370. Record.AddDeclarationNameInfo(E->getConceptNameInfo());
  371. Record.AddDeclRef(E->getNamedConcept());
  372. Record.AddDeclRef(E->getFoundDecl());
  373. Record.AddASTTemplateArgumentListInfo(E->getTemplateArgsAsWritten());
  374. for (const TemplateArgument &Arg : TemplateArgs)
  375. Record.AddTemplateArgument(Arg);
  376. if (!E->isValueDependent())
  377. addConstraintSatisfaction(Record, E->getSatisfaction());
  378. Code = serialization::EXPR_CONCEPT_SPECIALIZATION;
  379. }
  380. void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) {
  381. VisitExpr(E);
  382. Record.push_back(E->getLocalParameters().size());
  383. Record.push_back(E->getRequirements().size());
  384. Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc);
  385. Record.push_back(E->RequiresExprBits.IsSatisfied);
  386. Record.AddDeclRef(E->getBody());
  387. for (ParmVarDecl *P : E->getLocalParameters())
  388. Record.AddDeclRef(P);
  389. for (concepts::Requirement *R : E->getRequirements()) {
  390. if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(R)) {
  391. Record.push_back(concepts::Requirement::RK_Type);
  392. Record.push_back(TypeReq->Status);
  393. if (TypeReq->Status == concepts::TypeRequirement::SS_SubstitutionFailure)
  394. addSubstitutionDiagnostic(Record, TypeReq->getSubstitutionDiagnostic());
  395. else
  396. Record.AddTypeSourceInfo(TypeReq->getType());
  397. } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(R)) {
  398. Record.push_back(ExprReq->getKind());
  399. Record.push_back(ExprReq->Status);
  400. if (ExprReq->isExprSubstitutionFailure()) {
  401. addSubstitutionDiagnostic(Record,
  402. ExprReq->Value.get<concepts::Requirement::SubstitutionDiagnostic *>());
  403. } else
  404. Record.AddStmt(ExprReq->Value.get<Expr *>());
  405. if (ExprReq->getKind() == concepts::Requirement::RK_Compound) {
  406. Record.AddSourceLocation(ExprReq->NoexceptLoc);
  407. const auto &RetReq = ExprReq->getReturnTypeRequirement();
  408. if (RetReq.isSubstitutionFailure()) {
  409. Record.push_back(2);
  410. addSubstitutionDiagnostic(Record, RetReq.getSubstitutionDiagnostic());
  411. } else if (RetReq.isTypeConstraint()) {
  412. Record.push_back(1);
  413. Record.AddTemplateParameterList(
  414. RetReq.getTypeConstraintTemplateParameterList());
  415. if (ExprReq->Status >=
  416. concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
  417. Record.AddStmt(
  418. ExprReq->getReturnTypeRequirementSubstitutedConstraintExpr());
  419. } else {
  420. assert(RetReq.isEmpty());
  421. Record.push_back(0);
  422. }
  423. }
  424. } else {
  425. auto *NestedReq = cast<concepts::NestedRequirement>(R);
  426. Record.push_back(concepts::Requirement::RK_Nested);
  427. Record.push_back(NestedReq->isSubstitutionFailure());
  428. if (NestedReq->isSubstitutionFailure()){
  429. addSubstitutionDiagnostic(Record,
  430. NestedReq->getSubstitutionDiagnostic());
  431. } else {
  432. Record.AddStmt(NestedReq->Value.get<Expr *>());
  433. if (!NestedReq->isDependent())
  434. addConstraintSatisfaction(Record, *NestedReq->Satisfaction);
  435. }
  436. }
  437. }
  438. Record.AddSourceLocation(E->getEndLoc());
  439. Code = serialization::EXPR_REQUIRES;
  440. }
  441. void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
  442. VisitStmt(S);
  443. // NumCaptures
  444. Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
  445. // CapturedDecl and captured region kind
  446. Record.AddDeclRef(S->getCapturedDecl());
  447. Record.push_back(S->getCapturedRegionKind());
  448. Record.AddDeclRef(S->getCapturedRecordDecl());
  449. // Capture inits
  450. for (auto *I : S->capture_inits())
  451. Record.AddStmt(I);
  452. // Body
  453. Record.AddStmt(S->getCapturedStmt());
  454. // Captures
  455. for (const auto &I : S->captures()) {
  456. if (I.capturesThis() || I.capturesVariableArrayType())
  457. Record.AddDeclRef(nullptr);
  458. else
  459. Record.AddDeclRef(I.getCapturedVar());
  460. Record.push_back(I.getCaptureKind());
  461. Record.AddSourceLocation(I.getLocation());
  462. }
  463. Code = serialization::STMT_CAPTURED;
  464. }
  465. void ASTStmtWriter::VisitExpr(Expr *E) {
  466. VisitStmt(E);
  467. Record.AddTypeRef(E->getType());
  468. Record.push_back(E->isTypeDependent());
  469. Record.push_back(E->isValueDependent());
  470. Record.push_back(E->isInstantiationDependent());
  471. Record.push_back(E->containsUnexpandedParameterPack());
  472. Record.push_back(E->containsErrors());
  473. Record.push_back(E->getValueKind());
  474. Record.push_back(E->getObjectKind());
  475. }
  476. void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
  477. VisitExpr(E);
  478. Record.push_back(E->ConstantExprBits.ResultKind);
  479. Record.push_back(E->ConstantExprBits.APValueKind);
  480. Record.push_back(E->ConstantExprBits.IsUnsigned);
  481. Record.push_back(E->ConstantExprBits.BitWidth);
  482. // HasCleanup not serialized since we can just query the APValue.
  483. Record.push_back(E->ConstantExprBits.IsImmediateInvocation);
  484. switch (E->ConstantExprBits.ResultKind) {
  485. case ConstantExpr::RSK_None:
  486. break;
  487. case ConstantExpr::RSK_Int64:
  488. Record.push_back(E->Int64Result());
  489. break;
  490. case ConstantExpr::RSK_APValue:
  491. Record.AddAPValue(E->APValueResult());
  492. break;
  493. default:
  494. llvm_unreachable("unexpected ResultKind!");
  495. }
  496. Record.AddStmt(E->getSubExpr());
  497. Code = serialization::EXPR_CONSTANT;
  498. }
  499. void ASTStmtWriter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
  500. VisitExpr(E);
  501. Record.AddSourceLocation(E->getLocation());
  502. Record.AddSourceLocation(E->getLParenLocation());
  503. Record.AddSourceLocation(E->getRParenLocation());
  504. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  505. Code = serialization::EXPR_SYCL_UNIQUE_STABLE_NAME;
  506. }
  507. void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
  508. VisitExpr(E);
  509. bool HasFunctionName = E->getFunctionName() != nullptr;
  510. Record.push_back(HasFunctionName);
  511. Record.push_back(E->getIdentKind()); // FIXME: stable encoding
  512. Record.AddSourceLocation(E->getLocation());
  513. if (HasFunctionName)
  514. Record.AddStmt(E->getFunctionName());
  515. Code = serialization::EXPR_PREDEFINED;
  516. }
  517. void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
  518. VisitExpr(E);
  519. Record.push_back(E->hasQualifier());
  520. Record.push_back(E->getDecl() != E->getFoundDecl());
  521. Record.push_back(E->hasTemplateKWAndArgsInfo());
  522. Record.push_back(E->hadMultipleCandidates());
  523. Record.push_back(E->refersToEnclosingVariableOrCapture());
  524. Record.push_back(E->isNonOdrUse());
  525. if (E->hasTemplateKWAndArgsInfo()) {
  526. unsigned NumTemplateArgs = E->getNumTemplateArgs();
  527. Record.push_back(NumTemplateArgs);
  528. }
  529. DeclarationName::NameKind nk = (E->getDecl()->getDeclName().getNameKind());
  530. if ((!E->hasTemplateKWAndArgsInfo()) && (!E->hasQualifier()) &&
  531. (E->getDecl() == E->getFoundDecl()) &&
  532. nk == DeclarationName::Identifier &&
  533. !E->refersToEnclosingVariableOrCapture() && !E->isNonOdrUse()) {
  534. AbbrevToUse = Writer.getDeclRefExprAbbrev();
  535. }
  536. if (E->hasQualifier())
  537. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  538. if (E->getDecl() != E->getFoundDecl())
  539. Record.AddDeclRef(E->getFoundDecl());
  540. if (E->hasTemplateKWAndArgsInfo())
  541. AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
  542. E->getTrailingObjects<TemplateArgumentLoc>());
  543. Record.AddDeclRef(E->getDecl());
  544. Record.AddSourceLocation(E->getLocation());
  545. Record.AddDeclarationNameLoc(E->DNLoc, E->getDecl()->getDeclName());
  546. Code = serialization::EXPR_DECL_REF;
  547. }
  548. void ASTStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
  549. VisitExpr(E);
  550. Record.AddSourceLocation(E->getLocation());
  551. Record.AddAPInt(E->getValue());
  552. if (E->getValue().getBitWidth() == 32) {
  553. AbbrevToUse = Writer.getIntegerLiteralAbbrev();
  554. }
  555. Code = serialization::EXPR_INTEGER_LITERAL;
  556. }
  557. void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
  558. VisitExpr(E);
  559. Record.AddSourceLocation(E->getLocation());
  560. Record.push_back(E->getScale());
  561. Record.AddAPInt(E->getValue());
  562. Code = serialization::EXPR_FIXEDPOINT_LITERAL;
  563. }
  564. void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
  565. VisitExpr(E);
  566. Record.push_back(E->getRawSemantics());
  567. Record.push_back(E->isExact());
  568. Record.AddAPFloat(E->getValue());
  569. Record.AddSourceLocation(E->getLocation());
  570. Code = serialization::EXPR_FLOATING_LITERAL;
  571. }
  572. void ASTStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
  573. VisitExpr(E);
  574. Record.AddStmt(E->getSubExpr());
  575. Code = serialization::EXPR_IMAGINARY_LITERAL;
  576. }
  577. void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) {
  578. VisitExpr(E);
  579. // Store the various bits of data of StringLiteral.
  580. Record.push_back(E->getNumConcatenated());
  581. Record.push_back(E->getLength());
  582. Record.push_back(E->getCharByteWidth());
  583. Record.push_back(E->getKind());
  584. Record.push_back(E->isPascal());
  585. // Store the trailing array of SourceLocation.
  586. for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
  587. Record.AddSourceLocation(E->getStrTokenLoc(I));
  588. // Store the trailing array of char holding the string data.
  589. StringRef StrData = E->getBytes();
  590. for (unsigned I = 0, N = E->getByteLength(); I != N; ++I)
  591. Record.push_back(StrData[I]);
  592. Code = serialization::EXPR_STRING_LITERAL;
  593. }
  594. void ASTStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
  595. VisitExpr(E);
  596. Record.push_back(E->getValue());
  597. Record.AddSourceLocation(E->getLocation());
  598. Record.push_back(E->getKind());
  599. AbbrevToUse = Writer.getCharacterLiteralAbbrev();
  600. Code = serialization::EXPR_CHARACTER_LITERAL;
  601. }
  602. void ASTStmtWriter::VisitParenExpr(ParenExpr *E) {
  603. VisitExpr(E);
  604. Record.AddSourceLocation(E->getLParen());
  605. Record.AddSourceLocation(E->getRParen());
  606. Record.AddStmt(E->getSubExpr());
  607. Code = serialization::EXPR_PAREN;
  608. }
  609. void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
  610. VisitExpr(E);
  611. Record.push_back(E->getNumExprs());
  612. for (auto *SubStmt : E->exprs())
  613. Record.AddStmt(SubStmt);
  614. Record.AddSourceLocation(E->getLParenLoc());
  615. Record.AddSourceLocation(E->getRParenLoc());
  616. Code = serialization::EXPR_PAREN_LIST;
  617. }
  618. void ASTStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
  619. VisitExpr(E);
  620. bool HasFPFeatures = E->hasStoredFPFeatures();
  621. // Write this first for easy access when deserializing, as they affect the
  622. // size of the UnaryOperator.
  623. Record.push_back(HasFPFeatures);
  624. Record.AddStmt(E->getSubExpr());
  625. Record.push_back(E->getOpcode()); // FIXME: stable encoding
  626. Record.AddSourceLocation(E->getOperatorLoc());
  627. Record.push_back(E->canOverflow());
  628. if (HasFPFeatures)
  629. Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
  630. Code = serialization::EXPR_UNARY_OPERATOR;
  631. }
  632. void ASTStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
  633. VisitExpr(E);
  634. Record.push_back(E->getNumComponents());
  635. Record.push_back(E->getNumExpressions());
  636. Record.AddSourceLocation(E->getOperatorLoc());
  637. Record.AddSourceLocation(E->getRParenLoc());
  638. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  639. for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
  640. const OffsetOfNode &ON = E->getComponent(I);
  641. Record.push_back(ON.getKind()); // FIXME: Stable encoding
  642. Record.AddSourceLocation(ON.getSourceRange().getBegin());
  643. Record.AddSourceLocation(ON.getSourceRange().getEnd());
  644. switch (ON.getKind()) {
  645. case OffsetOfNode::Array:
  646. Record.push_back(ON.getArrayExprIndex());
  647. break;
  648. case OffsetOfNode::Field:
  649. Record.AddDeclRef(ON.getField());
  650. break;
  651. case OffsetOfNode::Identifier:
  652. Record.AddIdentifierRef(ON.getFieldName());
  653. break;
  654. case OffsetOfNode::Base:
  655. Record.AddCXXBaseSpecifier(*ON.getBase());
  656. break;
  657. }
  658. }
  659. for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
  660. Record.AddStmt(E->getIndexExpr(I));
  661. Code = serialization::EXPR_OFFSETOF;
  662. }
  663. void ASTStmtWriter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
  664. VisitExpr(E);
  665. Record.push_back(E->getKind());
  666. if (E->isArgumentType())
  667. Record.AddTypeSourceInfo(E->getArgumentTypeInfo());
  668. else {
  669. Record.push_back(0);
  670. Record.AddStmt(E->getArgumentExpr());
  671. }
  672. Record.AddSourceLocation(E->getOperatorLoc());
  673. Record.AddSourceLocation(E->getRParenLoc());
  674. Code = serialization::EXPR_SIZEOF_ALIGN_OF;
  675. }
  676. void ASTStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
  677. VisitExpr(E);
  678. Record.AddStmt(E->getLHS());
  679. Record.AddStmt(E->getRHS());
  680. Record.AddSourceLocation(E->getRBracketLoc());
  681. Code = serialization::EXPR_ARRAY_SUBSCRIPT;
  682. }
  683. void ASTStmtWriter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
  684. VisitExpr(E);
  685. Record.AddStmt(E->getBase());
  686. Record.AddStmt(E->getRowIdx());
  687. Record.AddStmt(E->getColumnIdx());
  688. Record.AddSourceLocation(E->getRBracketLoc());
  689. Code = serialization::EXPR_ARRAY_SUBSCRIPT;
  690. }
  691. void ASTStmtWriter::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
  692. VisitExpr(E);
  693. Record.AddStmt(E->getBase());
  694. Record.AddStmt(E->getLowerBound());
  695. Record.AddStmt(E->getLength());
  696. Record.AddStmt(E->getStride());
  697. Record.AddSourceLocation(E->getColonLocFirst());
  698. Record.AddSourceLocation(E->getColonLocSecond());
  699. Record.AddSourceLocation(E->getRBracketLoc());
  700. Code = serialization::EXPR_OMP_ARRAY_SECTION;
  701. }
  702. void ASTStmtWriter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
  703. VisitExpr(E);
  704. Record.push_back(E->getDimensions().size());
  705. Record.AddStmt(E->getBase());
  706. for (Expr *Dim : E->getDimensions())
  707. Record.AddStmt(Dim);
  708. for (SourceRange SR : E->getBracketsRanges())
  709. Record.AddSourceRange(SR);
  710. Record.AddSourceLocation(E->getLParenLoc());
  711. Record.AddSourceLocation(E->getRParenLoc());
  712. Code = serialization::EXPR_OMP_ARRAY_SHAPING;
  713. }
  714. void ASTStmtWriter::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
  715. VisitExpr(E);
  716. Record.push_back(E->numOfIterators());
  717. Record.AddSourceLocation(E->getIteratorKwLoc());
  718. Record.AddSourceLocation(E->getLParenLoc());
  719. Record.AddSourceLocation(E->getRParenLoc());
  720. for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
  721. Record.AddDeclRef(E->getIteratorDecl(I));
  722. Record.AddSourceLocation(E->getAssignLoc(I));
  723. OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
  724. Record.AddStmt(Range.Begin);
  725. Record.AddStmt(Range.End);
  726. Record.AddStmt(Range.Step);
  727. Record.AddSourceLocation(E->getColonLoc(I));
  728. if (Range.Step)
  729. Record.AddSourceLocation(E->getSecondColonLoc(I));
  730. // Serialize helpers
  731. OMPIteratorHelperData &HD = E->getHelper(I);
  732. Record.AddDeclRef(HD.CounterVD);
  733. Record.AddStmt(HD.Upper);
  734. Record.AddStmt(HD.Update);
  735. Record.AddStmt(HD.CounterUpdate);
  736. }
  737. Code = serialization::EXPR_OMP_ITERATOR;
  738. }
  739. void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
  740. VisitExpr(E);
  741. Record.push_back(E->getNumArgs());
  742. Record.push_back(E->hasStoredFPFeatures());
  743. Record.AddSourceLocation(E->getRParenLoc());
  744. Record.AddStmt(E->getCallee());
  745. for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
  746. Arg != ArgEnd; ++Arg)
  747. Record.AddStmt(*Arg);
  748. Record.push_back(static_cast<unsigned>(E->getADLCallKind()));
  749. if (E->hasStoredFPFeatures())
  750. Record.push_back(E->getFPFeatures().getAsOpaqueInt());
  751. Code = serialization::EXPR_CALL;
  752. }
  753. void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr *E) {
  754. VisitExpr(E);
  755. Record.push_back(std::distance(E->children().begin(), E->children().end()));
  756. Record.AddSourceLocation(E->getBeginLoc());
  757. Record.AddSourceLocation(E->getEndLoc());
  758. for (Stmt *Child : E->children())
  759. Record.AddStmt(Child);
  760. Code = serialization::EXPR_RECOVERY;
  761. }
  762. void ASTStmtWriter::VisitMemberExpr(MemberExpr *E) {
  763. VisitExpr(E);
  764. bool HasQualifier = E->hasQualifier();
  765. bool HasFoundDecl =
  766. E->hasQualifierOrFoundDecl() &&
  767. (E->getFoundDecl().getDecl() != E->getMemberDecl() ||
  768. E->getFoundDecl().getAccess() != E->getMemberDecl()->getAccess());
  769. bool HasTemplateInfo = E->hasTemplateKWAndArgsInfo();
  770. unsigned NumTemplateArgs = E->getNumTemplateArgs();
  771. // Write these first for easy access when deserializing, as they affect the
  772. // size of the MemberExpr.
  773. Record.push_back(HasQualifier);
  774. Record.push_back(HasFoundDecl);
  775. Record.push_back(HasTemplateInfo);
  776. Record.push_back(NumTemplateArgs);
  777. Record.AddStmt(E->getBase());
  778. Record.AddDeclRef(E->getMemberDecl());
  779. Record.AddDeclarationNameLoc(E->MemberDNLoc,
  780. E->getMemberDecl()->getDeclName());
  781. Record.AddSourceLocation(E->getMemberLoc());
  782. Record.push_back(E->isArrow());
  783. Record.push_back(E->hadMultipleCandidates());
  784. Record.push_back(E->isNonOdrUse());
  785. Record.AddSourceLocation(E->getOperatorLoc());
  786. if (HasFoundDecl) {
  787. DeclAccessPair FoundDecl = E->getFoundDecl();
  788. Record.AddDeclRef(FoundDecl.getDecl());
  789. Record.push_back(FoundDecl.getAccess());
  790. }
  791. if (HasQualifier)
  792. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  793. if (HasTemplateInfo)
  794. AddTemplateKWAndArgsInfo(*E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
  795. E->getTrailingObjects<TemplateArgumentLoc>());
  796. Code = serialization::EXPR_MEMBER;
  797. }
  798. void ASTStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
  799. VisitExpr(E);
  800. Record.AddStmt(E->getBase());
  801. Record.AddSourceLocation(E->getIsaMemberLoc());
  802. Record.AddSourceLocation(E->getOpLoc());
  803. Record.push_back(E->isArrow());
  804. Code = serialization::EXPR_OBJC_ISA;
  805. }
  806. void ASTStmtWriter::
  807. VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
  808. VisitExpr(E);
  809. Record.AddStmt(E->getSubExpr());
  810. Record.push_back(E->shouldCopy());
  811. Code = serialization::EXPR_OBJC_INDIRECT_COPY_RESTORE;
  812. }
  813. void ASTStmtWriter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
  814. VisitExplicitCastExpr(E);
  815. Record.AddSourceLocation(E->getLParenLoc());
  816. Record.AddSourceLocation(E->getBridgeKeywordLoc());
  817. Record.push_back(E->getBridgeKind()); // FIXME: Stable encoding
  818. Code = serialization::EXPR_OBJC_BRIDGED_CAST;
  819. }
  820. void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
  821. VisitExpr(E);
  822. Record.push_back(E->path_size());
  823. Record.push_back(E->hasStoredFPFeatures());
  824. Record.AddStmt(E->getSubExpr());
  825. Record.push_back(E->getCastKind()); // FIXME: stable encoding
  826. for (CastExpr::path_iterator
  827. PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
  828. Record.AddCXXBaseSpecifier(**PI);
  829. if (E->hasStoredFPFeatures())
  830. Record.push_back(E->getFPFeatures().getAsOpaqueInt());
  831. }
  832. void ASTStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
  833. VisitExpr(E);
  834. bool HasFPFeatures = E->hasStoredFPFeatures();
  835. // Write this first for easy access when deserializing, as they affect the
  836. // size of the UnaryOperator.
  837. Record.push_back(HasFPFeatures);
  838. Record.push_back(E->getOpcode()); // FIXME: stable encoding
  839. Record.AddStmt(E->getLHS());
  840. Record.AddStmt(E->getRHS());
  841. Record.AddSourceLocation(E->getOperatorLoc());
  842. if (HasFPFeatures)
  843. Record.push_back(E->getStoredFPFeatures().getAsOpaqueInt());
  844. Code = serialization::EXPR_BINARY_OPERATOR;
  845. }
  846. void ASTStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
  847. VisitBinaryOperator(E);
  848. Record.AddTypeRef(E->getComputationLHSType());
  849. Record.AddTypeRef(E->getComputationResultType());
  850. Code = serialization::EXPR_COMPOUND_ASSIGN_OPERATOR;
  851. }
  852. void ASTStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
  853. VisitExpr(E);
  854. Record.AddStmt(E->getCond());
  855. Record.AddStmt(E->getLHS());
  856. Record.AddStmt(E->getRHS());
  857. Record.AddSourceLocation(E->getQuestionLoc());
  858. Record.AddSourceLocation(E->getColonLoc());
  859. Code = serialization::EXPR_CONDITIONAL_OPERATOR;
  860. }
  861. void
  862. ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
  863. VisitExpr(E);
  864. Record.AddStmt(E->getOpaqueValue());
  865. Record.AddStmt(E->getCommon());
  866. Record.AddStmt(E->getCond());
  867. Record.AddStmt(E->getTrueExpr());
  868. Record.AddStmt(E->getFalseExpr());
  869. Record.AddSourceLocation(E->getQuestionLoc());
  870. Record.AddSourceLocation(E->getColonLoc());
  871. Code = serialization::EXPR_BINARY_CONDITIONAL_OPERATOR;
  872. }
  873. void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
  874. VisitCastExpr(E);
  875. Record.push_back(E->isPartOfExplicitCast());
  876. if (E->path_size() == 0 && !E->hasStoredFPFeatures())
  877. AbbrevToUse = Writer.getExprImplicitCastAbbrev();
  878. Code = serialization::EXPR_IMPLICIT_CAST;
  879. }
  880. void ASTStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
  881. VisitCastExpr(E);
  882. Record.AddTypeSourceInfo(E->getTypeInfoAsWritten());
  883. }
  884. void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
  885. VisitExplicitCastExpr(E);
  886. Record.AddSourceLocation(E->getLParenLoc());
  887. Record.AddSourceLocation(E->getRParenLoc());
  888. Code = serialization::EXPR_CSTYLE_CAST;
  889. }
  890. void ASTStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
  891. VisitExpr(E);
  892. Record.AddSourceLocation(E->getLParenLoc());
  893. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  894. Record.AddStmt(E->getInitializer());
  895. Record.push_back(E->isFileScope());
  896. Code = serialization::EXPR_COMPOUND_LITERAL;
  897. }
  898. void ASTStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
  899. VisitExpr(E);
  900. Record.AddStmt(E->getBase());
  901. Record.AddIdentifierRef(&E->getAccessor());
  902. Record.AddSourceLocation(E->getAccessorLoc());
  903. Code = serialization::EXPR_EXT_VECTOR_ELEMENT;
  904. }
  905. void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
  906. VisitExpr(E);
  907. // NOTE: only add the (possibly null) syntactic form.
  908. // No need to serialize the isSemanticForm flag and the semantic form.
  909. Record.AddStmt(E->getSyntacticForm());
  910. Record.AddSourceLocation(E->getLBraceLoc());
  911. Record.AddSourceLocation(E->getRBraceLoc());
  912. bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
  913. Record.push_back(isArrayFiller);
  914. if (isArrayFiller)
  915. Record.AddStmt(E->getArrayFiller());
  916. else
  917. Record.AddDeclRef(E->getInitializedFieldInUnion());
  918. Record.push_back(E->hadArrayRangeDesignator());
  919. Record.push_back(E->getNumInits());
  920. if (isArrayFiller) {
  921. // ArrayFiller may have filled "holes" due to designated initializer.
  922. // Replace them by 0 to indicate that the filler goes in that place.
  923. Expr *filler = E->getArrayFiller();
  924. for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
  925. Record.AddStmt(E->getInit(I) != filler ? E->getInit(I) : nullptr);
  926. } else {
  927. for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
  928. Record.AddStmt(E->getInit(I));
  929. }
  930. Code = serialization::EXPR_INIT_LIST;
  931. }
  932. void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
  933. VisitExpr(E);
  934. Record.push_back(E->getNumSubExprs());
  935. for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
  936. Record.AddStmt(E->getSubExpr(I));
  937. Record.AddSourceLocation(E->getEqualOrColonLoc());
  938. Record.push_back(E->usesGNUSyntax());
  939. for (const DesignatedInitExpr::Designator &D : E->designators()) {
  940. if (D.isFieldDesignator()) {
  941. if (FieldDecl *Field = D.getField()) {
  942. Record.push_back(serialization::DESIG_FIELD_DECL);
  943. Record.AddDeclRef(Field);
  944. } else {
  945. Record.push_back(serialization::DESIG_FIELD_NAME);
  946. Record.AddIdentifierRef(D.getFieldName());
  947. }
  948. Record.AddSourceLocation(D.getDotLoc());
  949. Record.AddSourceLocation(D.getFieldLoc());
  950. } else if (D.isArrayDesignator()) {
  951. Record.push_back(serialization::DESIG_ARRAY);
  952. Record.push_back(D.getFirstExprIndex());
  953. Record.AddSourceLocation(D.getLBracketLoc());
  954. Record.AddSourceLocation(D.getRBracketLoc());
  955. } else {
  956. assert(D.isArrayRangeDesignator() && "Unknown designator");
  957. Record.push_back(serialization::DESIG_ARRAY_RANGE);
  958. Record.push_back(D.getFirstExprIndex());
  959. Record.AddSourceLocation(D.getLBracketLoc());
  960. Record.AddSourceLocation(D.getEllipsisLoc());
  961. Record.AddSourceLocation(D.getRBracketLoc());
  962. }
  963. }
  964. Code = serialization::EXPR_DESIGNATED_INIT;
  965. }
  966. void ASTStmtWriter::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
  967. VisitExpr(E);
  968. Record.AddStmt(E->getBase());
  969. Record.AddStmt(E->getUpdater());
  970. Code = serialization::EXPR_DESIGNATED_INIT_UPDATE;
  971. }
  972. void ASTStmtWriter::VisitNoInitExpr(NoInitExpr *E) {
  973. VisitExpr(E);
  974. Code = serialization::EXPR_NO_INIT;
  975. }
  976. void ASTStmtWriter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
  977. VisitExpr(E);
  978. Record.AddStmt(E->SubExprs[0]);
  979. Record.AddStmt(E->SubExprs[1]);
  980. Code = serialization::EXPR_ARRAY_INIT_LOOP;
  981. }
  982. void ASTStmtWriter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
  983. VisitExpr(E);
  984. Code = serialization::EXPR_ARRAY_INIT_INDEX;
  985. }
  986. void ASTStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
  987. VisitExpr(E);
  988. Code = serialization::EXPR_IMPLICIT_VALUE_INIT;
  989. }
  990. void ASTStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
  991. VisitExpr(E);
  992. Record.AddStmt(E->getSubExpr());
  993. Record.AddTypeSourceInfo(E->getWrittenTypeInfo());
  994. Record.AddSourceLocation(E->getBuiltinLoc());
  995. Record.AddSourceLocation(E->getRParenLoc());
  996. Record.push_back(E->isMicrosoftABI());
  997. Code = serialization::EXPR_VA_ARG;
  998. }
  999. void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
  1000. VisitExpr(E);
  1001. Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
  1002. Record.AddSourceLocation(E->getBeginLoc());
  1003. Record.AddSourceLocation(E->getEndLoc());
  1004. Record.push_back(E->getIdentKind());
  1005. Code = serialization::EXPR_SOURCE_LOC;
  1006. }
  1007. void ASTStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
  1008. VisitExpr(E);
  1009. Record.AddSourceLocation(E->getAmpAmpLoc());
  1010. Record.AddSourceLocation(E->getLabelLoc());
  1011. Record.AddDeclRef(E->getLabel());
  1012. Code = serialization::EXPR_ADDR_LABEL;
  1013. }
  1014. void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) {
  1015. VisitExpr(E);
  1016. Record.AddStmt(E->getSubStmt());
  1017. Record.AddSourceLocation(E->getLParenLoc());
  1018. Record.AddSourceLocation(E->getRParenLoc());
  1019. Record.push_back(E->getTemplateDepth());
  1020. Code = serialization::EXPR_STMT;
  1021. }
  1022. void ASTStmtWriter::VisitChooseExpr(ChooseExpr *E) {
  1023. VisitExpr(E);
  1024. Record.AddStmt(E->getCond());
  1025. Record.AddStmt(E->getLHS());
  1026. Record.AddStmt(E->getRHS());
  1027. Record.AddSourceLocation(E->getBuiltinLoc());
  1028. Record.AddSourceLocation(E->getRParenLoc());
  1029. Record.push_back(E->isConditionDependent() ? false : E->isConditionTrue());
  1030. Code = serialization::EXPR_CHOOSE;
  1031. }
  1032. void ASTStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
  1033. VisitExpr(E);
  1034. Record.AddSourceLocation(E->getTokenLocation());
  1035. Code = serialization::EXPR_GNU_NULL;
  1036. }
  1037. void ASTStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
  1038. VisitExpr(E);
  1039. Record.push_back(E->getNumSubExprs());
  1040. for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
  1041. Record.AddStmt(E->getExpr(I));
  1042. Record.AddSourceLocation(E->getBuiltinLoc());
  1043. Record.AddSourceLocation(E->getRParenLoc());
  1044. Code = serialization::EXPR_SHUFFLE_VECTOR;
  1045. }
  1046. void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
  1047. VisitExpr(E);
  1048. Record.AddSourceLocation(E->getBuiltinLoc());
  1049. Record.AddSourceLocation(E->getRParenLoc());
  1050. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  1051. Record.AddStmt(E->getSrcExpr());
  1052. Code = serialization::EXPR_CONVERT_VECTOR;
  1053. }
  1054. void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) {
  1055. VisitExpr(E);
  1056. Record.AddDeclRef(E->getBlockDecl());
  1057. Code = serialization::EXPR_BLOCK;
  1058. }
  1059. void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
  1060. VisitExpr(E);
  1061. Record.push_back(E->getNumAssocs());
  1062. Record.push_back(E->ResultIndex);
  1063. Record.AddSourceLocation(E->getGenericLoc());
  1064. Record.AddSourceLocation(E->getDefaultLoc());
  1065. Record.AddSourceLocation(E->getRParenLoc());
  1066. Stmt **Stmts = E->getTrailingObjects<Stmt *>();
  1067. // Add 1 to account for the controlling expression which is the first
  1068. // expression in the trailing array of Stmt *. This is not needed for
  1069. // the trailing array of TypeSourceInfo *.
  1070. for (unsigned I = 0, N = E->getNumAssocs() + 1; I < N; ++I)
  1071. Record.AddStmt(Stmts[I]);
  1072. TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
  1073. for (unsigned I = 0, N = E->getNumAssocs(); I < N; ++I)
  1074. Record.AddTypeSourceInfo(TSIs[I]);
  1075. Code = serialization::EXPR_GENERIC_SELECTION;
  1076. }
  1077. void ASTStmtWriter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
  1078. VisitExpr(E);
  1079. Record.push_back(E->getNumSemanticExprs());
  1080. // Push the result index. Currently, this needs to exactly match
  1081. // the encoding used internally for ResultIndex.
  1082. unsigned result = E->getResultExprIndex();
  1083. result = (result == PseudoObjectExpr::NoResult ? 0 : result + 1);
  1084. Record.push_back(result);
  1085. Record.AddStmt(E->getSyntacticForm());
  1086. for (PseudoObjectExpr::semantics_iterator
  1087. i = E->semantics_begin(), e = E->semantics_end(); i != e; ++i) {
  1088. Record.AddStmt(*i);
  1089. }
  1090. Code = serialization::EXPR_PSEUDO_OBJECT;
  1091. }
  1092. void ASTStmtWriter::VisitAtomicExpr(AtomicExpr *E) {
  1093. VisitExpr(E);
  1094. Record.push_back(E->getOp());
  1095. for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
  1096. Record.AddStmt(E->getSubExprs()[I]);
  1097. Record.AddSourceLocation(E->getBuiltinLoc());
  1098. Record.AddSourceLocation(E->getRParenLoc());
  1099. Code = serialization::EXPR_ATOMIC;
  1100. }
  1101. //===----------------------------------------------------------------------===//
  1102. // Objective-C Expressions and Statements.
  1103. //===----------------------------------------------------------------------===//
  1104. void ASTStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
  1105. VisitExpr(E);
  1106. Record.AddStmt(E->getString());
  1107. Record.AddSourceLocation(E->getAtLoc());
  1108. Code = serialization::EXPR_OBJC_STRING_LITERAL;
  1109. }
  1110. void ASTStmtWriter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
  1111. VisitExpr(E);
  1112. Record.AddStmt(E->getSubExpr());
  1113. Record.AddDeclRef(E->getBoxingMethod());
  1114. Record.AddSourceRange(E->getSourceRange());
  1115. Code = serialization::EXPR_OBJC_BOXED_EXPRESSION;
  1116. }
  1117. void ASTStmtWriter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
  1118. VisitExpr(E);
  1119. Record.push_back(E->getNumElements());
  1120. for (unsigned i = 0; i < E->getNumElements(); i++)
  1121. Record.AddStmt(E->getElement(i));
  1122. Record.AddDeclRef(E->getArrayWithObjectsMethod());
  1123. Record.AddSourceRange(E->getSourceRange());
  1124. Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
  1125. }
  1126. void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
  1127. VisitExpr(E);
  1128. Record.push_back(E->getNumElements());
  1129. Record.push_back(E->HasPackExpansions);
  1130. for (unsigned i = 0; i < E->getNumElements(); i++) {
  1131. ObjCDictionaryElement Element = E->getKeyValueElement(i);
  1132. Record.AddStmt(Element.Key);
  1133. Record.AddStmt(Element.Value);
  1134. if (E->HasPackExpansions) {
  1135. Record.AddSourceLocation(Element.EllipsisLoc);
  1136. unsigned NumExpansions = 0;
  1137. if (Element.NumExpansions)
  1138. NumExpansions = *Element.NumExpansions + 1;
  1139. Record.push_back(NumExpansions);
  1140. }
  1141. }
  1142. Record.AddDeclRef(E->getDictWithObjectsMethod());
  1143. Record.AddSourceRange(E->getSourceRange());
  1144. Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
  1145. }
  1146. void ASTStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
  1147. VisitExpr(E);
  1148. Record.AddTypeSourceInfo(E->getEncodedTypeSourceInfo());
  1149. Record.AddSourceLocation(E->getAtLoc());
  1150. Record.AddSourceLocation(E->getRParenLoc());
  1151. Code = serialization::EXPR_OBJC_ENCODE;
  1152. }
  1153. void ASTStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
  1154. VisitExpr(E);
  1155. Record.AddSelectorRef(E->getSelector());
  1156. Record.AddSourceLocation(E->getAtLoc());
  1157. Record.AddSourceLocation(E->getRParenLoc());
  1158. Code = serialization::EXPR_OBJC_SELECTOR_EXPR;
  1159. }
  1160. void ASTStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
  1161. VisitExpr(E);
  1162. Record.AddDeclRef(E->getProtocol());
  1163. Record.AddSourceLocation(E->getAtLoc());
  1164. Record.AddSourceLocation(E->ProtoLoc);
  1165. Record.AddSourceLocation(E->getRParenLoc());
  1166. Code = serialization::EXPR_OBJC_PROTOCOL_EXPR;
  1167. }
  1168. void ASTStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
  1169. VisitExpr(E);
  1170. Record.AddDeclRef(E->getDecl());
  1171. Record.AddSourceLocation(E->getLocation());
  1172. Record.AddSourceLocation(E->getOpLoc());
  1173. Record.AddStmt(E->getBase());
  1174. Record.push_back(E->isArrow());
  1175. Record.push_back(E->isFreeIvar());
  1176. Code = serialization::EXPR_OBJC_IVAR_REF_EXPR;
  1177. }
  1178. void ASTStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
  1179. VisitExpr(E);
  1180. Record.push_back(E->SetterAndMethodRefFlags.getInt());
  1181. Record.push_back(E->isImplicitProperty());
  1182. if (E->isImplicitProperty()) {
  1183. Record.AddDeclRef(E->getImplicitPropertyGetter());
  1184. Record.AddDeclRef(E->getImplicitPropertySetter());
  1185. } else {
  1186. Record.AddDeclRef(E->getExplicitProperty());
  1187. }
  1188. Record.AddSourceLocation(E->getLocation());
  1189. Record.AddSourceLocation(E->getReceiverLocation());
  1190. if (E->isObjectReceiver()) {
  1191. Record.push_back(0);
  1192. Record.AddStmt(E->getBase());
  1193. } else if (E->isSuperReceiver()) {
  1194. Record.push_back(1);
  1195. Record.AddTypeRef(E->getSuperReceiverType());
  1196. } else {
  1197. Record.push_back(2);
  1198. Record.AddDeclRef(E->getClassReceiver());
  1199. }
  1200. Code = serialization::EXPR_OBJC_PROPERTY_REF_EXPR;
  1201. }
  1202. void ASTStmtWriter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
  1203. VisitExpr(E);
  1204. Record.AddSourceLocation(E->getRBracket());
  1205. Record.AddStmt(E->getBaseExpr());
  1206. Record.AddStmt(E->getKeyExpr());
  1207. Record.AddDeclRef(E->getAtIndexMethodDecl());
  1208. Record.AddDeclRef(E->setAtIndexMethodDecl());
  1209. Code = serialization::EXPR_OBJC_SUBSCRIPT_REF_EXPR;
  1210. }
  1211. void ASTStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
  1212. VisitExpr(E);
  1213. Record.push_back(E->getNumArgs());
  1214. Record.push_back(E->getNumStoredSelLocs());
  1215. Record.push_back(E->SelLocsKind);
  1216. Record.push_back(E->isDelegateInitCall());
  1217. Record.push_back(E->IsImplicit);
  1218. Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
  1219. switch (E->getReceiverKind()) {
  1220. case ObjCMessageExpr::Instance:
  1221. Record.AddStmt(E->getInstanceReceiver());
  1222. break;
  1223. case ObjCMessageExpr::Class:
  1224. Record.AddTypeSourceInfo(E->getClassReceiverTypeInfo());
  1225. break;
  1226. case ObjCMessageExpr::SuperClass:
  1227. case ObjCMessageExpr::SuperInstance:
  1228. Record.AddTypeRef(E->getSuperType());
  1229. Record.AddSourceLocation(E->getSuperLoc());
  1230. break;
  1231. }
  1232. if (E->getMethodDecl()) {
  1233. Record.push_back(1);
  1234. Record.AddDeclRef(E->getMethodDecl());
  1235. } else {
  1236. Record.push_back(0);
  1237. Record.AddSelectorRef(E->getSelector());
  1238. }
  1239. Record.AddSourceLocation(E->getLeftLoc());
  1240. Record.AddSourceLocation(E->getRightLoc());
  1241. for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
  1242. Arg != ArgEnd; ++Arg)
  1243. Record.AddStmt(*Arg);
  1244. SourceLocation *Locs = E->getStoredSelLocs();
  1245. for (unsigned i = 0, e = E->getNumStoredSelLocs(); i != e; ++i)
  1246. Record.AddSourceLocation(Locs[i]);
  1247. Code = serialization::EXPR_OBJC_MESSAGE_EXPR;
  1248. }
  1249. void ASTStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
  1250. VisitStmt(S);
  1251. Record.AddStmt(S->getElement());
  1252. Record.AddStmt(S->getCollection());
  1253. Record.AddStmt(S->getBody());
  1254. Record.AddSourceLocation(S->getForLoc());
  1255. Record.AddSourceLocation(S->getRParenLoc());
  1256. Code = serialization::STMT_OBJC_FOR_COLLECTION;
  1257. }
  1258. void ASTStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
  1259. VisitStmt(S);
  1260. Record.AddStmt(S->getCatchBody());
  1261. Record.AddDeclRef(S->getCatchParamDecl());
  1262. Record.AddSourceLocation(S->getAtCatchLoc());
  1263. Record.AddSourceLocation(S->getRParenLoc());
  1264. Code = serialization::STMT_OBJC_CATCH;
  1265. }
  1266. void ASTStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
  1267. VisitStmt(S);
  1268. Record.AddStmt(S->getFinallyBody());
  1269. Record.AddSourceLocation(S->getAtFinallyLoc());
  1270. Code = serialization::STMT_OBJC_FINALLY;
  1271. }
  1272. void ASTStmtWriter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
  1273. VisitStmt(S); // FIXME: no test coverage.
  1274. Record.AddStmt(S->getSubStmt());
  1275. Record.AddSourceLocation(S->getAtLoc());
  1276. Code = serialization::STMT_OBJC_AUTORELEASE_POOL;
  1277. }
  1278. void ASTStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
  1279. VisitStmt(S);
  1280. Record.push_back(S->getNumCatchStmts());
  1281. Record.push_back(S->getFinallyStmt() != nullptr);
  1282. Record.AddStmt(S->getTryBody());
  1283. for (ObjCAtCatchStmt *C : S->catch_stmts())
  1284. Record.AddStmt(C);
  1285. if (S->getFinallyStmt())
  1286. Record.AddStmt(S->getFinallyStmt());
  1287. Record.AddSourceLocation(S->getAtTryLoc());
  1288. Code = serialization::STMT_OBJC_AT_TRY;
  1289. }
  1290. void ASTStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
  1291. VisitStmt(S); // FIXME: no test coverage.
  1292. Record.AddStmt(S->getSynchExpr());
  1293. Record.AddStmt(S->getSynchBody());
  1294. Record.AddSourceLocation(S->getAtSynchronizedLoc());
  1295. Code = serialization::STMT_OBJC_AT_SYNCHRONIZED;
  1296. }
  1297. void ASTStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
  1298. VisitStmt(S); // FIXME: no test coverage.
  1299. Record.AddStmt(S->getThrowExpr());
  1300. Record.AddSourceLocation(S->getThrowLoc());
  1301. Code = serialization::STMT_OBJC_AT_THROW;
  1302. }
  1303. void ASTStmtWriter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
  1304. VisitExpr(E);
  1305. Record.push_back(E->getValue());
  1306. Record.AddSourceLocation(E->getLocation());
  1307. Code = serialization::EXPR_OBJC_BOOL_LITERAL;
  1308. }
  1309. void ASTStmtWriter::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
  1310. VisitExpr(E);
  1311. Record.AddSourceRange(E->getSourceRange());
  1312. Record.AddVersionTuple(E->getVersion());
  1313. Code = serialization::EXPR_OBJC_AVAILABILITY_CHECK;
  1314. }
  1315. //===----------------------------------------------------------------------===//
  1316. // C++ Expressions and Statements.
  1317. //===----------------------------------------------------------------------===//
  1318. void ASTStmtWriter::VisitCXXCatchStmt(CXXCatchStmt *S) {
  1319. VisitStmt(S);
  1320. Record.AddSourceLocation(S->getCatchLoc());
  1321. Record.AddDeclRef(S->getExceptionDecl());
  1322. Record.AddStmt(S->getHandlerBlock());
  1323. Code = serialization::STMT_CXX_CATCH;
  1324. }
  1325. void ASTStmtWriter::VisitCXXTryStmt(CXXTryStmt *S) {
  1326. VisitStmt(S);
  1327. Record.push_back(S->getNumHandlers());
  1328. Record.AddSourceLocation(S->getTryLoc());
  1329. Record.AddStmt(S->getTryBlock());
  1330. for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
  1331. Record.AddStmt(S->getHandler(i));
  1332. Code = serialization::STMT_CXX_TRY;
  1333. }
  1334. void ASTStmtWriter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
  1335. VisitStmt(S);
  1336. Record.AddSourceLocation(S->getForLoc());
  1337. Record.AddSourceLocation(S->getCoawaitLoc());
  1338. Record.AddSourceLocation(S->getColonLoc());
  1339. Record.AddSourceLocation(S->getRParenLoc());
  1340. Record.AddStmt(S->getInit());
  1341. Record.AddStmt(S->getRangeStmt());
  1342. Record.AddStmt(S->getBeginStmt());
  1343. Record.AddStmt(S->getEndStmt());
  1344. Record.AddStmt(S->getCond());
  1345. Record.AddStmt(S->getInc());
  1346. Record.AddStmt(S->getLoopVarStmt());
  1347. Record.AddStmt(S->getBody());
  1348. Code = serialization::STMT_CXX_FOR_RANGE;
  1349. }
  1350. void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
  1351. VisitStmt(S);
  1352. Record.AddSourceLocation(S->getKeywordLoc());
  1353. Record.push_back(S->isIfExists());
  1354. Record.AddNestedNameSpecifierLoc(S->getQualifierLoc());
  1355. Record.AddDeclarationNameInfo(S->getNameInfo());
  1356. Record.AddStmt(S->getSubStmt());
  1357. Code = serialization::STMT_MS_DEPENDENT_EXISTS;
  1358. }
  1359. void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
  1360. VisitCallExpr(E);
  1361. Record.push_back(E->getOperator());
  1362. Record.AddSourceRange(E->Range);
  1363. Code = serialization::EXPR_CXX_OPERATOR_CALL;
  1364. }
  1365. void ASTStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
  1366. VisitCallExpr(E);
  1367. Code = serialization::EXPR_CXX_MEMBER_CALL;
  1368. }
  1369. void ASTStmtWriter::VisitCXXRewrittenBinaryOperator(
  1370. CXXRewrittenBinaryOperator *E) {
  1371. VisitExpr(E);
  1372. Record.push_back(E->isReversed());
  1373. Record.AddStmt(E->getSemanticForm());
  1374. Code = serialization::EXPR_CXX_REWRITTEN_BINARY_OPERATOR;
  1375. }
  1376. void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
  1377. VisitExpr(E);
  1378. Record.push_back(E->getNumArgs());
  1379. Record.push_back(E->isElidable());
  1380. Record.push_back(E->hadMultipleCandidates());
  1381. Record.push_back(E->isListInitialization());
  1382. Record.push_back(E->isStdInitListInitialization());
  1383. Record.push_back(E->requiresZeroInitialization());
  1384. Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
  1385. Record.AddSourceLocation(E->getLocation());
  1386. Record.AddDeclRef(E->getConstructor());
  1387. Record.AddSourceRange(E->getParenOrBraceRange());
  1388. for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
  1389. Record.AddStmt(E->getArg(I));
  1390. Code = serialization::EXPR_CXX_CONSTRUCT;
  1391. }
  1392. void ASTStmtWriter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
  1393. VisitExpr(E);
  1394. Record.AddDeclRef(E->getConstructor());
  1395. Record.AddSourceLocation(E->getLocation());
  1396. Record.push_back(E->constructsVBase());
  1397. Record.push_back(E->inheritedFromVBase());
  1398. Code = serialization::EXPR_CXX_INHERITED_CTOR_INIT;
  1399. }
  1400. void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
  1401. VisitCXXConstructExpr(E);
  1402. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  1403. Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
  1404. }
  1405. void ASTStmtWriter::VisitLambdaExpr(LambdaExpr *E) {
  1406. VisitExpr(E);
  1407. Record.push_back(E->LambdaExprBits.NumCaptures);
  1408. Record.AddSourceRange(E->IntroducerRange);
  1409. Record.push_back(E->LambdaExprBits.CaptureDefault); // FIXME: stable encoding
  1410. Record.AddSourceLocation(E->CaptureDefaultLoc);
  1411. Record.push_back(E->LambdaExprBits.ExplicitParams);
  1412. Record.push_back(E->LambdaExprBits.ExplicitResultType);
  1413. Record.AddSourceLocation(E->ClosingBrace);
  1414. // Add capture initializers.
  1415. for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
  1416. CEnd = E->capture_init_end();
  1417. C != CEnd; ++C) {
  1418. Record.AddStmt(*C);
  1419. }
  1420. // Don't serialize the body. It belongs to the call operator declaration.
  1421. // LambdaExpr only stores a copy of the Stmt *.
  1422. Code = serialization::EXPR_LAMBDA;
  1423. }
  1424. void ASTStmtWriter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
  1425. VisitExpr(E);
  1426. Record.AddStmt(E->getSubExpr());
  1427. Code = serialization::EXPR_CXX_STD_INITIALIZER_LIST;
  1428. }
  1429. void ASTStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
  1430. VisitExplicitCastExpr(E);
  1431. Record.AddSourceRange(SourceRange(E->getOperatorLoc(), E->getRParenLoc()));
  1432. Record.AddSourceRange(E->getAngleBrackets());
  1433. }
  1434. void ASTStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
  1435. VisitCXXNamedCastExpr(E);
  1436. Code = serialization::EXPR_CXX_STATIC_CAST;
  1437. }
  1438. void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
  1439. VisitCXXNamedCastExpr(E);
  1440. Code = serialization::EXPR_CXX_DYNAMIC_CAST;
  1441. }
  1442. void ASTStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
  1443. VisitCXXNamedCastExpr(E);
  1444. Code = serialization::EXPR_CXX_REINTERPRET_CAST;
  1445. }
  1446. void ASTStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
  1447. VisitCXXNamedCastExpr(E);
  1448. Code = serialization::EXPR_CXX_CONST_CAST;
  1449. }
  1450. void ASTStmtWriter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
  1451. VisitCXXNamedCastExpr(E);
  1452. Code = serialization::EXPR_CXX_ADDRSPACE_CAST;
  1453. }
  1454. void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
  1455. VisitExplicitCastExpr(E);
  1456. Record.AddSourceLocation(E->getLParenLoc());
  1457. Record.AddSourceLocation(E->getRParenLoc());
  1458. Code = serialization::EXPR_CXX_FUNCTIONAL_CAST;
  1459. }
  1460. void ASTStmtWriter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
  1461. VisitExplicitCastExpr(E);
  1462. Record.AddSourceLocation(E->getBeginLoc());
  1463. Record.AddSourceLocation(E->getEndLoc());
  1464. Code = serialization::EXPR_BUILTIN_BIT_CAST;
  1465. }
  1466. void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
  1467. VisitCallExpr(E);
  1468. Record.AddSourceLocation(E->UDSuffixLoc);
  1469. Code = serialization::EXPR_USER_DEFINED_LITERAL;
  1470. }
  1471. void ASTStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
  1472. VisitExpr(E);
  1473. Record.push_back(E->getValue());
  1474. Record.AddSourceLocation(E->getLocation());
  1475. Code = serialization::EXPR_CXX_BOOL_LITERAL;
  1476. }
  1477. void ASTStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
  1478. VisitExpr(E);
  1479. Record.AddSourceLocation(E->getLocation());
  1480. Code = serialization::EXPR_CXX_NULL_PTR_LITERAL;
  1481. }
  1482. void ASTStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
  1483. VisitExpr(E);
  1484. Record.AddSourceRange(E->getSourceRange());
  1485. if (E->isTypeOperand()) {
  1486. Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
  1487. Code = serialization::EXPR_CXX_TYPEID_TYPE;
  1488. } else {
  1489. Record.AddStmt(E->getExprOperand());
  1490. Code = serialization::EXPR_CXX_TYPEID_EXPR;
  1491. }
  1492. }
  1493. void ASTStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
  1494. VisitExpr(E);
  1495. Record.AddSourceLocation(E->getLocation());
  1496. Record.push_back(E->isImplicit());
  1497. Code = serialization::EXPR_CXX_THIS;
  1498. }
  1499. void ASTStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
  1500. VisitExpr(E);
  1501. Record.AddSourceLocation(E->getThrowLoc());
  1502. Record.AddStmt(E->getSubExpr());
  1503. Record.push_back(E->isThrownVariableInScope());
  1504. Code = serialization::EXPR_CXX_THROW;
  1505. }
  1506. void ASTStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
  1507. VisitExpr(E);
  1508. Record.AddDeclRef(E->getParam());
  1509. Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
  1510. Record.AddSourceLocation(E->getUsedLocation());
  1511. Code = serialization::EXPR_CXX_DEFAULT_ARG;
  1512. }
  1513. void ASTStmtWriter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
  1514. VisitExpr(E);
  1515. Record.AddDeclRef(E->getField());
  1516. Record.AddDeclRef(cast_or_null<Decl>(E->getUsedContext()));
  1517. Record.AddSourceLocation(E->getExprLoc());
  1518. Code = serialization::EXPR_CXX_DEFAULT_INIT;
  1519. }
  1520. void ASTStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
  1521. VisitExpr(E);
  1522. Record.AddCXXTemporary(E->getTemporary());
  1523. Record.AddStmt(E->getSubExpr());
  1524. Code = serialization::EXPR_CXX_BIND_TEMPORARY;
  1525. }
  1526. void ASTStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
  1527. VisitExpr(E);
  1528. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  1529. Record.AddSourceLocation(E->getRParenLoc());
  1530. Code = serialization::EXPR_CXX_SCALAR_VALUE_INIT;
  1531. }
  1532. void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
  1533. VisitExpr(E);
  1534. Record.push_back(E->isArray());
  1535. Record.push_back(E->hasInitializer());
  1536. Record.push_back(E->getNumPlacementArgs());
  1537. Record.push_back(E->isParenTypeId());
  1538. Record.push_back(E->isGlobalNew());
  1539. Record.push_back(E->passAlignment());
  1540. Record.push_back(E->doesUsualArrayDeleteWantSize());
  1541. Record.push_back(E->CXXNewExprBits.StoredInitializationStyle);
  1542. Record.AddDeclRef(E->getOperatorNew());
  1543. Record.AddDeclRef(E->getOperatorDelete());
  1544. Record.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo());
  1545. if (E->isParenTypeId())
  1546. Record.AddSourceRange(E->getTypeIdParens());
  1547. Record.AddSourceRange(E->getSourceRange());
  1548. Record.AddSourceRange(E->getDirectInitRange());
  1549. for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), N = E->raw_arg_end();
  1550. I != N; ++I)
  1551. Record.AddStmt(*I);
  1552. Code = serialization::EXPR_CXX_NEW;
  1553. }
  1554. void ASTStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
  1555. VisitExpr(E);
  1556. Record.push_back(E->isGlobalDelete());
  1557. Record.push_back(E->isArrayForm());
  1558. Record.push_back(E->isArrayFormAsWritten());
  1559. Record.push_back(E->doesUsualArrayDeleteWantSize());
  1560. Record.AddDeclRef(E->getOperatorDelete());
  1561. Record.AddStmt(E->getArgument());
  1562. Record.AddSourceLocation(E->getBeginLoc());
  1563. Code = serialization::EXPR_CXX_DELETE;
  1564. }
  1565. void ASTStmtWriter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
  1566. VisitExpr(E);
  1567. Record.AddStmt(E->getBase());
  1568. Record.push_back(E->isArrow());
  1569. Record.AddSourceLocation(E->getOperatorLoc());
  1570. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  1571. Record.AddTypeSourceInfo(E->getScopeTypeInfo());
  1572. Record.AddSourceLocation(E->getColonColonLoc());
  1573. Record.AddSourceLocation(E->getTildeLoc());
  1574. // PseudoDestructorTypeStorage.
  1575. Record.AddIdentifierRef(E->getDestroyedTypeIdentifier());
  1576. if (E->getDestroyedTypeIdentifier())
  1577. Record.AddSourceLocation(E->getDestroyedTypeLoc());
  1578. else
  1579. Record.AddTypeSourceInfo(E->getDestroyedTypeInfo());
  1580. Code = serialization::EXPR_CXX_PSEUDO_DESTRUCTOR;
  1581. }
  1582. void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) {
  1583. VisitExpr(E);
  1584. Record.push_back(E->getNumObjects());
  1585. for (auto &Obj : E->getObjects()) {
  1586. if (auto *BD = Obj.dyn_cast<BlockDecl *>()) {
  1587. Record.push_back(serialization::COK_Block);
  1588. Record.AddDeclRef(BD);
  1589. } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) {
  1590. Record.push_back(serialization::COK_CompoundLiteral);
  1591. Record.AddStmt(CLE);
  1592. }
  1593. }
  1594. Record.push_back(E->cleanupsHaveSideEffects());
  1595. Record.AddStmt(E->getSubExpr());
  1596. Code = serialization::EXPR_EXPR_WITH_CLEANUPS;
  1597. }
  1598. void ASTStmtWriter::VisitCXXDependentScopeMemberExpr(
  1599. CXXDependentScopeMemberExpr *E) {
  1600. VisitExpr(E);
  1601. // Don't emit anything here (or if you do you will have to update
  1602. // the corresponding deserialization function).
  1603. Record.push_back(E->hasTemplateKWAndArgsInfo());
  1604. Record.push_back(E->getNumTemplateArgs());
  1605. Record.push_back(E->hasFirstQualifierFoundInScope());
  1606. if (E->hasTemplateKWAndArgsInfo()) {
  1607. const ASTTemplateKWAndArgsInfo &ArgInfo =
  1608. *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
  1609. AddTemplateKWAndArgsInfo(ArgInfo,
  1610. E->getTrailingObjects<TemplateArgumentLoc>());
  1611. }
  1612. Record.push_back(E->isArrow());
  1613. Record.AddSourceLocation(E->getOperatorLoc());
  1614. Record.AddTypeRef(E->getBaseType());
  1615. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  1616. if (!E->isImplicitAccess())
  1617. Record.AddStmt(E->getBase());
  1618. else
  1619. Record.AddStmt(nullptr);
  1620. if (E->hasFirstQualifierFoundInScope())
  1621. Record.AddDeclRef(E->getFirstQualifierFoundInScope());
  1622. Record.AddDeclarationNameInfo(E->MemberNameInfo);
  1623. Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
  1624. }
  1625. void
  1626. ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
  1627. VisitExpr(E);
  1628. // Don't emit anything here, HasTemplateKWAndArgsInfo must be
  1629. // emitted first.
  1630. Record.push_back(E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo);
  1631. if (E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo) {
  1632. const ASTTemplateKWAndArgsInfo &ArgInfo =
  1633. *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
  1634. Record.push_back(ArgInfo.NumTemplateArgs);
  1635. AddTemplateKWAndArgsInfo(ArgInfo,
  1636. E->getTrailingObjects<TemplateArgumentLoc>());
  1637. }
  1638. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  1639. Record.AddDeclarationNameInfo(E->NameInfo);
  1640. Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
  1641. }
  1642. void
  1643. ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
  1644. VisitExpr(E);
  1645. Record.push_back(E->getNumArgs());
  1646. for (CXXUnresolvedConstructExpr::arg_iterator
  1647. ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
  1648. Record.AddStmt(*ArgI);
  1649. Record.AddTypeSourceInfo(E->getTypeSourceInfo());
  1650. Record.AddSourceLocation(E->getLParenLoc());
  1651. Record.AddSourceLocation(E->getRParenLoc());
  1652. Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
  1653. }
  1654. void ASTStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
  1655. VisitExpr(E);
  1656. Record.push_back(E->getNumDecls());
  1657. Record.push_back(E->hasTemplateKWAndArgsInfo());
  1658. if (E->hasTemplateKWAndArgsInfo()) {
  1659. const ASTTemplateKWAndArgsInfo &ArgInfo =
  1660. *E->getTrailingASTTemplateKWAndArgsInfo();
  1661. Record.push_back(ArgInfo.NumTemplateArgs);
  1662. AddTemplateKWAndArgsInfo(ArgInfo, E->getTrailingTemplateArgumentLoc());
  1663. }
  1664. for (OverloadExpr::decls_iterator OvI = E->decls_begin(),
  1665. OvE = E->decls_end();
  1666. OvI != OvE; ++OvI) {
  1667. Record.AddDeclRef(OvI.getDecl());
  1668. Record.push_back(OvI.getAccess());
  1669. }
  1670. Record.AddDeclarationNameInfo(E->getNameInfo());
  1671. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  1672. }
  1673. void ASTStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
  1674. VisitOverloadExpr(E);
  1675. Record.push_back(E->isArrow());
  1676. Record.push_back(E->hasUnresolvedUsing());
  1677. Record.AddStmt(!E->isImplicitAccess() ? E->getBase() : nullptr);
  1678. Record.AddTypeRef(E->getBaseType());
  1679. Record.AddSourceLocation(E->getOperatorLoc());
  1680. Code = serialization::EXPR_CXX_UNRESOLVED_MEMBER;
  1681. }
  1682. void ASTStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
  1683. VisitOverloadExpr(E);
  1684. Record.push_back(E->requiresADL());
  1685. Record.push_back(E->isOverloaded());
  1686. Record.AddDeclRef(E->getNamingClass());
  1687. Code = serialization::EXPR_CXX_UNRESOLVED_LOOKUP;
  1688. }
  1689. void ASTStmtWriter::VisitTypeTraitExpr(TypeTraitExpr *E) {
  1690. VisitExpr(E);
  1691. Record.push_back(E->TypeTraitExprBits.NumArgs);
  1692. Record.push_back(E->TypeTraitExprBits.Kind); // FIXME: Stable encoding
  1693. Record.push_back(E->TypeTraitExprBits.Value);
  1694. Record.AddSourceRange(E->getSourceRange());
  1695. for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
  1696. Record.AddTypeSourceInfo(E->getArg(I));
  1697. Code = serialization::EXPR_TYPE_TRAIT;
  1698. }
  1699. void ASTStmtWriter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
  1700. VisitExpr(E);
  1701. Record.push_back(E->getTrait());
  1702. Record.push_back(E->getValue());
  1703. Record.AddSourceRange(E->getSourceRange());
  1704. Record.AddTypeSourceInfo(E->getQueriedTypeSourceInfo());
  1705. Record.AddStmt(E->getDimensionExpression());
  1706. Code = serialization::EXPR_ARRAY_TYPE_TRAIT;
  1707. }
  1708. void ASTStmtWriter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
  1709. VisitExpr(E);
  1710. Record.push_back(E->getTrait());
  1711. Record.push_back(E->getValue());
  1712. Record.AddSourceRange(E->getSourceRange());
  1713. Record.AddStmt(E->getQueriedExpression());
  1714. Code = serialization::EXPR_CXX_EXPRESSION_TRAIT;
  1715. }
  1716. void ASTStmtWriter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
  1717. VisitExpr(E);
  1718. Record.push_back(E->getValue());
  1719. Record.AddSourceRange(E->getSourceRange());
  1720. Record.AddStmt(E->getOperand());
  1721. Code = serialization::EXPR_CXX_NOEXCEPT;
  1722. }
  1723. void ASTStmtWriter::VisitPackExpansionExpr(PackExpansionExpr *E) {
  1724. VisitExpr(E);
  1725. Record.AddSourceLocation(E->getEllipsisLoc());
  1726. Record.push_back(E->NumExpansions);
  1727. Record.AddStmt(E->getPattern());
  1728. Code = serialization::EXPR_PACK_EXPANSION;
  1729. }
  1730. void ASTStmtWriter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
  1731. VisitExpr(E);
  1732. Record.push_back(E->isPartiallySubstituted() ? E->getPartialArguments().size()
  1733. : 0);
  1734. Record.AddSourceLocation(E->OperatorLoc);
  1735. Record.AddSourceLocation(E->PackLoc);
  1736. Record.AddSourceLocation(E->RParenLoc);
  1737. Record.AddDeclRef(E->Pack);
  1738. if (E->isPartiallySubstituted()) {
  1739. for (const auto &TA : E->getPartialArguments())
  1740. Record.AddTemplateArgument(TA);
  1741. } else if (!E->isValueDependent()) {
  1742. Record.push_back(E->getPackLength());
  1743. }
  1744. Code = serialization::EXPR_SIZEOF_PACK;
  1745. }
  1746. void ASTStmtWriter::VisitSubstNonTypeTemplateParmExpr(
  1747. SubstNonTypeTemplateParmExpr *E) {
  1748. VisitExpr(E);
  1749. Record.AddDeclRef(E->getParameter());
  1750. Record.push_back(E->isReferenceParameter());
  1751. Record.AddSourceLocation(E->getNameLoc());
  1752. Record.AddStmt(E->getReplacement());
  1753. Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM;
  1754. }
  1755. void ASTStmtWriter::VisitSubstNonTypeTemplateParmPackExpr(
  1756. SubstNonTypeTemplateParmPackExpr *E) {
  1757. VisitExpr(E);
  1758. Record.AddDeclRef(E->getParameterPack());
  1759. Record.AddTemplateArgument(E->getArgumentPack());
  1760. Record.AddSourceLocation(E->getParameterPackLocation());
  1761. Code = serialization::EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK;
  1762. }
  1763. void ASTStmtWriter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
  1764. VisitExpr(E);
  1765. Record.push_back(E->getNumExpansions());
  1766. Record.AddDeclRef(E->getParameterPack());
  1767. Record.AddSourceLocation(E->getParameterPackLocation());
  1768. for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
  1769. I != End; ++I)
  1770. Record.AddDeclRef(*I);
  1771. Code = serialization::EXPR_FUNCTION_PARM_PACK;
  1772. }
  1773. void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
  1774. VisitExpr(E);
  1775. Record.push_back(static_cast<bool>(E->getLifetimeExtendedTemporaryDecl()));
  1776. if (E->getLifetimeExtendedTemporaryDecl())
  1777. Record.AddDeclRef(E->getLifetimeExtendedTemporaryDecl());
  1778. else
  1779. Record.AddStmt(E->getSubExpr());
  1780. Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
  1781. }
  1782. void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) {
  1783. VisitExpr(E);
  1784. Record.AddSourceLocation(E->LParenLoc);
  1785. Record.AddSourceLocation(E->EllipsisLoc);
  1786. Record.AddSourceLocation(E->RParenLoc);
  1787. Record.push_back(E->NumExpansions);
  1788. Record.AddStmt(E->SubExprs[0]);
  1789. Record.AddStmt(E->SubExprs[1]);
  1790. Record.AddStmt(E->SubExprs[2]);
  1791. Record.push_back(E->Opcode);
  1792. Code = serialization::EXPR_CXX_FOLD;
  1793. }
  1794. void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
  1795. VisitExpr(E);
  1796. Record.AddStmt(E->getSourceExpr());
  1797. Record.AddSourceLocation(E->getLocation());
  1798. Record.push_back(E->isUnique());
  1799. Code = serialization::EXPR_OPAQUE_VALUE;
  1800. }
  1801. void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) {
  1802. VisitExpr(E);
  1803. // TODO: Figure out sane writer behavior for a TypoExpr, if necessary
  1804. llvm_unreachable("Cannot write TypoExpr nodes");
  1805. }
  1806. //===----------------------------------------------------------------------===//
  1807. // CUDA Expressions and Statements.
  1808. //===----------------------------------------------------------------------===//
  1809. void ASTStmtWriter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
  1810. VisitCallExpr(E);
  1811. Record.AddStmt(E->getConfig());
  1812. Code = serialization::EXPR_CUDA_KERNEL_CALL;
  1813. }
  1814. //===----------------------------------------------------------------------===//
  1815. // OpenCL Expressions and Statements.
  1816. //===----------------------------------------------------------------------===//
  1817. void ASTStmtWriter::VisitAsTypeExpr(AsTypeExpr *E) {
  1818. VisitExpr(E);
  1819. Record.AddSourceLocation(E->getBuiltinLoc());
  1820. Record.AddSourceLocation(E->getRParenLoc());
  1821. Record.AddStmt(E->getSrcExpr());
  1822. Code = serialization::EXPR_ASTYPE;
  1823. }
  1824. //===----------------------------------------------------------------------===//
  1825. // Microsoft Expressions and Statements.
  1826. //===----------------------------------------------------------------------===//
  1827. void ASTStmtWriter::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
  1828. VisitExpr(E);
  1829. Record.push_back(E->isArrow());
  1830. Record.AddStmt(E->getBaseExpr());
  1831. Record.AddNestedNameSpecifierLoc(E->getQualifierLoc());
  1832. Record.AddSourceLocation(E->getMemberLoc());
  1833. Record.AddDeclRef(E->getPropertyDecl());
  1834. Code = serialization::EXPR_CXX_PROPERTY_REF_EXPR;
  1835. }
  1836. void ASTStmtWriter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
  1837. VisitExpr(E);
  1838. Record.AddStmt(E->getBase());
  1839. Record.AddStmt(E->getIdx());
  1840. Record.AddSourceLocation(E->getRBracketLoc());
  1841. Code = serialization::EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR;
  1842. }
  1843. void ASTStmtWriter::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
  1844. VisitExpr(E);
  1845. Record.AddSourceRange(E->getSourceRange());
  1846. Record.AddDeclRef(E->getGuidDecl());
  1847. if (E->isTypeOperand()) {
  1848. Record.AddTypeSourceInfo(E->getTypeOperandSourceInfo());
  1849. Code = serialization::EXPR_CXX_UUIDOF_TYPE;
  1850. } else {
  1851. Record.AddStmt(E->getExprOperand());
  1852. Code = serialization::EXPR_CXX_UUIDOF_EXPR;
  1853. }
  1854. }
  1855. void ASTStmtWriter::VisitSEHExceptStmt(SEHExceptStmt *S) {
  1856. VisitStmt(S);
  1857. Record.AddSourceLocation(S->getExceptLoc());
  1858. Record.AddStmt(S->getFilterExpr());
  1859. Record.AddStmt(S->getBlock());
  1860. Code = serialization::STMT_SEH_EXCEPT;
  1861. }
  1862. void ASTStmtWriter::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
  1863. VisitStmt(S);
  1864. Record.AddSourceLocation(S->getFinallyLoc());
  1865. Record.AddStmt(S->getBlock());
  1866. Code = serialization::STMT_SEH_FINALLY;
  1867. }
  1868. void ASTStmtWriter::VisitSEHTryStmt(SEHTryStmt *S) {
  1869. VisitStmt(S);
  1870. Record.push_back(S->getIsCXXTry());
  1871. Record.AddSourceLocation(S->getTryLoc());
  1872. Record.AddStmt(S->getTryBlock());
  1873. Record.AddStmt(S->getHandler());
  1874. Code = serialization::STMT_SEH_TRY;
  1875. }
  1876. void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
  1877. VisitStmt(S);
  1878. Record.AddSourceLocation(S->getLeaveLoc());
  1879. Code = serialization::STMT_SEH_LEAVE;
  1880. }
  1881. //===----------------------------------------------------------------------===//
  1882. // OpenMP Directives.
  1883. //===----------------------------------------------------------------------===//
  1884. void ASTStmtWriter::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
  1885. VisitStmt(S);
  1886. for (Stmt *SubStmt : S->SubStmts)
  1887. Record.AddStmt(SubStmt);
  1888. Code = serialization::STMT_OMP_CANONICAL_LOOP;
  1889. }
  1890. void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
  1891. Record.writeOMPChildren(E->Data);
  1892. Record.AddSourceLocation(E->getBeginLoc());
  1893. Record.AddSourceLocation(E->getEndLoc());
  1894. }
  1895. void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
  1896. VisitStmt(D);
  1897. Record.writeUInt32(D->getLoopsNumber());
  1898. VisitOMPExecutableDirective(D);
  1899. }
  1900. void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
  1901. VisitOMPLoopBasedDirective(D);
  1902. }
  1903. void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective *D) {
  1904. VisitStmt(D);
  1905. Record.push_back(D->getNumClauses());
  1906. VisitOMPExecutableDirective(D);
  1907. Code = serialization::STMT_OMP_META_DIRECTIVE;
  1908. }
  1909. void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) {
  1910. VisitStmt(D);
  1911. VisitOMPExecutableDirective(D);
  1912. Record.writeBool(D->hasCancel());
  1913. Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE;
  1914. }
  1915. void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) {
  1916. VisitOMPLoopDirective(D);
  1917. Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
  1918. }
  1919. void ASTStmtWriter::VisitOMPLoopTransformationDirective(
  1920. OMPLoopTransformationDirective *D) {
  1921. VisitOMPLoopBasedDirective(D);
  1922. Record.writeUInt32(D->getNumGeneratedLoops());
  1923. }
  1924. void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
  1925. VisitOMPLoopTransformationDirective(D);
  1926. Code = serialization::STMT_OMP_TILE_DIRECTIVE;
  1927. }
  1928. void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
  1929. VisitOMPLoopTransformationDirective(D);
  1930. Code = serialization::STMT_OMP_UNROLL_DIRECTIVE;
  1931. }
  1932. void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
  1933. VisitOMPLoopDirective(D);
  1934. Record.writeBool(D->hasCancel());
  1935. Code = serialization::STMT_OMP_FOR_DIRECTIVE;
  1936. }
  1937. void ASTStmtWriter::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
  1938. VisitOMPLoopDirective(D);
  1939. Code = serialization::STMT_OMP_FOR_SIMD_DIRECTIVE;
  1940. }
  1941. void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
  1942. VisitStmt(D);
  1943. VisitOMPExecutableDirective(D);
  1944. Record.writeBool(D->hasCancel());
  1945. Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
  1946. }
  1947. void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
  1948. VisitStmt(D);
  1949. VisitOMPExecutableDirective(D);
  1950. Record.writeBool(D->hasCancel());
  1951. Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
  1952. }
  1953. void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
  1954. VisitStmt(D);
  1955. VisitOMPExecutableDirective(D);
  1956. Code = serialization::STMT_OMP_SINGLE_DIRECTIVE;
  1957. }
  1958. void ASTStmtWriter::VisitOMPMasterDirective(OMPMasterDirective *D) {
  1959. VisitStmt(D);
  1960. VisitOMPExecutableDirective(D);
  1961. Code = serialization::STMT_OMP_MASTER_DIRECTIVE;
  1962. }
  1963. void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
  1964. VisitStmt(D);
  1965. VisitOMPExecutableDirective(D);
  1966. Record.AddDeclarationNameInfo(D->getDirectiveName());
  1967. Code = serialization::STMT_OMP_CRITICAL_DIRECTIVE;
  1968. }
  1969. void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
  1970. VisitOMPLoopDirective(D);
  1971. Record.writeBool(D->hasCancel());
  1972. Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
  1973. }
  1974. void ASTStmtWriter::VisitOMPParallelForSimdDirective(
  1975. OMPParallelForSimdDirective *D) {
  1976. VisitOMPLoopDirective(D);
  1977. Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
  1978. }
  1979. void ASTStmtWriter::VisitOMPParallelMasterDirective(
  1980. OMPParallelMasterDirective *D) {
  1981. VisitStmt(D);
  1982. VisitOMPExecutableDirective(D);
  1983. Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
  1984. }
  1985. void ASTStmtWriter::VisitOMPParallelSectionsDirective(
  1986. OMPParallelSectionsDirective *D) {
  1987. VisitStmt(D);
  1988. VisitOMPExecutableDirective(D);
  1989. Record.writeBool(D->hasCancel());
  1990. Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
  1991. }
  1992. void ASTStmtWriter::VisitOMPTaskDirective(OMPTaskDirective *D) {
  1993. VisitStmt(D);
  1994. VisitOMPExecutableDirective(D);
  1995. Record.writeBool(D->hasCancel());
  1996. Code = serialization::STMT_OMP_TASK_DIRECTIVE;
  1997. }
  1998. void ASTStmtWriter::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
  1999. VisitStmt(D);
  2000. VisitOMPExecutableDirective(D);
  2001. Record.writeBool(D->isXLHSInRHSPart());
  2002. Record.writeBool(D->isPostfixUpdate());
  2003. Code = serialization::STMT_OMP_ATOMIC_DIRECTIVE;
  2004. }
  2005. void ASTStmtWriter::VisitOMPTargetDirective(OMPTargetDirective *D) {
  2006. VisitStmt(D);
  2007. VisitOMPExecutableDirective(D);
  2008. Code = serialization::STMT_OMP_TARGET_DIRECTIVE;
  2009. }
  2010. void ASTStmtWriter::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
  2011. VisitStmt(D);
  2012. VisitOMPExecutableDirective(D);
  2013. Code = serialization::STMT_OMP_TARGET_DATA_DIRECTIVE;
  2014. }
  2015. void ASTStmtWriter::VisitOMPTargetEnterDataDirective(
  2016. OMPTargetEnterDataDirective *D) {
  2017. VisitStmt(D);
  2018. VisitOMPExecutableDirective(D);
  2019. Code = serialization::STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE;
  2020. }
  2021. void ASTStmtWriter::VisitOMPTargetExitDataDirective(
  2022. OMPTargetExitDataDirective *D) {
  2023. VisitStmt(D);
  2024. VisitOMPExecutableDirective(D);
  2025. Code = serialization::STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE;
  2026. }
  2027. void ASTStmtWriter::VisitOMPTargetParallelDirective(
  2028. OMPTargetParallelDirective *D) {
  2029. VisitStmt(D);
  2030. VisitOMPExecutableDirective(D);
  2031. Record.writeBool(D->hasCancel());
  2032. Code = serialization::STMT_OMP_TARGET_PARALLEL_DIRECTIVE;
  2033. }
  2034. void ASTStmtWriter::VisitOMPTargetParallelForDirective(
  2035. OMPTargetParallelForDirective *D) {
  2036. VisitOMPLoopDirective(D);
  2037. Record.writeBool(D->hasCancel());
  2038. Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE;
  2039. }
  2040. void ASTStmtWriter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
  2041. VisitStmt(D);
  2042. VisitOMPExecutableDirective(D);
  2043. Code = serialization::STMT_OMP_TASKYIELD_DIRECTIVE;
  2044. }
  2045. void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
  2046. VisitStmt(D);
  2047. VisitOMPExecutableDirective(D);
  2048. Code = serialization::STMT_OMP_BARRIER_DIRECTIVE;
  2049. }
  2050. void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
  2051. VisitStmt(D);
  2052. Record.push_back(D->getNumClauses());
  2053. VisitOMPExecutableDirective(D);
  2054. Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE;
  2055. }
  2056. void ASTStmtWriter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
  2057. VisitStmt(D);
  2058. VisitOMPExecutableDirective(D);
  2059. Code = serialization::STMT_OMP_TASKGROUP_DIRECTIVE;
  2060. }
  2061. void ASTStmtWriter::VisitOMPFlushDirective(OMPFlushDirective *D) {
  2062. VisitStmt(D);
  2063. VisitOMPExecutableDirective(D);
  2064. Code = serialization::STMT_OMP_FLUSH_DIRECTIVE;
  2065. }
  2066. void ASTStmtWriter::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
  2067. VisitStmt(D);
  2068. VisitOMPExecutableDirective(D);
  2069. Code = serialization::STMT_OMP_DEPOBJ_DIRECTIVE;
  2070. }
  2071. void ASTStmtWriter::VisitOMPScanDirective(OMPScanDirective *D) {
  2072. VisitStmt(D);
  2073. VisitOMPExecutableDirective(D);
  2074. Code = serialization::STMT_OMP_SCAN_DIRECTIVE;
  2075. }
  2076. void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
  2077. VisitStmt(D);
  2078. VisitOMPExecutableDirective(D);
  2079. Code = serialization::STMT_OMP_ORDERED_DIRECTIVE;
  2080. }
  2081. void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
  2082. VisitStmt(D);
  2083. VisitOMPExecutableDirective(D);
  2084. Code = serialization::STMT_OMP_TEAMS_DIRECTIVE;
  2085. }
  2086. void ASTStmtWriter::VisitOMPCancellationPointDirective(
  2087. OMPCancellationPointDirective *D) {
  2088. VisitStmt(D);
  2089. VisitOMPExecutableDirective(D);
  2090. Record.writeEnum(D->getCancelRegion());
  2091. Code = serialization::STMT_OMP_CANCELLATION_POINT_DIRECTIVE;
  2092. }
  2093. void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) {
  2094. VisitStmt(D);
  2095. VisitOMPExecutableDirective(D);
  2096. Record.writeEnum(D->getCancelRegion());
  2097. Code = serialization::STMT_OMP_CANCEL_DIRECTIVE;
  2098. }
  2099. void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
  2100. VisitOMPLoopDirective(D);
  2101. Record.writeBool(D->hasCancel());
  2102. Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE;
  2103. }
  2104. void ASTStmtWriter::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
  2105. VisitOMPLoopDirective(D);
  2106. Code = serialization::STMT_OMP_TASKLOOP_SIMD_DIRECTIVE;
  2107. }
  2108. void ASTStmtWriter::VisitOMPMasterTaskLoopDirective(
  2109. OMPMasterTaskLoopDirective *D) {
  2110. VisitOMPLoopDirective(D);
  2111. Record.writeBool(D->hasCancel());
  2112. Code = serialization::STMT_OMP_MASTER_TASKLOOP_DIRECTIVE;
  2113. }
  2114. void ASTStmtWriter::VisitOMPMasterTaskLoopSimdDirective(
  2115. OMPMasterTaskLoopSimdDirective *D) {
  2116. VisitOMPLoopDirective(D);
  2117. Code = serialization::STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE;
  2118. }
  2119. void ASTStmtWriter::VisitOMPParallelMasterTaskLoopDirective(
  2120. OMPParallelMasterTaskLoopDirective *D) {
  2121. VisitOMPLoopDirective(D);
  2122. Record.writeBool(D->hasCancel());
  2123. Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE;
  2124. }
  2125. void ASTStmtWriter::VisitOMPParallelMasterTaskLoopSimdDirective(
  2126. OMPParallelMasterTaskLoopSimdDirective *D) {
  2127. VisitOMPLoopDirective(D);
  2128. Code = serialization::STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE;
  2129. }
  2130. void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
  2131. VisitOMPLoopDirective(D);
  2132. Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE;
  2133. }
  2134. void ASTStmtWriter::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
  2135. VisitStmt(D);
  2136. VisitOMPExecutableDirective(D);
  2137. Code = serialization::STMT_OMP_TARGET_UPDATE_DIRECTIVE;
  2138. }
  2139. void ASTStmtWriter::VisitOMPDistributeParallelForDirective(
  2140. OMPDistributeParallelForDirective *D) {
  2141. VisitOMPLoopDirective(D);
  2142. Record.writeBool(D->hasCancel());
  2143. Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
  2144. }
  2145. void ASTStmtWriter::VisitOMPDistributeParallelForSimdDirective(
  2146. OMPDistributeParallelForSimdDirective *D) {
  2147. VisitOMPLoopDirective(D);
  2148. Code = serialization::STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
  2149. }
  2150. void ASTStmtWriter::VisitOMPDistributeSimdDirective(
  2151. OMPDistributeSimdDirective *D) {
  2152. VisitOMPLoopDirective(D);
  2153. Code = serialization::STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE;
  2154. }
  2155. void ASTStmtWriter::VisitOMPTargetParallelForSimdDirective(
  2156. OMPTargetParallelForSimdDirective *D) {
  2157. VisitOMPLoopDirective(D);
  2158. Code = serialization::STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE;
  2159. }
  2160. void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
  2161. VisitOMPLoopDirective(D);
  2162. Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE;
  2163. }
  2164. void ASTStmtWriter::VisitOMPTeamsDistributeDirective(
  2165. OMPTeamsDistributeDirective *D) {
  2166. VisitOMPLoopDirective(D);
  2167. Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE;
  2168. }
  2169. void ASTStmtWriter::VisitOMPTeamsDistributeSimdDirective(
  2170. OMPTeamsDistributeSimdDirective *D) {
  2171. VisitOMPLoopDirective(D);
  2172. Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
  2173. }
  2174. void ASTStmtWriter::VisitOMPTeamsDistributeParallelForSimdDirective(
  2175. OMPTeamsDistributeParallelForSimdDirective *D) {
  2176. VisitOMPLoopDirective(D);
  2177. Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
  2178. }
  2179. void ASTStmtWriter::VisitOMPTeamsDistributeParallelForDirective(
  2180. OMPTeamsDistributeParallelForDirective *D) {
  2181. VisitOMPLoopDirective(D);
  2182. Record.writeBool(D->hasCancel());
  2183. Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
  2184. }
  2185. void ASTStmtWriter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
  2186. VisitStmt(D);
  2187. VisitOMPExecutableDirective(D);
  2188. Code = serialization::STMT_OMP_TARGET_TEAMS_DIRECTIVE;
  2189. }
  2190. void ASTStmtWriter::VisitOMPTargetTeamsDistributeDirective(
  2191. OMPTargetTeamsDistributeDirective *D) {
  2192. VisitOMPLoopDirective(D);
  2193. Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE;
  2194. }
  2195. void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForDirective(
  2196. OMPTargetTeamsDistributeParallelForDirective *D) {
  2197. VisitOMPLoopDirective(D);
  2198. Record.writeBool(D->hasCancel());
  2199. Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE;
  2200. }
  2201. void ASTStmtWriter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
  2202. OMPTargetTeamsDistributeParallelForSimdDirective *D) {
  2203. VisitOMPLoopDirective(D);
  2204. Code = serialization::
  2205. STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE;
  2206. }
  2207. void ASTStmtWriter::VisitOMPTargetTeamsDistributeSimdDirective(
  2208. OMPTargetTeamsDistributeSimdDirective *D) {
  2209. VisitOMPLoopDirective(D);
  2210. Code = serialization::STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE;
  2211. }
  2212. void ASTStmtWriter::VisitOMPInteropDirective(OMPInteropDirective *D) {
  2213. VisitStmt(D);
  2214. VisitOMPExecutableDirective(D);
  2215. Code = serialization::STMT_OMP_INTEROP_DIRECTIVE;
  2216. }
  2217. void ASTStmtWriter::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
  2218. VisitStmt(D);
  2219. VisitOMPExecutableDirective(D);
  2220. Record.AddSourceLocation(D->getTargetCallLoc());
  2221. Code = serialization::STMT_OMP_DISPATCH_DIRECTIVE;
  2222. }
  2223. void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
  2224. VisitStmt(D);
  2225. VisitOMPExecutableDirective(D);
  2226. Code = serialization::STMT_OMP_MASKED_DIRECTIVE;
  2227. }
  2228. void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
  2229. VisitOMPLoopDirective(D);
  2230. Code = serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE;
  2231. }
  2232. //===----------------------------------------------------------------------===//
  2233. // ASTWriter Implementation
  2234. //===----------------------------------------------------------------------===//
  2235. unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
  2236. assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
  2237. "SwitchCase recorded twice");
  2238. unsigned NextID = SwitchCaseIDs.size();
  2239. SwitchCaseIDs[S] = NextID;
  2240. return NextID;
  2241. }
  2242. unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
  2243. assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
  2244. "SwitchCase hasn't been seen yet");
  2245. return SwitchCaseIDs[S];
  2246. }
  2247. void ASTWriter::ClearSwitchCaseIDs() {
  2248. SwitchCaseIDs.clear();
  2249. }
  2250. /// Write the given substatement or subexpression to the
  2251. /// bitstream.
  2252. void ASTWriter::WriteSubStmt(Stmt *S) {
  2253. RecordData Record;
  2254. ASTStmtWriter Writer(*this, Record);
  2255. ++NumStatements;
  2256. if (!S) {
  2257. Stream.EmitRecord(serialization::STMT_NULL_PTR, Record);
  2258. return;
  2259. }
  2260. llvm::DenseMap<Stmt *, uint64_t>::iterator I = SubStmtEntries.find(S);
  2261. if (I != SubStmtEntries.end()) {
  2262. Record.push_back(I->second);
  2263. Stream.EmitRecord(serialization::STMT_REF_PTR, Record);
  2264. return;
  2265. }
  2266. #ifndef NDEBUG
  2267. assert(!ParentStmts.count(S) && "There is a Stmt cycle!");
  2268. struct ParentStmtInserterRAII {
  2269. Stmt *S;
  2270. llvm::DenseSet<Stmt *> &ParentStmts;
  2271. ParentStmtInserterRAII(Stmt *S, llvm::DenseSet<Stmt *> &ParentStmts)
  2272. : S(S), ParentStmts(ParentStmts) {
  2273. ParentStmts.insert(S);
  2274. }
  2275. ~ParentStmtInserterRAII() {
  2276. ParentStmts.erase(S);
  2277. }
  2278. };
  2279. ParentStmtInserterRAII ParentStmtInserter(S, ParentStmts);
  2280. #endif
  2281. Writer.Visit(S);
  2282. uint64_t Offset = Writer.Emit();
  2283. SubStmtEntries[S] = Offset;
  2284. }
  2285. /// Flush all of the statements that have been added to the
  2286. /// queue via AddStmt().
  2287. void ASTRecordWriter::FlushStmts() {
  2288. // We expect to be the only consumer of the two temporary statement maps,
  2289. // assert that they are empty.
  2290. assert(Writer->SubStmtEntries.empty() && "unexpected entries in sub-stmt map");
  2291. assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt map");
  2292. for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
  2293. Writer->WriteSubStmt(StmtsToEmit[I]);
  2294. assert(N == StmtsToEmit.size() && "record modified while being written!");
  2295. // Note that we are at the end of a full expression. Any
  2296. // expression records that follow this one are part of a different
  2297. // expression.
  2298. Writer->Stream.EmitRecord(serialization::STMT_STOP, ArrayRef<uint32_t>());
  2299. Writer->SubStmtEntries.clear();
  2300. Writer->ParentStmts.clear();
  2301. }
  2302. StmtsToEmit.clear();
  2303. }
  2304. void ASTRecordWriter::FlushSubStmts() {
  2305. // For a nested statement, write out the substatements in reverse order (so
  2306. // that a simple stack machine can be used when loading), and don't emit a
  2307. // STMT_STOP after each one.
  2308. for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
  2309. Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
  2310. assert(N == StmtsToEmit.size() && "record modified while being written!");
  2311. }
  2312. StmtsToEmit.clear();
  2313. }