[cfe-commits] r39714 - in /cfe/cfe/trunk: Parse/ParseExpr.cpp Sema/SemaExprCXX.cpp include/clang/AST/ExprCXX.h include/clang/AST/StmtNodes.def

bwendlin at cs.uiuc.edu bwendlin at cs.uiuc.edu
Wed Jul 11 09:47:26 PDT 2007


Author: bwendlin
Date: Wed Jul 11 11:47:26 2007
New Revision: 39714

URL: http://llvm.org/viewvc/llvm-project?rev=39714&view=rev
Log:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Fix for C++ casting operators failing during parsing. Deriving the C++ cast
  expressions from CastExpr was the wrong way to go. Its constructor creates
  null QualTypes in one of its constructors. This doesn't work well with how
  the C++ casting expression class wanted to do things. Derive just from Expr
  instead.

Modified:
    cfe/cfe/trunk/Parse/ParseExpr.cpp
    cfe/cfe/trunk/Sema/SemaExprCXX.cpp
    cfe/cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/cfe/trunk/include/clang/AST/StmtNodes.def

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

==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:47:26 2007
@@ -413,6 +413,10 @@
 /// [OBC]   '@protocol' '(' identifier ')'             [TODO]
 /// [OBC]   '@encode' '(' type-name ')'                [TODO]
 /// [OBC]   objc-string-literal                        [TODO]
+/// [C++]   'const_cast' '<' type-name '>' '(' expression ')'       [C++ 5.2p1]
+/// [C++]   'dynamic_cast' '<' type-name '>' '(' expression ')'     [C++ 5.2p1]
+/// [C++]   'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
+/// [C++]   'static_cast' '<' type-name '>' '(' expression ')'      [C++ 5.2p1]
 ///
 ///       constant: [C99 6.4.4]
 ///         integer-constant

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExprCXX.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExprCXX.cpp Wed Jul 11 11:47:26 2007
@@ -32,7 +32,7 @@
   case tok::kw_static_cast:      Op = CXXCastExpr::StaticCast;      break;
   }
   
-  return new CXXCastExpr(Op, QualType::getFromOpaquePtr(Ty), (Expr*)E);
+  return new CXXCastExpr(Op, QualType::getFromOpaquePtr(Ty), (Expr*)E, OpLoc);
 }
 
 /// ParseCXXBoolLiteral - Parse {true,false} literals.

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=39714&r1=39713&r2=39714&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ExprCXX.h Wed Jul 11 11:47:26 2007
@@ -24,7 +24,7 @@
 
   /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
   /// 
-  class CXXCastExpr : public CastExpr {
+  class CXXCastExpr : public Expr {
   public:
     enum Opcode {
       DynamicCast,
@@ -32,18 +32,28 @@
       ReinterpretCast,
       ConstCast
     };
+  private:
+    QualType Ty;
+    Opcode Opc;
+    Expr *Op;
+    SourceLocation Loc; // the location of the casting op
+  public:
+    CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l)
+      : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {}
 
-    CXXCastExpr(Opcode op, QualType ty, Expr *expr)
-      : CastExpr(CXXCastExprClass, ty, expr), Op(op) {}
+    QualType getDestType() const { return Ty; }
+    Expr *getSubExpr() const { return Op; }
+  
+    Opcode getOpcode() const { return Opc; }
 
-    Opcode getOpcode() const { return Op; }
+    virtual SourceRange getSourceRange() const {
+      return SourceRange(Loc, getSubExpr()->getSourceRange().End());
+    }
     virtual void visit(StmtVisitor &Visitor);
     static bool classof(const Stmt *T) { 
       return T->getStmtClass() == CXXCastExprClass;
     }
     static bool classof(const CXXCastExpr *) { return true; }
-  private:
-    Opcode Op;
   };
 
   /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.

Modified: cfe/cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/StmtNodes.def?rev=39714&r1=39713&r2=39714&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/cfe/trunk/include/clang/AST/StmtNodes.def Wed Jul 11 11:47:26 2007
@@ -63,7 +63,7 @@
 STMT(47, AddrLabel            , Expr)
 
 // C++ Expressions.
-STMT(48, CXXCastExpr          , CastExpr)
+STMT(48, CXXCastExpr          , Expr)
 STMT(49, CXXBoolLiteralExpr   , Expr)
 LAST_EXPR(49)
 





More information about the cfe-commits mailing list