Changeset 41c3e46
- Timestamp:
- Mar 31, 2025, 1:20:45 PM (3 weeks ago)
- Branches:
- master
- Children:
- fc8ec54
- Parents:
- 52931c5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/ExpressionNode.cpp ¶
r52931c5 r41c3e46 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 16 20:50:27 202413 // Update Count : 11 1012 // Last Modified On : Mon Mar 31 12:08:13 2025 13 // Update Count : 1121 14 14 // 15 15 … … 443 443 } // sepString 444 444 445 ast::Expr * build_constantChar( const CodeLocation & location, string & str ) { 446 string units; // units 447 sepString( str, units, '\'' ); // separate constant from units 448 449 ast::Expr * ret = new ast::ConstantExpr( location, 450 new ast::BasicType( ast::BasicKind::Char ), 451 str, 452 (unsigned long long int)(unsigned char)str[1] ); 453 if ( units.length() != 0 ) { 454 ret = new ast::UntypedExpr( location, 455 new ast::NameExpr( location, units ), 456 { ret } ); 457 } // if 458 459 delete &str; // created by lex 460 return ret; 461 } // build_constantChar 445 static ast::Type * charstrKind( string & str ) { 446 ast::Type * kind; 447 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1 448 case 'u': 449 if ( str[1] == '8' ) goto Default; // utf-8 characters => array of char (save check for char as no 8 allowed) 450 // lookup type of associated typedef 451 kind = new ast::TypeInstType( "char16_t", ast::TypeDecl::Dtype ); 452 break; 453 case 'U': 454 kind = new ast::TypeInstType( "char32_t", ast::TypeDecl::Dtype ); 455 break; 456 case 'L': 457 kind = new ast::TypeInstType( "wchar_t", ast::TypeDecl::Dtype ); 458 break; 459 Default: // char default string type 460 default: 461 kind = new ast::BasicType( ast::BasicKind::Char ); 462 } // switch 463 return kind; 464 } // charstrKind 462 465 463 466 static bool isoctal( char ch ) { 464 467 return ('0' <= ch && ch <= '7'); 465 } 468 } // isoctal 466 469 467 470 // A "sequence" is the series of characters in a character/string literal that becomes a single … … 498 501 return 1; 499 502 } // switch 500 } 503 } // sequenceLength 504 505 ast::Expr * build_constantChar( const CodeLocation & location, string & str ) { 506 string units; // units 507 sepString( str, units, '\'' ); // separate constant from units 508 509 ast::Expr * ret = new ast::ConstantExpr( location, charstrKind( str ), str, (unsigned long long int)(unsigned char)str[1] ); 510 if ( units.length() != 0 ) { 511 ret = new ast::UntypedExpr( location, new ast::NameExpr( location, units ), { ret } ); 512 } // if 513 514 delete &str; // created by lex 515 return ret; 516 } // build_constantChar 501 517 502 518 ast::Expr * build_constantStr( const CodeLocation & location, string & str ) { … … 504 520 string units; // units 505 521 sepString( str, units, '"' ); // separate constant from units 506 507 ast::Type * strtype;508 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1509 case 'u':510 if ( str[1] == '8' ) goto Default; // utf-8 characters => array of char511 // lookup type of associated typedef512 strtype = new ast::TypeInstType( "char16_t", ast::TypeDecl::Dtype );513 break;514 case 'U':515 strtype = new ast::TypeInstType( "char32_t", ast::TypeDecl::Dtype );516 break;517 case 'L':518 strtype = new ast::TypeInstType( "wchar_t", ast::TypeDecl::Dtype );519 break;520 Default: // char default string type521 default:522 strtype = new ast::BasicType( ast::BasicKind::Char );523 } // switch524 522 525 523 // The length value of the type is equal to the number of "sequences" not including the openning … … 536 534 } // for 537 535 538 ast::ArrayType * at = new ast::ArrayType( 539 strtype, 540 ast::ConstantExpr::from_ulong( location, length ), 541 ast::FixedLen, 542 ast::DynamicDim ); 536 ast::ArrayType * at = new ast::ArrayType( charstrKind( str ), ast::ConstantExpr::from_ulong( location, length ), ast::FixedLen, ast::DynamicDim ); 543 537 ast::Expr * ret = new ast::ConstantExpr( location, at, str, std::nullopt ); 544 538 if ( units.length() != 0 ) {
Note: See TracChangeset
for help on using the changeset viewer.