blob: f31bcec73adc2b52cee1ca1d566d4c37b08100c0 [file] [log] [blame]
Zhongxing Xu7b71c192010-03-23 07:32:14 +00001//=-- 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
18using namespace clang;
19
20namespace {
Zhongxing Xu66af6ac2010-08-29 05:16:31 +000021/// 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 Xu7b71c192010-03-23 07:32:14 +000028class AggExprVisitor : public StmtVisitor<AggExprVisitor> {
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000029 const MemRegion *Dest;
Zhongxing Xu7b71c192010-03-23 07:32:14 +000030 ExplodedNode *Pred;
31 ExplodedNodeSet &DstSet;
32 GRExprEngine &Eng;
33
34public:
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000035 AggExprVisitor(const MemRegion *dest, ExplodedNode *N, ExplodedNodeSet &dst,
Zhongxing Xu7b71c192010-03-23 07:32:14 +000036 GRExprEngine &eng)
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000037 : Dest(dest), Pred(N), DstSet(dst), Eng(eng) {}
Zhongxing Xu7b71c192010-03-23 07:32:14 +000038
39 void VisitCastExpr(CastExpr *E);
40 void VisitCXXConstructExpr(CXXConstructExpr *E);
41};
42}
43
44void AggExprVisitor::VisitCastExpr(CastExpr *E) {
45 switch (E->getCastKind()) {
46 default:
47 assert(0 && "Unhandled cast kind");
John McCall2de56d12010-08-25 11:45:40 +000048 case CK_NoOp:
49 case CK_ConstructorConversion:
Zhongxing Xu7b71c192010-03-23 07:32:14 +000050 Visit(E->getSubExpr());
51 break;
52 }
53}
54
55void AggExprVisitor::VisitCXXConstructExpr(CXXConstructExpr *E) {
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000056 Eng.VisitCXXConstructExpr(E, Dest, Pred, DstSet);
Zhongxing Xu7b71c192010-03-23 07:32:14 +000057}
58
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000059void GRExprEngine::VisitAggExpr(const Expr *E, const MemRegion *Dest,
60 ExplodedNode *Pred, ExplodedNodeSet &Dst) {
Zhongxing Xu7b71c192010-03-23 07:32:14 +000061 AggExprVisitor(Dest, Pred, Dst, *this).Visit(const_cast<Expr *>(E));
62}