Ignore:
Timestamp:
May 19, 2015, 7:57:09 AM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
a08ba92
Parents:
51587aa
Message:

licencing: fifth groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/GenPoly/PolyMutator.cc

    r51587aa r01aeade  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// PolyMutator.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 07:45:50 2015
     13// Update Count     : 1
    1414//
    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  */
    2115
    2216#include "PolyMutator.h"
     
    2923
    3024namespace GenPoly {
     25        namespace {
     26                const std::list<Label> noLabels;
     27        }
    3128
    32 namespace {
    33 const std::list<Label> noLabels;
    34 }
     29        PolyMutator::PolyMutator() : env( 0 ) {
     30        }
    3531
    36 PolyMutator::PolyMutator()
    37   : env( 0 )
    38 {
    39 }
     32        void PolyMutator::mutateStatementList( std::list< Statement* > &statements ) {
     33                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     34                        if ( ! stmtsToAddAfter.empty() ) {
     35                                statements.splice( i, stmtsToAddAfter );
     36                        } // if
     37                        *i = (*i)->acceptMutator( *this );
     38                        if ( ! stmtsToAdd.empty() ) {
     39                                statements.splice( i, stmtsToAdd );
     40                        } // if
     41                } // for
     42                if ( ! stmtsToAddAfter.empty() ) {
     43                        statements.splice( statements.end(), stmtsToAddAfter );
     44                } // if
     45        }
    4046
    41 void
    42 PolyMutator::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 }
     47        Statement * PolyMutator::mutateStatement( Statement *stmt ) {
     48                Statement *newStmt = maybeMutate( stmt, *this );
     49                if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) {
     50                        CompoundStmt *compound = new CompoundStmt( noLabels );
     51                        compound->get_kids().splice( compound->get_kids().end(), stmtsToAdd );
     52                        compound->get_kids().push_back( newStmt );
     53                        compound->get_kids().splice( compound->get_kids().end(), stmtsToAddAfter );
     54                        // doEndScope();
     55                        return compound;
     56                } else {
     57                        return newStmt;
     58                }
     59        }
    5760
    58 Statement*
    59 PolyMutator::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 }
     61        Expression * PolyMutator::mutateExpression( Expression *expr ) {
     62                if ( expr ) {
     63                        if ( expr->get_env() ) {
     64                                env = expr->get_env();
     65                        }
     66                        return expr->acceptMutator( *this );
     67                } else {
     68                        return expr;
     69                }
     70        }
    7371
    74 Expression*
    75 PolyMutator::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 }
     72        CompoundStmt * PolyMutator::mutate(CompoundStmt *compoundStmt) {
     73                doBeginScope();
     74                mutateStatementList( compoundStmt->get_kids() );
     75                doEndScope();
     76                return compoundStmt;
     77        }
    8678
    87 CompoundStmt*
    88 PolyMutator::mutate(CompoundStmt *compoundStmt)
    89 {
    90   doBeginScope();
    91   mutateStatementList( compoundStmt->get_kids() );
    92   doEndScope();
    93   return compoundStmt;
    94 }
     79        Statement * PolyMutator::mutate(IfStmt *ifStmt) {
     80                ifStmt->set_thenPart(  mutateStatement( ifStmt->get_thenPart() ) );
     81                ifStmt->set_elsePart(  mutateStatement( ifStmt->get_elsePart() ) );
     82                ifStmt->set_condition(  mutateExpression( ifStmt->get_condition() ) );
     83                return ifStmt;
     84        }
    9585
    96 Statement*
    97 PolyMutator::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 }
     86        Statement * PolyMutator::mutate(WhileStmt *whileStmt) {
     87                whileStmt->set_body(  mutateStatement( whileStmt->get_body() ) );
     88                whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
     89                return whileStmt;
     90        }
    10491
    105 Statement*
    106 PolyMutator::mutate(WhileStmt *whileStmt)
    107 {
    108   whileStmt->set_body(  mutateStatement( whileStmt->get_body() ) );
    109   whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
    110   return whileStmt;
    111 }
     92        Statement * PolyMutator::mutate(ForStmt *forStmt) {
     93                forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
     94                forStmt->set_initialization(  maybeMutate( forStmt->get_initialization(), *this ) );
     95                forStmt->set_condition(  mutateExpression( forStmt->get_condition() ) );
     96                forStmt->set_increment(  mutateExpression( forStmt->get_increment() ) );
     97                return forStmt;
     98        }
    11299
    113 Statement*
    114 PolyMutator::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 }
     100        Statement * PolyMutator::mutate(SwitchStmt *switchStmt) {
     101                mutateStatementList( switchStmt->get_branches() );
     102                switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
     103                return switchStmt;
     104        }
    122105
    123 Statement*
    124 PolyMutator::mutate(SwitchStmt *switchStmt)
    125 {
    126   mutateStatementList( switchStmt->get_branches() );
    127   switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
    128   return switchStmt;
    129 }
     106        Statement * PolyMutator::mutate(ChooseStmt *switchStmt) {
     107                mutateStatementList( switchStmt->get_branches() );
     108                switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
     109                return switchStmt;
     110        }
    130111
    131 Statement*
    132 PolyMutator::mutate(ChooseStmt *switchStmt)
    133 {
    134   mutateStatementList( switchStmt->get_branches() );
    135   switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
    136   return switchStmt;
    137 }
     112        Statement * PolyMutator::mutate(CaseStmt *caseStmt) {
     113                mutateStatementList( caseStmt->get_statements() );
     114                caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
     115                return caseStmt;
     116        }
    138117
    139 Statement*
    140 PolyMutator::mutate(CaseStmt *caseStmt)
    141 {
    142   mutateStatementList( caseStmt->get_statements() );
    143   caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
     118        Statement * PolyMutator::mutate(TryStmt *tryStmt) {
     119                tryStmt->set_block(  maybeMutate( tryStmt->get_block(), *this ) );
     120                mutateAll( tryStmt->get_catchers(), *this );
     121                return tryStmt;
     122        }
    144123
    145   return caseStmt;
    146 }
     124        Statement * PolyMutator::mutate(CatchStmt *cathStmt) {
     125                cathStmt->set_body(  mutateStatement( cathStmt->get_body() ) );
     126                cathStmt->set_decl(  maybeMutate( cathStmt->get_decl(), *this ) );
     127                return cathStmt;
     128        }
    147129
    148 Statement*
    149 PolyMutator::mutate(TryStmt *tryStmt)
    150 {
    151   tryStmt->set_block(  maybeMutate( tryStmt->get_block(), *this ) );
    152   mutateAll( tryStmt->get_catchers(), *this );
    153  
    154   return tryStmt;
    155 }
     130        Statement * PolyMutator::mutate(ReturnStmt *retStmt) {
     131                retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
     132                return retStmt;
     133        }
    156134
    157 Statement*
    158 PolyMutator::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 
    165 Statement*
    166 PolyMutator::mutate(ReturnStmt *retStmt)
    167 {
    168   retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
    169   return retStmt;
    170 }
    171 
    172 Statement*
    173 PolyMutator::mutate(ExprStmt *exprStmt)
    174 {
    175   exprStmt->set_expr( mutateExpression( exprStmt->get_expr() ) );
    176   return exprStmt;
    177 }
     135        Statement * PolyMutator::mutate(ExprStmt *exprStmt) {
     136                exprStmt->set_expr( mutateExpression( exprStmt->get_expr() ) );
     137                return exprStmt;
     138        }
    178139
    179140
    180 Expression*
    181 PolyMutator::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 }
     141        Expression * PolyMutator::mutate(UntypedExpr *untypedExpr) {
     142                for ( std::list< Expression* >::iterator i = untypedExpr->get_args().begin(); i != untypedExpr->get_args().end(); ++i ) {
     143                        *i = mutateExpression( *i );
     144                } // for
     145                return untypedExpr;
     146        }
    188147 
    189 /* static class method */
    190 void
    191 PolyMutator::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 }
     148        /* static class method */
     149        void PolyMutator::makeTyVarMap( Type *type, TyVarMap &tyVarMap ) {
     150                for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {
     151                        assert( *tyVar );
     152                        tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind();
     153                }
     154                if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {
     155                        makeTyVarMap( pointer->get_base(), tyVarMap );
     156                }
     157        }
     158} // namespace GenPoly
    201159
    202 /* static class method */
    203 } // namespace GenPoly
    204160// Local Variables: //
    205161// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.