Changeset ff29f08 for src/Parser/StatementNode.cc
- Timestamp:
- May 18, 2018, 2:09:21 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 2472a19
- Parents:
- f6f0cca3 (diff), c7d8100c (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
rf6f0cca3 rff29f08 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 8 14:31:32201813 // Update Count : 3 4812 // Last Modified On : Mon Apr 30 09:21:16 2018 13 // Update Count : 354 14 14 // 15 15 16 16 #include <cassert> // for assert, strict_dynamic_cast, assertf 17 17 #include <list> // for list 18 #include <memory> // for unique_ptr 18 19 #include <string> // for string 19 20 … … 32 33 33 34 34 StatementNode::StatementNode( DeclarationNode * decl ) {35 StatementNode::StatementNode( DeclarationNode * decl ) { 35 36 assert( decl ); 36 DeclarationNode * agg = decl->extractAggregate();37 DeclarationNode * agg = decl->extractAggregate(); 37 38 if ( agg ) { 38 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );39 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) ); 39 40 set_next( nextStmt ); 40 41 if ( decl->get_next() ) { … … 52 53 } // StatementNode::StatementNode 53 54 54 StatementNode * StatementNode::append_last_case( StatementNode *stmt ) {55 StatementNode * prev = this;55 StatementNode * StatementNode::append_last_case( StatementNode * stmt ) { 56 StatementNode * prev = this; 56 57 // find end of list and maintain previous pointer 57 58 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 58 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr);59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr); 59 60 assert( dynamic_cast< CaseStmt * >(node->stmt) ); 60 61 prev = curr; 61 62 } // for 62 63 // convert from StatementNode list to Statement list 63 StatementNode * node = dynamic_cast< StatementNode * >(prev);64 StatementNode * node = dynamic_cast< StatementNode * >(prev); 64 65 std::list< Statement * > stmts; 65 66 buildMoveList( stmt, stmts ); … … 70 71 } 71 72 72 Statement * build_expr( ExpressionNode *ctl ) {73 Expression * e = maybeMoveBuild< Expression >( ctl );73 Statement * build_expr( ExpressionNode * ctl ) { 74 Expression * e = maybeMoveBuild< Expression >( ctl ); 74 75 75 76 if ( e ) … … 79 80 } 80 81 81 Statement * build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {82 Statement * thenb, *elseb = 0;82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 83 Statement * thenb, * elseb = 0; 83 84 std::list< Statement * > branches; 84 85 buildMoveList< Statement, StatementNode >( then_stmt, branches ); … … 115 116 } 116 117 117 Statement * build_switch( bool isSwitch, ExpressionNode *ctl, StatementNode *stmt ) {118 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { 118 119 std::list< Statement * > branches; 119 120 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 130 131 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); 131 132 } 132 Statement * build_case( ExpressionNode *ctl ) {133 Statement * build_case( ExpressionNode * ctl ) { 133 134 std::list< Statement * > branches; 134 135 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 135 136 } 136 Statement * build_default() {137 Statement * build_default() { 137 138 std::list< Statement * > branches; 138 139 return new CaseStmt( nullptr, branches, true ); 139 140 } 140 141 141 Statement * build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {142 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) { 142 143 std::list< Statement * > branches; 143 144 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 146 147 } 147 148 148 Statement * build_for( ForCtl *forctl, StatementNode *stmt ) {149 Statement * build_for( ForCtl * forctl, StatementNode * stmt ) { 149 150 std::list< Statement * > branches; 150 151 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 156 157 } // if 157 158 158 Expression * cond = 0;159 Expression * cond = 0; 159 160 if ( forctl->condition != 0 ) 160 161 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 161 162 162 Expression * incr = 0;163 Expression * incr = 0; 163 164 if ( forctl->change != 0 ) 164 165 incr = maybeMoveBuild< Expression >(forctl->change); … … 168 169 } 169 170 170 Statement * build_branch( BranchStmt::Type kind ) {171 Statement * build_branch( BranchStmt::Type kind ) { 171 172 Statement * ret = new BranchStmt( "", kind ); 172 173 return ret; 173 174 } 174 Statement * build_branch( std::string *identifier, BranchStmt::Type kind ) {175 Statement * ret = new BranchStmt( * identifier, kind );175 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) { 176 Statement * ret = new BranchStmt( * identifier, kind ); 176 177 delete identifier; // allocated by lexer 177 178 return ret; 178 179 } 179 Statement * build_computedgoto( ExpressionNode *ctl ) {180 Statement * build_computedgoto( ExpressionNode * ctl ) { 180 181 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 181 182 } 182 183 183 Statement * build_return( ExpressionNode *ctl ) {184 Statement * build_return( ExpressionNode * ctl ) { 184 185 std::list< Expression * > exps; 185 186 buildMoveList( ctl, exps ); … … 187 188 } 188 189 189 Statement * build_throw( ExpressionNode *ctl ) {190 Statement * build_throw( ExpressionNode * ctl ) { 190 191 std::list< Expression * > exps; 191 192 buildMoveList( ctl, exps ); … … 194 195 } 195 196 196 Statement * build_resume( ExpressionNode *ctl ) {197 Statement * build_resume( ExpressionNode * ctl ) { 197 198 std::list< Expression * > exps; 198 199 buildMoveList( ctl, exps ); … … 201 202 } 202 203 203 Statement * build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) {204 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) { 204 205 (void)ctl; 205 206 (void)target; … … 207 208 } 208 209 209 Statement * build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {210 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) { 210 211 std::list< CatchStmt * > branches; 211 212 buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches ); 212 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));213 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );213 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 214 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 214 215 return new TryStmt( tryBlock, branches, finallyBlock ); 215 216 } 216 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) {217 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) { 217 218 std::list< Statement * > branches; 218 219 buildMoveList< Statement, StatementNode >( body, branches ); … … 220 221 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 221 222 } 222 Statement * build_finally( StatementNode *stmt ) {223 Statement * build_finally( StatementNode * stmt ) { 223 224 std::list< Statement * > branches; 224 225 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 303 304 } 304 305 305 Statement * build_compound( StatementNode *first ) {306 CompoundStmt * cs = new CompoundStmt();306 Statement * build_compound( StatementNode * first ) { 307 CompoundStmt * cs = new CompoundStmt(); 307 308 buildMoveList( first, cs->get_kids() ); 308 309 return cs; 309 310 } 310 311 311 Statement * build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {312 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 312 313 std::list< Expression * > out, in; 313 314 std::list< ConstantExpr * > clob; … … 317 318 buildMoveList( clobber, clob ); 318 319 return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 320 } 321 322 Statement * build_directive( string * directive ) { 323 return new DirectiveStmt( *directive ); 319 324 } 320 325
Note: See TracChangeset
for help on using the changeset viewer.