00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef CBZ_BASIC_TYPE_H
00038 #define CBZ_BASIC_TYPE_H
00039
00040
00041
00042 class basic_type
00043 {
00044
00045 private:
00046
00047
00048
00049
00050 static const unsigned int NO_TYPE, INT, CHAR, FLOAT, VOID, ELLIPSIS;
00051
00052
00053 static const unsigned int NO_LENGTH, SHORT, LONG, LONGLONG;
00054
00055
00056 static const unsigned int NO_SIGN, SIGNED, UNSIGNED;
00057
00058
00059 static const unsigned int PARSE_ONLY;
00060
00061 public:
00062
00063
00064
00065 static const basic_type Void;
00066 static const basic_type Ellipsis;
00067 static const basic_type SChar, UChar;
00068 static const basic_type SShort, UShort, SInt, UInt, SLong, ULong;
00069 static const basic_type SLongLong, ULongLong;
00070 static const basic_type Float, Double, LongDouble;
00071
00072
00073
00074 static const basic_type Char, Int;
00075 static const basic_type Signed, Unsigned;
00076 static const basic_type Short, Long, LongLong;
00077 static const basic_type IntParseOnly;
00078
00079
00080
00081 static const unsigned int TARGET_MAX_UCHAR, TARGET_MAX_INT, TARGET_MAX_UINT,
00082 TARGET_MAX_LONG, TARGET_MAX_ULONG;
00083
00084 static const unsigned int CHAR_SIZE, CHAR_ALIGN, SHORT_SIZE, SHORT_ALIGN,
00085 INT_SIZE, INT_ALIGN, FLOAT_SIZE, FLOAT_ALIGN, DOUBLE_SIZE, DOUBLE_ALIGN,
00086 LONGDOUBLE_SIZE, LONGDOUBLE_ALIGN, LONG_SIZE, LONG_ALIGN,
00087 POINTER_SIZE, POINTER_ALIGN,
00088 BYTE_LENGTH, WORD_LENGTH;
00089
00090 private:
00091
00092 unsigned int _base_type:3;
00093 unsigned int _length:2;
00094 unsigned int _sign:2;
00095 unsigned int _parse_only:1;
00096
00097 inline unsigned int base_type() const { return _base_type; }
00098 inline void base_type(unsigned int bt) { _base_type = bt; }
00099
00100 inline unsigned int length() const { return _length; }
00101 inline void length(unsigned int l) { _length = l; }
00102
00103 inline unsigned int sign() const { return _sign; }
00104 inline void sign(unsigned int s) { _sign = s; }
00105
00106 public:
00107
00108 basic_type()
00109 : _base_type(0), _length(0), _sign(0), _parse_only(0)
00110 {}
00111
00112 basic_type(unsigned int sign, unsigned int length,
00113 unsigned int base_type, unsigned int parse_only = 0)
00114 : _base_type(base_type),
00115 _length(length),
00116 _sign(sign),
00117 _parse_only(parse_only)
00118 {}
00119
00120
00121
00122 bool operator==(const basic_type & bt2) const {
00123 return ((base_type() == bt2.base_type()) &&
00124 (length() == bt2.length()) &&
00125 (sign() == bt2.sign()));
00126 }
00127
00128
00129
00130 bool operator<(const basic_type & bt2) const {
00131 if (base_type() == bt2.base_type())
00132 if (length() == bt2.length())
00133 if (sign() == bt2.sign())
00134 return false;
00135 else
00136 return (sign() < bt2.sign());
00137 else
00138 return (length() < bt2.length());
00139 else
00140 return (base_type() < bt2.base_type());
00141 }
00142
00143
00144
00145 inline bool is_no_sign() const { return _sign == NO_SIGN; }
00146 inline void set_no_sign() { _sign = NO_SIGN; }
00147
00148 inline bool is_signed() const { return _sign == SIGNED; }
00149 inline void set_signed() { _sign = SIGNED; }
00150
00151 inline bool is_unsigned() const { return _sign == UNSIGNED; }
00152 inline void set_unsigned() { _sign = UNSIGNED; }
00153
00154 inline bool parse_only() const { return (_parse_only != 0); }
00155 inline void parse_only(bool po) { _parse_only = po ? 1 : 0; }
00156
00157 inline bool is_no_type() const { return _base_type == NO_TYPE; }
00158 inline void set_no_type() { _base_type = NO_TYPE; }
00159
00160 inline bool is_int() const { return _base_type == INT; }
00161 inline void set_int() { _base_type = INT; }
00162
00163 inline bool is_char() const { return _base_type == CHAR; }
00164 inline void set_char() { _base_type = CHAR; }
00165
00166 inline bool is_float() const { return _base_type == FLOAT; }
00167 inline void set_float() { _base_type = FLOAT; }
00168
00169 inline bool is_void() const { return _base_type == VOID; }
00170 inline void set_void() { _base_type = VOID; }
00171
00172 inline bool is_ellipsis() const { return _base_type == ELLIPSIS; }
00173 inline void set_ellipsis() { _base_type = ELLIPSIS; }
00174
00175 inline bool is_no_length() const { return _length == NO_LENGTH; }
00176 inline void set_no_length() { _length = NO_LENGTH; }
00177
00178 inline bool is_short() const { return _length == SHORT; }
00179 inline void set_short() { _length = SHORT; }
00180
00181 inline bool is_long() const { return _length == LONG; }
00182 inline void set_long() { _length = LONG; }
00183
00184 inline bool is_longlong() const { return _length == LONGLONG; }
00185 inline void set_longlong() { _length = LONGLONG; }
00186
00187
00188
00189 inline bool is_integer() const { return ((_base_type == INT) ||
00190 (_base_type == CHAR)); }
00191
00192 inline bool is_arithmetic() const { return ((_base_type == INT) ||
00193 (_base_type == CHAR) ||
00194 (_base_type == FLOAT)); }
00195
00196 inline bool is_scalar() const { return ((_base_type != VOID) &&
00197 (_base_type != ELLIPSIS)); }
00198
00199
00200
00201 string to_string() const;
00202 string base_name() const;
00203 string length_name() const;
00204 string sign_name() const;
00205
00206
00207
00208 int size();
00209 int alignment();
00210
00211
00212
00213 void merge_in(basic_type & other, Coord coord = Coord::Unknown);
00214
00215
00216
00217 void finish();
00218
00219 };
00220
00221
00222 #endif // CBZ_BASIC_TYPE_H