|
||
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
basic_type.hGo to the documentation of this file.00001 // $Id: basic_type.h,v 1.9 2003/08/11 17:13:57 abrown Exp $ 00002 // ---------------------------------------------------------------------- 00003 // 00004 // C-Breeze 00005 // C Compiler Framework 00006 // 00007 // Copyright (c) 2000 University of Texas at Austin 00008 // 00009 // Samuel Z. Guyer 00010 // Daniel A. Jimenez 00011 // Calvin Lin 00012 // 00013 // Permission is hereby granted, free of charge, to any person 00014 // obtaining a copy of this software and associated documentation 00015 // files (the "Software"), to deal in the Software without 00016 // restriction, including without limitation the rights to use, copy, 00017 // modify, merge, publish, distribute, sublicense, and/or sell copies 00018 // of the Software, and to permit persons to whom the Software is 00019 // furnished to do so, subject to the following conditions: 00020 // 00021 // The above copyright notice and this permission notice shall be 00022 // included in all copies or substantial portions of the Software. 00023 // 00024 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00025 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00026 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00027 // NONINFRINGEMENT. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT 00028 // AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 00029 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00030 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00031 // THE SOFTWARE. 00032 // 00033 // We acknowledge the C-to-C Translator from MIT Laboratory for 00034 // Computer Science for inspiring parts of the C-Breeze design. 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 // -- PRIVATE: Global values for basic type fields... 00049 00050 // -- Basic types 00051 static const unsigned int NO_TYPE, INT, CHAR, FLOAT, VOID, ELLIPSIS; 00052 00053 // -- Length 00054 static const unsigned int NO_LENGTH, SHORT, LONG, LONGLONG; 00055 00056 // -- Sign (NOTE: it defaults to signed) 00057 static const unsigned int NO_SIGN, SIGNED, UNSIGNED; 00058 00059 // -- Used in parsing only 00060 static const unsigned int PARSE_ONLY; 00061 00062 public: 00063 00064 // -- PUBLIC: Predefined global basic data types... 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 // -- For parsing only... 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 // -- Sizes and alignments 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 /* LONGLONG_SIZE, LONGLONG_ALIGN, */ 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 // -- Simple == operator 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 // -- Less-than operator for sets and maps 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 // -- Query and modify 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 // -- Type predicates 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 // -- Return a string representation 00205 00206 string to_string() const; 00207 string base_name() const; 00208 string length_name() const; 00209 string sign_name() const; 00210 00211 // -- Size and alignment 00212 00213 int size(); 00214 int alignment(); 00215 00216 // -- Merge basic types (used in MergePrimTypes type.c) 00217 00218 void merge_in(basic_type & other, Coord coord = Coord::Unknown); 00219 00220 // -- Finish (used in FinishPrimType type.c) 00221 00222 void finish(); 00223 00224 // -- Return the basic type as a single number 00225 00226 int to_num() const; 00227 00228 }; 00229 00230 00231 #endif // CBZ_BASIC_TYPE_H |
Generated on February 1, 2006
Back to the C-Breeze home page