blob: 6d472f46b45ac7b5c976ee50ada47b28aac6b0d6 [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> {
29 SVal DestPtr;
30 ExplodedNode *Pred;
31 ExplodedNodeSet &DstSet;
32 GRExprEngine &Eng;
33
34public:
35 AggExprVisitor(SVal dest, ExplodedNode *N, ExplodedNodeSet &dst,
36 GRExprEngine &eng)
37 : DestPtr(dest), Pred(N), DstSet(dst), Eng(eng) {}
38
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) {
56 Eng.VisitCXXConstructExpr(E, DestPtr, Pred, DstSet);
57}
58
59void GRExprEngine::VisitAggExpr(const Expr *E, SVal Dest, ExplodedNode *Pred,
60 ExplodedNodeSet &Dst) {
61 AggExprVisitor(Dest, Pred, Dst, *this).Visit(const_cast<Expr *>(E));
62}