Changeset 201aeb9 for src/Parser/ExpressionNode.cc
- Timestamp:
- Sep 26, 2017, 11:22:08 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d67cdb7
- Parents:
- 9bae71f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r9bae71f r201aeb9 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Sep 14 23:09:34201713 // Update Count : 69012 // Last Modified On : Tue Sep 26 11:23:36 2017 13 // Update Count : 780 14 14 // 15 15 … … 60 60 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 61 61 62 static const char * lnthsInt[2][6] = { 63 { "int8_t", "int16_t", "int32_t", "int64_t", "size_t", }, 64 { "uint8_t", "uint16_t", "uint32_t", "uint64_t", "size_t", } 65 }; // lnthsInt 66 67 static inline void checkLNInt( string & str, int & lnth, int & size ) { 68 string::size_type posn = str.find_first_of( "lL" ), start = posn; 69 if ( posn == string::npos ) return; 70 size = 4; // assume largest size 71 posn += 1; // advance to size 72 if ( str[posn] == '8' ) { // 8 73 lnth = 0; 74 } else if ( str[posn] == '1' ) { 75 posn += 1; 76 if ( str[posn] == '6' ) { // 16 77 lnth = 1; 78 } else { // 128 79 posn += 1; 80 lnth = 5; 81 } // if 82 } else { 83 if ( str[posn] == '3' ) { // 32 84 lnth = 2; 85 } else if ( str[posn] == '6' ) { // 64 86 lnth = 3; 87 } else { 88 assertf( false, "internal error, bad integral length %s", str.c_str() ); 89 } // if 90 posn += 1; 91 } // if 92 str.erase( start, posn - start + 1 ); // remove length suffix 93 } // checkLNInt 94 62 95 static void sepNumeric( string & str, string & units ) { 63 96 string::size_type posn = str.find_first_of( "`" ); … … 69 102 70 103 Expression * build_constantInteger( string & str ) { 71 static const BasicType::Kind kind[2][ 5] = {104 static const BasicType::Kind kind[2][6] = { 72 105 // short (h) must be before char (hh) 73 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },74 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },106 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt128, }, 107 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt128, }, 75 108 }; 76 109 77 string units; // units110 string units; 78 111 sepNumeric( str, units ); // separate constant from units 79 112 80 113 bool dec = true, Unsigned = false; // decimal, unsigned constant 81 int size; // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t 114 int size; // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => int128 115 int lnth = -1; // literal length 116 82 117 unsigned long long int v; // converted integral value 83 118 size_t last = str.length() - 1; // last character of constant … … 140 175 } // if 141 176 str.erase( last - size - 1, size + 1 ); // remove 'h'/"hh" 177 } else { // suffix "ln" ? 178 checkLNInt( str, lnth, size ); 142 179 } // if 143 180 } else if ( checkL( str[ last ] ) ) { // suffix 'l' ? … … 163 200 str.erase( last - size, size + 1 ); // remove 'h'/"hh" 164 201 } else if ( checkZ( str[last] ) ) { // suffix 'z' ? 165 size = 5;202 lnth = 4; 166 203 str.erase( last, 1 ); // remove 'z' 167 } // if 168 204 } else { // suffix "ln" ? 205 checkLNInt( str, lnth, size ); 206 } // if 207 208 assert( 0 <= size && size < 6 ); 169 209 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 170 if ( Unsigned && size < 2 ) { //less than int ?171 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates warnings for large values.210 if ( size < 2 ) { // hh or h, less than int ? 211 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values. 172 212 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) ); 173 } else if ( size == 5 ) { // explicit cast to size_t 174 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) ); 213 } else if ( lnth != -1 ) { // explicit length ? 214 if ( lnth == 5 ) { // int128 ? 215 size = 5; 216 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) ); 217 } else { 218 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) ); 219 } // if 175 220 } // if 176 221 CLEANUP: … … 182 227 return ret; 183 228 } // build_constantInteger 229 230 231 static inline void checkLNFloat( string & str, int & lnth, int & size ) { 232 string::size_type posn = str.find_first_of( "lL" ), start = posn; 233 if ( posn == string::npos ) return; 234 size = 2; // assume largest size 235 lnth = 0; 236 posn += 1; // advance to size 237 if ( str[posn] == '3' ) { // 32 238 size = 0; 239 } else if ( str[posn] == '6' ) { // 64 240 size = 1; 241 } else if ( str[posn] == '8' || str[posn] == '1' ) { // 80, 128 242 size = 2; 243 if ( str[posn] == '1' ) posn += 1; 244 } else { 245 assertf( false, "internal error, bad floating point length %s", str.c_str() ); 246 } // if 247 posn += 1; 248 str.erase( start, posn - start + 1 ); // remove length suffix 249 } // checkLNFloat 250 184 251 185 252 Expression * build_constantFloat( string & str ) { … … 189 256 }; 190 257 191 string units; // units258 string units; 192 259 sepNumeric( str, units ); // separate constant from units 193 260 194 261 bool complx = false; // real, complex 195 int size = 1; // 0 => float, 1 => double (default), 2 => long double 262 int size = 1; // 0 => float, 1 => double, 2 => long double 263 int lnth = -1; // literal length 196 264 // floating-point constant has minimum of 2 characters: 1. or .1 197 265 size_t last = str.length() - 1; … … 211 279 } else if ( checkL( str[last] ) ) { // long double ? 212 280 size = 2; 281 } else { 282 size = 1; // double (default) 283 checkLNFloat( str, lnth, size ); 213 284 } // if 214 285 if ( ! complx && checkI( str[last - 1] ) ) { // imaginary ? … … 216 287 } // if 217 288 289 assert( 0 <= size && size < 3 ); 218 290 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 291 if ( lnth != -1 ) { // explicit length ? 292 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) ); 293 } // if 219 294 if ( units.length() != 0 ) { 220 295 ret = new UntypedExpr( new NameExpr( units ), { ret } );
Note: See TracChangeset
for help on using the changeset viewer.