source: translator/GenPoly/PolyMutator.cc @ 51587aa

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

licencing: fourth groups of files

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