Ignore:
Timestamp:
Feb 13, 2022, 4:38:25 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
a8ef59e
Parents:
ea89e36
Message:

Enable typed enum

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rea89e36 ra77713b  
    22772277        ;
    22782278
    2279 enum_type:                                                                                              // enum
     2279enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );                                                                                         // enum
    22802280        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2281                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     2281                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    22822282        | ENUM attribute_list_opt identifier
    22832283                { typedefTable.makeTypedef( *$3 ); }
    22842284          '{' enumerator_list comma_opt '}'
    2285                 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
     2285                { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); }
    22862286        | ENUM attribute_list_opt typedef_name                          // unqualified type name
    22872287          '{' enumerator_list comma_opt '}'
    2288                 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2288                { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); }
    22892289        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    22902290                {
    2291                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    2292                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
    2293                 }
    2294         | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     2291                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 )
     2292                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2293                        // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2294                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 );
     2295                }
     2296        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
    22952297                {
    22962298                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    22992301          '{' enumerator_list comma_opt '}'
    23002302                {
    2301                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2303                        $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23022304                }
    23032305        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23052307                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23062308                        typedefTable.makeTypedef( *$6->name );
    2307                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2309                        $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23082310                }
    23092311        | enum_type_nobody
     
    23122314enum_type_nobody:                                                                               // enum - {...}
    23132315        ENUM attribute_list_opt identifier
    2314                 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }
     2316                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }
    23152317        | ENUM attribute_list_opt type_name                                     // qualified type name
    2316                 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }
     2318                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }
    23172319        ;
    23182320
Note: See TracChangeset for help on using the changeset viewer.