Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/TranslateEnumRange.cpp

    ra9ae5ca r0c327ce  
    55
    66namespace ControlStruct {
     7
     8struct addInitType {
     9    const ast::Stmt * postvisit( const ast::ForStmt * stmt );
     10};
    711
    812struct addInit {
     
    1317    const ast::Stmt * postvisit( const ast::ForStmt * stmt );
    1418};
     19
     20const ast::Stmt* addInitType::postvisit( const ast::ForStmt * stmt ) {
     21    if ( stmt->range_over ) {
     22        auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>();
     23        auto type = typeExpr->type;
     24
     25        auto objInit = stmt->inits.front();
     26        assert( stmt->inits.size() == 1 );
     27
     28        if (auto declStmt = objInit.as<ast::DeclStmt>()) {
     29            auto decl = declStmt->decl;
     30            if ( auto objDecl = decl.as<ast::ObjectDecl>()) {
     31                if ( !objDecl->type && type ) {
     32                    auto objDeclWithType = ast::mutate_field( objDecl, &ast::ObjectDecl::type, type );
     33                    auto declWithType = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithType );
     34                    stmt = ast::mutate_field_index( stmt, &ast::ForStmt::inits, 0, declWithType );
     35                }
     36            }
     37        }
     38    }
     39    return stmt;
     40}
    1541
    1642const ast::Stmt* addInit::postvisit( const ast::ForStmt * stmt ) {
     
    6187    mut = ast::mutate_field(stmt, &ast::ForStmt::inc, assig );
    6288    return mut;
    63 } 
     89}
    6490
    6591void translateEnumRange( ast::TranslationUnit & translationUnit ) {
Note: See TracChangeset for help on using the changeset viewer.