Changeset 5695645


Ignore:
Timestamp:
May 4, 2022, 2:27:02 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
b738974
Parents:
b6ae4fb
Message:

print warning for empty loop conditional with an else clause

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rb6ae4fb r5695645  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 14 16:35:29 2022
    13 // Update Count     : 5276
     12// Last Modified On : Wed May  4 14:25:20 2022
     13// Update Count     : 5277
    1414//
    1515
     
    111111
    112112void distInl( DeclarationNode * declaration ) {
    113         // distribute EXTENSION across all declarations
     113        // distribute INLINE across all declarations
    114114        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    115115                iter->set_inLine( true );
     
    12211221
    12221222iteration_statement:
    1223         WHILE '(' ')' statement                                                         // CFA => while ( 1 )
     1223        WHILE '(' ')' statement                                                         %prec THEN // CFA => while ( 1 )
    12241224                { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
     1225        | WHILE '(' ')' statement ELSE statement                        // CFA
     1226                { SemanticWarning( yylloc, Warning::SuperfluousElse ); }
    12251227        | WHILE '(' conditional_declaration ')' statement       %prec THEN
    12261228                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
     
    12291231        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    12301232                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
     1233        | DO statement WHILE '(' ')' ELSE statement                     // CFA
     1234                { SemanticWarning( yylloc, Warning::SuperfluousElse ); }
    12311235        | DO statement WHILE '(' comma_expression ')' ';'       %prec THEN
    12321236                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
     
    23182322                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23192323
    2320                         $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 ) ->addQualifiers( $5 );
     2324                        $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 );
    23212325                }
    23222326        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     
    23272331          '{' enumerator_list comma_opt '}'
    23282332                {
    2329                         $$ = DeclarationNode::newEnum( $6, $10, true, $3 ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
     2333                        $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    23302334                }
    23312335        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23332337                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23342338                        typedefTable.makeTypedef( *$6->name );
    2335                         $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
     2339                        $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    23362340                }
    23372341        | enum_type_nobody
Note: See TracChangeset for help on using the changeset viewer.