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 | |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 15 | #include "clang/GR/PathSensitive/ExprEngine.h" |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 16 | #include "clang/AST/StmtVisitor.h" |
| 17 | |
| 18 | using namespace clang; |
Argyrios Kyrtzidis | 5a4f98f | 2010-12-22 18:53:20 +0000 | [diff] [blame] | 19 | using namespace GR; |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 20 | |
| 21 | namespace { |
Zhongxing Xu | 66af6ac | 2010-08-29 05:16:31 +0000 | [diff] [blame] | 22 | /// AggExprVisitor is designed after AggExprEmitter of the CodeGen module. It |
| 23 | /// is used for evaluating exprs of C++ object type. Evaluating such exprs |
| 24 | /// requires a destination pointer pointing to the object being evaluated |
| 25 | /// into. Passing such a pointer around would pollute the Visit* interface of |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 26 | /// ExprEngine. AggExprVisitor encapsulates code that goes through various |
Zhongxing Xu | 66af6ac | 2010-08-29 05:16:31 +0000 | [diff] [blame] | 27 | /// cast and construct exprs (and others), and at the final point, dispatches |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 28 | /// back to the ExprEngine to let the real evaluation logic happen. |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 29 | class AggExprVisitor : public StmtVisitor<AggExprVisitor> { |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame] | 30 | const MemRegion *Dest; |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 31 | ExplodedNode *Pred; |
| 32 | ExplodedNodeSet &DstSet; |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 33 | ExprEngine &Eng; |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 34 | |
| 35 | public: |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame] | 36 | AggExprVisitor(const MemRegion *dest, ExplodedNode *N, ExplodedNodeSet &dst, |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 37 | ExprEngine &eng) |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame] | 38 | : Dest(dest), Pred(N), DstSet(dst), Eng(eng) {} |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 39 | |
| 40 | void VisitCastExpr(CastExpr *E); |
| 41 | void VisitCXXConstructExpr(CXXConstructExpr *E); |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | void AggExprVisitor::VisitCastExpr(CastExpr *E) { |
| 46 | switch (E->getCastKind()) { |
| 47 | default: |
| 48 | assert(0 && "Unhandled cast kind"); |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 49 | case CK_NoOp: |
| 50 | case CK_ConstructorConversion: |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 51 | Visit(E->getSubExpr()); |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void AggExprVisitor::VisitCXXConstructExpr(CXXConstructExpr *E) { |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 57 | Eng.VisitCXXConstructExpr(E, Dest, Pred, DstSet); |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Argyrios Kyrtzidis | d2592a3 | 2010-12-22 18:53:44 +0000 | [diff] [blame^] | 60 | void ExprEngine::VisitAggExpr(const Expr *E, const MemRegion *Dest, |
Zhongxing Xu | 7ce351d | 2010-11-01 09:09:44 +0000 | [diff] [blame] | 61 | ExplodedNode *Pred, ExplodedNodeSet &Dst) { |
Zhongxing Xu | 7b71c19 | 2010-03-23 07:32:14 +0000 | [diff] [blame] | 62 | AggExprVisitor(Dest, Pred, Dst, *this).Visit(const_cast<Expr *>(E)); |
| 63 | } |