Changes in src/Parser/ExpressionNode.cc [201aeb9:db70fe4]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r201aeb9 rdb70fe4 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Sep 26 11:23:36201713 // Update Count : 78012 // Last Modified On : Thu Sep 14 23:09:34 2017 13 // Update Count : 690 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 }; // lnthsInt66 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 size71 posn += 1; // advance to size72 if ( str[posn] == '8' ) { // 873 lnth = 0;74 } else if ( str[posn] == '1' ) {75 posn += 1;76 if ( str[posn] == '6' ) { // 1677 lnth = 1;78 } else { // 12879 posn += 1;80 lnth = 5;81 } // if82 } else {83 if ( str[posn] == '3' ) { // 3284 lnth = 2;85 } else if ( str[posn] == '6' ) { // 6486 lnth = 3;87 } else {88 assertf( false, "internal error, bad integral length %s", str.c_str() );89 } // if90 posn += 1;91 } // if92 str.erase( start, posn - start + 1 ); // remove length suffix93 } // checkLNInt94 95 62 static void sepNumeric( string & str, string & units ) { 96 63 string::size_type posn = str.find_first_of( "`" ); … … 102 69 103 70 Expression * build_constantInteger( string & str ) { 104 static const BasicType::Kind kind[2][ 6] = {71 static const BasicType::Kind kind[2][5] = { 105 72 // short (h) must be before char (hh) 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,},73 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 74 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 108 75 }; 109 76 110 string units; 77 string units; // units 111 78 sepNumeric( str, units ); // separate constant from units 112 79 113 80 bool dec = true, Unsigned = false; // decimal, unsigned constant 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 81 int size; // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t 117 82 unsigned long long int v; // converted integral value 118 83 size_t last = str.length() - 1; // last character of constant … … 175 140 } // if 176 141 str.erase( last - size - 1, size + 1 ); // remove 'h'/"hh" 177 } else { // suffix "ln" ?178 checkLNInt( str, lnth, size );179 142 } // if 180 143 } else if ( checkL( str[ last ] ) ) { // suffix 'l' ? … … 200 163 str.erase( last - size, size + 1 ); // remove 'h'/"hh" 201 164 } else if ( checkZ( str[last] ) ) { // suffix 'z' ? 202 lnth = 4;165 size = 5; 203 166 str.erase( last, 1 ); // remove 'z' 204 } else { // suffix "ln" ? 205 checkLNInt( str, lnth, size ); 206 } // if 207 208 assert( 0 <= size && size < 6 ); 167 } // if 168 209 169 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 210 if ( size < 2 ) { // hh or h,less than int ?211 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunatelyeliminates warnings for large values.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. 212 172 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) ); 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 173 } else if ( size == 5 ) { // explicit cast to size_t 174 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) ); 220 175 } // if 221 176 CLEANUP: … … 227 182 return ret; 228 183 } // 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 size235 lnth = 0;236 posn += 1; // advance to size237 if ( str[posn] == '3' ) { // 32238 size = 0;239 } else if ( str[posn] == '6' ) { // 64240 size = 1;241 } else if ( str[posn] == '8' || str[posn] == '1' ) { // 80, 128242 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 } // if247 posn += 1;248 str.erase( start, posn - start + 1 ); // remove length suffix249 } // checkLNFloat250 251 184 252 185 Expression * build_constantFloat( string & str ) { … … 256 189 }; 257 190 258 string units; 191 string units; // units 259 192 sepNumeric( str, units ); // separate constant from units 260 193 261 194 bool complx = false; // real, complex 262 int size = 1; // 0 => float, 1 => double, 2 => long double 263 int lnth = -1; // literal length 195 int size = 1; // 0 => float, 1 => double (default), 2 => long double 264 196 // floating-point constant has minimum of 2 characters: 1. or .1 265 197 size_t last = str.length() - 1; … … 279 211 } else if ( checkL( str[last] ) ) { // long double ? 280 212 size = 2; 281 } else {282 size = 1; // double (default)283 checkLNFloat( str, lnth, size );284 213 } // if 285 214 if ( ! complx && checkI( str[last - 1] ) ) { // imaginary ? … … 287 216 } // if 288 217 289 assert( 0 <= size && size < 3 );290 218 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 } // if294 219 if ( units.length() != 0 ) { 295 220 ret = new UntypedExpr( new NameExpr( units ), { ret } );
Note:
See TracChangeset
for help on using the changeset viewer.