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
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index d5fd241..535e1ef 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -231,7 +231,7 @@
}
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 25caaef..0a46cbc 100644
--- a/AST/StmtDumper.cpp
+++ b/AST/StmtDumper.cpp
@@ -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");
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index ec37f9e..633278f 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -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 << " ? ";
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index f002cfe..e571f11 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -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;
}
};
diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def
index 5f8ac72..6d23a67 100644
--- a/include/clang/AST/StmtNodes.def
+++ b/include/clang/AST/StmtNodes.def
@@ -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