[analyzer] Refactoring: include/clang/Checker -> include/clang/GR
[clang.git] / lib / Checker / AggExprVisitor.cpp
blobb8ec92ff8101fff455c3699827e5de68e044531b
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/GR/PathSensitive/GRExprEngine.h"
16 #include "clang/AST/StmtVisitor.h"
18 using namespace clang;
20 namespace {
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;
30 ExplodedNode *Pred;
31 ExplodedNodeSet &DstSet;
32 GRExprEngine &Eng;
34 public:
35 AggExprVisitor(const MemRegion *dest, ExplodedNode *N, ExplodedNodeSet &dst,
36 GRExprEngine &eng)
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()) {
46 default:
47 assert(0 && "Unhandled cast kind");
48 case CK_NoOp:
49 case CK_ConstructorConversion:
50 Visit(E->getSubExpr());
51 break;
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));