Changeset e4d7c1c for src/AST


Ignore:
Timestamp:
Nov 14, 2022, 3:07:34 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
db6cdc0
Parents:
71806e0
Message:

Implement enum Hiding

Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r71806e0 re4d7c1c  
    17641764                        { old->linkage.val },
    17651765                        GET_ACCEPT_1(base, Type),
     1766                        old->hide == EnumDecl::EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible,
    17661767                        old->enumValues
    17671768                );
  • src/AST/Decl.hpp

    r71806e0 re4d7c1c  
    315315        // enum (type_optional) Name {...}
    316316        ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum
    317 
    318         EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false,
     317        enum class EnumHiding { Visible, Hide } hide;
     318
     319        EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false,
    319320                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall,
    320                 Type const * base = nullptr,
     321                Type const * base = nullptr, EnumHiding hide = EnumHiding::Hide,
    321322                std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() )
    322         : AggregateDecl( loc, name, std::move(attrs), linkage ), isTyped(isTyped), base(base), enumValues(enumValues) {}
     323        : AggregateDecl( loc, name, std::move(attrs), linkage ), isTyped(isTyped), base(base), hide(hide), enumValues(enumValues) {}
    323324
    324325        /// gets the integer value for this enumerator, returning true iff value found
  • src/AST/Pass.impl.hpp

    r71806e0 re4d7c1c  
    686686
    687687        if ( __visit_children() ) {
    688                 // unlike structs, traits, and unions, enums inject their members into the global scope
    689                 maybe_accept( node, &EnumDecl::base );
    690                 maybe_accept( node, &EnumDecl::params     );
    691                 maybe_accept( node, &EnumDecl::members    );
    692                 maybe_accept( node, &EnumDecl::attributes );
     688                if ( node->hide == ast::EnumDecl::EnumHiding::Hide ) {
     689                        guard_symtab guard { *this };
     690                        maybe_accept( node, &EnumDecl::base );
     691                        maybe_accept( node, &EnumDecl::params     );
     692                        maybe_accept( node, &EnumDecl::members    );
     693                        maybe_accept( node, &EnumDecl::attributes );
     694                } else {
     695                        maybe_accept( node, &EnumDecl::base );
     696                        maybe_accept( node, &EnumDecl::params     );
     697                        maybe_accept( node, &EnumDecl::members    );
     698                        maybe_accept( node, &EnumDecl::attributes );
     699                }
    693700        }
    694701
Note: See TracChangeset for help on using the changeset viewer.