Changeset f9a0dd0
- Timestamp:
- Dec 16, 2024, 9:30:52 PM (31 hours ago)
- Branches:
- master
- Children:
- 9a01745
- Parents:
- 0497b6ba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cpp
r0497b6ba rf9a0dd0 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 12 22:40:35202413 // Update Count : 1 09012 // Last Modified On : Mon Dec 16 20:50:27 2024 13 // Update Count : 1110 14 14 // 15 15 … … 162 162 lnthSuffix( str, type, ltype ); // could have length suffix 163 163 } else { 164 // At least one digit in integer constant, so safe to backup while looking for suffix. 165 // This declaration and the comma expressions in the conditions mimic166 // the declare and check pattern allowed in later compiler versions.167 // (Only some early compilers/C++ standards donot support it.)164 // At least one digit in integer constant, so safe to backup while looking for suffix. This 165 // declaration and the comma expressions in the conditions mimic the declare and check 166 // pattern allowed in later compiler versions. (Only some early compilers/C++ standards do 167 // not support it.) 168 168 string::size_type posn; 169 169 // pointer value … … 465 465 } 466 466 467 // A "sequence" is the series of characters in a character/string literal 468 // that becomes a singlecharacter value in the runtime value.467 // A "sequence" is the series of characters in a character/string literal that becomes a single 468 // character value in the runtime value. 469 469 static size_t sequenceLength( const std::string & str, size_t pos ) { 470 470 // Most "sequences" are just a single character, filter those out: … … 497 497 assertf( false, "Unknown escape sequence (start %c).", str[pos] ); 498 498 return 1; 499 } 499 } // switch 500 500 } 501 501 502 ast::Expr * build_constantStr( 503 const CodeLocation & location, 504 string & str ) { 502 ast::Expr * build_constantStr( const CodeLocation & location, string & str ) { 505 503 assert( str.length() > 0 ); 506 504 string units; // units … … 525 523 } // switch 526 524 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 } 525 // The length value of the type is equal to the number of "sequences" not including the openning 526 // and closing quotes in the literal plus 1 for the implicit null terminator. 527 size_t length = 1; 528 for ( size_t pos = 1 ; pos < str.size() - 1 ; pos += sequenceLength( str, pos ) ) { 529 if ( '"' == str[pos] ) { // concatenated strings ? "ABC" "DEF" 530 int cnt = 1; // skip outside quotes and space between 531 for ( unsigned int i = pos + 1; str[i] != '"'; i += 1, cnt += 1 ); 532 pos += cnt; 533 continue; // not part of length 534 } // if 535 length += 1; 536 } // for 535 537 536 538 ast::ArrayType * at = new ast::ArrayType( 537 539 strtype, 538 ast::ConstantExpr::from_ulong( location, dimension),540 ast::ConstantExpr::from_ulong( location, length ), 539 541 ast::FixedLen, 540 542 ast::DynamicDim ); 541 543 ast::Expr * ret = new ast::ConstantExpr( location, at, str, std::nullopt ); 542 544 if ( units.length() != 0 ) { 543 ret = new ast::UntypedExpr( location, 544 new ast::NameExpr( location, units ), 545 { ret } ); 545 ret = new ast::UntypedExpr( location, new ast::NameExpr( location, units ), { ret } ); 546 546 } // if 547 547
Note: See TracChangeset
for help on using the changeset viewer.