ASTWriterStmt.cpp 90 KB

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