Changeset 057b34f
- Timestamp:
- Jul 31, 2016, 12:41:25 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 08061589, c45170a
- Parents:
- 3778cb2
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r3778cb2 r057b34f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jul 30 14:59:34 201613 // Update Count : 34 112 // Last Modified On : Sun Jul 31 00:11:54 2016 13 // Update Count : 343 14 14 // 15 15 … … 419 419 assert( false ); 420 420 421 422 421 case OT_CTOR: 423 422 case OT_DTOR: … … 473 472 } // switch 474 473 } else { 475 if ( nameExpr->get_name() != "Range" ) { // builtin routines 474 if ( nameExpr->get_name() == "Range" ) { // case V1 ... V2 or case V1~V2 475 assert( untypedExpr->get_args().size() == 2 ); 476 (*untypedExpr->get_args().begin())->accept( *this ); 477 output << " ... "; 478 (*--untypedExpr->get_args().end())->accept( *this ); 479 } else { // builtin routines 476 480 nameExpr->accept( *this ); 477 481 output << "("; 478 482 genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() ); 479 483 output << ")"; 480 } else { // case V1 ... V2 or case V1~V2481 assert( untypedExpr->get_args().size() == 2 );482 (*untypedExpr->get_args().begin())->accept( *this );483 output << " ... ";484 (*--untypedExpr->get_args().end())->accept( *this );485 484 } // if 486 485 } // if -
src/ControlStruct/CaseRangeMutator.cc
r3778cb2 r057b34f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 28 01:56:47201613 // Update Count : 1412 // Last Modified On : Sun Jul 31 00:14:16 2016 13 // Update Count : 29 14 14 // 15 15 … … 34 34 std::list< Statement * >::iterator i = cases.begin(); 35 35 while ( i != cases.end() ) { 36 (*i 36 (*i)->acceptMutator( *this ); 37 37 38 38 if ( ! newCaseLabels.empty() ) { … … 41 41 // transform( newCaseLabels.begin(), newCaseLabels.end(), bnd1st( ptr_fun( ctor< CaseStmt, Label, Expression * > ) ) ); 42 42 43 for ( std::list< Expression * >::iterator j = newCaseLabels.begin(); 44 j != newCaseLabels.end(); j++ ) { 45 std::list<Label> emptyLabels; 46 std::list< Statement *> emptyStmts; 43 for ( std::list< Expression * >::iterator j = newCaseLabels.begin(); j != newCaseLabels.end(); j++ ) { 44 std::list< Label > emptyLabels; 45 std::list< Statement * > emptyStmts; 47 46 newCases.push_back( new CaseStmt( emptyLabels, *j, emptyStmts ) ); 48 47 } // for 49 48 50 if ( CaseStmt *currentCase = dynamic_cast< CaseStmt * > 49 if ( CaseStmt *currentCase = dynamic_cast< CaseStmt * >( *i ) ) 51 50 if ( ! currentCase->get_statements().empty() ) { 52 CaseStmt *lastCase = dynamic_cast< CaseStmt * > 51 CaseStmt *lastCase = dynamic_cast< CaseStmt * >( newCases.back() ); 53 52 if ( lastCase == 0 ) { throw ( 0 ); /* FIXME */ } // something is very wrong, as I just made these, and they were all cases 54 53 // transfer the statement block ( if any ) to the new list: 55 54 lastCase->set_statements( currentCase->get_statements() ); 56 55 } // if 57 std::list< Statement * >::iterator j = i; advance( j, 1 ); 58 replace ( cases, i, newCases ); 56 std::list< Statement * >::iterator j = i; 57 advance( j, 1 ); 58 replace( cases, i, newCases ); 59 59 i = j; 60 60 newCaseLabels.clear(); … … 67 67 68 68 Statement *CaseRangeMutator::mutate( CaseStmt *caseStmt ) { 69 UntypedExpr *cond; 70 if ( ( cond = dynamic_cast< UntypedExpr * >( caseStmt->get_condition() )) != 0 ) { 71 NameExpr *nmfunc; 72 if ( ( nmfunc = dynamic_cast< NameExpr *>( cond->get_function() )) != 0 ) { 73 if ( nmfunc->get_name() == "Range" ) { 74 assert( cond->get_args().size() == 2 ); 75 std::list<Expression *>::iterator i = cond->get_args().begin(); 76 Expression *lo = *i, *hi = *(++i ); // "unnecessary" temporaries 77 //fillRange( lo, hi ); 78 } // if 79 } // if 80 } else if ( TupleExpr *tcond = dynamic_cast< TupleExpr * >( caseStmt->get_condition() ) ) { 81 // case list 69 if ( TupleExpr *tcond = dynamic_cast< TupleExpr * >( caseStmt->get_condition() ) ) { // case list 82 70 assert( ! tcond->get_exprs().empty() ); 83 71 for ( std::list< Expression * >::iterator i = tcond->get_exprs().begin(); i != tcond->get_exprs().end(); i++ ) … … 86 74 87 75 std::list< Statement * > &stmts = caseStmt->get_statements(); 88 mutateAll 76 mutateAll( stmts, *this ); 89 77 90 78 return caseStmt; 91 }92 93 void CaseRangeMutator::fillRange( Expression *lo, Expression *hi ) {94 // generate the actual range ( and check for consistency )95 Constant *c_lo, *c_hi;96 ConstantExpr *ce_lo, *ce_hi;97 ce_lo = dynamic_cast< ConstantExpr * >( lo );98 ce_hi = dynamic_cast< ConstantExpr * >( hi );99 100 if ( ce_lo && ce_hi ) {101 std::cout << ce_lo->get_constant()->get_value() << " " << ce_hi->get_constant()->get_value() << std::endl;102 c_lo = ce_lo->get_constant(); c_hi = ce_hi->get_constant();103 } /* else {104 if ( ! ce_lo ) ;105 if ( ! ce_hi ) ;106 } */107 BasicType *ty_lo = dynamic_cast< BasicType * >( c_lo->get_type() ),108 *ty_hi = dynamic_cast< BasicType * >( c_hi->get_type() );109 110 if ( ! ty_lo || ! ty_hi )111 return; // one of them is not a constant112 #if 0113 switch ( ty_lo->get_kind() ) {114 case BasicType::Char:115 case BasicType::UnsignedChar:116 switch ( ty_hi->get_kind() ) {117 case BasicType::Char:118 case BasicType::UnsignedChar:119 // first case, they are both printable ASCII characters represented as 'x'120 if ( c_lo->get_value().size() == 3 && c_hi->get_value().size() == 3 ) {121 char ch_lo = ( c_lo->get_value())[1], ch_hi = ( c_hi->get_value())[1];122 123 if ( ch_lo > ch_hi ) { char t=ch_lo; ch_lo=ch_hi; ch_hi=t; }124 125 for ( char c = ch_lo; c <= ch_hi; c++ ) {126 Type::Qualifiers q;127 Constant cnst( new BasicType( q, BasicType::Char ),128 std::string("'") + c + std::string("'") );129 newCaseLabels.push_back( new ConstantExpr( cnst ) );130 } // for131 132 return;133 } // if134 break;135 default:136 // error: incompatible constants137 break;138 } // switch139 break;140 case BasicType::ShortSignedInt:141 case BasicType::ShortUnsignedInt:142 case BasicType::SignedInt:143 case BasicType::UnsignedInt:144 case BasicType::LongSignedInt:145 case BasicType::LongUnsignedInt:146 case BasicType::LongLongSignedInt:147 case BasicType::LongLongUnsignedInt:148 switch ( ty_hi->get_kind() ) {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 int i_lo = atoi( c_lo->get_value().c_str()),158 i_hi = atoi( c_hi->get_value().c_str());159 160 if ( i_lo > i_hi ) { int t=i_lo; i_lo=i_hi; i_hi=t; }161 162 for ( int c = i_lo; c <= i_hi; c++ ) {163 Type::Qualifiers q;164 Constant cnst( new BasicType( q, ty_hi->get_kind()), // figure can't hurt (used to think in positives)165 toString< int >( c ) );166 newCaseLabels.push_back( new ConstantExpr( cnst ) );167 }168 169 return;170 }171 default:172 // error: incompatible constants173 break;174 }175 break;176 default:177 break;178 } // switch179 #endif180 /* End: */{181 // invalid range, signal a warning (it still generates the two case labels)182 // newCaseLabels.push_back( lo );183 // newCaseLabels.push_back( hi );184 return;185 }186 79 } 187 80 } // namespace ControlStruct -
src/ControlStruct/CaseRangeMutator.h
r3778cb2 r057b34f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 12 17:35:30201613 // Update Count : 412 // Last Modified On : Sat Jul 30 23:41:57 2016 13 // Update Count : 5 14 14 // 15 15 … … 30 30 virtual Statement *mutate( CaseStmt * ); 31 31 private: 32 void fillRange( Expression *lo, Expression *hi );33 34 32 Expression *currentCondition; 35 33 std::list< Expression * > newCaseLabels; -
src/tests/switch.c
r3778cb2 r057b34f 10 10 // Created On : Tue Jul 12 06:50:22 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 30 1 1:31:13201613 // Update Count : 2812 // Last Modified On : Sat Jul 30 14:41:32 2016 13 // Update Count : 30 14 14 // 15 15 … … 33 33 } // switch 34 34 35 // switch (3 ) {36 //int j;37 //case 3:38 //break;39 //case 4:40 //j = 0;41 //}35 switch ( 3 ) { 36 int j; 37 case 3: 38 break; 39 case 4: 40 j = 0; 41 } 42 42 43 43 switch ( i ) {
Note: See TracChangeset
for help on using the changeset viewer.