Changeset 1e30df7 for src/Parser


Ignore:
Timestamp:
Oct 18, 2022, 5:48:13 PM (21 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
5408b59
Parents:
a55472cc
Message:

Supports inline enums

Location:
src/Parser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    ra55472cc r1e30df7  
    297297        } // if
    298298} // DeclarationNode::newEnumValueGeneric
     299
     300DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
     301        DeclarationNode * newnode = newName( new std::string(name) );
     302        newnode->enumInLine = true;
     303        return newnode;
     304}
    299305
    300306DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
  • src/Parser/ParseNode.h

    ra55472cc r1e30df7  
    240240        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    241241        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
     242        static DeclarationNode * newEnumInLine( const std::string name );
    242243        static DeclarationNode * newName( const std::string * );
    243244        static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params );
     
    339340
    340341        bool inLine = false;
     342        bool enumInLine = false;
    341343        Type::FuncSpecifiers funcSpecs;
    342344        Type::StorageClasses storageClasses;
  • src/Parser/TypeData.cc

    ra55472cc r1e30df7  
    924924        list< Declaration * >::iterator members = ret->get_members().begin();
    925925        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     926                if ( cur->enumInLine ) {
     927                        // Tell the compiler this is a inline value placeholder
     928                        ObjectDecl * member = dynamic_cast< ObjectDecl* >(* members);
     929                        member->enumInLine = true;
     930                }
    926931                if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) {
    927932                        SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." );
  • src/Parser/parser.yy

    ra55472cc r1e30df7  
    26012601                { $$ = DeclarationNode::newEnumValueGeneric( $1, $2 ); }
    26022602        | INLINE type_name
    2603                 { $$ = DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ); }
     2603                { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); }
    26042604        | enumerator_list ',' identifier_or_type_name enumerator_value_opt
    26052605                { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $3, $4 ) ); }
Note: See TracChangeset for help on using the changeset viewer.