aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-25 02:00:02 +0000
committerChris Lattner <sabre@nondot.org>2007-08-25 02:00:02 +0000
commiteb14fe839ec24c2ca14e5f094be147a34e3d3339 (patch)
treee6d87604b5f5169fd6cc1f32155b38a8d5546243
parent1f683e9cf2e855b32d3fb4b142aa121cd3cf1088 (diff)
Split the ASTNode out for compound assignments out from binary operators. Now
they show up in dumps etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41393 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/Expr.cpp2
-rw-r--r--AST/StmtDumper.cpp16
-rw-r--r--AST/StmtPrinter.cpp5
-rw-r--r--include/clang/AST/Expr.h12
-rw-r--r--include/clang/AST/StmtNodes.def57
5 files changed, 51 insertions, 41 deletions
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index d5fd241e8a..535e1ef786 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -231,7 +231,7 @@ bool Expr::hasLocalSideEffect() const {
}
case BinaryOperatorClass:
return cast<BinaryOperator>(this)->isAssignmentOp();
- case CompoundAssignOperator:
+ case CompoundAssignOperatorClass:
return true;
case MemberExprClass:
diff --git a/AST/StmtDumper.cpp b/AST/StmtDumper.cpp
index 25caaef390..0a46cbc5c1 100644
--- a/AST/StmtDumper.cpp
+++ b/AST/StmtDumper.cpp
@@ -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");
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index ec37f9e81c..633278f2fd 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -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 << " ? ";
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index f002cfede1..e571f11792 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -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;
}
};
diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def
index 5f8ac72989..6d23a67776 100644
--- a/include/clang/AST/StmtNodes.def
+++ b/include/clang/AST/StmtNodes.def
@@ -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