Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

basic_type.h

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

Generated on Thu Jan 10 12:06:18 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001