Ignore:
Timestamp:
Mar 21, 2022, 3:17:37 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
4390fb6
Parents:
3e54399
Message:

Enable numeric type for typed enum

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    r3e54399 rf238fcc2  
    918918EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
    919919        assert( td->kind == TypeData::Enum );
    920         Type* baseType = td->base ? typebuild(td->base) : nullptr;
     920        Type * baseType = td->base ? typebuild(td->base) : nullptr;
    921921        EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );
    922         buildList( td->enumeration.constants, ret->get_members() ); // enumConstant is both a node and a list
     922        buildList( td->enumeration.constants, ret->get_members() );
    923923        list< Declaration * >::iterator members = ret->get_members().begin();
    924924        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     
    926926                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    927927                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
     928                } else {
     929                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) {
     930                                SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." );
     931                        }
    928932                } // if
    929933        } // for
Note: See TracChangeset for help on using the changeset viewer.