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