Otawa  0.10
type.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * deprecated
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2003-10, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef OTAWA_TYPE_H
23 #define OTAWA_TYPE_H
24 
25 #include <elm/io.h>
26 
27 namespace otawa {
28 
29 using namespace elm;
30 
31 // Defined class
32 class Type;
33 class BaseType;
34 class NoType;
35 class BlockType;
36 
37 
38 // Type class
39 class Type {
40 protected:
41  virtual ~Type(void) { }
42 
43 public:
44 
45  // Kind
46  typedef enum kind_t {
47  NONE = 0,
48  BASE = 1,
49  ENUM = 2,
50  ARRAY = 3,
51  STRUCT = 4,
52  UNION = 5,
53  PTR = 6,
54  FUN = 7
55  } kind_t;
56 
57  // Base types
58  typedef enum base_t {
59  VOID = 0,
60  BLOCK = 1,
61  BOOL = 2,
62  CHAR = 3,
63  INT8 = 4,
64  UINT8 =5,
65  INT16 = 6,
66  UINT16 = 7,
67  INT32 = 8,
68  UINT32 = 9,
69  INT64 = 10,
70  UINT64 = 11,
71  FLOAT32 = 12,
72  FLOAT64 = 13,
73  FLOAT128 = 14,
74  ADDR32 = 15,
75  CSTRING = 16,
76  STRING_ = 17,
77  BASE_TOP = 18
78  } base_t;
79 
80  // Predefined types
81  static const NoType no_type;
82  static const BaseType void_type;
83  static const BaseType block_type;
84  static const BaseType bool_type;
85  static const BaseType char_type;
86  static const BaseType int8_type;
87  static const BaseType uint8_type;
88  static const BaseType int16_type;
89  static const BaseType uint16_type;
90  static const BaseType int32_type;
91  static const BaseType uint32_type;
92  static const BaseType int64_type;
93  static const BaseType uint64_type;
94  static const BaseType float32_type;
95  static const BaseType float64_type;
96  static const BaseType float128_type;
97  static const BaseType addr32_type;
98  static const BaseType cstring_type;
99  static const BaseType string_type;
100 
101  // Constructors
102  static const BaseType& getBaseType(base_t type);
103 
104  // Methods
105  inline bool equals(const Type& type) const { return this == &type; };
106  virtual kind_t kind(void) const = 0;
107  virtual const BaseType *toBase(void) const { return 0; };
108  virtual void print(elm::io::Output& output) const;
109 
110  // Operators
111  inline bool operator==(const Type& type) const { return equals(type); }
112  inline bool operator!=(const Type& type) const { return !equals(type); }
113 };
114 
115 
116 // NoType class
117 class NoType: public Type {
118 public:
119  inline NoType(void) { }
120 
121  // Type overload
122  virtual kind_t kind(void) const;
123  virtual void print(elm::io::Output& output) const;
124 };
125 
126 
127 // BaseType class
128 class BaseType: public Type {
129  friend class Type;
131  inline BaseType(base_t base_kind): bknd(base_kind) { };
132 public:
133  inline base_t base(void) const { return bknd; };
134 
135  // Type overload
136  virtual Type::kind_t kind(void) const { return Type::BASE; };
137  virtual const BaseType *toBase(void) const { return this; };
138  virtual void print(elm::io::Output& output) const;
139 };
140 
141 // typeof function
142 template <class T> struct __type { static inline const Type& _(void) { return Type::no_type; } };
143 
144 template <> struct __type<void> { static inline const Type& _(void) { return Type::void_type; } };
145 template <> struct __type<bool> { static inline const Type& _(void) { return Type::bool_type; } };
146 template <> struct __type<char> { static inline const Type& _(void) { return Type::char_type; } };
147 template <> struct __type<signed char> { static inline const Type& _(void) { return Type::int8_type; } };
148 template <> struct __type<unsigned char> { static inline const Type& _(void) { return Type::uint8_type; } };
149 template <> struct __type<short> { static inline const Type& _(void) { return Type::int16_type; } };
150 template <> struct __type<unsigned short> { static inline const Type& _(void) { return Type::uint16_type; } };
151 template <> struct __type<int> { static inline const Type& _(void) { return Type::int32_type; } };
152 template <> struct __type<unsigned int> { static inline const Type& _(void) { return Type::uint32_type; } };
153 template <> struct __type<long> { static inline const Type& _(void) { return Type::int32_type; } };
154 template <> struct __type<unsigned long> { static inline const Type& _(void) { return Type::uint32_type; } };
155 template <> struct __type<long long> { static inline const Type& _(void) { return Type::int64_type; } };
156 template <> struct __type<unsigned long long> { static inline const Type& _(void) { return Type::uint64_type; } };
157 template <> struct __type<float> { static inline const Type& _(void) { return Type::float32_type; } };
158 template <> struct __type<double> { static inline const Type& _(void) { return Type::float64_type; } };
159 template <> struct __type<long double> { static inline const Type& _(void) { return Type::float128_type; } };
160 template <> struct __type<elm::CString> { static inline const Type& _(void) { return Type::cstring_type; } };
161 template <> struct __type<elm::String> { static inline const Type& _(void) { return Type::string_type; } };
162 
163 template <class T> inline const Type& type(void) { return __type<T>::_(); }
164 
165 
166 // display
168  type.print(out);
169  return out;
170 }
171 
172 } // namespace otawa
173 
174 #endif // OTAWA_TYPE_H
static const Type & _(void)
Definition: type.h:146
static const BaseType float32_type
Definition: type.h:94
static const Type & _(void)
Definition: type.h:156
Definition: type.h:142
static const BaseType uint16_type
Definition: type.h:89
Null value for types.
Definition: type.h:117
Definition: type.h:48
static const Type & _(void)
Definition: type.h:160
Definition: inst.h:99
static const BaseType bool_type
Definition: type.h:84
Definition: ClpValue.h:54
static const Type & _(void)
Definition: type.h:148
static const BaseType uint8_type
Definition: type.h:87
static const Type & _(void)
Definition: type.h:157
NoType(void)
Definition: type.h:119
static const BaseType cstring_type
Definition: type.h:98
bool operator!=(const Type &type) const
Definition: type.h:112
static const Type & _(void)
Definition: type.h:152
Definition: inst.h:98
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
static const BaseType string_type
Definition: type.h:99
static const BaseType int32_type
Definition: type.h:90
Definition: inst.h:100
base_t bknd
Definition: type.h:130
ENUM(otawa::hard::Cache::replace_policy_t)
Inst::kind_t kind
Definition: odisasm.cpp:106
static const BaseType addr32_type
Definition: type.h:97
static const Type & _(void)
Definition: type.h:158
virtual Type::kind_t kind(void) const
Get the kind of the type.
Definition: type.h:136
static const BaseType block_type
Definition: type.h:83
Identifier< FunAST * > FUN
A property with this identifier is put on each instruction, start of an AST function.
kind_t
Allowed types for values: NONE represents nothing; REG is only used for addresses, and represents a register; VAL represents some values (either a constant or an interval); ALL is the Top element.
Definition: ClpValue.h:53
base_t base(void) const
Get the base type kind.
Definition: type.h:133
static const Type & _(void)
Definition: type.h:154
static const Type & _(void)
Definition: type.h:145
static const Type & _(void)
Definition: type.h:149
static const Type & _(void)
Definition: type.h:159
bool equals(const Type &type) const
Definition: type.h:105
virtual const BaseType * toBase(void) const
If the type is a base type, return it.
Definition: type.h:137
virtual const BaseType * toBase(void) const
If the type is a base type, return it.
Definition: type.h:107
Definition: inst.h:102
static const Type & _(void)
Definition: type.h:147
static const BaseType int16_type
Definition: type.h:88
virtual void print(elm::io::Output &output) const
Print a text representation of the type.
Definition: type.cpp:133
static const Type & _(void)
Definition: type.h:150
sys::SystemOutStream & out
static const Type & _(void)
Definition: type.h:144
static const BaseType uint64_type
Definition: type.h:93
This class provides a representation for the base type.
Definition: type.h:128
Definition: ParExeGraph.h:52
static const Type & _(void)
Definition: type.h:153
Definition: inst.h:97
virtual ~Type(void)
Definition: type.h:41
Definition: inst.h:96
static const BaseType float128_type
Definition: type.h:96
static const BaseType void_type
Definition: type.h:82
static const NoType no_type
Definition: type.h:81
Definition: inst.h:103
static const BaseType uint32_type
Definition: type.h:91
bool operator==(const Type &type) const
Definition: type.h:111
static const Type & _(void)
Definition: type.h:151
static const BaseType float64_type
Definition: type.h:95
Definition: inst.h:105
Definition: inst.h:104
BaseType(base_t base_kind)
Definition: type.h:131
static const BaseType char_type
Definition: type.h:85
static const Type & _(void)
Definition: type.h:155
static const BaseType int64_type
Definition: type.h:92
const Type & type(void)
Definition: type.h:163
This class describes the type of the data in the program.
Definition: type.h:39
static const Type & _(void)
Definition: type.h:142
Definition: inst.h:101
kind_t
Definition: type.h:46
void print(Output &out, const T &v)
Definition: Identifier.h:44
static const Type & _(void)
Definition: type.h:161
base_t
Definition: type.h:58
static const BaseType int8_type
Definition: type.h:86