Changes in src/Parser/StatementNode.cc [e82aa9df:777bfcf]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
re82aa9df r777bfcf 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 14:40:05201613 // Update Count : 31712 // Last Modified On : Sun Aug 14 13:10:54 2016 13 // Update Count : 288 14 14 // 15 15 … … 26 26 using namespace std; 27 27 28 29 StatementNode::StatementNode( DeclarationNode *decl ) { 28 const char *StatementNode::StType[] = { 29 "Exp", "If", "Switch", "Case", "Default", "Choose", "Fallthru", 30 "While", "Do", "For", 31 "Goto", "Continue", "Break", "Return", "Throw", 32 "Try", "Catch", "Finally", "Asm", 33 "Decl" 34 }; 35 36 StatementNode::StatementNode() : ParseNode(), labels( 0 ), decl( 0 ) {} 37 38 StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), labels( 0 ) { 39 assert( false ); 30 40 if ( decl ) { 31 DeclarationNode *agg = decl->extractAggregate(); 32 if ( agg ) { 33 StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) ); 41 if ( DeclarationNode *agg = decl->extractAggregate() ) { 42 this->decl = agg; 43 StatementNode *nextStmt = new StatementNode; 44 nextStmt->type = Decl; 45 nextStmt->decl = decl; 34 46 next = nextStmt; 35 47 if ( decl->get_next() ) { 36 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next()) ) );48 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next() ) ) ); 37 49 decl->set_next( 0 ); 38 50 } // if … … 42 54 decl->set_next( 0 ); 43 55 } // if 56 this->decl = decl; 57 } // if 58 } // if 59 } 60 61 StatementNode2::StatementNode2( DeclarationNode *decl ) { 62 if ( decl ) { 63 DeclarationNode *agg = decl->extractAggregate(); 64 if ( agg ) { 65 StatementNode *nextStmt = new StatementNode; 66 nextStmt->type = Decl; 67 nextStmt->decl = decl; 68 next = nextStmt; 69 if ( decl->get_next() ) { 70 next->set_next( new StatementNode2( dynamic_cast<DeclarationNode *>(decl->get_next()) ) ); 71 decl->set_next( 0 ); 72 } // if 73 } else { 74 if ( decl->get_next() ) { 75 next = new StatementNode2( dynamic_cast<DeclarationNode *>( decl->get_next() ) ); 76 decl->set_next( 0 ); 77 } // if 44 78 agg = decl; 45 79 } // if … … 50 84 } 51 85 86 StatementNode::~StatementNode() { 87 delete decl; 88 } 89 90 StatementNode * StatementNode::clone() const { 91 assert( false ); 92 return 0; 93 } 94 95 StatementNode *StatementNode::add_label( const std::string *l ) { 96 if ( l != 0 ) { 97 labels.push_front( *l ); 98 delete l; 99 } // if 100 return this; 101 } 102 52 103 StatementNode *StatementNode::append_last_case( StatementNode *stmt ) { 104 assert( false ); 105 return this; 106 } 107 108 StatementNode *StatementNode2::append_last_case( StatementNode *stmt ) { 53 109 StatementNode *prev = this; 54 110 // find end of list and maintain previous pointer 55 111 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 56 StatementNode *node = dynamic_cast<StatementNode*>(curr);112 StatementNode2 *node = dynamic_cast<StatementNode2 *>(curr); 57 113 assert( node ); 58 114 assert( dynamic_cast<CaseStmt *>(node->stmt) ); 59 115 prev = curr; 60 116 } // for 61 // conver tfrom StatementNode list to Statement list62 StatementNode *node = dynamic_cast<StatementNode*>(prev);117 // conver from StatementNode list to Statement list 118 StatementNode2 *node = dynamic_cast<StatementNode2 *>(prev); 63 119 std::list<Statement *> stmts; 64 120 buildList( stmt, stmts ); 65 // splice any new Statements to end of current Statements121 // splice any new Statements to end of currents Statements 66 122 CaseStmt * caseStmt = dynamic_cast<CaseStmt *>(node->stmt); 67 123 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 68 124 return this; 125 } 126 127 Statement *StatementNode::build() const { 128 switch ( type ) { 129 case Decl: 130 return new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ); 131 assert( false ); 132 case Exp: 133 case If: 134 case Switch: 135 case Case: 136 case Default: 137 case While: 138 case Do: 139 case For: 140 case Goto: 141 case Break: 142 case Continue: 143 case Return: 144 case Throw : 145 case Try: 146 case Catch: 147 case Finally: 148 case Asm: 149 default: 150 assert( false ); 151 return 0; 152 } // switch 69 153 } 70 154 … … 177 261 } 178 262 179 Statement *build_compound( StatementNode *first ) { 180 CompoundStmt *cs = new CompoundStmt( noLabels ); 263 264 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {} 265 266 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ) : first( stmt ) { 267 if ( first ) { 268 last = ( StatementNode *)( stmt->get_last()); 269 } else { 270 last = 0; 271 } // if 272 } 273 274 CompoundStmtNode::~CompoundStmtNode() { 275 delete first; 276 } 277 278 void CompoundStmtNode::add_statement( StatementNode *stmt ) { 279 if ( stmt != 0 ) { 280 last->set_last( stmt ); 281 last = ( StatementNode *)( stmt->get_next()); 282 } // if 283 } 284 285 void CompoundStmtNode::print( ostream &os, int indent ) const { 286 if ( first ) { 287 first->printList( os, indent+2 ); 288 } // if 289 } 290 291 Statement *CompoundStmtNode::build() const { 292 std::list<Label> labs; 293 const std::list<std::string> &labels = get_labels(); 294 295 if ( ! labels.empty() ) { 296 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 297 copy( labels.begin(), labels.end(), lab_it ); 298 } // if 299 300 CompoundStmt *cs = new CompoundStmt( labs ); 181 301 buildList( first, cs->get_kids() ); 182 302 return cs; 183 303 } 184 304 185 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) { 305 306 AsmStmtNode::AsmStmtNode( bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) : 307 voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ) { 308 type = Asm; 309 if ( gotolabels ) { 310 this->gotolabels = gotolabels->get_labels(); 311 delete gotolabels; 312 } // if 313 } 314 315 AsmStmtNode::~AsmStmtNode() { 316 delete output; delete input; delete clobber; 317 } 318 319 Statement *AsmStmtNode::build() const { 320 std::list<Label> labs; 321 322 if ( ! get_labels().empty() ) { 323 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 324 copy( get_labels().begin(), get_labels().end(), lab_it ); 325 } // if 326 186 327 std::list< Expression * > out, in; 187 328 std::list< ConstantExpr * > clob; 188 189 329 buildList( output, out ); 190 330 buildList( input, in ); 191 331 buildList( clobber, clob ); 192 return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 193 } 332 std::list< Label > gotolabs = gotolabels; 333 return new AsmStmt( labs, voltile, instruction, out, in, clob, gotolabs ); 334 } 335 336 // Statement *build_asm( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 ) { 337 // std::list<Label> labs; 338 339 // if ( ! get_labels().empty() ) { 340 // std::back_insert_iterator< std::list<Label> > lab_it( labs ); 341 // copy( get_labels().begin(), get_labels().end(), lab_it ); 342 // } // if 343 344 // std::list< Expression * > out, in; 345 // std::list< ConstantExpr * > clob; 346 // buildList( output, out ); 347 // buildList( input, in ); 348 // buildList( clobber, clob ); 349 // std::list< Label > gotolabs = gotolabels; 350 // return new AsmStmt( labs, voltile, instruction, out, in, clob, gotolabs ); 351 // } 194 352 195 353 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.