Changeset 3b0bc16 for src/Parser
- Timestamp:
- Feb 1, 2022, 8:22:12 PM (2 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- fde0a58
- Parents:
- 729c991
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
r729c991 r3b0bc16 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 29 09:45:56202213 // Update Count : 90 112 // Last Modified On : Tue Feb 1 11:06:18 2022 13 // Update Count : 903 14 14 // 15 15 … … 414 414 Statement * build_case( ExpressionNode * ctl ); 415 415 Statement * build_default(); 416 Statement * build_while( CondCtl * ctl, StatementNode * stmt );417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt );416 Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * els = nullptr ); 417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * els = nullptr ); 418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * els = nullptr ); 419 419 Statement * build_branch( BranchStmt::Type kind ); 420 420 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); -
src/Parser/StatementNode.cc
r729c991 r3b0bc16 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 29 09:45:51202213 // Update Count : 3 8412 // Last Modified On : Tue Feb 1 18:39:00 2022 13 // Update Count : 395 14 14 // 15 15 … … 145 145 } // build_default 146 146 147 Statement * build_while( CondCtl * ctl, StatementNode * stmt ) { 148 std::list< Statement * > branches; 149 buildMoveList< Statement, StatementNode >( stmt, branches ); 150 assert( branches.size() == 1 ); 151 147 Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ ) { 152 148 std::list< Statement * > init; 153 149 Expression * cond = build_if_control( ctl, init ); 154 return new WhileStmt( cond, branches.front(), init, false ); 150 151 std::list< Statement * > aststmt; 152 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 153 assert( aststmt.size() == 1 ); 154 155 std::list< Statement * > astelse; 156 buildMoveList< Statement, StatementNode >( else_, astelse ); 157 158 return new WhileDoStmt( cond, aststmt.front(), astelse.front(), init, false ); 155 159 } // build_while 156 160 157 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) { 158 std::list< Statement * > branches; 159 buildMoveList< Statement, StatementNode >( stmt, branches ); 160 assert( branches.size() == 1 ); 161 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ ) { 162 std::list< Statement * > aststmt; 163 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 164 assert( aststmt.size() == 1 ); 165 166 std::list< Statement * > astelse; 167 buildMoveList< Statement, StatementNode >( else_, astelse ); 161 168 162 169 std::list< Statement * > init; 163 return new While Stmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true );170 return new WhileDoStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), aststmt.front(), astelse.front(), init, true ); 164 171 } // build_do_while 165 172 166 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ) { 167 std::list< Statement * > branches; 168 buildMoveList< Statement, StatementNode >( stmt, branches ); 169 assert( branches.size() == 1 ); 170 173 Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ ) { 171 174 std::list< Statement * > init; 172 if ( forctl->init != 0) {175 if ( forctl->init != nullptr ) { 173 176 buildMoveList( forctl->init, init ); 174 177 } // if 175 178 176 Expression * cond = 0;177 if ( forctl->condition != 0)179 Expression * cond = nullptr; 180 if ( forctl->condition != nullptr ) 178 181 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 179 182 180 Expression * incr = 0;181 if ( forctl->change != 0)183 Expression * incr = nullptr; 184 if ( forctl->change != nullptr ) 182 185 incr = maybeMoveBuild< Expression >(forctl->change); 183 186 187 std::list< Statement * > aststmt; 188 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 189 assert( aststmt.size() == 1 ); 190 191 std::list< Statement * > astelse; 192 buildMoveList< Statement, StatementNode >( else_, astelse ); 193 184 194 delete forctl; 185 return new ForStmt( init, cond, incr, branches.front() );195 return new ForStmt( init, cond, incr, aststmt.front(), astelse.front() ); 186 196 } // build_for 187 197 -
src/Parser/parser.yy
r729c991 r3b0bc16 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 30 09:41:13 202213 // Update Count : 516 512 // Last Modified On : Tue Feb 1 11:06:13 2022 13 // Update Count : 5167 14 14 // 15 15 … … 1197 1197 { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); } 1198 1198 | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA 1199 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1199 // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1200 { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ), $7 ) ); } 1200 1201 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1201 1202 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); } … … 1203 1204 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); } 1204 1205 | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA 1205 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1206 // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1207 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); } 1206 1208 | FOR '(' ')' statement // CFA => for ( ;; ) 1207 1209 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); } … … 1209 1211 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); } 1210 1212 | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA 1211 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1213 // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1214 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); } 1212 1215 ; 1213 1216
Note: See TracChangeset
for help on using the changeset viewer.