Changes in src/Parser/ExpressionNode.cc [013b028:b81fd95]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cc (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r013b028 rb81fd95 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 20 14:01:46202013 // Update Count : 10 7612 // Last Modified On : Wed Jul 15 08:24:08 2020 13 // Update Count : 1046 14 14 // 15 15 … … 65 65 66 66 void lnthSuffix( string & str, int & type, int & ltype ) { 67 // 'u' can appear before or after length suffix68 67 string::size_type posn = str.find_last_of( "lL" ); 69 68 70 69 if ( posn == string::npos ) return; // no suffix 71 size_t end = str.length() - 1; 72 if ( posn == end ) { type = 3; return; } // no length after 'l' => long 73 70 if ( posn == str.length() - 1 ) { type = 3; return; } // no length => long 71 74 72 string::size_type next = posn + 1; // advance to length 75 73 if ( str[next] == '3' ) { // 32 … … 86 84 } // if 87 85 } // if 88 89 char fix = '\0'; 90 if ( str[end] == 'u' || str[end] == 'U' ) fix = str[end]; // ends with 'uU' ? 91 str.erase( posn ); // remove length suffix and possibly uU 92 if ( type == 5 ) { // L128 does not need uU 93 end = str.length() - 1; 94 if ( str[end] == 'u' || str[end] == 'U' ) str.erase( end ); // ends with 'uU' ? remove 95 } else if ( fix != '\0' ) str += fix; // put 'uU' back if removed 86 // remove "lL" for these cases because it may not imply long 87 str.erase( posn ); // remove length suffix and "uU" 96 88 } // lnthSuffix 97 89 … … 164 156 if ( isdigit( str[str.length() - 1] ) ) { // no suffix ? 165 157 lnthSuffix( str, type, ltype ); // could have length suffix 158 if ( type == 5 && Unsigned ) str.erase( str.length() - 1 ); // L128 and terminating "uU" ? 166 159 } else { 167 160 // At least one digit in integer constant, so safe to backup while looking for suffix. … … 202 195 if ( type < 5 ) { // not L128 ? 203 196 sscanf( (char *)str.c_str(), "%llx", &v ); 204 #if defined(__SIZEOF_INT128__)205 197 } else { // hex int128 constant 206 198 unsigned int len = str.length(); … … 212 204 FHEX1: ; 213 205 sscanf( (char *)str.c_str(), "%llx", &v ); 214 #endif // __SIZEOF_INT128__215 206 } // if 216 207 //printf( "%llx %llu\n", v, v ); 217 208 } else if ( checkB( str[1] ) ) { // binary constant ? 218 #if defined(__SIZEOF_INT128__)219 209 unsigned int len = str.length(); 220 210 if ( type == 5 && len > 2 + 64 ) { … … 224 214 scanbin( str2, v2 ); 225 215 } // if 226 #endif // __SIZEOF_INT128__227 216 scanbin( str, v ); 228 217 //printf( "%#llx %llu\n", v, v ); … … 234 223 unsigned int len = str.length(); 235 224 if ( len > 1 + 43 || (len == 1 + 43 && str[0] > '3') ) SemanticError( yylloc, "128-bit octal constant to large " + str ); 236 char buf[32];237 225 if ( len <= 1 + 21 ) { // value < 21 octal digitis 238 sscanf( (char *)str.c_str(), "%llo", &v ); 226 sscanf( (char *)str.c_str(), "%llo", &v ); // leave value in octal 239 227 } else { 240 228 sscanf( &str[len - 21], "%llo", &v ); … … 249 237 } // if 250 238 v = val >> 64; v2 = (uint64_t)val; // replace octal constant with 2 hex constants 239 char buf[32]; 251 240 sprintf( buf, "%#llx", v2 ); 252 241 str2 = buf; 242 sprintf( buf, "%#llx", v ); 243 str = buf; 253 244 } // if 254 sprintf( buf, "%#llx", v );255 str = buf;256 245 #endif // __SIZEOF_INT128__ 257 246 } // if … … 267 256 if ( str.length() == 39 && str > (Unsigned ? "340282366920938463463374607431768211455" : "170141183460469231731687303715884105727") ) 268 257 SemanticError( yylloc, "128-bit decimal constant to large " + str ); 269 char buf[32];270 258 if ( len <= 19 ) { // value < 19 decimal digitis 271 sscanf( (char *)str.c_str(), "%llu", &v ); 259 sscanf( (char *)str.c_str(), "%llu", &v ); // leave value in decimal 272 260 } else { 273 261 sscanf( &str[len - 19], "%llu", &v ); … … 282 270 } // if 283 271 v = val >> 64; v2 = (uint64_t)val; // replace decimal constant with 2 hex constants 272 char buf[32]; 284 273 sprintf( buf, "%#llx", v2 ); 285 274 str2 = buf; 275 sprintf( buf, "%#llx", v ); 276 str = buf; 286 277 } // if 287 sprintf( buf, "%#llx", v );288 str = buf;289 278 #endif // __SIZEOF_INT128__ 290 279 } // if
Note:
See TracChangeset
for help on using the changeset viewer.