Changes in src/Parser/StatementNode.cc [6a276a0:61fc4f6]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r6a276a0 r61fc4f6 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 : Sun Apr 29 14:21:45 2018 13 // Update Count : 353 14 14 // 15 15 … … 33 33 34 34 35 StatementNode::StatementNode( DeclarationNode * decl ) {35 StatementNode::StatementNode( DeclarationNode * decl ) { 36 36 assert( decl ); 37 DeclarationNode * agg = decl->extractAggregate();37 DeclarationNode * agg = decl->extractAggregate(); 38 38 if ( agg ) { 39 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );39 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) ); 40 40 set_next( nextStmt ); 41 41 if ( decl->get_next() ) { … … 53 53 } // StatementNode::StatementNode 54 54 55 StatementNode * StatementNode::append_last_case( StatementNode *stmt ) {56 StatementNode * prev = this;55 StatementNode * StatementNode::append_last_case( StatementNode * stmt ) { 56 StatementNode * prev = this; 57 57 // find end of list and maintain previous pointer 58 58 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr);59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr); 60 60 assert( dynamic_cast< CaseStmt * >(node->stmt.get()) ); 61 61 prev = curr; 62 62 } // for 63 63 // convert from StatementNode list to Statement list 64 StatementNode * node = dynamic_cast< StatementNode * >(prev);64 StatementNode * node = dynamic_cast< StatementNode * >(prev); 65 65 std::list< Statement * > stmts; 66 66 buildMoveList( stmt, stmts ); … … 71 71 } 72 72 73 Statement * build_expr( ExpressionNode *ctl ) {74 Expression * e = maybeMoveBuild< Expression >( ctl );73 Statement * build_expr( ExpressionNode * ctl ) { 74 Expression * e = maybeMoveBuild< Expression >( ctl ); 75 75 76 76 if ( e ) … … 80 80 } 81 81 82 Statement * build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {83 Statement * thenb, *elseb = 0;82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 83 Statement * thenb, * elseb = 0; 84 84 std::list< Statement * > branches; 85 85 buildMoveList< Statement, StatementNode >( then_stmt, branches ); … … 116 116 } 117 117 118 Statement * build_switch( bool isSwitch, ExpressionNode *ctl, StatementNode *stmt ) {118 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { 119 119 std::list< Statement * > branches; 120 120 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 131 131 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); 132 132 } 133 Statement * build_case( ExpressionNode *ctl ) {133 Statement * build_case( ExpressionNode * ctl ) { 134 134 std::list< Statement * > branches; 135 135 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 136 136 } 137 Statement * build_default() {137 Statement * build_default() { 138 138 std::list< Statement * > branches; 139 139 return new CaseStmt( nullptr, branches, true ); 140 140 } 141 141 142 Statement * build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {142 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) { 143 143 std::list< Statement * > branches; 144 144 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 147 147 } 148 148 149 Statement * build_for( ForCtl *forctl, StatementNode *stmt ) {149 Statement * build_for( ForCtl * forctl, StatementNode * stmt ) { 150 150 std::list< Statement * > branches; 151 151 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 157 157 } // if 158 158 159 Expression * cond = 0;159 Expression * cond = 0; 160 160 if ( forctl->condition != 0 ) 161 161 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 162 162 163 Expression * incr = 0;163 Expression * incr = 0; 164 164 if ( forctl->change != 0 ) 165 165 incr = maybeMoveBuild< Expression >(forctl->change); … … 169 169 } 170 170 171 Statement * build_branch( BranchStmt::Type kind ) {171 Statement * build_branch( BranchStmt::Type kind ) { 172 172 Statement * ret = new BranchStmt( "", kind ); 173 173 return ret; 174 174 } 175 Statement * build_branch( std::string *identifier, BranchStmt::Type kind ) {176 Statement * ret = new BranchStmt( * identifier, kind );175 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) { 176 Statement * ret = new BranchStmt( * identifier, kind ); 177 177 delete identifier; // allocated by lexer 178 178 return ret; 179 179 } 180 Statement * build_computedgoto( ExpressionNode *ctl ) {180 Statement * build_computedgoto( ExpressionNode * ctl ) { 181 181 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 182 182 } 183 183 184 Statement * build_return( ExpressionNode *ctl ) {184 Statement * build_return( ExpressionNode * ctl ) { 185 185 std::list< Expression * > exps; 186 186 buildMoveList( ctl, exps ); … … 188 188 } 189 189 190 Statement * build_throw( ExpressionNode *ctl ) {190 Statement * build_throw( ExpressionNode * ctl ) { 191 191 std::list< Expression * > exps; 192 192 buildMoveList( ctl, exps ); … … 195 195 } 196 196 197 Statement * build_resume( ExpressionNode *ctl ) {197 Statement * build_resume( ExpressionNode * ctl ) { 198 198 std::list< Expression * > exps; 199 199 buildMoveList( ctl, exps ); … … 202 202 } 203 203 204 Statement * build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) {204 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) { 205 205 (void)ctl; 206 206 (void)target; … … 208 208 } 209 209 210 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 ) { 211 211 std::list< CatchStmt * > branches; 212 212 buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches ); 213 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));214 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) ); 215 215 return new TryStmt( tryBlock, branches, finallyBlock ); 216 216 } 217 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 ) { 218 218 std::list< Statement * > branches; 219 219 buildMoveList< Statement, StatementNode >( body, branches ); … … 221 221 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 222 222 } 223 Statement * build_finally( StatementNode *stmt ) {223 Statement * build_finally( StatementNode * stmt ) { 224 224 std::list< Statement * > branches; 225 225 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 304 304 } 305 305 306 Statement * build_compound( StatementNode *first ) {307 CompoundStmt * cs = new CompoundStmt();306 Statement * build_compound( StatementNode * first ) { 307 CompoundStmt * cs = new CompoundStmt(); 308 308 buildMoveList( first, cs->get_kids() ); 309 309 return cs; 310 310 } 311 311 312 Statement * build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {312 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 313 313 std::list< Expression * > out, in; 314 314 std::list< ConstantExpr * > clob; … … 318 318 buildMoveList( clobber, clob ); 319 319 return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 320 } 321 322 Statement * build_dirstmt( string * directive ) { 323 cout << *directive << endl; 324 return nullptr; 320 325 } 321 326
Note:
See TracChangeset
for help on using the changeset viewer.