Changes in / [274ce8c:8f6dfe7]
- Location:
- src
- Files:
-
- 10 edited
-
ControlStruct/ForExprMutator.cc (modified) (3 diffs)
-
ControlStruct/ForExprMutator.h (modified) (2 diffs)
-
Parser/StatementNode.cc (modified) (3 diffs)
-
Parser/parser.yy (modified) (3 diffs)
-
SymTab/Indexer.cc (modified) (2 diffs)
-
SymTab/Indexer.h (modified) (2 diffs)
-
SynTree/Mutator.cc (modified) (2 diffs)
-
SynTree/Statement.cc (modified) (15 diffs)
-
SynTree/Statement.h (modified) (3 diffs)
-
SynTree/Visitor.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ForExprMutator.cc
r274ce8c r8f6dfe7 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Aug 17 15:32:46 201713 // Update Count : 1 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:14:44 2015 13 // Update Count : 10 14 14 // 15 15 … … 21 21 22 22 namespace ControlStruct { 23 Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {24 std::list<Statement *> &init = ifStmt->get_initialization();25 if ( init.size() == 0 ) {26 return ifStmt;27 } // if28 29 // create compound statement, move initializers outside, leave _for_ as-is30 CompoundStmt *block = new CompoundStmt( std::list< Label >() );31 std::list<Statement *> &stmts = block->get_kids();32 stmts.splice( stmts.end(), init );33 34 // add for to the new block35 stmts.push_back( ifStmt );36 return block;37 }38 39 23 Statement *ForExprMutator::postmutate( ForStmt *forStmt ) { 40 24 // hoist any initializer declarations to make them C89 (rather than C99) … … 47 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 48 32 std::list<Statement *> &stmts = block->get_kids(); 49 stmts.splice( stmts.end(), init ); 33 for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) { 34 stmts.push_back( *it ); 35 } // for 50 36 51 37 // add for to the new block 52 38 stmts.push_back( forStmt ); 39 forStmt->set_initialization( std::list<Statement *>() ); 53 40 return block; 54 41 } -
src/ControlStruct/ForExprMutator.h
r274ce8c r8f6dfe7 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 17 15:32:48 201713 // Update Count : 512 // Last Modified On : Sat Jul 22 09:17:08 2017 13 // Update Count : 4 14 14 // 15 15 16 16 #pragma once 17 17 18 class IfStmt;19 18 class ForStmt; 20 19 class Statement; … … 23 22 class ForExprMutator { 24 23 public: 25 Statement *postmutate( IfStmt * );26 24 Statement *postmutate( ForStmt * ); 27 25 }; -
src/Parser/StatementNode.cc
r274ce8c r8f6dfe7 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:01:31201713 // Update Count : 34 512 // Last Modified On : Wed Aug 16 16:39:43 2017 13 // Update Count : 340 14 14 // 15 15 … … 24 24 #include "SynTree/Expression.h" // for Expression, ConstantExpr 25 25 #include "SynTree/Label.h" // for Label, noLabels 26 #include "SynTree/Declaration.h"27 26 #include "SynTree/Statement.h" // for Statement, BranchStmt, CaseStmt 28 27 #include "parserutility.h" // for notZeroExpr … … 99 98 } // if 100 99 101 Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) ); 102 delete ctl; 103 return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init ); 100 return new IfStmt( noLabels, notZeroExpr( 101 /*ctl->condition 102 ?*/ maybeMoveBuild< Expression >(ctl->condition) 103 /*: new VariableExpr( init.end() )*/ ) 104 , thenb, elseb ); 105 // ret->initialization = init; 106 // delete ctl; 107 // assert( ret ); 108 // return ret; 104 109 } 105 110 -
src/Parser/parser.yy
r274ce8c r8f6dfe7 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:52:12201713 // Update Count : 248 912 // Last Modified On : Wed Aug 16 18:09:14 2017 13 // Update Count : 2485 14 14 // 15 15 … … 796 796 797 797 selection_statement: 798 IF '(' pushif_control_expression ')' statement %prec THEN798 IF '(' if_control_expression ')' statement %prec THEN 799 799 // explicitly deal with the shift/reduce conflict on if/else 800 { $$ = new StatementNode( build_if( $ 4, $6, nullptr ) ); }801 | IF '(' pushif_control_expression ')' statement ELSE statement802 { $$ = new StatementNode( build_if( $ 4, $6, $8) ); }800 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 801 | IF '(' if_control_expression ')' statement ELSE statement 802 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 803 803 | SWITCH '(' comma_expression ')' case_clause // CFA 804 804 { $$ = new StatementNode( build_switch( $3, $5 ) ); } … … 823 823 824 824 if_control_expression: 825 comma_expression pop825 comma_expression 826 826 { $$ = new IfCtl( nullptr, $1 ); } 827 | c_declaration // no semi-col on827 | c_declaration // no semi-coln 828 828 { $$ = new IfCtl( $1, nullptr ); } 829 829 | cfa_declaration // no semi-colon 830 830 { $$ = new IfCtl( $1, nullptr ); } 831 | declaration comma_expression // semi-colon separated831 | declaration comma_expression 832 832 { $$ = new IfCtl( $1, $2 ); } 833 833 ; -
src/SymTab/Indexer.cc
r274ce8c r8f6dfe7 10 10 // Created On : Sun May 17 21:37:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:08:40201713 // Update Count : 2012 // Last Modified On : Thu Mar 30 16:38:47 2017 13 // Update Count : 19 14 14 // 15 15 … … 351 351 acceptAll( compoundStmt->get_kids(), *this ); 352 352 leaveScope(); 353 }354 355 void Indexer::visit( IfStmt *ifStmt ) {356 // for statements introduce a level of scope357 enterScope();358 Visitor::visit( ifStmt );359 leaveScope();360 353 } 361 354 -
src/SymTab/Indexer.h
r274ce8c r8f6dfe7 10 10 // Created On : Sun May 17 21:38:55 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:09:12201713 // Update Count : 812 // Last Modified On : Sat Jul 22 09:46:34 2017 13 // Update Count : 7 14 14 // 15 15 … … 45 45 46 46 virtual void visit( CompoundStmt *compoundStmt ); 47 virtual void visit( IfStmt *ifStmt );48 47 virtual void visit( ForStmt *forStmt ); 49 48 virtual void visit( CatchStmt *catchStmt ); -
src/SynTree/Mutator.cc
r274ce8c r8f6dfe7 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 15:39:37201713 // Update Count : 2 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 24 16:32:00 2017 13 // Update Count : 25 14 14 // 15 15 … … 114 114 115 115 Statement *Mutator::mutate( IfStmt *ifStmt ) { 116 mutateAll( ifStmt->get_initialization(), *this );117 116 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 118 117 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); -
src/SynTree/Statement.cc
r274ce8c r8f6dfe7 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 16:17:20 201713 // Update Count : 6 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Aug 14 12:26:00 2017 13 // Update Count : 65 14 14 // 15 15 … … 32 32 using std::endl; 33 33 34 Statement::Statement( std::list<Label> labels ) : labels(labels ) {}34 Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {} 35 35 36 36 void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {} … … 38 38 Statement::~Statement() {} 39 39 40 ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr(expr ) {}40 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {} 41 41 42 42 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 88 88 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 89 89 90 BranchStmt::BranchStmt( std::list<Label> labels, Label target, Typetype ) throw ( SemanticError ) :91 Statement( labels ), originalTarget( target ), target( target ), computedTarget( NULL ), type(type ) {90 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) : 91 Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) { 92 92 //actually this is a syntactic error signaled by the parser 93 93 if ( type == BranchStmt::Goto && target.empty() ) … … 95 95 } 96 96 97 BranchStmt::BranchStmt( std::list<Label> labels, Expression * computedTarget, Typetype ) throw ( SemanticError ) :98 Statement( labels ), computedTarget( computedTarget ), type(type ) {97 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) : 98 Statement( labels ), computedTarget( _computedTarget ), type( _type ) { 99 99 if ( type != BranchStmt::Goto || computedTarget == 0 ) 100 100 throw SemanticError("Computed target not valid in branch statement"); … … 105 105 } 106 106 107 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression * expr ) : Statement( labels ), expr(expr ) {}107 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {} 108 108 109 109 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 122 122 } 123 123 124 IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization):125 Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization) {}124 IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ): 125 Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {} 126 126 127 127 IfStmt::IfStmt( const IfStmt & other ) : 128 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { 129 cloneAll( other.initialization, initialization ); 130 } 128 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {} 131 129 132 130 IfStmt::~IfStmt() { 133 deleteAll( initialization );134 131 delete condition; 135 132 delete thenPart; … … 142 139 condition->print( os, indent + 4 ); 143 140 144 if ( !initialization.empty() ) {145 os << string( indent + 2, ' ' ) << "initialization: \n";146 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {147 os << string( indent + 4, ' ' );148 (*it)->print( os, indent + 4 );149 }150 os << endl;151 }152 153 141 os << string( indent+2, ' ' ) << "... then: " << endl; 154 142 … … 163 151 } 164 152 165 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):166 Statement( labels ), condition( condition ), statements(statements ) {153 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ): 154 Statement( _labels ), condition( _condition ), statements( _statements ) { 167 155 } 168 156 … … 191 179 } 192 180 193 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :194 Statement( labels ), condition( condition ), stmts(statements ), _isDefault( deflt ) {181 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 182 Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) { 195 183 if ( isDefault() && condition != 0 ) 196 184 throw SemanticError("default with conditions"); … … 228 216 } 229 217 230 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition , Statement *body, bool isDoWhile):231 Statement( labels ), condition( condition ), body( body), isDoWhile( isDoWhile) {218 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): 219 Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { 232 220 } 233 221 … … 250 238 } 251 239 252 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization , Expression *condition, Expression *increment, Statement *body):253 Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body) {240 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): 241 Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { 254 242 } 255 243 … … 329 317 } 330 318 331 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt *finallyBlock ) :332 Statement( labels ), block( tryBlock ), handlers( handlers ), finallyBlock(finallyBlock ) {319 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) : 320 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { 333 321 } 334 322 … … 363 351 } 364 352 365 CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :366 Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body(body ) {353 CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) : 354 Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) { 367 355 } 368 356 … … 401 389 402 390 403 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt * block ) : Statement( labels ), block(block ) {391 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { 404 392 assert( labels.empty() ); // finally statement cannot be labeled 405 393 } -
src/SynTree/Statement.h
r274ce8c r8f6dfe7 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 17 15:37:53201713 // Update Count : 7 212 // Last Modified On : Wed Aug 16 16:28:55 2017 13 // Update Count : 70 14 14 // 15 15 … … 127 127 class IfStmt : public Statement { 128 128 public: 129 std::list<Statement *> initialization; 129 130 Expression *condition; 130 131 Statement *thenPart; 131 132 Statement *elsePart; 132 std::list<Statement *> initialization; 133 134 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, 135 std::list<Statement *> initialization = std::list<Statement *>() ); 133 134 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 136 135 IfStmt( const IfStmt &other ); 137 136 virtual ~IfStmt(); 138 137 139 138 std::list<Statement *> &get_initialization() { return initialization; } 139 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; } 140 140 Expression *get_condition() { return condition; } 141 141 void set_condition( Expression *newValue ) { condition = newValue; } … … 239 239 240 240 std::list<Statement *> &get_initialization() { return initialization; } 241 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; } 241 242 Expression *get_condition() { return condition; } 242 243 void set_condition( Expression *newValue ) { condition = newValue; } -
src/SynTree/Visitor.cc
r274ce8c r8f6dfe7 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 15:39:38201713 // Update Count : 2 911 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 24 16:30:00 2017 13 // Update Count : 27 14 14 // 15 15 … … 99 99 100 100 void Visitor::visit( IfStmt *ifStmt ) { 101 acceptAll( ifStmt->get_initialization(), *this );102 101 maybeAccept( ifStmt->get_condition(), *this ); 103 102 maybeAccept( ifStmt->get_thenPart(), *this );
Note:
See TracChangeset
for help on using the changeset viewer.