aboutsummaryrefslogtreecommitdiff
path: root/include/clang/AST/ExprCXX.h
blob: 14b1cc7d3aff1ce68b366003689d35641f46fcf3 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Bill Wendling and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines the Expr interface and subclasses for C++ expressions.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_EXPRCXX_H
#define LLVM_CLANG_AST_EXPRCXX_H

#include "clang/AST/Expr.h"

namespace clang {

  //===--------------------------------------------------------------------===//
  // C++ Expressions.
  //===--------------------------------------------------------------------===//

  /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
  /// 
  class CXXCastExpr : public Expr {
  public:
    enum Opcode {
      DynamicCast,
      StaticCast,
      ReinterpretCast,
      ConstCast
    };
  private:
    QualType Ty;
    Opcode Opc;
    Expr *Op;
    SourceLocation Loc; // the location of the casting op
  public:
    CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l)
      : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {}

    QualType getDestType() const { return Ty; }
    Expr *getSubExpr() const { return Op; }
  
    Opcode getOpcode() const { return Opc; }

    /// getOpcodeStr - Turn an Opcode enum value into the string it represents,
    /// e.g. "reinterpret_cast".
    static const char *getOpcodeStr(Opcode Op) {
      // FIXME: move out of line.
      switch (Op) {
      default: assert(0 && "Not a C++ cast expression");
      case CXXCastExpr::ConstCast:       return "const_cast";
      case CXXCastExpr::DynamicCast:     return "dynamic_cast";
      case CXXCastExpr::ReinterpretCast: return "reinterpret_cast";
      case CXXCastExpr::StaticCast:      return "static_cast";
      }
    }
    
    virtual SourceRange getSourceRange() const {
      return SourceRange(Loc, getSubExpr()->getSourceRange().End());
    }
    static bool classof(const Stmt *T) { 
      return T->getStmtClass() == CXXCastExprClass;
    }
    static bool classof(const CXXCastExpr *) { return true; }
        
    // Iterators
    virtual child_iterator child_begin();
    virtual child_iterator child_end();
  };

  /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
  /// 
  class CXXBoolLiteralExpr : public Expr {
    bool Value;
    SourceLocation Loc;
  public:
    CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 
      Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
    
    bool getValue() const { return Value; }

    virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
      
    static bool classof(const Stmt *T) { 
      return T->getStmtClass() == CXXBoolLiteralExprClass;
    }
    static bool classof(const CXXBoolLiteralExpr *) { return true; }
        
    // Iterators
    virtual child_iterator child_begin();
    virtual child_iterator child_end();
  };

}  // end namespace clang

#endif