source: translator/ControlStruct/ChooseMutator.cc@ 51587aa

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 stuck-waitfor-destruct with_gc
Last change on this file since 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

licencing: fourth groups of files

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// XXX.cc --
8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
11// Last Modified By :
12// Last Modified On :
13// Update Count : 0
14//
15#include <list>
16
17#include "SynTree/Statement.h"
18#include "ChooseMutator.h"
19
20namespace ControlStruct {
21 Statement *ChooseMutator::mutate( ChooseStmt *chooseStmt) {
22 bool enclosingChoose = insideChoose;
23 insideChoose = true;
24 mutateAll( chooseStmt->get_branches(), *this );
25 insideChoose = enclosingChoose;
26 return new SwitchStmt( chooseStmt->get_labels(), chooseStmt->get_condition(), chooseStmt->get_branches() );
27 }
28
29 Statement *ChooseMutator::mutate( SwitchStmt *switchStmt ) {
30 bool enclosingChoose = insideChoose;
31 insideChoose = false;
32 mutateAll( switchStmt->get_branches(), *this );
33 insideChoose = enclosingChoose;
34 return switchStmt;
35 }
36
37 Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) {
38 delete fallthruStmt;
39 return new NullStmt();
40 }
41
42 Statement* ChooseMutator::mutate(CaseStmt *caseStmt) {
43 std::list< Statement * > &stmts = caseStmt->get_statements();
44
45 if ( insideChoose ) {
46 BranchStmt *posBrk;
47 if ( (( posBrk = dynamic_cast< BranchStmt * > ( stmts.back() ) ) &&
48 ( posBrk->get_type() == BranchStmt::Break )) // last statement in the list is a (superfluous) 'break'
49 || dynamic_cast< FallthruStmt * > ( stmts.back() ) )
50 ;
51 else {
52 stmts.push_back( new BranchStmt( std::list< Label >(), "", BranchStmt::Break ) );
53 } // if
54 } // if
55
56 mutateAll ( stmts, *this );
57 return caseStmt;
58 }
59} // namespace ControlStruct
60// Local Variables: //
61// tab-width: 4 //
62// mode: c++ //
63// compile-command: "make install" //
64// End: //
Note: See TracBrowser for help on using the repository browser.