Ignore:
Timestamp:
Feb 15, 2019, 9:59:48 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
ada4575
Parents:
70a3e16 (diff), 85d44c6 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r70a3e16 rfba51ab  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 17:56:23 2019
    13 // Update Count     : 4064
     12// Last Modified On : Thu Feb 14 22:23:13 2019
     13// Update Count     : 4217
    1414//
    1515
     
    9999        // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
    100100        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
    101         //cur->addType( specifier );
    102         for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
     101        for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    103102                cl->cloneBaseType( cur );
    104103        } // for
    105104        declList->addType( cl );
    106 //      delete cl;
    107105        return declList;
    108106} // distAttr
     
    201199        if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->get_expr()) ) {
    202200                return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
     201        } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->get_expr()) ) {
     202                if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1 ) ) {
     203                        return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
     204                } else {
     205                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     206                } // if
    203207        } else {
    204208                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     
    325329%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    326330%type<ifctl> if_control_expression
    327 %type<fctl> for_control_expression
     331%type<fctl> for_control_expression              for_control_expression_list
    328332%type<compop> inclexcl
    329333%type<en> subrange
     
    985989                // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
    986990        identifier_or_type_name ':' attribute_list_opt statement
    987                 {
    988                         $$ = $4->add_label( $1, $3 );
    989                 }
     991                { $$ = $4->add_label( $1, $3 ); }
    990992        ;
    991993
     
    10031005        statement_decl
    10041006        | statement_decl_list statement_decl
    1005                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     1007                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    10061008        ;
    10071009
     
    10101012                { $$ = new StatementNode( $1 ); }
    10111013        | EXTENSION declaration                                                         // GCC
    1012                 {
    1013                         distExt( $2 );
    1014                         $$ = new StatementNode( $2 );
    1015                 }
     1014                { distExt( $2 ); $$ = new StatementNode( $2 ); }
    10161015        | function_definition
    10171016                { $$ = new StatementNode( $1 ); }
    10181017        | EXTENSION function_definition                                         // GCC
    1019                 {
    1020                         distExt( $2 );
    1021                         $$ = new StatementNode( $2 );
    1022                 }
     1018                { distExt( $2 ); $$ = new StatementNode( $2 ); }
    10231019        | statement
    10241020        ;
     
    10271023        statement
    10281024        | statement_list_nodecl statement
    1029                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     1025                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    10301026        ;
    10311027
     
    11391135        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    11401136                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); }
    1141         | FOR '(' push for_control_expression ')' statement pop
     1137        | FOR '(' push for_control_expression_list ')' statement pop
    11421138                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    11431139        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     
    11451141        ;
    11461142
     1143for_control_expression_list:
     1144        for_control_expression
     1145        | for_control_expression_list ':' for_control_expression
     1146                { $$ = $3; }
     1147        ;
     1148
    11471149for_control_expression:
    1148         comma_expression                                                                        // CFA
     1150        ';' comma_expression_opt ';' comma_expression_opt
     1151                { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
     1152        | comma_expression ';' comma_expression_opt ';' comma_expression_opt
     1153                { $$ = new ForCtrl( $1, $3, $5 ); }
     1154        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
     1155                { $$ = new ForCtrl( $1, $2, $4 ); }
     1156        | comma_expression                                                                      // CFA
    11491157                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11501158                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1151         | constant_expression inclexcl constant_expression      // CFA
     1159        | comma_expression inclexcl comma_expression            // CFA
    11521160                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1153         | constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1161        | comma_expression inclexcl comma_expression '~' comma_expression // CFA
    11541162                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    11551163        | comma_expression ';' comma_expression                         // CFA
    11561164                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11571165                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1158         | comma_expression ';' constant_expression inclexcl constant_expression // CFA
     1166        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    11591167                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1160         | comma_expression ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1168        | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA
    11611169                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); }
    1162         | comma_expression ';' comma_expression_opt ';' comma_expression_opt
    1163                 { $$ = new ForCtrl( $1, $3, $5 ); }
    1164         | ';' comma_expression_opt ';' comma_expression_opt
    1165                 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
    1166         | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
    1167                 { $$ = new ForCtrl( $1, $2, $4 ); }
    11681170        ;
    11691171
Note: See TracChangeset for help on using the changeset viewer.