Changeset d78c238


Ignore:
Timestamp:
Aug 8, 2022, 5:13:11 PM (20 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
5c98a25
Parents:
66406f3
Message:

update for-control with explicit type declarations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r66406f3 rd78c238  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  1 15:35:08 2022
    13 // Update Count     : 5405
     12// Last Modified On : Mon Aug  8 15:45:04 2022
     13// Update Count     : 5574
    1414//
    1515
     
    5858
    5959// lex uses __null in a boolean context, it's fine.
    60 #pragma GCC diagnostic ignored "-Wparentheses-equality"
     60//#pragma GCC diagnostic ignored "-Wparentheses-equality"
    6161
    6262extern DeclarationNode * parseTree;
     
    197197} // fieldDecl
    198198
     199#define NEW_ZERO new ExpressionNode( build_constantInteger( *new string( "0" ) ) )
     200#define NEW_ONE  new ExpressionNode( build_constantInteger( *new string( "1" ) ) )
     201
     202ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     203        if ( index->initializer ) {
     204                SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     205        } // if
     206        if ( index->next ) {
     207                SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." );
     208        } // if
     209        return new ForCtrl( index->addInitializer( new InitializerNode( start ) ),
     210                // NULL comp/inc => leave blank
     211                comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index->name ) ) ), comp ) ) : nullptr,
     212                inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
     213                                                        OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index->name ) ) ), inc ) ) : nullptr );
     214} // forCtrl
     215
    199216ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    200217        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
     
    206223                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    207224                // NULL comp/inc => leave blank
    208                 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : 0,
     225                comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : nullptr,
    209226                inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
    210                                                         OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : 0 );
     227                                                        OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : nullptr );
    211228} // forCtrl
    212229
     
    346363%type<ifctl> conditional_declaration
    347364%type<fctl> for_control_expression              for_control_expression_list
    348 %type<compop> inclexcl
     365%type<compop> updown updowneq downupdowneq
    349366%type<en> subrange
    350367%type<decl> asm_name_opt
     
    12391256iteration_statement:
    12401257        WHILE '(' ')' statement                                                         %prec THEN // CFA => while ( 1 )
    1241                 { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
     1258                { $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( $4 ) ) ); }
    12421259        | WHILE '(' ')' statement ELSE statement                        // CFA
    12431260                {
    1244                         $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) );
     1261                        $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( $4 ) ) );
    12451262                        SemanticWarning( yylloc, Warning::SuperfluousElse, "" );
    12461263                }
     
    12501267                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ), $7 ) ); }
    12511268        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    1252                 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
     1269                { $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound( $2 ) ) ); }
    12531270        | DO statement WHILE '(' ')' ELSE statement                     // CFA
    12541271                {
    1255                         $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) );
     1272                        $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound( $2 ) ) );
    12561273                        SemanticWarning( yylloc, Warning::SuperfluousElse, "" );
    12571274                }
     
    13051322
    13061323        | comma_expression                                                                      // CFA
    1307                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1308                                                 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1309         | '=' comma_expression                                                          // CFA
    1310                 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1311                                                 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1312         | comma_expression inclexcl comma_expression            // CFA
    1313                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1314         | comma_expression inclexcl comma_expression '~' comma_expression // CFA
     1324                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); }
     1325        | downupdowneq comma_expression                                         // CFA
     1326                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), $1 == OperKinds::GThan || $1 == OperKinds::GEThan ? $2->clone() : NEW_ZERO, $1, $2->clone(), NEW_ONE ); }
     1327        | comma_expression updowneq comma_expression            // CFA
     1328                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, NEW_ONE ); }
     1329        | '@' updowneq comma_expression                                         // CFA
     1330                { $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ),
     1331                                                $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3->clone(), NEW_ONE ); }
     1332        | comma_expression updown '@'                                           // CFA
     1333                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, NEW_ONE ); }
     1334
     1335        | comma_expression updowneq comma_expression '~' comma_expression // CFA
    13151336                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
     1337        | '@' updowneq comma_expression '~' comma_expression // CFA
     1338                { $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ),
     1339                                                $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO,     $2, $3->clone(), $5 ); }
     1340        | comma_expression updown '@' '~' comma_expression      // CFA
     1341                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, $5 ); }
     1342        | comma_expression updown '@' '~' '@'                           // CFA
     1343                {
     1344                        if ( $2 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; }
     1345                        else $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, nullptr );
     1346                }
    13161347        | comma_expression ';'                                                          // CFA
    13171348                { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); }
    13181349        | comma_expression ';' comma_expression                         // CFA
    1319                 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1320                                                 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1321         | comma_expression ';' '=' comma_expression                     // CFA
    1322                 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1323                                                 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1324         | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    1325                 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1326         | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA
     1350                { $$ = forCtrl( $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }
     1351        | comma_expression ';' downupdowneq comma_expression // CFA
     1352                { $$ = forCtrl( $4, $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4->clone(), NEW_ONE ); }
     1353        | comma_expression ';' comma_expression updowneq comma_expression // CFA
     1354                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, NEW_ONE ); }
     1355        | comma_expression ';' '@' updowneq comma_expression // CFA
     1356                { $$ = forCtrl( $5, $1, $4 == OperKinds::GThan || $4 == OperKinds::GEThan ? $5->clone() : NEW_ZERO, $4, $5->clone(), NEW_ONE ); }
     1357        | comma_expression ';' comma_expression updown '@'      // CFA
     1358                { $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); }
     1359
     1360        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
    13271361                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); }
     1362        | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA
     1363                { $$ = forCtrl( $5, $1, $4 == OperKinds::GThan || $4 == OperKinds::GEThan ? $5->clone() : NEW_ZERO, $4, $5->clone(), $7 ); }
     1364        | comma_expression ';' comma_expression updown '@' '~' comma_expression // CFA
     1365                { $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, $7 ); }
     1366        | comma_expression ';' comma_expression updown '@' '~' '@' // CFA
     1367                {
     1368                        if ( $4 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; }
     1369                        else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, nullptr );
     1370                }
     1371
     1372        | declaration comma_expression                                          // CFA
     1373                { $$ = forCtrl( $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); }
     1374        | declaration downupdowneq comma_expression                     // CFA
     1375                { $$ = forCtrl( $1, $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3, NEW_ONE ); }
     1376        | declaration comma_expression updowneq comma_expression // CFA
     1377                { $$ = forCtrl( $1, $2, $3, $4, NEW_ONE ); }
     1378        | declaration '@' updowneq comma_expression                     // CFA
     1379                { $$ = forCtrl( $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4, NEW_ONE ); }
     1380        | declaration comma_expression updown '@'                       // CFA
     1381                { $$ = forCtrl( $1, $2, $3, nullptr, NEW_ONE ); }
     1382
     1383        | declaration comma_expression updowneq comma_expression '~' comma_expression // CFA
     1384                { $$ = forCtrl( $1, $2, $3, $4, $6 ); }
     1385        | declaration '@' updowneq comma_expression '~' comma_expression // CFA
     1386                { $$ = forCtrl( $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4, $6 ); }
     1387        | declaration comma_expression updown '@' '~' comma_expression // CFA
     1388                { $$ = forCtrl( $1, $2, $3, nullptr, $6 ); }
     1389        | declaration comma_expression updown '@' '~' '@'       // CFA
     1390                {
     1391                        if ( $3 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; }
     1392                        else $$ = forCtrl( $1, $2, $3, nullptr, nullptr );
     1393                }
    13281394
    13291395        | comma_expression ';' TYPEDEFname                                      // CFA, array type
    13301396                {
    1331                         SemanticError( yylloc, "Array interator is currently unimplemented." ); $$ = nullptr;
    1332                         $$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr );
    1333                 }
    1334 
    1335                 // There is a S/R conflicit if ~ and -~ are factored out.
    1336         | comma_expression ';' comma_expression '~' '@'         // CFA
    1337                 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1338         | comma_expression ';' comma_expression ErangeDown '@' // CFA
    1339                 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1340         | comma_expression ';' comma_expression '~' '@' '~' comma_expression // CFA
    1341                 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, $7 ); }
    1342         | comma_expression ';' comma_expression ErangeDown '@' '~' comma_expression // CFA
    1343                 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, $7 ); }
    1344         | comma_expression ';' comma_expression '~' '@' '~' '@' // CFA
    1345                 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, nullptr ); }
     1397                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
     1398                        //$$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr );
     1399                }
     1400        | comma_expression ';' downupdowneq TYPEDEFname         // CFA, array type
     1401                {
     1402                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
     1403                }
    13461404        ;
    13471405
    1348 inclexcl:
     1406downupdowneq:
     1407        ErangeDown
     1408                { $$ = OperKinds::GThan; }
     1409        | ErangeUpEq
     1410                { $$ = OperKinds::LEThan; }
     1411        | ErangeDownEq
     1412                { $$ = OperKinds::GEThan; }
     1413        ;
     1414
     1415updown:
    13491416        '~'
    13501417                { $$ = OperKinds::LThan; }
     1418        | ErangeDown
     1419                { $$ = OperKinds::GThan; }
     1420        ;
     1421
     1422updowneq:
     1423        updown
    13511424        | ErangeUpEq
    13521425                { $$ = OperKinds::LEThan; }
    1353         | ErangeDown
    1354                 { $$ = OperKinds::GThan; }
    13551426        | ErangeDownEq
    13561427                { $$ = OperKinds::GEThan; }
     
    23952466          '{' enumerator_list comma_opt '}'
    23962467                { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2468        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
     2469                { SemanticError( yylloc, "Unvalued enumerated type is currently unimplemented." ); $$ = nullptr; }
    23972470        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    23982471                {
Note: See TracChangeset for help on using the changeset viewer.