Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/EnumAndPointerDecay.cpp

    r19a8c40 re9e9f56  
    2121#include "AST/Type.hpp"
    2222#include "SymTab/FixFunction.h"
    23 #include "Validate/NoIdSymbolTable.hpp"
    2423
    2524namespace Validate {
     
    2726namespace {
    2827
    29 struct EnumAndPointerDecayCore final : public WithNoIdSymbolTable, public ast::WithCodeLocation {
     28struct EnumAndPointerDecayCore final : public ast::WithCodeLocation {
    3029        ast::EnumDecl const * previsit( ast::EnumDecl const * decl );
    3130        ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl );
     
    4039        // Set the type of each member of the enumeration to be EnumContant.
    4140        auto mut = ast::mutate( decl );
    42         std::vector<ast::ptr<ast::Decl>> buffer;
    43         for ( auto member : decl->members ) {
    44                 if ( ast::ObjectDecl const * object = member.as<ast::ObjectDecl>() ) {
    45                         buffer.push_back( ast::mutate_field( object,
    46                                 &ast::ObjectDecl::type,
    47                                 new ast::EnumInstType( decl, ast::CV::Const ) ) );
    48                 } else if ( auto value = member.as<ast::InlineMemberDecl>() ) {
    49                         if ( auto targetEnum = symtab.lookupEnum( value->name ) ) {
    50                                 for ( auto enumMember : targetEnum->members ) {
    51                                         auto enumObject = enumMember.strict_as<ast::ObjectDecl>();
    52                                         buffer.push_back( new ast::ObjectDecl(
    53                                                 // Get the location from the "inline" declaration.
    54                                                 value->location,
    55                                                 enumObject->name,
    56                                                 // Construct a new EnumInstType as the type.
    57                                                 new ast::EnumInstType( decl, ast::CV::Const ),
    58                                                 enumObject->init,
    59                                                 enumObject->storage,
    60                                                 enumObject->linkage,
    61                                                 enumObject->bitfieldWidth,
    62                                                 {},
    63                                                 enumObject->funcSpec
    64                                         ) );
    65                                 }
    66                         }
    67                 }
     41        for ( ast::ptr<ast::Decl> & member : mut->members ) {
     42                ast::ObjectDecl const * object = member.strict_as<ast::ObjectDecl>();
     43                member = ast::mutate_field( object, &ast::ObjectDecl::type,
     44                        new ast::EnumInstType( decl, ast::CV::Const ) );
    6845        }
    69         mut->members = buffer;
    7046        return mut;
    7147}
Note: See TracChangeset for help on using the changeset viewer.