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