source: translator/ControlStruct/ChooseMutator.cc@ 643a2e1

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 643a2e1 was d9a0e76, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

remove Parser.old, add -XCFA to driver, copy ptrdiff_t from stddef.h in preclude, remove casts from initialization constants, adjust formatting

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <list>
2
3#include "SynTree/Statement.h"
4#include "ChooseMutator.h"
5
6namespace ControlStruct {
7 Statement *ChooseMutator::mutate( ChooseStmt *chooseStmt) {
8 bool enclosingChoose = insideChoose;
9 insideChoose = true;
10 mutateAll( chooseStmt->get_branches(), *this );
11 insideChoose = enclosingChoose;
12 return new SwitchStmt( chooseStmt->get_labels(), chooseStmt->get_condition(), chooseStmt->get_branches() );
13 }
14
15 Statement *ChooseMutator::mutate( SwitchStmt *switchStmt ) {
16 bool enclosingChoose = insideChoose;
17 insideChoose = false;
18 mutateAll( switchStmt->get_branches(), *this );
19 insideChoose = enclosingChoose;
20 return switchStmt;
21 }
22
23 Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) {
24 delete fallthruStmt;
25 return new NullStmt();
26 }
27
28 Statement* ChooseMutator::mutate(CaseStmt *caseStmt) {
29 std::list< Statement * > &stmts = caseStmt->get_statements();
30
31 if ( insideChoose ) {
32 BranchStmt *posBrk;
33 if ( (( posBrk = dynamic_cast< BranchStmt * > ( stmts.back() ) ) &&
34 ( posBrk->get_type() == BranchStmt::Break )) // last statement in the list is a (superfluous) 'break'
35 || dynamic_cast< FallthruStmt * > ( stmts.back() ) )
36 ;
37 else {
38 stmts.push_back( new BranchStmt( std::list< Label >(), "", BranchStmt::Break ) );
39 } // if
40 } // if
41
42 mutateAll ( stmts, *this );
43 return caseStmt;
44 }
45} // namespace ControlStruct
Note: See TracBrowser for help on using the repository browser.