Changes in src/Parser/StatementNode.cc [7f5566b:145f1fc]
- File:
-
- 1 edited
-
src/Parser/StatementNode.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cc
r7f5566b r145f1fc 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 14:59:41 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Jul 30 14:39:39201513 // Update Count : 13011 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:20:44 2015 13 // Update Count : 21 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( const 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 ) { … … 60 60 } 61 61 62 StatementNode::StatementNode( Type t, ExpressionNode *ctrl_label, StatementNode *block ) : type( t ), control( ctrl_label ), block( block ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) { 63 this->control = ( t == Default ) ? 0 : control; 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; 64 66 } 65 67 66 StatementNode::StatementNode( Type t, string *target ) : type( t ), control( 0 ), block( 0 ), labels( 0 ), target( target ), decl( 0 ), isCatchRest ( false ) {} 68 StatementNode::StatementNode( Type t, string *_target ) : 69 type( t ), control( 0 ), block( 0 ), labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {} 67 70 68 71 StatementNode::~StatementNode() { 69 72 delete control; 70 73 delete block; 74 delete labels; 71 75 delete target; 72 76 delete decl; … … 99 103 } 100 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 101 127 StatementNode *StatementNode::add_label( const std::string *l ) { 102 128 if ( l != 0 ) { 103 labels.push_front( *l ); 129 if ( labels == 0 ) 130 labels = new std::list<std::string>(); 131 132 labels->push_front(*l ); 104 133 delete l; 105 134 } // if 106 135 return this; 107 136 } 137 138 std::list<std::string> *StatementNode::get_labels() const { return labels; } 108 139 109 140 StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) { 110 141 if ( control && e ) 111 142 control->add_to_list( e ); // xxx - check this 143 112 144 return this; 113 145 } … … 138 170 139 171 void StatementNode::print( std::ostream &os, int indent ) const { 140 if ( ! labels.empty() ) { 141 std::list<std::string>::const_iterator i; 142 143 os << string( indent, ' ' ); 144 for ( i = labels.begin(); i != labels.end(); i++ ) 145 os << *i << ":"; 146 os << endl; 172 if ( labels != 0 ) { 173 if ( ! labels->empty()) { 174 std::list<std::string>::const_iterator i; 175 176 os << string( indent, ' ' ); 177 for ( i = labels->begin(); i != labels->end(); i++ ) 178 os << *i << ":"; 179 os << endl; 180 } // if 147 181 } // if 148 182 … … 164 198 if ( decl ) { 165 199 os << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl; 166 decl->print( os, indent + 2 *ParseNode::indent_by );200 decl->print( os, indent + 2*ParseNode::indent_by ); 167 201 } else if ( isCatchRest ) { 168 202 os << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl; … … 172 206 } // if 173 207 if ( control ) { 174 os << string( indent + ParseNode::indent_by, ' ' ) << " Control: " << endl;175 control->printList( os, indent + 2 *ParseNode::indent_by );208 os << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl; 209 control->printList( os, indent + 2*ParseNode::indent_by ); 176 210 } // if 177 211 if ( block ) { 178 212 os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl; 179 block->printList( os, indent + 2 *ParseNode::indent_by );213 block->printList( os, indent + 2*ParseNode::indent_by ); 180 214 } // if 181 215 if ( target ) { … … 191 225 std::list<Label> labs; 192 226 193 if ( ! labels.empty()) {227 if ( labels != 0 ) { 194 228 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 195 copy( labels .begin(), labels.end(), lab_it );229 copy( labels->begin(), labels->end(), lab_it ); 196 230 } // if 197 231 … … 240 274 if ( ctl->get_init() != 0 ) { 241 275 buildList( ctl->get_init(), init ); 242 } // if276 } 243 277 244 278 Expression *cond = 0; … … 307 341 return new FinallyStmt( labs, block ); 308 342 } 309 case Asm:310 assert( false );311 343 default: 312 344 // shouldn't be here … … 314 346 } // switch 315 347 } 316 317 348 318 349 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {} … … 347 378 Statement *CompoundStmtNode::build() const { 348 379 std::list<Label> labs; 349 const std::list<std::string> &labels = get_labels();350 351 if ( ! labels.empty()) {380 std::list<std::string> *labels = get_labels(); 381 382 if ( labels != 0 ) { 352 383 std::back_insert_iterator< std::list<Label> > lab_it( labs ); 353 copy( labels .begin(), labels.end(), lab_it );384 copy( labels->begin(), labels->end(), lab_it ); 354 385 } // if 355 386 … … 358 389 return cs; 359 390 } 360 361 362 AsmStmtNode::AsmStmtNode( Type t, bool voltile, ConstantNode *instruction, ExpressionNode *output, ExpressionNode *input, ConstantNode *clobber, LabelNode *gotolabels ) :363 StatementNode( t ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ) {364 if ( gotolabels ) {365 this->gotolabels = gotolabels->get_labels();366 delete gotolabels;367 } // if368 }369 370 AsmStmtNode::~AsmStmtNode() {371 delete instruction; delete output; delete input; delete clobber;372 }373 374 void AsmStmtNode::print( std::ostream &os, int indent ) const {375 StatementNode::print( os, indent ); // print statement labels376 os << string( indent + ParseNode::indent_by, ' ' ) << "volatile:" << voltile << endl;377 if ( instruction ) {378 os << string( indent + ParseNode::indent_by, ' ' ) << "Instruction:" << endl;379 instruction->printList( os, indent + 2 * ParseNode::indent_by );380 } // if381 if ( output ) {382 os << string( indent + ParseNode::indent_by, ' ' ) << "Output:" << endl;383 output->printList( os, indent + 2 * ParseNode::indent_by );384 } // if385 if ( input ) {386 os << string( indent + ParseNode::indent_by, ' ' ) << "Input:" << endl;387 input->printList( os, indent + 2 * ParseNode::indent_by );388 } // if389 if ( clobber ) {390 os << string( indent + ParseNode::indent_by, ' ' ) << "Clobber:" << endl;391 clobber->printList( os, indent + 2 * ParseNode::indent_by );392 } // if393 if ( ! gotolabels.empty() ) {394 os << string( indent + ParseNode::indent_by, ' ' ) << "Goto Labels:" << endl;395 os << string( indent + 2 * ParseNode::indent_by, ' ' );396 for ( std::list<std::string>::const_iterator i = gotolabels.begin();; ) {397 os << *i;398 i++;399 if ( i == gotolabels.end() ) break;400 os << ", ";401 }402 os << endl;403 } // if404 }405 406 Statement *AsmStmtNode::build() const {407 std::list<Label> labs;408 409 if ( ! get_labels().empty() ) {410 std::back_insert_iterator< std::list<Label> > lab_it( labs );411 copy( get_labels().begin(), get_labels().end(), lab_it );412 } // if413 414 std::list< Expression * > out, in;415 std::list< ConstantExpr * > clob;416 buildList( output, out );417 buildList( input, in );418 buildList( clobber, clob );419 std::list< Label > gotolabs = gotolabels;420 return new AsmStmt( labs, voltile, (ConstantExpr *)maybeBuild< Expression >( instruction ), out, in, clob, gotolabs );421 }422 423 391 424 392 void NullStmtNode::print( ostream &os, int indent ) const {
Note:
See TracChangeset
for help on using the changeset viewer.