- File:
-
- 1 edited
-
src/ControlStruct/TranslateEnumRange.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/TranslateEnumRange.cpp
r6d2b3dc r73d0e3f4 22 22 auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>(); 23 23 auto type = typeExpr->type; 24 auto inits = stmt->inits; 25 auto enumInst = type.strict_as<ast::EnumInstType>(); 26 auto enumDecl = enumInst->base; 24 27 25 28 auto objInit = stmt->inits.front(); 29 auto initLocation = objInit->location; 30 auto rangeLocation = stmt->range_over->location; 26 31 assert( stmt->inits.size() == 1 ); 27 32 … … 42 47 const ast::Stmt* addInit::postvisit( const ast::ForStmt * stmt ) { 43 48 if ( stmt->range_over ) { 49 auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>(); 50 auto type = typeExpr->type; 44 51 auto inits = stmt->inits; 52 auto enumInst = type.strict_as<ast::EnumInstType>(); 53 auto enumDecl = enumInst->base; 54 45 55 auto init = stmt->inits.front(); 46 56 … … 50 60 if ( !objDecl->init ) { 51 61 auto location = stmt->location; 62 // auto newInit = new ast::SingleInit( location, new ast::NameExpr( location, enumDecl->members.front()->name ) ); 52 63 ast::SingleInit * newInit = new ast::SingleInit( location, 53 stmt->is_inc? 54 ast::UntypedExpr::createCall( location, "lowerBound", {} ): 55 ast::UntypedExpr::createCall( location, "upperBound", {} ), 56 ast::ConstructFlag::MaybeConstruct 57 ); 64 new ast::NameExpr( location, 65 stmt->is_inc? enumDecl->members.front()->name: enumDecl->members.back()->name ) ); 58 66 auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit ); 59 67 auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit ); … … 72 80 auto initDecl = declStmt->decl.strict_as<ast::ObjectDecl>(); 73 81 auto indexName = initDecl->name; 82 83 auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>(); 84 auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>(); 85 auto enumDecl = enumInst->base; 74 86 75 87 // Both inc and dec check if the current posn less than the number of enumerator … … 78 90 ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location, 79 91 "?<=?", 80 { new ast::NameExpr( location, indexName ), 81 ast::UntypedExpr::createCall( location, "upperBound", {} ) }); 92 {new ast::CastExpr(location, 93 new ast::NameExpr( location, indexName ), 94 new ast::BasicType( ast::BasicKind::UnsignedInt 95 ),ast::GeneratedFlag::ExplicitCast), 96 ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 ) }); 82 97 auto increment = ast::UntypedExpr::createCall( location, 83 stmt->is_inc? "succ": "pred", 84 { new ast::NameExpr( location, indexName ) }); 98 stmt->is_inc? "succ": "pred",{ 99 new ast::NameExpr( location, indexName ) 100 }); 85 101 auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment ); 86 102 auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition ); … … 90 106 91 107 void translateEnumRange( ast::TranslationUnit & translationUnit ) { 108 ast::Pass<addInitType>::run( translationUnit ); 92 109 ast::Pass<addInit>::run( translationUnit ); 93 110 ast::Pass<translateEnumRangeCore>::run( translationUnit );
Note:
See TracChangeset
for help on using the changeset viewer.