[cfe-commits] r39338 - in /cfe/cfe/trunk: AST/Sema.h AST/SemaExpr.cpp AST/SemaExprCXX.cpp AST/SemaType.cpp Parse/ParseDecl.cpp Parse/ParseExpr.cpp Parse/ParseExprCXX.cpp Sema/Sema.h Sema/SemaExpr.cpp Sema/SemaExprCXX.cpp Sema/SemaType.cpp include/clang/AST/ExprCXX.h include/clang/Basic/TokenKinds.def include/clang/Parse/Action.h include/clang/Parse/Parser.h

wendling at cs.uiuc.edu wendling at cs.uiuc.edu
Wed Jul 11 09:43:18 PDT 2007


Author: wendling
Date: Wed Jul 11 11:43:17 2007
New Revision: 39338

URL: http://llvm.org/viewvc/llvm-project?rev=39338&view=rev
Log:
C++: Added support for bool types.

Modified:
    cfe/cfe/trunk/AST/Sema.h
    cfe/cfe/trunk/AST/SemaExpr.cpp
    cfe/cfe/trunk/AST/SemaExprCXX.cpp
    cfe/cfe/trunk/AST/SemaType.cpp
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/Parse/ParseExpr.cpp
    cfe/cfe/trunk/Parse/ParseExprCXX.cpp
    cfe/cfe/trunk/Sema/Sema.h
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/Sema/SemaExprCXX.cpp
    cfe/cfe/trunk/Sema/SemaType.cpp
    cfe/cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/cfe/trunk/include/clang/Basic/TokenKinds.def
    cfe/cfe/trunk/include/clang/Parse/Action.h
    cfe/cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:43:17 2007
@@ -208,6 +208,10 @@
                                    SourceLocation RAngleBracketLoc,
                                    SourceLocation LParenLoc, ExprTy *E,
                                    SourceLocation RParenLoc);
+
+  /// ParseCXXBoolLiteral - Parse {true,false} literals.
+  virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
+					 tok::TokenKind Kind);
 };
 
 

Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:43:17 2007
@@ -249,7 +249,7 @@
   // 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++.

Modified: cfe/cfe/trunk/AST/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExprCXX.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaExprCXX.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExprCXX.cpp Wed Jul 11 11:43:17 2007
@@ -26,7 +26,7 @@
   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 @@
   
   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);
+}

Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:43:17 2007
@@ -68,7 +68,7 @@
            "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

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:43:17 2007
@@ -230,6 +230,7 @@
 ///         struct-or-union-specifier
 ///         enum-specifier
 ///         typedef-name
+/// [C++]   'bool'
 /// [C99]   '_Bool'
 /// [C99]   '_Complex'
 /// [C99]   '_Imaginary'  // Removed in TC2?
@@ -341,6 +342,7 @@
     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;

Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:43:17 2007
@@ -398,6 +398,7 @@
 ///         identifier
 ///         constant
 ///         string-literal
+/// [C++]   boolean-literal  [C++ 2.13.5]
 ///         '(' expression ')'
 ///         '__func__'        [C99 6.4.2.2]
 /// [GNU]   '__FUNCTION__'
@@ -484,6 +485,10 @@
     // 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 '('.

Modified: cfe/cfe/trunk/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExprCXX.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseExprCXX.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExprCXX.cpp Wed Jul 11 11:43:17 2007
@@ -68,3 +68,13 @@
 
   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);
+}

Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:43:17 2007
@@ -208,6 +208,10 @@
                                    SourceLocation RAngleBracketLoc,
                                    SourceLocation LParenLoc, ExprTy *E,
                                    SourceLocation RParenLoc);
+
+  /// ParseCXXBoolLiteral - Parse {true,false} literals.
+  virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
+					 tok::TokenKind Kind);
 };
 
 

Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:43:17 2007
@@ -249,7 +249,7 @@
   // 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++.

Modified: cfe/cfe/trunk/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExprCXX.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExprCXX.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExprCXX.cpp Wed Jul 11 11:43:17 2007
@@ -26,7 +26,7 @@
   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 @@
   
   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);
+}

Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:43:17 2007
@@ -68,7 +68,7 @@
            "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

Modified: cfe/cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ExprCXX.h?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ExprCXX.h Wed Jul 11 11:43:17 2007
@@ -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
 

Modified: cfe/cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/TokenKinds.def Wed Jul 11 11:43:17 2007
@@ -228,6 +228,7 @@
 
 // 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)

Modified: cfe/cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Action.h?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:43:17 2007
@@ -342,6 +342,12 @@
                                    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

Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=39338&r1=39337&r2=39338&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:43:17 2007
@@ -297,6 +297,10 @@
   ExprResult ParseCXXCasts();
 
   //===--------------------------------------------------------------------===//
+  // C++ 2.13.5: C++ Boolean Literals
+  ExprResult ParseCXXBoolLiteral();
+
+  //===--------------------------------------------------------------------===//
   // C99 6.7.8: Initialization.
   ExprResult ParseInitializer();
   ExprResult ParseInitializerWithPotentialDesignator();





More information about the cfe-commits mailing list