Changes in src/Parser/StatementNode.cc [cc32d83:8d7bef2]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
rcc32d83 r8d7bef2 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 30 09:21:16 201813 // Update Count : 3 5412 // Last Modified On : Fri Sep 1 23:25:23 2017 13 // Update Count : 346 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_ptr19 18 #include <string> // for string 20 19 … … 33 32 34 33 35 StatementNode::StatementNode( DeclarationNode * decl ) {34 StatementNode::StatementNode( DeclarationNode *decl ) { 36 35 assert( decl ); 37 DeclarationNode * agg = decl->extractAggregate();36 DeclarationNode *agg = decl->extractAggregate(); 38 37 if ( agg ) { 39 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );38 StatementNode *nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) ); 40 39 set_next( nextStmt ); 41 40 if ( decl->get_next() ) { … … 50 49 agg = decl; 51 50 } // if 52 stmt .reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );51 stmt = new DeclStmt{ maybeMoveBuild< Declaration >(agg) }; 53 52 } // StatementNode::StatementNode 54 53 55 StatementNode * StatementNode::append_last_case( StatementNode *stmt ) {56 StatementNode * prev = this;54 StatementNode *StatementNode::append_last_case( StatementNode *stmt ) { 55 StatementNode *prev = this; 57 56 // find end of list and maintain previous pointer 58 57 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr);60 assert( dynamic_cast< CaseStmt * >(node->stmt .get()) );58 StatementNode *node = strict_dynamic_cast< StatementNode * >(curr); 59 assert( dynamic_cast< CaseStmt * >(node->stmt) ); 61 60 prev = curr; 62 61 } // for 63 62 // convert from StatementNode list to Statement list 64 StatementNode * node = dynamic_cast< StatementNode * >(prev);63 StatementNode *node = dynamic_cast< StatementNode * >(prev); 65 64 std::list< Statement * > stmts; 66 65 buildMoveList( stmt, stmts ); 67 66 // splice any new Statements to end of current Statements 68 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt .get());67 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt); 69 68 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 70 69 return this; 71 70 } 72 71 73 Statement * build_expr( ExpressionNode *ctl ) {74 Expression * e = maybeMoveBuild< Expression >( ctl );72 Statement *build_expr( ExpressionNode *ctl ) { 73 Expression *e = maybeMoveBuild< Expression >( ctl ); 75 74 76 75 if ( e ) … … 80 79 } 81 80 82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode *else_stmt ) {83 Statement * thenb, *elseb = 0;81 Statement *build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) { 82 Statement *thenb, *elseb = 0; 84 83 std::list< Statement * > branches; 85 84 buildMoveList< Statement, StatementNode >( then_stmt, branches ); … … 116 115 } 117 116 118 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode *stmt ) {117 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) { 119 118 std::list< Statement * > branches; 120 119 buildMoveList< Statement, StatementNode >( stmt, branches ); 121 if ( ! isSwitch ) { // choose statement122 for ( Statement * stmt : branches ) {123 CaseStmt * caseStmt = strict_dynamic_cast< CaseStmt * >( stmt );124 if ( ! caseStmt->stmts.empty() ) { // code after "case" => end of case list125 CompoundStmt * block = strict_dynamic_cast< CompoundStmt * >( caseStmt->stmts.front() );126 block->kids.push_back( new BranchStmt( "", BranchStmt::Break ) );127 } // if128 } // for129 } // if130 120 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements 131 121 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); 132 122 } 133 Statement * build_case( ExpressionNode *ctl ) {123 Statement *build_case( ExpressionNode *ctl ) { 134 124 std::list< Statement * > branches; 135 125 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 136 126 } 137 Statement * build_default() {127 Statement *build_default() { 138 128 std::list< Statement * > branches; 139 129 return new CaseStmt( nullptr, branches, true ); 140 130 } 141 131 142 Statement * build_while( ExpressionNode * ctl, StatementNode *stmt, bool kind ) {132 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) { 143 133 std::list< Statement * > branches; 144 134 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 147 137 } 148 138 149 Statement * build_for( ForCtl * forctl, StatementNode *stmt ) {139 Statement *build_for( ForCtl *forctl, StatementNode *stmt ) { 150 140 std::list< Statement * > branches; 151 141 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 157 147 } // if 158 148 159 Expression * cond = 0;149 Expression *cond = 0; 160 150 if ( forctl->condition != 0 ) 161 151 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 162 152 163 Expression * incr = 0;153 Expression *incr = 0; 164 154 if ( forctl->change != 0 ) 165 155 incr = maybeMoveBuild< Expression >(forctl->change); … … 169 159 } 170 160 171 Statement * build_branch( BranchStmt::Type kind ) {161 Statement *build_branch( BranchStmt::Type kind ) { 172 162 Statement * ret = new BranchStmt( "", kind ); 173 163 return ret; 174 164 } 175 Statement * build_branch( std::string *identifier, BranchStmt::Type kind ) {176 Statement * ret = new BranchStmt( * identifier, kind );165 Statement *build_branch( std::string *identifier, BranchStmt::Type kind ) { 166 Statement * ret = new BranchStmt( *identifier, kind ); 177 167 delete identifier; // allocated by lexer 178 168 return ret; 179 169 } 180 Statement * build_computedgoto( ExpressionNode *ctl ) {170 Statement *build_computedgoto( ExpressionNode *ctl ) { 181 171 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 182 172 } 183 173 184 Statement * build_return( ExpressionNode *ctl ) {174 Statement *build_return( ExpressionNode *ctl ) { 185 175 std::list< Expression * > exps; 186 176 buildMoveList( ctl, exps ); … … 188 178 } 189 179 190 Statement * build_throw( ExpressionNode *ctl ) {180 Statement *build_throw( ExpressionNode *ctl ) { 191 181 std::list< Expression * > exps; 192 182 buildMoveList( ctl, exps ); … … 195 185 } 196 186 197 Statement * build_resume( ExpressionNode *ctl ) {187 Statement *build_resume( ExpressionNode *ctl ) { 198 188 std::list< Expression * > exps; 199 189 buildMoveList( ctl, exps ); … … 202 192 } 203 193 204 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode *target ) {194 Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) { 205 195 (void)ctl; 206 196 (void)target; … … 208 198 } 209 199 210 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode *finally_stmt ) {200 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) { 211 201 std::list< CatchStmt * > branches; 212 202 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) );203 CompoundStmt *tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 204 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 215 205 return new TryStmt( tryBlock, branches, finallyBlock ); 216 206 } 217 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode *body ) {207 Statement *build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) { 218 208 std::list< Statement * > branches; 219 209 buildMoveList< Statement, StatementNode >( body, branches ); … … 221 211 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 222 212 } 223 Statement * build_finally( StatementNode *stmt ) {213 Statement *build_finally( StatementNode *stmt ) { 224 214 std::list< Statement * > branches; 225 215 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 304 294 } 305 295 306 Statement * build_compound( StatementNode *first ) {307 CompoundStmt * cs = new CompoundStmt();296 Statement *build_compound( StatementNode *first ) { 297 CompoundStmt *cs = new CompoundStmt(); 308 298 buildMoveList( first, cs->get_kids() ); 309 299 return cs; 310 300 } 311 301 312 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode *gotolabels ) {302 Statement *build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) { 313 303 std::list< Expression * > out, in; 314 304 std::list< ConstantExpr * > clob; … … 318 308 buildMoveList( clobber, clob ); 319 309 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 );324 310 } 325 311
Note:
See TracChangeset
for help on using the changeset viewer.