Changes in src/Parser/ExpressionNode.cpp [45ee172:2ac78a1]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cpp
r45ee172 r2ac78a1 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 23 10:22:00202413 // Update Count : 10 8811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Sep 12 22:40:35 2024 13 // Update Count : 1090 14 14 // 15 15 … … 381 381 const CodeLocation & location, string & str ) { 382 382 static const ast::BasicKind kind[2][12] = { 383 { ast::BasicKind::Float, ast::BasicKind::Double, ast::BasicKind::LongDouble, ast::BasicKind:: uuFloat80, ast::BasicKind::uuFloat128, ast::BasicKind::uFloat16, ast::BasicKind::uFloat32, ast::BasicKind::uFloat32x, ast::BasicKind::uFloat64, ast::BasicKind::uFloat64x, ast::BasicKind::uFloat128, ast::BasicKind::uFloat128x },384 { ast::BasicKind::FloatComplex, ast::BasicKind::DoubleComplex, ast::BasicKind::LongDoubleComplex, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind:: uFloat16Complex, ast::BasicKind::uFloat32Complex, ast::BasicKind::uFloat32xComplex, ast::BasicKind::uFloat64Complex, ast::BasicKind::uFloat64xComplex, ast::BasicKind::uFloat128Complex, ast::BasicKind::uFloat128xComplex },383 { ast::BasicKind::Float, ast::BasicKind::Double, ast::BasicKind::LongDouble, ast::BasicKind::Float80, ast::BasicKind::uuFloat128, ast::BasicKind::Float16, ast::BasicKind::Float32, ast::BasicKind::Float32x, ast::BasicKind::Float64, ast::BasicKind::Float64x, ast::BasicKind::Float128, ast::BasicKind::Float128x }, 384 { ast::BasicKind::FloatComplex, ast::BasicKind::DoubleComplex, ast::BasicKind::LongDoubleComplex, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::Float16Complex, ast::BasicKind::Float32Complex, ast::BasicKind::Float32xComplex, ast::BasicKind::Float64Complex, ast::BasicKind::Float64xComplex, ast::BasicKind::Float128Complex, ast::BasicKind::Float128xComplex }, 385 385 }; 386 386 … … 460 460 return ret; 461 461 } // build_constantChar 462 463 static bool isoctal( char ch ) { 464 return ('0' <= ch && ch <= '7'); 465 } 466 467 // A "sequence" is the series of characters in a character/string literal 468 // that becomes a single character value in the runtime value. 469 static size_t sequenceLength( const std::string & str, size_t pos ) { 470 // Most "sequences" are just a single character, filter those out: 471 if ( '\\' != str[pos] ) return 1; 472 switch ( str[pos + 1] ) { 473 // Simple Escape Sequence (\_ where _ is one of the following): 474 case '\'': case '\"': case '?': case '\\': 475 case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v': 476 // GCC Escape Sequence (as simple, just some different letters): 477 case 'e': 478 return 2; 479 // Numeric Escape Sequence (\___ where _ is 1-3 octal digits): 480 case '0': case '1': case '2': case '3': 481 case '4': case '5': case '6': case '7': 482 return ( !isoctal( str[pos + 2] ) ) ? 2 : 483 ( !isoctal( str[pos + 3] ) ) ? 3 : 4; 484 // Numeric Escape Sequence (\x_ where _ is 1 or more hexadecimal digits): 485 case 'x': { 486 size_t length = 2; 487 while ( isxdigit( str[pos + length] ) ) ++length; 488 return length; 489 } 490 // Universal Character Name (\u____ where _ is 4 decimal digits): 491 case 'u': 492 return 6; 493 // Universal Character Name (\U________ where _ is 8 decimal digits): 494 case 'U': 495 return 10; 496 default: 497 assertf( false, "Unknown escape sequence (start %c).", str[pos] ); 498 return 1; 499 } 500 } 462 501 463 502 ast::Expr * build_constantStr( … … 485 524 strtype = new ast::BasicType( ast::BasicKind::Char ); 486 525 } // switch 526 527 // The dimension value of the type is equal to the number of "sequences" 528 // not including the openning and closing quotes in the literal plus 1 529 // for the implicit null terminator. 530 size_t dimension = 1; 531 for ( size_t pos = 1 ; pos < str.size() - 1 ; 532 pos += sequenceLength( str, pos ) ) { 533 dimension += 1; 534 } 535 487 536 ast::ArrayType * at = new ast::ArrayType( 488 537 strtype, 489 // Length is adjusted: +1 for '\0' and -2 for '"' 490 ast::ConstantExpr::from_ulong( location, str.size() + 1 - 2 ), 538 ast::ConstantExpr::from_ulong( location, dimension ), 491 539 ast::FixedLen, 492 540 ast::DynamicDim );
Note:
See TracChangeset
for help on using the changeset viewer.