Changeset 408ab79 for src/Parser


Ignore:
Timestamp:
Jan 25, 2021, 10:17:37 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5282010
Parents:
4f3a4d75
Message:

parse typed enumeration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r4f3a4d75 r408ab79  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 11 21:32:10 2021
    13 // Update Count     : 4633
     12// Last Modified On : Mon Jan 25 21:41:56 2021
     13// Update Count     : 4670
    1414//
    1515
     
    6363extern TypedefTable typedefTable;
    6464
    65 stack< LinkageSpec::Spec > linkageStack;
     65stack<LinkageSpec::Spec> linkageStack;
    6666
    6767bool appendStr( string & to, string & from ) {
     
    187187        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
    188188        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    189         type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     189        type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    190190        } // if
    191191        return new ForCtrl(
     
    440440
    441441%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
    442 %type<decl> type_specifier type_specifier_nobody
     442%type<decl> type_specifier type_specifier_nobody enum_specifier_nobody
    443443
    444444%type<decl> variable_declarator variable_ptr variable_array variable_function
    445445%type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function
    446446
    447 %type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name
     447%type<decl> attribute_list_opt attribute_list attribute_opt attribute attribute_name_list attribute_name
    448448
    449449// initializers
     
    578578                { $$ = $2; }
    579579        | '(' compound_statement ')'                                            // GCC, lambda expression
    580                 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
     580                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
    581581        | type_name '.' identifier                                                      // CFA, nested type
    582582                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    610610                {
    611611                        // create a GenericExpr wrapper with one association pair
    612                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
     612                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } );
    613613                }
    614614        | DEFAULT ':' assignment_expression
    615                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
     615                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); }
    616616        ;
    617617
     
    743743                        switch ( $1 ) {
    744744                          case OperKinds::AddressOf:
    745                                 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) );
     745                                $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) );
    746746                                break;
    747747                          case OperKinds::PointTo:
     
    749749                                break;
    750750                          case OperKinds::And:
    751                                 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) ) );
     751                                $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) );
    752752                                break;
    753753                          default:
     
    762762                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
    763763        | SIZEOF unary_expression
    764                 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
     764                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
    765765        | SIZEOF '(' type_no_function ')'
    766766                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); }
    767767        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    768                 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
     768                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
    769769        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    770770                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
     
    794794                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    795795        | '(' VIRTUAL ')' cast_expression                                       // CFA
    796                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     796                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    797797        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    798                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
     798                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }
    799799        | '(' RETURN type_no_function ')' cast_expression       // CFA
    800800                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     
    977977        assignment_expression
    978978        | comma_expression ',' assignment_expression
    979                 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
     979                { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
    980980        ;
    981981
     
    11021102        constant_expression                                                     { $$ = $1; }
    11031103        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    1104                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
     1104                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
    11051105        | subrange                                                                                      // CFA, subrange
    11061106        ;
     
    14481448asm_operand:                                                                                    // GCC
    14491449        string_literal '(' constant_expression ')'
    1450                 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); }
     1450                { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    14511451        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    1452                 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); }
     1452                { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); }
    14531453        ;
    14541454
     
    17361736        | sue_type_specifier_nobody
    17371737        | type_type_specifier
     1738        ;
     1739
     1740enum_specifier_nobody:                                                                  // type specifier - {...}
     1741                // Preclude SUE declarations in restricted scopes:
     1742                //
     1743                //    int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
     1744                //
     1745                // because it is impossible to call f due to name equivalence.
     1746        basic_type_specifier
     1747        | sue_type_specifier_nobody
    17381748        ;
    17391749
     
    21842194        ;
    21852195
     2196// Cannot use attribute_list_opt because of ambiguity with enum_specifier_nobody, which already parses attributes.
    21862197enum_type:                                                                                              // enum
    2187         ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
     2198        ENUM attribute_opt '{' enumerator_list comma_opt '}'
    21882199                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    2189         | ENUM attribute_list_opt identifier
     2200        | ENUM attribute_opt identifier
    21902201                { typedefTable.makeTypedef( *$3 ); }
    21912202          '{' enumerator_list comma_opt '}'
    21922203                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
    2193         | ENUM attribute_list_opt type_name
     2204        | ENUM attribute_opt typedef
    21942205          '{' enumerator_list comma_opt '}'
    2195                 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }
     2206                { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2207        | ENUM enum_specifier_nobody '{' enumerator_list comma_opt '}'
     2208                // { $$ = DeclarationNode::newEnum( nullptr, $4, true ); }
     2209                { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2210        | ENUM enum_specifier_nobody declarator '{' enumerator_list comma_opt '}'
     2211                // {
     2212                //      typedefTable.makeTypedef( *$3->name );
     2213                //      $$ = DeclarationNode::newEnum( nullptr, $5, true );
     2214                // }
     2215                { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
    21962216        | enum_type_nobody
    21972217        ;
    21982218
    21992219enum_type_nobody:                                                                               // enum - {...}
    2200         ENUM attribute_list_opt identifier
     2220        ENUM attribute_opt identifier
    22012221                {
    22022222                        typedefTable.makeTypedef( *$3 );
    22032223                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
    22042224                }
    2205         | ENUM attribute_list_opt type_name
     2225        | ENUM attribute_opt type_name
    22062226                {
    22072227                        typedefTable.makeTypedef( *$3->type->symbolic.name );
     
    22202240        // empty
    22212241                { $$ = nullptr; }
    2222         | '=' constant_expression
    2223                 { $$ = $2; }
     2242        // | '=' constant_expression
     2243        //      { $$ = $2; }
     2244        | '=' initializer
     2245                { $$ = $2->get_expression(); }                                  // FIX ME: enum only deals with constant_expression
    22242246        ;
    22252247
     
    24032425                { $$ = $3; }
    24042426        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    2405                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
     2427                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }
    24062428        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    24072429                { $$ = $4; }
     
    24412463type_parameter:                                                                                 // CFA
    24422464        type_class identifier_or_type_name
    2443                 {   typedefTable.addToScope( *$2, TYPEDEFname, "9" );
     2465                {
     2466                        typedefTable.addToScope( *$2, TYPEDEFname, "9" );
    24442467                        if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated" ); }
    24452468                        if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated" ); }
     
    27382761subrange:
    27392762        constant_expression '~' constant_expression                     // CFA, integer subrange
    2740                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
     2763                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
    27412764        ;
    27422765
     
    27622785        | attribute_list attribute
    27632786                { $$ = $2->addQualifiers( $1 ); }
     2787        ;
     2788
     2789attribute_opt:
     2790        // empty
     2791                { $$ = nullptr; }
     2792        | attribute
    27642793        ;
    27652794
Note: See TracChangeset for help on using the changeset viewer.