2009-04-27 14:20:01 +08:00
|
|
|
//===--- PCHWriterStmt.cpp - Statement and Expression Serialization -------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements serialization for Statements and Expressions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Frontend/PCHWriter.h"
|
2009-09-10 07:08:42 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-04-27 14:20:01 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/StmtVisitor.h"
|
|
|
|
#include "llvm/Bitcode/BitstreamWriter.h"
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Statement/expression serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PCHStmtWriter : public StmtVisitor<PCHStmtWriter, void> {
|
|
|
|
PCHWriter &Writer;
|
|
|
|
PCHWriter::RecordData &Record;
|
|
|
|
|
|
|
|
public:
|
|
|
|
pch::StmtCode Code;
|
|
|
|
|
|
|
|
PCHStmtWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
|
|
|
|
: Writer(Writer), Record(Record) { }
|
2010-06-28 17:31:48 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
AddExplicitTemplateArgumentList(const ExplicitTemplateArgumentList &Args);
|
2009-04-27 14:20:01 +08:00
|
|
|
|
|
|
|
void VisitStmt(Stmt *S);
|
|
|
|
void VisitNullStmt(NullStmt *S);
|
|
|
|
void VisitCompoundStmt(CompoundStmt *S);
|
|
|
|
void VisitSwitchCase(SwitchCase *S);
|
|
|
|
void VisitCaseStmt(CaseStmt *S);
|
|
|
|
void VisitDefaultStmt(DefaultStmt *S);
|
|
|
|
void VisitLabelStmt(LabelStmt *S);
|
|
|
|
void VisitIfStmt(IfStmt *S);
|
|
|
|
void VisitSwitchStmt(SwitchStmt *S);
|
|
|
|
void VisitWhileStmt(WhileStmt *S);
|
|
|
|
void VisitDoStmt(DoStmt *S);
|
|
|
|
void VisitForStmt(ForStmt *S);
|
|
|
|
void VisitGotoStmt(GotoStmt *S);
|
|
|
|
void VisitIndirectGotoStmt(IndirectGotoStmt *S);
|
|
|
|
void VisitContinueStmt(ContinueStmt *S);
|
|
|
|
void VisitBreakStmt(BreakStmt *S);
|
|
|
|
void VisitReturnStmt(ReturnStmt *S);
|
|
|
|
void VisitDeclStmt(DeclStmt *S);
|
|
|
|
void VisitAsmStmt(AsmStmt *S);
|
|
|
|
void VisitExpr(Expr *E);
|
|
|
|
void VisitPredefinedExpr(PredefinedExpr *E);
|
|
|
|
void VisitDeclRefExpr(DeclRefExpr *E);
|
|
|
|
void VisitIntegerLiteral(IntegerLiteral *E);
|
|
|
|
void VisitFloatingLiteral(FloatingLiteral *E);
|
|
|
|
void VisitImaginaryLiteral(ImaginaryLiteral *E);
|
|
|
|
void VisitStringLiteral(StringLiteral *E);
|
|
|
|
void VisitCharacterLiteral(CharacterLiteral *E);
|
|
|
|
void VisitParenExpr(ParenExpr *E);
|
|
|
|
void VisitUnaryOperator(UnaryOperator *E);
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
void VisitOffsetOfExpr(OffsetOfExpr *E);
|
2009-04-27 14:20:01 +08:00
|
|
|
void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
|
|
|
|
void VisitArraySubscriptExpr(ArraySubscriptExpr *E);
|
|
|
|
void VisitCallExpr(CallExpr *E);
|
|
|
|
void VisitMemberExpr(MemberExpr *E);
|
|
|
|
void VisitCastExpr(CastExpr *E);
|
|
|
|
void VisitBinaryOperator(BinaryOperator *E);
|
|
|
|
void VisitCompoundAssignOperator(CompoundAssignOperator *E);
|
|
|
|
void VisitConditionalOperator(ConditionalOperator *E);
|
|
|
|
void VisitImplicitCastExpr(ImplicitCastExpr *E);
|
|
|
|
void VisitExplicitCastExpr(ExplicitCastExpr *E);
|
|
|
|
void VisitCStyleCastExpr(CStyleCastExpr *E);
|
|
|
|
void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
|
|
|
|
void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
|
|
|
|
void VisitInitListExpr(InitListExpr *E);
|
|
|
|
void VisitDesignatedInitExpr(DesignatedInitExpr *E);
|
|
|
|
void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
|
|
|
|
void VisitVAArgExpr(VAArgExpr *E);
|
|
|
|
void VisitAddrLabelExpr(AddrLabelExpr *E);
|
|
|
|
void VisitStmtExpr(StmtExpr *E);
|
|
|
|
void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
|
|
|
|
void VisitChooseExpr(ChooseExpr *E);
|
|
|
|
void VisitGNUNullExpr(GNUNullExpr *E);
|
|
|
|
void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
|
|
|
|
void VisitBlockExpr(BlockExpr *E);
|
|
|
|
void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
// Objective-C Expressions
|
|
|
|
void VisitObjCStringLiteral(ObjCStringLiteral *E);
|
|
|
|
void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
|
|
|
|
void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
|
|
|
|
void VisitObjCProtocolExpr(ObjCProtocolExpr *E);
|
|
|
|
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
|
|
|
|
void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E);
|
2009-08-21 01:02:02 +08:00
|
|
|
void VisitObjCImplicitSetterGetterRefExpr(
|
|
|
|
ObjCImplicitSetterGetterRefExpr *E);
|
2009-04-27 14:20:01 +08:00
|
|
|
void VisitObjCMessageExpr(ObjCMessageExpr *E);
|
|
|
|
void VisitObjCSuperExpr(ObjCSuperExpr *E);
|
2009-07-25 01:54:45 +08:00
|
|
|
void VisitObjCIsaExpr(ObjCIsaExpr *E);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
// Objective-C Statements
|
2009-04-27 14:20:01 +08:00
|
|
|
void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
|
|
|
|
void VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
|
|
|
|
void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *);
|
|
|
|
void VisitObjCAtTryStmt(ObjCAtTryStmt *);
|
|
|
|
void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
|
|
|
|
void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
|
2009-07-14 11:19:21 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// C++ Statements
|
2009-07-14 11:19:21 +08:00
|
|
|
void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
|
2010-05-09 13:36:05 +08:00
|
|
|
void VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
|
2009-09-10 07:08:42 +08:00
|
|
|
void VisitCXXConstructExpr(CXXConstructExpr *E);
|
2010-01-17 05:21:01 +08:00
|
|
|
void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
|
|
|
|
void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
|
|
|
|
void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
|
|
|
|
void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
|
|
|
|
void VisitCXXConstCastExpr(CXXConstCastExpr *E);
|
|
|
|
void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
|
2010-02-07 14:32:43 +08:00
|
|
|
void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
|
|
|
|
void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
|
2010-05-09 14:03:39 +08:00
|
|
|
void VisitCXXTypeidExpr(CXXTypeidExpr *E);
|
2010-05-09 14:15:05 +08:00
|
|
|
void VisitCXXThisExpr(CXXThisExpr *E);
|
|
|
|
void VisitCXXThrowExpr(CXXThrowExpr *E);
|
2010-05-09 14:40:08 +08:00
|
|
|
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
|
2010-05-10 08:25:06 +08:00
|
|
|
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
|
2010-06-24 16:57:31 +08:00
|
|
|
|
2010-05-10 09:22:27 +08:00
|
|
|
void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
|
|
|
|
void VisitCXXNewExpr(CXXNewExpr *E);
|
2010-06-23 01:07:59 +08:00
|
|
|
void VisitCXXDeleteExpr(CXXDeleteExpr *E);
|
2010-06-24 16:57:31 +08:00
|
|
|
|
2010-05-10 08:25:06 +08:00
|
|
|
void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
|
2010-06-24 16:57:31 +08:00
|
|
|
void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
|
|
|
|
void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
|
2010-06-25 17:03:26 +08:00
|
|
|
|
|
|
|
void VisitOverloadExpr(OverloadExpr *E);
|
|
|
|
void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
|
2010-06-25 17:03:34 +08:00
|
|
|
void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
|
2009-04-27 14:20:01 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-06-28 17:31:48 +08:00
|
|
|
/// \brief Return the number of Exprs contained in the given TemplateArgument.
|
|
|
|
static unsigned NumExprsContainedIn(const TemplateArgument &Arg) {
|
|
|
|
switch (Arg.getKind()) {
|
|
|
|
default: break;
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
return 1;
|
|
|
|
case TemplateArgument::Pack: {
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end();
|
|
|
|
I != E; ++I)
|
|
|
|
Count += NumExprsContainedIn(*I);
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Return the number of Exprs contained in the given
|
|
|
|
/// ExplicitTemplateArgumentList.
|
|
|
|
static unsigned NumExprsContainedIn(const ExplicitTemplateArgumentList &Args) {
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (unsigned i=0; i != Args.NumTemplateArgs; ++i) {
|
|
|
|
const TemplateArgumentLoc &ArgLoc = Args.getTemplateArgs()[i];
|
|
|
|
const TemplateArgument &TemplA = ArgLoc.getArgument();
|
|
|
|
Count += NumExprsContainedIn(TemplA);
|
|
|
|
if (TemplA.getKind() == TemplateArgument::Expression &&
|
|
|
|
TemplA.getAsExpr() != ArgLoc.getLocInfo().getAsExpr())
|
|
|
|
++Count; // 1 in TemplateArgumentLocInfo.
|
|
|
|
}
|
|
|
|
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::
|
|
|
|
AddExplicitTemplateArgumentList(const ExplicitTemplateArgumentList &Args) {
|
|
|
|
Record.push_back(NumExprsContainedIn(Args));
|
|
|
|
Writer.AddSourceLocation(Args.LAngleLoc, Record);
|
|
|
|
Writer.AddSourceLocation(Args.RAngleLoc, Record);
|
|
|
|
for (unsigned i=0; i != Args.NumTemplateArgs; ++i)
|
|
|
|
Writer.AddTemplateArgumentLoc(Args.getTemplateArgs()[i], Record);
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void PCHStmtWriter::VisitStmt(Stmt *S) {
|
2009-04-27 14:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitNullStmt(NullStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.AddSourceLocation(S->getSemiLoc(), Record);
|
|
|
|
Code = pch::STMT_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Record.push_back(S->size());
|
|
|
|
for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end();
|
|
|
|
CS != CSEnd; ++CS)
|
|
|
|
Writer.WriteSubStmt(*CS);
|
|
|
|
Writer.AddSourceLocation(S->getLBracLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getRBracLoc(), Record);
|
|
|
|
Code = pch::STMT_COMPOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitSwitchCase(SwitchCase *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Record.push_back(Writer.RecordSwitchCaseID(S));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCaseStmt(CaseStmt *S) {
|
|
|
|
VisitSwitchCase(S);
|
|
|
|
Writer.WriteSubStmt(S->getLHS());
|
|
|
|
Writer.WriteSubStmt(S->getRHS());
|
|
|
|
Writer.WriteSubStmt(S->getSubStmt());
|
|
|
|
Writer.AddSourceLocation(S->getCaseLoc(), Record);
|
2009-05-16 07:57:33 +08:00
|
|
|
Writer.AddSourceLocation(S->getEllipsisLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getColonLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::STMT_CASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitDefaultStmt(DefaultStmt *S) {
|
|
|
|
VisitSwitchCase(S);
|
|
|
|
Writer.WriteSubStmt(S->getSubStmt());
|
|
|
|
Writer.AddSourceLocation(S->getDefaultLoc(), Record);
|
2009-05-16 07:57:33 +08:00
|
|
|
Writer.AddSourceLocation(S->getColonLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::STMT_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitLabelStmt(LabelStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.AddIdentifierRef(S->getID(), Record);
|
|
|
|
Writer.WriteSubStmt(S->getSubStmt());
|
|
|
|
Writer.AddSourceLocation(S->getIdentLoc(), Record);
|
|
|
|
Record.push_back(Writer.GetLabelID(S));
|
|
|
|
Code = pch::STMT_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitIfStmt(IfStmt *S) {
|
|
|
|
VisitStmt(S);
|
2009-11-24 07:44:04 +08:00
|
|
|
Writer.AddDeclRef(S->getConditionVariable(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getCond());
|
|
|
|
Writer.WriteSubStmt(S->getThen());
|
|
|
|
Writer.WriteSubStmt(S->getElse());
|
|
|
|
Writer.AddSourceLocation(S->getIfLoc(), Record);
|
2009-05-16 02:53:42 +08:00
|
|
|
Writer.AddSourceLocation(S->getElseLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::STMT_IF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitSwitchStmt(SwitchStmt *S) {
|
|
|
|
VisitStmt(S);
|
2009-11-25 01:07:59 +08:00
|
|
|
Writer.AddDeclRef(S->getConditionVariable(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getCond());
|
|
|
|
Writer.WriteSubStmt(S->getBody());
|
|
|
|
Writer.AddSourceLocation(S->getSwitchLoc(), Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
for (SwitchCase *SC = S->getSwitchCaseList(); SC;
|
2009-04-27 14:20:01 +08:00
|
|
|
SC = SC->getNextSwitchCase())
|
|
|
|
Record.push_back(Writer.getSwitchCaseID(SC));
|
|
|
|
Code = pch::STMT_SWITCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitWhileStmt(WhileStmt *S) {
|
|
|
|
VisitStmt(S);
|
2009-11-25 05:15:44 +08:00
|
|
|
Writer.AddDeclRef(S->getConditionVariable(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getCond());
|
|
|
|
Writer.WriteSubStmt(S->getBody());
|
|
|
|
Writer.AddSourceLocation(S->getWhileLoc(), Record);
|
|
|
|
Code = pch::STMT_WHILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitDoStmt(DoStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.WriteSubStmt(S->getCond());
|
|
|
|
Writer.WriteSubStmt(S->getBody());
|
|
|
|
Writer.AddSourceLocation(S->getDoLoc(), Record);
|
2009-05-16 05:56:04 +08:00
|
|
|
Writer.AddSourceLocation(S->getWhileLoc(), Record);
|
2009-06-13 07:04:47 +08:00
|
|
|
Writer.AddSourceLocation(S->getRParenLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::STMT_DO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitForStmt(ForStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.WriteSubStmt(S->getInit());
|
|
|
|
Writer.WriteSubStmt(S->getCond());
|
2009-11-25 08:27:52 +08:00
|
|
|
Writer.AddDeclRef(S->getConditionVariable(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getInc());
|
|
|
|
Writer.WriteSubStmt(S->getBody());
|
|
|
|
Writer.AddSourceLocation(S->getForLoc(), Record);
|
2009-05-16 06:12:32 +08:00
|
|
|
Writer.AddSourceLocation(S->getLParenLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getRParenLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::STMT_FOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitGotoStmt(GotoStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Record.push_back(Writer.GetLabelID(S->getLabel()));
|
|
|
|
Writer.AddSourceLocation(S->getGotoLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getLabelLoc(), Record);
|
|
|
|
Code = pch::STMT_GOTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.AddSourceLocation(S->getGotoLoc(), Record);
|
2009-05-16 08:20:29 +08:00
|
|
|
Writer.AddSourceLocation(S->getStarLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getTarget());
|
|
|
|
Code = pch::STMT_INDIRECT_GOTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitContinueStmt(ContinueStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.AddSourceLocation(S->getContinueLoc(), Record);
|
|
|
|
Code = pch::STMT_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitBreakStmt(BreakStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.AddSourceLocation(S->getBreakLoc(), Record);
|
|
|
|
Code = pch::STMT_BREAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.WriteSubStmt(S->getRetValue());
|
|
|
|
Writer.AddSourceLocation(S->getReturnLoc(), Record);
|
2010-05-15 14:01:05 +08:00
|
|
|
Writer.AddDeclRef(S->getNRVOCandidate(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::STMT_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitDeclStmt(DeclStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.AddSourceLocation(S->getStartLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getEndLoc(), Record);
|
|
|
|
DeclGroupRef DG = S->getDeclGroup();
|
|
|
|
for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
|
|
|
|
Writer.AddDeclRef(*D, Record);
|
|
|
|
Code = pch::STMT_DECL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitAsmStmt(AsmStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Record.push_back(S->getNumOutputs());
|
|
|
|
Record.push_back(S->getNumInputs());
|
|
|
|
Record.push_back(S->getNumClobbers());
|
|
|
|
Writer.AddSourceLocation(S->getAsmLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getRParenLoc(), Record);
|
|
|
|
Record.push_back(S->isVolatile());
|
|
|
|
Record.push_back(S->isSimple());
|
2010-01-05 06:37:17 +08:00
|
|
|
Record.push_back(S->isMSAsm());
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getAsmString());
|
|
|
|
|
|
|
|
// Outputs
|
2010-01-31 06:25:16 +08:00
|
|
|
for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
|
|
|
|
Writer.AddIdentifierRef(S->getOutputIdentifier(I), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getOutputConstraintLiteral(I));
|
|
|
|
Writer.WriteSubStmt(S->getOutputExpr(I));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
|
2010-01-31 06:25:16 +08:00
|
|
|
Writer.AddIdentifierRef(S->getInputIdentifier(I), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getInputConstraintLiteral(I));
|
|
|
|
Writer.WriteSubStmt(S->getInputExpr(I));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clobbers
|
|
|
|
for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(S->getClobber(I));
|
|
|
|
|
|
|
|
Code = pch::STMT_ASM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitExpr(Expr *E) {
|
|
|
|
VisitStmt(E);
|
|
|
|
Writer.AddTypeRef(E->getType(), Record);
|
|
|
|
Record.push_back(E->isTypeDependent());
|
|
|
|
Record.push_back(E->isValueDependent());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Record.push_back(E->getIdentType()); // FIXME: stable encoding
|
|
|
|
Code = pch::EXPR_PREDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getDecl(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
2009-10-24 02:54:35 +08:00
|
|
|
// FIXME: write qualifier
|
|
|
|
// FIXME: write explicit template arguments
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::EXPR_DECL_REF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Writer.AddAPInt(E->getValue(), Record);
|
|
|
|
Code = pch::EXPR_INTEGER_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddAPFloat(E->getValue(), Record);
|
|
|
|
Record.push_back(E->isExact());
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Code = pch::EXPR_FLOATING_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Code = pch::EXPR_IMAGINARY_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitStringLiteral(StringLiteral *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getByteLength());
|
|
|
|
Record.push_back(E->getNumConcatenated());
|
|
|
|
Record.push_back(E->isWide());
|
|
|
|
// FIXME: String data should be stored as a blob at the end of the
|
|
|
|
// StringLiteral. However, we can't do so now because we have no
|
|
|
|
// provision for coping with abbreviations when we're jumping around
|
|
|
|
// the PCH file during deserialization.
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.insert(Record.end(),
|
2009-04-27 14:20:01 +08:00
|
|
|
E->getStrData(), E->getStrData() + E->getByteLength());
|
|
|
|
for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
|
|
|
|
Writer.AddSourceLocation(E->getStrTokenLoc(I), Record);
|
|
|
|
Code = pch::EXPR_STRING_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getValue());
|
2009-08-25 01:39:36 +08:00
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Record.push_back(E->isWide());
|
|
|
|
Code = pch::EXPR_CHARACTER_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitParenExpr(ParenExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLParen(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParen(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Code = pch::EXPR_PAREN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitUnaryOperator(UnaryOperator *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Record.push_back(E->getOpcode()); // FIXME: stable encoding
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
Code = pch::EXPR_UNARY_OPERATOR;
|
|
|
|
}
|
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
void PCHStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumComponents());
|
|
|
|
Record.push_back(E->getNumExpressions());
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
|
|
|
|
for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
|
|
|
|
const OffsetOfExpr::OffsetOfNode &ON = E->getComponent(I);
|
|
|
|
Record.push_back(ON.getKind()); // FIXME: Stable encoding
|
|
|
|
Writer.AddSourceLocation(ON.getRange().getBegin(), Record);
|
|
|
|
Writer.AddSourceLocation(ON.getRange().getEnd(), Record);
|
|
|
|
switch (ON.getKind()) {
|
|
|
|
case OffsetOfExpr::OffsetOfNode::Array:
|
|
|
|
Record.push_back(ON.getArrayExprIndex());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OffsetOfExpr::OffsetOfNode::Field:
|
|
|
|
Writer.AddDeclRef(ON.getField(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OffsetOfExpr::OffsetOfNode::Identifier:
|
|
|
|
Writer.AddIdentifierRef(ON.getFieldName(), Record);
|
|
|
|
break;
|
2010-04-29 08:18:15 +08:00
|
|
|
|
|
|
|
case OffsetOfExpr::OffsetOfNode::Base:
|
|
|
|
// FIXME: Implement this!
|
|
|
|
llvm_unreachable("PCH for offsetof(base-specifier) not implemented");
|
|
|
|
break;
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(E->getIndexExpr(I));
|
|
|
|
Code = pch::EXPR_OFFSETOF;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void PCHStmtWriter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
|
2009-04-27 14:20:01 +08:00
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->isSizeOf());
|
|
|
|
if (E->isArgumentType())
|
2009-12-07 10:54:59 +08:00
|
|
|
Writer.AddTypeSourceInfo(E->getArgumentTypeInfo(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
else {
|
|
|
|
Record.push_back(0);
|
|
|
|
Writer.WriteSubStmt(E->getArgumentExpr());
|
|
|
|
}
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_SIZEOF_ALIGN_OF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getLHS());
|
|
|
|
Writer.WriteSubStmt(E->getRHS());
|
|
|
|
Writer.AddSourceLocation(E->getRBracketLoc(), Record);
|
|
|
|
Code = pch::EXPR_ARRAY_SUBSCRIPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCallExpr(CallExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumArgs());
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getCallee());
|
|
|
|
for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
|
|
|
|
Arg != ArgEnd; ++Arg)
|
|
|
|
Writer.WriteSubStmt(*Arg);
|
|
|
|
Code = pch::EXPR_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
Writer.AddDeclRef(E->getMemberDecl(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getMemberLoc(), Record);
|
|
|
|
Record.push_back(E->isArrow());
|
2009-09-01 07:44:04 +08:00
|
|
|
// FIXME: C++ nested-name-specifier
|
2009-09-01 08:37:14 +08:00
|
|
|
// FIXME: C++ template argument list
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::EXPR_MEMBER;
|
2009-07-25 01:54:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
Writer.AddSourceLocation(E->getIsaMemberLoc(), Record);
|
|
|
|
Record.push_back(E->isArrow());
|
|
|
|
Code = pch::EXPR_OBJC_ISA;
|
2009-04-27 14:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
2009-07-31 08:48:10 +08:00
|
|
|
Record.push_back(E->getCastKind()); // FIXME: stable encoding
|
2009-04-27 14:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getLHS());
|
|
|
|
Writer.WriteSubStmt(E->getRHS());
|
|
|
|
Record.push_back(E->getOpcode()); // FIXME: stable encoding
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
Code = pch::EXPR_BINARY_OPERATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
|
|
|
|
VisitBinaryOperator(E);
|
|
|
|
Writer.AddTypeRef(E->getComputationLHSType(), Record);
|
|
|
|
Writer.AddTypeRef(E->getComputationResultType(), Record);
|
|
|
|
Code = pch::EXPR_COMPOUND_ASSIGN_OPERATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getCond());
|
|
|
|
Writer.WriteSubStmt(E->getLHS());
|
|
|
|
Writer.WriteSubStmt(E->getRHS());
|
2009-08-26 22:37:04 +08:00
|
|
|
Writer.AddSourceLocation(E->getQuestionLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getColonLoc(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::EXPR_CONDITIONAL_OPERATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
|
|
|
|
VisitCastExpr(E);
|
|
|
|
Record.push_back(E->isLvalueCast());
|
|
|
|
Code = pch::EXPR_IMPLICIT_CAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
|
|
|
|
VisitCastExpr(E);
|
2010-01-16 02:39:57 +08:00
|
|
|
Writer.AddTypeSourceInfo(E->getTypeInfoAsWritten(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
|
|
|
|
VisitExplicitCastExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLParenLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_CSTYLE_CAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLParenLoc(), Record);
|
2010-01-19 03:35:47 +08:00
|
|
|
Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(E->getInitializer());
|
|
|
|
Record.push_back(E->isFileScope());
|
|
|
|
Code = pch::EXPR_COMPOUND_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
Writer.AddIdentifierRef(&E->getAccessor(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getAccessorLoc(), Record);
|
|
|
|
Code = pch::EXPR_EXT_VECTOR_ELEMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitInitListExpr(InitListExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumInits());
|
|
|
|
for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(E->getInit(I));
|
|
|
|
Writer.WriteSubStmt(E->getSyntacticForm());
|
|
|
|
Writer.AddSourceLocation(E->getLBraceLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRBraceLoc(), Record);
|
|
|
|
Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record);
|
|
|
|
Record.push_back(E->hadArrayRangeDesignator());
|
|
|
|
Code = pch::EXPR_INIT_LIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumSubExprs());
|
|
|
|
for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr(I));
|
|
|
|
Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record);
|
|
|
|
Record.push_back(E->usesGNUSyntax());
|
|
|
|
for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
|
|
|
|
DEnd = E->designators_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
if (D->isFieldDesignator()) {
|
|
|
|
if (FieldDecl *Field = D->getField()) {
|
|
|
|
Record.push_back(pch::DESIG_FIELD_DECL);
|
|
|
|
Writer.AddDeclRef(Field, Record);
|
|
|
|
} else {
|
|
|
|
Record.push_back(pch::DESIG_FIELD_NAME);
|
|
|
|
Writer.AddIdentifierRef(D->getFieldName(), Record);
|
|
|
|
}
|
|
|
|
Writer.AddSourceLocation(D->getDotLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getFieldLoc(), Record);
|
|
|
|
} else if (D->isArrayDesignator()) {
|
|
|
|
Record.push_back(pch::DESIG_ARRAY);
|
|
|
|
Record.push_back(D->getFirstExprIndex());
|
|
|
|
Writer.AddSourceLocation(D->getLBracketLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getRBracketLoc(), Record);
|
|
|
|
} else {
|
|
|
|
assert(D->isArrayRangeDesignator() && "Unknown designator");
|
|
|
|
Record.push_back(pch::DESIG_ARRAY_RANGE);
|
|
|
|
Record.push_back(D->getFirstExprIndex());
|
|
|
|
Writer.AddSourceLocation(D->getLBracketLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getEllipsisLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getRBracketLoc(), Record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Code = pch::EXPR_DESIGNATED_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Code = pch::EXPR_IMPLICIT_VALUE_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_VA_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getAmpAmpLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getLabelLoc(), Record);
|
|
|
|
Record.push_back(Writer.GetLabelID(E->getLabel()));
|
|
|
|
Code = pch::EXPR_ADDR_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getSubStmt());
|
|
|
|
Writer.AddSourceLocation(E->getLParenLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_STMT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddTypeRef(E->getArgType1(), Record);
|
|
|
|
Writer.AddTypeRef(E->getArgType2(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_TYPES_COMPATIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitChooseExpr(ChooseExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getCond());
|
|
|
|
Writer.WriteSubStmt(E->getLHS());
|
|
|
|
Writer.WriteSubStmt(E->getRHS());
|
|
|
|
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_CHOOSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getTokenLocation(), Record);
|
|
|
|
Code = pch::EXPR_GNU_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumSubExprs());
|
|
|
|
for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(E->getExpr(I));
|
|
|
|
Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_SHUFFLE_VECTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitBlockExpr(BlockExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getBlockDecl(), Record);
|
|
|
|
Record.push_back(E->hasBlockDeclRefExprs());
|
|
|
|
Code = pch::EXPR_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getDecl(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Record.push_back(E->isByRef());
|
2009-06-20 08:02:26 +08:00
|
|
|
Record.push_back(E->isConstQualAdded());
|
2010-06-05 03:06:53 +08:00
|
|
|
Writer.WriteSubStmt(E->getCopyConstructorExpr());
|
2009-04-27 14:20:01 +08:00
|
|
|
Code = pch::EXPR_BLOCK_DECL_REF;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Objective-C Expressions and Statements.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.WriteSubStmt(E->getString());
|
|
|
|
Writer.AddSourceLocation(E->getAtLoc(), Record);
|
|
|
|
Code = pch::EXPR_OBJC_STRING_LITERAL;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
|
2009-04-27 14:20:01 +08:00
|
|
|
VisitExpr(E);
|
2010-04-20 23:39:42 +08:00
|
|
|
Writer.AddTypeSourceInfo(E->getEncodedTypeSourceInfo(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.AddSourceLocation(E->getAtLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_OBJC_ENCODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSelectorRef(E->getSelector(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getAtLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_OBJC_SELECTOR_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getProtocol(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getAtLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_OBJC_PROTOCOL_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getDecl(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
Record.push_back(E->isArrow());
|
|
|
|
Record.push_back(E->isFreeIvar());
|
|
|
|
Code = pch::EXPR_OBJC_IVAR_REF_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getProperty(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
Code = pch::EXPR_OBJC_PROPERTY_REF_EXPR;
|
|
|
|
}
|
|
|
|
|
2009-08-21 01:02:02 +08:00
|
|
|
void PCHStmtWriter::VisitObjCImplicitSetterGetterRefExpr(
|
|
|
|
ObjCImplicitSetterGetterRefExpr *E) {
|
2009-04-27 14:20:01 +08:00
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddDeclRef(E->getGetterMethod(), Record);
|
|
|
|
Writer.AddDeclRef(E->getSetterMethod(), Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-19 05:37:33 +08:00
|
|
|
// NOTE: InterfaceDecl and Base are mutually exclusive.
|
|
|
|
Writer.AddDeclRef(E->getInterfaceDecl(), Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getClassLoc(), Record);
|
|
|
|
Code = pch::EXPR_OBJC_KVC_REF_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumArgs());
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
llvm-svn: 101972
2010-04-21 08:45:42 +08:00
|
|
|
Record.push_back((unsigned)E->getReceiverKind()); // FIXME: stable encoding
|
|
|
|
switch (E->getReceiverKind()) {
|
|
|
|
case ObjCMessageExpr::Instance:
|
|
|
|
Writer.WriteSubStmt(E->getInstanceReceiver());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::Class:
|
|
|
|
Writer.AddTypeSourceInfo(E->getClassReceiverTypeInfo(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperClass:
|
|
|
|
case ObjCMessageExpr::SuperInstance:
|
|
|
|
Writer.AddTypeRef(E->getSuperType(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getSuperLoc(), Record);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (E->getMethodDecl()) {
|
|
|
|
Record.push_back(1);
|
|
|
|
Writer.AddDeclRef(E->getMethodDecl(), Record);
|
|
|
|
} else {
|
|
|
|
Record.push_back(0);
|
|
|
|
Writer.AddSelectorRef(E->getSelector(), Record);
|
|
|
|
}
|
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.AddSourceLocation(E->getLeftLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRightLoc(), Record);
|
|
|
|
|
|
|
|
for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
|
|
|
|
Arg != ArgEnd; ++Arg)
|
|
|
|
Writer.WriteSubStmt(*Arg);
|
|
|
|
Code = pch::EXPR_OBJC_MESSAGE_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCSuperExpr(ObjCSuperExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLoc(), Record);
|
|
|
|
Code = pch::EXPR_OBJC_SUPER_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
|
|
|
|
VisitStmt(S);
|
|
|
|
Writer.WriteSubStmt(S->getElement());
|
|
|
|
Writer.WriteSubStmt(S->getCollection());
|
|
|
|
Writer.WriteSubStmt(S->getBody());
|
|
|
|
Writer.AddSourceLocation(S->getForLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getRParenLoc(), Record);
|
|
|
|
Code = pch::STMT_OBJC_FOR_COLLECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
|
|
|
|
Writer.WriteSubStmt(S->getCatchBody());
|
|
|
|
Writer.AddDeclRef(S->getCatchParamDecl(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(S->getRParenLoc(), Record);
|
|
|
|
Code = pch::STMT_OBJC_CATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
|
|
|
|
Writer.WriteSubStmt(S->getFinallyBody());
|
|
|
|
Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
|
|
|
|
Code = pch::STMT_OBJC_FINALLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
|
2010-04-24 06:50:49 +08:00
|
|
|
Record.push_back(S->getNumCatchStmts());
|
|
|
|
Record.push_back(S->getFinallyStmt() != 0);
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.WriteSubStmt(S->getTryBody());
|
2010-04-24 06:50:49 +08:00
|
|
|
for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(S->getCatchStmt(I));
|
|
|
|
if (S->getFinallyStmt())
|
|
|
|
Writer.WriteSubStmt(S->getFinallyStmt());
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.AddSourceLocation(S->getAtTryLoc(), Record);
|
|
|
|
Code = pch::STMT_OBJC_AT_TRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
|
|
|
|
Writer.WriteSubStmt(S->getSynchExpr());
|
|
|
|
Writer.WriteSubStmt(S->getSynchBody());
|
|
|
|
Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
|
|
|
|
Code = pch::STMT_OBJC_AT_SYNCHRONIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
|
|
|
|
Writer.WriteSubStmt(S->getThrowExpr());
|
|
|
|
Writer.AddSourceLocation(S->getThrowLoc(), Record);
|
|
|
|
Code = pch::STMT_OBJC_AT_THROW;
|
|
|
|
}
|
|
|
|
|
2009-07-14 11:19:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C++ Expressions and Statements.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
|
|
|
|
VisitCallExpr(E);
|
|
|
|
Record.push_back(E->getOperator());
|
|
|
|
Code = pch::EXPR_CXX_OPERATOR_CALL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 13:36:05 +08:00
|
|
|
void PCHStmtWriter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
|
|
|
|
VisitCallExpr(E);
|
|
|
|
Code = pch::EXPR_CXX_MEMBER_CALL;
|
|
|
|
}
|
|
|
|
|
2009-09-10 07:08:42 +08:00
|
|
|
void PCHStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
|
|
|
|
VisitExpr(E);
|
2010-06-24 16:57:09 +08:00
|
|
|
Record.push_back(E->getNumArgs());
|
|
|
|
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
|
|
|
|
Writer.WriteSubStmt(E->getArg(I));
|
2009-09-10 07:08:42 +08:00
|
|
|
Writer.AddDeclRef(E->getConstructor(), Record);
|
2009-12-16 09:38:02 +08:00
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
2009-09-10 07:08:42 +08:00
|
|
|
Record.push_back(E->isElidable());
|
2009-12-17 02:50:27 +08:00
|
|
|
Record.push_back(E->requiresZeroInitialization());
|
2010-05-15 08:13:29 +08:00
|
|
|
Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
|
2009-09-10 07:08:42 +08:00
|
|
|
Code = pch::EXPR_CXX_CONSTRUCT;
|
|
|
|
}
|
|
|
|
|
2010-01-17 05:21:01 +08:00
|
|
|
void PCHStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
|
|
|
|
VisitExplicitCastExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
|
|
|
|
VisitCXXNamedCastExpr(E);
|
|
|
|
Code = pch::EXPR_CXX_STATIC_CAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
|
|
|
|
VisitCXXNamedCastExpr(E);
|
|
|
|
Code = pch::EXPR_CXX_DYNAMIC_CAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
|
|
|
|
VisitCXXNamedCastExpr(E);
|
|
|
|
Code = pch::EXPR_CXX_REINTERPRET_CAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
|
|
|
|
VisitCXXNamedCastExpr(E);
|
|
|
|
Code = pch::EXPR_CXX_CONST_CAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
|
|
|
|
VisitExplicitCastExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_CXX_FUNCTIONAL_CAST;
|
|
|
|
}
|
|
|
|
|
2010-02-07 14:32:43 +08:00
|
|
|
void PCHStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getValue());
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Code = pch::EXPR_CXX_BOOL_LITERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Code = pch::EXPR_CXX_NULL_PTR_LITERAL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 14:03:39 +08:00
|
|
|
void PCHStmtWriter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceRange(E->getSourceRange(), Record);
|
|
|
|
if (E->isTypeOperand()) {
|
|
|
|
Writer.AddTypeSourceInfo(E->getTypeOperandSourceInfo(), Record);
|
|
|
|
Code = pch::EXPR_CXX_TYPEID_TYPE;
|
|
|
|
} else {
|
|
|
|
Writer.WriteSubStmt(E->getExprOperand());
|
|
|
|
Code = pch::EXPR_CXX_TYPEID_EXPR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-09 14:15:05 +08:00
|
|
|
void PCHStmtWriter::VisitCXXThisExpr(CXXThisExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getLocation(), Record);
|
|
|
|
Record.push_back(E->isImplicit());
|
|
|
|
Code = pch::EXPR_CXX_THIS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
|
2010-05-09 14:40:08 +08:00
|
|
|
VisitExpr(E);
|
2010-05-09 14:15:05 +08:00
|
|
|
Writer.AddSourceLocation(E->getThrowLoc(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Code = pch::EXPR_CXX_THROW;
|
|
|
|
}
|
|
|
|
|
2010-05-09 14:40:08 +08:00
|
|
|
void PCHStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getUsedLocation(), Record);
|
|
|
|
if (E->isExprStored()) {
|
|
|
|
Record.push_back(1);
|
|
|
|
Writer.WriteSubStmt(E->getExpr());
|
|
|
|
} else {
|
|
|
|
Record.push_back(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Code = pch::EXPR_CXX_DEFAULT_ARG;
|
|
|
|
}
|
|
|
|
|
2010-05-10 08:25:06 +08:00
|
|
|
void PCHStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddCXXTemporary(E->getTemporary(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Code = pch::EXPR_CXX_BIND_TEMPORARY;
|
|
|
|
}
|
|
|
|
|
2010-05-10 09:22:27 +08:00
|
|
|
void PCHStmtWriter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_CXX_ZERO_INIT_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->isGlobalNew());
|
|
|
|
Record.push_back(E->isParenTypeId());
|
|
|
|
Record.push_back(E->hasInitializer());
|
|
|
|
Record.push_back(E->isArray());
|
|
|
|
Record.push_back(E->getNumPlacementArgs());
|
|
|
|
Record.push_back(E->getNumConstructorArgs());
|
|
|
|
Writer.AddDeclRef(E->getOperatorNew(), Record);
|
|
|
|
Writer.AddDeclRef(E->getOperatorDelete(), Record);
|
|
|
|
Writer.AddDeclRef(E->getConstructor(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getStartLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getEndLoc(), Record);
|
|
|
|
for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
|
|
|
|
I != e; ++I)
|
|
|
|
Writer.WriteSubStmt(*I);
|
|
|
|
|
|
|
|
Code = pch::EXPR_CXX_NEW;
|
|
|
|
}
|
|
|
|
|
2010-06-23 01:07:59 +08:00
|
|
|
void PCHStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->isGlobalDelete());
|
|
|
|
Record.push_back(E->isArrayForm());
|
|
|
|
Writer.AddDeclRef(E->getOperatorDelete(), Record);
|
|
|
|
Writer.WriteSubStmt(E->getArgument());
|
|
|
|
Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record);
|
|
|
|
|
|
|
|
Code = pch::EXPR_CXX_DELETE;
|
|
|
|
}
|
2010-05-10 09:22:27 +08:00
|
|
|
|
2010-05-10 08:25:06 +08:00
|
|
|
void PCHStmtWriter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->getNumTemporaries());
|
|
|
|
for (unsigned i = 0, e = E->getNumTemporaries(); i != e; ++i)
|
|
|
|
Writer.AddCXXTemporary(E->getTemporary(i), Record);
|
|
|
|
|
|
|
|
Writer.WriteSubStmt(E->getSubExpr());
|
|
|
|
Code = pch::EXPR_CXX_EXPR_WITH_TEMPORARIES;
|
|
|
|
}
|
|
|
|
|
2010-06-24 16:57:31 +08:00
|
|
|
void
|
|
|
|
PCHStmtWriter::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){
|
|
|
|
VisitExpr(E);
|
2010-06-28 17:31:48 +08:00
|
|
|
|
|
|
|
// Don't emit anything here, NumTemplateArgs must be emitted first.
|
2010-06-24 16:57:31 +08:00
|
|
|
|
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
2010-06-28 17:31:48 +08:00
|
|
|
const ExplicitTemplateArgumentList &Args
|
|
|
|
= *E->getExplicitTemplateArgumentList();
|
|
|
|
assert(Args.NumTemplateArgs &&
|
2010-06-24 16:57:31 +08:00
|
|
|
"Num of template args was zero! PCH reading will mess up!");
|
2010-06-28 17:31:48 +08:00
|
|
|
Record.push_back(Args.NumTemplateArgs);
|
|
|
|
AddExplicitTemplateArgumentList(Args);
|
2010-06-24 16:57:31 +08:00
|
|
|
} else {
|
|
|
|
Record.push_back(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!E->isImplicitAccess())
|
|
|
|
Writer.WriteSubStmt(E->getBase());
|
|
|
|
else
|
|
|
|
Writer.WriteSubStmt(0);
|
|
|
|
Writer.AddTypeRef(E->getBaseType(), Record);
|
|
|
|
Record.push_back(E->isArrow());
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
|
|
|
|
Writer.AddSourceRange(E->getQualifierRange(), Record);
|
|
|
|
Writer.AddDeclRef(E->getFirstQualifierFoundInScope(), Record);
|
|
|
|
Writer.AddDeclarationName(E->getMember(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getMemberLoc(), Record);
|
|
|
|
Code = pch::EXPR_CXX_DEPENDENT_SCOPE_MEMBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PCHStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
|
|
|
|
VisitExpr(E);
|
|
|
|
Record.push_back(E->arg_size());
|
|
|
|
for (CXXUnresolvedConstructExpr::arg_iterator
|
|
|
|
ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
|
|
|
|
Writer.WriteSubStmt(*ArgI);
|
|
|
|
Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
|
|
|
|
Writer.AddTypeRef(E->getTypeAsWritten(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getLParenLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getRParenLoc(), Record);
|
|
|
|
Code = pch::EXPR_CXX_UNRESOLVED_CONSTRUCT;
|
|
|
|
}
|
2010-05-09 14:15:05 +08:00
|
|
|
|
2010-06-25 17:03:26 +08:00
|
|
|
void PCHStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
|
|
|
|
VisitExpr(E);
|
2010-06-28 17:31:48 +08:00
|
|
|
|
|
|
|
// Don't emit anything here, NumTemplateArgs must be emitted first.
|
2010-06-25 17:03:26 +08:00
|
|
|
|
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
|
|
|
const ExplicitTemplateArgumentList &Args = E->getExplicitTemplateArgs();
|
|
|
|
assert(Args.NumTemplateArgs &&
|
|
|
|
"Num of template args was zero! PCH reading will mess up!");
|
|
|
|
Record.push_back(Args.NumTemplateArgs);
|
2010-06-28 17:31:48 +08:00
|
|
|
AddExplicitTemplateArgumentList(Args);
|
2010-06-25 17:03:26 +08:00
|
|
|
} else {
|
|
|
|
Record.push_back(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Record.push_back(E->getNumDecls());
|
|
|
|
for (OverloadExpr::decls_iterator
|
|
|
|
OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
|
|
|
|
Writer.AddDeclRef(OvI.getDecl(), Record);
|
|
|
|
Record.push_back(OvI.getAccess());
|
|
|
|
}
|
|
|
|
|
|
|
|
Writer.AddDeclarationName(E->getName(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
|
|
|
|
Writer.AddSourceRange(E->getQualifierRange(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
|
|
|
|
VisitOverloadExpr(E);
|
|
|
|
Record.push_back(E->isArrow());
|
|
|
|
Record.push_back(E->hasUnresolvedUsing());
|
|
|
|
Writer.WriteSubStmt(!E->isImplicitAccess() ? E->getBase() : 0);
|
|
|
|
Writer.AddTypeRef(E->getBaseType(), Record);
|
|
|
|
Writer.AddSourceLocation(E->getOperatorLoc(), Record);
|
|
|
|
Code = pch::EXPR_CXX_UNRESOLVED_MEMBER;
|
|
|
|
}
|
|
|
|
|
2010-06-25 17:03:34 +08:00
|
|
|
void PCHStmtWriter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
|
|
|
|
VisitOverloadExpr(E);
|
|
|
|
Record.push_back(E->requiresADL());
|
|
|
|
Record.push_back(E->isOverloaded());
|
|
|
|
Writer.AddDeclRef(E->getNamingClass(), Record);
|
|
|
|
Code = pch::EXPR_CXX_UNRESOLVED_LOOKUP;
|
|
|
|
}
|
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PCHWriter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
unsigned PCHWriter::RecordSwitchCaseID(SwitchCase *S) {
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
|
2009-04-27 14:20:01 +08:00
|
|
|
"SwitchCase recorded twice");
|
|
|
|
unsigned NextID = SwitchCaseIDs.size();
|
|
|
|
SwitchCaseIDs[S] = NextID;
|
|
|
|
return NextID;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PCHWriter::getSwitchCaseID(SwitchCase *S) {
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
|
2009-04-27 14:20:01 +08:00
|
|
|
"SwitchCase hasn't been seen yet");
|
|
|
|
return SwitchCaseIDs[S];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Retrieve the ID for the given label statement, which may
|
|
|
|
/// or may not have been emitted yet.
|
|
|
|
unsigned PCHWriter::GetLabelID(LabelStmt *S) {
|
|
|
|
std::map<LabelStmt *, unsigned>::iterator Pos = LabelIDs.find(S);
|
|
|
|
if (Pos != LabelIDs.end())
|
|
|
|
return Pos->second;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
unsigned NextID = LabelIDs.size();
|
|
|
|
LabelIDs[S] = NextID;
|
|
|
|
return NextID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Write the given substatement or subexpression to the
|
|
|
|
/// bitstream.
|
|
|
|
void PCHWriter::WriteSubStmt(Stmt *S) {
|
|
|
|
RecordData Record;
|
|
|
|
PCHStmtWriter Writer(*this, Record);
|
|
|
|
++NumStatements;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
if (!S) {
|
|
|
|
Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.Code = pch::STMT_NULL_PTR;
|
|
|
|
Writer.Visit(S);
|
2010-05-10 09:22:27 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (Writer.Code == pch::STMT_NULL_PTR) {
|
2010-06-25 17:03:12 +08:00
|
|
|
SourceManager &SrcMgr
|
|
|
|
= DeclIDs.begin()->first->getASTContext().getSourceManager();
|
|
|
|
S->dump(SrcMgr);
|
2010-05-10 09:22:27 +08:00
|
|
|
assert(0 && "Unhandled sub statement writing PCH file");
|
|
|
|
}
|
|
|
|
#endif
|
2009-09-09 23:08:12 +08:00
|
|
|
Stream.EmitRecord(Writer.Code, Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Flush all of the statements that have been added to the
|
|
|
|
/// queue via AddStmt().
|
|
|
|
void PCHWriter::FlushStmts() {
|
|
|
|
RecordData Record;
|
|
|
|
PCHStmtWriter Writer(*this, Record);
|
2010-06-28 17:31:42 +08:00
|
|
|
|
|
|
|
EmittingStmts = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
|
|
|
|
++NumStatements;
|
|
|
|
Stmt *S = StmtsToEmit[I];
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
if (!S) {
|
|
|
|
Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
|
2010-06-26 00:25:02 +08:00
|
|
|
Stream.EmitRecord(pch::STMT_STOP, Record);
|
2009-04-27 14:20:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
Writer.Code = pch::STMT_NULL_PTR;
|
|
|
|
Writer.Visit(S);
|
2010-05-10 08:25:06 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (Writer.Code == pch::STMT_NULL_PTR) {
|
|
|
|
S->dump();
|
|
|
|
assert(0 && "Unhandled expression writing PCH file");
|
|
|
|
}
|
|
|
|
#endif
|
2009-09-09 23:08:12 +08:00
|
|
|
Stream.EmitRecord(Writer.Code, Record);
|
|
|
|
|
|
|
|
assert(N == StmtsToEmit.size() &&
|
2009-04-27 14:20:01 +08:00
|
|
|
"Substatement writen via AddStmt rather than WriteSubStmt!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
// Note that we are at the end of a full expression. Any
|
|
|
|
// expression records that follow this one are part of a different
|
|
|
|
// expression.
|
|
|
|
Record.clear();
|
|
|
|
Stream.EmitRecord(pch::STMT_STOP, Record);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-06-28 17:31:42 +08:00
|
|
|
EmittingStmts = false;
|
|
|
|
|
2009-04-27 14:20:01 +08:00
|
|
|
StmtsToEmit.clear();
|
|
|
|
}
|