blob: 45022986de7cbc979562758c6be65436d71fc002 [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
Argyrios Kyrtzidisd2592a32010-12-22 18:53:44 +000015#include "clang/GR/PathSensitive/ExprEngine.h"
Zhongxing Xu7b71c192010-03-23 07:32:14 +000016#include "clang/AST/StmtVisitor.h"
17
18using namespace clang;
Argyrios Kyrtzidis5a4f98f2010-12-22 18:53:20 +000019using namespace GR;
Zhongxing Xu7b71c192010-03-23 07:32:14 +000020
21namespace {
Zhongxing Xu66af6ac2010-08-29 05:16:31 +000022/// 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 Kyrtzidisd2592a32010-12-22 18:53:44 +000026/// ExprEngine. AggExprVisitor encapsulates code that goes through various
Zhongxing Xu66af6ac2010-08-29 05:16:31 +000027/// cast and construct exprs (and others), and at the final point, dispatches
Argyrios Kyrtzidisd2592a32010-12-22 18:53:44 +000028/// back to the ExprEngine to let the real evaluation logic happen.
Zhongxing Xu7b71c192010-03-23 07:32:14 +000029class AggExprVisitor : public StmtVisitor<AggExprVisitor> {
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000030 const MemRegion *Dest;
Zhongxing Xu7b71c192010-03-23 07:32:14 +000031 ExplodedNode *Pred;
32 ExplodedNodeSet &DstSet;
Argyrios Kyrtzidisd2592a32010-12-22 18:53:44 +000033 ExprEngine &Eng;
Zhongxing Xu7b71c192010-03-23 07:32:14 +000034
35public:
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000036 AggExprVisitor(const MemRegion *dest, ExplodedNode *N, ExplodedNodeSet &dst,
Argyrios Kyrtzidisd2592a32010-12-22 18:53:44 +000037 ExprEngine &eng)
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000038 : Dest(dest), Pred(N), DstSet(dst), Eng(eng) {}
Zhongxing Xu7b71c192010-03-23 07:32:14 +000039
40 void VisitCastExpr(CastExpr *E);
41 void VisitCXXConstructExpr(CXXConstructExpr *E);
42};
43}
44
45void AggExprVisitor::VisitCastExpr(CastExpr *E) {
46 switch (E->getCastKind()) {
47 default:
48 assert(0 && "Unhandled cast kind");
John McCall2de56d12010-08-25 11:45:40 +000049 case CK_NoOp:
50 case CK_ConstructorConversion:
Zhongxing Xu7b71c192010-03-23 07:32:14 +000051 Visit(E->getSubExpr());
52 break;
53 }
54}
55
56void AggExprVisitor::VisitCXXConstructExpr(CXXConstructExpr *E) {
Ted Kremenek892697d2010-12-16 07:46:53 +000057 Eng.VisitCXXConstructExpr(E, Dest, Pred, DstSet);
Zhongxing Xu7b71c192010-03-23 07:32:14 +000058}
59
Argyrios Kyrtzidisd2592a32010-12-22 18:53:44 +000060void ExprEngine::VisitAggExpr(const Expr *E, const MemRegion *Dest,
Zhongxing Xu7ce351d2010-11-01 09:09:44 +000061 ExplodedNode *Pred, ExplodedNodeSet &Dst) {
Zhongxing Xu7b71c192010-03-23 07:32:14 +000062 AggExprVisitor(Dest, Pred, Dst, *this).Visit(const_cast<Expr *>(E));
63}