Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 1 | //=-- AggExprVisitor.cpp - evaluating expressions of C++ class type -*- C++ -*-= |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines AggExprVisitor class, which contains lots of boiler |
| 11 | // plate code for evaluating expressions of C++ class type. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Checker/PathSensitive/GRExprEngine.h" |
| 16 | #include "clang/AST/StmtVisitor.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | namespace { |
Zhongxing Xu | 66af6ac | 2010-08-29 05:16:31 +0000 | [diff] [blame] | 21 | /// AggExprVisitor is designed after AggExprEmitter of the CodeGen module. It |
| 22 | /// is used for evaluating exprs of C++ object type. Evaluating such exprs |
| 23 | /// requires a destination pointer pointing to the object being evaluated |
| 24 | /// into. Passing such a pointer around would pollute the Visit* interface of |
| 25 | /// GRExprEngine. AggExprVisitor encapsulates code that goes through various |
| 26 | /// cast and construct exprs (and others), and at the final point, dispatches |
| 27 | /// back to the GRExprEngine to let the real evaluation logic happen. |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 28 | class AggExprVisitor : public StmtVisitor<AggExprVisitor> { |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame^] | 29 | const MemRegion *Dest; |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 30 | ExplodedNode *Pred; |
| 31 | ExplodedNodeSet &DstSet; |
| 32 | GRExprEngine &Eng; |
| 33 | |
| 34 | public: |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame^] | 35 | AggExprVisitor(const MemRegion *dest, ExplodedNode *N, ExplodedNodeSet &dst, |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 36 | GRExprEngine &eng) |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame^] | 37 | : Dest(dest), Pred(N), DstSet(dst), Eng(eng) {} |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 38 | |
| 39 | void VisitCastExpr(CastExpr *E); |
| 40 | void VisitCXXConstructExpr(CXXConstructExpr *E); |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | void AggExprVisitor::VisitCastExpr(CastExpr *E) { |
| 45 | switch (E->getCastKind()) { |
| 46 | default: |
| 47 | assert(0 && "Unhandled cast kind"); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 48 | case CK_NoOp: |
| 49 | case CK_ConstructorConversion: |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 50 | Visit(E->getSubExpr()); |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void AggExprVisitor::VisitCXXConstructExpr(CXXConstructExpr *E) { |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame^] | 56 | Eng.VisitCXXConstructExpr(E, Dest, Pred, DstSet); |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame^] | 59 | void GRExprEngine::VisitAggExpr(const Expr *E, const MemRegion *Dest, |
| 60 | ExplodedNode *Pred, ExplodedNodeSet &Dst) { |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 61 | AggExprVisitor(Dest, Pred, Dst, *this).Visit(const_cast<Expr *>(E)); |
| 62 | } |