Changeset a08ba92


Ignore:
Timestamp:
May 19, 2015, 4:58:14 PM (10 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:
843054c2
Parents:
01aeade
Message:

licencing: sixth groups of files

Location:
translator
Files:
75 edited

Legend:

Unmodified
Added
Removed
  • translator/CodeGen/GenType.cc

    r01aeade ra08ba92  
    122122        }
    123123
    124         void GenType::visit( ArrayType *arrayType ){
     124        void GenType::visit( ArrayType *arrayType ) {
    125125                genArray( arrayType->get_qualifiers(), arrayType->get_base(), arrayType->get_dimension(), arrayType->get_isVarLen(), arrayType->get_isStatic() );
    126126        }
     
    153153                        cg.genCommaList( pars.begin(), pars.end() );
    154154
    155                         if ( funcType->get_isVarArgs() ){
     155                        if ( funcType->get_isVarArgs() ) {
    156156                                os << ", ...";
    157157                        } // if
  • translator/Common/utility.h

    r01aeade ra08ba92  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:27:38 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 15:34:57 2015
     13// Update Count     : 3
    1414//
    1515
     
    116116        Ts ret;
    117117
    118         switch ( l.size() ){
     118        switch ( l.size() ) {
    119119          case 0:
    120120                return ret;
     
    156156
    157157        //if ( next != org.end() ) {
    158     org.erase( pos );
    159     org.splice( next, with );
    160     //}
     158        org.erase( pos );
     159        org.splice( next, with );
     160        //}
    161161
    162162        return;
     
    175175template< typename T >
    176176struct is_null_pointer {
    177         bool operator()( const T *ptr ){ return ( ptr == 0 ); }
     177        bool operator()( const T *ptr ) { return ( ptr == 0 ); }
    178178};
    179179
  • translator/ControlStruct/CaseRangeMutator.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// CaseRangeMutator.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
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 13:00:28 2015
     13// Update Count     : 3
     14//
     15
    1516#include <list>
    1617#include <cassert>
     
    2728
    2829namespace ControlStruct {
    29     Statement *CaseRangeMutator::mutate(ChooseStmt *chooseStmt) {
    30         /* There shouldn't be any `choose' statements by now, throw an exception or something. */
    31         throw( 0 ) ; /* FIXME */
    32     }
    33 
    34     Statement *CaseRangeMutator::mutate(SwitchStmt *switchStmt) {
    35         std::list< Statement * > &cases = switchStmt->get_branches();
    36 
    37         // a `for' would be more natural... all this contortions are because `replace' invalidates the iterator
    38         std::list< Statement * >::iterator i = cases.begin();
    39         while (  i != cases.end() ) {
    40             (*i)->acceptMutator( *this );
    41 
    42             if ( ! newCaseLabels.empty() ) {
    43                 std::list< Statement * > newCases;
    44 
    45                 // transform( newCaseLabels.begin(), newCaseLabels.end(), bnd1st( ptr_fun( ctor< CaseStmt, Label, Expression * > ) ) );
    46 
    47                 for ( std::list< Expression * >::iterator j = newCaseLabels.begin();
    48                       j != newCaseLabels.end(); j++ ) {
    49                     std::list<Label> emptyLabels;
    50                     std::list< Statement *> emptyStmts;
    51                     newCases.push_back( new CaseStmt( emptyLabels, *j, emptyStmts ) );
    52                 }
    53 
    54                 if ( CaseStmt *currentCase = dynamic_cast< CaseStmt * > ( *i ) )
    55                     if ( ! currentCase->get_statements().empty() ) {
    56                         CaseStmt *lastCase = dynamic_cast< CaseStmt * > ( newCases.back() );
    57                         if ( lastCase == 0 ) { throw ( 0 ); /* FIXME */ } // something is very wrong, as I just made these, and they were all cases
    58                         // transfer the statement block (if any) to the new list:
    59                         lastCase->set_statements( currentCase->get_statements() );
    60                     }
    61                 std::list< Statement * >::iterator j = i; advance( j, 1 );
    62                 replace ( cases, i, newCases );
    63                 i = j;
    64                 newCaseLabels.clear();
    65             } else
    66                 i++;
    67         } // while
    68 
    69         return switchStmt;
    70     }
    71 
    72     Statement *CaseRangeMutator::mutate(FallthruStmt *fallthruStmt) {
    73         //delete fallthruStmt;
    74         return new NullStmt();
    75     }
    76 
    77     Statement *CaseRangeMutator::mutate(CaseStmt *caseStmt) {
    78         UntypedExpr *cond;
    79         if ( (cond = dynamic_cast< UntypedExpr * >( caseStmt->get_condition() )) != 0 ) {
    80             NameExpr *nmfunc;
    81             if ( (nmfunc = dynamic_cast< NameExpr *>( cond->get_function() )) != 0 ) {
    82                 if ( nmfunc->get_name() == std::string("Range") ) {
    83                     assert( cond->get_args().size() == 2 );
    84                     std::list<Expression *>::iterator i = cond->get_args().begin();
    85                     Expression *lo = *i, *hi = *(++i); // "unnecessary" temporaries
    86                     fillRange( lo, hi);
    87                 }
    88             }
    89         } else if ( TupleExpr *tcond = dynamic_cast< TupleExpr * >( caseStmt->get_condition() ) ) {
    90             // case list
    91             assert( ! tcond->get_exprs().empty() );
    92             for ( std::list< Expression * >::iterator i = tcond->get_exprs().begin(); i != tcond->get_exprs().end(); i++ )
    93                 newCaseLabels.push_back( *i ); // do I need to clone them?
    94         } // if
    95 
    96         std::list< Statement * > &stmts = caseStmt->get_statements();
    97         mutateAll ( stmts, *this );
    98 
    99         return caseStmt;
    100     }
    101 
    102     void CaseRangeMutator::fillRange(Expression *lo, Expression *hi) {
    103         // generate the actual range (and check for consistency)
    104         Constant *c_lo, *c_hi;
    105         ConstantExpr *ce_lo, *ce_hi;
    106         ce_lo = dynamic_cast< ConstantExpr * >( lo );
    107         ce_hi = dynamic_cast< ConstantExpr * >( hi );
    108 
    109         if ( ce_lo && ce_hi ) {
    110             c_lo = ce_lo->get_constant(); c_hi = ce_hi->get_constant();
    111         } /* else {
    112              if ( ! ce_lo ) ;
    113              if ( ! ce_hi ) ;
    114              } */
    115         BasicType *ty_lo = dynamic_cast< BasicType * >( c_lo->get_type() ),
    116             *ty_hi = dynamic_cast< BasicType * >( c_hi->get_type() );
    117    
    118         if ( ! ty_lo || ! ty_hi )
    119             return; // one of them is not a constant
    120 
    121         switch ( ty_lo->get_kind() ) {
    122           case BasicType::Char:
    123           case BasicType::UnsignedChar:
    124             switch ( ty_hi->get_kind() ){
     30        Statement *CaseRangeMutator::mutate( ChooseStmt *chooseStmt ) {
     31                // There shouldn't be any `choose' statements by now, throw an exception or something.
     32                throw( 0 ) ; /* FIXME */
     33        }
     34
     35        Statement *CaseRangeMutator::mutate( SwitchStmt *switchStmt ) {
     36                std::list< Statement * > &cases = switchStmt->get_branches();
     37
     38                // a `for' would be more natural... all this contortions are because `replace' invalidates the iterator
     39                std::list< Statement * >::iterator i = cases.begin();
     40                while ( i != cases.end() ) {
     41                        (*i )->acceptMutator( *this );
     42
     43                        if ( ! newCaseLabels.empty() ) {
     44                                std::list< Statement * > newCases;
     45
     46                                // transform( newCaseLabels.begin(), newCaseLabels.end(), bnd1st( ptr_fun( ctor< CaseStmt, Label, Expression * > ) ) );
     47
     48                                for ( std::list< Expression * >::iterator j = newCaseLabels.begin();
     49                                          j != newCaseLabels.end(); j++ ) {
     50                                        std::list<Label> emptyLabels;
     51                                        std::list< Statement *> emptyStmts;
     52                                        newCases.push_back( new CaseStmt( emptyLabels, *j, emptyStmts ) );
     53                                } // for
     54
     55                                if ( CaseStmt *currentCase = dynamic_cast< CaseStmt * > ( *i ) )
     56                                        if ( ! currentCase->get_statements().empty() ) {
     57                                                CaseStmt *lastCase = dynamic_cast< CaseStmt * > ( newCases.back() );
     58                                                if ( lastCase == 0 ) { throw ( 0 ); /* FIXME */ } // something is very wrong, as I just made these, and they were all cases
     59                                                // transfer the statement block ( if any ) to the new list:
     60                                                lastCase->set_statements( currentCase->get_statements() );
     61                                        } // if
     62                                std::list< Statement * >::iterator j = i; advance( j, 1 );
     63                                replace ( cases, i, newCases );
     64                                i = j;
     65                                newCaseLabels.clear();
     66                        } else
     67                                i++;
     68                } // while
     69
     70                return switchStmt;
     71        }
     72
     73        Statement *CaseRangeMutator::mutate( FallthruStmt *fallthruStmt ) {
     74                //delete fallthruStmt;
     75                return new NullStmt();
     76        }
     77
     78        Statement *CaseRangeMutator::mutate( CaseStmt *caseStmt ) {
     79                UntypedExpr *cond;
     80                if ( ( cond = dynamic_cast< UntypedExpr * >( caseStmt->get_condition() )) != 0 ) {
     81                        NameExpr *nmfunc;
     82                        if ( ( nmfunc = dynamic_cast< NameExpr *>( cond->get_function() )) != 0 ) {
     83                                if ( nmfunc->get_name() == std::string("Range") ) {
     84                                        assert( cond->get_args().size() == 2 );
     85                                        std::list<Expression *>::iterator i = cond->get_args().begin();
     86                                        Expression *lo = *i, *hi = *(++i ); // "unnecessary" temporaries
     87                                        fillRange( lo, hi );
     88                                } // if
     89                        } // if
     90                } else if ( TupleExpr *tcond = dynamic_cast< TupleExpr * >( caseStmt->get_condition() ) ) {
     91                        // case list
     92                        assert( ! tcond->get_exprs().empty() );
     93                        for ( std::list< Expression * >::iterator i = tcond->get_exprs().begin(); i != tcond->get_exprs().end(); i++ )
     94                                newCaseLabels.push_back( *i ); // do I need to clone them?
     95                } // if
     96
     97                std::list< Statement * > &stmts = caseStmt->get_statements();
     98                mutateAll ( stmts, *this );
     99
     100                return caseStmt;
     101        }
     102
     103        void CaseRangeMutator::fillRange( Expression *lo, Expression *hi ) {
     104                // generate the actual range ( and check for consistency )
     105                Constant *c_lo, *c_hi;
     106                ConstantExpr *ce_lo, *ce_hi;
     107                ce_lo = dynamic_cast< ConstantExpr * >( lo );
     108                ce_hi = dynamic_cast< ConstantExpr * >( hi );
     109
     110                if ( ce_lo && ce_hi ) {
     111                        c_lo = ce_lo->get_constant(); c_hi = ce_hi->get_constant();
     112                } /* else {
     113                         if ( ! ce_lo ) ;
     114                         if ( ! ce_hi ) ;
     115                         } */
     116                BasicType *ty_lo = dynamic_cast< BasicType * >( c_lo->get_type() ),
     117                        *ty_hi = dynamic_cast< BasicType * >( c_hi->get_type() );
     118       
     119                if ( ! ty_lo || ! ty_hi )
     120                        return; // one of them is not a constant
     121
     122                switch ( ty_lo->get_kind() ) {
    125123                  case BasicType::Char:
    126124                  case BasicType::UnsignedChar:
    127                     // first case, they are both printable ASCII characters represented as 'x'
    128                     if ( c_lo->get_value().size() == 3 && c_hi->get_value().size() == 3 ) {
    129                         char ch_lo = (c_lo->get_value())[1], ch_hi = (c_hi->get_value())[1];
    130 
    131                         if ( ch_lo > ch_hi ) { char t=ch_lo; ch_lo=ch_hi; ch_hi=t; }
    132 
    133                         for ( char c = ch_lo; c <=  ch_hi; c++ ){
    134                             Type::Qualifiers q;
    135                             Constant cnst( new BasicType(q, BasicType::Char),
    136                                            std::string("'") + c + std::string("'") );
    137                             newCaseLabels.push_back( new ConstantExpr( cnst ) );
     125                        switch ( ty_hi->get_kind() ) {
     126                          case BasicType::Char:
     127                          case BasicType::UnsignedChar:
     128                                // first case, they are both printable ASCII characters represented as 'x'
     129                                if ( c_lo->get_value().size() == 3 && c_hi->get_value().size() == 3 ) {
     130                                        char ch_lo = ( c_lo->get_value())[1], ch_hi = ( c_hi->get_value())[1];
     131
     132                                        if ( ch_lo > ch_hi ) { char t=ch_lo; ch_lo=ch_hi; ch_hi=t; }
     133
     134                                        for ( char c = ch_lo; c <=  ch_hi; c++ ) {
     135                                                Type::Qualifiers q;
     136                                                Constant cnst( new BasicType( q, BasicType::Char ),
     137                                                                           std::string("'") + c + std::string("'") );
     138                                                newCaseLabels.push_back( new ConstantExpr( cnst ) );
     139                                        } // for
     140
     141                                        return;
     142                                } // if
     143                                break;
     144                          default:
     145                                // error: incompatible constants
     146                                break;
     147                        } // switch
     148                        break;
     149                  case BasicType::ShortSignedInt:
     150                  case BasicType::ShortUnsignedInt:
     151                  case BasicType::SignedInt:
     152                  case BasicType::UnsignedInt:
     153                  case BasicType::LongSignedInt:
     154                  case BasicType::LongUnsignedInt:
     155                  case BasicType::LongLongSignedInt:
     156                  case BasicType::LongLongUnsignedInt:
     157                        switch ( ty_hi->get_kind() ) {
     158                          case BasicType::ShortSignedInt:
     159                          case BasicType::ShortUnsignedInt:
     160                          case BasicType::SignedInt:
     161                          case BasicType::UnsignedInt:
     162                          case BasicType::LongSignedInt:
     163                          case BasicType::LongUnsignedInt:
     164                          case BasicType::LongLongSignedInt:
     165                          case BasicType::LongLongUnsignedInt: {
     166                                  int i_lo = atoi( c_lo->get_value().c_str()),
     167                                          i_hi = atoi( c_hi->get_value().c_str());
     168
     169                                  if ( i_lo > i_hi ) { int t=i_lo; i_lo=i_hi; i_hi=t; }
     170
     171                                  for ( int c = i_lo; c <=  i_hi; c++ ) {
     172                                          Type::Qualifiers q;
     173                                          Constant cnst( new BasicType( q, ty_hi->get_kind()), // figure can't hurt (used to think in positives)
     174                                                                         toString< int >( c ) );
     175                                          newCaseLabels.push_back( new ConstantExpr( cnst ) );
     176                                  }
     177
     178                                  return;
     179                          }
     180                          default:
     181                                // error: incompatible constants
     182                                break;
    138183                        }
    139 
     184                        break;
     185                  default:
     186                        break;
     187                } // switch
     188
     189                /* End: */{
     190                        // invalid range, signal a warning (it still generates the two case labels)
     191                        newCaseLabels.push_back( lo );
     192                        newCaseLabels.push_back( hi );
    140193                        return;
    141                     }
    142                     break;
    143                   default:
    144                     // error: incompatible constants
    145                     break;
    146194                }
    147             break;
    148           case BasicType::ShortSignedInt:
    149           case BasicType::ShortUnsignedInt:
    150           case BasicType::SignedInt:
    151           case BasicType::UnsignedInt:
    152           case BasicType::LongSignedInt:
    153           case BasicType::LongUnsignedInt:
    154           case BasicType::LongLongSignedInt:
    155           case BasicType::LongLongUnsignedInt:
    156             switch ( ty_hi->get_kind() ) {
    157               case BasicType::ShortSignedInt:
    158               case BasicType::ShortUnsignedInt:
    159               case BasicType::SignedInt:
    160               case BasicType::UnsignedInt:
    161               case BasicType::LongSignedInt:
    162               case BasicType::LongUnsignedInt:
    163               case BasicType::LongLongSignedInt:
    164               case BasicType::LongLongUnsignedInt: {
    165                   int i_lo = atoi(c_lo->get_value().c_str()),
    166                       i_hi = atoi(c_hi->get_value().c_str());
    167 
    168                   if ( i_lo > i_hi ) { int t=i_lo; i_lo=i_hi; i_hi=t; }
    169 
    170                   for ( int c = i_lo; c <=  i_hi; c++ ){
    171                       Type::Qualifiers q;
    172                       Constant cnst( new BasicType(q, ty_hi->get_kind()), // figure can't hurt (used to think in positives)
    173                                      toString< int >( c ) );
    174                       newCaseLabels.push_back( new ConstantExpr( cnst ) );
    175                   }
    176 
    177                   return;
    178               }
    179               default:
    180                 // error: incompatible constants
    181                 break;
    182             }
    183             break;
    184           default:
    185             break;
    186         } // switch
    187 
    188         /* End: */{
    189             // invalid range, signal a warning (it still generates the two case labels)
    190             newCaseLabels.push_back( lo );
    191             newCaseLabels.push_back( hi );
    192             return;
    193         }
    194     }
     195        }
    195196} // namespace ControlStruct
     197
    196198// Local Variables: //
    197199// tab-width: 4 //
  • translator/ControlStruct/CaseRangeMutator.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// CaseRangeMutator.h --
    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 15:22:51 2015
     13// Update Count     : 3
    1414//
     15
    1516#ifndef CASERNG_MUTATOR_H
    1617#define CASERNG_MUTATOR_H
     
    2122
    2223namespace ControlStruct {
    23     class CaseRangeMutator : public Mutator {
    24       public:
    25         CaseRangeMutator() {}
     24        class CaseRangeMutator : public Mutator {
     25          public:
     26                CaseRangeMutator() {}
    2627
    27         virtual Statement *mutate( ChooseStmt * );
    28         virtual Statement *mutate( SwitchStmt * );
    29         virtual Statement *mutate( FallthruStmt * );
    30         virtual Statement *mutate( CaseStmt * );
    31       private:
    32         void fillRange( Expression *lo, Expression *hi );
     28                virtual Statement *mutate( ChooseStmt * );
     29                virtual Statement *mutate( SwitchStmt * );
     30                virtual Statement *mutate( FallthruStmt * );
     31                virtual Statement *mutate( CaseStmt * );
     32          private:
     33                void fillRange( Expression *lo, Expression *hi );
    3334
    34         Expression *currentCondition;
    35         std::list< Expression * > newCaseLabels;
    36     };
    37 
     35                Expression *currentCondition;
     36                std::list< Expression * > newCaseLabels;
     37        };
    3838} // namespace ControlStruct
    3939
    4040#endif // CASERNG_MUTATOR_H
    4141
    42 /*
    43   Local Variables:
    44   mode: c++
    45   End:
    46 */
    4742// Local Variables: //
    4843// tab-width: 4 //
  • translator/ControlStruct/ChooseMutator.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// ChooseMutator.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 15:31:39 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <list>
    1617
     
    1920
    2021namespace 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     }
     22        Statement *ChooseMutator::mutate( ChooseStmt *chooseStmt ) {
     23                bool enclosingChoose = insideChoose;
     24                insideChoose = true;
     25                mutateAll( chooseStmt->get_branches(), *this );
     26                insideChoose = enclosingChoose;
     27                return new SwitchStmt( chooseStmt->get_labels(),  chooseStmt->get_condition(), chooseStmt->get_branches() );
     28        }
    2829
    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     }
     30        Statement *ChooseMutator::mutate( SwitchStmt *switchStmt ) {
     31                bool enclosingChoose = insideChoose;
     32                insideChoose = false;
     33                mutateAll( switchStmt->get_branches(), *this );
     34                insideChoose = enclosingChoose;
     35                return switchStmt;
     36        }
    3637
    37     Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) {
    38         delete fallthruStmt;
    39         return new NullStmt();
    40     }
     38        Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) {
     39                delete fallthruStmt;
     40                return new NullStmt();
     41        }
    4142
    42     Statement* ChooseMutator::mutate(CaseStmt *caseStmt) {
    43         std::list< Statement * > &stmts = caseStmt->get_statements();
     43        Statement* ChooseMutator::mutate( CaseStmt *caseStmt ) {
     44                std::list< Statement * > &stmts = caseStmt->get_statements();
    4445
    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
     46                if ( insideChoose ) {
     47                        BranchStmt *posBrk;
     48                        if ( (( posBrk = dynamic_cast< BranchStmt * > ( stmts.back() ) ) &&
     49                                  ( posBrk->get_type() == BranchStmt::Break ))  // last statement in the list is a (superfluous) 'break'
     50                                || dynamic_cast< FallthruStmt * > ( stmts.back() ) )
     51                                ;
     52                        else {
     53                                stmts.push_back( new BranchStmt( std::list< Label >(), "", BranchStmt::Break ) );
     54                        } // if
     55                } // if
    5556
    56         mutateAll ( stmts, *this );
    57         return caseStmt;
    58     }
     57                mutateAll ( stmts, *this );
     58                return caseStmt;
     59        }
    5960} // namespace ControlStruct
     61
    6062// Local Variables: //
    6163// tab-width: 4 //
  • translator/ControlStruct/ChooseMutator.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// ChooseMutator.h --
    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 15:33:11 2015
     13// Update Count     : 3
    1414//
     15
    1516#ifndef CHOOSE_MUTATOR_H
    1617#define CHOOSE_MUTATOR_H
     
    2122
    2223namespace ControlStruct {
     24        class ChooseMutator : public Mutator {
     25          public:
     26                ChooseMutator() : insideChoose( false ) {}
    2327
    24     class ChooseMutator : public Mutator {
    25       public:
    26         ChooseMutator() : insideChoose( false ) {}
    27 
    28         virtual Statement *mutate( ChooseStmt * );
    29         virtual Statement *mutate( SwitchStmt * );
    30         virtual Statement *mutate( FallthruStmt * );
    31         virtual Statement *mutate( CaseStmt * );
    32       private:
    33         bool insideChoose;
    34     };
     28                virtual Statement *mutate( ChooseStmt * );
     29                virtual Statement *mutate( SwitchStmt * );
     30                virtual Statement *mutate( FallthruStmt * );
     31                virtual Statement *mutate( CaseStmt * );
     32          private:
     33                bool insideChoose;
     34        };
    3535} // namespace ControlStruct
    3636
    3737#endif // CHOOSE_MUTATOR_H
    3838
    39 /*
    40   Local Variables:
    41   mode: c++
    42   End:
    43 */
    4439// Local Variables: //
    4540// tab-width: 4 //
  • translator/ControlStruct/ForExprMutator.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// ForExprMutator.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 15:31:47 2015
     13// Update Count     : 2
    1414//
     15
    1516#include "SynTree/Mutator.h"
    1617#include "SynTree/Statement.h"
     
    1819
    1920namespace ControlStruct {
    20     Statement *ForExprMutator::mutate( ForStmt *forStmt ) {
    21         // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)
    22         forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );
    23         if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {
    24             // create compound statement, move initializer declaration outside, leave _for_ as-is
    25             CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    26             std::list<Statement *> &stmts = block->get_kids();
     21        Statement *ForExprMutator::mutate( ForStmt *forStmt ) {
     22                // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)
     23                forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );
     24                if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {
     25                        // create compound statement, move initializer declaration outside, leave _for_ as-is
     26                        CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     27                        std::list<Statement *> &stmts = block->get_kids();
    2728
    28             stmts.push_back( decl );
    29             forStmt->set_initialization( 0 );
    30             stmts.push_back( forStmt );
     29                        stmts.push_back( decl );
     30                        forStmt->set_initialization( 0 );
     31                        stmts.push_back( forStmt );
    3132
    32             return block;
    33         } // if
     33                        return block;
     34                } // if
    3435
    35         return forStmt;
    36     }
     36                return forStmt;
     37        }
    3738} // namespace ControlStruct
     39
    3840// Local Variables: //
    3941// tab-width: 4 //
  • translator/ControlStruct/ForExprMutator.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// ForExprMutator.h --
    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 15:25:19 2015
     13// Update Count     : 2
    1414//
     15
    1516#ifndef FOR_MUTATOR_H
    1617#define FOR_MUTATOR_H
    1718
    1819#include "SynTree/Mutator.h"
    19 
    2020#include "utility.h"
    2121
    2222namespace ControlStruct {
    23     class ForExprMutator : public Mutator {
    24       public:
    25         virtual Statement *mutate( ForStmt * );
    26     };
     23        class ForExprMutator : public Mutator {
     24          public:
     25                virtual Statement *mutate( ForStmt * );
     26        };
    2727} // namespace ControlStruct
    2828
    2929#endif // CHOOSE_MUTATOR_H
    3030
    31 /*
    32   Local Variables:
    33   mode: c++
    34   End:
    35 */
    3631// Local Variables: //
    3732// tab-width: 4 //
  • translator/ControlStruct/LabelFixer.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// LabelFixer.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 15:25:59 2015
     13// Update Count     : 1
    1414//
     15
    1516#include <list>
    1617#include <cassert>
     
    2324
    2425namespace ControlStruct {
    25     LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) {
    26         if ( from != 0 )
    27             usage.push_back( from );
    28     }
    29 
    30     bool LabelFixer::Entry::insideLoop() {
    31         return ( dynamic_cast< ForStmt * > ( definition ) ||
    32                  dynamic_cast< WhileStmt * > ( definition )  );
    33     }
    34 
    35     LabelFixer::LabelFixer( LabelGenerator *gen ) : generator ( gen ) {
    36         if ( generator == 0 )
    37             generator = LabelGenerator::getGenerator();
    38     }
    39 
    40     void LabelFixer::visit( FunctionDecl *functionDecl ) {
    41         if ( functionDecl->get_statements() != 0 )
    42             functionDecl->get_statements()->accept( *this );
    43 
    44         MLEMutator mlemut( resolveJumps(), generator );
    45         functionDecl->acceptMutator( mlemut );
    46     }
    47 
    48     void LabelFixer::visit( Statement *stmt ) {
    49         std::list< Label > &labels = stmt->get_labels();
    50 
    51         if ( ! labels.empty() ) {
    52             Label current = setLabelsDef( labels, stmt );
    53             labels.clear();
    54             labels.push_front( current );
    55         } // if
    56     }
    57 
    58     void LabelFixer::visit( BranchStmt *branchStmt ) {
    59         visit ( ( Statement * )branchStmt );  // the labels this statement might have
    60 
    61         Label target;
    62         if ( (target = branchStmt->get_target()) != "" ) {
    63             setLabelsUsg( target, branchStmt );
    64         } //else       /* computed goto or normal exit-loop statements */
    65     }
    66 
    67     Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) {
    68         assert( definition != 0 );
    69         Entry *entry = new Entry( definition );
    70         bool used = false;
    71 
    72         for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ )
    73             if ( labelTable.find( *i ) == labelTable.end() )
    74                 { used = true; labelTable[ *i ] = entry; } // undefined and unused
    75             else
    76                 if ( labelTable[ *i ]->defined() )
    77                     throw SemanticError( "Duplicate definition of label: " + *i );
    78                 else
    79                     labelTable[ *i ]->set_definition( definition );
    80 
    81         if (! used ) delete entry;
    82 
    83         return labelTable[ llabel.front() ]->get_label();  // this *must* exist
    84     }
    85 
    86     Label LabelFixer::setLabelsUsg( Label orgValue, Statement *use ) {
    87         assert( use != 0 );
    88 
    89         if ( labelTable.find( orgValue ) != labelTable.end() )
    90             labelTable[ orgValue ]->add_use( use );         // the label has been defined or used before
    91         else
    92             labelTable[ orgValue ] = new Entry( 0, use );
    93 
    94         return labelTable[ orgValue ]->get_label();
    95     }
    96 
    97     std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {
    98         std::map< Statement *, Entry * > def_us;
    99 
    100         for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) {
    101             Entry *e = i->second;
    102 
    103             if ( def_us.find ( e->get_definition() ) == def_us.end() )
    104                 def_us[ e->get_definition() ] = e;
    105             else
    106                 if ( e->used() )
    107                     def_us[ e->get_definition() ]->add_uses( e->get_uses() );
     26        LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) {
     27                if ( from != 0 )
     28                        usage.push_back( from );
    10829        }
    10930
    110         // get rid of labelTable
    111         for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) {
    112             Statement *to = (*i).first;
    113             std::list< Statement *> &from = (*i).second->get_uses();
    114             Label finalLabel = generator->newLabel();
    115             (*i).second->set_label( finalLabel );
     31        bool LabelFixer::Entry::insideLoop() {
     32                return ( dynamic_cast< ForStmt * > ( definition ) ||
     33                                 dynamic_cast< WhileStmt * > ( definition )  );
     34        }
    11635
    117             if ( to == 0 ) {
    118                 BranchStmt *first_use = dynamic_cast<BranchStmt *>(from.back());
    119                 Label undef("");
    120                 if ( first_use != 0 )
    121                     undef = first_use->get_target();
    122                 throw SemanticError ( "'" + undef + "' label not defined");
    123             }
     36        LabelFixer::LabelFixer( LabelGenerator *gen ) : generator ( gen ) {
     37                if ( generator == 0 )
     38                        generator = LabelGenerator::getGenerator();
     39        }
    12440
    125             to->get_labels().clear();
    126             to->get_labels().push_back( finalLabel );
     41        void LabelFixer::visit( FunctionDecl *functionDecl ) {
     42                if ( functionDecl->get_statements() != 0 )
     43                        functionDecl->get_statements()->accept( *this );
    12744
    128             for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) {
    129                 BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j );
    130                 assert( jumpTo != 0 );
    131                 jumpTo->set_target( finalLabel );
    132             } // for
    133         } // for
     45                MLEMutator mlemut( resolveJumps(), generator );
     46                functionDecl->acceptMutator( mlemut );
     47        }
    13448
    135         // reverse table
    136         std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
    137         for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ )
    138             (*ret)[ (*i).second->get_label() ] = (*i).first;
     49        void LabelFixer::visit( Statement *stmt ) {
     50                std::list< Label > &labels = stmt->get_labels();
    13951
    140         return ret;
    141     }
     52                if ( ! labels.empty() ) {
     53                        Label current = setLabelsDef( labels, stmt );
     54                        labels.clear();
     55                        labels.push_front( current );
     56                } // if
     57        }
     58
     59        void LabelFixer::visit( BranchStmt *branchStmt ) {
     60                visit ( ( Statement * )branchStmt );  // the labels this statement might have
     61
     62                Label target;
     63                if ( (target = branchStmt->get_target()) != "" ) {
     64                        setLabelsUsg( target, branchStmt );
     65                } //else       /* computed goto or normal exit-loop statements */
     66        }
     67
     68        Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) {
     69                assert( definition != 0 );
     70                Entry *entry = new Entry( definition );
     71                bool used = false;
     72
     73                for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ )
     74                        if ( labelTable.find( *i ) == labelTable.end() )
     75                                { used = true; labelTable[ *i ] = entry; } // undefined and unused
     76                        else
     77                                if ( labelTable[ *i ]->defined() )
     78                                        throw SemanticError( "Duplicate definition of label: " + *i );
     79                                else
     80                                        labelTable[ *i ]->set_definition( definition );
     81
     82                if ( ! used ) delete entry;
     83
     84                return labelTable[ llabel.front() ]->get_label();  // this *must* exist
     85        }
     86
     87        Label LabelFixer::setLabelsUsg( Label orgValue, Statement *use ) {
     88                assert( use != 0 );
     89
     90                if ( labelTable.find( orgValue ) != labelTable.end() )
     91                        labelTable[ orgValue ]->add_use( use );         // the label has been defined or used before
     92                else
     93                        labelTable[ orgValue ] = new Entry( 0, use );
     94
     95                return labelTable[ orgValue ]->get_label();
     96        }
     97
     98        std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {
     99                std::map< Statement *, Entry * > def_us;
     100
     101                for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) {
     102                        Entry *e = i->second;
     103
     104                        if ( def_us.find ( e->get_definition() ) == def_us.end() )
     105                                def_us[ e->get_definition() ] = e;
     106                        else
     107                                if ( e->used() )
     108                                        def_us[ e->get_definition() ]->add_uses( e->get_uses() );
     109                }
     110
     111                // get rid of labelTable
     112                for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) {
     113                        Statement *to = (*i).first;
     114                        std::list< Statement *> &from = (*i).second->get_uses();
     115                        Label finalLabel = generator->newLabel();
     116                        (*i).second->set_label( finalLabel );
     117
     118                        if ( to == 0 ) {
     119                                BranchStmt *first_use = dynamic_cast<BranchStmt *>(from.back());
     120                                Label undef("");
     121                                if ( first_use != 0 )
     122                                        undef = first_use->get_target();
     123                                throw SemanticError ( "'" + undef + "' label not defined");
     124                        }
     125
     126                        to->get_labels().clear();
     127                        to->get_labels().push_back( finalLabel );
     128
     129                        for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) {
     130                                BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j );
     131                                assert( jumpTo != 0 );
     132                                jumpTo->set_target( finalLabel );
     133                        } // for
     134                } // for
     135
     136                // reverse table
     137                std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
     138                for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ )
     139                        (*ret)[ (*i).second->get_label() ] = (*i).first;
     140
     141                return ret;
     142        }
    142143}  // namespace ControlStruct
     144
    143145// Local Variables: //
    144146// tab-width: 4 //
  • translator/ControlStruct/LabelFixer.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// LabelFixer.h --
    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 15:31:55 2015
     13// Update Count     : 3
    1414//
     15
    1516#ifndef LABEL_FIXER_H
    1617#define LABEL_FIXER_H
    1718
    1819#include "utility.h"
    19 
    2020#include "SynTree/SynTree.h"
    2121#include "SynTree/Visitor.h"
    22 
    2322#include "LabelGenerator.h"
    2423
     
    2625
    2726namespace ControlStruct {
    28     class LabelFixer : public Visitor {
    29         typedef Visitor Parent;
    30       public:
    31         LabelFixer( LabelGenerator *gen = 0 );
     27        class LabelFixer : public Visitor {
     28                typedef Visitor Parent;
     29          public:
     30                LabelFixer( LabelGenerator *gen = 0 );
    3231
    33         std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );
     32                std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );
    3433
    35         // Declarations
    36         virtual void visit( FunctionDecl *functionDecl );
     34                // Declarations
     35                virtual void visit( FunctionDecl *functionDecl );
    3736
    38         // Statements
    39         void visit( Statement *stmt );
     37                // Statements
     38                void visit( Statement *stmt );
    4039
    41         virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    42         virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    43         virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    44         virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    45         virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    46         virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    47         virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    48         virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    49         virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    50         virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    51         virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    52         virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    53         virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    54         virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    55         virtual void visit( BranchStmt *branchStmt );
     40                virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     41                virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     42                virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     43                virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     44                virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     45                virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     46                virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     47                virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     48                virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     49                virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     50                virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     51                virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     52                virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     53                virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
     54                virtual void visit( BranchStmt *branchStmt );
    5655
    57         Label setLabelsDef( std::list< Label > &, Statement *definition );
    58         Label setLabelsUsg( Label, Statement *usage = 0 );
     56                Label setLabelsDef( std::list< Label > &, Statement *definition );
     57                Label setLabelsUsg( Label, Statement *usage = 0 );
    5958
    60       private:
    61         class Entry {
    62           public:
    63             Entry( Statement *to = 0, Statement *from = 0 );
    64             bool used() { return ( usage.empty() ); }
    65             bool defined() { return ( definition != 0 ); }
    66             bool insideLoop();
     59          private:
     60                class Entry {
     61                  public:
     62                        Entry( Statement *to = 0, Statement *from = 0 );
     63                        bool used() { return ( usage.empty() ); }
     64                        bool defined() { return ( definition != 0 ); }
     65                        bool insideLoop();
    6766
    68             Label get_label() const { return label; }
    69             Statement *get_definition() const { return definition; }
    70             std::list< Statement *> &get_uses() { return usage; }
     67                        Label get_label() const { return label; }
     68                        Statement *get_definition() const { return definition; }
     69                        std::list< Statement *> &get_uses() { return usage; }
    7170
    72             void add_use ( Statement *use ) { usage.push_back( use ); }
    73             void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); }
    74             void set_definition( Statement *def ) { definition = def; }
     71                        void add_use ( Statement *use ) { usage.push_back( use ); }
     72                        void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); }
     73                        void set_definition( Statement *def ) { definition = def; }
    7574
    76             void set_label( Label lab ) { label = lab; }
    77             Label gset_label() const { return label; }
    78           private:
    79             Label label; 
    80             Statement *definition;
    81             std::list<Statement *> usage;
     75                        void set_label( Label lab ) { label = lab; }
     76                        Label gset_label() const { return label; }
     77                  private:
     78                        Label label; 
     79                        Statement *definition;
     80                        std::list<Statement *> usage;
     81                };
     82                 
     83                std::map < Label, Entry *> labelTable;
     84                LabelGenerator *generator;
    8285        };
    83              
    84         std::map < Label, Entry *> labelTable;
    85         LabelGenerator *generator;
    86     };
    8786} // namespace ControlStruct
    8887
    8988#endif // LABEL_FIXER_H
    9089
    91 /*
    92   Local Variables:
    93   mode: c++
    94   End:
    95 */
    9690// Local Variables: //
    9791// tab-width: 4 //
  • translator/ControlStruct/LabelGenerator.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// LabelGenerator.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 15:32:04 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <iostream>
    1617#include <strstream>
     
    1920
    2021namespace ControlStruct {
    21     LabelGenerator *LabelGenerator::labelGenerator = 0;
     22        LabelGenerator *LabelGenerator::labelGenerator = 0;
    2223
    23     LabelGenerator *LabelGenerator::getGenerator() {
    24         if ( LabelGenerator::labelGenerator == 0 )
    25             LabelGenerator::labelGenerator = new LabelGenerator();
     24        LabelGenerator *LabelGenerator::getGenerator() {
     25                if ( LabelGenerator::labelGenerator == 0 )
     26                        LabelGenerator::labelGenerator = new LabelGenerator();
    2627
    27         return labelGenerator;
    28     }
     28                return labelGenerator;
     29        }
    2930
    30     Label LabelGenerator::newLabel() {
    31         std::ostrstream os;
    32         os << "__L" << current++ << "__";// << std::ends;
    33         os.freeze( false );
    34         std::string ret = std::string (os.str(), os.pcount());
    35         return Label( ret );
    36     }
     31        Label LabelGenerator::newLabel() {
     32                std::ostrstream os;
     33                os << "__L" << current++ << "__";// << std::ends;
     34                os.freeze( false );
     35                std::string ret = std::string (os.str(), os.pcount());
     36                return Label( ret );
     37        }
    3738} // namespace ControlStruct
     39
    3840// Local Variables: //
    3941// tab-width: 4 //
  • translator/ControlStruct/LabelGenerator.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// LabelGenerator.h --
    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 15:33:20 2015
     13// Update Count     : 3
    1414//
     15
    1516#ifndef LABEL_GENERATOR_H
    1617#define LABEL_GENERATOR_H
     
    1920
    2021namespace ControlStruct {
    21     class LabelGenerator {
    22       public:
    23         static LabelGenerator *getGenerator();
    24         Label newLabel();
    25         void reset() { current = 0; }
    26         void rewind() { current--; }
    27       protected:
    28         LabelGenerator(): current(0) {}
    29       private:
    30         int current;
    31         static LabelGenerator *labelGenerator;
    32     };
     22        class LabelGenerator {
     23          public:
     24                static LabelGenerator *getGenerator();
     25                Label newLabel();
     26                void reset() { current = 0; }
     27                void rewind() { current--; }
     28          protected:
     29                LabelGenerator(): current(0) {}
     30          private:
     31                int current;
     32                static LabelGenerator *labelGenerator;
     33        };
    3334} // namespace ControlStruct
    3435
    3536#endif // LABEL_GENERATOR_H
    3637
    37 /*
    38   Local Variables:
    39   mode: c++
    40   End:
    41 */
    4238// Local Variables: //
    4339// tab-width: 4 //
  • translator/ControlStruct/LabelTypeChecker.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// LabelTypeChecker.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 15:32:15 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <list>
    1617#include <cassert>
     
    2324#include "LabelTypeChecker.h"
    2425
     26namespace ControlStruct {
     27        void LabelTypeChecker::visit(UntypedExpr *untypedExpr) {
     28                assert( untypedExpr != 0 );
     29                NameExpr *fname;
     30                if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0)
     31                         && fname->get_name() == std::string("LabAddress") )
     32                        std::cerr << "Taking the label of an address." << std::endl;
     33                else {
     34                        acceptAll( untypedExpr->get_results(), *this );
     35                        acceptAll( untypedExpr->get_args(), *this );
     36                } // if
     37                return;
     38        }
    2539
    26 namespace ControlStruct {
    27     void LabelTypeChecker::visit(UntypedExpr *untypedExpr){
    28         assert( untypedExpr != 0 );
    29         NameExpr *fname;
    30         if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0)
    31             && fname->get_name() == std::string("LabAddress") )
    32             std::cerr << "Taking the label of an address." << std::endl;
    33         else {
    34             acceptAll( untypedExpr->get_results(), *this );
    35             acceptAll( untypedExpr->get_args(), *this );
    36         } // if
    37         return;
    38     }
     40        void LabelTypeChecker::visit(CompoundStmt *compoundStmt) {
     41                index.enterScope();
     42                acceptAll( compoundStmt->get_kids(), *this );
     43                index.leaveScope();
     44        }
    3945
    40     void LabelTypeChecker::visit(CompoundStmt *compoundStmt) {
    41         index.enterScope();
    42         acceptAll( compoundStmt->get_kids(), *this );
    43         index.leaveScope();
    44     }
     46        void LabelTypeChecker::visit(DeclStmt *declStmt) {
     47                declStmt->accept( index );
    4548
    46     void LabelTypeChecker::visit(DeclStmt *declStmt){
    47         declStmt->accept( index );
     49                //ObjectDecl *odecl = 0;
     50                // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ) {
     51                return;
     52        }
    4853
    49         //ObjectDecl *odecl = 0;
    50         // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ){
    51         return;
    52     }
     54        void LabelTypeChecker::visit(BranchStmt *branchStmt) {
     55                if ( branchStmt->get_type() != BranchStmt::Goto ) return;
     56                Expression *target;
     57                if ( (target = branchStmt->get_computedTarget()) == 0 ) return;
    5358
    54     void LabelTypeChecker::visit(BranchStmt *branchStmt) {
    55         if ( branchStmt->get_type() != BranchStmt::Goto ) return;
    56         Expression *target;
    57         if ( (target = branchStmt->get_computedTarget()) == 0 ) return;
     59                NameExpr *name;
     60                if ( ((name = dynamic_cast<NameExpr *>(target)) == 0) )
     61                        return; // Not a name expression
     62       
     63                std::list< DeclarationWithType * > interps;
     64                index.lookupId(name->get_name(), interps);
     65                if ( interps.size() != 1)
     66                        // in case of multiple declarations
     67                        throw SemanticError("Illegal label expression: " + name->get_name() );
    5868
    59         NameExpr *name;
    60         if ( ((name = dynamic_cast<NameExpr *>(target)) == 0) )
    61             return; // Not a name expression
    62    
    63         std::list< DeclarationWithType * > interps;
    64         index.lookupId(name->get_name(), interps);
    65         if ( interps.size() != 1)
    66             // in case of multiple declarations
    67             throw SemanticError("Illegal label expression: " + name->get_name() );
     69                PointerType *ptr;
     70                if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 )
     71                        if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 )
     72                                return;
     73                        else
     74                                throw SemanticError("Wrong type of parameter for computed goto");
     75                else
     76                        throw SemanticError("Wrong type of parameter for computed goto");
    6877
    69         PointerType *ptr;
    70         if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 )
    71             if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 )
    7278                return;
    73             else
    74                 throw SemanticError("Wrong type of parameter for computed goto");
    75         else
    76             throw SemanticError("Wrong type of parameter for computed goto");
     79        }
     80} // namespace ControlStruct
    7781
    78         return;
    79     }
    80 } // namespace ControlStruct
    8182// Local Variables: //
    8283// tab-width: 4 //
  • translator/ControlStruct/LabelTypeChecker.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// LabelTypeChecker.h --
    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 15:33:47 2015
     13// Update Count     : 3
    1414//
     15
    1516#ifndef LABEL_TYPE_H
    1617#define LABEL_TYPE_H
     
    2324
    2425namespace ControlStruct {
    25     class LabelTypeChecker : public Visitor {
    26       public:
    27         //LabelTypeChecker() {
     26        class LabelTypeChecker : public Visitor {
     27          public:
     28                //LabelTypeChecker() {
    2829
    29         virtual void visit( CompoundStmt *compoundStmt );
    30         virtual void visit( DeclStmt *declStmt );
    31         virtual void visit( BranchStmt *branchStmt );
    32         virtual void visit( UntypedExpr *untypedExpr );
    33       private:
    34         SymTab::Indexer index;
    35     };
     30                virtual void visit( CompoundStmt *compoundStmt );
     31                virtual void visit( DeclStmt *declStmt );
     32                virtual void visit( BranchStmt *branchStmt );
     33                virtual void visit( UntypedExpr *untypedExpr );
     34          private:
     35                SymTab::Indexer index;
     36        };
    3637} // namespace ControlStruct
    3738
    3839#endif // LABEL_TYPE_H
    39 
    40 /*
    41   Local Variables:
    42   mode: c++
    43   End:
    44 */
    45 
    46 
    4740
    4841// Local Variables: //
  • translator/ControlStruct/MLEMutator.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// MLEMutator.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
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 15:32:26 2015
     13// Update Count     : 2
     14//
     15
    1516#include <cassert>
    1617#include <algorithm>
     
    1920#include "SynTree/Statement.h"
    2021
    21 
    2222namespace ControlStruct {
    23     MLEMutator::~MLEMutator() {
    24         delete targetTable;
    25         targetTable = 0;
    26     }
    27 
    28     CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) {
    29         bool labeledBlock = false;
    30         if ( !((cmpndStmt->get_labels()).empty()) ) {
    31             labeledBlock = true;
    32             enclosingBlocks.push_back( Entry( cmpndStmt ) );
    33         }
    34 
    35         std::list< Statement * > &kids = cmpndStmt->get_kids();
    36         for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) {
    37             *k = (*k)->acceptMutator(*this);
    38 
    39             if ( ! get_breakLabel().empty() ) {
    40                 std::list< Statement * >::iterator next = k; next++;
    41                 if ( next == kids.end() ) {
    42                     std::list<Label> ls; ls.push_back( get_breakLabel() );
    43                     kids.push_back( new NullStmt( ls ) );
    44                 } else
    45                     (*next)->get_labels().push_back( get_breakLabel() );
    46 
    47                 set_breakLabel("");
    48             } // if
    49         } // for
    50 
    51         if ( labeledBlock ) {
    52             assert( ! enclosingBlocks.empty() );
    53             if ( ! enclosingBlocks.back().get_breakExit().empty() )
    54                 set_breakLabel( enclosingBlocks.back().get_breakExit() );
    55             enclosingBlocks.pop_back();
    56         } // if
    57 
    58         //mutateAll( cmpndStmt->get_kids(), *this );
    59         return cmpndStmt;
    60     }
    61 
    62     Statement *MLEMutator::mutate( WhileStmt *whileStmt ) {
    63         enclosingLoops.push_back( Entry( whileStmt ) );
    64         whileStmt->set_body ( whileStmt->get_body()->acceptMutator( *this ) );
    65 
    66         Entry &e = enclosingLoops.back();
    67         assert ( e == whileStmt );
    68         whileStmt->set_body( mutateLoop( whileStmt->get_body(), e ) );
    69         enclosingLoops.pop_back();
    70 
    71         return whileStmt;
    72     }
    73 
    74     Statement *MLEMutator::mutate( ForStmt *forStmt ) {
    75         enclosingLoops.push_back( Entry( forStmt ) );
    76         maybeMutate( forStmt->get_body(), *this );
    77 
    78         Entry &e = enclosingLoops.back();
    79         assert ( e == forStmt );
    80         forStmt->set_body( mutateLoop( forStmt->get_body(), e ) );
    81         enclosingLoops.pop_back();
    82 
    83         return forStmt;
    84     }
    85 
    86     Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) {
    87         if ( branchStmt->get_type() == BranchStmt::Goto )
    88             return branchStmt;
    89 
    90         // test if continue target is a loop
    91         if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() )
    92             throw SemanticError( "'continue' outside a loop" );
    93 
    94         if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) )
    95             throw SemanticError( "'break' outside a loop or switch" );
    96 
    97         if ( branchStmt->get_target() == "" ) return branchStmt;
    98 
    99         if ( targetTable->find( branchStmt->get_target() ) == targetTable->end() )
    100             throw SemanticError("The label defined in the exit loop statement does not exist." );  // shouldn't happen (since that's already checked)
    101 
    102         std::list< Entry >::iterator check;
    103         if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() )
    104             // not in loop, checking if in block
    105             if ( (check = std::find( enclosingBlocks.begin(), enclosingBlocks.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingBlocks.end() )
    106                 // neither in loop nor in block, checking if in switch/choose
    107                 if ( (check = std::find( enclosingSwitches.begin(), enclosingSwitches.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingSwitches.end() )
    108                     throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing loop.");
    109 
    110         if ( enclosingLoops.back() == (*check) )
    111             return branchStmt;                          // exit the innermost loop (labels unnecessary)
    112 
    113         Label newLabel;
    114         switch ( branchStmt->get_type() ) {
    115           case BranchStmt::Break:
    116             if ( check->get_breakExit() != "" )
    117                 newLabel = check->get_breakExit();
    118             else {
    119                 newLabel = generator->newLabel();
    120                 check->set_breakExit( newLabel );
    121             } // if
    122             break;
    123           case BranchStmt::Continue:
    124             if ( check->get_contExit() != "" )
    125                 newLabel = check->get_contExit();
    126             else {
    127                 newLabel = generator->newLabel();
    128                 check->set_contExit( newLabel );
    129             } // if
    130             break;
    131           default:
    132             return 0;                                   // shouldn't be here
    133         } // switch
    134 
    135         return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto );
    136     }
    137 
    138 
    139     Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) {
    140         Label brkLabel = generator->newLabel();
    141         enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) );
    142         mutateAll( switchStmt->get_branches(), *this ); {
    143             // check if this is necessary (if there is a break to this point, otherwise do not generate
    144             std::list<Label> temp; temp.push_back( brkLabel );
    145             switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
    146         }
    147         assert ( enclosingSwitches.back() == switchStmt );
    148         enclosingSwitches.pop_back();
    149         return switchStmt;
    150     }
    151 
    152     Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) {
    153         Label brkLabel = generator->newLabel();
    154         enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) );
    155         mutateAll( switchStmt->get_branches(), *this ); {
    156             // check if this is necessary (if there is a break to this point, otherwise do not generate
    157             std::list<Label> temp; temp.push_back( brkLabel );
    158             switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
    159         }
    160         assert ( enclosingSwitches.back() == switchStmt );
    161         enclosingSwitches.pop_back();
    162         return switchStmt;
    163     }
    164 
    165     Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
    166         CompoundStmt *newBody;
    167         if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {
    168             newBody = new CompoundStmt( std::list< Label >() );
    169             newBody->get_kids().push_back( bodyLoop );
    170         } // if
    171 
    172         Label endLabel = e.get_contExit();
    173 
    174         if ( e.get_breakExit() != "" ) {
    175             if ( endLabel == "" ) endLabel = generator->newLabel();
    176             // check for whether this label is used or not, so as to not generate extraneous gotos
    177             if (e.breakExitUsed)
    178                 newBody->get_kids().push_back( new BranchStmt( std::list< Label >(), endLabel, BranchStmt::Goto ) );
    179             // xxx
    180             //std::list< Label > ls; ls.push_back( e.get_breakExit() );
    181             set_breakLabel( e.get_breakExit() );
    182             //newBody->get_kids().push_back( new BranchStmt( ls, "", BranchStmt::Break ) );
    183         } // if
    184 
    185         if ( e.get_breakExit() != "" || e.get_contExit() != "" ){
    186             if (dynamic_cast< NullStmt *>( newBody->get_kids().back() ))
    187                 newBody->get_kids().back()->get_labels().push_back( endLabel );
    188             else {
    189                 std::list < Label > ls; ls.push_back( endLabel );
    190                 newBody->get_kids().push_back( new NullStmt( ls ) );
    191             } // if
    192         } // if
    193 
    194         return newBody;
    195     }
    196 
    197     //*** Entry's methods
    198     void MLEMutator::Entry::set_contExit( Label l ) {
    199         assert ( contExit == "" || contExit == l );
    200         contExit = l;
    201     }
    202 
    203     void MLEMutator::Entry::set_breakExit( Label l ) {
    204         assert ( breakExit == "" || breakExit == l );
    205         breakExit = l;
    206     }
     23        MLEMutator::~MLEMutator() {
     24                delete targetTable;
     25                targetTable = 0;
     26        }
     27
     28        CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) {
     29                bool labeledBlock = false;
     30                if ( !((cmpndStmt->get_labels()).empty()) ) {
     31                        labeledBlock = true;
     32                        enclosingBlocks.push_back( Entry( cmpndStmt ) );
     33                } // if
     34
     35                std::list< Statement * > &kids = cmpndStmt->get_kids();
     36                for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) {
     37                        *k = (*k)->acceptMutator(*this);
     38
     39                        if ( ! get_breakLabel().empty() ) {
     40                                std::list< Statement * >::iterator next = k; next++;
     41                                if ( next == kids.end() ) {
     42                                        std::list<Label> ls; ls.push_back( get_breakLabel() );
     43                                        kids.push_back( new NullStmt( ls ) );
     44                                } else
     45                                        (*next)->get_labels().push_back( get_breakLabel() );
     46
     47                                set_breakLabel("");
     48                        } // if
     49                } // for
     50
     51                if ( labeledBlock ) {
     52                        assert( ! enclosingBlocks.empty() );
     53                        if ( ! enclosingBlocks.back().get_breakExit().empty() )
     54                                set_breakLabel( enclosingBlocks.back().get_breakExit() );
     55                        enclosingBlocks.pop_back();
     56                } // if
     57
     58                //mutateAll( cmpndStmt->get_kids(), *this );
     59                return cmpndStmt;
     60        }
     61
     62        Statement *MLEMutator::mutate( WhileStmt *whileStmt ) {
     63                enclosingLoops.push_back( Entry( whileStmt ) );
     64                whileStmt->set_body ( whileStmt->get_body()->acceptMutator( *this ) );
     65
     66                Entry &e = enclosingLoops.back();
     67                assert ( e == whileStmt );
     68                whileStmt->set_body( mutateLoop( whileStmt->get_body(), e ) );
     69                enclosingLoops.pop_back();
     70
     71                return whileStmt;
     72        }
     73
     74        Statement *MLEMutator::mutate( ForStmt *forStmt ) {
     75                enclosingLoops.push_back( Entry( forStmt ) );
     76                maybeMutate( forStmt->get_body(), *this );
     77
     78                Entry &e = enclosingLoops.back();
     79                assert ( e == forStmt );
     80                forStmt->set_body( mutateLoop( forStmt->get_body(), e ) );
     81                enclosingLoops.pop_back();
     82
     83                return forStmt;
     84        }
     85
     86        Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) {
     87                if ( branchStmt->get_type() == BranchStmt::Goto )
     88                        return branchStmt;
     89
     90                // test if continue target is a loop
     91                if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() )
     92                        throw SemanticError( "'continue' outside a loop" );
     93
     94                if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) )
     95                        throw SemanticError( "'break' outside a loop or switch" );
     96
     97                if ( branchStmt->get_target() == "" ) return branchStmt;
     98
     99                if ( targetTable->find( branchStmt->get_target() ) == targetTable->end() )
     100                        throw SemanticError("The label defined in the exit loop statement does not exist." );  // shouldn't happen (since that's already checked)
     101
     102                std::list< Entry >::iterator check;
     103                if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() )
     104                        // not in loop, checking if in block
     105                        if ( (check = std::find( enclosingBlocks.begin(), enclosingBlocks.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingBlocks.end() )
     106                                // neither in loop nor in block, checking if in switch/choose
     107                                if ( (check = std::find( enclosingSwitches.begin(), enclosingSwitches.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingSwitches.end() )
     108                                        throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing loop.");
     109
     110                if ( enclosingLoops.back() == (*check) )
     111                        return branchStmt;                              // exit the innermost loop (labels unnecessary)
     112
     113                Label newLabel;
     114                switch ( branchStmt->get_type() ) {
     115                  case BranchStmt::Break:
     116                        if ( check->get_breakExit() != "" )
     117                                newLabel = check->get_breakExit();
     118                        else {
     119                                newLabel = generator->newLabel();
     120                                check->set_breakExit( newLabel );
     121                        } // if
     122                        break;
     123                  case BranchStmt::Continue:
     124                        if ( check->get_contExit() != "" )
     125                                newLabel = check->get_contExit();
     126                        else {
     127                                newLabel = generator->newLabel();
     128                                check->set_contExit( newLabel );
     129                        } // if
     130                        break;
     131                  default:
     132                        return 0;                                       // shouldn't be here
     133                } // switch
     134
     135                return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto );
     136        }
     137
     138
     139        Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) {
     140                Label brkLabel = generator->newLabel();
     141                enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) );
     142                mutateAll( switchStmt->get_branches(), *this ); {
     143                        // check if this is necessary (if there is a break to this point, otherwise do not generate
     144                        std::list<Label> temp; temp.push_back( brkLabel );
     145                        switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
     146                }
     147                assert ( enclosingSwitches.back() == switchStmt );
     148                enclosingSwitches.pop_back();
     149                return switchStmt;
     150        }
     151
     152        Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) {
     153                Label brkLabel = generator->newLabel();
     154                enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) );
     155                mutateAll( switchStmt->get_branches(), *this ); {
     156                        // check if this is necessary (if there is a break to this point, otherwise do not generate
     157                        std::list<Label> temp; temp.push_back( brkLabel );
     158                        switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
     159                }
     160                assert ( enclosingSwitches.back() == switchStmt );
     161                enclosingSwitches.pop_back();
     162                return switchStmt;
     163        }
     164
     165        Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     166                CompoundStmt *newBody;
     167                if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {
     168                        newBody = new CompoundStmt( std::list< Label >() );
     169                        newBody->get_kids().push_back( bodyLoop );
     170                } // if
     171
     172                Label endLabel = e.get_contExit();
     173
     174                if ( e.get_breakExit() != "" ) {
     175                        if ( endLabel == "" ) endLabel = generator->newLabel();
     176                        // check for whether this label is used or not, so as to not generate extraneous gotos
     177                        if (e.breakExitUsed)
     178                                newBody->get_kids().push_back( new BranchStmt( std::list< Label >(), endLabel, BranchStmt::Goto ) );
     179                        // xxx
     180                        //std::list< Label > ls; ls.push_back( e.get_breakExit() );
     181                        set_breakLabel( e.get_breakExit() );
     182                        //newBody->get_kids().push_back( new BranchStmt( ls, "", BranchStmt::Break ) );
     183                } // if
     184
     185                if ( e.get_breakExit() != "" || e.get_contExit() != "" ) {
     186                        if (dynamic_cast< NullStmt *>( newBody->get_kids().back() ))
     187                                newBody->get_kids().back()->get_labels().push_back( endLabel );
     188                        else {
     189                                std::list < Label > ls; ls.push_back( endLabel );
     190                                newBody->get_kids().push_back( new NullStmt( ls ) );
     191                        } // if
     192                } // if
     193
     194                return newBody;
     195        }
     196
     197        //*** Entry's methods
     198        void MLEMutator::Entry::set_contExit( Label l ) {
     199                assert ( contExit == "" || contExit == l );
     200                contExit = l;
     201        }
     202
     203        void MLEMutator::Entry::set_breakExit( Label l ) {
     204                assert ( breakExit == "" || breakExit == l );
     205                breakExit = l;
     206        }
    207207} // namespace ControlStruct
     208
    208209// Local Variables: //
    209210// tab-width: 4 //
  • translator/ControlStruct/MLEMutator.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// MLEMutator.h --
    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 15:32:39 2015
     13// Update Count     : 3
    1414//
     15
    1516#ifndef MLE_MUTATOR_H
    1617#define MLE_MUTATOR_H
     
    2627
    2728namespace ControlStruct {
    28     class MLEMutator : public Mutator {
    29         class Entry;
    30       public:
    31         MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
    32         ~MLEMutator();
     29        class MLEMutator : public Mutator {
     30                class Entry;
     31          public:
     32                MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
     33                ~MLEMutator();
    3334
    34         CompoundStmt *mutate( CompoundStmt *cmpndStmt );
    35         Statement *mutate( WhileStmt *whileStmt );
    36         Statement *mutate( ForStmt *forStmt );
    37         Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError );
     35                CompoundStmt *mutate( CompoundStmt *cmpndStmt );
     36                Statement *mutate( WhileStmt *whileStmt );
     37                Statement *mutate( ForStmt *forStmt );
     38                Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError );
    3839
    39         Statement *mutate( SwitchStmt *switchStmt );
    40         Statement *mutate( ChooseStmt *switchStmt );
     40                Statement *mutate( SwitchStmt *switchStmt );
     41                Statement *mutate( ChooseStmt *switchStmt );
    4142
    42         Statement *mutateLoop( Statement *bodyLoop, Entry &e );
     43                Statement *mutateLoop( Statement *bodyLoop, Entry &e );
    4344
    44         Label &get_breakLabel() { return breakLabel; }
    45         void set_breakLabel( Label newValue ) { breakLabel = newValue; }
    46       private:
    47         class Entry {
    48           public:
    49             explicit Entry( Statement *_loop = 0, Label _contExit = Label(""), Label _breakExit = Label("") ) :
    50                 loop( _loop ), contExit( _contExit ), breakExit( _breakExit ), contExitUsed( false ), breakExitUsed( false ) {}
     45                Label &get_breakLabel() { return breakLabel; }
     46                void set_breakLabel( Label newValue ) { breakLabel = newValue; }
     47          private:
     48                class Entry {
     49                  public:
     50                        explicit Entry( Statement *_loop = 0, Label _contExit = Label(""), Label _breakExit = Label("") ) :
     51                                loop( _loop ), contExit( _contExit ), breakExit( _breakExit ), contExitUsed( false ), breakExitUsed( false ) {}
    5152
    52             bool operator==( const Statement *stmt ) { return ( loop == stmt ); }
    53             bool operator!=( const Statement *stmt ) { return ( loop != stmt ); }
     53                        bool operator==( const Statement *stmt ) { return ( loop == stmt ); }
     54                        bool operator!=( const Statement *stmt ) { return ( loop != stmt ); }
    5455
    55             bool operator==( const Entry &other ) { return ( loop == other.get_loop() ); }
     56                        bool operator==( const Entry &other ) { return ( loop == other.get_loop() ); }
    5657
    57             Statement *get_loop() const { return loop; }
     58                        Statement *get_loop() const { return loop; }
    5859
    59             Label get_contExit() const { return contExit; }
    60             void set_contExit( Label );
     60                        Label get_contExit() const { return contExit; }
     61                        void set_contExit( Label );
    6162
    62             Label get_breakExit() const { return breakExit; }
    63             void set_breakExit( Label );
     63                        Label get_breakExit() const { return breakExit; }
     64                        void set_breakExit( Label );
    6465
    65           private:
    66             Statement *loop;
    67             Label contExit, breakExit;
    68           public: // hack, provide proper [sg]etters
    69             bool contExitUsed, breakExitUsed;
     66                  private:
     67                        Statement *loop;
     68                        Label contExit, breakExit;
     69                  public: // hack, provide proper [sg]etters
     70                        bool contExitUsed, breakExitUsed;
     71                };
     72
     73                std::map< Label, Statement * > *targetTable;
     74                std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches;
     75                Label breakLabel;
     76                LabelGenerator *generator;
    7077        };
    71 
    72         std::map< Label, Statement * > *targetTable;
    73         std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches;
    74         Label breakLabel;
    75         LabelGenerator *generator;
    76     };
    77 
    7878} // namespace ControlStruct
    7979
    80 #endif
     80#endif // MLE_MUTATOR_H
    8181
    82 /*
    83   Local Variables:
    84   mode: c++
    85   End:
    86 */
    8782// Local Variables: //
    8883// tab-width: 4 //
  • translator/ControlStruct/Mutate.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Mutate.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 15:32:52 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <algorithm>
    1617#include <iostream>
     
    3435
    3536namespace ControlStruct {
    36     void mutate( std::list< Declaration * > translationUnit ) {
    37         // ForExprMutator formut;
    38         LabelFixer lfix;
    39         ChooseMutator chmut;
    40         CaseRangeMutator ranges;  // has to run after ChooseMutator
    41         //ExceptMutator exc;
    42         // LabelTypeChecker lbl;
     37        void mutate( std::list< Declaration * > translationUnit ) {
     38                // ForExprMutator formut;
     39                LabelFixer lfix;
     40                ChooseMutator chmut;
     41                CaseRangeMutator ranges;  // has to run after ChooseMutator
     42                //ExceptMutator exc;
     43                // LabelTypeChecker lbl;
    4344
    44         // mutateAll( translationUnit, formut );
    45         acceptAll( translationUnit, lfix );
    46         mutateAll( translationUnit, chmut );
    47         mutateAll( translationUnit, ranges );
    48         //mutateAll( translationUnit, exc );
    49         //acceptAll( translationUnit, lbl );
    50     }
     45                // mutateAll( translationUnit, formut );
     46                acceptAll( translationUnit, lfix );
     47                mutateAll( translationUnit, chmut );
     48                mutateAll( translationUnit, ranges );
     49                //mutateAll( translationUnit, exc );
     50                //acceptAll( translationUnit, lbl );
     51        }
    5152} // namespace CodeGen
     53
    5254// Local Variables: //
    5355// tab-width: 4 //
  • translator/ControlStruct/Mutate.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Mutate.h --
    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 15:31:20 2015
     13// Update Count     : 2
    1414//
     15
    1516#ifndef CTRLS_MUTATE_H
    1617#define CTRLS_MUTATE_H
     
    2223
    2324namespace ControlStruct {
    24     void mutate( std::list< Declaration* > translationUnit );
     25        void mutate( std::list< Declaration* > translationUnit );
    2526} // namespace ControlStruct
    2627
    2728#endif // CTRLS_MUTATE_H
    2829
    29 /*
    30   Local Variables:
    31   mode: c++
    32   End:
    33 */
    3430// Local Variables: //
    3531// tab-width: 4 //
  • translator/Designators/Processor.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Processor.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 16:23:10 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <vector>
    1617#include <algorithm>
     
    2021
    2122namespace Designators {
    22     Matcher::Matcher( const std::list< DeclarationWithType * > &decls ) {
    23         int cnt = 0;
    24         for ( std::list< DeclarationWithType * >::const_iterator i = decls.begin();
    25              i != decls.end(); i++, cnt++ ) {
    26             std::string newName = (*i)->get_name();
    27             if ( table.find( newName ) == table.end() ) {
    28                 table.insert( std::pair<std::string, int>(newName, cnt) );
    29                 order.push_back( newName );
    30                 declarations.push_back( *i );
    31                 alternatives.push_back( 0 );
    32             }
     23        Matcher::Matcher( const std::list< DeclarationWithType * > &decls ) {
     24                int cnt = 0;
     25                for ( std::list< DeclarationWithType * >::const_iterator i = decls.begin();
     26                          i != decls.end(); i++, cnt++ ) {
     27                        std::string newName = (*i)->get_name();
     28                        if ( table.find( newName ) == table.end() ) {
     29                                table.insert( std::pair<std::string, int>(newName, cnt) );
     30                                order.push_back( newName );
     31                                declarations.push_back( *i );
     32                                alternatives.push_back( 0 );
     33                        } // if
     34                } // for
    3335        }
    34     }
    3536
    36     template< class InputIterator >
    37     bool Matcher::add(InputIterator begin, InputIterator end, ResolvExpr::Alternative &alt ) {
    38         while ( begin != end ) {
    39             if ( table.find( *begin ) != table.end() )
    40                 alternatives[ table[ *begin ] ] = new ResolvExpr::Alternative(alt);
    41             else
    42                 return false;
    43             begin++;
     37        template< class InputIterator >
     38        bool Matcher::add(InputIterator begin, InputIterator end, ResolvExpr::Alternative &alt ) {
     39                while ( begin != end ) {
     40                        if ( table.find( *begin ) != table.end() )
     41                                alternatives[ table[ *begin ] ] = new ResolvExpr::Alternative(alt);
     42                        else
     43                                return false;
     44                        begin++;
     45                } // while
     46                return true;
    4447        }
    45         return true;
    46     }
    4748
    48     template< class InputIterator, class OutputIterator >
    49     bool Matcher::slice(InputIterator begin, InputIterator end, OutputIterator out ) {
    50         while ( begin != end )
    51             if ( table.find( *begin ) != table.end() )
    52                 *out++ = declarations [ table[ *begin++ ] ];
    53             else
    54                 return false; // throw 0;
    55         return true;
    56     }
     49        template< class InputIterator, class OutputIterator >
     50        bool Matcher::slice(InputIterator begin, InputIterator end, OutputIterator out ) {
     51                while ( begin != end )
     52                        if ( table.find( *begin ) != table.end() )
     53                                *out++ = declarations [ table[ *begin++ ] ];
     54                        else
     55                                return false; // throw 0;
     56                return true;
     57        }
    5758
    58     template< class OutputIterator >
    59     bool Matcher::get_reorderedCall( OutputIterator out ) {
    60         // fill call with defaults, if need be
    61         for (Matcher::iterator o = begin(); o != end(); o++ )
    62             if ( alternatives[ table[ *o ] ] == 0 )
    63                 return false;
    64             else
    65                 out++ = *alternatives[table[ *o ]];
    66         return true;
    67     }
     59        template< class OutputIterator >
     60        bool Matcher::get_reorderedCall( OutputIterator out ) {
     61                // fill call with defaults, if need be
     62                for (Matcher::iterator o = begin(); o != end(); o++ )
     63                        if ( alternatives[ table[ *o ] ] == 0 )
     64                                return false;
     65                        else
     66                                out++ = *alternatives[table[ *o ]];
     67                return true;
     68        }
    6869
    69     bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation ) {
    70         // Distribute `designation' over alternatives contained in `finder'
    71         if ( ! designation) return false;
    72         else
    73             for ( ResolvExpr::AlternativeFinder::iterator alt = finder.begin(); alt != finder.end(); alt++ )
    74                 alt->expr->set_argName( designation );
    75         return true;
    76     }
     70        bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation ) {
     71                // Distribute `designation' over alternatives contained in `finder'
     72                if ( ! designation) return false;
     73                else
     74                        for ( ResolvExpr::AlternativeFinder::iterator alt = finder.begin(); alt != finder.end(); alt++ )
     75                                alt->expr->set_argName( designation );
     76                return true;
     77        }
    7778
    78     template < class OutputIterator >
    79     bool extractNames( Expression *expr, OutputIterator out, Matcher matcher ) {
    80         Expression *designator = expr->get_argName();
    81         if ( designator == 0 ) return false;
     79        template < class OutputIterator >
     80        bool extractNames( Expression *expr, OutputIterator out, Matcher matcher ) {
     81                Expression *designator = expr->get_argName();
     82                if ( designator == 0 ) return false;
    8283
    83         if ( NameExpr *ndes = dynamic_cast<NameExpr *>(designator) )
    84             out++ = ndes->get_name();
    85         else if ( TupleExpr *tdes = dynamic_cast<TupleExpr *>(designator) ) {
    86             std::cerr << "Tuple designation" << std::endl;
     84                if ( NameExpr *ndes = dynamic_cast<NameExpr *>(designator) )
     85                        out++ = ndes->get_name();
     86                else if ( TupleExpr *tdes = dynamic_cast<TupleExpr *>(designator) ) {
     87                        std::cerr << "Tuple designation" << std::endl;
    8788//      ObjectDecl *decl = extractTupleV(matcher, tdes); // xxx
    88             // transform?
    89             for ( std::list< Expression * >::iterator n = tdes->get_exprs().begin();
    90                 n != tdes->get_exprs().end(); n++ ) {
     89                        // transform?
     90                        for ( std::list< Expression * >::iterator n = tdes->get_exprs().begin();
     91                                  n != tdes->get_exprs().end(); n++ ) {
    9192
    92                 if ( NameExpr *name = dynamic_cast<NameExpr *>(*n) )
    93                     out++ = name->get_name();
    94                 else
    95                     // flatten nested Tuples
    96                     throw SemanticError( "Invalid tuple designation." );
    97             }
     93                                if ( NameExpr *name = dynamic_cast<NameExpr *>(*n) )
     94                                        out++ = name->get_name();
     95                                else
     96                                        // flatten nested Tuples
     97                                        throw SemanticError( "Invalid tuple designation." );
     98                        } // for
     99                } // if
     100                return true;
    98101        }
    99         return true;
    100     }
    101102
    102     std::string extractName( Expression *expr ) /* throw NoNameExtraction */ {
    103         if ( NameExpr *name = dynamic_cast< NameExpr *>(expr) )
    104             return name->get_name();
    105         else /* if () */
    106             throw 0;
    107     }
     103        std::string extractName( Expression *expr ) /* throw NoNameExtraction */ {
     104                if ( NameExpr *name = dynamic_cast< NameExpr *>(expr) )
     105                        return name->get_name();
     106                else /* if () */
     107                        throw 0;
     108        }
    108109
    109     DeclarationWithType *gensym( DeclarationWithType *, std::string prefix ) {
    110         return 0;
    111     }
     110        DeclarationWithType *gensym( DeclarationWithType *, std::string prefix ) {
     111                return 0;
     112        }
    112113
    113     ObjectDecl *extractTupleV( Matcher matcher, TupleExpr *nmTuple ) {
    114         // extract a subtuple of the function `fun' argument list, corresponding to the tuple of names requested by
    115         // `nmTuple'.
    116         std::list< Expression * > &exprs = nmTuple->get_exprs();
    117         std::cerr << "In extractTupleV, the tuple has " << exprs.size() << " components." << std::endl;
    118         std::list< std::string > names;
    119         std::transform( exprs.begin(), exprs.end(), back_inserter(names), extractName );
    120         std::list< DeclarationWithType * > decls;
    121         matcher.slice( names.begin(), names.end(), back_inserter(decls) );
    122         //std::for_each( decls.begin(), decls.end(), gensym );
    123         std::cerr << "Returning declaration with " << decls.size() << " components." << std::endl;
     114        ObjectDecl *extractTupleV( Matcher matcher, TupleExpr *nmTuple ) {
     115                // extract a subtuple of the function `fun' argument list, corresponding to the tuple of names requested by
     116                // `nmTuple'.
     117                std::list< Expression * > &exprs = nmTuple->get_exprs();
     118                std::cerr << "In extractTupleV, the tuple has " << exprs.size() << " components." << std::endl;
     119                std::list< std::string > names;
     120                std::transform( exprs.begin(), exprs.end(), back_inserter(names), extractName );
     121                std::list< DeclarationWithType * > decls;
     122                matcher.slice( names.begin(), names.end(), back_inserter(decls) );
     123                //std::for_each( decls.begin(), decls.end(), gensym );
     124                std::cerr << "Returning declaration with " << decls.size() << " components." << std::endl;
    124125
    125         return 0;//new ObjectDecl()
    126     }
     126                return 0;//new ObjectDecl()
     127        }
    127128
    128     void check_alternative( FunctionType *fun, ResolvExpr::AltList &args ) {
    129         using namespace ResolvExpr;
     129        void check_alternative( FunctionType *fun, ResolvExpr::AltList &args ) {
     130                using namespace ResolvExpr;
    130131
    131         Matcher matcher( fun->get_parameters() );
    132         for ( AltList::iterator a = args.begin(); a != args.end(); a++ ) {
    133             std::list< std::string > actNames;
    134             if ( ! extractNames( a->expr, back_inserter(actNames), matcher ) ) {
    135                 return; // not a designated call, leave alternative alone
    136             } else {
    137                 // see if there's a match
    138                 matcher.add( actNames.begin(), actNames.end(), *a );
    139             }
     132                Matcher matcher( fun->get_parameters() );
     133                for ( AltList::iterator a = args.begin(); a != args.end(); a++ ) {
     134                        std::list< std::string > actNames;
     135                        if ( ! extractNames( a->expr, back_inserter(actNames), matcher ) ) {
     136                                return; // not a designated call, leave alternative alone
     137                        } else {
     138                                // see if there's a match
     139                                matcher.add( actNames.begin(), actNames.end(), *a );
     140                        } // if
     141                } // for
     142                //AltList newArgs;
     143                args.clear();
     144                matcher.get_reorderedCall( back_inserter(args) );
     145
     146                return;
    140147        }
    141         //AltList newArgs;
    142         args.clear();
    143         matcher.get_reorderedCall( back_inserter(args) );
    144 
    145         return;
    146     }
    147148#if 0
    148     void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder &finder ) {
    149         if ( expr->get_argName() != 0 ) {
    150             // Looking at designated expression
    151             using namespace ResolvExpr;
    152             AltList &alternatives = finder.get_alternatives();
    153             std::cerr << "Now printing alternatives: " << std::endl;
    154             for ( AltList::iterator a = alternatives.begin(); a != alternatives.end(); a++ )
    155                 a->expr->print( std::cerr );
    156             //std::cerr << "Looking for constructions of length no more than: " << tdes->get_exprs().size() << "." << std::endl;
     149        void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder &finder ) {
     150                if ( expr->get_argName() != 0 ) {
     151                        // Looking at designated expression
     152                        using namespace ResolvExpr;
     153                        AltList &alternatives = finder.get_alternatives();
     154                        std::cerr << "Now printing alternatives: " << std::endl;
     155                        for ( AltList::iterator a = alternatives.begin(); a != alternatives.end(); a++ )
     156                                a->expr->print( std::cerr );
     157                        //std::cerr << "Looking for constructions of length no more than: " << tdes->get_exprs().size() << "." << std::endl;
     158                }
     159                return;
    157160        }
    158         return;
    159     }
    160161#endif // 0
    161162} // namespaces Designators
     163
    162164// Local Variables: //
    163165// tab-width: 4 //
  • translator/Designators/Processor.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Processor.h --
    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 16:24:34 2015
     13// Update Count     : 3
    1414//
     15
    1516#include "SynTree/Declaration.h"
    1617#include "SynTree/Expression.h"
     
    2425
    2526namespace Designators {
    26   class Matcher;
    27   class GenSym;
     27        class Matcher;
     28        class GenSym;
    2829
    29   template < class OutputIterator >  bool extractNames( std::list< DeclarationWithType * > &, OutputIterator );
    30   template < class OutputIterator >  bool extractNames( Expression *, OutputIterator, Matcher );
    31   void check_alternative( FunctionType *, ResolvExpr::AltList & );
    32   ObjectDecl *extractTupleV( Matcher, TupleExpr *names );
    33   bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation );
    34   DeclarationWithType *gensym( GenSym &, DeclarationWithType * );
     30        template < class OutputIterator >  bool extractNames( std::list< DeclarationWithType * > &, OutputIterator );
     31        template < class OutputIterator >  bool extractNames( Expression *, OutputIterator, Matcher );
     32        void check_alternative( FunctionType *, ResolvExpr::AltList & );
     33        ObjectDecl *extractTupleV( Matcher, TupleExpr *names );
     34        bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation );
     35        DeclarationWithType *gensym( GenSym &, DeclarationWithType * );
    3536
    36   class GenSym {
    37   public:
    38     GenSym( std::string prefix = "" ) : gensym_count(0) {}
    39     GenSym( GenSym &other ) { gensym_count = other.gensym_count; }
     37        class GenSym {
     38          public:
     39                GenSym( std::string prefix = "" ) : gensym_count(0) {}
     40                GenSym( GenSym &other ) { gensym_count = other.gensym_count; }
    4041
    4142//    std::string get_symbol() { }
    42   private:
    43     std::string prefix;
    44     int gensym_count;
    45   };
     43          private:
     44                std::string prefix;
     45                int gensym_count;
     46        };
    4647
    47   // template< typename Key >
    48   class Matcher {
    49   public:
    50     typedef std::vector< std::string >::iterator iterator;
     48        // template< typename Key >
     49        class Matcher {
     50          public:
     51                typedef std::vector< std::string >::iterator iterator;
    5152
    52     Matcher( const std::list< DeclarationWithType * > & );
    53     ~Matcher() {}
     53                Matcher( const std::list< DeclarationWithType * > & );
     54                ~Matcher() {}
    5455
    55     template< class OutputIterator > bool get_reorderedCall( OutputIterator );
    56     template< class InputIterator >  bool add(InputIterator, InputIterator, ResolvExpr::Alternative &);
    57     template< class InputIterator, class OutputIterator >  bool slice(InputIterator begin, InputIterator end, OutputIterator );
    58     //std::vector<std::string> &get_order() const { return order; }
     56                template< class OutputIterator > bool get_reorderedCall( OutputIterator );
     57                template< class InputIterator >  bool add(InputIterator, InputIterator, ResolvExpr::Alternative &);
     58                template< class InputIterator, class OutputIterator >  bool slice(InputIterator begin, InputIterator end, OutputIterator );
     59                //std::vector<std::string> &get_order() const { return order; }
    5960
    60     iterator begin() { return order.begin(); }
    61     iterator end() { return order.end(); }
     61                iterator begin() { return order.begin(); }
     62                iterator end() { return order.end(); }
    6263
    63     //Expression *operator[]( int idx ) { return table( order[ idx ] ); }
    64   private:
    65     std::map< std::string, int > table;
    66     std::vector<std::string> order;
    67     std::vector<DeclarationWithType *> declarations;
    68     std::vector<ResolvExpr::Alternative *> alternatives;
    69   };
    70   //  void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder & );
    71 
     64                //Expression *operator[]( int idx ) { return table( order[ idx ] ); }
     65          private:
     66                std::map< std::string, int > table;
     67                std::vector<std::string> order;
     68                std::vector<DeclarationWithType *> declarations;
     69                std::vector<ResolvExpr::Alternative *> alternatives;
     70        };
     71        //  void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder & );
    7272} // namespace Designators
    7373
    74 /*
    75   Local Variables:
    76   mode: c++
    77   End:
    78 */
    7974// Local Variables: //
    8075// tab-width: 4 //
  • translator/GenPoly/ScrubTyVars.cc

    r01aeade ra08ba92  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:47:31 2015
    13 // Update Count     : 1
     12// Last Modified On : Tue May 19 16:42:42 2015
     13// Update Count     : 2
    1414//
    1515
     
    2222
    2323namespace GenPoly {
    24     Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
     24        Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
    2525                TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() );
    2626                if ( doAll || tyVar != tyVars.end() ) {
     
    3939                } // if
    4040                return typeInst;
    41     }
     41        }
    4242
    43     Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
     43        Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
    4444                // sizeof( T ) => T parameter, which is the size of T
    4545                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
     
    4949                        return Mutator::mutate( szeof );
    5050                } // if
    51     }
     51        }
    5252
    53     Type * ScrubTyVars::mutate( PointerType *pointer ) {
     53        Type * ScrubTyVars::mutate( PointerType *pointer ) {
    5454                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {
    5555                        if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
     
    6262                } // if
    6363                return Mutator::mutate( pointer );
    64     }
     64        }
    6565} // namespace GenPoly
    6666
  • translator/InitTweak/Association.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Association.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 16:25:09 2015
     13// Update Count     : 1
    1414//
     15
    1516#include "Association.h"
    1617
     
    2223const int RangeAssociation::RangeAssociation::UNDEF = -1;
    2324RangeAssociation::~RangeAssociation() {}
     25
    2426// Local Variables: //
    2527// tab-width: 4 //
  • translator/InitTweak/Association.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Association.h --
    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
    14 //
    15 #ifndef _ASSOCIATE_H_
    16 #define _ASSOCIATE_H_
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:27:09 2015
     13// Update Count     : 2
     14//
     15
     16#ifndef _ASSOCIATION_H_
     17#define _ASSOCIATION_H_
    1718
    1819#include <map>
     
    3435// ** exceptions
    3536class AssocException : public std::exception {
    36 public:
    37   AssocException() {}
    38   AssocException( std::string _what ) : what( _what ) {}
    39   ~AssocException() throw () {}
    40 
    41   std::string get_what() const { return what; }
    42   void set_what( std::string newValue ) { what = newValue; }
    43 private:
    44   std::string what;
     37  public:
     38        AssocException() {}
     39        AssocException( std::string _what ) : what( _what ) {}
     40        ~AssocException() throw () {}
     41
     42        std::string get_what() const { return what; }
     43        void set_what( std::string newValue ) { what = newValue; }
     44  private:
     45        std::string what;
    4546};
    4647
    4748// ** visitors
    4849class AssociationVisitor {
    49 public:
    50   AssociationVisitor() {}
    51   virtual ~AssociationVisitor() {}
    52 
    53   virtual void visit( SingleName * ) = 0;
    54   virtual void visit( PointAssociation * ) = 0;
    55   virtual void visit( RangeAssociation * ) = 0;
     50  public:
     51        AssociationVisitor() {}
     52        virtual ~AssociationVisitor() {}
     53
     54        virtual void visit( SingleName * ) = 0;
     55        virtual void visit( PointAssociation * ) = 0;
     56        virtual void visit( RangeAssociation * ) = 0;
    5657};
    5758
    5859// ** containers
    5960class Association {
    60  public:
    61   virtual ~Association();
    62 
    63   virtual Association *clone() = 0;
    64   virtual long int add_single( std::string, Expression *) = 0;
    65   virtual long int add_single( long int, Expression *expr) = 0;
    66 
    67   virtual Association *operator[]( int idx ) = 0;
    68   virtual Association *operator[]( std::string ) = 0;
    69 
    70   //  virtual AssociationIterator *get_iterator() = 0;
    71 
    72   virtual void accept( AssociationVisitor & ) = 0;
    73   virtual void display( std::ostream & ) = 0;
     61  public:
     62        virtual ~Association();
     63
     64        virtual Association *clone() = 0;
     65        virtual long int add_single( std::string, Expression *) = 0;
     66        virtual long int add_single( long int, Expression *expr) = 0;
     67
     68        virtual Association *operator[]( int idx ) = 0;
     69        virtual Association *operator[]( std::string ) = 0;
     70
     71        //  virtual AssociationIterator *get_iterator() = 0;
     72
     73        virtual void accept( AssociationVisitor & ) = 0;
     74        virtual void display( std::ostream & ) = 0;
    7475};
    7576
    7677class SingleName : public Association {
    77 public:
    78   SingleName( Expression *initExpr = 0 ) : expr( initExpr ) {}
    79   virtual ~SingleName();
    80 
    81   virtual SingleName *clone() {
    82     return 0; // XXX!
    83   }
    84 
    85   virtual long int add_single( long int idx, Expression *newExpr) {
    86     if ( expr == 0 ) //|| *expr == *newExpr )
    87       expr = newExpr;
    88     return 0;
    89   }
    90 
    91   virtual long int add_single( std::string str, Expression *newExpr) {
    92     if ( expr == 0 ) //|| *expr == *newExpr )
    93       expr = newExpr;
    94     return 0;
    95   }
    96 
    97   virtual Association *operator[]( int idx ) { assert(false); }
    98   virtual Association *operator[]( std::string idx ) { assert(false); }
    99 
    100   virtual void accept( AssociationVisitor &v ) { v.visit( this ); }
    101   virtual void display( std::ostream &os ) {
    102     os << "Single association" << std::endl;
    103   }
    104 
    105   Expression *get_expr() const { return expr; }
    106 
    107 private:
    108   Expression *expr;
    109   Expression *deflt;
     78  public:
     79        SingleName( Expression *initExpr = 0 ) : expr( initExpr ) {}
     80        virtual ~SingleName();
     81
     82        virtual SingleName *clone() {
     83                return 0; // XXX!
     84        }
     85
     86        virtual long int add_single( long int idx, Expression *newExpr) {
     87                if ( expr == 0 ) //|| *expr == *newExpr )
     88                        expr = newExpr;
     89                return 0;
     90        }
     91
     92        virtual long int add_single( std::string str, Expression *newExpr ) {
     93                if ( expr == 0 ) //|| *expr == *newExpr )
     94                        expr = newExpr;
     95                return 0;
     96        }
     97
     98        virtual Association *operator[]( int idx ) { assert(false); }
     99        virtual Association *operator[]( std::string idx ) { assert(false); }
     100
     101        virtual void accept( AssociationVisitor &v ) { v.visit( this ); }
     102        virtual void display( std::ostream &os ) {
     103                os << "Single association" << std::endl;
     104        }
     105
     106        Expression *get_expr() const { return expr; }
     107
     108  private:
     109        Expression *expr;
     110        Expression *deflt;
    110111};
    111112
    112113class PointAssociation : public Association {
    113 public:
    114   typedef std::map< std::string, std::pair< long int, Association *> > map_type;
    115 
    116   PointAssociation() {}
    117   PointAssociation( const PointAssociation &other ) {
    118     copy( other.anonym.begin(), other.anonym.end(), back_inserter( anonym ));
    119   }
    120 
    121   virtual ~PointAssociation();
    122 
    123   virtual PointAssociation *clone() {
    124     return ( new PointAssociation( *this ) );
    125   }
    126 
    127   virtual long int add_single( long int idx, Expression *expr) {
    128     long int ret;
    129 
    130     if ( idx >= (long int)ordering.size() ) throw AssocException("extra (spurious) members");
    131 
    132     if ( ordering[ idx ] == "")
    133       std::cerr << "Checkpoint 2" << std::endl;
    134     else {
    135       assert( table[ordering[idx]].second != 0 );
    136       ret = idx;
    137       table[ ordering[idx] ].second->add_single("", expr );
    138     }
    139     return ret;
    140   }
    141 
    142   virtual long int add_single( std::string idx, Expression *expr) {
    143     if ( idx == "" )
    144       std::cerr << "Checkpoint 1" << std::endl;
    145     else {
    146       map_type::iterator j;
    147       if (  (j = table.find( idx )) == table.end() )  // this doesn't amount for reachable members deeper down the structure, fix
    148         throw AssocException("No such member");
    149       else
    150         return add_single( j->second.first, expr );
    151     }
    152 
    153     return -1;
    154   }
    155 
    156   void add_member( std::string str ) {
    157     if ( table.find( str ) != table.end() ) return;
    158     ordering.push_back( str );
    159     if ( str != "" ) {
    160       std::pair<long int, Association *> p( ordering.size() - 1, 0 );
    161       table.insert( std::pair< std::string, std::pair<long int, Association *> >(str, p) );
    162     }
    163     return;
    164   }
    165 
    166   virtual void set_member( std::string str, Association *assoc ) {
    167     if ( str == "" )
    168       anonym.push_back( assoc );
    169     else  if ( table.find( str ) == table.end() )
    170       throw AssocException( "no such member" );
    171     else
    172       table[ str ] = std::pair<long int, Association *>(ordering.size() - 1, assoc);
    173 
    174     return;
    175   }
    176 
    177   virtual Association *operator[]( int idx ) {
    178     if ( ordering[idx] == "" ) {
    179       std::cerr << "Error, anonymous members not implemented yet" << std::endl;
    180       throw 0;
    181     } else
    182       return table[ ordering[idx] ].second;
    183   }
    184 
    185   virtual Association *operator[]( std::string idx ) {
    186     if ( table.find( idx ) == table.end() )
    187       throw AssocException("Member not found");
    188     else
    189       return table[ idx ].second;
    190   }
    191 
    192   /*
    193   virtual AssociationIterator *get_iterator() {
    194     PointAssocIterator *it;
    195     return it;
    196   }
    197   */
    198 
    199   void accept( AssociationVisitor &v ) { v.visit( this ); }
    200 
    201   virtual void display( std::ostream &os ) {
    202     os << "Point association: " << std::endl;
    203     for ( map_type::iterator i = table.begin(); i != table.end(); i++ ) {
    204       os << "Member [" << i->first << ", index = " << i->second.first << "]";
    205       if ( i->second.second != 0 )
    206         i->second.second->display( os );
    207       else
    208         std::cerr << "No recursive association" << std::endl;
    209 
    210       os << std::endl;
    211     }
    212   }
    213 
    214   const int size() const { return ordering.size(); }
    215 
    216 private:
    217   PointAssociation &operator=(const PointAssociation &);
    218   std::vector<std::string> ordering;
    219   std::list< Association * > anonym;
    220   std::map< std::string, std::pair<long int, Association *> > table;
     114  public:
     115        typedef std::map< std::string, std::pair< long int, Association *> > map_type;
     116
     117        PointAssociation() {}
     118        PointAssociation( const PointAssociation &other ) {
     119                copy( other.anonym.begin(), other.anonym.end(), back_inserter( anonym ));
     120        }
     121
     122        virtual ~PointAssociation();
     123
     124        virtual PointAssociation *clone() {
     125                return ( new PointAssociation( *this ) );
     126        }
     127
     128        virtual long int add_single( long int idx, Expression *expr) {
     129                long int ret;
     130
     131                if ( idx >= (long int)ordering.size() ) throw AssocException("extra (spurious) members");
     132
     133                if ( ordering[ idx ] == "")
     134                        std::cerr << "Checkpoint 2" << std::endl;
     135                else {
     136                        assert( table[ordering[idx]].second != 0 );
     137                        ret = idx;
     138                        table[ ordering[idx] ].second->add_single("", expr );
     139                } // if
     140                return ret;
     141        }
     142
     143        virtual long int add_single( std::string idx, Expression *expr) {
     144                if ( idx == "" )
     145                        std::cerr << "Checkpoint 1" << std::endl;
     146                else {
     147                        map_type::iterator j;
     148                        if (  (j = table.find( idx )) == table.end() )  // this doesn't amount for reachable members deeper down the structure, fix
     149                                throw AssocException("No such member");
     150                        else
     151                                return add_single( j->second.first, expr );
     152                } // if
     153
     154                return -1;
     155        }
     156
     157        void add_member( std::string str ) {
     158                if ( table.find( str ) != table.end() ) return;
     159                ordering.push_back( str );
     160                if ( str != "" ) {
     161                        std::pair<long int, Association *> p( ordering.size() - 1, 0 );
     162                        table.insert( std::pair< std::string, std::pair<long int, Association *> >(str, p) );
     163                } // if
     164                return;
     165        }
     166
     167        virtual void set_member( std::string str, Association *assoc ) {
     168                if ( str == "" )
     169                        anonym.push_back( assoc );
     170                else  if ( table.find( str ) == table.end() )
     171                        throw AssocException( "no such member" );
     172                else
     173                        table[ str ] = std::pair<long int, Association *>(ordering.size() - 1, assoc);
     174
     175                return;
     176        }
     177
     178        virtual Association *operator[]( int idx ) {
     179                if ( ordering[idx] == "" ) {
     180                        std::cerr << "Error, anonymous members not implemented yet" << std::endl;
     181                        throw 0;
     182                } else
     183                        return table[ ordering[idx] ].second;
     184        }
     185
     186        virtual Association *operator[]( std::string idx ) {
     187                if ( table.find( idx ) == table.end() )
     188                        throw AssocException("Member not found");
     189                else
     190                        return table[ idx ].second;
     191        }
     192
     193        /*
     194          virtual AssociationIterator *get_iterator() {
     195          PointAssocIterator *it;
     196          return it;
     197          }
     198        */
     199
     200        void accept( AssociationVisitor &v ) { v.visit( this ); }
     201
     202        virtual void display( std::ostream &os ) {
     203                os << "Point association: " << std::endl;
     204                for ( map_type::iterator i = table.begin(); i != table.end(); i++ ) {
     205                        os << "Member [" << i->first << ", index = " << i->second.first << "]";
     206                        if ( i->second.second != 0 )
     207                                i->second.second->display( os );
     208                        else
     209                                std::cerr << "No recursive association" << std::endl;
     210
     211                        os << std::endl;
     212                } // for
     213        }
     214
     215        const int size() const { return ordering.size(); }
     216
     217  private:
     218        PointAssociation &operator=(const PointAssociation &);
     219        std::vector<std::string> ordering;
     220        std::list< Association * > anonym;
     221        std::map< std::string, std::pair<long int, Association *> > table;
    221222};
    222223
    223224class RangeAssociation : public Association {
    224 public:
    225   static const int UNDEF;
    226   RangeAssociation( int _hi= UNDEF ) : hi( _hi ) {
    227     std::cerr << "Constructed RangeAssociation with: [" << hi << "]" << std::endl;
    228   }
    229 
    230   virtual ~RangeAssociation();
    231 
    232   virtual RangeAssociation *clone() {
    233     return 0; // XXX !!!!
    234   }
    235 
    236   virtual Association *operator[]( int idx ) {
    237     return 0; // XXX !!!
    238   }
    239 
    240   virtual Association *operator[]( std::string idx ) { assert(false); return 0; }
    241 
    242   /*
    243   virtual AssociationIterator *get_iterator() {
    244     RangeAssocIterator *it;
    245     return it;
    246   }
    247   */
    248 
    249   virtual long int add_single( long int idx, Expression *newExpr) { return 0; }
    250   virtual long int add_single( std::string, Expression *) { return 0; }
    251   void accept( AssociationVisitor &v ) { v.visit( this ); }
    252   virtual void display( std::ostream &os ) {
    253     os << "Range association, with limit: " << std::endl;
    254   }
    255 
    256 private:
    257   int hi;
    258   diet::diet_tree<int> tree;
    259   /*
    260   for ( diet_tree<int>::iterator i = tree.begin(); i != tree.end(); i++ )
    261     std::cout << "--(" << (*i).first << ", " << (*i).second << ")--" << std::endl;
    262   diet_tree<int> tree;
    263   tree.insert(100,200);
    264   */
     225  public:
     226        static const int UNDEF;
     227        RangeAssociation( int _hi= UNDEF ) : hi( _hi ) {
     228                std::cerr << "Constructed RangeAssociation with: [" << hi << "]" << std::endl;
     229        }
     230
     231        virtual ~RangeAssociation();
     232
     233        virtual RangeAssociation *clone() {
     234                return 0; // XXX !!!!
     235        }
     236
     237        virtual Association *operator[]( int idx ) {
     238                return 0; // XXX !!!
     239        }
     240
     241        virtual Association *operator[]( std::string idx ) { assert(false); return 0; }
     242
     243        /*
     244          virtual AssociationIterator *get_iterator() {
     245          RangeAssocIterator *it;
     246          return it;
     247          }
     248        */
     249
     250        virtual long int add_single( long int idx, Expression *newExpr) { return 0; }
     251        virtual long int add_single( std::string, Expression *) { return 0; }
     252        void accept( AssociationVisitor &v ) { v.visit( this ); }
     253        virtual void display( std::ostream &os ) {
     254                os << "Range association, with limit: " << std::endl;
     255        }
     256
     257  private:
     258        int hi;
     259        diet::diet_tree<int> tree;
     260        /*
     261          for ( diet_tree<int>::iterator i = tree.begin(); i != tree.end(); i++ )
     262          std::cout << "--(" << (*i).first << ", " << (*i).second << ")--" << std::endl;
     263          diet_tree<int> tree;
     264          tree.insert(100,200);
     265        */
    265266};
    266267
    267268// ** builders
    268269class AssociationBuilder {
    269 public:
    270   /* AssociationBuilder( Declaration * ) */
    271   virtual ~AssociationBuilder() {}
    272   virtual Association *get_assoc() = 0;
    273   virtual Association *grab_assoc() = 0;
    274   virtual void set_assoc(   Association * ) = 0;
     270  public:
     271        /* AssociationBuilder( Declaration * ) */
     272        virtual ~AssociationBuilder() {}
     273        virtual Association *get_assoc() = 0;
     274        virtual Association *grab_assoc() = 0;
     275        virtual void set_assoc(   Association * ) = 0;
    275276};
    276277
    277278class AssociationFiller {
    278 public:
    279   // AssociationFiller( Declaration * ) {}
    280   virtual ~AssociationFiller() {}
    281   virtual Association *get_assoc() = 0;
    282   virtual void set_assoc( Association * ) = 0;
    283 };
    284 
    285 #endif //#define _ASSOCIATE_H_
    286 
    287 /*
    288   Local Variables:
    289   mode: c++
    290   End:
    291 */
     279  public:
     280        // AssociationFiller( Declaration * ) {}
     281        virtual ~AssociationFiller() {}
     282        virtual Association *get_assoc() = 0;
     283        virtual void set_assoc( Association * ) = 0;
     284};
     285
     286#endif // _ASSOCIATION_H_
     287
    292288// Local Variables: //
    293289// tab-width: 4 //
  • translator/InitTweak/BasicInit.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// BasicInit.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
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:30:43 2015
     13// Update Count     : 1
     14//
     15
    1516#include <list>
    1617#include <cassert>
     
    3233
    3334namespace InitTweak {
    34 
    35   CompoundStmt* BasicInit::mutate(CompoundStmt *compoundStmt)
    36   {
    37     index.visit( compoundStmt );
    38 
    39     std::list< Statement * > &kids = compoundStmt->get_kids();
    40     std::list< Statement * > newKids;
    41 
    42     for ( std::list< Statement * >::iterator i = kids.begin(); i!= kids.end(); i++ ) {
    43       //BasicInit newMut(  );
    44       (*i)->acceptMutator( *this );
    45       newKids.push_back( *i );
    46 
    47       if ( has_bindings() ) { //       if ( get_bindings() != 0  ) {
    48         std::list< Statement *> newSt = get_statements();
    49         //newSt.push_back( *i );
    50         newKids.splice( newKids.end(), newSt );
    51         bindings = 0;
    52         stmts.clear();
    53       }
    54     }
    55 
    56     compoundStmt->get_kids() = newKids;
    57     return compoundStmt;
    58   }
    59 
    60   Statement * BasicInit::mutate(DeclStmt *declStmt) {
    61 
    62     declStmt->accept( index );
    63 
    64     ObjectDecl *odecl = 0;
    65 
    66     if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ){
    67 
    68       Initializer *init = odecl->get_init();
    69       if ( init == 0 ) return declStmt;
    70 
    71       if ( Classify::type( odecl->get_type() ) == Classify::COMPOUND_T )
    72         if ( Classify::initializer(init) == Classify::SINGLE_I )
    73           throw( 0 ); // mismatch of type and initializer
    74         else {
    75           NameInCollection *col = Classify::declaration( odecl, &index );
    76           bindings = NameAssociation< Expression *, BreakInitializer >::createNameAssoc(col);
    77           bindings->add_value( std::string(""), BreakInitializer(init) );
    78           BasicInit::build_statements( bindings, odecl->get_name(), stmts );
    79         }
    80       else
    81         if ( Classify::initializer(init) == Classify::COMPOUND_I )
    82           throw( 0 ); // mismatch of type and initializer
    83         else {
    84           // Single inits
    85           SingleInit *sinit = dynamic_cast< SingleInit * > ( init );
    86           assert( sinit != 0);
    87 
    88           std::list<Expression *> args;
    89           args.push_back( new AddressExpr( new NameExpr( odecl->get_name() )) );    // have to get address of object
    90           args.push_back( sinit->get_value() );
    91           // replace declaration with initialization
    92           stmts.push_back(new ExprStmt(std::list<Label>(), new UntypedExpr(new NameExpr("?=?"), args)));
    93         }
    94 
    95       delete init;
    96       odecl->set_init( 0 );
    97     } else {
    98       // no declaration statement
    99     }
    100 
    101     return declStmt;
    102   }
    103 
    104   ExprStmt *assignFromDecl( DeclStmt *declStmt )
    105   {
    106     ObjectDecl *decl;
    107     if ( (decl = dynamic_cast<ObjectDecl *>( declStmt->get_decl() )) != 0 )
    108       {
    109         SingleInit *init;
    110         if ( (init = dynamic_cast<SingleInit *>(decl->get_init())) != 0 )
    111           {
    112           }
    113       }
    114 
    115     return 0;
    116   }
    117 
    118   bool isDeclStmtP(Statement *stmt)
    119   {
    120     return ( dynamic_cast< DeclStmt *>(stmt) != 0 );
    121   }
    122 
    123   BasicInit::Classify::TypeKind BasicInit::Classify::type( Type *toClassify ) {
    124     if ( toClassify == 0 ) return NULL_T;
    125 
    126     if ( dynamic_cast< StructInstType * >(toClassify) ||
    127          dynamic_cast< UnionInstType * >(toClassify) ||
    128          dynamic_cast< ArrayType * >(toClassify)         )
    129       return COMPOUND_T;
    130     else
    131       return SINGLE_T;
    132   }
    133 
    134   BasicInit::Classify::InitKind BasicInit::Classify::initializer( Initializer *init) {
    135     if ( init == 0 ) return NULL_I;
    136     if ( dynamic_cast< ListInit * >(init) )
    137       return COMPOUND_I;
    138     if ( dynamic_cast< SingleInit * >(init) )
    139       return SINGLE_I;
    140 
    141     return NULL_I; // shouldn't be here anyways
    142   }
    143 
    144   NameInCollection *
    145   BasicInit::Classify::declaration( ObjectDecl *objdecl, SymTab::Indexer *index ) {
    146     assert ( index != 0 );
    147 
    148     ReferenceToType *reftype;
    149     if ( (reftype = dynamic_cast< StructInstType * >( objdecl->get_type() )) != 0 ){
    150       StructDecl *strDecl = index->lookupStruct( reftype->get_name() );
    151       if ( strDecl != 0 ) {
    152         NameCollectionBuilder bld;
    153         NameCollector nc( bld );
    154         strDecl->accept( nc );
    155         NameInCollection *col = nc.get_builder().get_collection();
    156         nc.get_builder().set_collection( 0 );
    157 
    158         return col;
    159       } else
    160         throw( SemanticError( std::string("No structure of name: ") + reftype->get_name() ) );
    161     } else {
    162       throw(SemanticError( reftype->get_name() + std::string("is not a reference to type") ));
    163       return 0;
    164     }
    165   }
    166 
    167   std::list< Statement * >
    168   BasicInit::Classify::matchInit( NameInCollection *col,
    169                                   ObjectDecl *toInitialize,
    170                                   Initializer *init ) {
    171     assert ( col != 0 );
    172 
    173     std::list< Statement * > arranged(0); //( col->size() );
    174     std::fill( arranged.begin(), arranged.end(), (Statement *)0 );
    175     int current = 0;
    176 
    177     if ( init == 0 )
    178       // no initializer... shouldn't even bother... fix this.
    179       return arranged;
    180 
    181     {
    182       ListInit *li = dynamic_cast< ListInit * >( init );
    183 
    184       if ( li != 0 ) {
    185         for ( std::list<Initializer *>::iterator i = li->begin_initializers();
    186                                                          i != li->end_initializers();
    187               i++) {
    188           std::list<Expression *> d_orig = (*i)->get_designators();
    189 
    190           NameInCollection *corrsp; // corresponding element to this initializer
    191           if ( ! d_orig.empty() ) {
    192             // 1) has designators
    193             std::list<NameExpr *> des;
    194             std::transform( d_orig.begin(), d_orig.end(),
    195                             std::back_inserter( des ), cast_ptr<Expression, NameExpr > );
    196 
    197             for ( std::list<NameExpr *>::iterator j = des.begin(); j != des.end(); j++ ) {
    198               // check for existence of the element
    199 
    200               if ( (corrsp = (*col)[ (*j)->get_name() ]) != 0 ) {
    201                 // current++;
    202                 SingleInit *sinit;
    203                 if ( (sinit = dynamic_cast< SingleInit * >( *i )) != 0 )
    204                   arranged.push_back( constructAssgn( corrsp->get_name(), toInitialize, sinit ) );
     35        CompoundStmt* BasicInit::mutate(CompoundStmt *compoundStmt) {
     36                index.visit( compoundStmt );
     37
     38                std::list< Statement * > &kids = compoundStmt->get_kids();
     39                std::list< Statement * > newKids;
     40
     41                for ( std::list< Statement * >::iterator i = kids.begin(); i!= kids.end(); i++ ) {
     42                        //BasicInit newMut(  );
     43                        (*i)->acceptMutator( *this );
     44                        newKids.push_back( *i );
     45
     46                        if ( has_bindings() ) { //       if ( get_bindings() != 0  ) {
     47                                std::list< Statement *> newSt = get_statements();
     48                                //newSt.push_back( *i );
     49                                newKids.splice( newKids.end(), newSt );
     50                                bindings = 0;
     51                                stmts.clear();
     52                        } // if
     53                } // for
     54
     55                compoundStmt->get_kids() = newKids;
     56                return compoundStmt;
     57        }
     58
     59        Statement * BasicInit::mutate(DeclStmt *declStmt) {
     60                declStmt->accept( index );
     61
     62                ObjectDecl *odecl = 0;
     63
     64                if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ) {
     65                        Initializer *init = odecl->get_init();
     66                        if ( init == 0 ) return declStmt;
     67
     68                        if ( Classify::type( odecl->get_type() ) == Classify::COMPOUND_T )
     69                                if ( Classify::initializer(init) == Classify::SINGLE_I )
     70                                        throw( 0 ); // mismatch of type and initializer
     71                                else {
     72                                        NameInCollection *col = Classify::declaration( odecl, &index );
     73                                        bindings = NameAssociation< Expression *, BreakInitializer >::createNameAssoc(col);
     74                                        bindings->add_value( std::string(""), BreakInitializer(init) );
     75                                        BasicInit::build_statements( bindings, odecl->get_name(), stmts );
     76                                } // if
     77                        else
     78                                if ( Classify::initializer(init) == Classify::COMPOUND_I )
     79                                        throw( 0 ); // mismatch of type and initializer
     80                                else {
     81                                        // Single inits
     82                                        SingleInit *sinit = dynamic_cast< SingleInit * > ( init );
     83                                        assert( sinit != 0);
     84
     85                                        std::list<Expression *> args;
     86                                        args.push_back( new AddressExpr( new NameExpr( odecl->get_name() )) );    // have to get address of object
     87                                        args.push_back( sinit->get_value() );
     88                                        // replace declaration with initialization
     89                                        stmts.push_back(new ExprStmt(std::list<Label>(), new UntypedExpr(new NameExpr("?=?"), args)));
     90                                } // if
     91
     92                        delete init;
     93                        odecl->set_init( 0 );
     94                } else {
     95                        // no declaration statement
     96                } // if
     97
     98                return declStmt;
     99        }
     100
     101        ExprStmt *assignFromDecl( DeclStmt *declStmt ) {
     102                ObjectDecl *decl;
     103                if ( (decl = dynamic_cast<ObjectDecl *>( declStmt->get_decl() )) != 0 ) {
     104                        SingleInit *init;
     105                        if ( (init = dynamic_cast<SingleInit *>(decl->get_init())) != 0 ) {
     106                        } // if
     107                } // if
     108
     109                return 0;
     110        }
     111
     112        bool isDeclStmtP(Statement *stmt) {
     113                return ( dynamic_cast< DeclStmt *>(stmt) != 0 );
     114        }
     115
     116        BasicInit::Classify::TypeKind BasicInit::Classify::type( Type *toClassify ) {
     117                if ( toClassify == 0 ) return NULL_T;
     118
     119                if ( dynamic_cast< StructInstType * >(toClassify) ||
     120                         dynamic_cast< UnionInstType * >(toClassify) ||
     121                         dynamic_cast< ArrayType * >(toClassify)         )
     122                        return COMPOUND_T;
    205123                else
    206                   ; // recursive call to matchInit
    207               } else
    208                 // error, member doesn't exist
    209                 return arranged; // throw( 0 ); // XXX
    210             }
    211           } else {
    212             // 2) doesn't have designators
    213             if ( (corrsp = (*col)[ current++ ]) != 0 ) {
    214               SingleInit *sinit;
    215               if ( (sinit = dynamic_cast< SingleInit * >( *i )) != 0 )
    216                 arranged.push_back( constructAssgn( corrsp->get_name(), toInitialize, sinit ) );
    217               else
    218                 ; // recursive call to matchInit
    219             } else {
    220               // Shouldn't be here... probably too many elements in initializer?
    221             }
    222           }
    223         }
    224       }
    225     }
    226 
    227     return arranged;
    228   }
    229 
    230   Statement *BasicInit::Classify::constructAssgn( std::string membName, ObjectDecl *toInit, SingleInit *sinit ) {
    231     std::list< Expression * > args;
    232     args.push_back(new AddressExpr( new UntypedMemberExpr( membName, new NameExpr(toInit->get_name()) )));
    233     args.push_back( sinit->get_value() );
    234     Statement *ret = new ExprStmt(std::list<Label>(), new UntypedExpr(new NameExpr("?=?"), args));
    235     return ret;
    236   }
    237 
    238   void BasicInit::build_statements( NameAssociation< Expression *, BreakInitializer > *assoc,
    239                                     std::string aggName, std::list< Statement *> &stmts ) {
    240     assert( assoc != 0 );
    241     static std::list< std::string > prefix;
    242 
    243     NameInCollection *col = assoc->get_collection();
    244     if ( col->isComposite() ) {
    245       VariousNames *vc = dynamic_cast< VariousNames * >( col );
    246       for ( VariousNames::key_iterator it = vc->keys_begin(); it != vc->keys_end(); it++ ) {
    247         prefix.push_back( *it );
    248         if ( (*assoc)[ *it ] != 0 )
    249           build_statements( (*assoc)[ *it ], aggName, stmts );
    250 
    251         prefix.pop_back();
    252       }
    253     } else {
    254       SingleNameAssoc< Expression *, BreakInitializer > *sa = \
    255         dynamic_cast< SingleNameAssoc< Expression *, BreakInitializer > * >( assoc );
    256       assert( sa != 0 );
    257 
    258       Expression * rh = sa->get_data();
    259 
    260       if (rh != 0) {
    261         // construct assignment statement list
    262         Expression *lh = new NameExpr ( aggName );
    263         for ( std::list< std::string >::iterator i = prefix.begin(); i != prefix.end(); i++ )
    264           lh = new UntypedMemberExpr( *i, lh );
    265 
    266         std::list< Expression * > args;
    267         args.push_back( new AddressExpr(lh) );  args.push_back( rh );
    268 
    269         stmts.push_back( new ExprStmt(std::list<Label>(), new UntypedExpr(new NameExpr("?=?"), args)) );
    270       }
    271     }
    272 
    273     return;
    274   }
    275 
     124                        return SINGLE_T;
     125        }
     126
     127        BasicInit::Classify::InitKind BasicInit::Classify::initializer( Initializer *init) {
     128                if ( init == 0 ) return NULL_I;
     129                if ( dynamic_cast< ListInit * >(init) )
     130                        return COMPOUND_I;
     131                if ( dynamic_cast< SingleInit * >(init) )
     132                        return SINGLE_I;
     133
     134                return NULL_I; // shouldn't be here anyways
     135        }
     136
     137        NameInCollection * BasicInit::Classify::declaration( ObjectDecl *objdecl, SymTab::Indexer *index ) {
     138                assert ( index != 0 );
     139
     140                ReferenceToType *reftype;
     141                if ( (reftype = dynamic_cast< StructInstType * >( objdecl->get_type() )) != 0 ) {
     142                        StructDecl *strDecl = index->lookupStruct( reftype->get_name() );
     143                        if ( strDecl != 0 ) {
     144                                NameCollectionBuilder bld;
     145                                NameCollector nc( bld );
     146                                strDecl->accept( nc );
     147                                NameInCollection *col = nc.get_builder().get_collection();
     148                                nc.get_builder().set_collection( 0 );
     149
     150                                return col;
     151                        } else
     152                                throw( SemanticError( std::string("No structure of name: ") + reftype->get_name() ) );
     153                } else {
     154                        throw(SemanticError( reftype->get_name() + std::string("is not a reference to type") ));
     155                        return 0;
     156                } // if
     157        }
     158
     159        std::list< Statement * >
     160        BasicInit::Classify::matchInit( NameInCollection *col, ObjectDecl *toInitialize, Initializer *init ) {
     161                assert ( col != 0 );
     162
     163                std::list< Statement * > arranged(0); //( col->size() );
     164                std::fill( arranged.begin(), arranged.end(), (Statement *)0 );
     165                int current = 0;
     166
     167                if ( init == 0 )
     168                        // no initializer... shouldn't even bother... fix this.
     169                        return arranged;
     170
     171                ListInit *li = dynamic_cast< ListInit * >( init );
     172
     173                if ( li != 0 ) {
     174                        for ( std::list<Initializer *>::iterator i = li->begin_initializers();
     175                                  i != li->end_initializers();
     176                                  i++) {
     177                                std::list<Expression *> d_orig = (*i)->get_designators();
     178
     179                                NameInCollection *corrsp; // corresponding element to this initializer
     180                                if ( ! d_orig.empty() ) {
     181                                        // 1) has designators
     182                                        std::list<NameExpr *> des;
     183                                        std::transform( d_orig.begin(), d_orig.end(),
     184                                                                        std::back_inserter( des ), cast_ptr<Expression, NameExpr > );
     185
     186                                        for ( std::list<NameExpr *>::iterator j = des.begin(); j != des.end(); j++ ) {
     187                                                // check for existence of the element
     188
     189                                                if ( (corrsp = (*col)[ (*j)->get_name() ]) != 0 ) {
     190                                                        // current++;
     191                                                        SingleInit *sinit;
     192                                                        if ( (sinit = dynamic_cast< SingleInit * >( *i )) != 0 )
     193                                                                arranged.push_back( constructAssgn( corrsp->get_name(), toInitialize, sinit ) );
     194                                                        else
     195                                                                ; // recursive call to matchInit
     196                                                } else
     197                                                        // error, member doesn't exist
     198                                                        return arranged; // throw( 0 ); // XXX
     199                                        }
     200                                } else {
     201                                        // 2) doesn't have designators
     202                                        if ( (corrsp = (*col)[ current++ ]) != 0 ) {
     203                                                SingleInit *sinit;
     204                                                if ( (sinit = dynamic_cast< SingleInit * >( *i )) != 0 )
     205                                                        arranged.push_back( constructAssgn( corrsp->get_name(), toInitialize, sinit ) );
     206                                                else
     207                                                        ; // recursive call to matchInit
     208                                        } else {
     209                                                // Shouldn't be here... probably too many elements in initializer?
     210                                        } // if
     211                                } // if
     212                        } // for
     213                } // if
     214
     215                return arranged;
     216        }
     217
     218        Statement *BasicInit::Classify::constructAssgn( std::string membName, ObjectDecl *toInit, SingleInit *sinit ) {
     219                std::list< Expression * > args;
     220                args.push_back(new AddressExpr( new UntypedMemberExpr( membName, new NameExpr(toInit->get_name()) )));
     221                args.push_back( sinit->get_value() );
     222                Statement *ret = new ExprStmt(std::list<Label>(), new UntypedExpr(new NameExpr("?=?"), args));
     223                return ret;
     224        }
     225
     226        void BasicInit::build_statements( NameAssociation< Expression *, BreakInitializer > *assoc,  std::string aggName, std::list< Statement *> &stmts ) {
     227                assert( assoc != 0 );
     228                static std::list< std::string > prefix;
     229
     230                NameInCollection *col = assoc->get_collection();
     231                if ( col->isComposite() ) {
     232                        VariousNames *vc = dynamic_cast< VariousNames * >( col );
     233                        for ( VariousNames::key_iterator it = vc->keys_begin(); it != vc->keys_end(); it++ ) {
     234                                prefix.push_back( *it );
     235                                if ( (*assoc)[ *it ] != 0 )
     236                                        build_statements( (*assoc)[ *it ], aggName, stmts );
     237
     238                                prefix.pop_back();
     239                        }
     240                } else {
     241                        SingleNameAssoc< Expression *, BreakInitializer > *sa = \
     242                                dynamic_cast< SingleNameAssoc< Expression *, BreakInitializer > * >( assoc );
     243                        assert( sa != 0 );
     244
     245                        Expression * rh = sa->get_data();
     246
     247                        if (rh != 0) {
     248                                // construct assignment statement list
     249                                Expression *lh = new NameExpr ( aggName );
     250                                for ( std::list< std::string >::iterator i = prefix.begin(); i != prefix.end(); i++ )
     251                                        lh = new UntypedMemberExpr( *i, lh );
     252
     253                                std::list< Expression * > args;
     254                                args.push_back( new AddressExpr(lh) );  args.push_back( rh );
     255
     256                                stmts.push_back( new ExprStmt(std::list<Label>(), new UntypedExpr(new NameExpr("?=?"), args)) );
     257                        } // if
     258                } // if
     259
     260                return;
     261        }
    276262} // namespace InitTweak
    277263
  • translator/InitTweak/BasicInit.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// BasicInit.h --
    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
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:32:21 2015
     13// Update Count     : 3
     14//
     15
    1516#ifndef _BASINIT_H_
    1617#define _BASINIT_H_
     
    2829
    2930namespace InitTweak {
    30 
    31   bool isDeclStmtP(Statement *stmt);
    32 
    33   class BreakInitializer;
    34   class BreakDesignator;
    35 
    36   class BasicInit: public Mutator
    37     {
    38     public:
    39       BasicInit() : bindings( 0 ) {}
    40       BasicInit( SymTab::Indexer &_index ) : bindings( 0 ), index( _index ) {}
    41       BasicInit( const BasicInit &other ) {
    42         bindings = other.get_bindings();
    43         index = other.index;
    44       }
    45 
    46       ~BasicInit() { /* delete bindings; bindings = 0; */ }
    47 
    48       NameAssociation< Expression *, BreakInitializer > *get_bindings() const { return bindings; }
    49       void set_bindings( NameAssociation< Expression *, BreakInitializer > *newValue ) {
    50         bindings = newValue;
    51       }
    52 
    53       bool has_bindings() {
    54         return ( get_bindings() != 0 || ! stmts.empty() );
    55       }
    56 
    57       virtual ObjectDecl     *mutate( ObjectDecl *objectDecl )
    58       { index.visit( objectDecl ); return objectDecl; }
    59       virtual TypeDecl       *mutate( TypeDecl *typeDecl )
    60       { index.visit( typeDecl ); return typeDecl; }
    61       virtual TypedefDecl    *mutate( TypedefDecl *typeDecl )
    62       { index.visit( typeDecl ); return typeDecl; }
    63       virtual StructDecl     *mutate( StructDecl *aggregateDecl )
    64       { index.visit( aggregateDecl ); return aggregateDecl; }
    65       virtual UnionDecl      *mutate( UnionDecl *aggregateDecl )
    66       { index.visit( aggregateDecl ); return aggregateDecl; }
    67       virtual EnumDecl       *mutate( EnumDecl *aggregateDecl )
    68       { index.visit( aggregateDecl ); return aggregateDecl; }
    69 
    70       virtual Type           *mutate( StructInstType *aggrInst )
    71       { index.visit( aggrInst ); return aggrInst; }
    72       virtual Type           *mutate( UnionInstType *aggrInst )
    73       { index.visit( aggrInst ); return aggrInst; }
    74 
    75       virtual CompoundStmt   *mutate(CompoundStmt *compoundStmt);
    76       virtual Statement *mutate(DeclStmt *declStmt);
    77 
    78       std::list< Statement *> get_statements() const { return stmts;  }
    79 
    80       static void build_statements( NameAssociation< Expression *, BreakInitializer > *assoc,
    81                                     std::string aggName, std::list< Statement *> &stmts );
    82     private:
    83       NameAssociation< Expression *, BreakInitializer > *bindings;
    84       Statement *assignFromDecl( DeclStmt *declStmt );
    85       SymTab::Indexer index;
    86       std::list< Statement *> stmts;
    87 
    88       class Classify {
    89       public:
    90         enum TypeKind { NULL_T, SINGLE_T, COMPOUND_T };
    91         enum InitKind { NULL_I, SINGLE_I, COMPOUND_I };
    92 
    93         static TypeKind type( Type * );
    94         static InitKind initializer( Initializer *);
    95 
    96         static NameInCollection *declaration( ObjectDecl *objdecl, SymTab::Indexer *index );
    97         static std::list< Statement * >
    98            matchInit( NameInCollection *, ObjectDecl *, Initializer * );
    99         static Statement *constructAssgn( std::string membname, ObjectDecl *toInit, SingleInit *sinit );
    100 
    101         // static std::list< Statement * > constructListAssgn( NameAssociation<Expression *, BreakDesignator > assoc );
    102       };
    103   };
    104 
    105   class BreakInitializer {
    106     enum InitKind { EMPTY, SINGLE, COMPOUND };
    107 
    108     class BreakDesignator;
    109     typedef BreakDesignator NameSplitter;
    110 
    111   public:
    112     typedef std::list<Initializer *>::iterator element_iterator;
    113     typedef std::list< NameSplitter >::iterator name_iterator;
    114 
    115     BreakInitializer ( Initializer *_init ) : kind( EMPTY ), sinit(0), cinit(0) {
    116       std::list<Expression *> temp;
    117 
    118       if ( ( sinit=dynamic_cast< SingleInit * >(_init) ) != 0 ) {
    119         kind = SINGLE;
    120         temp = sinit->get_designators();
    121       } else if ( ( cinit=dynamic_cast< ListInit * >(_init) ) != 0 ) {
    122         kind = COMPOUND;
    123         temp = cinit->get_designators();
    124       }
    125 
    126       std::transform( temp.begin(), temp.end(), std::back_inserter( designators ),
    127                       ctor_noptr<NameSplitter, Expression *> );
    128 
    129     }
    130 
    131     //BreakInitializer( const BreakInitializer &other ) { this.col = other.col; }
    132     ~BreakInitializer () {}
    133 
    134     BreakInitializer set_name( NameSplitter &name ) {
    135       designators.clear();
    136       designators.push_back( name );
    137 
    138       return *this;
    139     }
    140 
    141     element_iterator element_begin() {
    142       assert( cinit != 0 );
    143       return cinit->begin_initializers();
    144     }
    145     element_iterator element_end() {
    146       assert( cinit != 0 );
    147       return cinit->end_initializers();
    148     }
    149 
    150     name_iterator names_begin() { return designators.begin(); }
    151     name_iterator names_end() { return designators.end(); }
    152 
    153     int names_size() const { return designators.size(); }
    154 
    155     bool has_index() const { return ! designators.empty(); }
    156     bool is_single() const { return kind == SINGLE; }
    157     bool is_composite() const { return kind == COMPOUND;  }
    158 
    159     Expression *get_value() {
    160       switch ( kind ) {
    161       case EMPTY:
    162         return 0;
    163         break;
    164       case SINGLE:
    165         return sinit->get_value();
    166         break;
    167       case COMPOUND:
    168         assert(false);
    169         break;
    170       default:
    171         assert(false);
    172       }
    173       return 0;
    174     }
    175 
    176     // attributes
    177   private:
    178     InitKind kind;
    179     SingleInit *sinit;
    180     ListInit *cinit;
    181     std::list< BreakDesignator > designators;
    182 
    183     // helper classes
    184   public:
    185     class BreakDesignator {
    186     public:
    187       BreakDesignator( Expression *exp ) {
    188         Expression *prfx = exp;
    189         UntypedMemberExpr *me = 0;
    190 
    191         do {
    192           if ( (me=dynamic_cast< UntypedMemberExpr * >( prfx )) == 0 ) break;
    193           blown_struct.push_front( me->get_member() );
    194           prfx = me->get_aggregate();
    195         } while ( prfx != 0 );
    196 
    197         NameExpr *ne;
    198         if ( (ne=dynamic_cast< NameExpr * >( prfx )) != 0 )
    199           blown_struct.push_front( ne->get_name() );
    200       }
    201 
    202       BreakDesignator( std::string name ) {
    203         blown_struct.push_front( name );
    204       }
    205 
    206       bool is_flat() const { return blown_struct.size() == 1; }
    207       bool is_nested() const { return blown_struct.size() > 1; }
    208 
    209       std::string get_name() { return blown_struct.front(); }
    210 
    211       BreakDesignator &name_remainder() {
    212         blown_struct.pop_front();
    213         return *this;
    214       }
    215 
    216     private:
    217       std::list< std::string > blown_struct;
    218     };
    219 
    220   };
    221 
     31        bool isDeclStmtP(Statement *stmt);
     32
     33        class BreakInitializer;
     34        class BreakDesignator;
     35
     36        class BasicInit: public Mutator {
     37          public:
     38                BasicInit() : bindings( 0 ) {}
     39                BasicInit( SymTab::Indexer &_index ) : bindings( 0 ), index( _index ) {}
     40                BasicInit( const BasicInit &other ) {
     41                        bindings = other.get_bindings();
     42                        index = other.index;
     43                }
     44
     45                ~BasicInit() { /* delete bindings; bindings = 0; */ }
     46
     47                NameAssociation< Expression *, BreakInitializer > *get_bindings() const { return bindings; }
     48                void set_bindings( NameAssociation< Expression *, BreakInitializer > *newValue ) {
     49                        bindings = newValue;
     50                }
     51
     52                bool has_bindings() {
     53                        return ( get_bindings() != 0 || ! stmts.empty() );
     54                }
     55
     56                virtual ObjectDecl     *mutate( ObjectDecl *objectDecl )
     57                        { index.visit( objectDecl ); return objectDecl; }
     58                virtual TypeDecl       *mutate( TypeDecl *typeDecl )
     59                        { index.visit( typeDecl ); return typeDecl; }
     60                virtual TypedefDecl    *mutate( TypedefDecl *typeDecl )
     61                        { index.visit( typeDecl ); return typeDecl; }
     62                virtual StructDecl     *mutate( StructDecl *aggregateDecl )
     63                        { index.visit( aggregateDecl ); return aggregateDecl; }
     64                virtual UnionDecl      *mutate( UnionDecl *aggregateDecl )
     65                        { index.visit( aggregateDecl ); return aggregateDecl; }
     66                virtual EnumDecl       *mutate( EnumDecl *aggregateDecl )
     67                        { index.visit( aggregateDecl ); return aggregateDecl; }
     68
     69                virtual Type           *mutate( StructInstType *aggrInst )
     70                        { index.visit( aggrInst ); return aggrInst; }
     71                virtual Type           *mutate( UnionInstType *aggrInst )
     72                        { index.visit( aggrInst ); return aggrInst; }
     73
     74                virtual CompoundStmt   *mutate(CompoundStmt *compoundStmt);
     75                virtual Statement *mutate(DeclStmt *declStmt);
     76
     77                std::list< Statement *> get_statements() const { return stmts;  }
     78
     79                static void build_statements( NameAssociation< Expression *, BreakInitializer > *assoc, std::string aggName, std::list< Statement *> &stmts );
     80          private:
     81                NameAssociation< Expression *, BreakInitializer > *bindings;
     82                Statement *assignFromDecl( DeclStmt *declStmt );
     83                SymTab::Indexer index;
     84                std::list< Statement *> stmts;
     85
     86                class Classify {
     87                  public:
     88                        enum TypeKind { NULL_T, SINGLE_T, COMPOUND_T };
     89                        enum InitKind { NULL_I, SINGLE_I, COMPOUND_I };
     90
     91                        static TypeKind type( Type * );
     92                        static InitKind initializer( Initializer *);
     93
     94                        static NameInCollection *declaration( ObjectDecl *objdecl, SymTab::Indexer *index );
     95                        static std::list< Statement * >
     96                        matchInit( NameInCollection *, ObjectDecl *, Initializer * );
     97                        static Statement *constructAssgn( std::string membname, ObjectDecl *toInit, SingleInit *sinit );
     98
     99                        // static std::list< Statement * > constructListAssgn( NameAssociation<Expression *, BreakDesignator > assoc );
     100                };
     101        };
     102
     103        class BreakInitializer {
     104                enum InitKind { EMPTY, SINGLE, COMPOUND };
     105
     106                class BreakDesignator;
     107                typedef BreakDesignator NameSplitter;
     108
     109          public:
     110                typedef std::list<Initializer *>::iterator element_iterator;
     111                typedef std::list< NameSplitter >::iterator name_iterator;
     112
     113                BreakInitializer ( Initializer *_init ) : kind( EMPTY ), sinit(0), cinit(0) {
     114                        std::list<Expression *> temp;
     115
     116                        if ( ( sinit=dynamic_cast< SingleInit * >(_init) ) != 0 ) {
     117                                kind = SINGLE;
     118                                temp = sinit->get_designators();
     119                        } else if ( ( cinit=dynamic_cast< ListInit * >(_init) ) != 0 ) {
     120                                kind = COMPOUND;
     121                                temp = cinit->get_designators();
     122                        } // if
     123
     124                        std::transform( temp.begin(), temp.end(), std::back_inserter( designators ), ctor_noptr<NameSplitter, Expression *> );
     125                }
     126
     127                //BreakInitializer( const BreakInitializer &other ) { this.col = other.col; }
     128                ~BreakInitializer () {}
     129
     130                BreakInitializer set_name( NameSplitter &name ) {
     131                        designators.clear();
     132                        designators.push_back( name );
     133
     134                        return *this;
     135                }
     136
     137                element_iterator element_begin() {
     138                        assert( cinit != 0 );
     139                        return cinit->begin_initializers();
     140                }
     141                element_iterator element_end() {
     142                        assert( cinit != 0 );
     143                        return cinit->end_initializers();
     144                }
     145
     146                name_iterator names_begin() { return designators.begin(); }
     147                name_iterator names_end() { return designators.end(); }
     148
     149                int names_size() const { return designators.size(); }
     150
     151                bool has_index() const { return ! designators.empty(); }
     152                bool is_single() const { return kind == SINGLE; }
     153                bool is_composite() const { return kind == COMPOUND;  }
     154
     155                Expression *get_value() {
     156                        switch ( kind ) {
     157                          case EMPTY:
     158                                return 0;
     159                                break;
     160                          case SINGLE:
     161                                return sinit->get_value();
     162                                break;
     163                          case COMPOUND:
     164                                assert(false);
     165                                break;
     166                          default:
     167                                assert(false);
     168                        } // switch
     169                        return 0;
     170                }
     171                // attributes
     172          private:
     173                InitKind kind;
     174                SingleInit *sinit;
     175                ListInit *cinit;
     176                std::list< BreakDesignator > designators;
     177                // helper classes
     178          public:
     179                class BreakDesignator {
     180                  public:
     181                        BreakDesignator( Expression *exp ) {
     182                                Expression *prfx = exp;
     183                                UntypedMemberExpr *me = 0;
     184
     185                                do {
     186                                        if ( (me=dynamic_cast< UntypedMemberExpr * >( prfx )) == 0 ) break;
     187                                        blown_struct.push_front( me->get_member() );
     188                                        prfx = me->get_aggregate();
     189                                } while ( prfx != 0 );
     190
     191                                NameExpr *ne;
     192                                if ( (ne=dynamic_cast< NameExpr * >( prfx )) != 0 )
     193                                        blown_struct.push_front( ne->get_name() );
     194                        }
     195
     196                        BreakDesignator( std::string name ) {
     197                                blown_struct.push_front( name );
     198                        }
     199
     200                        bool is_flat() const { return blown_struct.size() == 1; }
     201                        bool is_nested() const { return blown_struct.size() > 1; }
     202
     203                        std::string get_name() { return blown_struct.front(); }
     204
     205                        BreakDesignator &name_remainder() {
     206                                blown_struct.pop_front();
     207                                return *this;
     208                        }
     209
     210                  private:
     211                        std::list< std::string > blown_struct;
     212                };
     213        };
    222214} // namespace InitTweak
    223215
    224 #endif // #ifndef _BASINIT_H_
    225 
    226 /*
    227   Local Variables:
    228   mode: c++
    229   End:
    230 */
     216#endif // _BASINIT_H_
     217
    231218// Local Variables: //
    232219// tab-width: 4 //
  • translator/InitTweak/DeclarationHoister.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// DeclarationHoister.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 16:33:20 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <list>
    1617#include <cassert>
     
    2728#include "DeclarationHoister.h"
    2829
     30namespace InitTweak {
     31        CompoundStmt* DeclarationHoister::mutate( CompoundStmt *compoundStmt ) {
     32                typedef std::list<Statement *>::iterator stmt_it;
     33                // 1. collect Declaration Statements  in this scope
     34                std::list<Statement *> &kids = compoundStmt->get_kids();
     35                std::list<Statement *>::iterator result = kids.begin();
     36                std::list< stmt_it > decls;
    2937
    30 namespace InitTweak {
     38                while ( result !=  kids.end() ) {
     39                        result = std::find_if (result, kids.end(), cast_ptr< Statement, DeclStmt > );
    3140
    32   CompoundStmt* DeclarationHoister::mutate(CompoundStmt *compoundStmt) {
    33     typedef std::list<Statement *>::iterator stmt_it;
    34     // 1. collect Declaration Statements  in this scope
    35     std::list<Statement *> &kids = compoundStmt->get_kids();
    36     std::list<Statement *>::iterator result = kids.begin();
    37     std::list< stmt_it > decls;
     41                        if ( result != kids.end() ) {
     42                                decls.push_back( result );
     43                                std::advance( result, 1 );
     44                        } // if
     45                } // while
    3846
    39     while ( result !=  kids.end() ) {
    40       result = std::find_if (result, kids.end(), cast_ptr< Statement, DeclStmt > );
     47                for ( std::list< stmt_it >::reverse_iterator i = decls.rbegin(); i!= decls.rend(); i++ ) {
     48                        kids.push_front( **i );
     49                        kids.erase( *i );
     50                } // for
    4151
    42       if ( result != kids.end() ) {
    43         decls.push_back( result );
    44         std::advance( result, 1 );
    45       }
    46     }
    47 
    48     for ( std::list< stmt_it >::reverse_iterator i = decls.rbegin(); i!= decls.rend(); i++ ){
    49       kids.push_front( **i );
    50       kids.erase( *i );
    51     }
    52 
    53     return compoundStmt;
    54   }
     52                return compoundStmt;
     53        }
    5554} // namespace InitTweak
    56 
    57 
    58 
    59 
    60 
    61 
    62 
    6355
    6456// Local Variables: //
  • translator/InitTweak/DeclarationHoister.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// DeclarationHoister.h --
    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 16:33:48 2015
     13// Update Count     : 2
    1414//
     15
    1516#include "SynTree/Visitor.h"
    1617#include "SymTab/Indexer.h"
    1718
    1819namespace InitTweak {
     20        bool isDeclStmtP(Statement *stmt);
    1921
    20   bool isDeclStmtP(Statement *stmt);
    21 
    22   class DeclarationHoister: public Mutator {
    23   public:
    24     virtual CompoundStmt   *mutate(CompoundStmt *compoundStmt);
    25   };
    26 
     22        class DeclarationHoister: public Mutator {
     23          public:
     24                virtual CompoundStmt   *mutate(CompoundStmt *compoundStmt);
     25        };
    2726}  // namespace InitTweak
    2827
    29 /*
    30   Local Variables:
    31   mode: c++
    32   End:
    33 */
    3428// Local Variables: //
    3529// tab-width: 4 //
  • translator/InitTweak/InitExpander.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// InitExpander.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 16:34:12 2015
     13// Update Count     : 1
    1414//
     15
    1516#include <list>
    1617#include <stack>
    1718#include <cassert>
    1819#include <algorithm>
    19 
    2020
    2121#include "utility.h"
     
    2424
    2525namespace InitTweak {
     26        InitExpander::InitExpander() {}
    2627
    27   InitExpander::InitExpander() {}
     28        InitExpander::~InitExpander() {}
    2829
    29   InitExpander::~InitExpander() {}
     30        ObjectDecl *InitExpander::mutate( ObjectDecl *objectDecl ) {
     31                index.visit( objectDecl );
    3032
    31   ObjectDecl *InitExpander::mutate( ObjectDecl *objectDecl ) {
    32     index.visit( objectDecl );
     33                if ( objectDecl->get_init() == 0 ) return objectDecl;
    3334
    34     if ( objectDecl->get_init() == 0 ) return objectDecl;
     35                InitModelBuilder builder( objectDecl );
     36                builder.get_assoc()->display( std::cerr ); // xxx
     37                InitModelFiller filler( builder.get_assoc(), objectDecl->get_init(), true );
     38                // filler.get_assoc()->display( std::cerr ); // xxx
     39                InitUnspooler exp;
     40                filler.get_assoc()->accept( exp );
     41                objectDecl->set_init( exp.grab_initializer() );
     42                objectDecl->get_init()->print( std::cerr );
    3543
    36     InitModelBuilder builder( objectDecl );
    37     builder.get_assoc()->display( std::cerr ); // xxx
    38     InitModelFiller filler( builder.get_assoc(), objectDecl->get_init(), true );
    39     // filler.get_assoc()->display( std::cerr ); // xxx
    40     InitUnspooler exp;
    41     filler.get_assoc()->accept( exp );
    42     objectDecl->set_init( exp.grab_initializer() );
    43     objectDecl->get_init()->print( std::cerr );
    44 
    45     return objectDecl;
    46   }
    47 
     44                return objectDecl;
     45        }
    4846} // namespace InitTweak
    4947
  • translator/InitTweak/InitExpander.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// InitExpander.h --
    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 16:35:33 2015
     13// Update Count     : 2
    1414//
     15
    1516#ifndef _INIT_EXPANDER_H_
    1617#define _INIT_EXPANDER_H_
     
    2728
    2829namespace InitTweak {
     30        class InitExpander : public Mutator {
     31                typedef Mutator Parent;
     32          public:
     33                InitExpander();
     34                ~InitExpander();
    2935
    30   class InitExpander : public Mutator
    31   {
    32     typedef Mutator Parent;
     36                virtual ObjectDecl *mutate( ObjectDecl * );
    3337
    34   public:
    35     InitExpander();
    36     ~InitExpander();
     38                // indexer runs
     39                virtual FunctionDecl   *mutate( FunctionDecl *functionDecl ) {
     40                        functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
     41                        mutateAll( functionDecl->get_oldDecls(), *this );
     42                        functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
    3743
    38     virtual ObjectDecl *mutate( ObjectDecl * );
     44                        index.visit( functionDecl );
     45                        return functionDecl;
     46                }
    3947
    40     // indexer runs
    41     virtual FunctionDecl   *mutate( FunctionDecl *functionDecl )
    42     {
    43       functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
    44       mutateAll( functionDecl->get_oldDecls(), *this );
    45       functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
     48                virtual TypeDecl *mutate( TypeDecl *typeDecl )
     49                        { index.visit( typeDecl ); return typeDecl; }
     50                virtual TypedefDecl *mutate( TypedefDecl *typeDecl )
     51                        { index.visit( typeDecl ); return typeDecl; }
     52                virtual StructDecl *mutate( StructDecl *aggregateDecl )
     53                        { index.visit( aggregateDecl ); return aggregateDecl; }
     54                virtual UnionDecl *mutate( UnionDecl *aggregateDecl )
     55                        { index.visit( aggregateDecl ); return aggregateDecl; }
     56                virtual EnumDecl *mutate( EnumDecl *aggregateDecl )
     57                        { index.visit( aggregateDecl ); return aggregateDecl; }
    4658
    47       index.visit( functionDecl );
    48       return functionDecl;
    49     }
    50 
    51     virtual TypeDecl       *mutate( TypeDecl *typeDecl )
    52     { index.visit( typeDecl ); return typeDecl; }
    53     virtual TypedefDecl    *mutate( TypedefDecl *typeDecl )
    54     { index.visit( typeDecl ); return typeDecl; }
    55     virtual StructDecl     *mutate( StructDecl *aggregateDecl )
    56     { index.visit( aggregateDecl ); return aggregateDecl; }
    57     virtual UnionDecl      *mutate( UnionDecl *aggregateDecl )
    58     { index.visit( aggregateDecl ); return aggregateDecl; }
    59     virtual EnumDecl       *mutate( EnumDecl *aggregateDecl )
    60     { index.visit( aggregateDecl ); return aggregateDecl; }
    61 
    62     virtual Type           *mutate( StructInstType *aggrInst )
    63     { index.visit( aggrInst ); return aggrInst; }
    64     virtual Type           *mutate( UnionInstType *aggrInst )
    65     { index.visit( aggrInst ); return aggrInst; }
    66 
    67   private:
    68     SymTab::Indexer index;
    69   };  // class InitExpander
    70 
     59                virtual Type *mutate( StructInstType *aggrInst )
     60                        { index.visit( aggrInst ); return aggrInst; }
     61                virtual Type *mutate( UnionInstType *aggrInst )
     62                        { index.visit( aggrInst ); return aggrInst; }
     63          private:
     64                SymTab::Indexer index;
     65        };  // class InitExpander
    7166} // namespace InitTweak
    7267
     68#endif // _INIT_EXPANDER_H_
    7369
    74 #endif // #ifndef _INIT_EXPANDER_H_
    75 
    76 /*
    77   Local Variables:
    78   mode: c++
    79   End:
    80 */
    8170// Local Variables: //
    8271// tab-width: 4 //
  • translator/InitTweak/InitModel.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// InitModel.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
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:37:08 2015
     13// Update Count     : 1
     14//
     15
    1516#include "SynTree/Constant.h"
    1617#include "InitModel.h"
     
    2122
    2223namespace InitTweak {
    23 
    24   InitModelBuilder::InitModelBuilder( Declaration *_decl )
    25     : taken( false ), decl( 0 ), building(0) {
    26 
    27     ObjectDecl *_odecl = dynamic_cast< ObjectDecl * >( _decl );
    28     assert( _odecl != 0 );
    29     Type *objectType = _odecl->get_type();
    30 
    31     /* this to be replaced by dynamic dispatch */
    32     if ( dynamic_cast< BasicType * >(objectType) != 0 ) {
    33       if ( building == 0 ) building = new SingleName;
    34     } else if ( ReferenceToType *rt = dynamic_cast< ReferenceToType * >(objectType) ) {
    35       rt->accept( *this );
    36     } else if ( ArrayType *at = dynamic_cast< ArrayType * >(objectType) ) {
    37       at->accept( *this );
    38     } else // if (tuples)
    39       std::cerr << "Got something else" << std::endl;
    40 
    41     if ( decl != 0 ) init();
    42   }
    43 
    44   InitModelBuilder::~InitModelBuilder() { if ( ! taken ) { delete building; building = 0; } }
    45 
    46   void InitModelBuilder::init() {
    47     assert( decl != 0 );
    48     decl->accept( *this );
    49   }
    50 
    51   // Visitor interface
    52   void InitModelBuilder::visit( ArrayType *at ) {
    53     if ( building == 0 ) building = new RangeAssociation(interpretDimension( at->get_dimension() ));
    54     decl = 0;
    55     return;
    56   }
    57 
    58   void InitModelBuilder::visit( StructInstType *st ) {
    59     if ( building == 0 ) building = new PointAssociation;
    60     decl = st->get_baseStruct();
    61     return;
    62   }
    63 
    64   void InitModelBuilder::visit( UnionInstType *ut ) {
    65     decl = ut->get_baseUnion();
    66     return;
    67   }
    68   void InitModelBuilder::visit( EnumInstType * ) {}
    69 
    70   void InitModelBuilder::visit( StructDecl *aggregateDecl) {
    71     PointAssociation *pa = dynamic_cast< PointAssociation * >( building );
    72     assert( pa != 0 );
    73     std::list< Declaration * > mem = aggregateDecl->get_members();
    74 
    75     for ( std::list<Declaration *>::iterator i = mem.begin(); i != mem.end(); i++ ) {
    76       pa->add_member( (*i)->get_name() );
    77       InitModelBuilder rec(*i);
    78       pa->set_member( (*i)->get_name(), rec.grab_assoc() );
    79     }
    80 
    81     return;
    82   }
    83 
    84   void InitModelBuilder::visit( UnionDecl *) {}
    85   void InitModelBuilder::visit( EnumDecl *) {}
    86 
    87   // InitModelBuilder::ConstantFolder
    88   void InitModelBuilder::ConstantFolder::visit( ConstantExpr *cnst ) {
    89     Constant *c = cnst->get_constant();
    90     assert (c != 0);
    91     if ( BasicType *bt = dynamic_cast<BasicType *>( c->get_type() ) ) {
    92       if ( bt->isInteger() ) {
    93         // need more intelligence here, not necessarily base 10
    94         value = std::strtol( c->get_value().c_str(), NULL, 10 );
    95         return;
    96       } else
    97         std::cerr << "Basic type but not integer" << std::endl;
    98     }
    99     throw 0;
    100   }
    101 
    102   // InitModelFiller
    103   InitModelFiller::InitModelFiller( Association *_model, Initializer *_init, bool _topLevel )
    104       : model( _model ), orgInit( _init ), topLevel( _topLevel ), next( 0 ) {
    105     //next = model.begin();
    106     if ( orgInit != 0 ) init();
    107   }
    108 
    109   void InitModelFiller::init() {
    110     assert( model != 0 ); // change it into a reference
    111     assert( orgInit != 0 );
    112     orgInit->accept( *this );
    113   }
    114 
    115   void InitModelFiller::visit( SingleInit *singleInit ) {
    116     std::list< Expression *> &des = singleInit->get_designators();
    117 
    118     if ( topLevel ) {
    119       assert ( des.empty() );
    120       assert ( dynamic_cast< SingleName * >(model) != 0 );
    121       try {
    122         model->add_single( next++, singleInit->get_value() );
    123       } catch (...) {
    124         std::cerr << "Illegal initialization" << std::endl;
    125       }
    126       return;
    127     }
    128 
    129     if ( des.empty() ) {
    130       assert( model != 0 );
    131       try {
    132         model->add_single( next++, singleInit->get_value() );
    133       } catch ( AssocException &e ) {
    134         throw SemanticError( "Illegal initialization: " + e.get_what() );
    135       } catch ( ... ) {
    136         std::cerr << "Shouldn't be here" << std::endl;
    137       }
    138       return;
    139     }
    140 
    141     // not general enough (does not contend well with designated arrays)
    142     std::list<std::string> desnames;
    143     std::transform( des.begin(), des.end(), back_inserter(desnames), Initializer::designator_name );
    144 
    145     for ( std::list<std::string>::iterator i = desnames.begin(); i != desnames.end(); i++ ) {
    146       try {
    147         next = model->add_single( *i, singleInit->get_value() );
    148         next++;
    149       } catch ( AssocException &e ) {
    150         throw SemanticError( "Illegal initialization: " + e.get_what() );
    151       } catch ( ... ) {
    152         std::cerr << "Shouldn't happen, check association" << std::endl;
    153       }
    154     }
    155 
    156     return;
    157   }
    158 
    159   void InitModelFiller::visit( ListInit *listInit ) {
    160     assert( listInit != 0 );
    161 
    162     // designators
    163     std::list< Expression *> &des = listInit->get_designators();
    164     std::list< Initializer *> &ini = listInit->get_initializers();
    165 
    166     if (! des.empty() ) {
    167       if (topLevel)
    168         throw SemanticError( "Invalid initializer: designated at top level." );
    169 
    170       std::list<Expression *> des2;
    171       std::copy (des.begin(), des.end(), back_inserter( des2 ));
    172       std::list< Expression * > empty;
    173       listInit->set_designators( empty );
    174       for ( std::list<Expression *>::iterator i = des2.begin(); i != des2.end(); i++ ) {
    175         Association * newModel = 0;
    176         if ( NameExpr *n = dynamic_cast< NameExpr * >( *i ) )
    177           try {
    178             newModel = (*model)[ n->get_name() ];
    179           } catch( AssocException &e ) {
    180             std::cerr << "Didn't find member: " << e.get_what() << std::endl;
    181           }
    182         else // if ( RangeExpr *r = dynamic_cast< RangeExpr * >( *i ) )
    183           std::cerr << "Invalid designator specification" << std::endl;
    184 
    185         InitModelFiller rec( newModel, listInit, true );
    186       }
    187 
    188     } else
    189       if (topLevel) {
    190         topLevel = false;
    191         for ( std::list<Initializer*>::iterator i = ini.begin(); i != ini.end(); i++ )
    192           (*i)->accept(*this);
    193       } else
    194         // next available uninitialized member
    195         InitModelFiller rec( (*model)[next++], listInit, true );
    196   }
    197 
    198   void InitUnspooler::visit( SingleName *single ) {
    199     assert(init == 0 && single != 0);
    200     std::list< Expression * > empty;
    201     init = new SingleInit( single->get_expr(), empty );
    202     return;
    203   }
    204 
    205   void InitUnspooler::visit( PointAssociation *pa ) {
    206     assert( pa != 0 );
    207 
    208     std::list< Initializer * > contents;
    209     for ( int i = 0; i < pa->size(); i++ )
    210       if ( (*pa)[i] != 0 ) {
    211         InitUnspooler rec;
    212         (*pa)[i]->accept( rec );
    213         assert( rec.get_initializer() != 0 );
    214         contents.push_back( rec.grab_initializer() );
    215       }
    216 
    217     init = new ListInit( contents );
    218     return;
    219   }
    220 
    221 
    222 
     24        InitModelBuilder::InitModelBuilder( Declaration *_decl )
     25                : taken( false ), decl( 0 ), building(0) {
     26
     27                ObjectDecl *_odecl = dynamic_cast< ObjectDecl * >( _decl );
     28                assert( _odecl != 0 );
     29                Type *objectType = _odecl->get_type();
     30
     31                /* this to be replaced by dynamic dispatch */
     32                if ( dynamic_cast< BasicType * >(objectType) != 0 ) {
     33                        if ( building == 0 ) building = new SingleName;
     34                } else if ( ReferenceToType *rt = dynamic_cast< ReferenceToType * >(objectType) ) {
     35                        rt->accept( *this );
     36                } else if ( ArrayType *at = dynamic_cast< ArrayType * >(objectType) ) {
     37                        at->accept( *this );
     38                } else // if (tuples)
     39                        std::cerr << "Got something else" << std::endl;
     40
     41                if ( decl != 0 ) init();
     42        }
     43
     44        InitModelBuilder::~InitModelBuilder() { if ( ! taken ) { delete building; building = 0; } }
     45
     46        void InitModelBuilder::init() {
     47                assert( decl != 0 );
     48                decl->accept( *this );
     49        }
     50
     51        // Visitor interface
     52        void InitModelBuilder::visit( ArrayType *at ) {
     53                if ( building == 0 ) building = new RangeAssociation(interpretDimension( at->get_dimension() ));
     54                decl = 0;
     55                return;
     56        }
     57
     58        void InitModelBuilder::visit( StructInstType *st ) {
     59                if ( building == 0 ) building = new PointAssociation;
     60                decl = st->get_baseStruct();
     61                return;
     62        }
     63
     64        void InitModelBuilder::visit( UnionInstType *ut ) {
     65                decl = ut->get_baseUnion();
     66                return;
     67        }
     68        void InitModelBuilder::visit( EnumInstType * ) {}
     69
     70        void InitModelBuilder::visit( StructDecl *aggregateDecl) {
     71                PointAssociation *pa = dynamic_cast< PointAssociation * >( building );
     72                assert( pa != 0 );
     73                std::list< Declaration * > mem = aggregateDecl->get_members();
     74
     75                for ( std::list<Declaration *>::iterator i = mem.begin(); i != mem.end(); i++ ) {
     76                        pa->add_member( (*i)->get_name() );
     77                        InitModelBuilder rec(*i);
     78                        pa->set_member( (*i)->get_name(), rec.grab_assoc() );
     79                } // for
     80
     81                return;
     82        }
     83
     84        void InitModelBuilder::visit( UnionDecl *) {}
     85        void InitModelBuilder::visit( EnumDecl *) {}
     86
     87        // InitModelBuilder::ConstantFolder
     88        void InitModelBuilder::ConstantFolder::visit( ConstantExpr *cnst ) {
     89                Constant *c = cnst->get_constant();
     90                assert (c != 0);
     91                if ( BasicType *bt = dynamic_cast<BasicType *>( c->get_type() ) ) {
     92                        if ( bt->isInteger() ) {
     93                                // need more intelligence here, not necessarily base 10
     94                                value = std::strtol( c->get_value().c_str(), NULL, 10 );
     95                                return;
     96                        } else
     97                                std::cerr << "Basic type but not integer" << std::endl;
     98                } // if
     99                throw 0;
     100        }
     101
     102        // InitModelFiller
     103        InitModelFiller::InitModelFiller( Association *_model, Initializer *_init, bool _topLevel )
     104                : model( _model ), orgInit( _init ), topLevel( _topLevel ), next( 0 ) {
     105                //next = model.begin();
     106                if ( orgInit != 0 ) init();
     107        }
     108
     109        void InitModelFiller::init() {
     110                assert( model != 0 ); // change it into a reference
     111                assert( orgInit != 0 );
     112                orgInit->accept( *this );
     113        }
     114
     115        void InitModelFiller::visit( SingleInit *singleInit ) {
     116                std::list< Expression *> &des = singleInit->get_designators();
     117
     118                if ( topLevel ) {
     119                        assert ( des.empty() );
     120                        assert ( dynamic_cast< SingleName * >(model) != 0 );
     121                        try {
     122                                model->add_single( next++, singleInit->get_value() );
     123                        } catch (...) {
     124                                std::cerr << "Illegal initialization" << std::endl;
     125                        }
     126                        return;
     127                } // if
     128
     129                if ( des.empty() ) {
     130                        assert( model != 0 );
     131                        try {
     132                                model->add_single( next++, singleInit->get_value() );
     133                        } catch ( AssocException &e ) {
     134                                throw SemanticError( "Illegal initialization: " + e.get_what() );
     135                        } catch ( ... ) {
     136                                std::cerr << "Shouldn't be here" << std::endl;
     137                        } // try
     138                        return;
     139                } // if
     140
     141                // not general enough (does not contend well with designated arrays)
     142                std::list<std::string> desnames;
     143                std::transform( des.begin(), des.end(), back_inserter(desnames), Initializer::designator_name );
     144
     145                for ( std::list<std::string>::iterator i = desnames.begin(); i != desnames.end(); i++ ) {
     146                        try {
     147                                next = model->add_single( *i, singleInit->get_value() );
     148                                next++;
     149                        } catch ( AssocException &e ) {
     150                                throw SemanticError( "Illegal initialization: " + e.get_what() );
     151                        } catch ( ... ) {
     152                                std::cerr << "Shouldn't happen, check association" << std::endl;
     153                        } // try
     154                } // for
     155
     156                return;
     157        }
     158
     159        void InitModelFiller::visit( ListInit *listInit ) {
     160                assert( listInit != 0 );
     161
     162                // designators
     163                std::list< Expression *> &des = listInit->get_designators();
     164                std::list< Initializer *> &ini = listInit->get_initializers();
     165
     166                if ( ! des.empty() ) {
     167                        if (topLevel)
     168                                throw SemanticError( "Invalid initializer: designated at top level." );
     169
     170                        std::list<Expression *> des2;
     171                        std::copy (des.begin(), des.end(), back_inserter( des2 ));
     172                        std::list< Expression * > empty;
     173                        listInit->set_designators( empty );
     174                        for ( std::list<Expression *>::iterator i = des2.begin(); i != des2.end(); i++ ) {
     175                                Association * newModel = 0;
     176                                if ( NameExpr *n = dynamic_cast< NameExpr * >( *i ) )
     177                                        try {
     178                                                newModel = (*model)[ n->get_name() ];
     179                                        } catch( AssocException &e ) {
     180                                                std::cerr << "Didn't find member: " << e.get_what() << std::endl;
     181                                        }
     182                                else // if ( RangeExpr *r = dynamic_cast< RangeExpr * >( *i ) )
     183                                        std::cerr << "Invalid designator specification" << std::endl;
     184
     185                                InitModelFiller rec( newModel, listInit, true );
     186                        } // for
     187                } else
     188                        if (topLevel) {
     189                                topLevel = false;
     190                                for ( std::list<Initializer*>::iterator i = ini.begin(); i != ini.end(); i++ )
     191                                        (*i)->accept(*this);
     192                        } else
     193                                // next available uninitialized member
     194                                InitModelFiller rec( (*model)[next++], listInit, true );
     195        }
     196
     197        void InitUnspooler::visit( SingleName *single ) {
     198                assert(init == 0 && single != 0);
     199                std::list< Expression * > empty;
     200                init = new SingleInit( single->get_expr(), empty );
     201                return;
     202        }
     203
     204        void InitUnspooler::visit( PointAssociation *pa ) {
     205                assert( pa != 0 );
     206
     207                std::list< Initializer * > contents;
     208                for ( int i = 0; i < pa->size(); i++ )
     209                        if ( (*pa)[i] != 0 ) {
     210                                InitUnspooler rec;
     211                                (*pa)[i]->accept( rec );
     212                                assert( rec.get_initializer() != 0 );
     213                                contents.push_back( rec.grab_initializer() );
     214                        } // if
     215
     216                init = new ListInit( contents );
     217                return;
     218        }
    223219} // namespace InitTweak
     220
    224221// Local Variables: //
    225222// tab-width: 4 //
  • translator/InitTweak/InitModel.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// InitModel.h --
    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 16:37:52 2015
     13// Update Count     : 2
    1414//
     15
    1516#ifndef _INITTWEAK_MODEL_H_
    1617#define _INITTWEAK_MODEL_H_
     
    2627
    2728namespace InitTweak {
    28     class InitModelBuilder : public AssociationBuilder, public Visitor {
    29       public:
    30         InitModelBuilder( Declaration * );
    31         ~InitModelBuilder();
     29        class InitModelBuilder : public AssociationBuilder, public Visitor {
     30          public:
     31                InitModelBuilder( Declaration * );
     32                ~InitModelBuilder();
    3233
    33         virtual Association *grab_assoc() { taken = true; return building; }
    34         virtual Association *get_assoc() { return building; }
    35         void set_assoc( Association *newAssoc ) { building = newAssoc; }
     34                virtual Association *grab_assoc() { taken = true; return building; }
     35                virtual Association *get_assoc() { return building; }
     36                void set_assoc( Association *newAssoc ) { building = newAssoc; }
    3637
    37         void init();
    38         static int interpretDimension( Expression *exp ) {
    39             ConstantFolder folder( exp );
    40             try {
    41                 return folder.get_constant();
    42             } catch (...) {
    43                 throw SemanticError("Invalid array dimension");
    44             }
    45         }
     38                void init();
     39                static int interpretDimension( Expression *exp ) {
     40                        ConstantFolder folder( exp );
     41                        try {
     42                                return folder.get_constant();
     43                        } catch (...) {
     44                                throw SemanticError("Invalid array dimension");
     45                        }
     46                }
    4647
    47         // types
    48         virtual void visit( ArrayType * );
    49         virtual void visit( StructInstType * );
    50         virtual void visit( UnionInstType * );
    51         virtual void visit( EnumInstType * );
    52         virtual void visit( ContextInstType * ) { throw 0; }
    53         virtual void visit( TypeInstType * )    { throw 0; }
    54         // virtual void visit( TupleType *tupleType );
    55         // declarations
    56         virtual void visit( StructDecl *);
    57         virtual void visit( UnionDecl *);
    58         virtual void visit( EnumDecl *);
    59       private:
    60         class ConstantFolder : public Visitor {
    61           public:
    62             ConstantFolder( Expression *_expr = 0 ): expr(_expr) {}
    63             int get_constant() throw() { expr->accept( *this ); return value; }
    64             void set_constant( Expression *newExp ) { expr = newExp; }
    65             // Visitor interface
    66             void visit( Expression * ) { throw 0; }
    67             void visit( NameExpr * ) { throw 0; }
    68             void visit( CastExpr * ) { throw 0; }
    69             void visit( UntypedMemberExpr * ) { throw 0; }
    70             void visit( VariableExpr * ) { throw 0; }
    71             void visit( ConstantExpr * );
    72             void visit( SizeofExpr * ) { throw 0; }
    73             void visit( AttrExpr * ) { throw 0; }
    74             void visit( LogicalExpr * ) { throw 0; }
    75             void visit( ConditionalExpr * ) { throw 0; }
    76             void visit( CommaExpr * ) { throw 0; }
     48                // types
     49                virtual void visit( ArrayType * );
     50                virtual void visit( StructInstType * );
     51                virtual void visit( UnionInstType * );
     52                virtual void visit( EnumInstType * );
     53                virtual void visit( ContextInstType * ) { throw 0; }
     54                virtual void visit( TypeInstType * )    { throw 0; }
     55                // virtual void visit( TupleType *tupleType );
     56                // declarations
     57                virtual void visit( StructDecl *);
     58                virtual void visit( UnionDecl *);
     59                virtual void visit( EnumDecl *);
    7760          private:
    78             Expression *expr;
    79             int value;
     61                class ConstantFolder : public Visitor {
     62                  public:
     63                        ConstantFolder( Expression *_expr = 0 ): expr(_expr) {}
     64                        int get_constant() throw() { expr->accept( *this ); return value; }
     65                        void set_constant( Expression *newExp ) { expr = newExp; }
     66                        // Visitor interface
     67                        void visit( Expression * ) { throw 0; }
     68                        void visit( NameExpr * ) { throw 0; }
     69                        void visit( CastExpr * ) { throw 0; }
     70                        void visit( UntypedMemberExpr * ) { throw 0; }
     71                        void visit( VariableExpr * ) { throw 0; }
     72                        void visit( ConstantExpr * );
     73                        void visit( SizeofExpr * ) { throw 0; }
     74                        void visit( AttrExpr * ) { throw 0; }
     75                        void visit( LogicalExpr * ) { throw 0; }
     76                        void visit( ConditionalExpr * ) { throw 0; }
     77                        void visit( CommaExpr * ) { throw 0; }
     78                  private:
     79                        Expression *expr;
     80                        int value;
     81                };
     82
     83                bool taken;
     84                Declaration *decl;  // ?
     85                Association *building;
    8086        };
    8187
    82         bool taken;
    83         Declaration *decl;  // ?
    84         Association *building;
    85     };
     88        class InitModelFiller : public AssociationFiller, public Visitor {
     89          public:
     90                InitModelFiller( Association *, Initializer *, bool _topLevel = false );
     91                ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ }
     92                virtual Association *get_assoc() { return model; }
     93                virtual void set_assoc( Association *newAssoc ) { model = newAssoc; }
    8694
    87     class InitModelFiller : public AssociationFiller, public Visitor {
    88       public:
    89         InitModelFiller( Association *, Initializer *, bool _topLevel = false );
    90         ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ }
    91         virtual Association *get_assoc() { return model; }
    92         virtual void set_assoc( Association *newAssoc ) { model = newAssoc; }
     95                void init();
     96                // Visitor interface
     97                virtual void visit( SingleInit *singleInit );
     98                virtual void visit( ListInit *listInit );
     99          private:
     100                Association *model;
     101                Initializer *orgInit;
     102                bool topLevel;
     103                long int next;
     104        };
    93105
    94         void init();
    95         // Visitor interface
    96         virtual void visit( SingleInit *singleInit );
    97         virtual void visit( ListInit *listInit );
    98       private:
    99         Association *model;
    100         Initializer *orgInit;
    101         bool topLevel;
    102         long int next;
    103     };
     106        class InitUnspooler : public AssociationVisitor {
     107          public:
     108                InitUnspooler() : init(0), taken( false ) {}
     109                virtual ~InitUnspooler() { if ( ! taken && (init != 0)) { delete init; init = 0; } }
     110                Initializer *get_initializer() { return init; }
     111                Initializer *grab_initializer() { taken = true; return init; }
    104112
    105     class InitUnspooler : public AssociationVisitor {
    106       public:
    107         InitUnspooler() : init(0), taken( false ) {}
    108         virtual ~InitUnspooler() { if (! taken && (init != 0)) { delete init; init = 0; } }
    109         Initializer *get_initializer() { return init; }
    110         Initializer *grab_initializer() { taken = true; return init; }
    111 
    112         virtual void visit( SingleName * );
    113         virtual void visit( PointAssociation * );
    114         virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; }
    115       private:
    116         Initializer *init;
    117         bool taken;
    118     };
    119 
     113                virtual void visit( SingleName * );
     114                virtual void visit( PointAssociation * );
     115                virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; }
     116          private:
     117                Initializer *init;
     118                bool taken;
     119        };
    120120} // namespace InitTweak
    121121
    122122#endif // _INITTWEAK_MODEL_H_
    123123
    124 /*
    125   Local Variables:
    126   mode: c++
    127   End:
    128 */
    129124// Local Variables: //
    130125// tab-width: 4 //
  • translator/InitTweak/Mutate.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Mutate.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 16:38:19 2015
     13// Update Count     : 1
    1414//
     15
    1516#include "SynTree/Mutator.h"
    1617
     
    2223
    2324namespace InitTweak {
     25        void mutate( std::list< Declaration * > translationUnit ) {
     26                //BasicInit bi;
     27                InitExpander ini;
     28                //DeclarationHoister dh;
    2429
    25   void mutate( std::list< Declaration * > translationUnit )
    26   {
    27     //BasicInit bi;
    28     InitExpander ini;
    29     //DeclarationHoister dh;
    30 
    31     //mutateAll( translationUnit, bi );
    32     mutateAll( translationUnit, ini );
    33     //mutateAll( translationUnit, dh );
    34   }
    35 
     30                //mutateAll( translationUnit, bi );
     31                mutateAll( translationUnit, ini );
     32                //mutateAll( translationUnit, dh );
     33        }
    3634} // namespace InitTweak
    37 
    3835
    3936// Local Variables: //
  • translator/InitTweak/Mutate.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Mutate.h --
    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 16:38:52 2015
     13// Update Count     : 2
    1414//
     15
    1516#ifndef INIT_MUTATE_H
    1617#define INIT_MUTATE_H
     
    2122
    2223namespace InitTweak {
    23 
    24   void mutate( std::list< Declaration* > translationUnit );
    25 
     24        void mutate( std::list< Declaration* > translationUnit );
    2625} // namespace InitTweak
    2726
    28 #endif // #ifndef INIT_MUTATE_H
     27#endif // INIT_MUTATE_H
    2928
    30 /*
    31   Local Variables:
    32   mode: c++
    33   End:
    34 */
    3529// Local Variables: //
    3630// tab-width: 4 //
  • translator/InitTweak/RemoveInit.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// RemoveInit.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 16:39:32 2015
     13// Update Count     : 1
    1414//
     15
    1516#include "RemoveInit.h"
    1617#include "SynTree/Declaration.h"
     
    2223
    2324namespace InitTweak {
     25        namespace {
     26                const std::list<Label> noLabels;
     27        }
    2428
    25 namespace {
    26 const std::list<Label> noLabels;
    27 }
     29        void tweak( std::list< Declaration * > translationUnit ) {
     30                RemoveInit remover;
     31                mutateAll( translationUnit, remover );
     32        }
    2833
    29 void tweak( std::list< Declaration * > translationUnit ) {
    30   RemoveInit remover;
    31   mutateAll( translationUnit, remover );
    32 }
     34        void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
     35                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     36                        if ( ! stmtsToAddAfter.empty() ) {
     37                                statements.splice( i, stmtsToAddAfter );
     38                        } // if
     39                        *i = (*i)->acceptMutator( *this );
     40                } // for
     41                if ( ! stmtsToAddAfter.empty() ) {
     42                        statements.splice( statements.end(), stmtsToAddAfter );
     43                } // if
     44        }
    3345
    34 void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
    35   for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    36     if ( ! stmtsToAddAfter.empty() ) {
    37       statements.splice( i, stmtsToAddAfter );
    38     }
    39     *i = (*i)->acceptMutator( *this );
    40   }
    41   if ( ! stmtsToAddAfter.empty() ) {
    42     statements.splice( statements.end(), stmtsToAddAfter );
    43   }
    44 }
    45 
    46 CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {
    47   mutateStatementList( compoundStmt->get_kids() );
    48   return compoundStmt;
    49 }
     46        CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {
     47                mutateStatementList( compoundStmt->get_kids() );
     48                return compoundStmt;
     49        }
    5050
    5151// in the case where an object has an initializer and a polymorphic type, insert an assignment
    5252// immediately after the declaration. This will (seemingly) cause the later phases to do the right
    5353// thing with the assignment
    54 ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {
    55   if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
    56     if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) {
    57       UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    58       assign->get_args().push_back( new AddressExpr (new NameExpr( objDecl->get_name() ) ) );
    59       assign->get_args().push_back( single->get_value()->clone() );
    60       stmtsToAddAfter.push_back(new ExprStmt(noLabels, assign));
    61     }
    62   }
    63   return objDecl;
    64 }
     54        ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {
     55                if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
     56                        if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) {
     57                                UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
     58                                assign->get_args().push_back( new AddressExpr (new NameExpr( objDecl->get_name() ) ) );
     59                                assign->get_args().push_back( single->get_value()->clone() );
     60                                stmtsToAddAfter.push_back(new ExprStmt(noLabels, assign));
     61                        } // if
     62                } // if
     63                return objDecl;
     64        }
    6565} // namespace InitTweak
    6666
  • translator/InitTweak/RemoveInit.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// RemoveInit.h --
    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 16:40:11 2015
     13// Update Count     : 1
    1414//
    15 /*
    16  * This file is part of the Cforall project
    17  *
    18  * $Id: PolyMutator.h,v 1.8 2005/08/29 20:14:13 rcbilson Exp $
    19  *
    20  */
    2115
    2216#ifndef REMOVE_INIT_H
     
    3125
    3226namespace InitTweak {
     27        void tweak( std::list< Declaration * > translationUnit );
    3328
    34 void tweak( std::list< Declaration * > translationUnit );
    35 
    36 class RemoveInit : public Mutator {
    37 public:
    38   // RemoveInit();
    39   virtual ObjectDecl *mutate(ObjectDecl *objDecl);
    40   virtual CompoundStmt *mutate(CompoundStmt *compoundStmt);
    41 protected:
    42   std::list< Statement* > stmtsToAddAfter;
    43   void mutateStatementList( std::list< Statement* > &statements );
    44 };
    45 
     29        class RemoveInit : public Mutator {
     30          public:
     31                // RemoveInit();
     32                virtual ObjectDecl *mutate(ObjectDecl *objDecl);
     33                virtual CompoundStmt *mutate(CompoundStmt *compoundStmt);
     34          protected:
     35                std::list< Statement* > stmtsToAddAfter;
     36                void mutateStatementList( std::list< Statement* > &statements );
     37        };
    4638} // namespace
    4739
    48 #endif /* #ifndef GENPOLY_POLYMUTATOR_H */
     40#endif // GENPOLY_POLYMUTATOR_H
     41
    4942// Local Variables: //
    5043// tab-width: 4 //
  • translator/InitTweak/diet_map.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// diet_map.h --
    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
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:41:17 2015
     13// Update Count     : 2
     14//
     15
    1516#include <cassert>
    1617#include <string>
     
    1819
    1920namespace diet {
    20   /* A DIET ( Discrete Interval Encoding Tree ) range-map
    21    */
    22 
    23   class diet_tree_exception : public std::exception {
    24   public:
    25     diet_tree_exception() {}
    26     diet_tree_exception( std::string _what ) : what( _what ) {}
    27     ~diet_tree_exception() throw () {}
    28 
    29     std::string get_what() const { return what; }
    30     void set_what( std::string newValue ) { what = newValue; }
    31   private:
    32     std::string what;
    33   };
    34 
    35   template < typename T > class diet_tree_node;
    36   template < typename T > class diet_tree_iterator;
    37 
    38   template< typename key_type >
    39   class diet_tree {
    40     typedef key_type OrderedValue;
    41     typedef OrderedValue T;
    42     friend class diet_tree_iterator<T>;
    43   public:
    44     typedef OrderedValue value_type;
    45     typedef diet_tree_iterator<OrderedValue> iterator;
    46     typedef std::pair<value_type, value_type> pair_type;
    47 
    48     diet_tree() : root(0), left(0), right(0) {}
    49     ~diet_tree() {
    50       if ( root != 0 ) { delete root; root = 0; }
    51       if ( left != 0 ) { delete left; left = 0; }
    52       if ( right != 0 ) { delete right; right = 0; }
    53     }
    54 
    55     void insert( value_type _lo, value_type _hi ) {
    56       if ( _lo > _hi ) return; // throw exception?
    57       if ( root == 0 )
    58         root = new diet_tree_node<value_type>(_lo, _hi);
    59       else {
    60         value_type lo = root->get_lo(), hi = root->get_hi();
    61         if ( _lo < lo ) {
    62           if ( _hi > hi ) {
    63             /* can either minimize the work or minimize the number of nodes.
    64                Let's minimize the work. */
    65             if ( left == 0 ) left = new diet_tree<T>();
    66             left->insert( _lo, lo );
    67             if ( right == 0 ) right = new diet_tree<T>();
    68             right->insert( _hi, hi );
    69             return;
    70           } else if ( _hi < lo ) {
    71             if ( left == 0 ) left = new diet_tree<T>();
    72             left->insert( _lo, _hi );
    73           } else if ( _hi <= hi ) {
    74             if ( left == 0 ) left = new diet_tree<T>();
    75             left->insert( _lo, _hi );
    76             root->set_range(_hi,hi);
    77           }
    78         } else if (_lo >= lo && _hi <= hi ) {
    79           root->set_range(_lo,_hi);
    80         } else if ( _hi > hi) {
    81           if ( _lo > hi ) {
    82             if ( right == 0 ) right = new diet_tree<T>();
    83             right->insert( _lo, _hi );
    84           } else if ( _lo < hi ) {
    85             root->set_range(lo, _lo);
    86             if ( right == 0 ) right = new diet_tree<T>();
    87             right->insert(_lo, _hi);
    88           }
    89         }
    90       }
    91       return;
    92     }
    93 
    94     void insert( std::pair<value_type, value_type> p ) {
    95       insert(p.first, p.second);
    96     }
    97 
    98     pair_type get_range_pair() const {
    99       return pair_type(root->get_lo(),root->get_hi());
    100     }
    101 
    102     /*
    103     void display( std::ostream &os = std::cout ) {
    104       if ( root != 0 ) {
    105         if ( left != 0 ) left->display(os);
    106         os << "(" << root->get_lo() << ", " << root->get_hi() << ")" << std::endl;
    107         if ( right != 0 ) right->display(os);
    108       }
    109       return;
    110     }
    111     */
    112 
    113     iterator begin() { return iterator( this ); }
    114     iterator end() { return iterator( (diet_tree< value_type > *)0 ); }
    115 
    116   protected:
    117     diet_tree( diet_tree_node< OrderedValue > *_root ) : root( _root ) {}
    118   private:
    119     diet_tree_node< value_type > *root;
    120     diet_tree< value_type > *left, *right;
    121   };
    122 
    123   template< typename OrderedValue >
    124   class diet_tree_node {
    125   public:
    126     typedef OrderedValue value_type;
    127 
    128     diet_tree_node( const OrderedValue &_lo, const OrderedValue &_hi )
    129       : lo( _lo ), hi( _hi ) {
    130       if ( lo >= hi ) throw diet_tree_exception( "Invalid range" );
    131     }
    132 
    133     void set_range(const OrderedValue &newLo, const OrderedValue &newHi)
    134     { lo = newLo; hi = newHi; }
    135     OrderedValue get_lo() const { return lo; }
    136     OrderedValue get_hi() const { return hi; }
    137 
    138   private:
    139     OrderedValue lo, hi;
    140   };
    141 
    142   /* forward iterator */
    143   template < typename T >
    144   class diet_tree_iterator {
    145     typedef diet_tree_iterator<T> self;
    146     typedef typename diet_tree<T>::pair_type pair_type;
    147 
    148   public:
    149     //    typedef forward_iterator_tag iterator_category;
    150 
    151     diet_tree_iterator( diet_tree<T> *_tree ) : current( _tree ) {
    152       // current is allowed to be 0 only for `end'
    153       if (_tree != 0) go_leftmost();
    154     }
    155 
    156     ~diet_tree_iterator() {}
    157     pair_type operator*() {
    158       if ( current == 0 ) throw diet_tree_exception( "Invalid dereference" );
    159       return current->get_range_pair();
    160     }
    161 
    162     bool operator==( const diet_tree_iterator<T> &other ) { return current == other.current;  }
    163     bool operator!=( const diet_tree_iterator<T> &other ) { return current != other.current;  }
    164 
    165     diet_tree_iterator<T> operator++() {
    166       assert(current != 0);
    167       if ( current->right == 0 )
    168         if ( ! st.empty() )
    169           { current = st.top(); st.pop(); }
    170         else
    171           current = 0;
    172       else {
    173         current = current->right;
    174         go_leftmost();
    175       }
    176       return *this;
    177     }
    178 
    179     diet_tree_iterator<T> operator++(int) {
    180       self temp = *this;
    181       this->operator++();
    182       return temp;
    183     }
    184 
    185   private:
    186     void go_leftmost() {
    187       assert(current != 0);
    188       diet_tree<T> *next = 0;
    189       while ( current->left != 0 ) {
    190         next = current->left; st.push( current ); current = next;
    191       }
    192       return;
    193     }
    194 
    195     void defrag() {
    196       /* join adjacent trees */
    197       return;
    198     }
    199 
    200     diet_tree<T> *current;
    201     std::stack< diet_tree<T> * > st;
    202   };
    203 
    204   template < typename Key, typename Value >
    205   class diet_tree_assoc_node : public diet_tree_node<Key> {
    206   public:
    207     typedef Key key_type;
    208     typedef Value data_type;
    209     typedef std::pair<Key,Value> value_type;
    210   private:
    211     Value data;
    212   };
    213 
     21        /* A DIET ( Discrete Interval Encoding Tree ) range-map
     22         */
     23
     24        class diet_tree_exception : public std::exception {
     25          public:
     26                diet_tree_exception() {}
     27                diet_tree_exception( std::string _what ) : what( _what ) {}
     28                ~diet_tree_exception() throw () {}
     29
     30                std::string get_what() const { return what; }
     31                void set_what( std::string newValue ) { what = newValue; }
     32          private:
     33                std::string what;
     34        };
     35
     36        template < typename T > class diet_tree_node;
     37        template < typename T > class diet_tree_iterator;
     38
     39        template< typename key_type >
     40        class diet_tree {
     41                typedef key_type OrderedValue;
     42                typedef OrderedValue T;
     43                friend class diet_tree_iterator<T>;
     44          public:
     45                typedef OrderedValue value_type;
     46                typedef diet_tree_iterator<OrderedValue> iterator;
     47                typedef std::pair<value_type, value_type> pair_type;
     48
     49                diet_tree() : root(0), left(0), right(0) {}
     50                ~diet_tree() {
     51                        if ( root != 0 ) { delete root; root = 0; }
     52                        if ( left != 0 ) { delete left; left = 0; }
     53                        if ( right != 0 ) { delete right; right = 0; }
     54                }
     55
     56                void insert( value_type _lo, value_type _hi ) {
     57                        if ( _lo > _hi ) return; // throw exception?
     58                        if ( root == 0 )
     59                                root = new diet_tree_node<value_type>(_lo, _hi);
     60                        else {
     61                                value_type lo = root->get_lo(), hi = root->get_hi();
     62                                if ( _lo < lo ) {
     63                                        if ( _hi > hi ) {
     64                                                /* can either minimize the work or minimize the number of nodes.
     65                                                   Let's minimize the work. */
     66                                                if ( left == 0 ) left = new diet_tree<T>();
     67                                                left->insert( _lo, lo );
     68                                                if ( right == 0 ) right = new diet_tree<T>();
     69                                                right->insert( _hi, hi );
     70                                                return;
     71                                        } else if ( _hi < lo ) {
     72                                                if ( left == 0 ) left = new diet_tree<T>();
     73                                                left->insert( _lo, _hi );
     74                                        } else if ( _hi <= hi ) {
     75                                                if ( left == 0 ) left = new diet_tree<T>();
     76                                                left->insert( _lo, _hi );
     77                                                root->set_range(_hi,hi);
     78                                        }
     79                                } else if (_lo >= lo && _hi <= hi ) {
     80                                        root->set_range(_lo,_hi);
     81                                } else if ( _hi > hi) {
     82                                        if ( _lo > hi ) {
     83                                                if ( right == 0 ) right = new diet_tree<T>();
     84                                                right->insert( _lo, _hi );
     85                                        } else if ( _lo < hi ) {
     86                                                root->set_range(lo, _lo);
     87                                                if ( right == 0 ) right = new diet_tree<T>();
     88                                                right->insert(_lo, _hi);
     89                                        } // if
     90                                } // if
     91                        } // if
     92                        return;
     93                }
     94
     95                void insert( std::pair<value_type, value_type> p ) {
     96                        insert(p.first, p.second);
     97                }
     98
     99                pair_type get_range_pair() const {
     100                        return pair_type(root->get_lo(),root->get_hi());
     101                }
     102
     103                /*
     104                  void display( std::ostream &os = std::cout ) {
     105                  if ( root != 0 ) {
     106                  if ( left != 0 ) left->display(os);
     107                  os << "(" << root->get_lo() << ", " << root->get_hi() << ")" << std::endl;
     108                  if ( right != 0 ) right->display(os);
     109                  }
     110                  return;
     111                  }
     112                */
     113
     114                iterator begin() { return iterator( this ); }
     115                iterator end() { return iterator( (diet_tree< value_type > *)0 ); }
     116
     117          protected:
     118                diet_tree( diet_tree_node< OrderedValue > *_root ) : root( _root ) {}
     119          private:
     120                diet_tree_node< value_type > *root;
     121                diet_tree< value_type > *left, *right;
     122        };
     123
     124        template< typename OrderedValue >
     125        class diet_tree_node {
     126          public:
     127                typedef OrderedValue value_type;
     128
     129                diet_tree_node( const OrderedValue &_lo, const OrderedValue &_hi )
     130                        : lo( _lo ), hi( _hi ) {
     131                        if ( lo >= hi ) throw diet_tree_exception( "Invalid range" );
     132                }
     133
     134                void set_range(const OrderedValue &newLo, const OrderedValue &newHi)
     135                        { lo = newLo; hi = newHi; }
     136                OrderedValue get_lo() const { return lo; }
     137                OrderedValue get_hi() const { return hi; }
     138
     139          private:
     140                OrderedValue lo, hi;
     141        };
     142
     143        /* forward iterator */
     144        template < typename T >
     145        class diet_tree_iterator {
     146                typedef diet_tree_iterator<T> self;
     147                typedef typename diet_tree<T>::pair_type pair_type;
     148
     149          public:
     150                //    typedef forward_iterator_tag iterator_category;
     151
     152                diet_tree_iterator( diet_tree<T> *_tree ) : current( _tree ) {
     153                        // current is allowed to be 0 only for `end'
     154                        if (_tree != 0) go_leftmost();
     155                }
     156
     157                ~diet_tree_iterator() {}
     158                pair_type operator*() {
     159                        if ( current == 0 ) throw diet_tree_exception( "Invalid dereference" );
     160                        return current->get_range_pair();
     161                }
     162
     163                bool operator==( const diet_tree_iterator<T> &other ) { return current == other.current;  }
     164                bool operator!=( const diet_tree_iterator<T> &other ) { return current != other.current;  }
     165
     166                diet_tree_iterator<T> operator++() {
     167                        assert(current != 0);
     168                        if ( current->right == 0 )
     169                                if ( ! st.empty() )
     170                                        { current = st.top(); st.pop(); }
     171                                else
     172                                        current = 0;
     173                        else {
     174                                current = current->right;
     175                                go_leftmost();
     176                        } // if
     177                        return *this;
     178                }
     179
     180                diet_tree_iterator<T> operator++(int) {
     181                        self temp = *this;
     182                        this->operator++();
     183                        return temp;
     184                }
     185
     186          private:
     187                void go_leftmost() {
     188                        assert(current != 0);
     189                        diet_tree<T> *next = 0;
     190                        while ( current->left != 0 ) {
     191                                next = current->left; st.push( current ); current = next;
     192                        }
     193                        return;
     194                }
     195
     196                void defrag() {
     197                        /* join adjacent trees */
     198                        return;
     199                }
     200
     201                diet_tree<T> *current;
     202                std::stack< diet_tree<T> * > st;
     203        };
     204
     205        template < typename Key, typename Value >
     206        class diet_tree_assoc_node : public diet_tree_node<Key> {
     207          public:
     208                typedef Key key_type;
     209                typedef Value data_type;
     210                typedef std::pair<Key,Value> value_type;
     211          private:
     212                Value data;
     213        };
    214214} // namespace diet
    215215
    216 
    217 /*
    218   Local Variables:
    219   mode: c++
    220   End:
    221 */
    222216// Local Variables: //
    223217// tab-width: 4 //
  • translator/Parser/ExpressionNode.cc

    r01aeade ra08ba92  
    8181}
    8282
    83 CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp ){
     83CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp ) {
    8484        return new CommaExprNode( this, exp );
    8585}
     
    111111}
    112112
    113 void ConstantNode::classify( std::string &str ){
    114         switch ( type ){
     113void ConstantNode::classify( std::string &str ) {
     114        switch ( type ) {
    115115          case Integer:
    116116          case Float:
     
    130130                        std::transform( sfx.begin(), sfx.end(), sfx.begin(), tolower_hack );
    131131
    132                         if ( sfx.find("ll") != string::npos ){
     132                        if ( sfx.find("ll") != string::npos ) {
    133133                                longs = 2;
    134                         } else if ( sfx.find("l") != string::npos ){
     134                        } else if ( sfx.find("l") != string::npos ) {
    135135                                longs = 1;
    136136                        } // if
     
    163163ConstantNode *ConstantNode::append( std::string *newValue ) {
    164164        if ( newValue ) {
    165                 if ( type == String ){
     165                if ( type == String ) {
    166166                        std::string temp = *newValue;
    167167                        value.resize( value.size() - 1 );
     
    209209        BasicType *bt;
    210210
    211         switch ( get_type()){
     211        switch ( get_type()) {
    212212          case Integer:
    213213                /* Cfr. standard 6.4.4.1 */
     
    354354                return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));
    355355        } else {
    356                 switch ( op->get_type()){
     356                switch ( op->get_type()) {
    357357                  case OperatorNode::Incr:
    358358                  case OperatorNode::Decr:
     
    563563}
    564564
    565 void CompositeExprNode::set_function( ExpressionNode *f ){
     565void CompositeExprNode::set_function( ExpressionNode *f ) {
    566566        function = f;
    567567}
    568568
    569 void CompositeExprNode::set_args( ExpressionNode *args ){
     569void CompositeExprNode::set_args( ExpressionNode *args ) {
    570570        arguments = args;
    571571}
     
    579579}
    580580
    581 void CompositeExprNode::add_arg( ExpressionNode *arg ){
     581void CompositeExprNode::add_arg( ExpressionNode *arg ) {
    582582        if ( arguments )
    583583                arguments->set_link( arg );
     
    594594}
    595595
    596 CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ){
     596CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ) {
    597597        add_arg( exp );
    598598
     
    646646}
    647647
    648 ForCtlExprNode::~ForCtlExprNode(){
     648ForCtlExprNode::~ForCtlExprNode() {
    649649        delete init;
    650650        delete condition;
  • translator/Parser/ParseNode.cc

    r01aeade ra08ba92  
    1010// Created On       : Sat May 16 13:26:29 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 13:27:51 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:48:30 2015
     13// Update Count     : 3
    1414//
    1515
     
    2424
    2525ParseNode *ParseNode::set_name( string _name ) {
    26     name = _name;
    27     return this;
     26        name = _name;
     27        return this;
    2828}
    2929
    3030ParseNode *ParseNode::set_name( string *_name ) {
    31     name = *_name; // deep copy
    32     delete _name;
     31        name = *_name; // deep copy
     32        delete _name;
    3333
    34     return this;
     34        return this;
    3535}
    3636
    3737ParseNode::~ParseNode( void ) {
    38     delete next;
     38        delete next;
    3939};
    4040
    4141string ParseNode::get_name( void ) {
    42     return name;
     42        return name;
    4343}
    4444
    4545ParseNode *ParseNode::get_link( void ) const {
    46     return next;
     46        return next;
    4747}
    4848
    4949ParseNode *ParseNode::get_last(void) {
    50     ParseNode *current = this;
     50        ParseNode *current = this;
    5151
    52     while ( current->get_link() != 0 )
     52        while ( current->get_link() != 0 )
    5353        current = current->get_link();
    5454
    55     return current;
     55        return current;
    5656}
    5757
    58 ParseNode *ParseNode::set_link(ParseNode *_next){
    59     ParseNode *follow;
     58ParseNode *ParseNode::set_link(ParseNode *_next) {
     59        ParseNode *follow;
    6060
    61     if ( _next == 0 ) return this;
     61        if ( _next == 0 ) return this;
    6262
    63     for ( follow = this; follow->next != 0; follow = follow->next );
    64     follow->next = _next;
     63        for ( follow = this; follow->next != 0; follow = follow->next );
     64        follow->next = _next;
    6565
    66     return this;
     66        return this;
    6767}
    6868
    6969const string ParseNode::get_name(void) const {
    70     return name;
     70        return name;
    7171}
    7272
     
    7575
    7676void ParseNode::printList( std::ostream &os, int indent ) const {
    77     print( os, indent );
     77        print( os, indent );
    7878
    79     if ( next ) {
     79        if ( next ) {
    8080        next->printList( os, indent );
    81     }
     81        }
    8282}
    8383
    8484ParseNode &ParseNode::operator,( ParseNode &p ) {
    85     set_link( &p );
     85        set_link( &p );
    8686
    87     return *this;
     87        return *this;
    8888}
    8989
    9090ParseNode *mkList( ParseNode &pn ) {
    91     // it just relies on `operator,' to take care of the "arguments" and provides a nice interface to an awful-looking
    92     // address-of, rendering, for example (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7))
    93     // (although "nice" is probably not the word)
    94     return &pn;
     91        // it just relies on `operator,' to take care of the "arguments" and provides a nice interface to an awful-looking
     92        // address-of, rendering, for example (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7))
     93        // (although "nice" is probably not the word)
     94        return &pn;
    9595}
    9696
  • translator/Parser/StatementNode.cc

    r01aeade ra08ba92  
    171171void StatementNode::print( std::ostream &os, int indent ) const {
    172172        if ( labels != 0 )
    173                 if (! labels->empty()) {
     173                if ( ! labels->empty()) {
    174174                        std::list<std::string>::const_iterator i;
    175175
  • translator/Parser/TypedefTable.cc

    r01aeade ra08ba92  
    123123        for ( tableType::iterator i = table.begin(); i != table.end(); ) {
    124124                list<Entry> &declList = (*i ).second;
    125                 while (! declList.empty() && declList.front().scope == currentScope ) {
     125                while ( ! declList.empty() && declList.front().scope == currentScope ) {
    126126                        declList.pop_front();
    127127                }
  • translator/Parser/lex.l

    r01aeade ra08ba92  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sat May 16 12:14:18 2015
    13  * Update Count     : 330
     12 * Last Modified On : Tue May 19 15:41:54 2015
     13 * Update Count     : 331
    1414 */
    1515
  • translator/ResolvExpr/ResolveTypeof.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 12:12:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 12:13:38 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:49:04 2015
     13// Update Count     : 3
    1414//
    1515
     
    2323
    2424namespace ResolvExpr {
    25     namespace {
     25        namespace {
    2626#if 0
    2727                void
     
    3434                }
    3535#endif
    36     }
     36        }
    3737
    38     class ResolveTypeof : public Mutator {
    39       public:
     38        class ResolveTypeof : public Mutator {
     39          public:
    4040                ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {}
    4141                Type *mutate( TypeofType *typeofType );
    4242
    43       private:
     43          private:
    4444                const SymTab::Indexer &indexer;
    45     };
     45        };
    4646
    47     Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {
     47        Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {
    4848                ResolveTypeof mutator( indexer );
    4949                return type->acceptMutator( mutator );
    50     }
     50        }
    5151
    52     Type *ResolveTypeof::mutate( TypeofType *typeofType ) {
     52        Type *ResolveTypeof::mutate( TypeofType *typeofType ) {
    5353#if 0
    5454                std::cout << "resolving typeof: ";
     
    7171                } // if
    7272                return typeofType;
    73     }
     73        }
    7474} // namespace ResolvExpr
    7575
  • translator/SymTab/IdTable.cc

    r01aeade ra08ba92  
    139139                                std::stack<DeclEntry> stack = inner->second;
    140140                                os << "dumping a stack" << std::endl;
    141                                 while (! stack.empty()) {
     141                                while ( ! stack.empty()) {
    142142                                        DeclEntry d = stack.top();
    143143                                        os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl;
  • translator/SymTab/IdTable.h

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:30:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:31:45 2015
    13 // Update Count     : 3
     12// Last Modified On : Tue May 19 16:49:33 2015
     13// Update Count     : 4
    1414//
    1515
     
    2525
    2626namespace SymTab {
    27     class IdTable {
    28       public:
     27        class IdTable {
     28          public:
    2929                IdTable();
    3030 
     
    3636 
    3737                void dump( std::ostream &os ) const;                    // debugging
    38       private:
     38          private:
    3939                typedef std::pair< DeclarationWithType*, int > DeclEntry;
    4040                typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType;
     
    4343                OuterTableType table;
    4444                int scopeLevel;
    45     };
     45        };
    4646} // namespace SymTab
    4747
  • translator/SymTab/Indexer.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:37:33 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:38:44 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:49:55 2015
     13// Update Count     : 3
    1414//
    1515
     
    2626
    2727namespace SymTab {
    28     Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}
    29 
    30     Indexer::~Indexer() {}
    31 
    32     void Indexer::visit( ObjectDecl *objectDecl ) {
     28        Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}
     29
     30        Indexer::~Indexer() {}
     31
     32        void Indexer::visit( ObjectDecl *objectDecl ) {
    3333                maybeAccept( objectDecl->get_type(), *this );
    3434                maybeAccept( objectDecl->get_init(), *this );
     
    3838                        idTable.addDecl( objectDecl );
    3939                } // if
    40     }
    41 
    42     void Indexer::visit( FunctionDecl *functionDecl ) {
     40        }
     41
     42        void Indexer::visit( FunctionDecl *functionDecl ) {
    4343                if ( functionDecl->get_name() == "" ) return;
    4444                debugPrint( "Adding function " << functionDecl->get_name() << std::endl );
     
    4949                maybeAccept( functionDecl->get_statements(), *this );
    5050                leaveScope();
    51     }
     51        }
    5252
    5353/********
     
    7070 */
    7171
    72     void Indexer::visit( TypeDecl *typeDecl ) {
     72        void Indexer::visit( TypeDecl *typeDecl ) {
    7373                // see A NOTE ON THE ORDER OF TRAVERSAL, above
    7474                // note that assertions come after the type is added to the symtab, since they aren't part
     
    8181                typeTable.add( typeDecl );
    8282                acceptAll( typeDecl->get_assertions(), *this );
    83     }
    84 
    85     void Indexer::visit( TypedefDecl *typeDecl ) {
     83        }
     84
     85        void Indexer::visit( TypedefDecl *typeDecl ) {
    8686                enterScope();
    8787                acceptAll( typeDecl->get_parameters(), *this );
     
    9090                debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );
    9191                typeTable.add( typeDecl );
    92     }
    93 
    94     void Indexer::visit( StructDecl *aggregateDecl ) {
     92        }
     93
     94        void Indexer::visit( StructDecl *aggregateDecl ) {
    9595                // make up a forward declaration and add it before processing the members
    9696                StructDecl fwdDecl( aggregateDecl->get_name() );
     
    107107                // this addition replaces the forward declaration
    108108                structTable.add( aggregateDecl );
    109     }
    110 
    111     void Indexer::visit( UnionDecl *aggregateDecl ) {
     109        }
     110
     111        void Indexer::visit( UnionDecl *aggregateDecl ) {
    112112                // make up a forward declaration and add it before processing the members
    113113                UnionDecl fwdDecl( aggregateDecl->get_name() );
     
    123123                debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
    124124                unionTable.add( aggregateDecl );
    125     }
    126 
    127     void Indexer::visit( EnumDecl *aggregateDecl ) {
     125        }
     126
     127        void Indexer::visit( EnumDecl *aggregateDecl ) {
    128128                debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );
    129129                enumTable.add( aggregateDecl );
    130130                // unlike structs, contexts, and unions, enums inject their members into the global scope
    131131                acceptAll( aggregateDecl->get_members(), *this );
    132     }
    133 
    134     void Indexer::visit( ContextDecl *aggregateDecl ) {
     132        }
     133
     134        void Indexer::visit( ContextDecl *aggregateDecl ) {
    135135                enterScope();
    136136                acceptAll( aggregateDecl->get_parameters(), *this );
     
    140140                debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
    141141                contextTable.add( aggregateDecl );
    142     }
    143 
    144     void Indexer::visit( CompoundStmt *compoundStmt ) {
     142        }
     143
     144        void Indexer::visit( CompoundStmt *compoundStmt ) {
    145145                enterScope();
    146146                acceptAll( compoundStmt->get_kids(), *this );
    147147                leaveScope();
    148     }
    149 
    150     void Indexer::visit( ContextInstType *contextInst ) {
     148        }
     149
     150        void Indexer::visit( ContextInstType *contextInst ) {
    151151                acceptAll( contextInst->get_parameters(), *this );
    152152                acceptAll( contextInst->get_members(), *this );
    153     }
    154 
    155     void Indexer::visit( StructInstType *structInst ) {
     153        }
     154
     155        void Indexer::visit( StructInstType *structInst ) {
    156156                if ( ! structTable.lookup( structInst->get_name() ) ) {
    157157                        debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl );
     
    161161                acceptAll( structInst->get_parameters(), *this );
    162162                leaveScope();
    163     }
    164 
    165     void Indexer::visit( UnionInstType *unionInst ) {
     163        }
     164
     165        void Indexer::visit( UnionInstType *unionInst ) {
    166166                if ( ! unionTable.lookup( unionInst->get_name() ) ) {
    167167                        debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl );
     
    171171                acceptAll( unionInst->get_parameters(), *this );
    172172                leaveScope();
    173     }
    174 
    175     void Indexer::visit( ForStmt *forStmt ) {
    176         // for statements introduce a level of scope
    177         enterScope();
    178         Visitor::visit( forStmt );
    179         leaveScope();
    180     }
    181 
    182 
    183     void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {
     173        }
     174
     175        void Indexer::visit( ForStmt *forStmt ) {
     176            // for statements introduce a level of scope
     177            enterScope();
     178            Visitor::visit( forStmt );
     179            leaveScope();
     180        }
     181
     182
     183        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {
    184184                idTable.lookupId( id, list );
    185     }
    186 
    187     DeclarationWithType* Indexer::lookupId( const std::string &id) const {
     185        }
     186
     187        DeclarationWithType* Indexer::lookupId( const std::string &id) const {
    188188                return idTable.lookupId(id);
    189     }
    190 
    191     NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
     189        }
     190
     191        NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
    192192                return typeTable.lookup( id );
    193     }
    194 
    195     StructDecl *Indexer::lookupStruct( const std::string &id ) const {
     193        }
     194
     195        StructDecl *Indexer::lookupStruct( const std::string &id ) const {
    196196                return structTable.lookup( id );
    197     }
    198 
    199     EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
     197        }
     198
     199        EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
    200200                return enumTable.lookup( id );
    201     }
    202 
    203     UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
     201        }
     202
     203        UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
    204204                return unionTable.lookup( id );
    205     }
    206 
    207     ContextDecl  * Indexer::lookupContext( const std::string &id ) const {
     205        }
     206
     207        ContextDecl  * Indexer::lookupContext( const std::string &id ) const {
    208208                return contextTable.lookup( id );
    209     }
    210 
    211     void Indexer::enterScope() {
     209        }
     210
     211        void Indexer::enterScope() {
    212212                if ( doDebug ) {
    213213                        std::cout << "--- Entering scope" << std::endl;
     
    219219                unionTable.enterScope();
    220220                contextTable.enterScope();
    221     }
    222 
    223     void Indexer::leaveScope() {
     221        }
     222
     223        void Indexer::leaveScope() {
    224224                using std::cout;
    225225                using std::endl;
     
    240240                unionTable.leaveScope();
    241241                contextTable.leaveScope();
    242     }
    243 
    244     void Indexer::print( std::ostream &os, int indent ) const {
    245         using std::cerr;
    246         using std::endl;
    247 
    248         cerr << "===idTable===" << endl;
    249         idTable.dump( os );
    250         cerr << "===typeTable===" << endl;
    251         typeTable.dump( os );
    252         cerr << "===structTable===" << endl;
    253         structTable.dump( os );
    254         cerr << "===enumTable===" << endl;
    255         enumTable.dump( os );
    256         cerr << "===unionTable===" << endl;
    257         unionTable.dump( os );
    258         cerr << "===contextTable===" << endl;
    259         contextTable.dump( os );
     242        }
     243
     244        void Indexer::print( std::ostream &os, int indent ) const {
     245            using std::cerr;
     246            using std::endl;
     247
     248            cerr << "===idTable===" << endl;
     249            idTable.dump( os );
     250            cerr << "===typeTable===" << endl;
     251            typeTable.dump( os );
     252            cerr << "===structTable===" << endl;
     253            structTable.dump( os );
     254            cerr << "===enumTable===" << endl;
     255            enumTable.dump( os );
     256            cerr << "===unionTable===" << endl;
     257            unionTable.dump( os );
     258            cerr << "===contextTable===" << endl;
     259            contextTable.dump( os );
    260260#if 0
    261261                idTable.dump( os );
     
    266266                contextTable.dump( os );
    267267#endif
    268     }
     268        }
    269269} // namespace SymTab
    270270
  • translator/SymTab/Indexer.h

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:38:55 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:40:17 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:51:21 2015
     13// Update Count     : 3
    1414//
    1515
     
    2727
    2828namespace SymTab {
    29     class Indexer : public Visitor {
    30       public:
    31         Indexer( bool useDebug = false );
    32         virtual ~Indexer();
     29        class Indexer : public Visitor {
     30          public:
     31                Indexer( bool useDebug = false );
     32                virtual ~Indexer();
    3333
    34         //using Visitor::visit;
    35         virtual void visit( ObjectDecl *objectDecl );
    36         virtual void visit( FunctionDecl *functionDecl );
    37         virtual void visit( TypeDecl *typeDecl );
    38         virtual void visit( TypedefDecl *typeDecl );
    39         virtual void visit( StructDecl *aggregateDecl );
    40         virtual void visit( UnionDecl *aggregateDecl );
    41         virtual void visit( EnumDecl *aggregateDecl );
    42         virtual void visit( ContextDecl *aggregateDecl );
     34                //using Visitor::visit;
     35                virtual void visit( ObjectDecl *objectDecl );
     36                virtual void visit( FunctionDecl *functionDecl );
     37                virtual void visit( TypeDecl *typeDecl );
     38                virtual void visit( TypedefDecl *typeDecl );
     39                virtual void visit( StructDecl *aggregateDecl );
     40                virtual void visit( UnionDecl *aggregateDecl );
     41                virtual void visit( EnumDecl *aggregateDecl );
     42                virtual void visit( ContextDecl *aggregateDecl );
    4343
    44         virtual void visit( CompoundStmt *compoundStmt );
     44                virtual void visit( CompoundStmt *compoundStmt );
    4545
    46         virtual void visit( ContextInstType *contextInst );
    47         virtual void visit( StructInstType *contextInst );
    48         virtual void visit( UnionInstType *contextInst );
     46                virtual void visit( ContextInstType *contextInst );
     47                virtual void visit( StructInstType *contextInst );
     48                virtual void visit( UnionInstType *contextInst );
    4949
    50         virtual void visit( ForStmt *forStmt );
     50                virtual void visit( ForStmt *forStmt );
    5151
    52         // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
    53         // explicitly when scopes begin and end
    54         void enterScope();
    55         void leaveScope();
     52                // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
     53                // explicitly when scopes begin and end
     54                void enterScope();
     55                void leaveScope();
    5656
    57         void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const;
    58         DeclarationWithType* lookupId( const std::string &id) const;
    59         NamedTypeDecl *lookupType( const std::string &id ) const;
    60         StructDecl *lookupStruct( const std::string &id ) const;
    61         EnumDecl *lookupEnum( const std::string &id ) const;
    62         UnionDecl *lookupUnion( const std::string &id ) const;
    63         ContextDecl *lookupContext( const std::string &id ) const;
     57                void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const;
     58                DeclarationWithType* lookupId( const std::string &id) const;
     59                NamedTypeDecl *lookupType( const std::string &id ) const;
     60                StructDecl *lookupStruct( const std::string &id ) const;
     61                EnumDecl *lookupEnum( const std::string &id ) const;
     62                UnionDecl *lookupUnion( const std::string &id ) const;
     63                ContextDecl *lookupContext( const std::string &id ) const;
    6464 
    65         void print( std::ostream &os, int indent = 0 ) const;
    66       private:
    67         IdTable idTable;
    68         TypeTable typeTable;
    69         StructTable structTable;
    70         EnumTable enumTable;
    71         UnionTable unionTable;
    72         ContextTable contextTable;
     65                void print( std::ostream &os, int indent = 0 ) const;
     66          private:
     67                IdTable idTable;
     68                TypeTable typeTable;
     69                StructTable structTable;
     70                EnumTable enumTable;
     71                UnionTable unionTable;
     72                ContextTable contextTable;
    7373 
    74         bool doDebug;                                   // display debugging trace
    75     };
     74                bool doDebug;                                   // display debugging trace
     75        };
    7676} // namespace SymTab
    7777
  • translator/SymTab/Mangler.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:40:29 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:43:49 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:50:47 2015
     13// Update Count     : 3
    1414//
    1515
     
    3030
    3131namespace SymTab {
    32     Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {
     32        Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {
    3333        }
    3434
     
    3737//{
    3838//}
    39     Mangler::Mangler( const Mangler &rhs ) : mangleName() {
     39        Mangler::Mangler( const Mangler &rhs ) : mangleName() {
    4040                varNums = rhs.varNums;
    4141                nextVarNum = rhs.nextVarNum;
    4242                isTopLevel = rhs.isTopLevel;
    43     }
    44 
    45     void Mangler::mangleDecl( DeclarationWithType *declaration ) {
     43        }
     44
     45        void Mangler::mangleDecl( DeclarationWithType *declaration ) {
    4646                bool wasTopLevel = isTopLevel;
    4747                if ( isTopLevel ) {
     
    6060                maybeAccept( declaration->get_type(), *this );
    6161                isTopLevel = wasTopLevel;
    62     }
    63 
    64     void Mangler::visit( ObjectDecl *declaration ) {
     62        }
     63
     64        void Mangler::visit( ObjectDecl *declaration ) {
    6565                mangleDecl( declaration );
    66     }
    67 
    68     void Mangler::visit( FunctionDecl *declaration ) {
     66        }
     67
     68        void Mangler::visit( FunctionDecl *declaration ) {
    6969                mangleDecl( declaration );
    70     }
    71 
    72     void Mangler::visit( VoidType *voidType ) {
     70        }
     71
     72        void Mangler::visit( VoidType *voidType ) {
    7373                printQualifiers( voidType );
    7474                mangleName << "v";
    75     }
    76 
    77     void Mangler::visit( BasicType *basicType ) {
     75        }
     76
     77        void Mangler::visit( BasicType *basicType ) {
    7878                static const char *btLetter[] = {
    7979                        "b",    // Bool
     
    102102                printQualifiers( basicType );
    103103                mangleName << btLetter[ basicType->get_kind() ];
    104     }
    105 
    106     void Mangler::visit( PointerType *pointerType ) {
     104        }
     105
     106        void Mangler::visit( PointerType *pointerType ) {
    107107                printQualifiers( pointerType );
    108108                mangleName << "P";
    109109                maybeAccept( pointerType->get_base(), *this );
    110     }
    111 
    112     void Mangler::visit( ArrayType *arrayType ) {
     110        }
     111
     112        void Mangler::visit( ArrayType *arrayType ) {
    113113                // TODO: encode dimension
    114114                printQualifiers( arrayType );
    115115                mangleName << "A0";
    116116                maybeAccept( arrayType->get_base(), *this );
    117     }
    118 
    119     namespace {
     117        }
     118
     119        namespace {
    120120                inline std::list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) {
    121121                        std::list< Type* > ret;
     
    124124                        return ret;
    125125                }
    126     }
    127 
    128     void Mangler::visit( FunctionType *functionType ) {
     126        }
     127
     128        void Mangler::visit( FunctionType *functionType ) {
    129129                printQualifiers( functionType );
    130130                mangleName << "F";
     
    135135                acceptAll( paramTypes, *this );
    136136                mangleName << "_";
    137     }
    138 
    139     void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {
     137        }
     138
     139        void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {
    140140                printQualifiers( refType );
    141141                mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();
    142     }
    143 
    144     void Mangler::visit( StructInstType *aggregateUseType ) {
     142        }
     143
     144        void Mangler::visit( StructInstType *aggregateUseType ) {
    145145                mangleRef( aggregateUseType, "s" );
    146     }
    147 
    148     void Mangler::visit( UnionInstType *aggregateUseType ) {
     146        }
     147
     148        void Mangler::visit( UnionInstType *aggregateUseType ) {
    149149                mangleRef( aggregateUseType, "u" );
    150     }
    151 
    152     void Mangler::visit( EnumInstType *aggregateUseType ) {
     150        }
     151
     152        void Mangler::visit( EnumInstType *aggregateUseType ) {
    153153                mangleRef( aggregateUseType, "e" );
    154     }
    155 
    156     void Mangler::visit( TypeInstType *typeInst ) {
     154        }
     155
     156        void Mangler::visit( TypeInstType *typeInst ) {
    157157                VarMapType::iterator varNum = varNums.find( typeInst->get_name() );
    158158                if ( varNum == varNums.end() ) {
     
    176176                        mangleName << std::string( numStream.str(), numStream.pcount() );
    177177                } // if
    178     }
    179 
    180     void Mangler::visit( TupleType *tupleType ) {
     178        }
     179
     180        void Mangler::visit( TupleType *tupleType ) {
    181181                printQualifiers( tupleType );
    182182                mangleName << "T";
    183183                acceptAll( tupleType->get_types(), *this );
    184184                mangleName << "_";
    185     }
    186 
    187     void Mangler::visit( TypeDecl *decl ) {
     185        }
     186
     187        void Mangler::visit( TypeDecl *decl ) {
    188188                static const char *typePrefix[] = { "BT", "BD", "BF" };
    189189                mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name();
    190     }
    191 
    192     void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) {
     190        }
     191
     192        void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) {
    193193                for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) {
    194194                        os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl;
    195195                } // for
    196     }
    197 
    198     void Mangler::printQualifiers( Type *type ) {
     196        }
     197
     198        void Mangler::printQualifiers( Type *type ) {
    199199                if ( ! type->get_forall().empty() ) {
    200200                        std::list< std::string > assertionNames;
     
    242242                        mangleName << "A";
    243243                } // if
    244     }
     244        }
    245245} // namespace SymTab
    246246
  • translator/SymTab/Mangler.h

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:44:03 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:45:05 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:49:21 2015
     13// Update Count     : 3
    1414//
    1515
     
    2222
    2323namespace SymTab {
    24     class Mangler : public Visitor {
    25       public:
     24        class Mangler : public Visitor {
     25          public:
    2626                template< typename SynTreeClass >
    2727            static std::string mangle( SynTreeClass *decl ); // interface to clients
     
    4444 
    4545                std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); }
    46       private:
     46          private:
    4747                std::ostrstream mangleName;
    4848                typedef std::map< std::string, std::pair< int, int > > VarMapType;
     
    5858 
    5959                void printQualifiers( Type *type );
    60     }; // Mangler
     60        }; // Mangler
    6161
    62     template< typename SynTreeClass >
    63     std::string Mangler::mangle( SynTreeClass *decl ) {
     62        template< typename SynTreeClass >
     63        std::string Mangler::mangle( SynTreeClass *decl ) {
    6464                Mangler mangler;
    6565                maybeAccept( decl, mangler );
    6666                return mangler.get_mangleName();
    67     }
     67        }
    6868} // SymTab
    6969
  • translator/SymTab/StackTable.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:45:15 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:46:59 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:51:53 2015
     13// Update Count     : 3
    1414//
    1515
     
    1919
    2020namespace SymTab {
    21     template< typename Element, typename ConflictFunction >
    22     StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) {
     21        template< typename Element, typename ConflictFunction >
     22        StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) {
    2323        }
    2424
    25     template< typename Element, typename ConflictFunction >
    26     void StackTable< Element, ConflictFunction >::enterScope() {
     25        template< typename Element, typename ConflictFunction >
     26        void StackTable< Element, ConflictFunction >::enterScope() {
    2727                scopeLevel++;
    28     }
     28        }
    2929
    30     template< typename Element, typename ConflictFunction >
    31     void StackTable< Element, ConflictFunction >::leaveScope() {
     30        template< typename Element, typename ConflictFunction >
     31        void StackTable< Element, ConflictFunction >::leaveScope() {
    3232                for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) {
    3333                        std::stack< Entry >& entry = it->second;
     
    3838                scopeLevel--;
    3939                assert( scopeLevel >= 0 );
    40     }
     40        }
    4141
    42     template< typename Element, typename ConflictFunction >
    43     void StackTable< Element, ConflictFunction >::add( Element *type ) {
     42        template< typename Element, typename ConflictFunction >
     43        void StackTable< Element, ConflictFunction >::add( Element *type ) {
    4444                std::stack< Entry >& entry = table[ type->get_name() ];
    4545                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     
    4848                        entry.push( Entry( type, scopeLevel ) );
    4949                } // if
    50     }
     50        }
    5151
    52     template< typename Element, typename ConflictFunction >
    53     void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) {
     52        template< typename Element, typename ConflictFunction >
     53        void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) {
    5454                add( new Element( fwdDeclName ) );
    55     }
     55        }
    5656
    57     template< typename Element, typename ConflictFunction >
    58     Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const {
     57        template< typename Element, typename ConflictFunction >
     58        Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const {
    5959                typename TableType::const_iterator it = table.find( id );
    6060                if ( it == table.end() ) {
     
    6565                        return 0;
    6666                } // if
    67     }
     67        }
    6868
    69     template< typename Element, typename ConflictFunction >
    70     void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const {
     69        template< typename Element, typename ConflictFunction >
     70        void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const {
    7171                for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) {
    7272                        const std::stack< Entry >& entry = it->second;
     
    7575                        } // if
    7676                } // for
    77     }
     77        }
    7878} // namespace SymTab
    7979
  • translator/SymTab/StackTable.h

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:47:10 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:48:15 2015
    13 // Update Count     : 3
     12// Last Modified On : Tue May 19 16:50:36 2015
     13// Update Count     : 4
    1414//
    1515
     
    2323
    2424namespace SymTab {
    25     template< typename Element, typename ConflictFunction >
     25        template< typename Element, typename ConflictFunction >
    2626        class StackTable {
    27       public:
     27          public:
    2828                StackTable();
    2929
     
    3535
    3636                void dump( std::ostream &os ) const;                    // debugging
    37       private:
     37          private:
    3838                typedef std::pair< Element*, int > Entry;
    3939                typedef std::map< std::string, std::stack< Entry > > TableType;
     
    4242                TableType table;
    4343                int scopeLevel;
    44     };
     44        };
    4545} // SymTab
    4646
  • translator/SymTab/TypeTable.h

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:48:32 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:49:49 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:50:25 2015
     13// Update Count     : 3
    1414//
    1515
     
    2727
    2828namespace SymTab {
    29     class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > {
    30       public:
     29        class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > {
     30          public:
    3131                NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) {
    3232                        if ( existing->get_base() == 0 ) {
     
    4040                        return 0;
    4141                }
    42     };
     42        };
    4343
    44     typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable;
     44        typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable;
    4545} // namespace SymTab
    4646
  • translator/SymTab/Validate.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:53:16 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:50:09 2015
     13// Update Count     : 3
    1414//
    1515
     
    5757
    5858namespace SymTab {
    59     class HoistStruct : public Visitor {
    60       public:
     59        class HoistStruct : public Visitor {
     60          public:
    6161                static void hoistStruct( std::list< Declaration * > &translationUnit );
    6262 
     
    7474                virtual void visit( CaseStmt *caseStmt );
    7575                virtual void visit( CatchStmt *catchStmt );
    76       private:
     76          private:
    7777                HoistStruct();
    7878
     
    8181                std::list< Declaration * > declsToAdd;
    8282                bool inStruct;
    83     };
    84 
    85     class Pass1 : public Visitor {
     83        };
     84
     85        class Pass1 : public Visitor {
    8686                typedef Visitor Parent;
    8787                virtual void visit( EnumDecl *aggregateDecl );
    8888                virtual void visit( FunctionType *func );
    89     };
    90  
    91     class Pass2 : public Indexer {
     89        };
     90 
     91        class Pass2 : public Indexer {
    9292                typedef Indexer Parent;
    93       public:
     93          public:
    9494                Pass2( bool doDebug, const Indexer *indexer );
    95       private:
     95          private:
    9696                virtual void visit( StructInstType *structInst );
    9797                virtual void visit( UnionInstType *unionInst );
     
    107107                ForwardStructsType forwardStructs;
    108108                ForwardUnionsType forwardUnions;
    109     };
    110 
    111     class Pass3 : public Indexer {
     109        };
     110
     111        class Pass3 : public Indexer {
    112112                typedef Indexer Parent;
    113       public:
     113          public:
    114114                Pass3( const Indexer *indexer );
    115       private:
     115          private:
    116116                virtual void visit( ObjectDecl *object );
    117117                virtual void visit( FunctionDecl *func );
    118118
    119119                const Indexer *indexer;
    120     };
    121 
    122     class AddStructAssignment : public Visitor {
    123       public:
     120        };
     121
     122        class AddStructAssignment : public Visitor {
     123          public:
    124124                static void addStructAssignment( std::list< Declaration * > &translationUnit );
    125125
     
    145145
    146146                AddStructAssignment() : functionNesting( 0 ) {}
    147       private:
     147          private:
    148148                template< typename StmtClass > void visitStatement( StmtClass *stmt );
    149149 
     
    151151                std::set< std::string > structsDone;
    152152                unsigned int functionNesting;                   // current level of nested functions
    153     };
    154 
    155     class EliminateTypedef : public Mutator {
    156       public:
     153        };
     154
     155        class EliminateTypedef : public Mutator {
     156          public:
    157157                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    158       private:
     158          private:
    159159                virtual Declaration *mutate( TypedefDecl *typeDecl );
    160160                virtual TypeDecl *mutate( TypeDecl *typeDecl );
     
    166166 
    167167                std::map< std::string, TypedefDecl * > typedefNames;
    168     };
    169 
    170     void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
     168        };
     169
     170        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    171171                Pass1 pass1;
    172172                Pass2 pass2( doDebug, 0 );
     
    178178                AddStructAssignment::addStructAssignment( translationUnit );
    179179                acceptAll( translationUnit, pass3 );
    180     }
    181    
    182     void validateType( Type *type, const Indexer *indexer ) {
     180        }
     181       
     182        void validateType( Type *type, const Indexer *indexer ) {
    183183                Pass1 pass1;
    184184                Pass2 pass2( false, indexer );
     
    187187                type->accept( pass2 );
    188188                type->accept( pass3 );
    189     }
    190 
    191     template< typename Visitor >
    192     void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
     189        }
     190
     191        template< typename Visitor >
     192        void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
    193193                std::list< Declaration * >::iterator i = translationUnit.begin();
    194194                while ( i != translationUnit.end() ) {
     
    201201                        i = next;
    202202                } // while
    203     }
    204 
    205     void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
     203        }
     204
     205        void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
    206206                HoistStruct hoister;
    207207                acceptAndAdd( translationUnit, hoister, true );
    208     }
    209 
    210     HoistStruct::HoistStruct() : inStruct( false ) {
    211     }
    212 
    213     void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {
     208        }
     209
     210        HoistStruct::HoistStruct() : inStruct( false ) {
     211        }
     212
     213        void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {
    214214                std::list< Declaration * >::iterator i = declList.begin();
    215215                while ( i != declList.end() ) {
     
    224224                        i = next;
    225225                } // while
    226     }
    227 
    228     bool isStructOrUnion( Declaration *decl ) {
     226        }
     227
     228        bool isStructOrUnion( Declaration *decl ) {
    229229                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
    230     }
    231 
    232     template< typename AggDecl >
    233     void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
     230        }
     231
     232        template< typename AggDecl >
     233        void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
    234234                if ( inStruct ) {
    235235                        // Add elements in stack order corresponding to nesting structure.
     
    243243                // Always remove the hoisted aggregate from the inner structure.
    244244                filter( aggregateDecl->get_members(), isStructOrUnion, false );
    245     }
    246 
    247     void HoistStruct::visit( StructDecl *aggregateDecl ) {
     245        }
     246
     247        void HoistStruct::visit( StructDecl *aggregateDecl ) {
    248248                handleAggregate( aggregateDecl );
    249     }
    250 
    251     void HoistStruct::visit( UnionDecl *aggregateDecl ) {
     249        }
     250
     251        void HoistStruct::visit( UnionDecl *aggregateDecl ) {
    252252                handleAggregate( aggregateDecl );
    253     }
    254 
    255     void HoistStruct::visit( CompoundStmt *compoundStmt ) {
     253        }
     254
     255        void HoistStruct::visit( CompoundStmt *compoundStmt ) {
    256256                addVisit( compoundStmt, *this );
    257     }
    258 
    259     void HoistStruct::visit( IfStmt *ifStmt ) {
     257        }
     258
     259        void HoistStruct::visit( IfStmt *ifStmt ) {
    260260                addVisit( ifStmt, *this );
    261     }
    262 
    263     void HoistStruct::visit( WhileStmt *whileStmt ) {
     261        }
     262
     263        void HoistStruct::visit( WhileStmt *whileStmt ) {
    264264                addVisit( whileStmt, *this );
    265     }
    266 
    267     void HoistStruct::visit( ForStmt *forStmt ) {
     265        }
     266
     267        void HoistStruct::visit( ForStmt *forStmt ) {
    268268                addVisit( forStmt, *this );
    269     }
    270 
    271     void HoistStruct::visit( SwitchStmt *switchStmt ) {
     269        }
     270
     271        void HoistStruct::visit( SwitchStmt *switchStmt ) {
    272272                addVisit( switchStmt, *this );
    273     }
    274 
    275     void HoistStruct::visit( ChooseStmt *switchStmt ) {
     273        }
     274
     275        void HoistStruct::visit( ChooseStmt *switchStmt ) {
    276276                addVisit( switchStmt, *this );
    277     }
    278 
    279     void HoistStruct::visit( CaseStmt *caseStmt ) {
     277        }
     278
     279        void HoistStruct::visit( CaseStmt *caseStmt ) {
    280280                addVisit( caseStmt, *this );
    281     }
    282 
    283     void HoistStruct::visit( CatchStmt *cathStmt ) {
     281        }
     282
     283        void HoistStruct::visit( CatchStmt *cathStmt ) {
    284284                addVisit( cathStmt, *this );
    285     }
    286 
    287     void Pass1::visit( EnumDecl *enumDecl ) {
     285        }
     286
     287        void Pass1::visit( EnumDecl *enumDecl ) {
    288288                // Set the type of each member of the enumeration to be EnumConstant
    289289 
     
    294294                } // for
    295295                Parent::visit( enumDecl );
    296     }
    297 
    298     namespace {
     296        }
     297
     298        namespace {
    299299                template< typename DWTIterator >
    300300                void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) {
     
    323323                        } // if
    324324                }
    325     }
    326 
    327     void Pass1::visit( FunctionType *func ) {
     325        }
     326
     327        void Pass1::visit( FunctionType *func ) {
    328328                // Fix up parameters and return types
    329329                fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func );
    330330                fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func );
    331331                Visitor::visit( func );
    332     }
    333 
    334     Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {
     332        }
     333
     334        Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {
    335335                if ( other_indexer ) {
    336336                        indexer = other_indexer;
     
    338338                        indexer = this;
    339339                } // if
    340     }
    341 
    342     void Pass2::visit( StructInstType *structInst ) {
     340        }
     341
     342        void Pass2::visit( StructInstType *structInst ) {
    343343                Parent::visit( structInst );
    344344                StructDecl *st = indexer->lookupStruct( structInst->get_name() );
     
    352352                        forwardStructs[ structInst->get_name() ].push_back( structInst );
    353353                } // if
    354     }
    355 
    356     void Pass2::visit( UnionInstType *unionInst ) {
     354        }
     355
     356        void Pass2::visit( UnionInstType *unionInst ) {
    357357                Parent::visit( unionInst );
    358358                UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
     
    365365                        forwardUnions[ unionInst->get_name() ].push_back( unionInst );
    366366                } // if
    367     }
    368 
    369     void Pass2::visit( ContextInstType *contextInst ) {
     367        }
     368
     369        void Pass2::visit( ContextInstType *contextInst ) {
    370370                Parent::visit( contextInst );
    371371                ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() );
     
    383383                } // for
    384384                applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
    385     }
    386 
    387     void Pass2::visit( StructDecl *structDecl ) {
     385        }
     386
     387        void Pass2::visit( StructDecl *structDecl ) {
    388388                if ( ! structDecl->get_members().empty() ) {
    389389                        ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
     
    396396                } // if
    397397                Indexer::visit( structDecl );
    398     }
    399 
    400     void Pass2::visit( UnionDecl *unionDecl ) {
     398        }
     399
     400        void Pass2::visit( UnionDecl *unionDecl ) {
    401401                if ( ! unionDecl->get_members().empty() ) {
    402402                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
     
    409409                } // if
    410410                Indexer::visit( unionDecl );
    411     }
    412 
    413     void Pass2::visit( TypeInstType *typeInst ) {
     411        }
     412
     413        void Pass2::visit( TypeInstType *typeInst ) {
    414414                if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
    415415                        if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
     
    417417                        } // if
    418418                } // if
    419     }
    420 
    421     Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
     419        }
     420
     421        Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
    422422                if ( other_indexer ) {
    423423                        indexer = other_indexer;
     
    425425                        indexer = this;
    426426                } // if
    427     }
    428 
    429     void forallFixer( Type *func ) {
     427        }
     428
     429        void forallFixer( Type *func ) {
    430430                // Fix up assertions
    431431                for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
     
    454454                        } // while
    455455                } // for
    456     }
    457 
    458     void Pass3::visit( ObjectDecl *object ) {
     456        }
     457
     458        void Pass3::visit( ObjectDecl *object ) {
    459459                forallFixer( object->get_type() );
    460460                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     
    463463                Parent::visit( object );
    464464                object->fixUniqueId();
    465     }
    466 
    467     void Pass3::visit( FunctionDecl *func ) {
     465        }
     466
     467        void Pass3::visit( FunctionDecl *func ) {
    468468                forallFixer( func->get_type() );
    469469                Parent::visit( func );
    470470                func->fixUniqueId();
    471     }
    472 
    473     static const std::list< std::string > noLabels;
    474 
    475     void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
     471        }
     472
     473        static const std::list< std::string > noLabels;
     474
     475        void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
    476476                AddStructAssignment visitor;
    477477                acceptAndAdd( translationUnit, visitor, false );
    478     }
    479 
    480     template< typename OutputIterator >
    481     void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) {
     478        }
     479
     480        template< typename OutputIterator >
     481        void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) {
    482482                ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member );
    483483                // unnamed bit fields are not copied as they cannot be accessed
     
    497497 
    498498                *out++ = new ExprStmt( noLabels, assignExpr );
    499     }
    500 
    501     template< typename OutputIterator >
    502     void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) {
     499        }
     500
     501        template< typename OutputIterator >
     502        void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) {
    503503                static UniqueName indexName( "_index" );
    504504 
     
    539539 
    540540                *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
    541     }
    542 
    543     Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
     541        }
     542
     543        Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
    544544                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    545545 
     
    570570 
    571571                return assignDecl;
    572     }
    573 
    574     Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
     572        }
     573
     574        Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
    575575                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    576576 
     
    598598 
    599599                return assignDecl;
    600     }
    601 
    602     void AddStructAssignment::visit( StructDecl *structDecl ) {
     600        }
     601
     602        void AddStructAssignment::visit( StructDecl *structDecl ) {
    603603                if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
    604604                        StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
     
    607607                        structsDone.insert( structDecl->get_name() );
    608608                } // if
    609     }
    610 
    611     void AddStructAssignment::visit( UnionDecl *unionDecl ) {
     609        }
     610
     611        void AddStructAssignment::visit( UnionDecl *unionDecl ) {
    612612                if ( ! unionDecl->get_members().empty() ) {
    613613                        UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
     
    615615                        declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
    616616                } // if
    617     }
    618 
    619     void AddStructAssignment::visit( TypeDecl *typeDecl ) {
     617        }
     618
     619        void AddStructAssignment::visit( TypeDecl *typeDecl ) {
    620620                CompoundStmt *stmts = 0;
    621621                TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
     
    636636                FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false );
    637637                declsToAdd.push_back( func );
    638     }
    639 
    640     void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) {
     638        }
     639
     640        void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) {
    641641                if ( ! declsToAdd.empty() ) {
    642642                        for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
     
    645645                        declsToAdd.clear();
    646646                } // if
    647     }
    648 
    649     void AddStructAssignment::visit( FunctionType *) {
     647        }
     648
     649        void AddStructAssignment::visit( FunctionType *) {
    650650                // ensure that we don't add assignment ops for types defined as part of the function
    651     }
    652 
    653     void AddStructAssignment::visit( PointerType *) {
     651        }
     652
     653        void AddStructAssignment::visit( PointerType *) {
    654654                // ensure that we don't add assignment ops for types defined as part of the pointer
    655     }
    656 
    657     void AddStructAssignment::visit( ContextDecl *) {
     655        }
     656
     657        void AddStructAssignment::visit( ContextDecl *) {
    658658                // ensure that we don't add assignment ops for types defined as part of the context
    659     }
    660 
    661     template< typename StmtClass >
    662     inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {
     659        }
     660
     661        template< typename StmtClass >
     662        inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {
    663663                std::set< std::string > oldStructs = structsDone;
    664664                addVisit( stmt, *this );
    665665                structsDone = oldStructs;
    666     }
    667 
    668     void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
     666        }
     667
     668        void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
    669669                maybeAccept( functionDecl->get_functionType(), *this );
    670670                acceptAll( functionDecl->get_oldDecls(), *this );
     
    672672                maybeAccept( functionDecl->get_statements(), *this );
    673673                functionNesting -= 1;
    674     }
    675 
    676     void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
     674        }
     675
     676        void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
    677677                visitStatement( compoundStmt );
    678     }
    679 
    680     void AddStructAssignment::visit( IfStmt *ifStmt ) {
     678        }
     679
     680        void AddStructAssignment::visit( IfStmt *ifStmt ) {
    681681                visitStatement( ifStmt );
    682     }
    683 
    684     void AddStructAssignment::visit( WhileStmt *whileStmt ) {
     682        }
     683
     684        void AddStructAssignment::visit( WhileStmt *whileStmt ) {
    685685                visitStatement( whileStmt );
    686     }
    687 
    688     void AddStructAssignment::visit( ForStmt *forStmt ) {
     686        }
     687
     688        void AddStructAssignment::visit( ForStmt *forStmt ) {
    689689                visitStatement( forStmt );
    690     }
    691 
    692     void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
     690        }
     691
     692        void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
    693693                visitStatement( switchStmt );
    694     }
    695 
    696     void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
     694        }
     695
     696        void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
    697697                visitStatement( switchStmt );
    698     }
    699 
    700     void AddStructAssignment::visit( CaseStmt *caseStmt ) {
     698        }
     699
     700        void AddStructAssignment::visit( CaseStmt *caseStmt ) {
    701701                visitStatement( caseStmt );
    702     }
    703 
    704     void AddStructAssignment::visit( CatchStmt *cathStmt ) {
     702        }
     703
     704        void AddStructAssignment::visit( CatchStmt *cathStmt ) {
    705705                visitStatement( cathStmt );
    706     }
    707 
    708     bool isTypedef( Declaration *decl ) {
     706        }
     707
     708        bool isTypedef( Declaration *decl ) {
    709709                return dynamic_cast< TypedefDecl * >( decl );
    710     }
    711 
    712     void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {
     710        }
     711
     712        void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {
    713713                EliminateTypedef eliminator;
    714714                mutateAll( translationUnit, eliminator );
    715715                filter( translationUnit, isTypedef, true );
    716     }
    717 
    718     Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
     716        }
     717
     718        Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
    719719                std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );
    720720                if ( def != typedefNames.end() ) {
     
    725725                } // if
    726726                return typeInst;
    727     }
    728 
    729     Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
     727        }
     728
     729        Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
    730730                Declaration *ret = Mutator::mutate( tyDecl );
    731731                typedefNames[ tyDecl->get_name() ] = tyDecl;
     
    745745                        return ret;
    746746                } // if
    747     }
    748 
    749     TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
     747        }
     748
     749        TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
    750750                std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );
    751751                if ( i != typedefNames.end() ) {
     
    753753                } // if
    754754                return typeDecl;
    755     }
    756 
    757     DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
     755        }
     756
     757        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
    758758                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    759759                DeclarationWithType *ret = Mutator::mutate( funcDecl );
    760760                typedefNames = oldNames;
    761761                return ret;
    762     }
    763 
    764     ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
     762        }
     763
     764        ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
    765765                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    766766                ObjectDecl *ret = Mutator::mutate( objDecl );
    767767                typedefNames = oldNames;
    768768                return ret;
    769     }
    770 
    771     Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
     769        }
     770
     771        Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
    772772                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    773773                Expression *ret = Mutator::mutate( castExpr );
    774774                typedefNames = oldNames;
    775775                return ret;
    776     }
    777 
    778     CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
     776        }
     777
     778        CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
    779779                std::map< std::string, TypedefDecl * > oldNames = typedefNames;
    780780                CompoundStmt *ret = Mutator::mutate( compoundStmt );
     
    793793                typedefNames = oldNames;
    794794                return ret;
    795     }
     795        }
    796796} // namespace SymTab
    797797
  • translator/SymTab/Validate.h

    r01aeade ra08ba92  
    1111// Created On       : Sun May 17 21:53:34 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sun May 17 21:55:09 2015
    14 // Update Count     : 2
     13// Last Modified On : Tue May 19 16:49:43 2015
     14// Update Count     : 3
    1515//
    1616
     
    2121
    2222namespace SymTab {
    23     class Indexer;
     23        class Indexer;
    2424
    25     void validate( std::list< Declaration * > &translationUnit, bool doDebug = false );
    26     void validateType( Type *type, const Indexer *indexer );
     25        void validate( std::list< Declaration * > &translationUnit, bool doDebug = false );
     26        void validateType( Type *type, const Indexer *indexer );
    2727} // namespace SymTab
    2828
  • translator/SynTree/AddressExpr.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 23:54:44 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 07:48:14 2015
    13 // Update Count     : 5
     12// Last Modified On : Tue May 19 16:52:51 2015
     13// Update Count     : 6
    1414//
    1515
     
    1919
    2020AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    21     for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) {
     21        for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) {
    2222                get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );
    23     } // for
     23        } // for
    2424}
    2525
     
    2828
    2929AddressExpr::~AddressExpr() {
    30     delete arg;
     30        delete arg;
    3131}
    3232
    3333void AddressExpr::print( std::ostream &os, int indent ) const {
    34     os << std::string( indent, ' ' ) << "Address of:" << std::endl;
    35     if ( arg ) {
     34        os << std::string( indent, ' ' ) << "Address of:" << std::endl;
     35        if ( arg ) {
    3636                arg->print( os, indent+2 );
    37     } // if
     37        } // if
    3838}
    3939
  • translator/SynTree/AggregateDecl.cc

    r01aeade ra08ba92  
    1010// Created On       : Sun May 17 23:56:39 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 07:48:23 2015
    13 // Update Count     : 4
     12// Last Modified On : Tue May 19 16:52:08 2015
     13// Update Count     : 5
    1414//
    1515
     
    2323
    2424AggregateDecl::AggregateDecl( const AggregateDecl &other ) : Parent( other ) {
    25     cloneAll( other.members, members );
    26     cloneAll( other.parameters, parameters );
     25        cloneAll( other.members, members );
     26        cloneAll( other.parameters, parameters );
    2727}
    2828
    2929AggregateDecl::~AggregateDecl() {
    30     deleteAll( members );
    31     deleteAll( parameters );
     30        deleteAll( members );
     31        deleteAll( parameters );
    3232}
    3333
    3434void AggregateDecl::print( std::ostream &os, int indent ) const {
    35     using std::string;
    36     using std::endl;
     35        using std::string;
     36        using std::endl;
    3737
    38     os << typeString() << " " << get_name();
    39     if ( ! parameters.empty() ) {
     38        os << typeString() << " " << get_name();
     39        if ( ! parameters.empty() ) {
    4040                os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    4141                printAll( parameters, os, indent+4 );
    42     } // if
    43     if ( ! members.empty() ) {
     42        } // if
     43        if ( ! members.empty() ) {
    4444                os << endl << string( indent+2, ' ' ) << "with members" << endl;
    4545                printAll( members, os, indent+4 );
    46     } // if
     46        } // if
    4747}
    4848
    4949void AggregateDecl::printShort( std::ostream &os, int indent ) const {
    50     using std::string;
    51     using std::endl;
     50        using std::string;
     51        using std::endl;
    5252
    53     os << typeString() << " " << get_name();
    54     if ( ! parameters.empty() ) {
     53        os << typeString() << " " << get_name();
     54        if ( ! parameters.empty() ) {
    5555                os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    5656                printAll( parameters, os, indent+4 );
    57     } // if
     57        } // if
    5858}
    5959
  • translator/SynTree/AttrType.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// AttrType.cc.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 07:53:48 2015
    13 // Update Count     : 1
     12// Last Modified On : Tue May 19 16:41:51 2015
     13// Update Count     : 2
    1414//
    1515
  • translator/SynTree/CodeGenVisitor.cc

    r01aeade ra08ba92  
    2222using namespace std;
    2323
    24 void CodeGenVisitor::visit( Type *type ){ }
     24void CodeGenVisitor::visit( Type *type ) { }
    2525void CodeGenVisitor::visit( BasicType *basicType ) { }
    2626
     
    2929}
    3030
    31 void CodeGenVisitor::visit( Expression *expr ){ }
     31void CodeGenVisitor::visit( Expression *expr ) { }
    3232
    3333void CodeGenVisitor::visit( ConstantExpr *cnst ) {
  • translator/SynTree/Expression.cc

    r01aeade ra08ba92  
    295295}
    296296
    297 LogicalExpr::~LogicalExpr(){
     297LogicalExpr::~LogicalExpr() {
    298298        delete arg1;
    299299        delete arg2;
  • translator/SynTree/ReferenceToType.cc

    r01aeade ra08ba92  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 10:49:00 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:52:40 2015
     13// Update Count     : 3
    1414//
    1515
     
    2727
    2828ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) {
    29     cloneAll( other.parameters, parameters );
     29        cloneAll( other.parameters, parameters );
    3030}
    3131
    3232ReferenceToType::~ReferenceToType() {
    33     deleteAll( parameters );
     33        deleteAll( parameters );
    3434}
    3535
    3636void ReferenceToType::print( std::ostream &os, int indent ) const {
    37     using std::endl;
    38    
    39     Type::print( os, indent );
    40     os << "instance of " << typeString() << " " << name << " ";
    41     if ( ! parameters.empty() ) {
     37        using std::endl;
     38       
     39        Type::print( os, indent );
     40        os << "instance of " << typeString() << " " << name << " ";
     41        if ( ! parameters.empty() ) {
    4242                os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    4343                printAll( parameters, os, indent+2 );
    44     } // if
     44        } // if
    4545}
    4646
     
    6060
    6161void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    62     assert( baseStruct );
    63     doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
     62        assert( baseStruct );
     63        doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
    6464}
    6565
     
    6767
    6868void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    69     assert( baseUnion );
    70     doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
     69        assert( baseUnion );
     70        doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
    7171}
    7272
     
    7676
    7777ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) {
    78     cloneAll( other.members, members );
     78        cloneAll( other.members, members );
    7979}
    8080
    8181ContextInstType::~ContextInstType() {
    82     deleteAll( members );
     82        deleteAll( members );
    8383}
    8484
    8585TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) {
    86     set_baseType( baseType );
     86        set_baseType( baseType );
    8787}
    8888
     
    9191
    9292void TypeInstType::set_baseType( TypeDecl *newValue ) {
    93     baseType = newValue;
    94     isFtype = newValue->get_kind() == TypeDecl::Ftype;
     93        baseType = newValue;
     94        isFtype = newValue->get_kind() == TypeDecl::Ftype;
    9595}
    9696
     
    9898
    9999void TypeInstType::print( std::ostream &os, int indent ) const {
    100     using std::endl;
    101    
    102     Type::print( os, indent );
    103     os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) ";
    104     if ( ! parameters.empty() ) {
     100        using std::endl;
     101       
     102        Type::print( os, indent );
     103        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) ";
     104        if ( ! parameters.empty() ) {
    105105                os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    106106                printAll( parameters, os, indent+2 );
    107     } // if
     107        } // if
    108108}
    109109
  • translator/SynTree/Statement.cc

    r01aeade ra08ba92  
    5858}
    5959
    60 void BranchStmt::print( std::ostream &os, int indent ){
     60void BranchStmt::print( std::ostream &os, int indent ) {
    6161        os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ;
    6262}
     
    7979IfStmt::~IfStmt() {}
    8080
    81 void IfStmt::print( std::ostream &os, int indent ){
     81void IfStmt::print( std::ostream &os, int indent ) {
    8282        os << "\r" << string( indent, ' ') << "If on condition: " << endl ;
    8383        condition->print( os, indent + 4 );
     
    175175}
    176176
    177 WhileStmt::~WhileStmt(){
     177WhileStmt::~WhileStmt() {
    178178        delete body;
    179179}
    180180
    181 void WhileStmt::print( std::ostream &os, int indent ){
     181void WhileStmt::print( std::ostream &os, int indent ) {
    182182        os << "\r" << string( indent, ' ') << "While on condition: " << endl ;
    183183        condition->print( os, indent + 4 );
     
    199199}
    200200
    201 void ForStmt::print( std::ostream &os, int indent ){
     201void ForStmt::print( std::ostream &os, int indent ) {
    202202        os << "\r" << string( indent, ' ') << "For Statement" << endl ;
    203203
     
    231231}
    232232
    233 TryStmt::~TryStmt(){
     233TryStmt::~TryStmt() {
    234234        delete block;
    235235}
     
    257257}
    258258
    259 CatchStmt::~CatchStmt(){
     259CatchStmt::~CatchStmt() {
    260260        delete decl;
    261261        delete body;
  • translator/SynTree/Type.cc

    r01aeade ra08ba92  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 11:00:29 2015
    13 // Update Count     : 1
     12// Last Modified On : Tue May 19 16:52:27 2015
     13// Update Count     : 2
    1414//
    1515
     
    2121
    2222const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = {
    23     "_Bool",
    24     "char",
    25     "char",
    26     "unsigned char",
    27     "short",
    28     "short unsigned",
    29     "int",
    30     "unsigned int",
    31     "long int",
    32     "long unsigned int",
    33     "long long int",
    34     "long long unsigned int",
    35     "float",
    36     "double",
    37     "long double",
    38     "float _Complex",
    39     "double _Complex",
    40     "long double _Complex",
    41     "float _Imaginary",
    42     "double _Imaginary",
    43     "long double _Imaginary",
     23        "_Bool",
     24        "char",
     25        "char",
     26        "unsigned char",
     27        "short",
     28        "short unsigned",
     29        "int",
     30        "unsigned int",
     31        "long int",
     32        "long unsigned int",
     33        "long long int",
     34        "long long unsigned int",
     35        "float",
     36        "double",
     37        "long double",
     38        "float _Complex",
     39        "double _Complex",
     40        "long double _Complex",
     41        "float _Imaginary",
     42        "double _Imaginary",
     43        "long double _Imaginary",
    4444};
    4545
     
    4747
    4848Type::Type( const Type &other ) : tq( other.tq ) {
    49     cloneAll( other.forall, forall );
     49        cloneAll( other.forall, forall );
    5050}
    5151
    5252Type::~Type() {
    53     deleteAll( forall );
     53        deleteAll( forall );
    5454}
    5555
    5656void Type::print( std::ostream &os, int indent ) const {
    57     if ( ! forall.empty() ) {
     57        if ( ! forall.empty() ) {
    5858                os << "forall" << std::endl;
    5959                printAll( forall, os, indent + 4 );
    6060                os << std::string( indent+2, ' ' );
    61     } // if
    62     if ( tq.isConst ) {
     61        } // if
     62        if ( tq.isConst ) {
    6363                os << "const ";
    64     } // if
    65     if ( tq.isVolatile ) {
     64        } // if
     65        if ( tq.isVolatile ) {
    6666                os << "volatile ";
    67     } // if
    68     if ( tq.isRestrict ) {
     67        } // if
     68        if ( tq.isRestrict ) {
    6969                os << "restrict ";
    70     } // if
    71     if ( tq.isLvalue ) {
     70        } // if
     71        if ( tq.isLvalue ) {
    7272                os << "lvalue ";
    73     } // if
    74     if ( tq.isAtomic ) {
     73        } // if
     74        if ( tq.isAtomic ) {
    7575                os << "_Atomic ";
    76     } // if
     76        } // if
    7777}
    7878
  • translator/SynTree/Visitor.cc

    r01aeade ra08ba92  
    111111}
    112112
    113 void Visitor::visit( FallthruStmt *fallthruStmt ){}
     113void Visitor::visit( FallthruStmt *fallthruStmt ) {}
    114114
    115115void Visitor::visit( CaseStmt *caseStmt ) {
  • translator/Tests/Syntax/Expression.c

    r01aeade ra08ba92  
    55    // order of evaluation (GCC is different)
    66/*
    7     i = sizeof( (int){3} );
    8     i = sizeof (int){3};
     7    i = sizeof( (int) {3} );
     8    i = sizeof (int) {3};
    99*/
    1010    // operators
  • translator/Tests/Syntax/Forall.c

    r01aeade ra08ba92  
    1616
    1717type T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
    18      T2(type P1, type P2 ) | (type Q, type W){ const Q 0; W ?+?(W, W); Q ?++(W); [Q] ?+=?(W,W); }(T1,T2(T1,f)),
     18     T2(type P1, type P2 ) | (type Q, type W) { const Q 0; W ?+?(W, W); Q ?++(W); [Q] ?+=?(W,W); }(T1,T2(T1,f)),
    1919     T3 | sumable(T3);
    2020
  • translator/Tests/Syntax/Initialization.c

    r01aeade ra08ba92  
    3232struct quintet { int v, w, x, y, z;};
    3333
    34 int foo(){
     34int foo() {
    3535  return 4;
    3636}
    3737
    38 int main(){
     38int main() {
    3939  foo();
    4040  int i;
  • translator/Tests/gcc/900516-1.c

    r01aeade ra08ba92  
    11/* added 'int' to argument */
    2 f(int c){ return!(c?2.0:1.0); }
     2f(int c) { return!(c?2.0:1.0); }
  • translator/Tests/gcc/920301-1.c

    r01aeade ra08ba92  
    1 f(){static void*t[];/*={&&x};*/ x:y:;}
    2 g(){static unsigned p[5];}
     1f() {static void*t[];/*={&&x};*/ x:y:;}
     2g() {static unsigned p[5];}
  • translator/Tests/gcc/920409-1.c

    r01aeade ra08ba92  
    1 x(){int y;y>0.0?y:y-1;}
     1x() {int y;y>0.0?y:y-1;}
  • translator/Tests/gcc/920409-2.c

    r01aeade ra08ba92  
    1 double x(){int x1,x2;double v;
     1double x() {int x1,x2;double v;
    22if (((long)(x1-x2))<1)return -1.0;v=t(v);v=y(1,v>0.0?(int)v:((int)v-1));}
  • translator/Tests/gcc/920501-1.c

    r01aeade ra08ba92  
    1 a(){int**b[]={&&c};c:;}
     1a() {int**b[]={&&c};c:;}
  • translator/Tests/gcc/920501-11.c

    r01aeade ra08ba92  
    1 typedef struct{int s;}S;foo(){int i=(int)&(S){(void*)((int)&(S){1})};}
     1typedef struct{int s;}S;foo() {int i=(int)&(S) {(void*)((int)&(S) {1})};}
  • translator/Tests/gcc/920501-19.c

    r01aeade ra08ba92  
    1 long long x=0;y(){x=0;}
     1long long x=0;y() {x=0;}
  • translator/Tuples/AssignExpand.cc

    r01aeade ra08ba92  
    3838
    3939                CompoundStmt *newSt = 0;
    40                 if (! extra.empty() ) {
     40                if ( ! extra.empty() ) {
    4141                        if ( ! newSt )
    4242                                newSt= new CompoundStmt(std::list<Label>());
     
    6969                   if ( tupleExpr->get_type() == SolvedTupleExpr::MASS ) {
    7070                   // extract lhs of assignments, assert that rhs is the same, create temporaries
    71                    assert (! exprs.empty());
     71                   assert ( ! exprs.empty());
    7272                   ApplicationExpr *ap1 = dynamic_cast< ApplicationExpr * >( exprs.front() );
    7373                   std::list<Expression *> &args = ap1->get_args();
  • translator/Tuples/MultRet.h

    r01aeade ra08ba92  
    3737                CompoundStmt *getVars() const { return newVars; }
    3838
    39                 bool hasResults() const { return (! results.empty()); }
     39                bool hasResults() const { return ( ! results.empty()); }
    4040                std::list<Expression *> &get_results() { return results; }
    4141          private:
  • translator/Tuples/TupleAssignment.cc

    r01aeade ra08ba92  
    6464
    6565                std::list< Expression * > new_assigns;
    66                 if (! matcher->match(new_assigns) )
     66                if ( ! matcher->match(new_assigns) )
    6767                        return false;
    6868
     
    171171                                                if ( best.size() == 1 ) {
    172172                                                        std::list<Expression *> solved_assigns;
    173                                                         for ( ResolvExpr::AltList::iterator i = best.front().begin(); i != best.front().end(); ++i ){
     173                                                        for ( ResolvExpr::AltList::iterator i = best.front().begin(); i != best.front().end(); ++i ) {
    174174                                                                solved_assigns.push_back( i->expr );
    175175                                                        }
     
    178178                                                }
    179179                                        } else {
    180                                                 assert(! optMass.empty() );
     180                                                assert( ! optMass.empty() );
    181181                                                ResolvExpr::AltList winners;
    182182                                                for ( std::vector< ResolvExpr::AltList >::iterator i = optMass.begin(); i != optMass.end(); ++i )
     
    377377
    378378        template< class InputIterator, class OutputIterator >
    379         void TupleAssignSpotter::Options::lift_intersection( InputIterator begin, InputIterator end, OutputIterator out ){
     379        void TupleAssignSpotter::Options::lift_intersection( InputIterator begin, InputIterator end, OutputIterator out ) {
    380380                if ( begin == end ) return;
    381381                InputIterator test = begin;
Note: See TracChangeset for help on using the changeset viewer.