]> granicus.if.org Git - clang/commitdiff
Split the ASTNode out for compound assignments out from binary operators. Now
authorChris Lattner <sabre@nondot.org>
Sat, 25 Aug 2007 02:00:02 +0000 (02:00 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 25 Aug 2007 02:00:02 +0000 (02:00 +0000)
they show up in dumps etc.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41393 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
AST/StmtDumper.cpp
AST/StmtPrinter.cpp
include/clang/AST/Expr.h
include/clang/AST/StmtNodes.def

index d5fd241e8a3d5ba3d694632e682487efc31babf4..535e1ef786f1938ffd70036a35d2467c661600ba 100644 (file)
@@ -231,7 +231,7 @@ bool Expr::hasLocalSideEffect() const {
   }
   case BinaryOperatorClass:
     return cast<BinaryOperator>(this)->isAssignmentOp();
-  case CompoundAssignOperator:
+  case CompoundAssignOperatorClass:
     return true;
 
   case MemberExprClass:
index 25caaef390768df1e939d98b551cb9c73603a94a..0a46cbc5c12550088181292f5ee3df37669b8d31 100644 (file)
@@ -425,11 +425,17 @@ void StmtDumper::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
 }
 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");
index ec37f9e81c5227d0515dd80030526caf6261fc20..633278f2fd69f4ce4558dcaedce522886c90f2ca 100644 (file)
@@ -475,6 +475,11 @@ void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
   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 << " ? ";
index f002cfede16de99ebe681571fd92ff663fc9542b..e571f11792c6a37b4d618761dc20eaa81de6e9a7 100644 (file)
@@ -729,8 +729,9 @@ public:
   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 @@ private:
 
 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 @@ public:
   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; 
   }
 };
 
index 5f8ac729890ae995d44f071d4a2186b8ef4ddfd8..6d23a6777641962776007948eed872a998b84d79 100644 (file)
@@ -44,41 +44,42 @@ LAST_STMT(17)
 
 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