Changes in src/Parser/StatementNode.cc [843054c2:59db689]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r843054c2 r59db689 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 15:10:45201513 // Update Count : 712 // Last Modified On : Sat Jun 6 23:25:41 2015 13 // Update Count : 19 14 14 // 15 15 … … 36 36 StatementNode::StatementNode() : ParseNode(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {} 37 37 38 StatementNode::StatementNode( string name_) : ParseNode( name_), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}38 StatementNode::StatementNode( const string *name_ ) : ParseNode( name_ ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {} 39 39 40 40 StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), isCatchRest ( false ) { … … 49 49 next->set_next( new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ) ); 50 50 decl->set_next( 0 ); 51 } 51 } // if 52 52 } else { 53 53 if ( decl->get_link() ) { 54 54 next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ); 55 55 decl->set_next( 0 ); 56 } 56 } // if 57 57 this->decl = decl; 58 } 59 } 58 } // if 59 } // if 60 60 } 61 61 … … 67 67 68 68 StatementNode::StatementNode( Type t, string *_target ) : 69 type( t ), control( 0 ), block( 0 ), labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {}69 type( t ), control( 0 ), block( 0 ), labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {} 70 70 71 71 StatementNode::~StatementNode() { … … 98 98 } else { 99 99 newnode->target = 0; 100 } 100 } // if 101 101 newnode->decl = maybeClone( decl ); 102 102 return newnode; … … 125 125 } 126 126 127 StatementNode *StatementNode::add_label( std::string *l ) {127 StatementNode *StatementNode::add_label( const std::string *l ) { 128 128 if ( l != 0 ) { 129 129 if ( labels == 0 ) … … 132 132 labels->push_front(*l ); 133 133 delete l; 134 } 134 } // if 135 135 return this; 136 136 } … … 151 151 else 152 152 block->set_link( stmt ); 153 } 153 } // if 154 154 return this; 155 155 } … … 165 165 else 166 166 block->set_link( stmt ); 167 } 167 } // if 168 168 return this; 169 169 } 170 170 171 171 void StatementNode::print( std::ostream &os, int indent ) const { 172 if ( labels != 0 ) 172 if ( labels != 0 ) { 173 173 if ( ! labels->empty()) { 174 174 std::list<std::string>::const_iterator i; 175 175 176 os << '\r' << string( indent, ' ');176 os << string( indent, ' ' ); 177 177 for ( i = labels->begin(); i != labels->end(); i++ ) 178 178 os << *i << ":"; 179 179 os << endl; 180 } 180 } // if 181 } // if 181 182 182 183 switch ( type ) { … … 193 194 break; 194 195 default: 195 os << '\r' << string( indent, ' ') << StatementNode::StType[type] << endl;196 os << string( indent, ' ' ) << StatementNode::StType[type] << endl; 196 197 if ( type == Catch ) { 197 198 if ( decl ) { 198 os << '\r' <<string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;199 os << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl; 199 200 decl->print( os, indent + 2*ParseNode::indent_by ); 200 201 } else if ( isCatchRest ) { 201 os << '\r' <<string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;202 os << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl; 202 203 } else { 203 204 ; // should never reach here 204 } 205 } 205 } // if 206 } // if 206 207 if ( control ) { 207 os << '\r' <<string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;208 os << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl; 208 209 control->printList( os, indent + 2*ParseNode::indent_by ); 209 } 210 } // if 210 211 if ( block ) { 211 os << '\r' <<string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;212 os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl; 212 213 block->printList( os, indent + 2*ParseNode::indent_by ); 213 } 214 } // if 214 215 if ( target ) { 215 os << '\r' <<string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;216 } 216 os << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl; 217 } // if 217 218 break; 218 } 219 } // switch 219 220 } 220 221 … … 227 228 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 228 229 copy( labels->begin(), labels->end(), lab_it ); 229 } 230 } // if 230 231 231 232 // try { … … 254 255 elseb = branches.front(); 255 256 branches.pop_front(); 256 } 257 } // if 257 258 return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb ); 258 259 } … … 299 300 assert( get_control() != 0 ); 300 301 return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto ); 301 } 302 } // if 302 303 303 304 return new BranchStmt( labs, get_target(), BranchStmt::Goto ); … … 322 323 if ( ( finallyBlock = dynamic_cast<FinallyStmt *>( branches.back())) ) { 323 324 branches.pop_back(); 324 } 325 } // if 325 326 return new TryStmt( labs, tryBlock, branches, finallyBlock ); 326 327 } … … 342 343 // shouldn't be here 343 344 return 0; 344 } 345 } 346 347 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) { 348 } 349 350 CompoundStmtNode::CompoundStmtNode( string *name_) : StatementNode(*name_), first( 0 ), last( 0 ) { 351 } 352 353 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ): first( stmt ) { 345 } // switch 346 } 347 348 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {} 349 350 CompoundStmtNode::CompoundStmtNode( const string *name_ ) : StatementNode( name_ ), first( 0 ), last( 0 ) {} 351 352 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ) : first( stmt ) { 354 353 if ( first ) { 355 354 last = ( StatementNode *)( stmt->get_last()); 356 355 } else { 357 356 last = 0; 358 } 357 } // if 359 358 } 360 359 … … 367 366 last->set_link( stmt ); 368 367 last = ( StatementNode *)( stmt->get_link()); 369 } 368 } // if 370 369 } 371 370 … … 373 372 if ( first ) { 374 373 first->printList( os, indent+2 ); 375 } 374 } // if 376 375 } 377 376 … … 383 382 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 384 383 copy( labels->begin(), labels->end(), lab_it ); 385 } 384 } // if 386 385 387 386 CompoundStmt *cs = new CompoundStmt( labs ); … … 391 390 392 391 void NullStmtNode::print( ostream &os, int indent ) const { 393 os << "\r" << string( indent, ' ') << "Null Statement:" << endl;392 os << string( indent, ' ' ) << "Null Statement:" << endl; 394 393 } 395 394
Note:
See TracChangeset
for help on using the changeset viewer.