source: translator/GenPoly/PolyMutator.cc @ b1a6d6b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since b1a6d6b was b1a6d6b, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

removed duplicate adapters, switch to c99 for initializer declarations

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: PolyMutator.cc,v 1.7 2005/08/29 20:14:13 rcbilson Exp $
5 *
6 */
7
8#include "PolyMutator.h"
9#include "SynTree/Declaration.h"
10#include "SynTree/Type.h"
11#include "SynTree/Expression.h"
12#include "SynTree/Statement.h"
13#include "SynTree/Mutator.h"
14
15
16namespace GenPoly {
17
18namespace {
19const std::list<Label> noLabels;
20}
21
22PolyMutator::PolyMutator()
23  : env( 0 )
24{
25}
26
27void
28PolyMutator::mutateStatementList( std::list< Statement* > &statements )
29{
30  for( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
31    if( !stmtsToAddAfter.empty() ) {
32      statements.splice( i, stmtsToAddAfter );
33    }
34    *i = (*i)->acceptMutator( *this );
35    if( !stmtsToAdd.empty() ) {
36      statements.splice( i, stmtsToAdd );
37    }
38  }
39  if( !stmtsToAddAfter.empty() ) {
40    statements.splice( statements.end(), stmtsToAddAfter );
41  }
42}
43
44Statement*
45PolyMutator::mutateStatement( Statement *stmt )
46{
47  Statement *newStmt = maybeMutate( stmt, *this );
48  if( !stmtsToAdd.empty() || !stmtsToAddAfter.empty() ) {
49    CompoundStmt *compound = new CompoundStmt( noLabels );
50    compound->get_kids().splice( compound->get_kids().end(), stmtsToAdd );
51    compound->get_kids().push_back( newStmt );
52    compound->get_kids().splice( compound->get_kids().end(), stmtsToAddAfter );
53    // doEndScope();
54    return compound;
55  } else {
56    return newStmt;
57  }
58}
59
60Expression*
61PolyMutator::mutateExpression( Expression *expr )
62{
63  if( expr ) {
64    if( expr->get_env() ) {
65      env = expr->get_env();
66    }
67    return expr->acceptMutator( *this );
68  } else {
69    return expr;
70  }
71}
72
73CompoundStmt*
74PolyMutator::mutate(CompoundStmt *compoundStmt)
75{
76  doBeginScope();
77  mutateStatementList( compoundStmt->get_kids() );
78  doEndScope();
79  return compoundStmt;
80}
81
82Statement*
83PolyMutator::mutate(IfStmt *ifStmt)
84{
85  ifStmt->set_thenPart(  mutateStatement( ifStmt->get_thenPart() ) );
86  ifStmt->set_elsePart(  mutateStatement( ifStmt->get_elsePart() ) );
87  ifStmt->set_condition(  mutateExpression( ifStmt->get_condition() ) );
88  return ifStmt;
89}
90
91Statement*
92PolyMutator::mutate(WhileStmt *whileStmt)
93{
94  whileStmt->set_body(  mutateStatement( whileStmt->get_body() ) );
95  whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
96  return whileStmt;
97}
98
99Statement*
100PolyMutator::mutate(ForStmt *forStmt)
101{
102  forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
103  forStmt->set_initialization(  maybeMutate( forStmt->get_initialization(), *this ) );
104  forStmt->set_condition(  mutateExpression( forStmt->get_condition() ) );
105  forStmt->set_increment(  mutateExpression( forStmt->get_increment() ) );
106  return forStmt;
107}
108
109Statement*
110PolyMutator::mutate(SwitchStmt *switchStmt)
111{
112  mutateStatementList( switchStmt->get_branches() );
113  switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
114  return switchStmt;
115}
116
117Statement*
118PolyMutator::mutate(ChooseStmt *switchStmt)
119{
120  mutateStatementList( switchStmt->get_branches() );
121  switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
122  return switchStmt;
123}
124
125Statement*
126PolyMutator::mutate(CaseStmt *caseStmt)
127{
128  mutateStatementList( caseStmt->get_statements() );
129  caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
130
131  return caseStmt;
132}
133
134Statement*
135PolyMutator::mutate(TryStmt *tryStmt)
136{
137  tryStmt->set_block(  maybeMutate( tryStmt->get_block(), *this ) );
138  mutateAll( tryStmt->get_catchers(), *this );
139 
140  return tryStmt;
141}
142
143Statement*
144PolyMutator::mutate(CatchStmt *cathStmt)
145{
146  cathStmt->set_body(  mutateStatement( cathStmt->get_body() ) );
147  cathStmt->set_decl(  maybeMutate( cathStmt->get_decl(), *this ) );
148  return cathStmt;
149}
150
151Statement* 
152PolyMutator::mutate(ReturnStmt *retStmt)
153{
154  retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
155  return retStmt;
156}
157
158Statement* 
159PolyMutator::mutate(ExprStmt *exprStmt)
160{
161  exprStmt->set_expr( mutateExpression( exprStmt->get_expr() ) );
162  return exprStmt;
163}
164
165
166Expression* 
167PolyMutator::mutate(UntypedExpr *untypedExpr)
168{
169  for( std::list< Expression* >::iterator i = untypedExpr->get_args().begin(); i != untypedExpr->get_args().end(); ++i ) {
170    *i = mutateExpression( *i );
171  }
172  return untypedExpr;
173}
174 
175/* static class method */
176void 
177PolyMutator::makeTyVarMap( Type *type, TyVarMap &tyVarMap )
178{
179  for( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {
180    assert( *tyVar );
181    tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind();
182  }
183  if( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {
184    makeTyVarMap( pointer->get_base(), tyVarMap );
185  }
186}
187
188/* static class method */
189} // namespace GenPoly
Note: See TracBrowser for help on using the repository browser.