[analyzer] Move the files in lib/StaticAnalyzer to lib/StaticAnalyzer/Core.
[clang.git] / lib / StaticAnalyzer / Core / AggExprVisitor.cpp
blob0cc23900ed0fcb7cc931ce3082224e603c5a9506
1 //=-- 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.
13 //===----------------------------------------------------------------------===//
15 #include "clang/StaticAnalyzer/PathSensitive/ExprEngine.h"
16 #include "clang/AST/StmtVisitor.h"
18 using namespace clang;
19 using namespace ento;
21 namespace {
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;
31 ExplodedNode *Pred;
32 ExplodedNodeSet &DstSet;
33 ExprEngine &Eng;
35 public:
36 AggExprVisitor(const MemRegion *dest, ExplodedNode *N, ExplodedNodeSet &dst,
37 ExprEngine &eng)
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()) {
47 default:
48 assert(0 && "Unhandled cast kind");
49 case CK_NoOp:
50 case CK_ConstructorConversion:
51 Visit(E->getSubExpr());
52 break;
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));