Add PCH support for CXXBoolLiteralExpr and CXXNullPtrLiteralExpr.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95513 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sam Weinig 2010-02-07 04:44:10 +00:00
Родитель f6b89a1738
Коммит 1eb1113b13
7 изменённых файлов: 88 добавлений и 9 удалений

Просмотреть файл

@ -241,10 +241,17 @@ public:
CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
explicit CXXBoolLiteralExpr(EmptyShell Empty)
: Expr(CXXBoolLiteralExprClass, Empty) { }
bool getValue() const { return Value; }
void setValue(bool V) { Value = V; }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
SourceLocation getLocation() const { return Loc; }
void setLocation(SourceLocation L) { Loc = L; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXBoolLiteralExprClass;
}
@ -262,8 +269,14 @@ public:
CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
: Expr(CXXNullPtrLiteralExprClass, Empty) { }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
SourceLocation getLocation() const { return Loc; }
void setLocation(SourceLocation L) { Loc = L; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXNullPtrLiteralExprClass;
}

Просмотреть файл

@ -686,7 +686,11 @@ namespace clang {
// \brief A CXXConstCastExpr record.
EXPR_CXX_CONST_CAST,
// \brief A CXXFunctionalCastExpr record.
EXPR_CXX_FUNCTIONAL_CAST
EXPR_CXX_FUNCTIONAL_CAST,
// \brief A CXXBoolLiteralExpr record.
EXPR_CXX_BOOL_LITERAL,
// \brief A CXXNullPtrLiteralExpr record.
EXPR_CXX_NULL_PTR_LITERAL
};
/// \brief The kinds of designators that can occur in a

Просмотреть файл

@ -123,6 +123,8 @@ namespace {
unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
unsigned VisitCXXConstCastExpr(CXXConstCastExpr *E);
unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
unsigned VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
unsigned VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
};
}
@ -906,6 +908,19 @@ unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
return num;
}
unsigned PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
VisitExpr(E);
E->setValue(Record[Idx++]);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
return 0;
}
unsigned PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
VisitExpr(E);
E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
return 0;
}
// Within the bitstream, expressions are stored in Reverse Polish
// Notation, with each of the subexpressions preceding the
// expression they are stored in. To evaluate expressions, we
@ -1235,7 +1250,13 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
S = new (Context) CXXFunctionalCastExpr(Empty);
break;
case pch::EXPR_CXX_BOOL_LITERAL:
S = new (Context) CXXBoolLiteralExpr(Empty);
break;
case pch::EXPR_CXX_NULL_PTR_LITERAL:
S = new (Context) CXXNullPtrLiteralExpr(Empty);
break;
}
// We hit a STMT_STOP, so we're done with this expression.

Просмотреть файл

@ -513,6 +513,15 @@ static void AddStmtsExprs(llvm::BitstreamWriter &Stream,
RECORD(STMT_OBJC_AT_TRY);
RECORD(STMT_OBJC_AT_SYNCHRONIZED);
RECORD(STMT_OBJC_AT_THROW);
RECORD(EXPR_CXX_OPERATOR_CALL);
RECORD(EXPR_CXX_CONSTRUCT);
RECORD(EXPR_CXX_STATIC_CAST);
RECORD(EXPR_CXX_DYNAMIC_CAST);
RECORD(EXPR_CXX_REINTERPRET_CAST);
RECORD(EXPR_CXX_CONST_CAST);
RECORD(EXPR_CXX_FUNCTIONAL_CAST);
RECORD(EXPR_CXX_BOOL_LITERAL);
RECORD(EXPR_CXX_NULL_PTR_LITERAL);
#undef RECORD
}

Просмотреть файл

@ -118,6 +118,8 @@ namespace {
void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
void VisitCXXConstCastExpr(CXXConstCastExpr *E);
void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
};
}
@ -834,6 +836,19 @@ void PCHStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
Code = pch::EXPR_CXX_FUNCTIONAL_CAST;
}
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;
}
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
//===----------------------------------------------------------------------===//

Просмотреть файл

@ -1,13 +1,14 @@
// Test this without pch.
// RUN: %clang_cc1 -include %S/cxx_exprs.h -fsyntax-only -verify %s
// RUN: %clang_cc1 -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s
// Test with pch.
// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx_exprs.h
// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
// RUN: %clang_cc1 -x c++-header -std=c++0x -emit-pch -o %t %S/cxx_exprs.h
// RUN: %clang_cc1 -std=c++0x -include-pch %t -fsyntax-only -verify %s
int integer;
double floating;
char character;
bool boolean;
// CXXStaticCastExpr
static_cast_result void_ptr = &integer;
@ -24,3 +25,11 @@ const_cast_result char_ptr = &character;
// CXXFunctionalCastExpr
functional_cast_result *double_ptr = &floating;
// CXXBoolLiteralExpr
bool_literal_result *bool_ptr = &boolean;
static_assert(true_value, "true_value is true");
static_assert(!false_value, "false_value is false");
// CXXNullPtrLiteralExpr
cxx_null_ptr_result null_ptr = nullptr;

Просмотреть файл

@ -1,21 +1,29 @@
// Header for PCH test cxx_exprs.cpp
// CXXStaticCastExpr
typedef typeof(static_cast<void *>(0)) static_cast_result;
typedef __typeof__(static_cast<void *>(0)) static_cast_result;
// CXXDynamicCastExpr
struct Base { virtual void f(); };
struct Derived : Base { };
Base *base_ptr;
typedef typeof(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
// CXXReinterpretCastExpr
typedef typeof(reinterpret_cast<void *>(0)) reinterpret_cast_result;
typedef __typeof__(reinterpret_cast<void *>(0)) reinterpret_cast_result;
// CXXConstCastExpr
const char *const_char_ptr_value;
typedef typeof(const_cast<char *>(const_char_ptr_value)) const_cast_result;
typedef __typeof__(const_cast<char *>(const_char_ptr_value)) const_cast_result;
// CXXFunctionalCastExpr
int int_value;
typedef typeof(double(int_value)) functional_cast_result;
typedef __typeof__(double(int_value)) functional_cast_result;
// CXXBoolLiteralExpr
typedef __typeof__(true) bool_literal_result;
const bool true_value = true;
const bool false_value = false;
// CXXNullPtrLiteralExpr
typedef __typeof__(nullptr) cxx_null_ptr_result;