[cfe-commits] r41393 - in /cfe/trunk: AST/Expr.cpp AST/StmtDumper.cpp AST/StmtPrinter.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def

Chris Lattner sabre at nondot.org
Fri Aug 24 19:00:02 PDT 2007


Author: lattner
Date: Fri Aug 24 21:00:02 2007
New Revision: 41393

URL: http://llvm.org/viewvc/llvm-project?rev=41393&view=rev
Log:
Split the ASTNode out for compound assignments out from binary operators.  Now
they show up in dumps etc.

Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/AST/StmtDumper.cpp
    cfe/trunk/AST/StmtPrinter.cpp
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/StmtNodes.def

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=41393&r1=41392&r2=41393&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Fri Aug 24 21:00:02 2007
@@ -231,7 +231,7 @@
   }
   case BinaryOperatorClass:
     return cast<BinaryOperator>(this)->isAssignmentOp();
-  case CompoundAssignOperator:
+  case CompoundAssignOperatorClass:
     return true;
 
   case MemberExprClass:

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=41393&r1=41392&r2=41393&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Fri Aug 24 21:00:02 2007
@@ -425,11 +425,17 @@
 }
 void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
   DumpExpr(Node);
-  fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
-  if (CompoundAssignOperator *CAO = dyn_cast<CompoundAssignOperator>(Node)) {
-    fprintf(F, " ComputeTy=");
-    DumpType(CAO->getComputationType());
-  }
+  fprintf(F, " '%s'\n", BinaryOperator::getOpcodeStr(Node->getOpcode()));
+  DumpSubTree(Node->getLHS());
+  fprintf(F, "\n");
+  DumpSubTree(Node->getRHS());
+  fprintf(F, ")");
+}
+void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
+  DumpExpr(Node);
+  fprintf(F, " '%s' ComputeTy=",
+          BinaryOperator::getOpcodeStr(Node->getOpcode()));
+  DumpType(Node->getComputationType());
   fprintf(F, "\n");
   DumpSubTree(Node->getLHS());
   fprintf(F, "\n");

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41393&r1=41392&r2=41393&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Fri Aug 24 21:00:02 2007
@@ -475,6 +475,11 @@
   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
   PrintExpr(Node->getRHS());
 }
+void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
+  PrintExpr(Node->getLHS());
+  OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
+  PrintExpr(Node->getRHS());
+}
 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
   PrintExpr(Node->getCond());
   OS << " ? ";

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Aug 24 21:00:02 2007
@@ -729,8 +729,9 @@
   bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
   bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
   
-  static bool classof(const Stmt *T) { 
-    return T->getStmtClass() == BinaryOperatorClass; 
+  static bool classof(const Stmt *S) { 
+    return S->getStmtClass() == BinaryOperatorClass ||
+           S->getStmtClass() == CompoundAssignOperatorClass; 
   }
   static bool classof(const BinaryOperator *) { return true; }
 
@@ -745,7 +746,7 @@
 
 protected:
   BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, bool dead)
-    : Expr(BinaryOperatorClass, ResTy), Opc(opc) {
+    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc) {
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
   }
@@ -770,11 +771,8 @@
   QualType getComputationType() const { return ComputationType; }
   
   static bool classof(const CompoundAssignOperator *) { return true; }
-  static bool classof(const BinaryOperator *B) { 
-    return B->isCompoundAssignmentOp(); 
-  }
   static bool classof(const Stmt *S) { 
-    return isa<BinaryOperator>(S) && classof(cast<BinaryOperator>(S));
+    return S->getStmtClass() == CompoundAssignOperatorClass; 
   }
 };
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Fri Aug 24 21:00:02 2007
@@ -44,41 +44,42 @@
 
 FIRST_EXPR(31)
 // Expressions.
-STMT(31, Expr                 , Stmt)
-STMT(32, PreDefinedExpr       , Expr)
-STMT(33, DeclRefExpr          , Expr)
-STMT(34, IntegerLiteral       , Expr)
-STMT(35, FloatingLiteral      , Expr)
-STMT(36, StringLiteral        , Expr)
-STMT(37, CharacterLiteral     , Expr)
-STMT(38, ParenExpr            , Expr)
-STMT(39, UnaryOperator        , Expr)
-STMT(40, SizeOfAlignOfTypeExpr, Expr)
-STMT(41, ArraySubscriptExpr   , Expr)
-STMT(42, CallExpr             , Expr)
-STMT(43, MemberExpr           , Expr)
-STMT(44, CastExpr             , Expr)
-STMT(45, BinaryOperator       , Expr)
-STMT(46, ConditionalOperator  , Expr)
-STMT(47, ImplicitCastExpr     , Expr)
-STMT(48, CompoundLiteralExpr  , Expr)
-STMT(49, OCUVectorElementExpr , Expr)
+STMT(31, Expr                  , Stmt)
+STMT(32, PreDefinedExpr        , Expr)
+STMT(33, DeclRefExpr           , Expr)
+STMT(34, IntegerLiteral        , Expr)
+STMT(35, FloatingLiteral       , Expr)
+STMT(36, StringLiteral         , Expr)
+STMT(37, CharacterLiteral      , Expr)
+STMT(38, ParenExpr             , Expr)
+STMT(39, UnaryOperator         , Expr)
+STMT(40, SizeOfAlignOfTypeExpr , Expr)
+STMT(41, ArraySubscriptExpr    , Expr)
+STMT(42, CallExpr              , Expr)
+STMT(43, MemberExpr            , Expr)
+STMT(44, CastExpr              , Expr)
+STMT(45, BinaryOperator        , Expr)
+STMT(46, CompoundAssignOperator, BinaryOperator)
+STMT(47, ConditionalOperator   , Expr)
+STMT(48, ImplicitCastExpr      , Expr)
+STMT(49, CompoundLiteralExpr   , Expr)
+STMT(50, OCUVectorElementExpr  , Expr)
 
 // GNU Extensions.
-STMT(50, AddrLabelExpr        , Expr)
-STMT(51, StmtExpr             , Expr)
-STMT(52, TypesCompatibleExpr  , Expr)
-STMT(53, ChooseExpr           , Expr)
+STMT(55, AddrLabelExpr        , Expr)
+STMT(56, StmtExpr             , Expr)
+STMT(57, TypesCompatibleExpr  , Expr)
+STMT(58, ChooseExpr           , Expr)
 
 // C++ Expressions.
-STMT(54, CXXCastExpr          , Expr)
-STMT(55, CXXBoolLiteralExpr   , Expr)
+STMT(60, CXXCastExpr          , Expr)
+STMT(61, CXXBoolLiteralExpr   , Expr)
 
 // Obj-C Expressions.
-STMT(56, ObjCStringLiteral    , Expr)
-STMT(57, ObjCEncodeExpr       , Expr)
+STMT(70, ObjCStringLiteral    , Expr)
+STMT(71, ObjCEncodeExpr       , Expr)
 
-LAST_EXPR(57)
+LAST_EXPR(71)
 
 #undef STMT
 #undef FIRST_STMT





More information about the cfe-commits mailing list