From 13d130c3d225cdb5b1e6d9e86cea12eea718c707 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 21 Aug 2007 18:18:25 +0000 Subject: [PATCH] add unary operator support to the stmtvisitor git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41242 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 1 + include/clang/AST/StmtVisitor.h | 107 ++++++++++++++++---------------- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 26d98610d8..94cf512e30 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -271,6 +271,7 @@ public: /// extensions. class UnaryOperator : public Expr { public: + // Note that additions to this should also update the StmtVisitor class. enum Opcode { PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. diff --git a/include/clang/AST/StmtVisitor.h b/include/clang/AST/StmtVisitor.h index fd577c6975..426e09a475 100644 --- a/include/clang/AST/StmtVisitor.h +++ b/include/clang/AST/StmtVisitor.h @@ -67,6 +67,25 @@ public: case BinaryOperator::XorAssign: DISPATCH(BinXorAssign, BinaryOperator); case BinaryOperator::Comma: DISPATCH(BinComma, BinaryOperator); } + } else if (UnaryOperator *UnOp = dyn_cast(S)) { + switch (UnOp->getOpcode()) { + default: assert(0 && "Unknown unary operator!"); + case UnaryOperator::PostInc: DISPATCH(UnaryPostInc, UnaryOperator); + case UnaryOperator::PostDec: DISPATCH(UnaryPostDec, UnaryOperator); + case UnaryOperator::PreInc: DISPATCH(UnaryPreInc, UnaryOperator); + case UnaryOperator::PreDec: DISPATCH(UnaryPreDec, UnaryOperator); + case UnaryOperator::AddrOf: DISPATCH(UnaryAddrOf, UnaryOperator); + case UnaryOperator::Deref: DISPATCH(UnaryDeref, UnaryOperator); + case UnaryOperator::Plus: DISPATCH(UnaryPlus, UnaryOperator); + case UnaryOperator::Minus: DISPATCH(UnaryMinus, UnaryOperator); + case UnaryOperator::Not: DISPATCH(UnaryNot, UnaryOperator); + case UnaryOperator::LNot: DISPATCH(UnaryLNot, UnaryOperator); + case UnaryOperator::SizeOf: DISPATCH(UnarySizeOf, UnaryOperator); + case UnaryOperator::AlignOf: DISPATCH(UnaryAlignOf, UnaryOperator); + case UnaryOperator::Real: DISPATCH(UnaryReal, UnaryOperator); + case UnaryOperator::Imag: DISPATCH(UnaryImag, UnaryOperator); + case UnaryOperator::Extension: DISPATCH(UnaryExtension, UnaryOperator); + } } // Top switch stmt: dispatch to VisitFooStmt for each FooStmt. @@ -86,60 +105,44 @@ public: // If the implementation doesn't implement binary operator methods, fall back // on VisitBinaryOperator. - RetTy VisitBinMul(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinDiv(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinRem(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinAdd(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinSub(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinShl(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinShr(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinLT (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinGT (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinLE (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinGE (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinEQ (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinNE (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinAnd(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinXor(BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinOr (BinaryOperator *S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinLAnd(BinaryOperator*S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinLOr (BinaryOperator*S){DISPATCH(BinaryOperator,BinaryOperator);} - RetTy VisitBinAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); +#define BINOP_FALLBACK(NAME) \ + RetTy VisitBin ## NAME(BinaryOperator *S) { \ + DISPATCH(BinaryOperator, BinaryOperator); \ } - RetTy VisitBinMulAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinDivAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinRemAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinAddAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinSubAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinShlAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinShrAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinAndAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinOrAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinXorAssign(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); - } - RetTy VisitBinComma(BinaryOperator *S) { - DISPATCH(BinaryOperator,BinaryOperator); + BINOP_FALLBACK(Mul) BINOP_FALLBACK(Div) BINOP_FALLBACK(Rem) + BINOP_FALLBACK(Add) BINOP_FALLBACK(Sub) BINOP_FALLBACK(Shl) + BINOP_FALLBACK(Shr) + + BINOP_FALLBACK(LT) BINOP_FALLBACK(GT) BINOP_FALLBACK(LE) + BINOP_FALLBACK(GE) BINOP_FALLBACK(EQ) BINOP_FALLBACK(NE) + BINOP_FALLBACK(And) BINOP_FALLBACK(Xor) BINOP_FALLBACK(Or) + BINOP_FALLBACK(LAnd) BINOP_FALLBACK(LOr) + + BINOP_FALLBACK(Assign) + BINOP_FALLBACK(MulAssign) BINOP_FALLBACK(DivAssign) BINOP_FALLBACK(RemAssign) + BINOP_FALLBACK(AddAssign) BINOP_FALLBACK(SubAssign) BINOP_FALLBACK(ShlAssign) + BINOP_FALLBACK(ShrAssign) BINOP_FALLBACK(AndAssign) BINOP_FALLBACK(OrAssign) + BINOP_FALLBACK(XorAssign) + + BINOP_FALLBACK(Comma) +#undef BINOP_FALLBACK + + // If the implementation doesn't implement unary operator methods, fall back + // on VisitUnaryOperator. +#define UNARYOP_FALLBACK(NAME) \ + RetTy VisitUnary ## NAME(UnaryOperator *S) { \ + DISPATCH(UnaryOperator, UnaryOperator); \ } + UNARYOP_FALLBACK(PostInc) UNARYOP_FALLBACK(PostDec) + UNARYOP_FALLBACK(PreInc) UNARYOP_FALLBACK(PreDec) + UNARYOP_FALLBACK(AddrOf) UNARYOP_FALLBACK(Deref) + + UNARYOP_FALLBACK(Plus) UNARYOP_FALLBACK(Minus) + UNARYOP_FALLBACK(Not) UNARYOP_FALLBACK(LNot) + UNARYOP_FALLBACK(SizeOf) UNARYOP_FALLBACK(AlignOf) + UNARYOP_FALLBACK(Real) UNARYOP_FALLBACK(Imag) + UNARYOP_FALLBACK(Extension) +#undef UNARYOP_FALLBACK // Base case, ignore it. :) RetTy VisitStmt(Stmt *Node) { return RetTy(); } -- 2.40.0