Coverage Report

Created: 2022-01-18 06:27

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