aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Analysis/PathSensitive/GRTransferFuncs.h
blob: 19e87dcd943185b57b155faa9c4a04fbd5c3cb2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//== GRTransferFuncs.h - Path-Sens. Transfer Functions Interface -*- C++ -*--=//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This files defines GRTransferFuncs, which provides a base-class that
//  defines an interface for transfer functions used by GRExprEngine.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_ANALYSIS_GRTF
#define LLVM_CLANG_ANALYSIS_GRTF

#include "clang/Analysis/PathSensitive/RValues.h"

namespace clang {
  
class GRTransferFuncs {
public:
  GRTransferFuncs() {}
  virtual ~GRTransferFuncs() {}
  
  // Casts.
  
  RValue EvalCast(ValueManager& ValMgr, RValue V, Expr* CastExpr);
  virtual RValue EvalCast(ValueManager& ValMgr, NonLValue V, Expr* CastExpr) =0;
  virtual RValue EvalCast(ValueManager& ValMgr, LValue V, Expr* CastExpr) = 0;

  // Unary Operators.
  
  virtual NonLValue EvalMinus(ValueManager& ValMgr, UnaryOperator* U,
                              NonLValue X) = 0;

  virtual NonLValue EvalComplement(ValueManager& ValMgr, NonLValue X) = 0;

  // Binary Operators.
  
  virtual NonLValue EvalBinaryOp(ValueManager& ValMgr,
                                 BinaryOperator::Opcode Op,
                                 NonLValue LHS, NonLValue RHS) = 0;
  
  RValue EvalBinaryOp(ValueManager& ValMgr,
                      BinaryOperator::Opcode Op,
                      LValue LHS, LValue RHS);
  
  // Pointer arithmetic.
  
  virtual LValue EvalBinaryOp(ValueManager& ValMgr, BinaryOperator::Opcode Op,
                              LValue LHS, NonLValue RHS) = 0;
  
  inline RValue EvalBinaryOp(ValueManager& ValMgr, BinaryOperator::Opcode Op,
                             const RValue& L, const RValue& R) {
    
    if (isa<LValue>(L)) {
      if (isa<LValue>(R))
        return EvalBinaryOp(ValMgr, Op, cast<LValue>(L), cast<LValue>(R));
      else
        return EvalBinaryOp(ValMgr, Op, cast<LValue>(L), cast<NonLValue>(R));
    }
    else
      return EvalBinaryOp(ValMgr, Op, cast<NonLValue>(L), cast<NonLValue>(R));
  }
  
  
  // Equality operators for LValues.
  virtual NonLValue EvalEQ(ValueManager& ValMgr, LValue LHS, LValue RHS) = 0;
  virtual NonLValue EvalNE(ValueManager& ValMgr, LValue LHS, LValue RHS) = 0;
};
  
} // end clang namespace

#endif