Changeset 089b39e1 for src


Ignore:
Timestamp:
Jun 25, 2024, 9:25:50 PM (10 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
343c8be
Parents:
5eb3f65
Message:

clean up, prepare for downto enumerating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r5eb3f65 r089b39e1  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 24 22:45:20 2024
    13 // Update Count     : 6684
     12// Last Modified On : Tue Jun 25 18:44:14 2024
     13// Update Count     : 6692
    1414//
    1515
     
    227227#define MISSING_HIGH "illegal syntax, missing high value for down-to range so index is uninitialized."
    228228
    229 static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, enum OperKinds compop,
    230                                                           ExpressionNode * comp, ExpressionNode * inc ) {
     229static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    231230        // Wrap both comp/inc if they are non-null.
    232231        if ( comp ) comp = new ExpressionNode( build_binary_val( location,
     
    243242}
    244243
    245 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     244ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    246245        if ( index->initializer ) {
    247246                SemanticError( yylloc, "illegal syntax, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     
    254253} // forCtrl
    255254
    256 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     255ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    257256        ast::ConstantExpr * constant = dynamic_cast<ast::ConstantExpr *>(type->expr.get());
    258257        if ( constant && (constant->rep == "0" || constant->rep == "1") ) {
     
    268267#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."
    269268
    270 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     269ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    271270        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) {
    272271                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         //      } // if
    279272        } else {
    280273                SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr;
     
    282275} // forCtrl
    283276
    284 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, ExpressionNode * range_over_expr ) {
     277ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, __attribute__((unused)) OperKinds compop, ExpressionNode * range_over_expr ) {
    285278        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) {
    286279                DeclarationNode * indexDecl = DeclarationNode::newName( new std::string(identifier->name) );
    287280                assert( range_over_expr );
    288281                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
    299282        } else {
    300283                SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr;
     
    15221505                { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; }
    15231506
     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.
    15241509        | comma_expression ';' comma_expression                         // CFA
    15251510                { $$ = forCtrl( yylloc, $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }
     
    16221607        | comma_expression ';' enum_key                                         // CFA, enum type
    16231608                {
    1624                         $$ = enumRangeCtrl( $1, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) );
     1609                        $$ = enumRangeCtrl( $1, OperKinds::LThan, new ExpressionNode( new ast::TypeExpr( yylloc, $3->buildType() ) ) );
    16251610                }
    16261611        | comma_expression ';' downupdowneq enum_key            // CFA, enum type, reverse direction
     
    16291614                                SemanticError( yylloc, "illegal syntax, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
    16301615                        }
    1631                         SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
     1616                        $$ = enumRangeCtrl( $1, $3, new ExpressionNode( new ast::TypeExpr( yylloc, $4->buildType() ) ) );
    16321617                }
    16331618        ;
Note: See TracChangeset for help on using the changeset viewer.