1 //===--- PCHReaderStmt.cpp - Stmt/Expr Deserialization ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Statement/expression deserialization. This implements the
11 // PCHReader::ReadStmt method.
13 //===----------------------------------------------------------------------===//
15 #include "clang/Frontend/PCHReader.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/StmtVisitor.h"
18 using namespace clang
;
21 class PCHStmtReader
: public StmtVisitor
<PCHStmtReader
, unsigned> {
23 const PCHReader::RecordData
&Record
;
25 llvm::SmallVectorImpl
<Stmt
*> &StmtStack
;
28 PCHStmtReader(PCHReader
&Reader
, const PCHReader::RecordData
&Record
,
29 unsigned &Idx
, llvm::SmallVectorImpl
<Stmt
*> &StmtStack
)
30 : Reader(Reader
), Record(Record
), Idx(Idx
), StmtStack(StmtStack
) { }
32 /// \brief The number of record fields required for the Stmt class
34 static const unsigned NumStmtFields
= 0;
36 /// \brief The number of record fields required for the Expr class
38 static const unsigned NumExprFields
= NumStmtFields
+ 3;
40 // Each of the Visit* functions reads in part of the expression
41 // from the given record and the current expression stack, then
42 // return the total number of operands that it read from the
45 unsigned VisitStmt(Stmt
*S
);
46 unsigned VisitNullStmt(NullStmt
*S
);
47 unsigned VisitCompoundStmt(CompoundStmt
*S
);
48 unsigned VisitSwitchCase(SwitchCase
*S
);
49 unsigned VisitCaseStmt(CaseStmt
*S
);
50 unsigned VisitDefaultStmt(DefaultStmt
*S
);
51 unsigned VisitLabelStmt(LabelStmt
*S
);
52 unsigned VisitIfStmt(IfStmt
*S
);
53 unsigned VisitSwitchStmt(SwitchStmt
*S
);
54 unsigned VisitWhileStmt(WhileStmt
*S
);
55 unsigned VisitDoStmt(DoStmt
*S
);
56 unsigned VisitForStmt(ForStmt
*S
);
57 unsigned VisitGotoStmt(GotoStmt
*S
);
58 unsigned VisitIndirectGotoStmt(IndirectGotoStmt
*S
);
59 unsigned VisitContinueStmt(ContinueStmt
*S
);
60 unsigned VisitBreakStmt(BreakStmt
*S
);
61 unsigned VisitReturnStmt(ReturnStmt
*S
);
62 unsigned VisitDeclStmt(DeclStmt
*S
);
63 unsigned VisitAsmStmt(AsmStmt
*S
);
64 unsigned VisitExpr(Expr
*E
);
65 unsigned VisitPredefinedExpr(PredefinedExpr
*E
);
66 unsigned VisitDeclRefExpr(DeclRefExpr
*E
);
67 unsigned VisitIntegerLiteral(IntegerLiteral
*E
);
68 unsigned VisitFloatingLiteral(FloatingLiteral
*E
);
69 unsigned VisitImaginaryLiteral(ImaginaryLiteral
*E
);
70 unsigned VisitStringLiteral(StringLiteral
*E
);
71 unsigned VisitCharacterLiteral(CharacterLiteral
*E
);
72 unsigned VisitParenExpr(ParenExpr
*E
);
73 unsigned VisitUnaryOperator(UnaryOperator
*E
);
74 unsigned VisitOffsetOfExpr(OffsetOfExpr
*E
);
75 unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr
*E
);
76 unsigned VisitArraySubscriptExpr(ArraySubscriptExpr
*E
);
77 unsigned VisitCallExpr(CallExpr
*E
);
78 unsigned VisitMemberExpr(MemberExpr
*E
);
79 unsigned VisitCastExpr(CastExpr
*E
);
80 unsigned VisitBinaryOperator(BinaryOperator
*E
);
81 unsigned VisitCompoundAssignOperator(CompoundAssignOperator
*E
);
82 unsigned VisitConditionalOperator(ConditionalOperator
*E
);
83 unsigned VisitImplicitCastExpr(ImplicitCastExpr
*E
);
84 unsigned VisitExplicitCastExpr(ExplicitCastExpr
*E
);
85 unsigned VisitCStyleCastExpr(CStyleCastExpr
*E
);
86 unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr
*E
);
87 unsigned VisitExtVectorElementExpr(ExtVectorElementExpr
*E
);
88 unsigned VisitInitListExpr(InitListExpr
*E
);
89 unsigned VisitDesignatedInitExpr(DesignatedInitExpr
*E
);
90 unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr
*E
);
91 unsigned VisitVAArgExpr(VAArgExpr
*E
);
92 unsigned VisitAddrLabelExpr(AddrLabelExpr
*E
);
93 unsigned VisitStmtExpr(StmtExpr
*E
);
94 unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr
*E
);
95 unsigned VisitChooseExpr(ChooseExpr
*E
);
96 unsigned VisitGNUNullExpr(GNUNullExpr
*E
);
97 unsigned VisitShuffleVectorExpr(ShuffleVectorExpr
*E
);
98 unsigned VisitBlockExpr(BlockExpr
*E
);
99 unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr
*E
);
100 unsigned VisitObjCStringLiteral(ObjCStringLiteral
*E
);
101 unsigned VisitObjCEncodeExpr(ObjCEncodeExpr
*E
);
102 unsigned VisitObjCSelectorExpr(ObjCSelectorExpr
*E
);
103 unsigned VisitObjCProtocolExpr(ObjCProtocolExpr
*E
);
104 unsigned VisitObjCIvarRefExpr(ObjCIvarRefExpr
*E
);
105 unsigned VisitObjCPropertyRefExpr(ObjCPropertyRefExpr
*E
);
106 unsigned VisitObjCImplicitSetterGetterRefExpr(
107 ObjCImplicitSetterGetterRefExpr
*E
);
108 unsigned VisitObjCMessageExpr(ObjCMessageExpr
*E
);
109 unsigned VisitObjCSuperExpr(ObjCSuperExpr
*E
);
110 unsigned VisitObjCIsaExpr(ObjCIsaExpr
*E
);
112 unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt
*);
113 unsigned VisitObjCAtCatchStmt(ObjCAtCatchStmt
*);
114 unsigned VisitObjCAtFinallyStmt(ObjCAtFinallyStmt
*);
115 unsigned VisitObjCAtTryStmt(ObjCAtTryStmt
*);
116 unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt
*);
117 unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt
*);
119 unsigned VisitCXXOperatorCallExpr(CXXOperatorCallExpr
*E
);
120 unsigned VisitCXXConstructExpr(CXXConstructExpr
*E
);
121 unsigned VisitCXXNamedCastExpr(CXXNamedCastExpr
*E
);
122 unsigned VisitCXXStaticCastExpr(CXXStaticCastExpr
*E
);
123 unsigned VisitCXXDynamicCastExpr(CXXDynamicCastExpr
*E
);
124 unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr
*E
);
125 unsigned VisitCXXConstCastExpr(CXXConstCastExpr
*E
);
126 unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr
*E
);
127 unsigned VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr
*E
);
128 unsigned VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr
*E
);
129 unsigned VisitCXXTypeidExpr(CXXTypeidExpr
*E
);
130 unsigned VisitCXXThisExpr(CXXThisExpr
*E
);
131 unsigned VisitCXXThrowExpr(CXXThrowExpr
*E
);
132 unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr
*E
);
133 unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr
*E
);
135 unsigned VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr
*E
);
136 unsigned VisitCXXNewExpr(CXXNewExpr
*E
);
137 unsigned VisitCXXDeleteExpr(CXXDeleteExpr
*E
);
139 unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries
*E
);
141 unsigned VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr
*E
);
142 unsigned VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr
*E
);
146 unsigned PCHStmtReader::VisitStmt(Stmt
*S
) {
147 assert(Idx
== NumStmtFields
&& "Incorrect statement field count");
151 unsigned PCHStmtReader::VisitNullStmt(NullStmt
*S
) {
153 S
->setSemiLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
157 unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt
*S
) {
159 unsigned NumStmts
= Record
[Idx
++];
160 S
->setStmts(*Reader
.getContext(),
161 StmtStack
.data() + StmtStack
.size() - NumStmts
, NumStmts
);
162 S
->setLBracLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
163 S
->setRBracLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
167 unsigned PCHStmtReader::VisitSwitchCase(SwitchCase
*S
) {
169 Reader
.RecordSwitchCaseID(S
, Record
[Idx
++]);
173 unsigned PCHStmtReader::VisitCaseStmt(CaseStmt
*S
) {
175 S
->setLHS(cast
<Expr
>(StmtStack
[StmtStack
.size() - 3]));
176 S
->setRHS(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
177 S
->setSubStmt(StmtStack
.back());
178 S
->setCaseLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
179 S
->setEllipsisLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
180 S
->setColonLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
184 unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt
*S
) {
186 S
->setSubStmt(StmtStack
.back());
187 S
->setDefaultLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
188 S
->setColonLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
192 unsigned PCHStmtReader::VisitLabelStmt(LabelStmt
*S
) {
194 S
->setID(Reader
.GetIdentifierInfo(Record
, Idx
));
195 S
->setSubStmt(StmtStack
.back());
196 S
->setIdentLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
197 Reader
.RecordLabelStmt(S
, Record
[Idx
++]);
201 unsigned PCHStmtReader::VisitIfStmt(IfStmt
*S
) {
203 S
->setConditionVariable(*Reader
.getContext(),
204 cast_or_null
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
205 S
->setCond(cast
<Expr
>(StmtStack
[StmtStack
.size() - 3]));
206 S
->setThen(StmtStack
[StmtStack
.size() - 2]);
207 S
->setElse(StmtStack
[StmtStack
.size() - 1]);
208 S
->setIfLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
209 S
->setElseLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
213 unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt
*S
) {
215 S
->setConditionVariable(*Reader
.getContext(),
216 cast_or_null
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
217 S
->setCond(cast
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
218 S
->setBody(StmtStack
.back());
219 S
->setSwitchLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
220 SwitchCase
*PrevSC
= 0;
221 for (unsigned N
= Record
.size(); Idx
!= N
; ++Idx
) {
222 SwitchCase
*SC
= Reader
.getSwitchCaseWithID(Record
[Idx
]);
224 PrevSC
->setNextSwitchCase(SC
);
226 S
->setSwitchCaseList(SC
);
228 // Retain this SwitchCase, since SwitchStmt::addSwitchCase() would
229 // normally retain it (but we aren't calling addSwitchCase).
236 unsigned PCHStmtReader::VisitWhileStmt(WhileStmt
*S
) {
238 S
->setConditionVariable(*Reader
.getContext(),
239 cast_or_null
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
240 S
->setCond(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
241 S
->setBody(StmtStack
.back());
242 S
->setWhileLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
246 unsigned PCHStmtReader::VisitDoStmt(DoStmt
*S
) {
248 S
->setCond(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
249 S
->setBody(StmtStack
.back());
250 S
->setDoLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
251 S
->setWhileLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
252 S
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
256 unsigned PCHStmtReader::VisitForStmt(ForStmt
*S
) {
258 S
->setInit(StmtStack
[StmtStack
.size() - 4]);
259 S
->setCond(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 3]));
260 S
->setConditionVariable(*Reader
.getContext(),
261 cast_or_null
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
262 S
->setInc(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
263 S
->setBody(StmtStack
.back());
264 S
->setForLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
265 S
->setLParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
266 S
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
270 unsigned PCHStmtReader::VisitGotoStmt(GotoStmt
*S
) {
272 Reader
.SetLabelOf(S
, Record
[Idx
++]);
273 S
->setGotoLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
274 S
->setLabelLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
278 unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt
*S
) {
280 S
->setGotoLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
281 S
->setStarLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
282 S
->setTarget(cast_or_null
<Expr
>(StmtStack
.back()));
286 unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt
*S
) {
288 S
->setContinueLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
292 unsigned PCHStmtReader::VisitBreakStmt(BreakStmt
*S
) {
294 S
->setBreakLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
298 unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt
*S
) {
300 S
->setRetValue(cast_or_null
<Expr
>(StmtStack
.back()));
301 S
->setReturnLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
302 S
->setNRVOCandidate(cast_or_null
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
306 unsigned PCHStmtReader::VisitDeclStmt(DeclStmt
*S
) {
308 S
->setStartLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
309 S
->setEndLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
311 if (Idx
+ 1 == Record
.size()) {
312 // Single declaration
313 S
->setDeclGroup(DeclGroupRef(Reader
.GetDecl(Record
[Idx
++])));
315 llvm::SmallVector
<Decl
*, 16> Decls
;
316 Decls
.reserve(Record
.size() - Idx
);
317 for (unsigned N
= Record
.size(); Idx
!= N
; ++Idx
)
318 Decls
.push_back(Reader
.GetDecl(Record
[Idx
]));
319 S
->setDeclGroup(DeclGroupRef(DeclGroup::Create(*Reader
.getContext(),
326 unsigned PCHStmtReader::VisitAsmStmt(AsmStmt
*S
) {
328 unsigned NumOutputs
= Record
[Idx
++];
329 unsigned NumInputs
= Record
[Idx
++];
330 unsigned NumClobbers
= Record
[Idx
++];
331 S
->setAsmLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
332 S
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
333 S
->setVolatile(Record
[Idx
++]);
334 S
->setSimple(Record
[Idx
++]);
335 S
->setMSAsm(Record
[Idx
++]);
338 = StmtStack
.size() - (NumOutputs
*2 + NumInputs
*2 + NumClobbers
+ 1);
339 S
->setAsmString(cast_or_null
<StringLiteral
>(StmtStack
[StackIdx
++]));
341 // Outputs and inputs
342 llvm::SmallVector
<IdentifierInfo
*, 16> Names
;
343 llvm::SmallVector
<StringLiteral
*, 16> Constraints
;
344 llvm::SmallVector
<Stmt
*, 16> Exprs
;
345 for (unsigned I
= 0, N
= NumOutputs
+ NumInputs
; I
!= N
; ++I
) {
346 Names
.push_back(Reader
.GetIdentifierInfo(Record
, Idx
));
347 Constraints
.push_back(cast_or_null
<StringLiteral
>(StmtStack
[StackIdx
++]));
348 Exprs
.push_back(StmtStack
[StackIdx
++]);
352 llvm::SmallVector
<StringLiteral
*, 16> Clobbers
;
353 for (unsigned I
= 0; I
!= NumClobbers
; ++I
)
354 Clobbers
.push_back(cast_or_null
<StringLiteral
>(StmtStack
[StackIdx
++]));
356 S
->setOutputsAndInputsAndClobbers(*Reader
.getContext(),
357 Names
.data(), Constraints
.data(),
358 Exprs
.data(), NumOutputs
, NumInputs
,
359 Clobbers
.data(), NumClobbers
);
361 assert(StackIdx
== StmtStack
.size() && "Error deserializing AsmStmt");
362 return NumOutputs
*2 + NumInputs
*2 + NumClobbers
+ 1;
365 unsigned PCHStmtReader::VisitExpr(Expr
*E
) {
367 E
->setType(Reader
.GetType(Record
[Idx
++]));
368 E
->setTypeDependent(Record
[Idx
++]);
369 E
->setValueDependent(Record
[Idx
++]);
370 assert(Idx
== NumExprFields
&& "Incorrect expression field count");
374 unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr
*E
) {
376 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
377 E
->setIdentType((PredefinedExpr::IdentType
)Record
[Idx
++]);
381 unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr
*E
) {
383 E
->setDecl(cast
<ValueDecl
>(Reader
.GetDecl(Record
[Idx
++])));
384 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
385 // FIXME: read qualifier
386 // FIXME: read explicit template arguments
390 unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral
*E
) {
392 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
393 E
->setValue(Reader
.ReadAPInt(Record
, Idx
));
397 unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral
*E
) {
399 E
->setValue(Reader
.ReadAPFloat(Record
, Idx
));
400 E
->setExact(Record
[Idx
++]);
401 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
405 unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral
*E
) {
407 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
411 unsigned PCHStmtReader::VisitStringLiteral(StringLiteral
*E
) {
413 unsigned Len
= Record
[Idx
++];
414 assert(Record
[Idx
] == E
->getNumConcatenated() &&
415 "Wrong number of concatenated tokens!");
417 E
->setWide(Record
[Idx
++]);
420 llvm::SmallString
<16> Str(&Record
[Idx
], &Record
[Idx
] + Len
);
421 E
->setString(*Reader
.getContext(), Str
.str());
424 // Read source locations
425 for (unsigned I
= 0, N
= E
->getNumConcatenated(); I
!= N
; ++I
)
426 E
->setStrTokenLoc(I
, SourceLocation::getFromRawEncoding(Record
[Idx
++]));
431 unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral
*E
) {
433 E
->setValue(Record
[Idx
++]);
434 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
435 E
->setWide(Record
[Idx
++]);
439 unsigned PCHStmtReader::VisitParenExpr(ParenExpr
*E
) {
441 E
->setLParen(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
442 E
->setRParen(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
443 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
447 unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator
*E
) {
449 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
450 E
->setOpcode((UnaryOperator::Opcode
)Record
[Idx
++]);
451 E
->setOperatorLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
455 unsigned PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr
*E
) {
456 typedef OffsetOfExpr::OffsetOfNode Node
;
458 assert(E
->getNumComponents() == Record
[Idx
]);
460 assert(E
->getNumExpressions() == Record
[Idx
]);
462 E
->setOperatorLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
463 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
464 E
->setTypeSourceInfo(Reader
.GetTypeSourceInfo(Record
, Idx
));
465 for (unsigned I
= 0, N
= E
->getNumComponents(); I
!= N
; ++I
) {
466 Node::Kind Kind
= static_cast<Node::Kind
>(Record
[Idx
++]);
467 SourceLocation Start
= SourceLocation::getFromRawEncoding(Record
[Idx
++]);
468 SourceLocation End
= SourceLocation::getFromRawEncoding(Record
[Idx
++]);
471 E
->setComponent(I
, Node(Start
, Record
[Idx
++], End
));
477 dyn_cast_or_null
<FieldDecl
>(Reader
.GetDecl(Record
[Idx
++])),
481 case Node::Identifier
:
482 E
->setComponent(I
, Node(Start
, Reader
.GetIdentifier(Record
[Idx
++]), End
));
486 // FIXME: Implement this!
487 llvm_unreachable("PCH for offsetof(base-specifier) not implemented");
492 for (unsigned I
= 0, N
= E
->getNumExpressions(); I
!= N
; ++I
)
493 E
->setIndexExpr(I
, cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - N
+ I
]));
495 return E
->getNumExpressions();
498 unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr
*E
) {
500 E
->setSizeof(Record
[Idx
++]);
501 if (Record
[Idx
] == 0) {
502 E
->setArgument(cast
<Expr
>(StmtStack
.back()));
505 E
->setArgument(Reader
.GetTypeSourceInfo(Record
, Idx
));
507 E
->setOperatorLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
508 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
509 return E
->isArgumentType()? 0 : 1;
512 unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr
*E
) {
514 E
->setLHS(cast
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
515 E
->setRHS(cast
<Expr
>(StmtStack
[StmtStack
.size() - 1]));
516 E
->setRBracketLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
520 unsigned PCHStmtReader::VisitCallExpr(CallExpr
*E
) {
522 E
->setNumArgs(*Reader
.getContext(), Record
[Idx
++]);
523 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
524 E
->setCallee(cast
<Expr
>(StmtStack
[StmtStack
.size() - E
->getNumArgs() - 1]));
525 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
)
526 E
->setArg(I
, cast
<Expr
>(StmtStack
[StmtStack
.size() - N
+ I
]));
527 return E
->getNumArgs() + 1;
530 unsigned PCHStmtReader::VisitMemberExpr(MemberExpr
*E
) {
532 E
->setBase(cast
<Expr
>(StmtStack
.back()));
533 E
->setMemberDecl(cast
<ValueDecl
>(Reader
.GetDecl(Record
[Idx
++])));
534 E
->setMemberLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
535 E
->setArrow(Record
[Idx
++]);
539 unsigned PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr
*E
) {
541 E
->setBase(cast
<Expr
>(StmtStack
.back()));
542 E
->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
543 E
->setArrow(Record
[Idx
++]);
547 unsigned PCHStmtReader::VisitCastExpr(CastExpr
*E
) {
549 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
550 E
->setCastKind((CastExpr::CastKind
)Record
[Idx
++]);
554 unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator
*E
) {
556 E
->setLHS(cast
<Expr
>(StmtStack
.end()[-2]));
557 E
->setRHS(cast
<Expr
>(StmtStack
.end()[-1]));
558 E
->setOpcode((BinaryOperator::Opcode
)Record
[Idx
++]);
559 E
->setOperatorLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
563 unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator
*E
) {
564 VisitBinaryOperator(E
);
565 E
->setComputationLHSType(Reader
.GetType(Record
[Idx
++]));
566 E
->setComputationResultType(Reader
.GetType(Record
[Idx
++]));
570 unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator
*E
) {
572 E
->setCond(cast
<Expr
>(StmtStack
[StmtStack
.size() - 3]));
573 E
->setLHS(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
574 E
->setRHS(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 1]));
575 E
->setQuestionLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
576 E
->setColonLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
580 unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr
*E
) {
582 E
->setLvalueCast(Record
[Idx
++]);
586 unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr
*E
) {
588 E
->setTypeInfoAsWritten(Reader
.GetTypeSourceInfo(Record
, Idx
));
592 unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr
*E
) {
593 VisitExplicitCastExpr(E
);
594 E
->setLParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
595 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
599 unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr
*E
) {
601 E
->setLParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
602 E
->setTypeSourceInfo(Reader
.GetTypeSourceInfo(Record
, Idx
));
603 E
->setInitializer(cast
<Expr
>(StmtStack
.back()));
604 E
->setFileScope(Record
[Idx
++]);
608 unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr
*E
) {
610 E
->setBase(cast
<Expr
>(StmtStack
.back()));
611 E
->setAccessor(Reader
.GetIdentifierInfo(Record
, Idx
));
612 E
->setAccessorLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
616 unsigned PCHStmtReader::VisitInitListExpr(InitListExpr
*E
) {
618 unsigned NumInits
= Record
[Idx
++];
619 E
->reserveInits(*Reader
.getContext(), NumInits
);
620 for (unsigned I
= 0; I
!= NumInits
; ++I
)
621 E
->updateInit(*Reader
.getContext(), I
,
622 cast
<Expr
>(StmtStack
[StmtStack
.size() - NumInits
- 1 + I
]));
623 E
->setSyntacticForm(cast_or_null
<InitListExpr
>(StmtStack
.back()));
624 E
->setLBraceLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
625 E
->setRBraceLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
626 E
->setInitializedFieldInUnion(
627 cast_or_null
<FieldDecl
>(Reader
.GetDecl(Record
[Idx
++])));
628 E
->sawArrayRangeDesignator(Record
[Idx
++]);
632 unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr
*E
) {
633 typedef DesignatedInitExpr::Designator Designator
;
636 unsigned NumSubExprs
= Record
[Idx
++];
637 assert(NumSubExprs
== E
->getNumSubExprs() && "Wrong number of subexprs");
638 for (unsigned I
= 0; I
!= NumSubExprs
; ++I
)
639 E
->setSubExpr(I
, cast
<Expr
>(StmtStack
[StmtStack
.size() - NumSubExprs
+ I
]));
640 E
->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
641 E
->setGNUSyntax(Record
[Idx
++]);
643 llvm::SmallVector
<Designator
, 4> Designators
;
644 while (Idx
< Record
.size()) {
645 switch ((pch::DesignatorTypes
)Record
[Idx
++]) {
646 case pch::DESIG_FIELD_DECL
: {
647 FieldDecl
*Field
= cast
<FieldDecl
>(Reader
.GetDecl(Record
[Idx
++]));
648 SourceLocation DotLoc
649 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
650 SourceLocation FieldLoc
651 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
652 Designators
.push_back(Designator(Field
->getIdentifier(), DotLoc
,
654 Designators
.back().setField(Field
);
658 case pch::DESIG_FIELD_NAME
: {
659 const IdentifierInfo
*Name
= Reader
.GetIdentifierInfo(Record
, Idx
);
660 SourceLocation DotLoc
661 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
662 SourceLocation FieldLoc
663 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
664 Designators
.push_back(Designator(Name
, DotLoc
, FieldLoc
));
668 case pch::DESIG_ARRAY
: {
669 unsigned Index
= Record
[Idx
++];
670 SourceLocation LBracketLoc
671 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
672 SourceLocation RBracketLoc
673 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
674 Designators
.push_back(Designator(Index
, LBracketLoc
, RBracketLoc
));
678 case pch::DESIG_ARRAY_RANGE
: {
679 unsigned Index
= Record
[Idx
++];
680 SourceLocation LBracketLoc
681 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
682 SourceLocation EllipsisLoc
683 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
684 SourceLocation RBracketLoc
685 = SourceLocation::getFromRawEncoding(Record
[Idx
++]);
686 Designators
.push_back(Designator(Index
, LBracketLoc
, EllipsisLoc
,
692 E
->setDesignators(*Reader
.getContext(),
693 Designators
.data(), Designators
.size());
698 unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr
*E
) {
703 unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr
*E
) {
705 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
706 E
->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
707 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
711 unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr
*E
) {
713 E
->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
714 E
->setLabelLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
715 Reader
.SetLabelOf(E
, Record
[Idx
++]);
719 unsigned PCHStmtReader::VisitStmtExpr(StmtExpr
*E
) {
721 E
->setLParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
722 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
723 E
->setSubStmt(cast_or_null
<CompoundStmt
>(StmtStack
.back()));
727 unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr
*E
) {
729 E
->setArgType1(Reader
.GetType(Record
[Idx
++]));
730 E
->setArgType2(Reader
.GetType(Record
[Idx
++]));
731 E
->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
732 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
736 unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr
*E
) {
738 E
->setCond(cast
<Expr
>(StmtStack
[StmtStack
.size() - 3]));
739 E
->setLHS(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
740 E
->setRHS(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 1]));
741 E
->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
742 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
746 unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr
*E
) {
748 E
->setTokenLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
752 unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr
*E
) {
754 unsigned NumExprs
= Record
[Idx
++];
755 E
->setExprs(*Reader
.getContext(),
756 (Expr
**)&StmtStack
[StmtStack
.size() - NumExprs
], NumExprs
);
757 E
->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
758 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
762 unsigned PCHStmtReader::VisitBlockExpr(BlockExpr
*E
) {
764 E
->setBlockDecl(cast_or_null
<BlockDecl
>(Reader
.GetDecl(Record
[Idx
++])));
765 E
->setHasBlockDeclRefExprs(Record
[Idx
++]);
769 unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr
*E
) {
771 E
->setDecl(cast
<ValueDecl
>(Reader
.GetDecl(Record
[Idx
++])));
772 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
773 E
->setByRef(Record
[Idx
++]);
774 E
->setConstQualAdded(Record
[Idx
++]);
775 E
->setCopyConstructorExpr(cast_or_null
<Expr
>(StmtStack
.back()));
779 //===----------------------------------------------------------------------===//
780 // Objective-C Expressions and Statements
782 unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral
*E
) {
784 E
->setString(cast
<StringLiteral
>(StmtStack
.back()));
785 E
->setAtLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
789 unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr
*E
) {
791 E
->setEncodedTypeSourceInfo(Reader
.GetTypeSourceInfo(Record
, Idx
));
792 E
->setAtLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
793 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
797 unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr
*E
) {
799 E
->setSelector(Reader
.GetSelector(Record
, Idx
));
800 E
->setAtLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
801 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
805 unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr
*E
) {
807 E
->setProtocol(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
808 E
->setAtLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
809 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
813 unsigned PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr
*E
) {
815 E
->setDecl(cast
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
816 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
817 E
->setBase(cast
<Expr
>(StmtStack
.back()));
818 E
->setIsArrow(Record
[Idx
++]);
819 E
->setIsFreeIvar(Record
[Idx
++]);
823 unsigned PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr
*E
) {
825 E
->setProperty(cast
<ObjCPropertyDecl
>(Reader
.GetDecl(Record
[Idx
++])));
826 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
827 E
->setBase(cast
<Expr
>(StmtStack
.back()));
831 unsigned PCHStmtReader::VisitObjCImplicitSetterGetterRefExpr(
832 ObjCImplicitSetterGetterRefExpr
*E
) {
835 cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
837 cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
839 cast_or_null
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
840 E
->setBase(cast_or_null
<Expr
>(StmtStack
.back()));
841 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
842 E
->setClassLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
846 unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr
*E
) {
848 assert(Record
[Idx
] == E
->getNumArgs());
850 ObjCMessageExpr::ReceiverKind Kind
851 = static_cast<ObjCMessageExpr::ReceiverKind
>(Record
[Idx
++]);
853 case ObjCMessageExpr::Instance
:
854 E
->setInstanceReceiver(
855 cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - E
->getNumArgs() - 1]));
858 case ObjCMessageExpr::Class
:
859 E
->setClassReceiver(Reader
.GetTypeSourceInfo(Record
, Idx
));
862 case ObjCMessageExpr::SuperClass
:
863 case ObjCMessageExpr::SuperInstance
: {
864 QualType T
= Reader
.GetType(Record
[Idx
++]);
865 SourceLocation SuperLoc
= SourceLocation::getFromRawEncoding(Record
[Idx
++]);
866 E
->setSuper(SuperLoc
, T
, Kind
== ObjCMessageExpr::SuperInstance
);
871 assert(Kind
== E
->getReceiverKind());
874 E
->setMethodDecl(cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
876 E
->setSelector(Reader
.GetSelector(Record
, Idx
));
878 E
->setLeftLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
879 E
->setRightLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
881 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
)
882 E
->setArg(I
, cast
<Expr
>(StmtStack
[StmtStack
.size() - N
+ I
]));
883 return E
->getNumArgs() + (Kind
== ObjCMessageExpr::Instance
);
886 unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr
*E
) {
888 E
->setLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
892 unsigned PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt
*S
) {
894 S
->setElement(cast_or_null
<Stmt
>(StmtStack
[StmtStack
.size() - 3]));
895 S
->setCollection(cast_or_null
<Expr
>(StmtStack
[StmtStack
.size() - 2]));
896 S
->setBody(cast_or_null
<Stmt
>(StmtStack
[StmtStack
.size() - 1]));
897 S
->setForLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
898 S
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
902 unsigned PCHStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt
*S
) {
904 S
->setCatchBody(cast_or_null
<Stmt
>(StmtStack
.back()));
905 S
->setCatchParamDecl(cast_or_null
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
906 S
->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
907 S
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
911 unsigned PCHStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt
*S
) {
913 S
->setFinallyBody(StmtStack
.back());
914 S
->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
918 unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt
*S
) {
920 assert(Record
[Idx
] == S
->getNumCatchStmts());
922 bool HasFinally
= Record
[Idx
++];
923 for (unsigned I
= 0, N
= S
->getNumCatchStmts(); I
!= N
; ++I
) {
924 unsigned Offset
= StmtStack
.size() - N
- HasFinally
+ I
;
925 S
->setCatchStmt(I
, cast_or_null
<ObjCAtCatchStmt
>(StmtStack
[Offset
]));
929 = StmtStack
.size() - S
->getNumCatchStmts() - HasFinally
- 1;
930 S
->setTryBody(cast_or_null
<Stmt
>(StmtStack
[TryOffset
]));
932 S
->setFinallyStmt(cast_or_null
<Stmt
>(StmtStack
[StmtStack
.size() - 1]));
933 S
->setAtTryLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
934 return 1 + S
->getNumCatchStmts() + HasFinally
;
937 unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt
*S
) {
939 S
->setSynchExpr(cast_or_null
<Stmt
>(StmtStack
[StmtStack
.size() - 2]));
940 S
->setSynchBody(cast_or_null
<Stmt
>(StmtStack
[StmtStack
.size() - 1]));
941 S
->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
945 unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt
*S
) {
947 S
->setThrowExpr(StmtStack
.back());
948 S
->setThrowLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
952 //===----------------------------------------------------------------------===//
953 // C++ Expressions and Statements
955 unsigned PCHStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr
*E
) {
956 unsigned num
= VisitCallExpr(E
);
957 E
->setOperator((OverloadedOperatorKind
)Record
[Idx
++]);
961 unsigned PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr
*E
) {
963 assert(Record
[Idx
] == E
->getNumArgs() &&
964 "Read wrong record during creation ?");
966 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
)
967 E
->setArg(I
, cast
<Expr
>(StmtStack
[StmtStack
.size() - N
+ I
]));
968 E
->setConstructor(cast
<CXXConstructorDecl
>(Reader
.GetDecl(Record
[Idx
++])));
969 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
970 E
->setElidable(Record
[Idx
++]);
971 E
->setRequiresZeroInitialization(Record
[Idx
++]);
972 E
->setConstructionKind((CXXConstructExpr::ConstructionKind
)Record
[Idx
++]);
973 return E
->getNumArgs();
976 unsigned PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr
*E
) {
977 unsigned num
= VisitExplicitCastExpr(E
);
978 E
->setOperatorLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
982 unsigned PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr
*E
) {
983 return VisitCXXNamedCastExpr(E
);
986 unsigned PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr
*E
) {
987 return VisitCXXNamedCastExpr(E
);
990 unsigned PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr
*E
) {
991 return VisitCXXNamedCastExpr(E
);
994 unsigned PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr
*E
) {
995 return VisitCXXNamedCastExpr(E
);
998 unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr
*E
) {
999 unsigned num
= VisitExplicitCastExpr(E
);
1000 E
->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1001 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1005 unsigned PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr
*E
) {
1007 E
->setValue(Record
[Idx
++]);
1008 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1012 unsigned PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr
*E
) {
1014 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1018 unsigned PCHStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr
*E
) {
1020 E
->setSourceRange(Reader
.ReadSourceRange(Record
, Idx
));
1021 if (E
->isTypeOperand()) { // typeid(int)
1022 E
->setTypeOperandSourceInfo(Reader
.GetTypeSourceInfo(Record
, Idx
));
1027 E
->setExprOperand(cast
<Expr
>(StmtStack
.back()));
1031 unsigned PCHStmtReader::VisitCXXThisExpr(CXXThisExpr
*E
) {
1033 E
->setLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1034 E
->setImplicit(Record
[Idx
++]);
1038 unsigned PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr
*E
) {
1040 E
->setThrowLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1041 E
->setSubExpr(cast_or_null
<Expr
>(StmtStack
.back()));
1045 unsigned PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr
*E
) {
1047 E
->setUsedLocation(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1048 bool HasStoredExpr
= Record
[Idx
++];
1049 if (!HasStoredExpr
) return 0;
1050 E
->setExpr(cast
<Expr
>(StmtStack
.back()));
1054 unsigned PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr
*E
) {
1056 E
->setTemporary(Reader
.ReadCXXTemporary(Record
, Idx
));
1057 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
1061 unsigned PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr
*E
) {
1063 E
->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1064 E
->setRParenLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1068 unsigned PCHStmtReader::VisitCXXNewExpr(CXXNewExpr
*E
) {
1070 E
->setGlobalNew(Record
[Idx
++]);
1071 E
->setParenTypeId(Record
[Idx
++]);
1072 E
->setHasInitializer(Record
[Idx
++]);
1073 bool isArray
= Record
[Idx
++];
1074 unsigned NumPlacementArgs
= Record
[Idx
++];
1075 unsigned NumCtorArgs
= Record
[Idx
++];
1076 E
->setOperatorNew(cast_or_null
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++])));
1077 E
->setOperatorDelete(
1078 cast_or_null
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++])));
1080 cast_or_null
<CXXConstructorDecl
>(Reader
.GetDecl(Record
[Idx
++])));
1081 E
->setStartLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1082 E
->setEndLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1084 E
->AllocateArgsArray(*Reader
.getContext(), isArray
, NumPlacementArgs
,
1087 // Install all the subexpressions.
1088 unsigned TotalSubExprs
= E
->raw_arg_end()-E
->raw_arg_begin();
1089 unsigned SSIdx
= StmtStack
.size()-TotalSubExprs
;
1090 for (CXXNewExpr::raw_arg_iterator I
= E
->raw_arg_begin(),e
= E
->raw_arg_end();
1092 *I
= StmtStack
[SSIdx
++];
1094 return TotalSubExprs
;
1097 unsigned PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr
*E
) {
1099 E
->setGlobalDelete(Record
[Idx
++]);
1100 E
->setArrayForm(Record
[Idx
++]);
1101 E
->setOperatorDelete(
1102 cast_or_null
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++])));
1103 E
->setArgument(cast_or_null
<Expr
>(StmtStack
.back()));
1104 E
->setStartLoc(SourceLocation::getFromRawEncoding(Record
[Idx
++]));
1108 unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries
*E
) {
1110 unsigned NumTemps
= Record
[Idx
++];
1112 E
->setNumTemporaries(*Reader
.getContext(), NumTemps
);
1113 for (unsigned i
= 0; i
!= NumTemps
; ++i
)
1114 E
->setTemporary(i
, Reader
.ReadCXXTemporary(Record
, Idx
));
1116 E
->setSubExpr(cast
<Expr
>(StmtStack
.back()));
1121 PCHStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr
*E
){
1124 unsigned NumTemplateArgs
= Record
[Idx
++];
1125 assert((NumTemplateArgs
!= 0) == E
->hasExplicitTemplateArgs() &&
1126 "Read wrong record during creation ?");
1127 if (E
->hasExplicitTemplateArgs()) {
1128 TemplateArgumentListInfo ArgInfo
;
1129 ArgInfo
.setLAngleLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1130 ArgInfo
.setRAngleLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1131 for (unsigned i
= 0; i
!= NumTemplateArgs
; ++i
)
1132 ArgInfo
.addArgument(Reader
.ReadTemplateArgumentLoc(Record
, Idx
));
1133 E
->initializeTemplateArgumentsFrom(ArgInfo
);
1136 E
->setBase(cast_or_null
<Expr
>(StmtStack
.back()));
1137 E
->setBaseType(Reader
.GetType(Record
[Idx
++]));
1138 E
->setArrow(Record
[Idx
++]);
1139 E
->setOperatorLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1140 E
->setQualifier(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
1141 E
->setQualifierRange(Reader
.ReadSourceRange(Record
, Idx
));
1142 E
->setFirstQualifierFoundInScope(
1143 cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++])));
1144 E
->setMember(Reader
.ReadDeclarationName(Record
, Idx
));
1145 E
->setMemberLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1151 PCHStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr
*E
) {
1153 assert(Record
[Idx
] == E
->arg_size() && "Read wrong record during creation ?");
1155 for (unsigned I
= 0, N
= E
->arg_size(); I
!= N
; ++I
)
1156 E
->setArg(I
, cast
<Expr
>(StmtStack
[StmtStack
.size() - N
+ I
]));
1157 E
->setTypeBeginLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1158 E
->setTypeAsWritten(Reader
.GetType(Record
[Idx
++]));
1159 E
->setLParenLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1160 E
->setRParenLoc(Reader
.ReadSourceLocation(Record
, Idx
));
1161 return E
->arg_size();
1165 // Within the bitstream, expressions are stored in Reverse Polish
1166 // Notation, with each of the subexpressions preceding the
1167 // expression they are stored in. To evaluate expressions, we
1168 // continue reading expressions and placing them on the stack, with
1169 // expressions having operands removing those operands from the
1170 // stack. Evaluation terminates when we see a STMT_STOP record, and
1171 // the single remaining expression on the stack is our result.
1172 Stmt
*PCHReader::ReadStmt(llvm::BitstreamCursor
&Cursor
) {
1175 llvm::SmallVector
<Stmt
*, 16> StmtStack
;
1176 PCHStmtReader
Reader(*this, Record
, Idx
, StmtStack
);
1177 Stmt::EmptyShell Empty
;
1180 unsigned Code
= Cursor
.ReadCode();
1181 if (Code
== llvm::bitc::END_BLOCK
) {
1182 if (Cursor
.ReadBlockEnd()) {
1183 Error("error at end of block in PCH file");
1189 if (Code
== llvm::bitc::ENTER_SUBBLOCK
) {
1190 // No known subblocks, always skip them.
1191 Cursor
.ReadSubBlockID();
1192 if (Cursor
.SkipBlock()) {
1193 Error("malformed block record in PCH file");
1199 if (Code
== llvm::bitc::DEFINE_ABBREV
) {
1200 Cursor
.ReadAbbrevRecord();
1207 bool Finished
= false;
1208 switch ((pch::StmtCode
)Cursor
.ReadRecord(Code
, Record
)) {
1209 case pch::STMT_STOP
:
1213 case pch::STMT_NULL_PTR
:
1217 case pch::STMT_NULL
:
1218 S
= new (Context
) NullStmt(Empty
);
1221 case pch::STMT_COMPOUND
:
1222 S
= new (Context
) CompoundStmt(Empty
);
1225 case pch::STMT_CASE
:
1226 S
= new (Context
) CaseStmt(Empty
);
1229 case pch::STMT_DEFAULT
:
1230 S
= new (Context
) DefaultStmt(Empty
);
1233 case pch::STMT_LABEL
:
1234 S
= new (Context
) LabelStmt(Empty
);
1238 S
= new (Context
) IfStmt(Empty
);
1241 case pch::STMT_SWITCH
:
1242 S
= new (Context
) SwitchStmt(Empty
);
1245 case pch::STMT_WHILE
:
1246 S
= new (Context
) WhileStmt(Empty
);
1250 S
= new (Context
) DoStmt(Empty
);
1254 S
= new (Context
) ForStmt(Empty
);
1257 case pch::STMT_GOTO
:
1258 S
= new (Context
) GotoStmt(Empty
);
1261 case pch::STMT_INDIRECT_GOTO
:
1262 S
= new (Context
) IndirectGotoStmt(Empty
);
1265 case pch::STMT_CONTINUE
:
1266 S
= new (Context
) ContinueStmt(Empty
);
1269 case pch::STMT_BREAK
:
1270 S
= new (Context
) BreakStmt(Empty
);
1273 case pch::STMT_RETURN
:
1274 S
= new (Context
) ReturnStmt(Empty
);
1277 case pch::STMT_DECL
:
1278 S
= new (Context
) DeclStmt(Empty
);
1282 S
= new (Context
) AsmStmt(Empty
);
1285 case pch::EXPR_PREDEFINED
:
1286 S
= new (Context
) PredefinedExpr(Empty
);
1289 case pch::EXPR_DECL_REF
:
1290 S
= new (Context
) DeclRefExpr(Empty
);
1293 case pch::EXPR_INTEGER_LITERAL
:
1294 S
= new (Context
) IntegerLiteral(Empty
);
1297 case pch::EXPR_FLOATING_LITERAL
:
1298 S
= new (Context
) FloatingLiteral(Empty
);
1301 case pch::EXPR_IMAGINARY_LITERAL
:
1302 S
= new (Context
) ImaginaryLiteral(Empty
);
1305 case pch::EXPR_STRING_LITERAL
:
1306 S
= StringLiteral::CreateEmpty(*Context
,
1307 Record
[PCHStmtReader::NumExprFields
+ 1]);
1310 case pch::EXPR_CHARACTER_LITERAL
:
1311 S
= new (Context
) CharacterLiteral(Empty
);
1314 case pch::EXPR_PAREN
:
1315 S
= new (Context
) ParenExpr(Empty
);
1318 case pch::EXPR_UNARY_OPERATOR
:
1319 S
= new (Context
) UnaryOperator(Empty
);
1322 case pch::EXPR_OFFSETOF
:
1323 S
= OffsetOfExpr::CreateEmpty(*Context
,
1324 Record
[PCHStmtReader::NumExprFields
],
1325 Record
[PCHStmtReader::NumExprFields
+ 1]);
1328 case pch::EXPR_SIZEOF_ALIGN_OF
:
1329 S
= new (Context
) SizeOfAlignOfExpr(Empty
);
1332 case pch::EXPR_ARRAY_SUBSCRIPT
:
1333 S
= new (Context
) ArraySubscriptExpr(Empty
);
1336 case pch::EXPR_CALL
:
1337 S
= new (Context
) CallExpr(*Context
, Stmt::CallExprClass
, Empty
);
1340 case pch::EXPR_MEMBER
:
1341 S
= new (Context
) MemberExpr(Empty
);
1344 case pch::EXPR_BINARY_OPERATOR
:
1345 S
= new (Context
) BinaryOperator(Empty
);
1348 case pch::EXPR_COMPOUND_ASSIGN_OPERATOR
:
1349 S
= new (Context
) CompoundAssignOperator(Empty
);
1352 case pch::EXPR_CONDITIONAL_OPERATOR
:
1353 S
= new (Context
) ConditionalOperator(Empty
);
1356 case pch::EXPR_IMPLICIT_CAST
:
1357 S
= new (Context
) ImplicitCastExpr(Empty
);
1360 case pch::EXPR_CSTYLE_CAST
:
1361 S
= new (Context
) CStyleCastExpr(Empty
);
1364 case pch::EXPR_COMPOUND_LITERAL
:
1365 S
= new (Context
) CompoundLiteralExpr(Empty
);
1368 case pch::EXPR_EXT_VECTOR_ELEMENT
:
1369 S
= new (Context
) ExtVectorElementExpr(Empty
);
1372 case pch::EXPR_INIT_LIST
:
1373 S
= new (Context
) InitListExpr(*getContext(), Empty
);
1376 case pch::EXPR_DESIGNATED_INIT
:
1377 S
= DesignatedInitExpr::CreateEmpty(*Context
,
1378 Record
[PCHStmtReader::NumExprFields
] - 1);
1382 case pch::EXPR_IMPLICIT_VALUE_INIT
:
1383 S
= new (Context
) ImplicitValueInitExpr(Empty
);
1386 case pch::EXPR_VA_ARG
:
1387 S
= new (Context
) VAArgExpr(Empty
);
1390 case pch::EXPR_ADDR_LABEL
:
1391 S
= new (Context
) AddrLabelExpr(Empty
);
1394 case pch::EXPR_STMT
:
1395 S
= new (Context
) StmtExpr(Empty
);
1398 case pch::EXPR_TYPES_COMPATIBLE
:
1399 S
= new (Context
) TypesCompatibleExpr(Empty
);
1402 case pch::EXPR_CHOOSE
:
1403 S
= new (Context
) ChooseExpr(Empty
);
1406 case pch::EXPR_GNU_NULL
:
1407 S
= new (Context
) GNUNullExpr(Empty
);
1410 case pch::EXPR_SHUFFLE_VECTOR
:
1411 S
= new (Context
) ShuffleVectorExpr(Empty
);
1414 case pch::EXPR_BLOCK
:
1415 S
= new (Context
) BlockExpr(Empty
);
1418 case pch::EXPR_BLOCK_DECL_REF
:
1419 S
= new (Context
) BlockDeclRefExpr(Empty
);
1422 case pch::EXPR_OBJC_STRING_LITERAL
:
1423 S
= new (Context
) ObjCStringLiteral(Empty
);
1425 case pch::EXPR_OBJC_ENCODE
:
1426 S
= new (Context
) ObjCEncodeExpr(Empty
);
1428 case pch::EXPR_OBJC_SELECTOR_EXPR
:
1429 S
= new (Context
) ObjCSelectorExpr(Empty
);
1431 case pch::EXPR_OBJC_PROTOCOL_EXPR
:
1432 S
= new (Context
) ObjCProtocolExpr(Empty
);
1434 case pch::EXPR_OBJC_IVAR_REF_EXPR
:
1435 S
= new (Context
) ObjCIvarRefExpr(Empty
);
1437 case pch::EXPR_OBJC_PROPERTY_REF_EXPR
:
1438 S
= new (Context
) ObjCPropertyRefExpr(Empty
);
1440 case pch::EXPR_OBJC_KVC_REF_EXPR
:
1441 S
= new (Context
) ObjCImplicitSetterGetterRefExpr(Empty
);
1443 case pch::EXPR_OBJC_MESSAGE_EXPR
:
1444 S
= ObjCMessageExpr::CreateEmpty(*Context
,
1445 Record
[PCHStmtReader::NumExprFields
]);
1447 case pch::EXPR_OBJC_SUPER_EXPR
:
1448 S
= new (Context
) ObjCSuperExpr(Empty
);
1450 case pch::EXPR_OBJC_ISA
:
1451 S
= new (Context
) ObjCIsaExpr(Empty
);
1453 case pch::STMT_OBJC_FOR_COLLECTION
:
1454 S
= new (Context
) ObjCForCollectionStmt(Empty
);
1456 case pch::STMT_OBJC_CATCH
:
1457 S
= new (Context
) ObjCAtCatchStmt(Empty
);
1459 case pch::STMT_OBJC_FINALLY
:
1460 S
= new (Context
) ObjCAtFinallyStmt(Empty
);
1462 case pch::STMT_OBJC_AT_TRY
:
1463 S
= ObjCAtTryStmt::CreateEmpty(*Context
,
1464 Record
[PCHStmtReader::NumStmtFields
],
1465 Record
[PCHStmtReader::NumStmtFields
+ 1]);
1467 case pch::STMT_OBJC_AT_SYNCHRONIZED
:
1468 S
= new (Context
) ObjCAtSynchronizedStmt(Empty
);
1470 case pch::STMT_OBJC_AT_THROW
:
1471 S
= new (Context
) ObjCAtThrowStmt(Empty
);
1474 case pch::EXPR_CXX_OPERATOR_CALL
:
1475 S
= new (Context
) CXXOperatorCallExpr(*Context
, Empty
);
1478 case pch::EXPR_CXX_MEMBER_CALL
:
1479 S
= new (Context
) CXXMemberCallExpr(*Context
, Empty
);
1482 case pch::EXPR_CXX_CONSTRUCT
:
1483 S
= new (Context
) CXXConstructExpr(Empty
, *Context
,
1484 Record
[PCHStmtReader::NumExprFields
]);
1487 case pch::EXPR_CXX_STATIC_CAST
:
1488 S
= new (Context
) CXXStaticCastExpr(Empty
);
1491 case pch::EXPR_CXX_DYNAMIC_CAST
:
1492 S
= new (Context
) CXXDynamicCastExpr(Empty
);
1495 case pch::EXPR_CXX_REINTERPRET_CAST
:
1496 S
= new (Context
) CXXReinterpretCastExpr(Empty
);
1499 case pch::EXPR_CXX_CONST_CAST
:
1500 S
= new (Context
) CXXConstCastExpr(Empty
);
1503 case pch::EXPR_CXX_FUNCTIONAL_CAST
:
1504 S
= new (Context
) CXXFunctionalCastExpr(Empty
);
1507 case pch::EXPR_CXX_BOOL_LITERAL
:
1508 S
= new (Context
) CXXBoolLiteralExpr(Empty
);
1511 case pch::EXPR_CXX_NULL_PTR_LITERAL
:
1512 S
= new (Context
) CXXNullPtrLiteralExpr(Empty
);
1514 case pch::EXPR_CXX_TYPEID_EXPR
:
1515 S
= new (Context
) CXXTypeidExpr(Empty
, true);
1517 case pch::EXPR_CXX_TYPEID_TYPE
:
1518 S
= new (Context
) CXXTypeidExpr(Empty
, false);
1520 case pch::EXPR_CXX_THIS
:
1521 S
= new (Context
) CXXThisExpr(Empty
);
1523 case pch::EXPR_CXX_THROW
:
1524 S
= new (Context
) CXXThrowExpr(Empty
);
1526 case pch::EXPR_CXX_DEFAULT_ARG
:
1527 S
= new (Context
) CXXDefaultArgExpr(Empty
);
1529 case pch::EXPR_CXX_BIND_TEMPORARY
:
1530 S
= new (Context
) CXXBindTemporaryExpr(Empty
);
1533 case pch::EXPR_CXX_ZERO_INIT_VALUE
:
1534 S
= new (Context
) CXXZeroInitValueExpr(Empty
);
1536 case pch::EXPR_CXX_NEW
:
1537 S
= new (Context
) CXXNewExpr(Empty
);
1539 case pch::EXPR_CXX_DELETE
:
1540 S
= new (Context
) CXXDeleteExpr(Empty
);
1543 case pch::EXPR_CXX_EXPR_WITH_TEMPORARIES
:
1544 S
= new (Context
) CXXExprWithTemporaries(Empty
);
1547 case pch::EXPR_CXX_DEPENDENT_SCOPE_MEMBER
:
1548 S
= CXXDependentScopeMemberExpr::CreateEmpty(*Context
,
1549 Record
[PCHStmtReader::NumExprFields
]);
1552 case pch::EXPR_CXX_UNRESOLVED_CONSTRUCT
:
1553 S
= CXXUnresolvedConstructExpr::CreateEmpty(*Context
,
1554 Record
[PCHStmtReader::NumExprFields
]);
1558 // We hit a STMT_STOP, so we're done with this expression.
1562 ++NumStatementsRead
;
1565 unsigned NumSubStmts
= Reader
.Visit(S
);
1566 while (NumSubStmts
> 0) {
1567 StmtStack
.pop_back();
1572 assert(Idx
== Record
.size() && "Invalid deserialization of statement");
1573 StmtStack
.push_back(S
);
1575 assert(StmtStack
.size() == 1 && "Extra expressions on stack!");
1576 return StmtStack
.back();