summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2007-02-13 01:51:42 +0000
committerBill Wendling <isanbard@gmail.com>2007-02-13 01:51:42 +0000
commit4073ed5daa69549cc20fa1b9e34ee0d2e6f01f8e (patch)
tree0ed7e7d427063bfafe731f9856f0e14cb7ea5e40
parentb5f661a255061ff40c85a7d1861e494138b1d947 (diff)
downloadbcm5719-llvm-4073ed5daa69549cc20fa1b9e34ee0d2e6f01f8e.tar.gz
bcm5719-llvm-4073ed5daa69549cc20fa1b9e34ee0d2e6f01f8e.zip
C++: Added support for bool types.
llvm-svn: 39338
-rw-r--r--clang/AST/Sema.h4
-rw-r--r--clang/AST/SemaExpr.cpp2
-rw-r--r--clang/AST/SemaExprCXX.cpp10
-rw-r--r--clang/AST/SemaType.cpp2
-rw-r--r--clang/Parse/ParseDecl.cpp2
-rw-r--r--clang/Parse/ParseExpr.cpp5
-rw-r--r--clang/Parse/ParseExprCXX.cpp10
-rw-r--r--clang/Sema/Sema.h4
-rw-r--r--clang/Sema/SemaExpr.cpp2
-rw-r--r--clang/Sema/SemaExprCXX.cpp10
-rw-r--r--clang/Sema/SemaType.cpp2
-rw-r--r--clang/include/clang/AST/ExprCXX.h50
-rw-r--r--clang/include/clang/Basic/TokenKinds.def1
-rw-r--r--clang/include/clang/Parse/Action.h6
-rw-r--r--clang/include/clang/Parse/Parser.h4
15 files changed, 87 insertions, 27 deletions
diff --git a/clang/AST/Sema.h b/clang/AST/Sema.h
index 8359999990f..151ce5dd466 100644
--- a/clang/AST/Sema.h
+++ b/clang/AST/Sema.h
@@ -208,6 +208,10 @@ public:
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc, ExprTy *E,
SourceLocation RParenLoc);
+
+ /// ParseCXXBoolLiteral - Parse {true,false} literals.
+ virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
+ tok::TokenKind Kind);
};
diff --git a/clang/AST/SemaExpr.cpp b/clang/AST/SemaExpr.cpp
index f7d48f08601..4ebff1b6354 100644
--- a/clang/AST/SemaExpr.cpp
+++ b/clang/AST/SemaExpr.cpp
@@ -249,7 +249,7 @@ Sema::ExprResult Sema::ParseIdentifierExpr(Scope *S, SourceLocation Loc,
// Could be enum-constant or decl.
Decl *D = LookupScopedDecl(&II, Decl::IDNS_Ordinary, Loc, S);
if (D == 0) {
- // Otherwise, this could be an imlicitly declared function reference (legal
+ // Otherwise, this could be an implicitly declared function reference (legal
// in C90, extension in C99).
if (HasTrailingLParen &&
// Not in C++.
diff --git a/clang/AST/SemaExprCXX.cpp b/clang/AST/SemaExprCXX.cpp
index e0a98ef737e..a88ec3d8793 100644
--- a/clang/AST/SemaExprCXX.cpp
+++ b/clang/AST/SemaExprCXX.cpp
@@ -26,7 +26,7 @@ Sema::ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
CXXCastExpr::Opcode Op;
switch (Kind) {
- default: assert(0 && "Unknown C++ cast!"); abort();
+ default: assert(0 && "Unknown C++ cast!");
case tok::kw_const_cast: Op = CXXCastExpr::ConstCast; break;
case tok::kw_dynamic_cast: Op = CXXCastExpr::DynamicCast; break;
case tok::kw_reinterpret_cast: Op = CXXCastExpr::ReinterpretCast; break;
@@ -35,3 +35,11 @@ Sema::ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
return new CXXCastExpr(Op, TypeRef::getFromOpaquePtr(Ty), (Expr*)E);
}
+
+/// ParseCXXBoolLiteral - Parse {true,false} literals.
+Action::ExprResult
+Sema::ParseCXXBoolLiteral(SourceLocation, tok::TokenKind Kind) {
+ assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
+ "Unknown C++ Boolean value!");
+ return new CXXBoolLiteralExpr(Kind == tok::kw_true);
+}
diff --git a/clang/AST/SemaType.cpp b/clang/AST/SemaType.cpp
index 08f1c63a1cc..6fb5522a2d4 100644
--- a/clang/AST/SemaType.cpp
+++ b/clang/AST/SemaType.cpp
@@ -68,7 +68,7 @@ static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
"FIXME: imaginary types not supported yet!");
return isLong ? Ctx.LongDoubleComplexTy : Ctx.DoubleComplexTy;
}
- case DeclSpec::TST_bool: // _Bool
+ case DeclSpec::TST_bool: // _Bool or bool
return Ctx.BoolTy;
case DeclSpec::TST_decimal32: // _Decimal32
case DeclSpec::TST_decimal64: // _Decimal64
diff --git a/clang/Parse/ParseDecl.cpp b/clang/Parse/ParseDecl.cpp
index e1b9d25b568..6897167a64f 100644
--- a/clang/Parse/ParseDecl.cpp
+++ b/clang/Parse/ParseDecl.cpp
@@ -230,6 +230,7 @@ void Parser::ParseSpecifierQualifierList(DeclSpec &DS) {
/// struct-or-union-specifier
/// enum-specifier
/// typedef-name
+/// [C++] 'bool'
/// [C99] '_Bool'
/// [C99] '_Complex'
/// [C99] '_Imaginary' // Removed in TC2?
@@ -341,6 +342,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
case tok::kw_double:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec);
break;
+ case tok::kw_bool: // [C++ 2.11p1]
case tok::kw__Bool:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec);
break;
diff --git a/clang/Parse/ParseExpr.cpp b/clang/Parse/ParseExpr.cpp
index d0964911fca..d5ffc627ada 100644
--- a/clang/Parse/ParseExpr.cpp
+++ b/clang/Parse/ParseExpr.cpp
@@ -398,6 +398,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) {
/// identifier
/// constant
/// string-literal
+/// [C++] boolean-literal [C++ 2.13.5]
/// '(' expression ')'
/// '__func__' [C99 6.4.2.2]
/// [GNU] '__FUNCTION__'
@@ -484,6 +485,10 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
// These can be followed by postfix-expr pieces.
return ParsePostfixExpressionSuffix(Res);
+ case tok::kw_true:
+ case tok::kw_false:
+ return ParseCXXBoolLiteral();
+
case tok::identifier: { // primary-expression: identifier
// constant: enumeration-constant
// Consume the identifier so that we can see if it is followed by a '('.
diff --git a/clang/Parse/ParseExprCXX.cpp b/clang/Parse/ParseExprCXX.cpp
index 2c09ddf12d7..52447f8688c 100644
--- a/clang/Parse/ParseExprCXX.cpp
+++ b/clang/Parse/ParseExprCXX.cpp
@@ -68,3 +68,13 @@ Parser::ExprResult Parser::ParseCXXCasts() {
return Result;
}
+
+/// ParseCXXBoolLiteral - This handles the C++ Boolean literals.
+///
+/// boolean-literal: [C++ 2.13.5]
+/// 'true'
+/// 'false'
+Parser::ExprResult Parser::ParseCXXBoolLiteral() {
+ tok::TokenKind Kind = Tok.getKind();
+ return Actions.ParseCXXBoolLiteral(ConsumeToken(), Kind);
+}
diff --git a/clang/Sema/Sema.h b/clang/Sema/Sema.h
index 8359999990f..151ce5dd466 100644
--- a/clang/Sema/Sema.h
+++ b/clang/Sema/Sema.h
@@ -208,6 +208,10 @@ public:
SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc, ExprTy *E,
SourceLocation RParenLoc);
+
+ /// ParseCXXBoolLiteral - Parse {true,false} literals.
+ virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
+ tok::TokenKind Kind);
};
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp
index f7d48f08601..4ebff1b6354 100644
--- a/clang/Sema/SemaExpr.cpp
+++ b/clang/Sema/SemaExpr.cpp
@@ -249,7 +249,7 @@ Sema::ExprResult Sema::ParseIdentifierExpr(Scope *S, SourceLocation Loc,
// Could be enum-constant or decl.
Decl *D = LookupScopedDecl(&II, Decl::IDNS_Ordinary, Loc, S);
if (D == 0) {
- // Otherwise, this could be an imlicitly declared function reference (legal
+ // Otherwise, this could be an implicitly declared function reference (legal
// in C90, extension in C99).
if (HasTrailingLParen &&
// Not in C++.
diff --git a/clang/Sema/SemaExprCXX.cpp b/clang/Sema/SemaExprCXX.cpp
index e0a98ef737e..a88ec3d8793 100644
--- a/clang/Sema/SemaExprCXX.cpp
+++ b/clang/Sema/SemaExprCXX.cpp
@@ -26,7 +26,7 @@ Sema::ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
CXXCastExpr::Opcode Op;
switch (Kind) {
- default: assert(0 && "Unknown C++ cast!"); abort();
+ default: assert(0 && "Unknown C++ cast!");
case tok::kw_const_cast: Op = CXXCastExpr::ConstCast; break;
case tok::kw_dynamic_cast: Op = CXXCastExpr::DynamicCast; break;
case tok::kw_reinterpret_cast: Op = CXXCastExpr::ReinterpretCast; break;
@@ -35,3 +35,11 @@ Sema::ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
return new CXXCastExpr(Op, TypeRef::getFromOpaquePtr(Ty), (Expr*)E);
}
+
+/// ParseCXXBoolLiteral - Parse {true,false} literals.
+Action::ExprResult
+Sema::ParseCXXBoolLiteral(SourceLocation, tok::TokenKind Kind) {
+ assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
+ "Unknown C++ Boolean value!");
+ return new CXXBoolLiteralExpr(Kind == tok::kw_true);
+}
diff --git a/clang/Sema/SemaType.cpp b/clang/Sema/SemaType.cpp
index 08f1c63a1cc..6fb5522a2d4 100644
--- a/clang/Sema/SemaType.cpp
+++ b/clang/Sema/SemaType.cpp
@@ -68,7 +68,7 @@ static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
"FIXME: imaginary types not supported yet!");
return isLong ? Ctx.LongDoubleComplexTy : Ctx.DoubleComplexTy;
}
- case DeclSpec::TST_bool: // _Bool
+ case DeclSpec::TST_bool: // _Bool or bool
return Ctx.BoolTy;
case DeclSpec::TST_decimal32: // _Decimal32
case DeclSpec::TST_decimal64: // _Decimal64
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 6b3e92b4102..25b798cc669 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -19,30 +19,38 @@
namespace llvm {
namespace clang {
-//===----------------------------------------------------------------------===//
-// C++ Expressions.
-//===----------------------------------------------------------------------===//
-
-/// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
-///
-class CXXCastExpr : public CastExpr {
-public:
- enum Opcode {
- DynamicCast,
- StaticCast,
- ReinterpretCast,
- ConstCast
+ //===--------------------------------------------------------------------===//
+ // C++ Expressions.
+ //===--------------------------------------------------------------------===//
+
+ /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
+ ///
+ class CXXCastExpr : public CastExpr {
+ public:
+ enum Opcode {
+ DynamicCast,
+ StaticCast,
+ ReinterpretCast,
+ ConstCast
+ };
+
+ CXXCastExpr(Opcode op, TypeRef ty, Expr *expr)
+ : CastExpr(ty, expr), Op(op) {}
+
+ Opcode getOpcode() const { return Op; }
+ virtual void visit(StmtVisitor &Visitor);
+ private:
+ Opcode Op;
};
- CXXCastExpr(Opcode op, TypeRef ty, Expr *expr)
- : CastExpr(ty, expr), Op(op) {}
+ /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
+ ///
+ class CXXBoolLiteralExpr : public Expr {
+ bool Value;
+ public:
+ CXXBoolLiteralExpr(bool val) : Value(val) {}
+ };
- Opcode getOpcode() const { return Op; }
- virtual void visit(StmtVisitor &Visitor);
-private:
- Opcode Op;
-};
-
} // end namespace clang
} // end namespace llvm
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index 850fcd613d5..4fab08dfde8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -228,6 +228,7 @@ KEYWORD(__PRETTY_FUNCTION__ , EXTC90|EXTC99|EXTCPP) // GCC Extension.
// C++ 2.11p1: Keywords.
KEYWORD(asm , EXTC90|EXTC99) // Exts in C90/C99
+KEYWORD(bool , NOTC90|NOTC99)
KEYWORD(catch , NOTC90|NOTC99)
KEYWORD(class , NOTC90|NOTC99)
KEYWORD(const_cast , NOTC90|NOTC99)
diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h
index 13a49efbb80..95435d6f8a7 100644
--- a/clang/include/clang/Parse/Action.h
+++ b/clang/include/clang/Parse/Action.h
@@ -342,6 +342,12 @@ public:
SourceLocation RParenLoc) {
return 0;
}
+
+ /// ParseCXXBoolLiteral - Parse {true,false} literals.
+ virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
+ tok::TokenKind Kind) {
+ return 0;
+ }
};
/// MinimalAction - Minimal actions are used by light-weight clients of the
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 6368a651425..2e4d654e0ff 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -297,6 +297,10 @@ private:
ExprResult ParseCXXCasts();
//===--------------------------------------------------------------------===//
+ // C++ 2.13.5: C++ Boolean Literals
+ ExprResult ParseCXXBoolLiteral();
+
+ //===--------------------------------------------------------------------===//
// C99 6.7.8: Initialization.
ExprResult ParseInitializer();
ExprResult ParseInitializerWithPotentialDesignator();
OpenPOWER on IntegriCloud