ASTWriterStmt.cpp 89 KB

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