Changeset a77713b for src/Parser


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

Enable typed enum

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rea89e36 ra77713b  
    253253} // DeclarationNode::newAggregate
    254254
    255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {
     255DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool ) {
    256256        DeclarationNode * newnode = new DeclarationNode;
    257257        newnode->type = new TypeData( TypeData::Enum );
     
    262262        return newnode;
    263263} // DeclarationNode::newEnum
     264
     265
    264266
    265267DeclarationNode * DeclarationNode::newName( const string * name ) {
  • src/Parser/ParseNode.h

    rea89e36 ra77713b  
    235235        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    236236        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    237         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
     237        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );
    238238        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    239239        static DeclarationNode * newName( const std::string * );
  • 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.