Changes in src/SynTree/Statement.cc [843054c2:de62360d]
- File:
-
- 1 edited
-
src/SynTree/Statement.cc (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Statement.cc
r843054c2 rde62360d 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:55:19 201513 // Update Count : 2 12 // Last Modified On : Tue Jun 23 11:42:09 2015 13 // Update Count : 21 14 14 // 15 15 … … 30 30 Statement::Statement( std::list<Label> _labels ) : labels(_labels ) {} 31 31 32 void Statement::print( std::ostream &, int indent ) {}32 void Statement::print( std::ostream &, int indent ) const {} 33 33 34 34 Statement::~Statement() {} … … 38 38 ExprStmt::~ExprStmt() {} 39 39 40 void ExprStmt::print( std::ostream &os, int indent ) {41 os << "\r" << string(indent, ' ') << "Expression Statement:" << endl;40 void ExprStmt::print( std::ostream &os, int indent ) const { 41 os << string( indent, ' ' ) << "Expression Statement:" << endl; 42 42 expr->print( os, indent + 2 ); 43 43 } … … 46 46 47 47 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) : 48 Statement( labels ), target(_target ), type(_type ) {48 Statement( labels ), originalTarget(_target ), target(_target ), type(_type ) { 49 49 //actually this is a syntactic error signaled by the parser 50 50 if ( type == BranchStmt::Goto && target.size() == 0 ) … … 58 58 } 59 59 60 void BranchStmt::print( std::ostream &os, int indent ) {61 os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ;60 void BranchStmt::print( std::ostream &os, int indent ) const { 61 os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ; 62 62 } 63 63 … … 68 68 } 69 69 70 void ReturnStmt::print( std::ostream &os, int indent ) {71 os << "\r" << std::string( indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";70 void ReturnStmt::print( std::ostream &os, int indent ) const { 71 os << std::string( indent, ' ' ) << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 72 72 if ( expr != 0 ) expr->print( os ); 73 73 os << endl; … … 79 79 IfStmt::~IfStmt() {} 80 80 81 void IfStmt::print( std::ostream &os, int indent ) {82 os << "\r" << string( indent, ' ') << "If on condition: " << endl ;81 void IfStmt::print( std::ostream &os, int indent ) const { 82 os << string( indent, ' ' ) << "If on condition: " << endl ; 83 83 condition->print( os, indent + 4 ); 84 84 85 os << string( indent, ' ' ) << ".... and branches: " << endl;85 os << string( indent, ' ' ) << ".... and branches: " << endl; 86 86 87 87 thenPart->print( os, indent + 4 ); … … 103 103 void SwitchStmt::add_case( CaseStmt *c ) {} 104 104 105 void SwitchStmt::print( std::ostream &os, int indent ) {106 os << "\r" << string( indent, ' ') << "Switch on condition: ";105 void SwitchStmt::print( std::ostream &os, int indent ) const { 106 os << string( indent, ' ' ) << "Switch on condition: "; 107 107 condition->print( os ); 108 108 os << endl; 109 109 110 110 // branches 111 std::list<Statement *>:: iterator i;111 std::list<Statement *>::const_iterator i; 112 112 for ( i = branches.begin(); i != branches.end(); i++) 113 (*i )->print( os, indent + 4 );113 (*i)->print( os, indent + 4 ); 114 114 115 115 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); … … 126 126 } 127 127 128 void CaseStmt::print( std::ostream &os, int indent ) { 129 os << "\r" << string( indent, ' '); 130 131 if ( isDefault()) 128 CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) { 129 return new CaseStmt( labels, 0, branches, true ); 130 } 131 132 void CaseStmt::print( std::ostream &os, int indent ) const { 133 os << string( indent, ' ' ); 134 135 if ( isDefault() ) 132 136 os << "Default "; 133 137 else { … … 138 142 os << endl; 139 143 140 std::list<Statement *>:: iterator i;144 std::list<Statement *>::const_iterator i; 141 145 for ( i = stmts.begin(); i != stmts.end(); i++) 142 146 (*i )->print( os, indent + 4 ); … … 154 158 void ChooseStmt::add_case( CaseStmt *c ) {} 155 159 156 void ChooseStmt::print( std::ostream &os, int indent ) {157 os << "\r" << string( indent, ' ') << "Choose on condition: ";160 void ChooseStmt::print( std::ostream &os, int indent ) const { 161 os << string( indent, ' ' ) << "Choose on condition: "; 158 162 condition->print( os ); 159 163 os << endl; 160 164 161 165 // branches 162 std::list<Statement *>:: iterator i;166 std::list<Statement *>::const_iterator i; 163 167 for ( i = branches.begin(); i != branches.end(); i++) 164 168 (*i )->print( os, indent + 4 ); … … 167 171 } 168 172 169 void FallthruStmt::print( std::ostream &os, int indent ) {170 os << "\r" << string( indent, ' ') << "Fall-through statement" << endl;173 void FallthruStmt::print( std::ostream &os, int indent ) const { 174 os << string( indent, ' ' ) << "Fall-through statement" << endl; 171 175 } 172 176 … … 179 183 } 180 184 181 void WhileStmt::print( std::ostream &os, int indent ) {182 os << "\r" << string( indent, ' ') << "While on condition: " << endl ;185 void WhileStmt::print( std::ostream &os, int indent ) const { 186 os << string( indent, ' ' ) << "While on condition: " << endl ; 183 187 condition->print( os, indent + 4 ); 184 188 185 os << string( indent, ' ' ) << ".... with body: " << endl;189 os << string( indent, ' ' ) << ".... with body: " << endl; 186 190 187 191 if ( body != 0 ) body->print( os, indent + 4 ); … … 199 203 } 200 204 201 void ForStmt::print( std::ostream &os, int indent ) { 202 os << "\r" << string( indent, ' ') << "For Statement" << endl ; 203 204 os << "\r" << string( indent + 2, ' ') << "initialization: \n"; 205 void ForStmt::print( std::ostream &os, int indent ) const { 206 os << string( indent, ' ' ) << "Labels: {"; 207 for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { 208 os << *it << ","; 209 } 210 os << "}" << endl; 211 212 os << string( indent, ' ' ) << "For Statement" << endl ; 213 214 os << string( indent + 2, ' ' ) << "initialization: \n"; 205 215 if ( initialization != 0 ) 206 216 initialization->print( os, indent + 4 ); 207 217 208 os << "\n \r" << string( indent + 2, ' ') << "condition: \n";218 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 209 219 if ( condition != 0 ) 210 220 condition->print( os, indent + 4 ); 211 221 212 os << "\n \r" << string( indent + 2, ' ') << "increment: \n";222 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 213 223 if ( increment != 0 ) 214 224 increment->print( os, indent + 4 ); 215 225 216 os << "\n \r" << string( indent + 2, ' ') << "statement block: \n";226 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 217 227 if ( body != 0 ) 218 228 body->print( os, indent + 4 ); … … 235 245 } 236 246 237 void TryStmt::print( std::ostream &os, int indent ) {238 os << "\r" << string( indent, ' ') << "Try Statement" << endl;239 os << string( indent + 2, ' ' ) << "with block: " << endl;247 void TryStmt::print( std::ostream &os, int indent ) const { 248 os << string( indent, ' ' ) << "Try Statement" << endl; 249 os << string( indent + 2, ' ' ) << "with block: " << endl; 240 250 block->print( os, indent + 4 ); 241 251 242 252 // handlers 243 os << string( indent + 2, ' ') << "and handlers: " << endl; 244 std::list<Statement *>::iterator i; 245 for ( i = handlers.begin(); i != handlers.end(); i++) 253 os << string( indent + 2, ' ' ) << "and handlers: " << endl; 254 for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) 246 255 (*i )->print( os, indent + 4 ); 247 256 248 257 // finally block 249 258 if ( finallyBlock != 0 ) { 250 os << string( indent + 2, ' ' ) << "Finally block: " << endl;259 os << string( indent + 2, ' ' ) << "Finally block: " << endl; 251 260 finallyBlock->print( os, indent + 4 ); 252 261 } // if … … 262 271 } 263 272 264 void CatchStmt::print( std::ostream &os, int indent ) {265 os << "\r" << string( indent, ' ') << "Catch Statement" << endl;266 267 os << "\r" << string( indent, ' ') << "... catching" << endl;273 void CatchStmt::print( std::ostream &os, int indent ) const { 274 os << string( indent, ' ' ) << "Catch Statement" << endl; 275 276 os << string( indent, ' ' ) << "... catching" << endl; 268 277 if ( decl ) { 269 278 decl->printShort( os, indent + 4 ); 270 279 os << endl; 271 280 } else if ( catchRest ) 272 os << "\r" << string( indent + 4 , ' ') << "the rest" << endl;281 os << string( indent + 4 , ' ' ) << "the rest" << endl; 273 282 else 274 os << "\r" << string( indent + 4 , ' ') << ">>> Error: this catch clause must have a declaration <<<" << endl;283 os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl; 275 284 } 276 285 … … 284 293 } 285 294 286 void FinallyStmt::print( std::ostream &os, int indent ) {287 os << "\r" << string( indent, ' ') << "Finally Statement" << endl;288 os << string( indent + 2, ' ' ) << "with block: " << endl;295 void FinallyStmt::print( std::ostream &os, int indent ) const { 296 os << string( indent, ' ' ) << "Finally Statement" << endl; 297 os << string( indent + 2, ' ' ) << "with block: " << endl; 289 298 block->print( os, indent + 4 ); 290 299 } … … 294 303 NullStmt::~NullStmt() {} 295 304 296 void NullStmt::print( std::ostream &os, int indent ) {297 os << "\r" << string( indent, ' ') << "Null Statement" << endl ;305 void NullStmt::print( std::ostream &os, int indent ) const { 306 os << string( indent, ' ' ) << "Null Statement" << endl ; 298 307 } 299 308
Note:
See TracChangeset
for help on using the changeset viewer.