Changes in src/SynTree/Statement.cc [7f5566b:8688ce1]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Statement.cc
r7f5566b r8688ce1 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Statement.cc -- 7 // Statement.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 25 12:19:50 201513 // Update Count : 5312 // Last Modified On : Thu Aug 4 11:25:20 2016 13 // Update Count : 61 14 14 // 15 15 … … 36 36 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {} 37 37 38 ExprStmt::~ExprStmt() {} 38 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 39 40 ExprStmt::~ExprStmt() { 41 delete expr; 42 } 39 43 40 44 void ExprStmt::print( std::ostream &os, int indent ) const { 41 os << string( indent, ' ' ) << "Expression Statement:" << endl;45 os << "Expression Statement:" << endl << std::string( indent + 2, ' ' ); 42 46 expr->print( os, indent + 2 ); 43 } 47 } 44 48 45 49 46 50 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {} 51 52 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { 53 cloneAll( other.output, output ); 54 cloneAll( other.input, input ); 55 cloneAll( other.clobber, clobber ); 56 } 47 57 48 58 AsmStmt::~AsmStmt() { … … 60 70 os << endl << std::string( indent, ' ' ) << "output: " << endl; 61 71 printAll( output, os, indent + 2 ); 62 } // if 72 } // if 63 73 if ( ! input.empty() ) { 64 74 os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' ); … … 69 79 printAll( clobber, os, indent + 2 ); 70 80 } // if 71 } 81 } 72 82 73 83 … … 77 87 Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) { 78 88 //actually this is a syntactic error signaled by the parser 79 if ( type == BranchStmt::Goto && target. size() == 0)89 if ( type == BranchStmt::Goto && target.empty() ) 80 90 throw SemanticError("goto without target"); 81 91 } … … 93 103 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {} 94 104 105 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ), isThrow( other.isThrow ) {} 106 95 107 ReturnStmt::~ReturnStmt() { 96 108 delete expr; … … 98 110 99 111 void ReturnStmt::print( std::ostream &os, int indent ) const { 100 os << std::string( indent, ' ' ) << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 101 if ( expr != 0 ) expr->print( os ); 112 os << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 113 if ( expr != 0 ) { 114 os << endl << string( indent+2, ' ' ); 115 expr->print( os, indent + 2 ); 116 } 102 117 os << endl; 103 118 } … … 106 121 Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {} 107 122 123 IfStmt::IfStmt( const IfStmt & other ) : 124 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {} 125 108 126 IfStmt::~IfStmt() {} 109 127 110 128 void IfStmt::print( std::ostream &os, int indent ) const { 111 os << string( indent, ' ' ) << "If on condition: " << endl ; 129 os << "If on condition: " << endl ; 130 os << string( indent+4, ' ' ); 112 131 condition->print( os, indent + 4 ); 113 132 114 os << string( indent, ' ' ) << ".... and branches: " << endl; 115 133 os << string( indent+2, ' ' ) << "... then: " << endl; 134 135 os << string( indent+4, ' ' ); 116 136 thenPart->print( os, indent + 4 ); 117 137 118 138 if ( elsePart != 0 ) { 139 os << string( indent+2, ' ' ) << "... else: " << endl; 140 os << string( indent+4, ' ' ); 119 141 elsePart->print( os, indent + 4 ); 120 142 } // if 121 143 } 122 144 123 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): 124 Statement( _labels ), condition( _condition ), branches( _branches ) { 145 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ): 146 Statement( _labels ), condition( _condition ), statements( _statements ) { 147 } 148 149 SwitchStmt::SwitchStmt( const SwitchStmt & other ): 150 Statement( other ), condition( maybeClone( other.condition ) ) { 151 cloneAll( other.statements, statements ); 125 152 } 126 153 127 154 SwitchStmt::~SwitchStmt() { 128 155 delete condition; 129 // destroy branches 130 } 131 132 void SwitchStmt::add_case( CaseStmt *c ) {} 156 // destroy statements 157 } 133 158 134 159 void SwitchStmt::print( std::ostream &os, int indent ) const { 135 os << string( indent, ' ' ) <<"Switch on condition: ";160 os << "Switch on condition: "; 136 161 condition->print( os ); 137 162 os << endl; 138 163 139 // branches164 // statements 140 165 std::list<Statement *>::const_iterator i; 141 for ( i = branches.begin(); i != branches.end(); i++)166 for ( i = statements.begin(); i != statements.end(); i++) 142 167 (*i)->print( os, indent + 4 ); 143 168 144 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));145 } 146 147 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 169 //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os )); 170 } 171 172 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 148 173 Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) { 149 174 if ( isDefault() && condition != 0 ) … … 151 176 } 152 177 178 CaseStmt::CaseStmt( const CaseStmt & other ) : 179 Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { 180 cloneAll( other.stmts, stmts ); 181 } 182 153 183 CaseStmt::~CaseStmt() { 154 184 delete condition; 155 185 } 156 186 157 CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) {158 return new CaseStmt( labels, 0, branches, true );187 CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) { 188 return new CaseStmt( labels, 0, stmts, true ); 159 189 } 160 190 … … 176 206 } 177 207 178 //ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {}179 ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):180 Statement( _labels ), condition( _condition ), branches( _branches ) {181 }182 183 ChooseStmt::~ChooseStmt() {184 delete condition;185 }186 187 void ChooseStmt::add_case( CaseStmt *c ) {}188 189 void ChooseStmt::print( std::ostream &os, int indent ) const {190 os << string( indent, ' ' ) << "Choose on condition: ";191 condition->print( os );192 os << endl;193 194 // branches195 std::list<Statement *>::const_iterator i;196 for ( i = branches.begin(); i != branches.end(); i++)197 (*i )->print( os, indent + 4 );198 199 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));200 }201 202 void FallthruStmt::print( std::ostream &os, int indent ) const {203 os << string( indent, ' ' ) << "Fall-through statement" << endl;204 }205 206 208 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): 207 209 Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { 208 210 } 209 211 212 WhileStmt::WhileStmt( const WhileStmt & other ): 213 Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { 214 } 215 210 216 WhileStmt::~WhileStmt() { 211 217 delete body; … … 213 219 214 220 void WhileStmt::print( std::ostream &os, int indent ) const { 215 os << string( indent, ' ' ) <<"While on condition: " << endl ;221 os << "While on condition: " << endl ; 216 222 condition->print( os, indent + 4 ); 217 223 … … 223 229 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): 224 230 Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { 231 } 232 233 ForStmt::ForStmt( const ForStmt & other ): 234 Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) { 235 cloneAll( other.initialization, initialization ); 236 225 237 } 226 238 … … 233 245 234 246 void ForStmt::print( std::ostream &os, int indent ) const { 235 os << string( indent, ' ' ) <<"Labels: {";247 os << "Labels: {"; 236 248 for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { 237 249 os << *it << ","; … … 241 253 os << string( indent, ' ' ) << "For Statement" << endl ; 242 254 243 os << string( indent + 2, ' ' ) << "initialization: \n"; 255 os << string( indent + 2, ' ' ) << "initialization: \n"; 244 256 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { 257 os << string( indent + 4, ' ' ); 245 258 (*it)->print( os, indent + 4 ); 246 259 } 247 260 248 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 249 if ( condition != 0 ) 261 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 262 if ( condition != 0 ) { 263 os << string( indent + 4, ' ' ); 250 264 condition->print( os, indent + 4 ); 251 252 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 253 if ( increment != 0 ) 265 } 266 267 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 268 if ( increment != 0 ) { 269 os << string( indent + 4, ' ' ); 254 270 increment->print( os, indent + 4 ); 255 256 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 257 if ( body != 0 ) 271 } 272 273 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 274 if ( body != 0 ) { 275 os << string( indent + 4, ' ' ); 258 276 body->print( os, indent + 4 ); 277 } 259 278 260 279 os << endl; … … 265 284 } 266 285 267 TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) { 268 block = other.block; 269 std::copy( other.handlers.begin(), other.handlers.end(), back_inserter( handlers ) ); 270 finallyBlock = other.finallyBlock; 286 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { 287 cloneAll( other.handlers, handlers ); 271 288 } 272 289 … … 276 293 277 294 void TryStmt::print( std::ostream &os, int indent ) const { 278 os << string( indent, ' ' ) <<"Try Statement" << endl;295 os << "Try Statement" << endl; 279 296 os << string( indent + 2, ' ' ) << "with block: " << endl; 280 297 block->print( os, indent + 4 ); … … 296 313 } 297 314 315 CatchStmt::CatchStmt( const CatchStmt & other ) : 316 Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) { 317 } 318 298 319 CatchStmt::~CatchStmt() { 299 320 delete decl; … … 302 323 303 324 void CatchStmt::print( std::ostream &os, int indent ) const { 304 os << string( indent, ' ' ) <<"Catch Statement" << endl;325 os << "Catch Statement" << endl; 305 326 306 327 os << string( indent, ' ' ) << "... catching" << endl; … … 319 340 } 320 341 342 FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { 343 } 344 321 345 FinallyStmt::~FinallyStmt() { 322 346 delete block; … … 324 348 325 349 void FinallyStmt::print( std::ostream &os, int indent ) const { 326 os << string( indent, ' ' ) <<"Finally Statement" << endl;350 os << "Finally Statement" << endl; 327 351 os << string( indent + 2, ' ' ) << "with block: " << endl; 328 352 block->print( os, indent + 4 ); … … 331 355 NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {} 332 356 NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {} 333 NullStmt::~NullStmt() {}334 357 335 358 void NullStmt::print( std::ostream &os, int indent ) const { 336 os << string( indent, ' ' ) << "Null Statement" << endl ; 359 os << "Null Statement" << endl ; 360 } 361 362 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { 363 assert( callStmt ); 364 } 365 366 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { 367 } 368 369 ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { 370 delete callStmt; 371 } 372 373 void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const { 374 os << "Implicit Ctor Dtor Statement" << endl; 375 os << string( indent + 2, ' ' ) << "with Ctor/Dtor: "; 376 callStmt->print( os, indent + 2); 377 os << endl; 378 } 379 380 std::ostream & operator<<( std::ostream & out, Statement * statement ) { 381 statement->print( out ); 382 return out; 337 383 } 338 384
Note:
See TracChangeset
for help on using the changeset viewer.