1 //=-- AggExprVisitor.cpp - evaluating expressions of C++ class type -*- C++ -*-=
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines AggExprVisitor class, which contains lots of boiler
11 // plate code for evaluating expressions of C++ class type.
13 //===----------------------------------------------------------------------===//
15 #include "clang/GR/PathSensitive/GRExprEngine.h"
16 #include "clang/AST/StmtVisitor.h"
18 using namespace clang
;
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.
28 class AggExprVisitor
: public StmtVisitor
<AggExprVisitor
> {
29 const MemRegion
*Dest
;
31 ExplodedNodeSet
&DstSet
;
35 AggExprVisitor(const MemRegion
*dest
, ExplodedNode
*N
, ExplodedNodeSet
&dst
,
37 : Dest(dest
), Pred(N
), DstSet(dst
), Eng(eng
) {}
39 void VisitCastExpr(CastExpr
*E
);
40 void VisitCXXConstructExpr(CXXConstructExpr
*E
);
44 void AggExprVisitor::VisitCastExpr(CastExpr
*E
) {
45 switch (E
->getCastKind()) {
47 assert(0 && "Unhandled cast kind");
49 case CK_ConstructorConversion
:
50 Visit(E
->getSubExpr());
55 void AggExprVisitor::VisitCXXConstructExpr(CXXConstructExpr
*E
) {
56 Eng
.VisitCXXConstructExpr(E
, Dest
, Pred
, DstSet
);
59 void GRExprEngine::VisitAggExpr(const Expr
*E
, const MemRegion
*Dest
,
60 ExplodedNode
*Pred
, ExplodedNodeSet
&Dst
) {
61 AggExprVisitor(Dest
, Pred
, Dst
, *this).Visit(const_cast<Expr
*>(E
));