Changes in src/Parser/StatementNode.cc [ac71a86:e82aa9df]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
rac71a86 re82aa9df 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 20:47:11201613 // Update Count : 3 2212 // Last Modified On : Mon Aug 15 14:40:05 2016 13 // Update Count : 317 14 14 // 15 15 … … 32 32 if ( agg ) { 33 33 StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) ); 34 set_next( nextStmt );34 next = nextStmt; 35 35 if ( decl->get_next() ) { 36 get_next()->set_next( new StatementNode( dynamic_cast< DeclarationNode *>(decl->get_next()) ) );36 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>(decl->get_next()) ) ); 37 37 decl->set_next( 0 ); 38 38 } // if 39 39 } else { 40 40 if ( decl->get_next() ) { 41 set_next(new StatementNode( dynamic_cast< DeclarationNode * >( decl->get_next()) ) );41 next = new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next() ) ); 42 42 decl->set_next( 0 ); 43 43 } // if 44 44 agg = decl; 45 45 } // if 46 stmt .reset( new DeclStmt( noLabels, maybeBuild< Declaration >(agg)) );46 stmt = new DeclStmt( noLabels, maybeBuild<Declaration>(agg) ); 47 47 } else { 48 48 assert( false ); … … 54 54 // find end of list and maintain previous pointer 55 55 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 56 StatementNode *node = dynamic_cast< StatementNode *>(curr);56 StatementNode *node = dynamic_cast<StatementNode *>(curr); 57 57 assert( node ); 58 assert( dynamic_cast< CaseStmt * >(node->stmt.get()) );58 assert( dynamic_cast<CaseStmt *>(node->stmt) ); 59 59 prev = curr; 60 60 } // for 61 61 // convert from StatementNode list to Statement list 62 StatementNode *node = dynamic_cast< StatementNode *>(prev);63 std::list< Statement *> stmts;64 build MoveList( stmt, stmts );62 StatementNode *node = dynamic_cast<StatementNode *>(prev); 63 std::list<Statement *> stmts; 64 buildList( stmt, stmts ); 65 65 // splice any new Statements to end of current Statements 66 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt.get());66 CaseStmt * caseStmt = dynamic_cast<CaseStmt *>(node->stmt); 67 67 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 68 68 return this; … … 70 70 71 71 Statement *build_expr( ExpressionNode *ctl ) { 72 Expression *e = maybe MoveBuild< Expression >( ctl );72 Expression *e = maybeBuild< Expression >( ctl ); 73 73 74 74 if ( e ) … … 80 80 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) { 81 81 Statement *thenb, *elseb = 0; 82 std::list< Statement *> branches;83 build MoveList< Statement, StatementNode>( then_stmt, branches );82 std::list<Statement *> branches; 83 buildList<Statement, StatementNode>( then_stmt, branches ); 84 84 assert( branches.size() == 1 ); 85 85 thenb = branches.front(); 86 86 87 87 if ( else_stmt ) { 88 std::list< Statement *> branches;89 build MoveList< Statement, StatementNode>( else_stmt, branches );88 std::list<Statement *> branches; 89 buildList<Statement, StatementNode>( else_stmt, branches ); 90 90 assert( branches.size() == 1 ); 91 91 elseb = branches.front(); 92 92 } // if 93 return new IfStmt( noLabels, notZeroExpr( maybe MoveBuild< Expression>(ctl) ), thenb, elseb );93 return new IfStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), thenb, elseb ); 94 94 } 95 95 96 96 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) { 97 std::list< Statement *> branches;98 build MoveList< Statement, StatementNode>( stmt, branches );97 std::list<Statement *> branches; 98 buildList<Statement, StatementNode>( stmt, branches ); 99 99 assert( branches.size() >= 0 ); // size == 0 for switch (...) {}, i.e., no declaration or statements 100 return new SwitchStmt( noLabels, maybe MoveBuild< Expression>(ctl), branches );100 return new SwitchStmt( noLabels, maybeBuild<Expression>(ctl), branches ); 101 101 } 102 102 Statement *build_case( ExpressionNode *ctl ) { 103 std::list< Statement *> branches;104 return new CaseStmt( noLabels, maybe MoveBuild< Expression>(ctl), branches );103 std::list<Statement *> branches; 104 return new CaseStmt( noLabels, maybeBuild<Expression>(ctl), branches ); 105 105 } 106 106 Statement *build_default() { 107 std::list< Statement *> branches;107 std::list<Statement *> branches; 108 108 return new CaseStmt( noLabels, nullptr, branches, true ); 109 109 } 110 110 111 111 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) { 112 std::list< Statement *> branches;113 build MoveList< Statement, StatementNode>( stmt, branches );112 std::list<Statement *> branches; 113 buildList<Statement, StatementNode>( stmt, branches ); 114 114 assert( branches.size() == 1 ); 115 return new WhileStmt( noLabels, notZeroExpr( maybe MoveBuild< Expression>(ctl) ), branches.front(), kind );115 return new WhileStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), branches.front(), kind ); 116 116 } 117 117 118 118 Statement *build_for( ForCtl *forctl, StatementNode *stmt ) { 119 std::list< Statement *> branches;120 build MoveList< Statement, StatementNode>( stmt, branches );119 std::list<Statement *> branches; 120 buildList<Statement, StatementNode>( stmt, branches ); 121 121 assert( branches.size() == 1 ); 122 122 123 std::list< Statement *> init;123 std::list<Statement *> init; 124 124 if ( forctl->init != 0 ) { 125 build MoveList( forctl->init, init );125 buildList( forctl->init, init ); 126 126 } // if 127 127 128 128 Expression *cond = 0; 129 129 if ( forctl->condition != 0 ) 130 cond = notZeroExpr( maybe MoveBuild< Expression>(forctl->condition) );130 cond = notZeroExpr( maybeBuild<Expression>(forctl->condition) ); 131 131 132 132 Expression *incr = 0; 133 133 if ( forctl->change != 0 ) 134 incr = maybe MoveBuild< Expression>(forctl->change);134 incr = maybeBuild<Expression>(forctl->change); 135 135 136 136 delete forctl; … … 142 142 } 143 143 Statement *build_computedgoto( ExpressionNode *ctl ) { 144 return new BranchStmt( noLabels, maybe MoveBuild< Expression>(ctl), BranchStmt::Goto );144 return new BranchStmt( noLabels, maybeBuild<Expression>(ctl), BranchStmt::Goto ); 145 145 } 146 146 147 147 Statement *build_return( ExpressionNode *ctl ) { 148 std::list< Expression *> exps;149 build MoveList( ctl, exps );148 std::list<Expression *> exps; 149 buildList( ctl, exps ); 150 150 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr ); 151 151 } 152 152 Statement *build_throw( ExpressionNode *ctl ) { 153 std::list< Expression * > exps; 154 buildMoveList( ctl, exps ); 155 assertf( exps.size() < 2, "This means we are leaking memory"); 156 return new ReturnStmt( noLabels, !exps.empty() ? exps.back() : nullptr, true ); 153 std::list<Expression *> exps; 154 buildList( ctl, exps ); 155 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true ); 157 156 } 158 157 159 158 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) { 160 std::list< Statement *> branches;161 build MoveList< Statement, StatementNode>( catch_stmt, branches );162 CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement>(try_stmt));159 std::list<Statement *> branches; 160 buildList<Statement, StatementNode>( catch_stmt, branches ); 161 CompoundStmt *tryBlock = dynamic_cast<CompoundStmt *>(maybeBuild<Statement>(try_stmt)); 163 162 assert( tryBlock ); 164 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement>(finally_stmt) );163 FinallyStmt *finallyBlock = dynamic_cast<FinallyStmt *>(maybeBuild<Statement>(finally_stmt) ); 165 164 return new TryStmt( noLabels, tryBlock, branches, finallyBlock ); 166 165 } 167 166 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) { 168 std::list< Statement *> branches;169 build MoveList< Statement, StatementNode>( stmt, branches );167 std::list<Statement *> branches; 168 buildList<Statement, StatementNode>( stmt, branches ); 170 169 assert( branches.size() == 1 ); 171 return new CatchStmt( noLabels, maybe MoveBuild< Declaration>(decl), branches.front(), catchAny );170 return new CatchStmt( noLabels, maybeBuild<Declaration>(decl), branches.front(), catchAny ); 172 171 } 173 172 Statement *build_finally( StatementNode *stmt ) { 174 std::list< Statement *> branches;175 build MoveList< Statement, StatementNode>( stmt, branches );173 std::list<Statement *> branches; 174 buildList<Statement, StatementNode>( stmt, branches ); 176 175 assert( branches.size() == 1 ); 177 return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt *>( branches.front() ) );176 return new FinallyStmt( noLabels, dynamic_cast<CompoundStmt *>( branches.front() ) ); 178 177 } 179 178 180 179 Statement *build_compound( StatementNode *first ) { 181 180 CompoundStmt *cs = new CompoundStmt( noLabels ); 182 build MoveList( first, cs->get_kids() );181 buildList( first, cs->get_kids() ); 183 182 return cs; 184 183 } … … 188 187 std::list< ConstantExpr * > clob; 189 188 190 build MoveList( output, out );191 build MoveList( input, in );192 build MoveList( clobber, clob );189 buildList( output, out ); 190 buildList( input, in ); 191 buildList( clobber, clob ); 193 192 return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 194 193 }
Note:
See TracChangeset
for help on using the changeset viewer.