Changeset 6840e7c for src/Parser/ExpressionNode.cc
- Timestamp:
- Oct 19, 2017, 12:01:04 PM (8 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 837ce06
- Parents:
- b96ec83 (diff), a15b72c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
rb96ec83 r6840e7c 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Sep 14 23:09:34201713 // Update Count : 69012 // Last Modified On : Wed Sep 27 22:51:55 2017 13 // Update Count : 781 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 ); 209 // Constant type is correct for overload resolving. 169 210 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.211 if ( Unsigned && size < 2 ) { // hh or h, less than int ? 212 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values. 172 213 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 ) ); 214 } else if ( lnth != -1 ) { // explicit length ? 215 if ( lnth == 5 ) { // int128 ? 216 size = 5; 217 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) ); 218 } else { 219 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) ); 220 } // if 175 221 } // if 176 222 CLEANUP: … … 182 228 return ret; 183 229 } // build_constantInteger 230 231 232 static inline void checkLNFloat( string & str, int & lnth, int & size ) { 233 string::size_type posn = str.find_first_of( "lL" ), start = posn; 234 if ( posn == string::npos ) return; 235 size = 2; // assume largest size 236 lnth = 0; 237 posn += 1; // advance to size 238 if ( str[posn] == '3' ) { // 32 239 size = 0; 240 } else if ( str[posn] == '6' ) { // 64 241 size = 1; 242 } else if ( str[posn] == '8' || str[posn] == '1' ) { // 80, 128 243 size = 2; 244 if ( str[posn] == '1' ) posn += 1; 245 } else { 246 assertf( false, "internal error, bad floating point length %s", str.c_str() ); 247 } // if 248 posn += 1; 249 str.erase( start, posn - start + 1 ); // remove length suffix 250 } // checkLNFloat 251 184 252 185 253 Expression * build_constantFloat( string & str ) { … … 189 257 }; 190 258 191 string units; // units259 string units; 192 260 sepNumeric( str, units ); // separate constant from units 193 261 194 262 bool complx = false; // real, complex 195 int size = 1; // 0 => float, 1 => double (default), 2 => long double 263 int size = 1; // 0 => float, 1 => double, 2 => long double 264 int lnth = -1; // literal length 196 265 // floating-point constant has minimum of 2 characters: 1. or .1 197 266 size_t last = str.length() - 1; … … 211 280 } else if ( checkL( str[last] ) ) { // long double ? 212 281 size = 2; 282 } else { 283 size = 1; // double (default) 284 checkLNFloat( str, lnth, size ); 213 285 } // if 214 286 if ( ! complx && checkI( str[last - 1] ) ) { // imaginary ? … … 216 288 } // if 217 289 290 assert( 0 <= size && size < 3 ); 218 291 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 292 if ( lnth != -1 ) { // explicit length ? 293 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) ); 294 } // if 219 295 if ( units.length() != 0 ) { 220 296 ret = new UntypedExpr( new NameExpr( units ), { ret } ); … … 321 397 322 398 NameExpr * build_varref( const string * name ) { 323 NameExpr * expr = new NameExpr( *name , nullptr);399 NameExpr * expr = new NameExpr( *name ); 324 400 delete name; 325 401 return expr; … … 412 488 list< Expression * > args; 413 489 buildMoveList( expr_node, args ); 414 return new UntypedExpr( maybeMoveBuild< Expression >(function), args , nullptr);490 return new UntypedExpr( maybeMoveBuild< Expression >(function), args ); 415 491 } // build_func 416 492
Note:
See TracChangeset
for help on using the changeset viewer.