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/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
16 #include "clang/AST/StmtVisitor.h"
18 using namespace clang
;
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
26 /// ExprEngine. AggExprVisitor encapsulates code that goes through various
27 /// cast and construct exprs (and others), and at the final point, dispatches
28 /// back to the ExprEngine to let the real evaluation logic happen.
29 class AggExprVisitor
: public StmtVisitor
<AggExprVisitor
> {
30 const MemRegion
*Dest
;
32 ExplodedNodeSet
&DstSet
;
36 AggExprVisitor(const MemRegion
*dest
, ExplodedNode
*N
, ExplodedNodeSet
&dst
,
38 : Dest(dest
), Pred(N
), DstSet(dst
), Eng(eng
) {}
40 void VisitCastExpr(CastExpr
*E
);
41 void VisitCXXConstructExpr(CXXConstructExpr
*E
);
45 void AggExprVisitor::VisitCastExpr(CastExpr
*E
) {
46 switch (E
->getCastKind()) {
48 assert(0 && "Unhandled cast kind");
50 case CK_ConstructorConversion
:
51 Visit(E
->getSubExpr());
56 void AggExprVisitor::VisitCXXConstructExpr(CXXConstructExpr
*E
) {
57 Eng
.VisitCXXConstructExpr(E
, Dest
, Pred
, DstSet
);
60 void ExprEngine::VisitAggExpr(const Expr
*E
, const MemRegion
*Dest
,
61 ExplodedNode
*Pred
, ExplodedNodeSet
&Dst
) {
62 AggExprVisitor(Dest
, Pred
, Dst
, *this).Visit(const_cast<Expr
*>(E
));