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