Changeset bc07190 for src/Parser
- Timestamp:
- Jun 29, 2024, 7:33:28 AM (19 months ago)
- Branches:
- master
- Children:
- 011c29e
- Parents:
- 62a38e7 (diff), 115ac1ce (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. - Location:
- src/Parser
- Files:
-
- 5 edited
-
StatementNode.cpp (modified) (1 diff)
-
StatementNode.hpp (modified) (2 diffs)
-
TypeData.cpp (modified) (1 diff)
-
lex.ll (modified) (2 diffs)
-
parser.yy (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cpp
r62a38e7 rbc07190 216 216 return new ast::ForStmt( location, 217 217 std::move( astinit ), 218 range_over, 218 range_over, forctl->kind == OperKinds::LThan, 219 219 buildMoveSingle( stmt ), 220 220 buildMoveOptional( else_ ) -
src/Parser/StatementNode.hpp
r62a38e7 rbc07190 64 64 ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) : 65 65 init( stmt ), condition( condition ), change( change ), range_over( nullptr ) {} 66 ForCtrl( StatementNode * decl, ExpressionNode * _range_over) :67 init( decl ), condition( nullptr ), change( nullptr ), range_over( _range_over) {}66 ForCtrl( StatementNode * decl, ExpressionNode * range_over, OperKinds kind ) : 67 init( decl ), condition( nullptr ), change( nullptr ), range_over( range_over ), kind( kind ) {} 68 68 69 69 StatementNode * init; … … 71 71 ExpressionNode * change; 72 72 ExpressionNode * range_over; 73 OperKinds kind; 73 74 }; 74 75 -
src/Parser/TypeData.cpp
r62a38e7 rbc07190 1469 1469 ast::ObjectDecl * object = strict_dynamic_cast<ast::ObjectDecl *>( member ); 1470 1470 object->isHidden = ast::EnumDecl::EnumHiding::Hide == ret->hide; 1471 if ( ret->is Typed && !ret->base&& cur->has_enumeratorValue() ) {1472 SemanticError( td->location, " Enumerator of enum(void)cannot have an explicit initializer value." );1471 if ( ret->isOpague() && cur->has_enumeratorValue() ) { 1472 SemanticError( td->location, "Opague cannot have an explicit initializer value." ); 1473 1473 } else if ( cur->has_enumeratorValue() ) { 1474 1474 object->init = new ast::SingleInit( -
src/Parser/lex.ll
r62a38e7 rbc07190 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Thu Jun 2 0 16:54:05202413 * Update Count : 7 7812 * Last Modified On : Thu Jun 27 14:38:27 2024 13 * Update Count : 780 14 14 */ 15 15 … … 458 458 459 459 "@=" { NAMEDOP_RETURN(ATassign); } // CFA 460 "+~" { NAMEDOP_RETURN(ErangeUp); } // CFA 460 461 "~=" { NAMEDOP_RETURN(ErangeUpEq); } // CFA 462 "+~=" { NAMEDOP_RETURN(ErangeUpEq); } // CFA 461 463 "-~" { NAMEDOP_RETURN(ErangeDown); } // CFA 462 464 "-~=" { NAMEDOP_RETURN(ErangeDownEq); } // CFA -
src/Parser/parser.yy
r62a38e7 rbc07190 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 24 22:45:20202413 // Update Count : 6 68412 // Last Modified On : Thu Jun 27 14:45:57 2024 13 // Update Count : 6705 14 14 // 15 15 … … 224 224 #define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right) 225 225 #define MISSING_ANON_FIELD "illegal syntax, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body." 226 #define MISSING_LOW "illegal syntax, missing low value for up-to range so index is uninitialized." 227 #define MISSING_HIGH "illegal syntax, missing high value for down-to range so index is uninitialized." 228 229 static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, enum OperKinds compop, 230 ExpressionNode * comp, ExpressionNode * inc ) { 226 #define MISSING_LOW "illegal syntax, missing low value for ascanding range so index is uninitialized." 227 #define MISSING_HIGH "illegal syntax, missing high value for descending range so index is uninitialized." 228 229 static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 231 230 // Wrap both comp/inc if they are non-null. 232 231 if ( comp ) comp = new ExpressionNode( build_binary_val( location, … … 243 242 } 244 243 245 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enumOperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {244 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 246 245 if ( index->initializer ) { 247 246 SemanticError( yylloc, "illegal syntax, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." ); … … 254 253 } // forCtrl 255 254 256 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, enumOperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {255 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 257 256 ast::ConstantExpr * constant = dynamic_cast<ast::ConstantExpr *>(type->expr.get()); 258 257 if ( constant && (constant->rep == "0" || constant->rep == "1") ) { … … 268 267 #define MISSING_LOOP_INDEX "illegal syntax, only a single identifier or declaration allowed in initialization, e.g., for ( i; ... ) or for ( int i; ... ). Expression disallowed." 269 268 270 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enumOperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {269 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 271 270 if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) { 272 271 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 273 // } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) {274 // if ( auto identifier = commaExpr->arg2.as<ast::NameExpr>() ) {275 // return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );276 // } else {277 // SemanticError( yylloc, "illegal syntax, loop-index name missing. Expression disallowed." ); return nullptr;278 // } // if279 272 } else { 280 273 SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr; … … 282 275 } // forCtrl 283 276 284 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, ExpressionNode * range_over_expr ) {277 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, __attribute__((unused)) OperKinds compop, ExpressionNode * range_over_expr ) { 285 278 if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) { 286 279 DeclarationNode * indexDecl = DeclarationNode::newName( new std::string(identifier->name) ); 287 280 assert( range_over_expr ); 288 return new ForCtrl( new StatementNode( indexDecl ), range_over_expr ); 289 // } else if (auto commaExpr = dynamic_cast<ast::CommaExpr *>( index_expr->expr.get() )) { 290 // if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) { 291 // assert( range_over_expr ); 292 // DeclarationNode * indexDecl = distAttr( 293 // DeclarationNode::newTypeof( range_over_expr, true ), 294 // DeclarationNode::newName( new std::string( identifier->name) ) ); 295 // return new ForCtrl( new StatementNode( indexDecl ), range_over_expr ); 296 // } else { 297 // SemanticError( yylloc, "illegal syntax, loop-index name missing. Comma expression disallowed." ); return nullptr; 298 // } // if 281 return new ForCtrl( new StatementNode( indexDecl ), range_over_expr, compop ); 299 282 } else { 300 283 SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr; … … 426 409 %token ANDassign ERassign ORassign // &= ^= |= 427 410 428 %token ErangeUp Eq ErangeDown ErangeDownEq //~= -~ -~=411 %token ErangeUp ErangeUpEq ErangeDown ErangeDownEq // +~ +~=/~= -~ -~= 429 412 %token ATassign // @= 430 413 … … 1522 1505 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1523 1506 1507 // These rules accept a comma_expression for the initialization, when only an identifier is correct. Being 1508 // permissive allows for a better error message from forCtrl. 1524 1509 | comma_expression ';' comma_expression // CFA 1525 1510 { $$ = forCtrl( yylloc, $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); } … … 1541 1526 } 1542 1527 | comma_expression ';' '@' updowneq '@' // CFA, invalid syntax rule 1543 { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-torange so index is uninitialized." ); $$ = nullptr; }1528 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; } 1544 1529 1545 1530 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA … … 1570 1555 } 1571 1556 | comma_expression ';' '@' updowneq '@' '~' '@' // CFA 1572 { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-torange so index is uninitialized." ); $$ = nullptr; }1557 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; } 1573 1558 1574 1559 | declaration comma_expression // CFA … … 1618 1603 } 1619 1604 | declaration '@' updowneq '@' '~' '@' // CFA, invalid syntax rule 1620 { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-torange so index is uninitialized." ); $$ = nullptr; }1605 { SemanticError( yylloc, "illegal syntax, missing low/high value for ascending/descending range so index is uninitialized." ); $$ = nullptr; } 1621 1606 1622 1607 | comma_expression ';' enum_key // CFA, enum type 1623 1608 { 1624 $$ = enumRangeCtrl( $1, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) );1609 $$ = enumRangeCtrl( $1, OperKinds::LEThan, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) ); 1625 1610 } 1626 1611 | comma_expression ';' downupdowneq enum_key // CFA, enum type, reverse direction 1627 1612 { 1628 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { 1629 SemanticError( yylloc, "illegal syntax, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; 1630 } 1631 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1613 if ( $3 == OperKinds::GThan ) { 1614 SemanticError( yylloc, "all enumeration ranges are equal (all values). Add an equal, e.g., ~=, -~=." ); $$ = nullptr; 1615 $3 = OperKinds::GEThan; 1616 } // if 1617 $$ = enumRangeCtrl( $1, $3, new ExpressionNode( new ast::TypeExpr( yylloc, $4->buildType() ) ) ); 1632 1618 } 1633 1619 ; … … 1642 1628 ; 1643 1629 1630 // This rule exists to handle the ambiguity with unary operator '~'. The rule is the same as updowneq minus the '~'. 1631 // Specifically, "for ( ~5 )" means the complement of 5, not loop 0..4. Hence, in this case "for ( ~= 5 )", i.e., 0..5, 1632 // it is not possible to just remove the '='. The entire '~=' must be removed. 1644 1633 downupdowneq: 1645 ErangeDown 1634 ErangeUp 1635 { $$ = OperKinds::LThan; } 1636 | ErangeDown 1646 1637 { $$ = OperKinds::GThan; } 1647 1638 | ErangeUpEq … … 1652 1643 1653 1644 updown: 1654 '~' 1645 '~' // shorthand 0 ~ 10 => 0 +~ 10 1646 { $$ = OperKinds::LThan; } 1647 | ErangeUp 1655 1648 { $$ = OperKinds::LThan; } 1656 1649 | ErangeDown
Note:
See TracChangeset
for help on using the changeset viewer.