Changeset b87a5ed for translator/Parser/StatementNode.cc
- Timestamp:
- May 16, 2015, 3:36:19 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- a32b204
- Parents:
- b8508a2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/StatementNode.cc
rb8508a2 rb87a5ed 1 /* -*- C++ -*- */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // StatementNode.cc -- 8 // 9 // Author : Rodolfo G. Esteves 10 // Created On : Sat May 16 14:59:41 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 15:10:45 2015 13 // Update Count : 7 14 // 15 2 16 #include <list> 3 17 #include <algorithm> … … 12 26 using namespace std; 13 27 14 const char *StatementNode::StType[] = 15 { "Exp", "If", "Switch", "Case", "Default", "Choose", "Fallthru", 16 "While", "Do", "For", 17 "Goto", "Continue", "Break", "Return", "Throw", 18 "Try", "Catch", "Finally", "Asm", 19 "Decl" 20 }; 21 22 StatementNode::StatementNode(void) : 23 ParseNode(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {} 24 25 StatementNode::StatementNode(string name_) : 26 ParseNode(name_), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {} 27 28 StatementNode::StatementNode( DeclarationNode *decl ) : 29 type( Decl ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), isCatchRest ( false ) 30 { 31 if( decl ) { 32 if( DeclarationNode *agg = decl->extractAggregate() ) { 33 this->decl = agg; 34 StatementNode *nextStmt = new StatementNode; 35 nextStmt->type = Decl; 36 nextStmt->decl = decl; 37 next = nextStmt; 38 if( decl->get_link() ) { 39 next->set_next( new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ) ); 40 decl->set_next( 0 ); 41 } 42 } else { 43 if( decl->get_link() ) { 44 next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ); 45 decl->set_next( 0 ); 46 } 47 this->decl = decl; 48 } 49 } 50 } 51 52 StatementNode::StatementNode(Type t, ExpressionNode *ctrl_label, StatementNode *block_ ) : 53 type(t), control(ctrl_label), block(block_), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) 54 { 55 if (t == Default) 56 control = 0; 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(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {} 37 38 StatementNode::StatementNode( string name_) : ParseNode( name_), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {} 39 40 StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), isCatchRest ( false ) { 41 if ( decl ) { 42 if ( DeclarationNode *agg = decl->extractAggregate() ) { 43 this->decl = agg; 44 StatementNode *nextStmt = new StatementNode; 45 nextStmt->type = Decl; 46 nextStmt->decl = decl; 47 next = nextStmt; 48 if ( decl->get_link() ) { 49 next->set_next( new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ) ); 50 decl->set_next( 0 ); 51 } 52 } else { 53 if ( decl->get_link() ) { 54 next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ); 55 decl->set_next( 0 ); 56 } 57 this->decl = decl; 58 } 59 } 60 } 61 62 StatementNode::StatementNode( Type t, ExpressionNode *ctrl_label, StatementNode *block_ ) : 63 type( t ), control( ctrl_label ), block( block_), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) { 64 if ( t == Default ) 65 control = 0; 57 66 } 58 67 59 StatementNode::StatementNode( Type t, string *_target) :60 type(t), control(0), block(0), labels( 0 ), target(_target), decl( 0 ), isCatchRest ( false ) {}61 62 StatementNode::~StatementNode( void){63 64 65 66 67 68 } 69 70 StatementNode * StatementNode::newCatchStmt( DeclarationNode *d, StatementNode *s, bool catchRestP ) {71 72 73 74 75 68 StatementNode::StatementNode( Type t, string *_target ) : 69 type( t ), control( 0 ), block( 0 ), labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {} 70 71 StatementNode::~StatementNode() { 72 delete control; 73 delete block; 74 delete labels; 75 delete target; 76 delete decl; 77 } 78 79 StatementNode * StatementNode::newCatchStmt( DeclarationNode *d, StatementNode *s, bool catchRestP ) { 80 StatementNode *ret = new StatementNode( StatementNode::Catch, 0, s ); 81 ret->addDeclaration( d ); 82 ret->setCatchRest( catchRestP ); 83 84 return ret; 76 85 } 77 86 78 87 std::string StatementNode::get_target() const{ 79 if(target) 80 return *target; 81 82 return string(""); 83 } 84 85 StatementNode * 86 StatementNode::clone() const 87 { 88 StatementNode *newnode = new StatementNode( type, maybeClone( control ), maybeClone( block ) ); 89 if( target ) { 90 newnode->target = new string( *target ); 91 } else { 92 newnode->target = 0; 93 } 94 newnode->decl = maybeClone( decl ); 95 return newnode; 96 } 97 98 void StatementNode::set_control(ExpressionNode *c){ 99 control = c; 100 } 101 102 StatementNode * StatementNode::set_block(StatementNode *b){ 103 block = b; 104 105 return this; 106 } 107 108 ExpressionNode *StatementNode::get_control(void) const { 109 return control; 110 } 111 112 StatementNode *StatementNode::get_block(void) const { 113 return block; 114 } 115 116 StatementNode::Type StatementNode::get_type(void) const { 117 return type; 118 } 119 120 StatementNode *StatementNode::add_label(std::string *l){ 121 if(l != 0){ 122 if(labels == 0) 123 labels = new std::list<std::string>(); 124 125 labels->push_front(*l); 126 delete l; 127 } 128 129 return this; 130 } 131 132 std::list<std::string> *StatementNode::get_labels() const 133 { return labels; } 134 135 StatementNode *StatementNode::add_controlexp(ExpressionNode *e){ 136 137 if(control && e) 138 control->add_to_list(e); // xxx - check this 139 140 return this; 141 } 142 143 StatementNode *StatementNode::append_block(StatementNode *stmt){ 144 if( stmt != 0) { 145 if( block == 0 ) 146 block = stmt; 147 else 148 block->set_link(stmt); 149 } 150 return this; 151 } 152 153 154 StatementNode *StatementNode::append_last_case(StatementNode *stmt){ 155 if( stmt != 0 ) { 156 StatementNode *next = (StatementNode *)get_link(); 157 if ( next && ( next->get_type() == StatementNode::Case || next->get_type() == StatementNode::Default) ) 158 next->append_last_case ( stmt ); 159 else 160 if( block == 0 ) 161 block = stmt; 162 else 163 block->set_link(stmt); 164 } 165 166 return this; 88 if ( target ) 89 return *target; 90 91 return string(""); 92 } 93 94 StatementNode * StatementNode::clone() const { 95 StatementNode *newnode = new StatementNode( type, maybeClone( control ), maybeClone( block ) ); 96 if ( target ) { 97 newnode->target = new string( *target ); 98 } else { 99 newnode->target = 0; 100 } 101 newnode->decl = maybeClone( decl ); 102 return newnode; 103 } 104 105 void StatementNode::set_control( ExpressionNode *c ) { 106 control = c; 107 } 108 109 StatementNode * StatementNode::set_block( StatementNode *b ) { 110 block = b; 111 112 return this; 113 } 114 115 ExpressionNode *StatementNode::get_control() const { 116 return control; 117 } 118 119 StatementNode *StatementNode::get_block() const { 120 return block; 121 } 122 123 StatementNode::Type StatementNode::get_type() const { 124 return type; 125 } 126 127 StatementNode *StatementNode::add_label( std::string *l ) { 128 if ( l != 0 ) { 129 if ( labels == 0 ) 130 labels = new std::list<std::string>(); 131 132 labels->push_front(*l ); 133 delete l; 134 } 135 return this; 136 } 137 138 std::list<std::string> *StatementNode::get_labels() const { return labels; } 139 140 StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) { 141 if ( control && e ) 142 control->add_to_list( e ); // xxx - check this 143 144 return this; 145 } 146 147 StatementNode *StatementNode::append_block( StatementNode *stmt ) { 148 if ( stmt != 0 ) { 149 if ( block == 0 ) 150 block = stmt; 151 else 152 block->set_link( stmt ); 153 } 154 return this; 155 } 156 157 StatementNode *StatementNode::append_last_case( StatementNode *stmt ) { 158 if ( stmt != 0 ) { 159 StatementNode *next = ( StatementNode *)get_link(); 160 if ( next && ( next->get_type() == StatementNode::Case || next->get_type() == StatementNode::Default ) ) 161 next->append_last_case ( stmt ); 162 else 163 if ( block == 0 ) 164 block = stmt; 165 else 166 block->set_link( stmt ); 167 } 168 return this; 167 169 } 168 170 169 171 void StatementNode::print( std::ostream &os, int indent ) const { 170 171 if(labels != 0) 172 if(!labels->empty()){ 173 std::list<std::string>::const_iterator i; 174 175 os << '\r' << string(indent, ' '); 176 for( i = labels->begin(); i != labels->end(); i++ ) 177 os << *i << ":"; 178 os << endl; 179 } 180 181 switch( type ) { 182 case Decl: 183 decl->print( os, indent ); 184 break; 185 186 case Exp: 187 if( control ) { 188 os << string( indent, ' ' ); 189 control->print( os, indent ); 190 os << endl; 191 } else 192 os << string( indent, ' ' ) << "Null Statement" << endl; 193 break; 194 195 default: 196 os << '\r' << string(indent, ' ') << StatementNode::StType[type] << endl; 197 198 if ( type == Catch ) { 199 if( decl ){ 200 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl; 201 decl->print( os, indent + 2*ParseNode::indent_by); 202 } else if ( isCatchRest ) { 203 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl; 204 } else { 205 ; // should never reach here 206 } 207 } 208 209 if( control ){ 210 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl; 211 control->printList( os, indent + 2*ParseNode::indent_by); 212 } 213 214 if( block ){ 215 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl; 216 block->printList( os, indent + 2*ParseNode::indent_by); 217 } 218 219 if( target ){ 220 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl; 221 } 222 223 break; 224 } 172 if ( labels != 0 ) 173 if (!labels->empty()) { 174 std::list<std::string>::const_iterator i; 175 176 os << '\r' << string( indent, ' '); 177 for( i = labels->begin(); i != labels->end(); i++ ) 178 os << *i << ":"; 179 os << endl; 180 } 181 182 switch( type ) { 183 case Decl: 184 decl->print( os, indent ); 185 break; 186 case Exp: 187 if ( control ) { 188 os << string( indent, ' ' ); 189 control->print( os, indent ); 190 os << endl; 191 } else 192 os << string( indent, ' ' ) << "Null Statement" << endl; 193 break; 194 default: 195 os << '\r' << string( indent, ' ') << StatementNode::StType[type] << endl; 196 if ( type == Catch ) { 197 if ( decl ) { 198 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl; 199 decl->print( os, indent + 2*ParseNode::indent_by ); 200 } else if ( isCatchRest ) { 201 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl; 202 } else { 203 ; // should never reach here 204 } 205 } 206 if ( control ) { 207 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl; 208 control->printList( os, indent + 2*ParseNode::indent_by ); 209 } 210 if ( block ) { 211 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl; 212 block->printList( os, indent + 2*ParseNode::indent_by ); 213 } 214 if ( target ) { 215 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl; 216 } 217 break; 218 } 225 219 } 226 220 227 221 Statement *StatementNode::build() const { 228 229 std::list<Statement *> branches; 230 std::list<Expression *> exps; 231 std::list<Label> labs; 232 233 if(labels != 0){ 234 std::back_insert_iterator< std::list<Label> > lab_it(labs); 235 copy(labels->begin(), labels->end(), lab_it); 236 } 237 238 // try { 239 buildList<Statement, StatementNode>(get_block(), branches); 240 241 switch( type ) { 242 case Decl: 243 return new DeclStmt( labs, maybeBuild< Declaration >( decl ) ); 244 245 case Exp: 246 { 247 Expression *e = maybeBuild< Expression >( get_control() ); 248 249 if(e) 250 return new ExprStmt( labs, e ); 251 else 252 return new NullStmt( labs ); 253 } 254 255 case If: 256 { 257 Statement *thenb = 0, *elseb = 0; 258 259 assert( branches.size() >= 1 ); 260 261 thenb = branches.front(); branches.pop_front(); 262 if(!branches.empty()) 263 { elseb = branches.front(); branches.pop_front(); } 264 265 return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb); 266 } 267 268 case While: 269 assert(branches.size() == 1); 270 return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front() ); 271 272 case Do: 273 assert(branches.size() == 1); 274 return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front(), true ); 275 276 case For: 277 { 278 assert(branches.size() == 1); 279 280 ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>(get_control()); 281 assert(ctl != 0); 282 283 Statement *stmt = 0; 284 if(ctl->get_init() != 0) 285 stmt = ctl->get_init()->build(); 286 287 Expression *cond = 0; 288 if(ctl->get_condition() != 0) 289 cond = notZeroExpr( ctl->get_condition()->build() ); 290 291 Expression *incr = 0; 292 if(ctl->get_change() != 0) 293 incr = ctl->get_change()->build(); 294 295 return new ForStmt( labs, stmt, cond, incr, branches.front() ); 296 } 297 298 case Switch: 299 // try{ 300 return new SwitchStmt( labs, get_control()->build(), branches ); 301 302 case Choose: 303 return new ChooseStmt( labs, get_control()->build(), branches ); 304 305 case Fallthru: 306 return new FallthruStmt( labs ); 307 308 case Case: 309 return new CaseStmt( labs, get_control()->build(), branches); 310 311 case Default: 312 return new CaseStmt( labs, 0, branches, true); 313 314 case Goto: 315 { 316 if (get_target() == "") { // computed goto 317 assert( get_control() != 0 ); 318 return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto ); 319 } 320 321 return new BranchStmt( labs, get_target(), BranchStmt::Goto); 322 } 323 324 case Break: 325 return new BranchStmt( labs, get_target(), BranchStmt::Break); 326 327 case Continue: 328 return new BranchStmt( labs, get_target(), BranchStmt::Continue); 329 330 case Return: 331 case Throw : 332 buildList( get_control(), exps ); 333 if( exps.size() ==0 ) 334 return new ReturnStmt( labs, 0, type == Throw ); 335 if( exps.size() > 0 ) 336 return new ReturnStmt( labs, exps.back(), type == Throw ); 337 338 case Try: 339 { 340 assert( branches.size() >= 0 ); 341 CompoundStmt *tryBlock = dynamic_cast<CompoundStmt *>(branches.front()); 342 branches.pop_front(); 343 FinallyStmt *finallyBlock = 0; 344 if( (finallyBlock = dynamic_cast<FinallyStmt *>(branches.back())) ) { 345 branches.pop_back(); 346 } 347 return new TryStmt( labs, tryBlock, branches, finallyBlock ); 348 } 349 350 case Catch: 351 { 352 assert( branches.size() == 1 ); 353 354 return new CatchStmt( labs, maybeBuild< Declaration >( decl ), branches.front(), isCatchRest ); 355 } 356 357 case Finally: 358 { 359 assert( branches.size() == 1 ); 360 CompoundStmt *block = dynamic_cast<CompoundStmt *>( branches.front() ); 361 assert( block != 0 ); 362 363 return new FinallyStmt( labs, block ); 364 } 365 366 default: 367 // shouldn't be here 368 return 0; 369 } 370 371 // shouldn't be here 372 } 373 374 CompoundStmtNode::CompoundStmtNode(void) 375 : first( 0 ), last( 0 ) 376 { 377 } 378 379 CompoundStmtNode::CompoundStmtNode(string *name_) 380 : StatementNode(*name_), first( 0 ), last( 0 ) 381 { 382 } 383 384 CompoundStmtNode::CompoundStmtNode(StatementNode *stmt): first(stmt) 385 { 386 if( first ) { 387 last = (StatementNode *)(stmt->get_last()); 388 } else { 389 last = 0; 390 } 391 } 392 393 CompoundStmtNode::~CompoundStmtNode() 394 { 395 delete first; 396 } 397 398 void CompoundStmtNode::add_statement(StatementNode *stmt) { 399 if(stmt != 0){ 400 last->set_link(stmt); 401 last = (StatementNode *)(stmt->get_link()); 402 } 403 } 404 405 void CompoundStmtNode::print(ostream &os, int indent) const { 406 if( first ) { 407 first->printList( os, indent+2 ); 408 } 222 std::list<Statement *> branches; 223 std::list<Expression *> exps; 224 std::list<Label> labs; 225 226 if ( labels != 0 ) { 227 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 228 copy( labels->begin(), labels->end(), lab_it ); 229 } 230 231 // try { 232 buildList<Statement, StatementNode>( get_block(), branches ); 233 234 switch( type ) { 235 case Decl: 236 return new DeclStmt( labs, maybeBuild< Declaration >( decl ) ); 237 case Exp: 238 { 239 Expression *e = maybeBuild< Expression >( get_control() ); 240 241 if ( e ) 242 return new ExprStmt( labs, e ); 243 else 244 return new NullStmt( labs ); 245 } 246 case If: 247 { 248 Statement *thenb = 0, *elseb = 0; 249 assert( branches.size() >= 1 ); 250 251 thenb = branches.front(); 252 branches.pop_front(); 253 if ( !branches.empty() ) { 254 elseb = branches.front(); 255 branches.pop_front(); 256 } 257 return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb ); 258 } 259 case While: 260 assert( branches.size() == 1 ); 261 return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front() ); 262 case Do: 263 assert( branches.size() == 1 ); 264 return new WhileStmt( labs, notZeroExpr( get_control()->build() ), branches.front(), true ); 265 case For: 266 { 267 assert( branches.size() == 1 ); 268 269 ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>( get_control() ); 270 assert( ctl != 0 ); 271 272 Statement *stmt = 0; 273 if ( ctl->get_init() != 0 ) 274 stmt = ctl->get_init()->build(); 275 276 Expression *cond = 0; 277 if ( ctl->get_condition() != 0 ) 278 cond = notZeroExpr( ctl->get_condition()->build() ); 279 280 Expression *incr = 0; 281 if ( ctl->get_change() != 0 ) 282 incr = ctl->get_change()->build(); 283 284 return new ForStmt( labs, stmt, cond, incr, branches.front() ); 285 } 286 case Switch: 287 return new SwitchStmt( labs, get_control()->build(), branches ); 288 case Choose: 289 return new ChooseStmt( labs, get_control()->build(), branches ); 290 case Fallthru: 291 return new FallthruStmt( labs ); 292 case Case: 293 return new CaseStmt( labs, get_control()->build(), branches ); 294 case Default: 295 return new CaseStmt( labs, 0, branches, true ); 296 case Goto: 297 { 298 if ( get_target() == "" ) { // computed goto 299 assert( get_control() != 0 ); 300 return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto ); 301 } 302 303 return new BranchStmt( labs, get_target(), BranchStmt::Goto ); 304 } 305 case Break: 306 return new BranchStmt( labs, get_target(), BranchStmt::Break ); 307 case Continue: 308 return new BranchStmt( labs, get_target(), BranchStmt::Continue ); 309 case Return: 310 case Throw : 311 buildList( get_control(), exps ); 312 if ( exps.size() ==0 ) 313 return new ReturnStmt( labs, 0, type == Throw ); 314 if ( exps.size() > 0 ) 315 return new ReturnStmt( labs, exps.back(), type == Throw ); 316 case Try: 317 { 318 assert( branches.size() >= 0 ); 319 CompoundStmt *tryBlock = dynamic_cast<CompoundStmt *>( branches.front()); 320 branches.pop_front(); 321 FinallyStmt *finallyBlock = 0; 322 if ( ( finallyBlock = dynamic_cast<FinallyStmt *>( branches.back())) ) { 323 branches.pop_back(); 324 } 325 return new TryStmt( labs, tryBlock, branches, finallyBlock ); 326 } 327 case Catch: 328 { 329 assert( branches.size() == 1 ); 330 331 return new CatchStmt( labs, maybeBuild< Declaration >( decl ), branches.front(), isCatchRest ); 332 } 333 case Finally: 334 { 335 assert( branches.size() == 1 ); 336 CompoundStmt *block = dynamic_cast<CompoundStmt *>( branches.front() ); 337 assert( block != 0 ); 338 339 return new FinallyStmt( labs, block ); 340 } 341 default: 342 // shouldn't be here 343 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 ) { 354 if ( first ) { 355 last = ( StatementNode *)( stmt->get_last()); 356 } else { 357 last = 0; 358 } 359 } 360 361 CompoundStmtNode::~CompoundStmtNode() { 362 delete first; 363 } 364 365 void CompoundStmtNode::add_statement( StatementNode *stmt ) { 366 if ( stmt != 0 ) { 367 last->set_link( stmt ); 368 last = ( StatementNode *)( stmt->get_link()); 369 } 370 } 371 372 void CompoundStmtNode::print( ostream &os, int indent ) const { 373 if ( first ) { 374 first->printList( os, indent+2 ); 375 } 409 376 } 410 377 411 378 Statement *CompoundStmtNode::build() const { 412 413 std::list<Label> labs; 414 std::list<std::string> *labels = get_labels(); 415 416 if(labels != 0){ 417 std::back_insert_iterator< std::list<Label> > lab_it(labs); 418 copy(labels->begin(), labels->end(), lab_it); 419 } 420 421 CompoundStmt *cs = new CompoundStmt( labs ); 422 buildList( first, cs->get_kids() ); 423 return cs; 424 } 425 426 void NullStmtNode::print(ostream &os, int indent) const { 427 os << "\r" << string(indent, ' ') << "Null Statement:" << endl; 379 std::list<Label> labs; 380 std::list<std::string> *labels = get_labels(); 381 382 if ( labels != 0 ) { 383 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 384 copy( labels->begin(), labels->end(), lab_it ); 385 } 386 387 CompoundStmt *cs = new CompoundStmt( labs ); 388 buildList( first, cs->get_kids() ); 389 return cs; 390 } 391 392 void NullStmtNode::print( ostream &os, int indent ) const { 393 os << "\r" << string( indent, ' ') << "Null Statement:" << endl; 428 394 } 429 395 430 396 Statement *NullStmtNode::build() const { 431 397 return new NullStmt; 432 398 } 433 399 434 400 // Local Variables: // 435 // mode: C++ // 436 // compile-command: "gmake -f ../Makefile" // 401 // tab-width: 4 // 402 // mode: c++ // 403 // compile-command: "make install" // 437 404 // End: //
Note: See TracChangeset
for help on using the changeset viewer.