Changeset e82aa9df for src/Parser/StatementNode.cc
- Timestamp:
- Aug 15, 2016, 4:13:38 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- b1848a0
- Parents:
- 797347f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r797347f re82aa9df 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 14 13:10:54201613 // Update Count : 28812 // Last Modified On : Mon Aug 15 14:40:05 2016 13 // Update Count : 317 14 14 // 15 15 … … 26 26 using namespace std; 27 27 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 28 36 StatementNode::StatementNode() : ParseNode(), labels( 0 ), decl( 0 ) {} 37 38 StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), labels( 0 ) { 39 assert( false ); 29 StatementNode::StatementNode( DeclarationNode *decl ) { 40 30 if ( decl ) { 41 if ( DeclarationNode *agg = decl->extractAggregate() ) { 42 this->decl = agg; 43 StatementNode *nextStmt = new StatementNode; 44 nextStmt->type = Decl; 45 nextStmt->decl = decl; 31 DeclarationNode *agg = decl->extractAggregate(); 32 if ( agg ) { 33 StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) ); 46 34 next = nextStmt; 47 35 if ( decl->get_next() ) { 48 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next()) ) );36 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>(decl->get_next()) ) ); 49 37 decl->set_next( 0 ); 50 38 } // if … … 52 40 if ( decl->get_next() ) { 53 41 next = new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next() ) ); 54 decl->set_next( 0 );55 } // if56 this->decl = decl;57 } // if58 } // if59 }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 } // if73 } else {74 if ( decl->get_next() ) {75 next = new StatementNode2( dynamic_cast<DeclarationNode *>( decl->get_next() ) );76 42 decl->set_next( 0 ); 77 43 } // if … … 84 50 } 85 51 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 } // if100 return this;101 }102 103 52 StatementNode *StatementNode::append_last_case( StatementNode *stmt ) { 104 assert( false );105 return this;106 }107 108 StatementNode *StatementNode2::append_last_case( StatementNode *stmt ) {109 53 StatementNode *prev = this; 110 54 // find end of list and maintain previous pointer 111 55 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 112 StatementNode 2 *node = dynamic_cast<StatementNode2*>(curr);56 StatementNode *node = dynamic_cast<StatementNode *>(curr); 113 57 assert( node ); 114 58 assert( dynamic_cast<CaseStmt *>(node->stmt) ); 115 59 prev = curr; 116 60 } // for 117 // conver from StatementNode list to Statement list118 StatementNode 2 *node = dynamic_cast<StatementNode2*>(prev);61 // convert from StatementNode list to Statement list 62 StatementNode *node = dynamic_cast<StatementNode *>(prev); 119 63 std::list<Statement *> stmts; 120 64 buildList( stmt, stmts ); 121 // splice any new Statements to end of current sStatements65 // splice any new Statements to end of current Statements 122 66 CaseStmt * caseStmt = dynamic_cast<CaseStmt *>(node->stmt); 123 67 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 124 68 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 } // switch153 69 } 154 70 … … 261 177 } 262 178 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 ); 179 Statement *build_compound( StatementNode *first ) { 180 CompoundStmt *cs = new CompoundStmt( noLabels ); 301 181 buildList( first, cs->get_kids() ); 302 182 return cs; 303 183 } 304 184 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 185 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) { 327 186 std::list< Expression * > out, in; 328 187 std::list< ConstantExpr * > clob; 188 329 189 buildList( output, out ); 330 190 buildList( input, in ); 331 191 buildList( clobber, clob ); 332 std::list< Label > gotolabs = gotolabels; 333 return new AsmStmt( labs, voltile, instruction, out, in, clob, gotolabs ); 192 return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 334 193 } 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 // } // if343 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 // }352 194 353 195 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.