Changeset 436bbe5 for src/Parser
- Timestamp:
- Feb 2, 2022, 10:14:37 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- ff3b0249
- Parents:
- fde0a58
- Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rfde0a58 r436bbe5 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 1 11:06:18202213 // Update Count : 90 312 // Last Modified On : Wed Feb 2 09:15:49 2022 13 // Update Count : 905 14 14 // 15 15 … … 410 410 411 411 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init ); 412 Statement * build_if( CondCtl * ctl, StatementNode * then _stmt, StatementNode * else_stmt);412 Statement * build_if( CondCtl * ctl, StatementNode * then, StatementNode * else_ ); 413 413 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 414 414 Statement * build_case( ExpressionNode * ctl ); 415 415 Statement * build_default(); 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 );416 Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ = nullptr ); 417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ = nullptr ); 418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ = nullptr ); 419 419 Statement * build_branch( BranchStmt::Type kind ); 420 420 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); … … 424 424 Statement * build_resume( ExpressionNode * ctl ); 425 425 Statement * build_resume_at( ExpressionNode * ctl , ExpressionNode * target ); 426 Statement * build_try( StatementNode * try_ stmt, StatementNode * catch_stmt, StatementNode * finally_stmt);427 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode *cond, StatementNode *body );426 Statement * build_try( StatementNode * try_, StatementNode * catch_, StatementNode * finally_ ); 427 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ); 428 428 Statement * build_finally( StatementNode * stmt ); 429 429 Statement * build_compound( StatementNode * first ); -
src/Parser/StatementNode.cc
rfde0a58 r436bbe5 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 1 18:39:00202213 // Update Count : 39512 // Last Modified On : Wed Feb 2 09:45:28 2022 13 // Update Count : 415 14 14 // 15 15 … … 63 63 // convert from StatementNode list to Statement list 64 64 StatementNode * node = dynamic_cast< StatementNode * >(prev); 65 std::list< Statement * > stmts;65 list< Statement * > stmts; 66 66 buildMoveList( stmt, stmts ); 67 67 // splice any new Statements to end of current Statements … … 78 78 } // build_expr 79 79 80 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init ) {80 Expression * build_if_control( CondCtl * ctl, list< Statement * > & init ) { 81 81 if ( ctl->init != 0 ) { 82 82 buildMoveList( ctl->init, init ); … … 100 100 } // build_if_control 101 101 102 Statement * build_if( CondCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 103 Statement * thenb, * elseb = nullptr; 104 std::list< Statement * > branches; 105 buildMoveList< Statement, StatementNode >( then_stmt, branches ); 106 assert( branches.size() == 1 ); 107 thenb = branches.front(); 108 109 if ( else_stmt ) { 110 std::list< Statement * > branches; 111 buildMoveList< Statement, StatementNode >( else_stmt, branches ); 112 assert( branches.size() == 1 ); 113 elseb = branches.front(); 114 } // if 115 116 std::list< Statement * > init; 117 Expression * cond = build_if_control( ctl, init ); 118 return new IfStmt( cond, thenb, elseb, init ); 102 Statement * build_if( CondCtl * ctl, StatementNode * then, StatementNode * else_ ) { 103 list< Statement * > astinit; // maybe empty 104 Expression * astcond = build_if_control( ctl, astinit ); // ctl deleted, cond/init set 105 106 Statement * astthen, * astelse = nullptr; 107 list< Statement * > aststmt; 108 buildMoveList< Statement, StatementNode >( then, aststmt ); 109 assert( aststmt.size() == 1 ); 110 astthen = aststmt.front(); 111 112 if ( else_ ) { 113 list< Statement * > aststmt; 114 buildMoveList< Statement, StatementNode >( else_, aststmt ); 115 assert( aststmt.size() == 1 ); 116 astelse = aststmt.front(); 117 } // if 118 119 return new IfStmt( astcond, astthen, astelse, astinit ); 119 120 } // build_if 120 121 121 122 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { 122 std::list< Statement * > branches;123 buildMoveList< Statement, StatementNode >( stmt, branches);124 if ( ! isSwitch ) { 125 for ( Statement * stmt : branches) {123 list< Statement * > aststmt; 124 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 125 if ( ! isSwitch ) { // choose statement 126 for ( Statement * stmt : aststmt ) { 126 127 CaseStmt * caseStmt = strict_dynamic_cast< CaseStmt * >( stmt ); 127 128 if ( ! caseStmt->stmts.empty() ) { // code after "case" => end of case list … … 131 132 } // for 132 133 } // if 133 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements134 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches);134 // aststmt.size() == 0 for switch (...) {}, i.e., no declaration or statements 135 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), aststmt ); 135 136 } // build_switch 136 137 137 138 Statement * build_case( ExpressionNode * ctl ) { 138 std::list< Statement * > branches; 139 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 139 return new CaseStmt( maybeMoveBuild< Expression >(ctl), list< Statement * >{} ); 140 140 } // build_case 141 141 142 142 Statement * build_default() { 143 std::list< Statement * > branches; 144 return new CaseStmt( nullptr, branches, true ); 143 return new CaseStmt( nullptr, list< Statement * >{}, true ); 145 144 } // build_default 146 145 147 146 Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ ) { 148 std::list< Statement * > init;149 Expression * cond = build_if_control( ctl, init );150 151 std::list< Statement * > aststmt;152 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 153 assert( aststmt.size() == 1 ); 154 155 std::list< Statement * > astelse;147 list< Statement * > astinit; // maybe empty 148 Expression * astcond = build_if_control( ctl, astinit ); // ctl deleted, cond/init set 149 150 list< Statement * > aststmt; // loop body, compound created if empty 151 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 152 assert( aststmt.size() == 1 ); 153 154 list< Statement * > astelse; // else clause, maybe empty 156 155 buildMoveList< Statement, StatementNode >( else_, astelse ); 157 156 158 return new WhileDoStmt( cond, aststmt.front(), astelse.front(),init, false );157 return new WhileDoStmt( astcond, aststmt.front(), astelse.front(), astinit, false ); 159 158 } // build_while 160 159 161 160 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; 161 // do-while cannot have declarations in the contitional, so always empty 162 list< Statement * > astinit; 163 164 list< Statement * > aststmt; // loop body, compound created if empty 165 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 166 assert( aststmt.size() == 1 ); // compound created if empty 167 168 list< Statement * > astelse; // else clause, maybe empty 167 169 buildMoveList< Statement, StatementNode >( else_, astelse ); 168 170 169 std::list< Statement * > init; 170 return new WhileDoStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), aststmt.front(), astelse.front(), init, true ); 171 return new WhileDoStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), aststmt.front(), astelse.front(), astinit, true ); 171 172 } // build_do_while 172 173 173 174 Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ ) { 174 std::list< Statement * > init; 175 if ( forctl->init != nullptr ) { 176 buildMoveList( forctl->init, init ); 177 } // if 178 179 Expression * cond = nullptr; 180 if ( forctl->condition != nullptr ) 181 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 182 183 Expression * incr = nullptr; 184 if ( forctl->change != nullptr ) 185 incr = maybeMoveBuild< Expression >(forctl->change); 186 187 std::list< Statement * > aststmt; 188 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 189 assert( aststmt.size() == 1 ); 190 191 std::list< Statement * > astelse; 175 list< Statement * > astinit; // maybe empty 176 buildMoveList( forctl->init, astinit ); 177 178 Expression * astcond = nullptr; // maybe empty 179 astcond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 180 181 Expression * astincr = nullptr; // maybe empty 182 astincr = maybeMoveBuild< Expression >(forctl->change); 183 delete forctl; 184 185 list< Statement * > aststmt; // loop body, compound created if empty 186 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 187 assert( aststmt.size() == 1 ); 188 189 list< Statement * > astelse; // else clause, maybe empty 192 190 buildMoveList< Statement, StatementNode >( else_, astelse ); 193 191 194 delete forctl; 195 return new ForStmt( init, cond, incr, aststmt.front(), astelse.front() ); 192 return new ForStmt( astinit, astcond, astincr, aststmt.front(), astelse.front() ); 196 193 } // build_for 197 194 … … 201 198 } // build_branch 202 199 203 Statement * build_branch( st d::string * identifier, BranchStmt::Type kind ) {200 Statement * build_branch( string * identifier, BranchStmt::Type kind ) { 204 201 Statement * ret = new BranchStmt( * identifier, kind ); 205 202 delete identifier; // allocated by lexer … … 212 209 213 210 Statement * build_return( ExpressionNode * ctl ) { 214 std::list< Expression * > exps;211 list< Expression * > exps; 215 212 buildMoveList( ctl, exps ); 216 213 return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr ); … … 218 215 219 216 Statement * build_throw( ExpressionNode * ctl ) { 220 std::list< Expression * > exps;217 list< Expression * > exps; 221 218 buildMoveList( ctl, exps ); 222 assertf( exps.size() < 2, " This means we are leaking memory");219 assertf( exps.size() < 2, "CFA internal error: leaking memory" ); 223 220 return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr ); 224 221 } // build_throw 225 222 226 223 Statement * build_resume( ExpressionNode * ctl ) { 227 std::list< Expression * > exps;224 list< Expression * > exps; 228 225 buildMoveList( ctl, exps ); 229 assertf( exps.size() < 2, " This means we are leaking memory");226 assertf( exps.size() < 2, "CFA internal error: leaking memory" ); 230 227 return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 231 228 } // build_resume … … 237 234 } // build_resume_at 238 235 239 Statement * build_try( StatementNode * try_ stmt, StatementNode * catch_stmt, StatementNode * finally_stmt) {240 std::list< CatchStmt * > branches;241 buildMoveList< CatchStmt, StatementNode >( catch_ stmt, branches);242 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_ stmt));243 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_ stmt) );244 return new TryStmt( tryBlock, branches, finallyBlock );236 Statement * build_try( StatementNode * try_, StatementNode * catch_, StatementNode * finally_ ) { 237 list< CatchStmt * > aststmt; 238 buildMoveList< CatchStmt, StatementNode >( catch_, aststmt ); 239 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_)); 240 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_) ); 241 return new TryStmt( tryBlock, aststmt, finallyBlock ); 245 242 } // build_try 246 243 247 244 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) { 248 std::list< Statement * > branches;249 buildMoveList< Statement, StatementNode >( body, branches);250 assert( branches.size() == 1 );251 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );245 list< Statement * > aststmt; 246 buildMoveList< Statement, StatementNode >( body, aststmt ); 247 assert( aststmt.size() == 1 ); 248 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), aststmt.front() ); 252 249 } // build_catch 253 250 254 251 Statement * build_finally( StatementNode * stmt ) { 255 std::list< Statement * > branches;256 buildMoveList< Statement, StatementNode >( stmt, branches);257 assert( branches.size() == 1 );258 return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );252 list< Statement * > aststmt; 253 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 254 assert( aststmt.size() == 1 ); 255 return new FinallyStmt( dynamic_cast< CompoundStmt * >( aststmt.front() ) ); 259 256 } // build_finally 260 257 … … 264 261 node->type = type; 265 262 266 std::list< Statement * > stmts;263 list< Statement * > stmts; 267 264 buildMoveList< Statement, StatementNode >( then, stmts ); 268 265 if(!stmts.empty()) { … … 329 326 } // build_waitfor_timeout 330 327 331 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_ stmt, ExpressionNode * else_when ) {328 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_, ExpressionNode * else_when ) { 332 329 auto node = new WaitForStmt(); 333 330 … … 336 333 node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 337 334 338 node->orelse.statement = maybeMoveBuild<Statement >( else_ stmt);335 node->orelse.statement = maybeMoveBuild<Statement >( else_ ); 339 336 node->orelse.condition = notZeroExpr( maybeMoveBuild<Expression>( else_when ) ); 340 337 … … 343 340 344 341 Statement * build_with( ExpressionNode * exprs, StatementNode * stmt ) { 345 std::list< Expression * > e;342 list< Expression * > e; 346 343 buildMoveList( exprs, e ); 347 344 Statement * s = maybeMoveBuild<Statement>( stmt ); … … 371 368 372 369 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 373 std::list< Expression * > out, in;374 std::list< ConstantExpr * > clob;370 list< Expression * > out, in; 371 list< ConstantExpr * > clob; 375 372 376 373 buildMoveList( output, out ); … … 385 382 386 383 Statement * build_mutex( ExpressionNode * exprs, StatementNode * stmt ) { 387 std::list< Expression * > expList;384 list< Expression * > expList; 388 385 buildMoveList( exprs, expList ); 389 386 Statement * body = maybeMoveBuild<Statement>( stmt );
Note: See TracChangeset
for help on using the changeset viewer.