Changeset a08ba92
- Timestamp:
- May 19, 2015, 4:58:14 PM (10 years ago)
- 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
- Location:
- translator
- Files:
-
- 75 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/CodeGen/GenType.cc
r01aeade ra08ba92 122 122 } 123 123 124 void GenType::visit( ArrayType *arrayType ) {124 void GenType::visit( ArrayType *arrayType ) { 125 125 genArray( arrayType->get_qualifiers(), arrayType->get_base(), arrayType->get_dimension(), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 126 126 } … … 153 153 cg.genCommaList( pars.begin(), pars.end() ); 154 154 155 if ( funcType->get_isVarArgs() ) {155 if ( funcType->get_isVarArgs() ) { 156 156 os << ", ..."; 157 157 } // if -
translator/Common/utility.h
r01aeade ra08ba92 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:27:38201513 // Update Count : 212 // Last Modified On : Tue May 19 15:34:57 2015 13 // Update Count : 3 14 14 // 15 15 … … 116 116 Ts ret; 117 117 118 switch ( l.size() ) {118 switch ( l.size() ) { 119 119 case 0: 120 120 return ret; … … 156 156 157 157 //if ( next != org.end() ) { 158 159 160 158 org.erase( pos ); 159 org.splice( next, with ); 160 //} 161 161 162 162 return; … … 175 175 template< typename T > 176 176 struct is_null_pointer { 177 bool operator()( const T *ptr ) { return ( ptr == 0 ); }177 bool operator()( const T *ptr ) { return ( ptr == 0 ); } 178 178 }; 179 179 -
translator/ControlStruct/CaseRangeMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // CaseRangeMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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 15 16 #include <list> 16 17 #include <cassert> … … 27 28 28 29 namespace 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() ) { 125 123 case BasicType::Char: 126 124 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; 138 183 } 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 ); 140 193 return; 141 }142 break;143 default:144 // error: incompatible constants145 break;146 194 } 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 } 195 196 } // namespace ControlStruct 197 196 198 // Local Variables: // 197 199 // tab-width: 4 // -
translator/ControlStruct/CaseRangeMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // CaseRangeMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:22:51 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef CASERNG_MUTATOR_H 16 17 #define CASERNG_MUTATOR_H … … 21 22 22 23 namespace ControlStruct { 23 24 25 CaseRangeMutator() {}24 class CaseRangeMutator : public Mutator { 25 public: 26 CaseRangeMutator() {} 26 27 27 virtual Statement *mutate( ChooseStmt * );28 virtual Statement *mutate( SwitchStmt * );29 virtual Statement *mutate( FallthruStmt * );30 virtual Statement *mutate( CaseStmt * );31 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 ); 33 34 34 Expression *currentCondition; 35 std::list< Expression * > newCaseLabels; 36 }; 37 35 Expression *currentCondition; 36 std::list< Expression * > newCaseLabels; 37 }; 38 38 } // namespace ControlStruct 39 39 40 40 #endif // CASERNG_MUTATOR_H 41 41 42 /*43 Local Variables:44 mode: c++45 End:46 */47 42 // Local Variables: // 48 43 // tab-width: 4 // -
translator/ControlStruct/ChooseMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // ChooseMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:39 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <list> 16 17 … … 19 20 20 21 namespace 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 } 28 29 29 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 } 36 37 37 38 delete fallthruStmt;39 return new NullStmt();40 38 Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) { 39 delete fallthruStmt; 40 return new NullStmt(); 41 } 41 42 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(); 44 45 45 if ( insideChoose ) {46 47 48 ( posBrk->get_type() == BranchStmt::Break )) // last statement in the list is a (superfluous) 'break'49 || dynamic_cast< FallthruStmt * > ( stmts.back() ) )50 ;51 52 stmts.push_back( new BranchStmt( std::list< Label >(), "", BranchStmt::Break ) );53 54 } // if46 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 55 56 56 mutateAll ( stmts, *this );57 return caseStmt;58 57 mutateAll ( stmts, *this ); 58 return caseStmt; 59 } 59 60 } // namespace ControlStruct 61 60 62 // Local Variables: // 61 63 // tab-width: 4 // -
translator/ControlStruct/ChooseMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // ChooseMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:33:11 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef CHOOSE_MUTATOR_H 16 17 #define CHOOSE_MUTATOR_H … … 21 22 22 23 namespace ControlStruct { 24 class ChooseMutator : public Mutator { 25 public: 26 ChooseMutator() : insideChoose( false ) {} 23 27 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 }; 35 35 } // namespace ControlStruct 36 36 37 37 #endif // CHOOSE_MUTATOR_H 38 38 39 /*40 Local Variables:41 mode: c++42 End:43 */44 39 // Local Variables: // 45 40 // tab-width: 4 // -
translator/ControlStruct/ForExprMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // ForExprMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:47 2015 13 // Update Count : 2 14 14 // 15 15 16 #include "SynTree/Mutator.h" 16 17 #include "SynTree/Statement.h" … … 18 19 19 20 namespace ControlStruct { 20 21 // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)22 23 if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {24 25 26 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(); 27 28 28 29 30 29 stmts.push_back( decl ); 30 forStmt->set_initialization( 0 ); 31 stmts.push_back( forStmt ); 31 32 32 33 } // if33 return block; 34 } // if 34 35 35 return forStmt;36 36 return forStmt; 37 } 37 38 } // namespace ControlStruct 39 38 40 // Local Variables: // 39 41 // tab-width: 4 // -
translator/ControlStruct/ForExprMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // ForExprMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:25:19 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef FOR_MUTATOR_H 16 17 #define FOR_MUTATOR_H 17 18 18 19 #include "SynTree/Mutator.h" 19 20 20 #include "utility.h" 21 21 22 22 namespace ControlStruct { 23 24 25 virtual Statement *mutate( ForStmt * );26 23 class ForExprMutator : public Mutator { 24 public: 25 virtual Statement *mutate( ForStmt * ); 26 }; 27 27 } // namespace ControlStruct 28 28 29 29 #endif // CHOOSE_MUTATOR_H 30 30 31 /*32 Local Variables:33 mode: c++34 End:35 */36 31 // Local Variables: // 37 32 // tab-width: 4 // -
translator/ControlStruct/LabelFixer.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // LabelFixer.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:25:59 2015 13 // Update Count : 1 14 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 23 24 24 25 namespace 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 ); 108 29 } 109 30 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 } 116 35 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 } 124 40 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 ); 127 44 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 } 134 48 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(); 139 51 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 } 142 143 } // namespace ControlStruct 144 143 145 // Local Variables: // 144 146 // tab-width: 4 // -
translator/ControlStruct/LabelFixer.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // LabelFixer.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:55 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef LABEL_FIXER_H 16 17 #define LABEL_FIXER_H 17 18 18 19 #include "utility.h" 19 20 20 #include "SynTree/SynTree.h" 21 21 #include "SynTree/Visitor.h" 22 23 22 #include "LabelGenerator.h" 24 23 … … 26 25 27 26 namespace ControlStruct { 28 29 typedef Visitor Parent;30 31 LabelFixer( LabelGenerator *gen = 0 );27 class LabelFixer : public Visitor { 28 typedef Visitor Parent; 29 public: 30 LabelFixer( LabelGenerator *gen = 0 ); 32 31 33 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );32 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); 34 33 35 // Declarations36 virtual void visit( FunctionDecl *functionDecl );34 // Declarations 35 virtual void visit( FunctionDecl *functionDecl ); 37 36 38 // Statements39 void visit( Statement *stmt );37 // Statements 38 void visit( Statement *stmt ); 40 39 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 ); 56 55 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 ); 59 58 60 61 class Entry {62 public:63 64 65 66 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(); 67 66 68 69 70 67 Label get_label() const { return label; } 68 Statement *get_definition() const { return definition; } 69 std::list< Statement *> &get_uses() { return usage; } 71 70 72 73 74 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; } 75 74 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; 82 85 }; 83 84 std::map < Label, Entry *> labelTable;85 LabelGenerator *generator;86 };87 86 } // namespace ControlStruct 88 87 89 88 #endif // LABEL_FIXER_H 90 89 91 /*92 Local Variables:93 mode: c++94 End:95 */96 90 // Local Variables: // 97 91 // tab-width: 4 // -
translator/ControlStruct/LabelGenerator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // LabelGenerator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:04 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <iostream> 16 17 #include <strstream> … … 19 20 20 21 namespace ControlStruct { 21 22 LabelGenerator *LabelGenerator::labelGenerator = 0; 22 23 23 24 if ( LabelGenerator::labelGenerator == 0 )25 24 LabelGenerator *LabelGenerator::getGenerator() { 25 if ( LabelGenerator::labelGenerator == 0 ) 26 LabelGenerator::labelGenerator = new LabelGenerator(); 26 27 27 return labelGenerator;28 28 return labelGenerator; 29 } 29 30 30 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 } 37 38 } // namespace ControlStruct 39 38 40 // Local Variables: // 39 41 // tab-width: 4 // -
translator/ControlStruct/LabelGenerator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // LabelGenerator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:33:20 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef LABEL_GENERATOR_H 16 17 #define LABEL_GENERATOR_H … … 19 20 20 21 namespace ControlStruct { 21 22 23 static LabelGenerator *getGenerator();24 Label newLabel();25 void reset() { current = 0; }26 void rewind() { current--; }27 28 LabelGenerator(): current(0) {}29 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 }; 33 34 } // namespace ControlStruct 34 35 35 36 #endif // LABEL_GENERATOR_H 36 37 37 /*38 Local Variables:39 mode: c++40 End:41 */42 38 // Local Variables: // 43 39 // tab-width: 4 // -
translator/ControlStruct/LabelTypeChecker.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // LabelTypeChecker.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:15 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 23 24 #include "LabelTypeChecker.h" 24 25 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 } 25 39 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 } 39 45 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 ); 45 48 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 } 48 53 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; 53 58 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() ); 58 68 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"); 68 77 69 PointerType *ptr;70 if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 )71 if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 )72 78 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 77 81 78 return;79 }80 } // namespace ControlStruct81 82 // Local Variables: // 82 83 // tab-width: 4 // -
translator/ControlStruct/LabelTypeChecker.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // LabelTypeChecker.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:33:47 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef LABEL_TYPE_H 16 17 #define LABEL_TYPE_H … … 23 24 24 25 namespace ControlStruct { 25 26 27 //LabelTypeChecker() {26 class LabelTypeChecker : public Visitor { 27 public: 28 //LabelTypeChecker() { 28 29 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 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 }; 36 37 } // namespace ControlStruct 37 38 38 39 #endif // LABEL_TYPE_H 39 40 /*41 Local Variables:42 mode: c++43 End:44 */45 46 47 40 48 41 // Local Variables: // -
translator/ControlStruct/MLEMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // MLEMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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 15 16 #include <cassert> 16 17 #include <algorithm> … … 19 20 #include "SynTree/Statement.h" 20 21 21 22 22 namespace ControlStruct { 23 24 delete targetTable;25 targetTable = 0;26 27 28 29 bool labeledBlock = false;30 if ( !((cmpndStmt->get_labels()).empty()) ) {31 32 33 }34 35 std::list< Statement * > &kids = cmpndStmt->get_kids();36 for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) {37 38 39 40 std::list< Statement * >::iterator next = k; next++;41 if ( next == kids.end() ) {42 43 44 } else45 46 47 set_breakLabel("");48 49 } // for50 51 if ( labeledBlock ) {52 53 54 set_breakLabel( enclosingBlocks.back().get_breakExit() );55 56 } // if57 58 //mutateAll( cmpndStmt->get_kids(), *this );59 return cmpndStmt;60 61 62 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 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 87 if ( branchStmt->get_type() == BranchStmt::Goto )88 89 90 // test if continue target is a loop91 if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() )92 93 94 if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) )95 96 97 if ( branchStmt->get_target() == "" ) return branchStmt;98 99 if ( targetTable->find( branchStmt->get_target() ) == targetTable->end() )100 101 102 std::list< Entry >::iterator check;103 if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() )104 105 106 // neither in loop nor in block, checking if in switch/choose107 if ( (check = std::find( enclosingSwitches.begin(), enclosingSwitches.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingSwitches.end() )108 109 110 if ( enclosingLoops.back() == (*check) )111 112 113 Label newLabel;114 switch ( branchStmt->get_type() ) {115 case BranchStmt::Break:116 117 newLabel = check->get_breakExit();118 119 newLabel = generator->newLabel();120 check->set_breakExit( newLabel );121 122 123 case BranchStmt::Continue:124 125 newLabel = check->get_contExit();126 127 newLabel = generator->newLabel();128 check->set_contExit( newLabel );129 130 131 default:132 133 } // switch134 135 return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto );136 137 138 139 140 Label brkLabel = generator->newLabel();141 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) );142 mutateAll( switchStmt->get_branches(), *this ); {143 144 145 146 }147 assert ( enclosingSwitches.back() == switchStmt );148 enclosingSwitches.pop_back();149 return switchStmt;150 151 152 153 Label brkLabel = generator->newLabel();154 enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) );155 mutateAll( switchStmt->get_branches(), *this ); {156 157 158 159 }160 assert ( enclosingSwitches.back() == switchStmt );161 enclosingSwitches.pop_back();162 return switchStmt;163 164 165 166 CompoundStmt *newBody;167 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {168 169 170 } // if171 172 Label endLabel = e.get_contExit();173 174 if ( e.get_breakExit() != "" ) {175 176 177 178 newBody->get_kids().push_back( new BranchStmt( std::list< Label >(), endLabel, BranchStmt::Goto ) );179 180 181 182 183 } // if184 185 if ( e.get_breakExit() != "" || e.get_contExit() != "" ){186 187 newBody->get_kids().back()->get_labels().push_back( endLabel );188 189 std::list < Label > ls; ls.push_back( endLabel );190 newBody->get_kids().push_back( new NullStmt( ls ) );191 192 } // if193 194 return newBody;195 196 197 198 199 assert ( contExit == "" || contExit == l );200 contExit = l;201 202 203 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 } 207 207 } // namespace ControlStruct 208 208 209 // Local Variables: // 209 210 // tab-width: 4 // -
translator/ControlStruct/MLEMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // MLEMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:39 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef MLE_MUTATOR_H 16 17 #define MLE_MUTATOR_H … … 26 27 27 28 namespace ControlStruct { 28 29 class Entry;30 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(); 33 34 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 ); 38 39 39 Statement *mutate( SwitchStmt *switchStmt );40 Statement *mutate( ChooseStmt *switchStmt );40 Statement *mutate( SwitchStmt *switchStmt ); 41 Statement *mutate( ChooseStmt *switchStmt ); 41 42 42 Statement *mutateLoop( Statement *bodyLoop, Entry &e );43 Statement *mutateLoop( Statement *bodyLoop, Entry &e ); 43 44 44 Label &get_breakLabel() { return breakLabel; }45 void set_breakLabel( Label newValue ) { breakLabel = newValue; }46 47 class Entry {48 public:49 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 ) {} 51 52 52 53 53 bool operator==( const Statement *stmt ) { return ( loop == stmt ); } 54 bool operator!=( const Statement *stmt ) { return ( loop != stmt ); } 54 55 55 56 bool operator==( const Entry &other ) { return ( loop == other.get_loop() ); } 56 57 57 58 Statement *get_loop() const { return loop; } 58 59 59 60 60 Label get_contExit() const { return contExit; } 61 void set_contExit( Label ); 61 62 62 63 63 Label get_breakExit() const { return breakExit; } 64 void set_breakExit( Label ); 64 65 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; 70 77 }; 71 72 std::map< Label, Statement * > *targetTable;73 std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches;74 Label breakLabel;75 LabelGenerator *generator;76 };77 78 78 } // namespace ControlStruct 79 79 80 #endif 80 #endif // MLE_MUTATOR_H 81 81 82 /*83 Local Variables:84 mode: c++85 End:86 */87 82 // Local Variables: // 88 83 // tab-width: 4 // -
translator/ControlStruct/Mutate.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // Mutate.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:52 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <algorithm> 16 17 #include <iostream> … … 34 35 35 36 namespace ControlStruct { 36 37 // ForExprMutator formut;38 LabelFixer lfix;39 ChooseMutator chmut;40 CaseRangeMutator ranges; // has to run after ChooseMutator41 //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; 43 44 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 } 51 52 } // namespace CodeGen 53 52 54 // Local Variables: // 53 55 // tab-width: 4 // -
translator/ControlStruct/Mutate.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // Mutate.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:20 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef CTRLS_MUTATE_H 16 17 #define CTRLS_MUTATE_H … … 22 23 23 24 namespace ControlStruct { 24 25 void mutate( std::list< Declaration* > translationUnit ); 25 26 } // namespace ControlStruct 26 27 27 28 #endif // CTRLS_MUTATE_H 28 29 29 /*30 Local Variables:31 mode: c++32 End:33 */34 30 // Local Variables: // 35 31 // tab-width: 4 // -
translator/Designators/Processor.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // Processor.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:23:10 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <vector> 16 17 #include <algorithm> … … 20 21 21 22 namespace 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 33 35 } 34 }35 36 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; 44 47 } 45 return true;46 }47 48 48 49 50 while ( begin != end )51 52 *out++ = declarations [ table[ *begin++ ] ];53 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 } 57 58 58 59 60 // fill call with defaults, if need be61 for (Matcher::iterator o = begin(); o != end(); o++ )62 63 return false;64 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 } 68 69 69 70 // Distribute `designation' over alternatives contained in `finder'71 if ( ! designation) return false;72 else73 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 } 77 78 78 79 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; 82 83 83 if ( NameExpr *ndes = dynamic_cast<NameExpr *>(designator) )84 85 else if ( TupleExpr *tdes = dynamic_cast<TupleExpr *>(designator) ) {86 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; 87 88 // ObjectDecl *decl = extractTupleV(matcher, tdes); // xxx 88 89 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++ ) { 91 92 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; 98 101 } 99 return true;100 }101 102 102 103 if ( NameExpr *name = dynamic_cast< NameExpr *>(expr) )104 105 else /* if () */106 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 } 108 109 109 110 return 0;111 110 DeclarationWithType *gensym( DeclarationWithType *, std::string prefix ) { 111 return 0; 112 } 112 113 113 114 // extract a subtuple of the function `fun' argument list, corresponding to the tuple of names requested by115 // `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; 124 125 125 return 0;//new ObjectDecl()126 126 return 0;//new ObjectDecl() 127 } 127 128 128 129 using namespace ResolvExpr;129 void check_alternative( FunctionType *fun, ResolvExpr::AltList &args ) { 130 using namespace ResolvExpr; 130 131 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; 140 147 } 141 //AltList newArgs;142 args.clear();143 matcher.get_reorderedCall( back_inserter(args) );144 145 return;146 }147 148 #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; 157 160 } 158 return;159 }160 161 #endif // 0 161 162 } // namespaces Designators 163 162 164 // Local Variables: // 163 165 // tab-width: 4 // -
translator/Designators/Processor.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // Processor.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:24:34 2015 13 // Update Count : 3 14 14 // 15 15 16 #include "SynTree/Declaration.h" 16 17 #include "SynTree/Expression.h" … … 24 25 25 26 namespace Designators { 26 27 27 class Matcher; 28 class GenSym; 28 29 29 30 31 32 33 34 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 * ); 35 36 36 37 public:38 39 37 class GenSym { 38 public: 39 GenSym( std::string prefix = "" ) : gensym_count(0) {} 40 GenSym( GenSym &other ) { gensym_count = other.gensym_count; } 40 41 41 42 // std::string get_symbol() { } 42 private:43 44 45 43 private: 44 std::string prefix; 45 int gensym_count; 46 }; 46 47 47 48 49 public:50 48 // template< typename Key > 49 class Matcher { 50 public: 51 typedef std::vector< std::string >::iterator iterator; 51 52 52 53 53 Matcher( const std::list< DeclarationWithType * > & ); 54 ~Matcher() {} 54 55 55 56 57 58 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; } 59 60 60 61 61 iterator begin() { return order.begin(); } 62 iterator end() { return order.end(); } 62 63 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 & ); 72 72 } // namespace Designators 73 73 74 /*75 Local Variables:76 mode: c++77 End:78 */79 74 // Local Variables: // 80 75 // tab-width: 4 // -
translator/GenPoly/ScrubTyVars.cc
r01aeade ra08ba92 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:47:31201513 // Update Count : 112 // Last Modified On : Tue May 19 16:42:42 2015 13 // Update Count : 2 14 14 // 15 15 … … 22 22 23 23 namespace GenPoly { 24 24 Type * ScrubTyVars::mutate( TypeInstType *typeInst ) { 25 25 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); 26 26 if ( doAll || tyVar != tyVars.end() ) { … … 39 39 } // if 40 40 return typeInst; 41 41 } 42 42 43 43 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { 44 44 // sizeof( T ) => T parameter, which is the size of T 45 45 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) { … … 49 49 return Mutator::mutate( szeof ); 50 50 } // if 51 51 } 52 52 53 53 Type * ScrubTyVars::mutate( PointerType *pointer ) { 54 54 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) { 55 55 if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) { … … 62 62 } // if 63 63 return Mutator::mutate( pointer ); 64 64 } 65 65 } // namespace GenPoly 66 66 -
translator/InitTweak/Association.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // Association.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:25:09 2015 13 // Update Count : 1 14 14 // 15 15 16 #include "Association.h" 16 17 … … 22 23 const int RangeAssociation::RangeAssociation::UNDEF = -1; 23 24 RangeAssociation::~RangeAssociation() {} 25 24 26 // Local Variables: // 25 27 // tab-width: 4 // -
translator/InitTweak/Association.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // Association.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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_ 17 18 18 19 #include <map> … … 34 35 // ** exceptions 35 36 class AssocException : public std::exception { 36 public:37 38 39 40 41 42 43 private:44 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; 45 46 }; 46 47 47 48 // ** visitors 48 49 class AssociationVisitor { 49 public:50 51 52 53 54 55 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; 56 57 }; 57 58 58 59 // ** containers 59 60 class Association { 60 public:61 62 63 64 65 66 67 68 69 70 71 72 73 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; 74 75 }; 75 76 76 77 class SingleName : public Association { 77 public:78 79 80 81 82 83 84 85 86 87 88 89 90 91 virtual long int add_single( std::string str, Expression *newExpr) {92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 private:108 109 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; 110 111 }; 111 112 112 113 class PointAssociation : public Association { 113 public:114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 } 139 140 141 142 143 144 145 146 147 148 throw AssocException("No such member");149 150 return add_single( j->second.first, expr );151 } 152 153 154 155 156 157 158 159 160 161 162 } 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 virtual AssociationIterator *get_iterator() {194 195 196 }197 198 199 200 201 202 203 204 205 206 i->second.second->display( os );207 208 std::cerr << "No recursive association" << std::endl;209 210 211 } 212 213 214 215 216 private:217 218 219 220 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; 221 222 }; 222 223 223 224 class RangeAssociation : public Association { 224 public:225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 virtual AssociationIterator *get_iterator() {244 245 246 }247 248 249 250 251 252 253 254 255 256 private:257 258 259 260 for ( diet_tree<int>::iterator i = tree.begin(); i != tree.end(); i++ )261 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 */ 265 266 }; 266 267 267 268 // ** builders 268 269 class AssociationBuilder { 269 public:270 271 272 273 274 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; 275 276 }; 276 277 277 278 class 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 292 288 // Local Variables: // 293 289 // tab-width: 4 // -
translator/InitTweak/BasicInit.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // BasicInit.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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 15 16 #include <list> 16 17 #include <cassert> … … 32 33 33 34 namespace 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; 205 123 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 } 276 262 } // namespace InitTweak 277 263 -
translator/InitTweak/BasicInit.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // BasicInit.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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 15 16 #ifndef _BASINIT_H_ 16 17 #define _BASINIT_H_ … … 28 29 29 30 namespace 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 }; 222 214 } // namespace InitTweak 223 215 224 #endif // #ifndef _BASINIT_H_ 225 226 /* 227 Local Variables: 228 mode: c++ 229 End: 230 */ 216 #endif // _BASINIT_H_ 217 231 218 // Local Variables: // 232 219 // tab-width: 4 // -
translator/InitTweak/DeclarationHoister.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // DeclarationHoister.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:33:20 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 27 28 #include "DeclarationHoister.h" 28 29 30 namespace 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; 29 37 30 namespace InitTweak { 38 while ( result != kids.end() ) { 39 result = std::find_if (result, kids.end(), cast_ptr< Statement, DeclStmt > ); 31 40 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 38 46 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 41 51 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 } 55 54 } // namespace InitTweak 56 57 58 59 60 61 62 63 55 64 56 // Local Variables: // -
translator/InitTweak/DeclarationHoister.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // DeclarationHoister.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:33:48 2015 13 // Update Count : 2 14 14 // 15 15 16 #include "SynTree/Visitor.h" 16 17 #include "SymTab/Indexer.h" 17 18 18 19 namespace InitTweak { 20 bool isDeclStmtP(Statement *stmt); 19 21 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 }; 27 26 } // namespace InitTweak 28 27 29 /*30 Local Variables:31 mode: c++32 End:33 */34 28 // Local Variables: // 35 29 // tab-width: 4 // -
translator/InitTweak/InitExpander.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // InitExpander.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:34:12 2015 13 // Update Count : 1 14 14 // 15 15 16 #include <list> 16 17 #include <stack> 17 18 #include <cassert> 18 19 #include <algorithm> 19 20 20 21 21 #include "utility.h" … … 24 24 25 25 namespace InitTweak { 26 InitExpander::InitExpander() {} 26 27 27 InitExpander::InitExpander() {}28 InitExpander::~InitExpander() {} 28 29 29 InitExpander::~InitExpander() {} 30 ObjectDecl *InitExpander::mutate( ObjectDecl *objectDecl ) { 31 index.visit( objectDecl ); 30 32 31 ObjectDecl *InitExpander::mutate( ObjectDecl *objectDecl ) { 32 index.visit( objectDecl ); 33 if ( objectDecl->get_init() == 0 ) return objectDecl; 33 34 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 ); 35 43 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 } 48 46 } // namespace InitTweak 49 47 -
translator/InitTweak/InitExpander.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // InitExpander.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:35:33 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _INIT_EXPANDER_H_ 16 17 #define _INIT_EXPANDER_H_ … … 27 28 28 29 namespace InitTweak { 30 class InitExpander : public Mutator { 31 typedef Mutator Parent; 32 public: 33 InitExpander(); 34 ~InitExpander(); 29 35 30 class InitExpander : public Mutator 31 { 32 typedef Mutator Parent; 36 virtual ObjectDecl *mutate( ObjectDecl * ); 33 37 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 ) ); 37 43 38 virtual ObjectDecl *mutate( ObjectDecl * ); 44 index.visit( functionDecl ); 45 return functionDecl; 46 } 39 47 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; } 46 58 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 71 66 } // namespace InitTweak 72 67 68 #endif // _INIT_EXPANDER_H_ 73 69 74 #endif // #ifndef _INIT_EXPANDER_H_75 76 /*77 Local Variables:78 mode: c++79 End:80 */81 70 // Local Variables: // 82 71 // tab-width: 4 // -
translator/InitTweak/InitModel.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // InitModel.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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 15 16 #include "SynTree/Constant.h" 16 17 #include "InitModel.h" … … 21 22 22 23 namespace 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 } 223 219 } // namespace InitTweak 220 224 221 // Local Variables: // 225 222 // tab-width: 4 // -
translator/InitTweak/InitModel.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // InitModel.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:37:52 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _INITTWEAK_MODEL_H_ 16 17 #define _INITTWEAK_MODEL_H_ … … 26 27 27 28 namespace InitTweak { 28 29 30 InitModelBuilder( Declaration * );31 ~InitModelBuilder();29 class InitModelBuilder : public AssociationBuilder, public Visitor { 30 public: 31 InitModelBuilder( Declaration * ); 32 ~InitModelBuilder(); 32 33 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; } 36 37 37 void init();38 static int interpretDimension( Expression *exp ) {39 40 41 return folder.get_constant();42 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 } 46 47 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 *); 77 60 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; 80 86 }; 81 87 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; } 86 94 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 }; 93 105 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; } 104 112 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 }; 120 120 } // namespace InitTweak 121 121 122 122 #endif // _INITTWEAK_MODEL_H_ 123 123 124 /*125 Local Variables:126 mode: c++127 End:128 */129 124 // Local Variables: // 130 125 // tab-width: 4 // -
translator/InitTweak/Mutate.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // Mutate.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:38:19 2015 13 // Update Count : 1 14 14 // 15 15 16 #include "SynTree/Mutator.h" 16 17 … … 22 23 23 24 namespace InitTweak { 25 void mutate( std::list< Declaration * > translationUnit ) { 26 //BasicInit bi; 27 InitExpander ini; 28 //DeclarationHoister dh; 24 29 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 } 36 34 } // namespace InitTweak 37 38 35 39 36 // Local Variables: // -
translator/InitTweak/Mutate.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // Mutate.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:38:52 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef INIT_MUTATE_H 16 17 #define INIT_MUTATE_H … … 21 22 22 23 namespace InitTweak { 23 24 void mutate( std::list< Declaration* > translationUnit ); 25 24 void mutate( std::list< Declaration* > translationUnit ); 26 25 } // namespace InitTweak 27 26 28 #endif // #ifndefINIT_MUTATE_H27 #endif // INIT_MUTATE_H 29 28 30 /*31 Local Variables:32 mode: c++33 End:34 */35 29 // Local Variables: // 36 30 // tab-width: 4 // -
translator/InitTweak/RemoveInit.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // RemoveInit.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:39:32 2015 13 // Update Count : 1 14 14 // 15 15 16 #include "RemoveInit.h" 16 17 #include "SynTree/Declaration.h" … … 22 23 23 24 namespace InitTweak { 25 namespace { 26 const std::list<Label> noLabels; 27 } 24 28 25 namespace { 26 const std::list<Label> noLabels; 27 } 29 void tweak( std::list< Declaration * > translationUnit ) { 30 RemoveInit remover; 31 mutateAll( translationUnit, remover ); 32 } 28 33 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 } 33 45 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 } 50 50 51 51 // in the case where an object has an initializer and a polymorphic type, insert an assignment 52 52 // immediately after the declaration. This will (seemingly) cause the later phases to do the right 53 53 // thing with the assignment 54 ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {55 56 57 58 59 60 61 } 62 } 63 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 } 65 65 } // namespace InitTweak 66 66 -
translator/InitTweak/RemoveInit.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // RemoveInit.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:40:11 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: PolyMutator.h,v 1.8 2005/08/29 20:14:13 rcbilson Exp $19 *20 */21 15 22 16 #ifndef REMOVE_INIT_H … … 31 25 32 26 namespace InitTweak { 27 void tweak( std::list< Declaration * > translationUnit ); 33 28 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 }; 46 38 } // namespace 47 39 48 #endif /* #ifndef GENPOLY_POLYMUTATOR_H */ 40 #endif // GENPOLY_POLYMUTATOR_H 41 49 42 // Local Variables: // 50 43 // tab-width: 4 // -
translator/InitTweak/diet_map.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // diet_map.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // 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 15 16 #include <cassert> 16 17 #include <string> … … 18 19 19 20 namespace 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 }; 214 214 } // namespace diet 215 215 216 217 /*218 Local Variables:219 mode: c++220 End:221 */222 216 // Local Variables: // 223 217 // tab-width: 4 // -
translator/Parser/ExpressionNode.cc
r01aeade ra08ba92 81 81 } 82 82 83 CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp ) {83 CommaExprNode *ExpressionNode::add_to_list( ExpressionNode *exp ) { 84 84 return new CommaExprNode( this, exp ); 85 85 } … … 111 111 } 112 112 113 void ConstantNode::classify( std::string &str ) {114 switch ( type ) {113 void ConstantNode::classify( std::string &str ) { 114 switch ( type ) { 115 115 case Integer: 116 116 case Float: … … 130 130 std::transform( sfx.begin(), sfx.end(), sfx.begin(), tolower_hack ); 131 131 132 if ( sfx.find("ll") != string::npos ) {132 if ( sfx.find("ll") != string::npos ) { 133 133 longs = 2; 134 } else if ( sfx.find("l") != string::npos ) {134 } else if ( sfx.find("l") != string::npos ) { 135 135 longs = 1; 136 136 } // if … … 163 163 ConstantNode *ConstantNode::append( std::string *newValue ) { 164 164 if ( newValue ) { 165 if ( type == String ) {165 if ( type == String ) { 166 166 std::string temp = *newValue; 167 167 value.resize( value.size() - 1 ); … … 209 209 BasicType *bt; 210 210 211 switch ( get_type()) {211 switch ( get_type()) { 212 212 case Integer: 213 213 /* Cfr. standard 6.4.4.1 */ … … 354 354 return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() )); 355 355 } else { 356 switch ( op->get_type()) {356 switch ( op->get_type()) { 357 357 case OperatorNode::Incr: 358 358 case OperatorNode::Decr: … … 563 563 } 564 564 565 void CompositeExprNode::set_function( ExpressionNode *f ) {565 void CompositeExprNode::set_function( ExpressionNode *f ) { 566 566 function = f; 567 567 } 568 568 569 void CompositeExprNode::set_args( ExpressionNode *args ) {569 void CompositeExprNode::set_args( ExpressionNode *args ) { 570 570 arguments = args; 571 571 } … … 579 579 } 580 580 581 void CompositeExprNode::add_arg( ExpressionNode *arg ) {581 void CompositeExprNode::add_arg( ExpressionNode *arg ) { 582 582 if ( arguments ) 583 583 arguments->set_link( arg ); … … 594 594 } 595 595 596 CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ) {596 CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ) { 597 597 add_arg( exp ); 598 598 … … 646 646 } 647 647 648 ForCtlExprNode::~ForCtlExprNode() {648 ForCtlExprNode::~ForCtlExprNode() { 649 649 delete init; 650 650 delete condition; -
translator/Parser/ParseNode.cc
r01aeade ra08ba92 10 10 // Created On : Sat May 16 13:26:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 13:27:51201513 // Update Count : 212 // Last Modified On : Tue May 19 16:48:30 2015 13 // Update Count : 3 14 14 // 15 15 … … 24 24 25 25 ParseNode *ParseNode::set_name( string _name ) { 26 27 26 name = _name; 27 return this; 28 28 } 29 29 30 30 ParseNode *ParseNode::set_name( string *_name ) { 31 32 31 name = *_name; // deep copy 32 delete _name; 33 33 34 34 return this; 35 35 } 36 36 37 37 ParseNode::~ParseNode( void ) { 38 38 delete next; 39 39 }; 40 40 41 41 string ParseNode::get_name( void ) { 42 42 return name; 43 43 } 44 44 45 45 ParseNode *ParseNode::get_link( void ) const { 46 46 return next; 47 47 } 48 48 49 49 ParseNode *ParseNode::get_last(void) { 50 50 ParseNode *current = this; 51 51 52 52 while ( current->get_link() != 0 ) 53 53 current = current->get_link(); 54 54 55 55 return current; 56 56 } 57 57 58 ParseNode *ParseNode::set_link(ParseNode *_next) {59 58 ParseNode *ParseNode::set_link(ParseNode *_next) { 59 ParseNode *follow; 60 60 61 61 if ( _next == 0 ) return this; 62 62 63 64 63 for ( follow = this; follow->next != 0; follow = follow->next ); 64 follow->next = _next; 65 65 66 66 return this; 67 67 } 68 68 69 69 const string ParseNode::get_name(void) const { 70 70 return name; 71 71 } 72 72 … … 75 75 76 76 void ParseNode::printList( std::ostream &os, int indent ) const { 77 77 print( os, indent ); 78 78 79 79 if ( next ) { 80 80 next->printList( os, indent ); 81 81 } 82 82 } 83 83 84 84 ParseNode &ParseNode::operator,( ParseNode &p ) { 85 85 set_link( &p ); 86 86 87 87 return *this; 88 88 } 89 89 90 90 ParseNode *mkList( ParseNode &pn ) { 91 92 93 94 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; 95 95 } 96 96 -
translator/Parser/StatementNode.cc
r01aeade ra08ba92 171 171 void StatementNode::print( std::ostream &os, int indent ) const { 172 172 if ( labels != 0 ) 173 if ( ! labels->empty()) {173 if ( ! labels->empty()) { 174 174 std::list<std::string>::const_iterator i; 175 175 -
translator/Parser/TypedefTable.cc
r01aeade ra08ba92 123 123 for ( tableType::iterator i = table.begin(); i != table.end(); ) { 124 124 list<Entry> &declList = (*i ).second; 125 while ( ! declList.empty() && declList.front().scope == currentScope ) {125 while ( ! declList.empty() && declList.front().scope == currentScope ) { 126 126 declList.pop_front(); 127 127 } -
translator/Parser/lex.l
r01aeade ra08ba92 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sat May 16 12:14:18201513 * Update Count : 33 012 * Last Modified On : Tue May 19 15:41:54 2015 13 * Update Count : 331 14 14 */ 15 15 -
translator/ResolvExpr/ResolveTypeof.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 12:12:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 12:13:38201513 // Update Count : 212 // Last Modified On : Tue May 19 16:49:04 2015 13 // Update Count : 3 14 14 // 15 15 … … 23 23 24 24 namespace ResolvExpr { 25 25 namespace { 26 26 #if 0 27 27 void … … 34 34 } 35 35 #endif 36 36 } 37 37 38 39 38 class ResolveTypeof : public Mutator { 39 public: 40 40 ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} 41 41 Type *mutate( TypeofType *typeofType ); 42 42 43 43 private: 44 44 const SymTab::Indexer &indexer; 45 45 }; 46 46 47 47 Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { 48 48 ResolveTypeof mutator( indexer ); 49 49 return type->acceptMutator( mutator ); 50 50 } 51 51 52 52 Type *ResolveTypeof::mutate( TypeofType *typeofType ) { 53 53 #if 0 54 54 std::cout << "resolving typeof: "; … … 71 71 } // if 72 72 return typeofType; 73 73 } 74 74 } // namespace ResolvExpr 75 75 -
translator/SymTab/IdTable.cc
r01aeade ra08ba92 139 139 std::stack<DeclEntry> stack = inner->second; 140 140 os << "dumping a stack" << std::endl; 141 while ( ! stack.empty()) {141 while ( ! stack.empty()) { 142 142 DeclEntry d = stack.top(); 143 143 os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl; -
translator/SymTab/IdTable.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:30:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:31:45201513 // Update Count : 312 // Last Modified On : Tue May 19 16:49:33 2015 13 // Update Count : 4 14 14 // 15 15 … … 25 25 26 26 namespace SymTab { 27 28 27 class IdTable { 28 public: 29 29 IdTable(); 30 30 … … 36 36 37 37 void dump( std::ostream &os ) const; // debugging 38 38 private: 39 39 typedef std::pair< DeclarationWithType*, int > DeclEntry; 40 40 typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType; … … 43 43 OuterTableType table; 44 44 int scopeLevel; 45 45 }; 46 46 } // namespace SymTab 47 47 -
translator/SymTab/Indexer.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:37:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:38:44201513 // Update Count : 212 // Last Modified On : Tue May 19 16:49:55 2015 13 // Update Count : 3 14 14 // 15 15 … … 26 26 27 27 namespace SymTab { 28 29 30 31 32 28 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {} 29 30 Indexer::~Indexer() {} 31 32 void Indexer::visit( ObjectDecl *objectDecl ) { 33 33 maybeAccept( objectDecl->get_type(), *this ); 34 34 maybeAccept( objectDecl->get_init(), *this ); … … 38 38 idTable.addDecl( objectDecl ); 39 39 } // if 40 41 42 40 } 41 42 void Indexer::visit( FunctionDecl *functionDecl ) { 43 43 if ( functionDecl->get_name() == "" ) return; 44 44 debugPrint( "Adding function " << functionDecl->get_name() << std::endl ); … … 49 49 maybeAccept( functionDecl->get_statements(), *this ); 50 50 leaveScope(); 51 51 } 52 52 53 53 /******** … … 70 70 */ 71 71 72 72 void Indexer::visit( TypeDecl *typeDecl ) { 73 73 // see A NOTE ON THE ORDER OF TRAVERSAL, above 74 74 // note that assertions come after the type is added to the symtab, since they aren't part … … 81 81 typeTable.add( typeDecl ); 82 82 acceptAll( typeDecl->get_assertions(), *this ); 83 84 85 83 } 84 85 void Indexer::visit( TypedefDecl *typeDecl ) { 86 86 enterScope(); 87 87 acceptAll( typeDecl->get_parameters(), *this ); … … 90 90 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl ); 91 91 typeTable.add( typeDecl ); 92 93 94 92 } 93 94 void Indexer::visit( StructDecl *aggregateDecl ) { 95 95 // make up a forward declaration and add it before processing the members 96 96 StructDecl fwdDecl( aggregateDecl->get_name() ); … … 107 107 // this addition replaces the forward declaration 108 108 structTable.add( aggregateDecl ); 109 110 111 109 } 110 111 void Indexer::visit( UnionDecl *aggregateDecl ) { 112 112 // make up a forward declaration and add it before processing the members 113 113 UnionDecl fwdDecl( aggregateDecl->get_name() ); … … 123 123 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 124 124 unionTable.add( aggregateDecl ); 125 126 127 125 } 126 127 void Indexer::visit( EnumDecl *aggregateDecl ) { 128 128 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl ); 129 129 enumTable.add( aggregateDecl ); 130 130 // unlike structs, contexts, and unions, enums inject their members into the global scope 131 131 acceptAll( aggregateDecl->get_members(), *this ); 132 133 134 132 } 133 134 void Indexer::visit( ContextDecl *aggregateDecl ) { 135 135 enterScope(); 136 136 acceptAll( aggregateDecl->get_parameters(), *this ); … … 140 140 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 141 141 contextTable.add( aggregateDecl ); 142 143 144 142 } 143 144 void Indexer::visit( CompoundStmt *compoundStmt ) { 145 145 enterScope(); 146 146 acceptAll( compoundStmt->get_kids(), *this ); 147 147 leaveScope(); 148 149 150 148 } 149 150 void Indexer::visit( ContextInstType *contextInst ) { 151 151 acceptAll( contextInst->get_parameters(), *this ); 152 152 acceptAll( contextInst->get_members(), *this ); 153 154 155 153 } 154 155 void Indexer::visit( StructInstType *structInst ) { 156 156 if ( ! structTable.lookup( structInst->get_name() ) ) { 157 157 debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl ); … … 161 161 acceptAll( structInst->get_parameters(), *this ); 162 162 leaveScope(); 163 164 165 163 } 164 165 void Indexer::visit( UnionInstType *unionInst ) { 166 166 if ( ! unionTable.lookup( unionInst->get_name() ) ) { 167 167 debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl ); … … 171 171 acceptAll( unionInst->get_parameters(), *this ); 172 172 leaveScope(); 173 174 175 176 177 178 179 180 181 182 183 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 { 184 184 idTable.lookupId( id, list ); 185 186 187 185 } 186 187 DeclarationWithType* Indexer::lookupId( const std::string &id) const { 188 188 return idTable.lookupId(id); 189 190 191 189 } 190 191 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 192 192 return typeTable.lookup( id ); 193 194 195 193 } 194 195 StructDecl *Indexer::lookupStruct( const std::string &id ) const { 196 196 return structTable.lookup( id ); 197 198 199 197 } 198 199 EnumDecl *Indexer::lookupEnum( const std::string &id ) const { 200 200 return enumTable.lookup( id ); 201 202 203 201 } 202 203 UnionDecl *Indexer::lookupUnion( const std::string &id ) const { 204 204 return unionTable.lookup( id ); 205 206 207 205 } 206 207 ContextDecl * Indexer::lookupContext( const std::string &id ) const { 208 208 return contextTable.lookup( id ); 209 210 211 209 } 210 211 void Indexer::enterScope() { 212 212 if ( doDebug ) { 213 213 std::cout << "--- Entering scope" << std::endl; … … 219 219 unionTable.enterScope(); 220 220 contextTable.enterScope(); 221 222 223 221 } 222 223 void Indexer::leaveScope() { 224 224 using std::cout; 225 225 using std::endl; … … 240 240 unionTable.leaveScope(); 241 241 contextTable.leaveScope(); 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 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 ); 260 260 #if 0 261 261 idTable.dump( os ); … … 266 266 contextTable.dump( os ); 267 267 #endif 268 268 } 269 269 } // namespace SymTab 270 270 -
translator/SymTab/Indexer.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:38:55 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:40:17201513 // Update Count : 212 // Last Modified On : Tue May 19 16:51:21 2015 13 // Update Count : 3 14 14 // 15 15 … … 27 27 28 28 namespace SymTab { 29 30 31 Indexer( bool useDebug = false );32 virtual ~Indexer();29 class Indexer : public Visitor { 30 public: 31 Indexer( bool useDebug = false ); 32 virtual ~Indexer(); 33 33 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 ); 43 43 44 virtual void visit( CompoundStmt *compoundStmt );44 virtual void visit( CompoundStmt *compoundStmt ); 45 45 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 ); 49 49 50 virtual void visit( ForStmt *forStmt );50 virtual void visit( ForStmt *forStmt ); 51 51 52 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer53 // explicitly when scopes begin and end54 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(); 56 56 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; 64 64 65 void print( std::ostream &os, int indent = 0 ) const;66 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; 73 73 74 bool doDebug; // display debugging trace75 74 bool doDebug; // display debugging trace 75 }; 76 76 } // namespace SymTab 77 77 -
translator/SymTab/Mangler.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:40:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:43:49201513 // Update Count : 212 // Last Modified On : Tue May 19 16:50:47 2015 13 // Update Count : 3 14 14 // 15 15 … … 30 30 31 31 namespace SymTab { 32 32 Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) { 33 33 } 34 34 … … 37 37 //{ 38 38 //} 39 39 Mangler::Mangler( const Mangler &rhs ) : mangleName() { 40 40 varNums = rhs.varNums; 41 41 nextVarNum = rhs.nextVarNum; 42 42 isTopLevel = rhs.isTopLevel; 43 44 45 43 } 44 45 void Mangler::mangleDecl( DeclarationWithType *declaration ) { 46 46 bool wasTopLevel = isTopLevel; 47 47 if ( isTopLevel ) { … … 60 60 maybeAccept( declaration->get_type(), *this ); 61 61 isTopLevel = wasTopLevel; 62 63 64 62 } 63 64 void Mangler::visit( ObjectDecl *declaration ) { 65 65 mangleDecl( declaration ); 66 67 68 66 } 67 68 void Mangler::visit( FunctionDecl *declaration ) { 69 69 mangleDecl( declaration ); 70 71 72 70 } 71 72 void Mangler::visit( VoidType *voidType ) { 73 73 printQualifiers( voidType ); 74 74 mangleName << "v"; 75 76 77 75 } 76 77 void Mangler::visit( BasicType *basicType ) { 78 78 static const char *btLetter[] = { 79 79 "b", // Bool … … 102 102 printQualifiers( basicType ); 103 103 mangleName << btLetter[ basicType->get_kind() ]; 104 105 106 104 } 105 106 void Mangler::visit( PointerType *pointerType ) { 107 107 printQualifiers( pointerType ); 108 108 mangleName << "P"; 109 109 maybeAccept( pointerType->get_base(), *this ); 110 111 112 110 } 111 112 void Mangler::visit( ArrayType *arrayType ) { 113 113 // TODO: encode dimension 114 114 printQualifiers( arrayType ); 115 115 mangleName << "A0"; 116 116 maybeAccept( arrayType->get_base(), *this ); 117 118 119 117 } 118 119 namespace { 120 120 inline std::list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) { 121 121 std::list< Type* > ret; … … 124 124 return ret; 125 125 } 126 127 128 126 } 127 128 void Mangler::visit( FunctionType *functionType ) { 129 129 printQualifiers( functionType ); 130 130 mangleName << "F"; … … 135 135 acceptAll( paramTypes, *this ); 136 136 mangleName << "_"; 137 138 139 137 } 138 139 void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) { 140 140 printQualifiers( refType ); 141 141 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 142 143 144 142 } 143 144 void Mangler::visit( StructInstType *aggregateUseType ) { 145 145 mangleRef( aggregateUseType, "s" ); 146 147 148 146 } 147 148 void Mangler::visit( UnionInstType *aggregateUseType ) { 149 149 mangleRef( aggregateUseType, "u" ); 150 151 152 150 } 151 152 void Mangler::visit( EnumInstType *aggregateUseType ) { 153 153 mangleRef( aggregateUseType, "e" ); 154 155 156 154 } 155 156 void Mangler::visit( TypeInstType *typeInst ) { 157 157 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 158 158 if ( varNum == varNums.end() ) { … … 176 176 mangleName << std::string( numStream.str(), numStream.pcount() ); 177 177 } // if 178 179 180 178 } 179 180 void Mangler::visit( TupleType *tupleType ) { 181 181 printQualifiers( tupleType ); 182 182 mangleName << "T"; 183 183 acceptAll( tupleType->get_types(), *this ); 184 184 mangleName << "_"; 185 186 187 185 } 186 187 void Mangler::visit( TypeDecl *decl ) { 188 188 static const char *typePrefix[] = { "BT", "BD", "BF" }; 189 189 mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name(); 190 191 192 190 } 191 192 void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) { 193 193 for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) { 194 194 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl; 195 195 } // for 196 197 198 196 } 197 198 void Mangler::printQualifiers( Type *type ) { 199 199 if ( ! type->get_forall().empty() ) { 200 200 std::list< std::string > assertionNames; … … 242 242 mangleName << "A"; 243 243 } // if 244 244 } 245 245 } // namespace SymTab 246 246 -
translator/SymTab/Mangler.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:44:03 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:45:05201513 // Update Count : 212 // Last Modified On : Tue May 19 16:49:21 2015 13 // Update Count : 3 14 14 // 15 15 … … 22 22 23 23 namespace SymTab { 24 25 24 class Mangler : public Visitor { 25 public: 26 26 template< typename SynTreeClass > 27 27 static std::string mangle( SynTreeClass *decl ); // interface to clients … … 44 44 45 45 std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } 46 46 private: 47 47 std::ostrstream mangleName; 48 48 typedef std::map< std::string, std::pair< int, int > > VarMapType; … … 58 58 59 59 void printQualifiers( Type *type ); 60 60 }; // Mangler 61 61 62 63 62 template< typename SynTreeClass > 63 std::string Mangler::mangle( SynTreeClass *decl ) { 64 64 Mangler mangler; 65 65 maybeAccept( decl, mangler ); 66 66 return mangler.get_mangleName(); 67 67 } 68 68 } // SymTab 69 69 -
translator/SymTab/StackTable.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:45:15 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:46:59201513 // Update Count : 212 // Last Modified On : Tue May 19 16:51:53 2015 13 // Update Count : 3 14 14 // 15 15 … … 19 19 20 20 namespace SymTab { 21 22 21 template< typename Element, typename ConflictFunction > 22 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) { 23 23 } 24 24 25 26 25 template< typename Element, typename ConflictFunction > 26 void StackTable< Element, ConflictFunction >::enterScope() { 27 27 scopeLevel++; 28 28 } 29 29 30 31 30 template< typename Element, typename ConflictFunction > 31 void StackTable< Element, ConflictFunction >::leaveScope() { 32 32 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 33 33 std::stack< Entry >& entry = it->second; … … 38 38 scopeLevel--; 39 39 assert( scopeLevel >= 0 ); 40 40 } 41 41 42 43 42 template< typename Element, typename ConflictFunction > 43 void StackTable< Element, ConflictFunction >::add( Element *type ) { 44 44 std::stack< Entry >& entry = table[ type->get_name() ]; 45 45 if ( ! entry.empty() && entry.top().second == scopeLevel ) { … … 48 48 entry.push( Entry( type, scopeLevel ) ); 49 49 } // if 50 50 } 51 51 52 53 52 template< typename Element, typename ConflictFunction > 53 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) { 54 54 add( new Element( fwdDeclName ) ); 55 55 } 56 56 57 58 57 template< typename Element, typename ConflictFunction > 58 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const { 59 59 typename TableType::const_iterator it = table.find( id ); 60 60 if ( it == table.end() ) { … … 65 65 return 0; 66 66 } // if 67 67 } 68 68 69 70 69 template< typename Element, typename ConflictFunction > 70 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const { 71 71 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 72 72 const std::stack< Entry >& entry = it->second; … … 75 75 } // if 76 76 } // for 77 77 } 78 78 } // namespace SymTab 79 79 -
translator/SymTab/StackTable.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:47:10 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:48:15201513 // Update Count : 312 // Last Modified On : Tue May 19 16:50:36 2015 13 // Update Count : 4 14 14 // 15 15 … … 23 23 24 24 namespace SymTab { 25 25 template< typename Element, typename ConflictFunction > 26 26 class StackTable { 27 27 public: 28 28 StackTable(); 29 29 … … 35 35 36 36 void dump( std::ostream &os ) const; // debugging 37 37 private: 38 38 typedef std::pair< Element*, int > Entry; 39 39 typedef std::map< std::string, std::stack< Entry > > TableType; … … 42 42 TableType table; 43 43 int scopeLevel; 44 44 }; 45 45 } // SymTab 46 46 -
translator/SymTab/TypeTable.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:48:32 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:49:49201513 // Update Count : 212 // Last Modified On : Tue May 19 16:50:25 2015 13 // Update Count : 3 14 14 // 15 15 … … 27 27 28 28 namespace SymTab { 29 30 29 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > { 30 public: 31 31 NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) { 32 32 if ( existing->get_base() == 0 ) { … … 40 40 return 0; 41 41 } 42 42 }; 43 43 44 44 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable; 45 45 } // namespace SymTab 46 46 -
translator/SymTab/Validate.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:53:16201513 // Update Count : 212 // Last Modified On : Tue May 19 16:50:09 2015 13 // Update Count : 3 14 14 // 15 15 … … 57 57 58 58 namespace SymTab { 59 60 59 class HoistStruct : public Visitor { 60 public: 61 61 static void hoistStruct( std::list< Declaration * > &translationUnit ); 62 62 … … 74 74 virtual void visit( CaseStmt *caseStmt ); 75 75 virtual void visit( CatchStmt *catchStmt ); 76 76 private: 77 77 HoistStruct(); 78 78 … … 81 81 std::list< Declaration * > declsToAdd; 82 82 bool inStruct; 83 84 85 83 }; 84 85 class Pass1 : public Visitor { 86 86 typedef Visitor Parent; 87 87 virtual void visit( EnumDecl *aggregateDecl ); 88 88 virtual void visit( FunctionType *func ); 89 90 91 89 }; 90 91 class Pass2 : public Indexer { 92 92 typedef Indexer Parent; 93 93 public: 94 94 Pass2( bool doDebug, const Indexer *indexer ); 95 95 private: 96 96 virtual void visit( StructInstType *structInst ); 97 97 virtual void visit( UnionInstType *unionInst ); … … 107 107 ForwardStructsType forwardStructs; 108 108 ForwardUnionsType forwardUnions; 109 110 111 109 }; 110 111 class Pass3 : public Indexer { 112 112 typedef Indexer Parent; 113 113 public: 114 114 Pass3( const Indexer *indexer ); 115 115 private: 116 116 virtual void visit( ObjectDecl *object ); 117 117 virtual void visit( FunctionDecl *func ); 118 118 119 119 const Indexer *indexer; 120 121 122 123 120 }; 121 122 class AddStructAssignment : public Visitor { 123 public: 124 124 static void addStructAssignment( std::list< Declaration * > &translationUnit ); 125 125 … … 145 145 146 146 AddStructAssignment() : functionNesting( 0 ) {} 147 147 private: 148 148 template< typename StmtClass > void visitStatement( StmtClass *stmt ); 149 149 … … 151 151 std::set< std::string > structsDone; 152 152 unsigned int functionNesting; // current level of nested functions 153 154 155 156 153 }; 154 155 class EliminateTypedef : public Mutator { 156 public: 157 157 static void eliminateTypedef( std::list< Declaration * > &translationUnit ); 158 158 private: 159 159 virtual Declaration *mutate( TypedefDecl *typeDecl ); 160 160 virtual TypeDecl *mutate( TypeDecl *typeDecl ); … … 166 166 167 167 std::map< std::string, TypedefDecl * > typedefNames; 168 169 170 168 }; 169 170 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 171 171 Pass1 pass1; 172 172 Pass2 pass2( doDebug, 0 ); … … 178 178 AddStructAssignment::addStructAssignment( translationUnit ); 179 179 acceptAll( translationUnit, pass3 ); 180 181 182 180 } 181 182 void validateType( Type *type, const Indexer *indexer ) { 183 183 Pass1 pass1; 184 184 Pass2 pass2( false, indexer ); … … 187 187 type->accept( pass2 ); 188 188 type->accept( pass3 ); 189 190 191 192 189 } 190 191 template< typename Visitor > 192 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) { 193 193 std::list< Declaration * >::iterator i = translationUnit.begin(); 194 194 while ( i != translationUnit.end() ) { … … 201 201 i = next; 202 202 } // while 203 204 205 203 } 204 205 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 206 206 HoistStruct hoister; 207 207 acceptAndAdd( translationUnit, hoister, true ); 208 209 210 211 212 213 208 } 209 210 HoistStruct::HoistStruct() : inStruct( false ) { 211 } 212 213 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) { 214 214 std::list< Declaration * >::iterator i = declList.begin(); 215 215 while ( i != declList.end() ) { … … 224 224 i = next; 225 225 } // while 226 227 228 226 } 227 228 bool isStructOrUnion( Declaration *decl ) { 229 229 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ); 230 231 232 233 230 } 231 232 template< typename AggDecl > 233 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { 234 234 if ( inStruct ) { 235 235 // Add elements in stack order corresponding to nesting structure. … … 243 243 // Always remove the hoisted aggregate from the inner structure. 244 244 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 245 246 247 245 } 246 247 void HoistStruct::visit( StructDecl *aggregateDecl ) { 248 248 handleAggregate( aggregateDecl ); 249 250 251 249 } 250 251 void HoistStruct::visit( UnionDecl *aggregateDecl ) { 252 252 handleAggregate( aggregateDecl ); 253 254 255 253 } 254 255 void HoistStruct::visit( CompoundStmt *compoundStmt ) { 256 256 addVisit( compoundStmt, *this ); 257 258 259 257 } 258 259 void HoistStruct::visit( IfStmt *ifStmt ) { 260 260 addVisit( ifStmt, *this ); 261 262 263 261 } 262 263 void HoistStruct::visit( WhileStmt *whileStmt ) { 264 264 addVisit( whileStmt, *this ); 265 266 267 265 } 266 267 void HoistStruct::visit( ForStmt *forStmt ) { 268 268 addVisit( forStmt, *this ); 269 270 271 269 } 270 271 void HoistStruct::visit( SwitchStmt *switchStmt ) { 272 272 addVisit( switchStmt, *this ); 273 274 275 273 } 274 275 void HoistStruct::visit( ChooseStmt *switchStmt ) { 276 276 addVisit( switchStmt, *this ); 277 278 279 277 } 278 279 void HoistStruct::visit( CaseStmt *caseStmt ) { 280 280 addVisit( caseStmt, *this ); 281 282 283 281 } 282 283 void HoistStruct::visit( CatchStmt *cathStmt ) { 284 284 addVisit( cathStmt, *this ); 285 286 287 285 } 286 287 void Pass1::visit( EnumDecl *enumDecl ) { 288 288 // Set the type of each member of the enumeration to be EnumConstant 289 289 … … 294 294 } // for 295 295 Parent::visit( enumDecl ); 296 297 298 296 } 297 298 namespace { 299 299 template< typename DWTIterator > 300 300 void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) { … … 323 323 } // if 324 324 } 325 326 327 325 } 326 327 void Pass1::visit( FunctionType *func ) { 328 328 // Fix up parameters and return types 329 329 fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func ); 330 330 fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func ); 331 331 Visitor::visit( func ); 332 333 334 332 } 333 334 Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) { 335 335 if ( other_indexer ) { 336 336 indexer = other_indexer; … … 338 338 indexer = this; 339 339 } // if 340 341 342 340 } 341 342 void Pass2::visit( StructInstType *structInst ) { 343 343 Parent::visit( structInst ); 344 344 StructDecl *st = indexer->lookupStruct( structInst->get_name() ); … … 352 352 forwardStructs[ structInst->get_name() ].push_back( structInst ); 353 353 } // if 354 355 356 354 } 355 356 void Pass2::visit( UnionInstType *unionInst ) { 357 357 Parent::visit( unionInst ); 358 358 UnionDecl *un = indexer->lookupUnion( unionInst->get_name() ); … … 365 365 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 366 366 } // if 367 368 369 367 } 368 369 void Pass2::visit( ContextInstType *contextInst ) { 370 370 Parent::visit( contextInst ); 371 371 ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() ); … … 383 383 } // for 384 384 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 385 } 386 387 void Pass2::visit( StructDecl *structDecl ) { 388 388 if ( ! structDecl->get_members().empty() ) { 389 389 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() ); … … 396 396 } // if 397 397 Indexer::visit( structDecl ); 398 399 400 398 } 399 400 void Pass2::visit( UnionDecl *unionDecl ) { 401 401 if ( ! unionDecl->get_members().empty() ) { 402 402 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() ); … … 409 409 } // if 410 410 Indexer::visit( unionDecl ); 411 412 413 411 } 412 413 void Pass2::visit( TypeInstType *typeInst ) { 414 414 if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) { 415 415 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) { … … 417 417 } // if 418 418 } // if 419 420 421 419 } 420 421 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) { 422 422 if ( other_indexer ) { 423 423 indexer = other_indexer; … … 425 425 indexer = this; 426 426 } // if 427 428 429 427 } 428 429 void forallFixer( Type *func ) { 430 430 // Fix up assertions 431 431 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) { … … 454 454 } // while 455 455 } // for 456 457 458 456 } 457 458 void Pass3::visit( ObjectDecl *object ) { 459 459 forallFixer( object->get_type() ); 460 460 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 463 463 Parent::visit( object ); 464 464 object->fixUniqueId(); 465 466 467 465 } 466 467 void Pass3::visit( FunctionDecl *func ) { 468 468 forallFixer( func->get_type() ); 469 469 Parent::visit( func ); 470 470 func->fixUniqueId(); 471 472 473 474 475 471 } 472 473 static const std::list< std::string > noLabels; 474 475 void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) { 476 476 AddStructAssignment visitor; 477 477 acceptAndAdd( translationUnit, visitor, false ); 478 479 480 481 478 } 479 480 template< typename OutputIterator > 481 void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) { 482 482 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member ); 483 483 // unnamed bit fields are not copied as they cannot be accessed … … 497 497 498 498 *out++ = new ExprStmt( noLabels, assignExpr ); 499 500 501 502 499 } 500 501 template< typename OutputIterator > 502 void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) { 503 503 static UniqueName indexName( "_index" ); 504 504 … … 539 539 540 540 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) ); 541 542 543 541 } 542 543 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 544 544 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 545 545 … … 570 570 571 571 return assignDecl; 572 573 574 572 } 573 574 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 575 575 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 576 576 … … 598 598 599 599 return assignDecl; 600 601 602 600 } 601 602 void AddStructAssignment::visit( StructDecl *structDecl ) { 603 603 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 604 604 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); … … 607 607 structsDone.insert( structDecl->get_name() ); 608 608 } // if 609 610 611 609 } 610 611 void AddStructAssignment::visit( UnionDecl *unionDecl ) { 612 612 if ( ! unionDecl->get_members().empty() ) { 613 613 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); … … 615 615 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 616 616 } // if 617 618 619 617 } 618 619 void AddStructAssignment::visit( TypeDecl *typeDecl ) { 620 620 CompoundStmt *stmts = 0; 621 621 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 636 636 FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false ); 637 637 declsToAdd.push_back( func ); 638 639 640 638 } 639 640 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) { 641 641 if ( ! declsToAdd.empty() ) { 642 642 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) { … … 645 645 declsToAdd.clear(); 646 646 } // if 647 648 649 647 } 648 649 void AddStructAssignment::visit( FunctionType *) { 650 650 // ensure that we don't add assignment ops for types defined as part of the function 651 652 653 651 } 652 653 void AddStructAssignment::visit( PointerType *) { 654 654 // ensure that we don't add assignment ops for types defined as part of the pointer 655 656 657 655 } 656 657 void AddStructAssignment::visit( ContextDecl *) { 658 658 // ensure that we don't add assignment ops for types defined as part of the context 659 660 661 662 659 } 660 661 template< typename StmtClass > 662 inline void AddStructAssignment::visitStatement( StmtClass *stmt ) { 663 663 std::set< std::string > oldStructs = structsDone; 664 664 addVisit( stmt, *this ); 665 665 structsDone = oldStructs; 666 667 668 666 } 667 668 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 669 669 maybeAccept( functionDecl->get_functionType(), *this ); 670 670 acceptAll( functionDecl->get_oldDecls(), *this ); … … 672 672 maybeAccept( functionDecl->get_statements(), *this ); 673 673 functionNesting -= 1; 674 675 676 674 } 675 676 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 677 677 visitStatement( compoundStmt ); 678 679 680 678 } 679 680 void AddStructAssignment::visit( IfStmt *ifStmt ) { 681 681 visitStatement( ifStmt ); 682 683 684 682 } 683 684 void AddStructAssignment::visit( WhileStmt *whileStmt ) { 685 685 visitStatement( whileStmt ); 686 687 688 686 } 687 688 void AddStructAssignment::visit( ForStmt *forStmt ) { 689 689 visitStatement( forStmt ); 690 691 692 690 } 691 692 void AddStructAssignment::visit( SwitchStmt *switchStmt ) { 693 693 visitStatement( switchStmt ); 694 695 696 694 } 695 696 void AddStructAssignment::visit( ChooseStmt *switchStmt ) { 697 697 visitStatement( switchStmt ); 698 699 700 698 } 699 700 void AddStructAssignment::visit( CaseStmt *caseStmt ) { 701 701 visitStatement( caseStmt ); 702 703 704 702 } 703 704 void AddStructAssignment::visit( CatchStmt *cathStmt ) { 705 705 visitStatement( cathStmt ); 706 707 708 706 } 707 708 bool isTypedef( Declaration *decl ) { 709 709 return dynamic_cast< TypedefDecl * >( decl ); 710 711 712 710 } 711 712 void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) { 713 713 EliminateTypedef eliminator; 714 714 mutateAll( translationUnit, eliminator ); 715 715 filter( translationUnit, isTypedef, true ); 716 717 718 716 } 717 718 Type *EliminateTypedef::mutate( TypeInstType *typeInst ) { 719 719 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() ); 720 720 if ( def != typedefNames.end() ) { … … 725 725 } // if 726 726 return typeInst; 727 728 729 727 } 728 729 Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) { 730 730 Declaration *ret = Mutator::mutate( tyDecl ); 731 731 typedefNames[ tyDecl->get_name() ] = tyDecl; … … 745 745 return ret; 746 746 } // if 747 748 749 747 } 748 749 TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) { 750 750 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() ); 751 751 if ( i != typedefNames.end() ) { … … 753 753 } // if 754 754 return typeDecl; 755 756 757 755 } 756 757 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) { 758 758 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 759 759 DeclarationWithType *ret = Mutator::mutate( funcDecl ); 760 760 typedefNames = oldNames; 761 761 return ret; 762 763 764 762 } 763 764 ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) { 765 765 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 766 766 ObjectDecl *ret = Mutator::mutate( objDecl ); 767 767 typedefNames = oldNames; 768 768 return ret; 769 770 771 769 } 770 771 Expression *EliminateTypedef::mutate( CastExpr *castExpr ) { 772 772 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 773 773 Expression *ret = Mutator::mutate( castExpr ); 774 774 typedefNames = oldNames; 775 775 return ret; 776 777 778 776 } 777 778 CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) { 779 779 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 780 780 CompoundStmt *ret = Mutator::mutate( compoundStmt ); … … 793 793 typedefNames = oldNames; 794 794 return ret; 795 795 } 796 796 } // namespace SymTab 797 797 -
translator/SymTab/Validate.h
r01aeade ra08ba92 11 11 // Created On : Sun May 17 21:53:34 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sun May 17 21:55:09201514 // Update Count : 213 // Last Modified On : Tue May 19 16:49:43 2015 14 // Update Count : 3 15 15 // 16 16 … … 21 21 22 22 namespace SymTab { 23 23 class Indexer; 24 24 25 26 25 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false ); 26 void validateType( Type *type, const Indexer *indexer ); 27 27 } // namespace SymTab 28 28 -
translator/SynTree/AddressExpr.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 23:54:44 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:48:14201513 // Update Count : 512 // Last Modified On : Tue May 19 16:52:51 2015 13 // Update Count : 6 14 14 // 15 15 … … 19 19 20 20 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) { 21 21 for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) { 22 22 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) ); 23 23 } // for 24 24 } 25 25 … … 28 28 29 29 AddressExpr::~AddressExpr() { 30 30 delete arg; 31 31 } 32 32 33 33 void AddressExpr::print( std::ostream &os, int indent ) const { 34 35 34 os << std::string( indent, ' ' ) << "Address of:" << std::endl; 35 if ( arg ) { 36 36 arg->print( os, indent+2 ); 37 37 } // if 38 38 } 39 39 -
translator/SynTree/AggregateDecl.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 23:56:39 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:48:23201513 // Update Count : 412 // Last Modified On : Tue May 19 16:52:08 2015 13 // Update Count : 5 14 14 // 15 15 … … 23 23 24 24 AggregateDecl::AggregateDecl( const AggregateDecl &other ) : Parent( other ) { 25 26 25 cloneAll( other.members, members ); 26 cloneAll( other.parameters, parameters ); 27 27 } 28 28 29 29 AggregateDecl::~AggregateDecl() { 30 31 30 deleteAll( members ); 31 deleteAll( parameters ); 32 32 } 33 33 34 34 void AggregateDecl::print( std::ostream &os, int indent ) const { 35 36 35 using std::string; 36 using std::endl; 37 37 38 39 38 os << typeString() << " " << get_name(); 39 if ( ! parameters.empty() ) { 40 40 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 41 41 printAll( parameters, os, indent+4 ); 42 43 42 } // if 43 if ( ! members.empty() ) { 44 44 os << endl << string( indent+2, ' ' ) << "with members" << endl; 45 45 printAll( members, os, indent+4 ); 46 46 } // if 47 47 } 48 48 49 49 void AggregateDecl::printShort( std::ostream &os, int indent ) const { 50 51 50 using std::string; 51 using std::endl; 52 52 53 54 53 os << typeString() << " " << get_name(); 54 if ( ! parameters.empty() ) { 55 55 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 56 56 printAll( parameters, os, indent+4 ); 57 57 } // if 58 58 } 59 59 -
translator/SynTree/AttrType.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // AttrType.cc.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:53:48201513 // Update Count : 112 // Last Modified On : Tue May 19 16:41:51 2015 13 // Update Count : 2 14 14 // 15 15 -
translator/SynTree/CodeGenVisitor.cc
r01aeade ra08ba92 22 22 using namespace std; 23 23 24 void CodeGenVisitor::visit( Type *type ) { }24 void CodeGenVisitor::visit( Type *type ) { } 25 25 void CodeGenVisitor::visit( BasicType *basicType ) { } 26 26 … … 29 29 } 30 30 31 void CodeGenVisitor::visit( Expression *expr ) { }31 void CodeGenVisitor::visit( Expression *expr ) { } 32 32 33 33 void CodeGenVisitor::visit( ConstantExpr *cnst ) { -
translator/SynTree/Expression.cc
r01aeade ra08ba92 295 295 } 296 296 297 LogicalExpr::~LogicalExpr() {297 LogicalExpr::~LogicalExpr() { 298 298 delete arg1; 299 299 delete arg2; -
translator/SynTree/ReferenceToType.cc
r01aeade ra08ba92 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:49:00 201513 // Update Count : 212 // Last Modified On : Tue May 19 16:52:40 2015 13 // Update Count : 3 14 14 // 15 15 … … 27 27 28 28 ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { 29 29 cloneAll( other.parameters, parameters ); 30 30 } 31 31 32 32 ReferenceToType::~ReferenceToType() { 33 33 deleteAll( parameters ); 34 34 } 35 35 36 36 void ReferenceToType::print( std::ostream &os, int indent ) const { 37 38 39 40 41 37 using std::endl; 38 39 Type::print( os, indent ); 40 os << "instance of " << typeString() << " " << name << " "; 41 if ( ! parameters.empty() ) { 42 42 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 43 43 printAll( parameters, os, indent+2 ); 44 44 } // if 45 45 } 46 46 … … 60 60 61 61 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 62 63 62 assert( baseStruct ); 63 doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); 64 64 } 65 65 … … 67 67 68 68 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 69 70 69 assert( baseUnion ); 70 doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); 71 71 } 72 72 … … 76 76 77 77 ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) { 78 78 cloneAll( other.members, members ); 79 79 } 80 80 81 81 ContextInstType::~ContextInstType() { 82 82 deleteAll( members ); 83 83 } 84 84 85 85 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { 86 86 set_baseType( baseType ); 87 87 } 88 88 … … 91 91 92 92 void TypeInstType::set_baseType( TypeDecl *newValue ) { 93 94 93 baseType = newValue; 94 isFtype = newValue->get_kind() == TypeDecl::Ftype; 95 95 } 96 96 … … 98 98 99 99 void TypeInstType::print( std::ostream &os, int indent ) const { 100 101 102 103 104 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() ) { 105 105 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 106 106 printAll( parameters, os, indent+2 ); 107 107 } // if 108 108 } 109 109 -
translator/SynTree/Statement.cc
r01aeade ra08ba92 58 58 } 59 59 60 void BranchStmt::print( std::ostream &os, int indent ) {60 void BranchStmt::print( std::ostream &os, int indent ) { 61 61 os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ; 62 62 } … … 79 79 IfStmt::~IfStmt() {} 80 80 81 void IfStmt::print( std::ostream &os, int indent ) {81 void IfStmt::print( std::ostream &os, int indent ) { 82 82 os << "\r" << string( indent, ' ') << "If on condition: " << endl ; 83 83 condition->print( os, indent + 4 ); … … 175 175 } 176 176 177 WhileStmt::~WhileStmt() {177 WhileStmt::~WhileStmt() { 178 178 delete body; 179 179 } 180 180 181 void WhileStmt::print( std::ostream &os, int indent ) {181 void WhileStmt::print( std::ostream &os, int indent ) { 182 182 os << "\r" << string( indent, ' ') << "While on condition: " << endl ; 183 183 condition->print( os, indent + 4 ); … … 199 199 } 200 200 201 void ForStmt::print( std::ostream &os, int indent ) {201 void ForStmt::print( std::ostream &os, int indent ) { 202 202 os << "\r" << string( indent, ' ') << "For Statement" << endl ; 203 203 … … 231 231 } 232 232 233 TryStmt::~TryStmt() {233 TryStmt::~TryStmt() { 234 234 delete block; 235 235 } … … 257 257 } 258 258 259 CatchStmt::~CatchStmt() {259 CatchStmt::~CatchStmt() { 260 260 delete decl; 261 261 delete body; -
translator/SynTree/Type.cc
r01aeade ra08ba92 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:00:29201513 // Update Count : 112 // Last Modified On : Tue May 19 16:52:27 2015 13 // Update Count : 2 14 14 // 15 15 … … 21 21 22 22 const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = { 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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", 44 44 }; 45 45 … … 47 47 48 48 Type::Type( const Type &other ) : tq( other.tq ) { 49 49 cloneAll( other.forall, forall ); 50 50 } 51 51 52 52 Type::~Type() { 53 53 deleteAll( forall ); 54 54 } 55 55 56 56 void Type::print( std::ostream &os, int indent ) const { 57 57 if ( ! forall.empty() ) { 58 58 os << "forall" << std::endl; 59 59 printAll( forall, os, indent + 4 ); 60 60 os << std::string( indent+2, ' ' ); 61 62 61 } // if 62 if ( tq.isConst ) { 63 63 os << "const "; 64 65 64 } // if 65 if ( tq.isVolatile ) { 66 66 os << "volatile "; 67 68 67 } // if 68 if ( tq.isRestrict ) { 69 69 os << "restrict "; 70 71 70 } // if 71 if ( tq.isLvalue ) { 72 72 os << "lvalue "; 73 74 73 } // if 74 if ( tq.isAtomic ) { 75 75 os << "_Atomic "; 76 76 } // if 77 77 } 78 78 -
translator/SynTree/Visitor.cc
r01aeade ra08ba92 111 111 } 112 112 113 void Visitor::visit( FallthruStmt *fallthruStmt ) {}113 void Visitor::visit( FallthruStmt *fallthruStmt ) {} 114 114 115 115 void Visitor::visit( CaseStmt *caseStmt ) { -
translator/Tests/Syntax/Expression.c
r01aeade ra08ba92 5 5 // order of evaluation (GCC is different) 6 6 /* 7 i = sizeof( (int) {3} );8 i = sizeof (int) {3};7 i = sizeof( (int) {3} ); 8 i = sizeof (int) {3}; 9 9 */ 10 10 // operators -
translator/Tests/Syntax/Forall.c
r01aeade ra08ba92 16 16 17 17 type 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)), 19 19 T3 | sumable(T3); 20 20 -
translator/Tests/Syntax/Initialization.c
r01aeade ra08ba92 32 32 struct quintet { int v, w, x, y, z;}; 33 33 34 int foo() {34 int foo() { 35 35 return 4; 36 36 } 37 37 38 int main() {38 int main() { 39 39 foo(); 40 40 int i; -
translator/Tests/gcc/900516-1.c
r01aeade ra08ba92 1 1 /* added 'int' to argument */ 2 f(int c) { return!(c?2.0:1.0); }2 f(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];}1 f() {static void*t[];/*={&&x};*/ x:y:;} 2 g() {static unsigned p[5];} -
translator/Tests/gcc/920409-1.c
r01aeade ra08ba92 1 x() {int y;y>0.0?y:y-1;}1 x() {int y;y>0.0?y:y-1;} -
translator/Tests/gcc/920409-2.c
r01aeade ra08ba92 1 double x() {int x1,x2;double v;1 double x() {int x1,x2;double v; 2 2 if (((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:;}1 a() {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})};}1 typedef 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;}1 long long x=0;y() {x=0;} -
translator/Tuples/AssignExpand.cc
r01aeade ra08ba92 38 38 39 39 CompoundStmt *newSt = 0; 40 if ( ! extra.empty() ) {40 if ( ! extra.empty() ) { 41 41 if ( ! newSt ) 42 42 newSt= new CompoundStmt(std::list<Label>()); … … 69 69 if ( tupleExpr->get_type() == SolvedTupleExpr::MASS ) { 70 70 // extract lhs of assignments, assert that rhs is the same, create temporaries 71 assert ( ! exprs.empty());71 assert ( ! exprs.empty()); 72 72 ApplicationExpr *ap1 = dynamic_cast< ApplicationExpr * >( exprs.front() ); 73 73 std::list<Expression *> &args = ap1->get_args(); -
translator/Tuples/MultRet.h
r01aeade ra08ba92 37 37 CompoundStmt *getVars() const { return newVars; } 38 38 39 bool hasResults() const { return ( ! results.empty()); }39 bool hasResults() const { return ( ! results.empty()); } 40 40 std::list<Expression *> &get_results() { return results; } 41 41 private: -
translator/Tuples/TupleAssignment.cc
r01aeade ra08ba92 64 64 65 65 std::list< Expression * > new_assigns; 66 if ( ! matcher->match(new_assigns) )66 if ( ! matcher->match(new_assigns) ) 67 67 return false; 68 68 … … 171 171 if ( best.size() == 1 ) { 172 172 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 ) { 174 174 solved_assigns.push_back( i->expr ); 175 175 } … … 178 178 } 179 179 } else { 180 assert( ! optMass.empty() );180 assert( ! optMass.empty() ); 181 181 ResolvExpr::AltList winners; 182 182 for ( std::vector< ResolvExpr::AltList >::iterator i = optMass.begin(); i != optMass.end(); ++i ) … … 377 377 378 378 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 ) { 380 380 if ( begin == end ) return; 381 381 InputIterator test = begin;
Note: See TracChangeset
for help on using the changeset viewer.