Coverage Report

Created: 2024-01-17 10:31

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