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_CONSTANT_H
00038 #define CBZ_CONSTANT_H
00039
00040
00041
00042 class constant {
00043
00044 private:
00045
00046 union {
00047 signed char SChar;
00048 unsigned char UChar;
00049 signed short int SShort;
00050 unsigned short int UShort;
00051 signed int SInt;
00052 unsigned int UInt;
00053 signed long int SLong;
00054 unsigned long int ULong;
00055 float Float;
00056 double Double;
00057
00058 char * Str;
00059 void * Ptr;
00060 } _v;
00061
00062 basic_type _bt;
00063 bool _is_ptr;
00064 bool _is_str;
00065 bool _no_val;
00066
00067 public:
00068
00069 inline const basic_type & basic() const { return _bt; }
00070
00071 constant(signed char SChar)
00072 : _bt(basic_type::SChar), _is_ptr(false), _is_str(false), _no_val(false)
00073 { _v.SChar = SChar; }
00074
00075 inline signed char SChar() const { return _v.SChar; }
00076
00077 constant(unsigned char UChar)
00078 : _bt(basic_type::UChar), _is_ptr(false), _is_str(false), _no_val(false)
00079 { _v.UChar = UChar; }
00080
00081 inline unsigned char UChar() const { return _v.UChar; }
00082
00083 constant(signed short int SShort)
00084 : _bt(basic_type::SShort), _is_ptr(false), _is_str(false), _no_val(false)
00085 { _v.SShort = SShort; }
00086
00087 inline signed short int SShort() const { return _v.SShort; }
00088
00089 constant(unsigned short int UShort)
00090 : _bt(basic_type::UShort), _is_ptr(false), _is_str(false), _no_val(false)
00091 { _v.UShort = UShort; }
00092
00093 inline unsigned short int UShort() const { return _v.UShort; }
00094
00095 constant(signed int SInt)
00096 : _bt(basic_type::SInt), _is_ptr(false), _is_str(false), _no_val(false)
00097 { _v.SInt = SInt; }
00098
00099 inline signed int SInt() const { return _v.SInt; }
00100
00101 constant(unsigned int UInt)
00102 : _bt(basic_type::UInt), _is_ptr(false), _is_str(false), _no_val(false)
00103 { _v.UInt = UInt; }
00104
00105 inline unsigned int UInt() const { return _v.UInt; }
00106
00107 constant(signed long int SLong)
00108 : _bt(basic_type::SLong), _is_ptr(false), _is_str(false), _no_val(false)
00109 { _v.SLong = SLong; }
00110
00111 inline signed long int SLong() const { return _v.SLong; }
00112
00113 constant(unsigned long int ULong)
00114 : _bt(basic_type::ULong), _is_ptr(false), _is_str(false), _no_val(false)
00115 { _v.ULong = ULong; }
00116
00117 inline unsigned long int ULong() const { return _v.ULong; }
00118
00119 constant(float Float)
00120 : _bt(basic_type::Float), _is_ptr(false), _is_str(false), _no_val(false)
00121 { _v.Float = Float; }
00122
00123 inline float Float() const { return _v.Float; }
00124
00125 constant(double Double)
00126 : _bt(basic_type::Double), _is_ptr(false), _is_str(false), _no_val(false)
00127 { _v.Double = Double; }
00128
00129 inline double Double() const { return _v.Double; }
00130
00131 constant(const char * Str)
00132 : _bt(), _is_ptr(false), _is_str(true), _no_val(false)
00133 { _v.Str = strdup(Str); }
00134
00135 inline char * Str() const { return _v.Str; }
00136 inline bool is_str() const { return _is_str; }
00137
00138 constant(void * Ptr)
00139 : _bt(), _is_ptr(true), _is_str(false), _no_val(false)
00140 { _v.Ptr = Ptr; }
00141
00142 inline void * Ptr() const { return _v.Ptr; }
00143 inline bool is_ptr() const { return _is_ptr; }
00144
00145 constant()
00146 : _bt(), _is_ptr(false), _is_str(false), _no_val(true)
00147 {}
00148
00149 inline bool no_val() const { return _no_val; }
00150 inline void set_no_val() { _no_val = true; }
00151
00152
00153
00154 constant(const constant & other);
00155
00156
00157
00158 ~constant();
00159
00160
00161
00162 constant & operator=(const constant & rhs);
00163
00164
00165
00166 unsigned long Integer() const;
00167 bool Boolean() const;
00168 bool is_zero() const;
00169
00170
00171
00172 bool is_equal_to(const constant & other) const;
00173
00174
00175
00176 bool operator<(const constant & other) const;
00177
00178
00179
00180 static constant eval(const Operator * op,
00181 const constant & operand1,
00182 const constant & operand2);
00183
00184 static constant eval(const Operator * op,
00185 const constant & operand);
00186
00187 static constant cast(const basic_type & new_bt, const constant & con);
00188
00189
00190
00191 string to_string() const;
00192
00193 private:
00194
00195 static void print_char(int value, ostrstream & ost);
00196
00197 };
00198
00199
00200
00201 #endif // CBZ_CONSTANT_H