Changeset f9c3100 for src


Ignore:
Timestamp:
Mar 23, 2021, 9:18:44 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:
1f55a75
Parents:
a46b69c
Message:

refactor assignment_operator, limit aggregate name to unqualified name, add new syntax for enumerated-type extensions and enum initialization, rename typedef rule to typedef_name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ra46b69c rf9c3100  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 15 13:34:17 2021
    13 // Update Count     : 4740
     12// Last Modified On : Tue Mar 23 20:56:24 2021
     13// Update Count     : 4929
    1414//
    1515
     
    3232//
    3333// 1. designation with and without '=' (use ':' instead)
    34 // 2. attributes not allowed in parenthesis of declarator
     34
    3535//
    3636// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
     
    321321%type<en> constant
    322322%type<en> tuple                                                 tuple_expression_list
    323 %type<op> ptrref_operator                               unary_operator                          assignment_operator
     323%type<op> ptrref_operator                               unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
    324324%type<en> primary_expression                    postfix_expression                      unary_expression
    325325%type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
     
    428428
    429429%type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
    430 %type<decl> typedef typedef_declaration typedef_expression
     430%type<decl> typedef_name typedef_declaration typedef_expression
    431431
    432432%type<decl> variable_type_redeclarator type_ptr type_array type_function
     
    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 enum_specifier_nobody
     442%type<decl> type_specifier type_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_opt attribute attribute_name_list attribute_name
     447%type<decl> attribute_list_opt attribute_list attribute attribute_name_list attribute_name
    448448
    449449// initializers
     
    950950
    951951assignment_operator:
     952        simple_assignment_operator
     953        | compound_assignment_operator
     954        ;
     955
     956simple_assignment_operator:
    952957        '='                                                                                     { $$ = OperKinds::Assign; }
    953         | ATassign                                                                      { $$ = OperKinds::AtAssn; }
    954         | EXPassign                                                                     { $$ = OperKinds::ExpAssn; }
     958        | ATassign                                                                      { $$ = OperKinds::AtAssn; } // CFA
     959        ;
     960
     961compound_assignment_operator:
     962        EXPassign                                                                       { $$ = OperKinds::ExpAssn; }
    955963        | MULTassign                                                            { $$ = OperKinds::MulAssn; }
    956964        | DIVassign                                                                     { $$ = OperKinds::DivAssn; }
     
    17541762        ;
    17551763
    1756 enum_specifier_nobody:                                                                  // type specifier - {...}
    1757                 // Preclude SUE declarations in restricted scopes (see type_specifier_nobody)
    1758         basic_type_specifier
    1759         | sue_type_specifier_nobody
    1760         ;
    1761 
    17621764type_qualifier_list_opt:                                                                // GCC, used in asm_statement
    17631765        // empty
     
    20382040          '{' field_declaration_list_opt '}' type_parameters_opt
    20392041                { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); }
    2040         | aggregate_key attribute_list_opt type_name
    2041                 {
    2042                         // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one)
    2043                         typedefTable.makeTypedef( *$3->type->leafName(), forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
     2042        | aggregate_key attribute_list_opt TYPEDEFname          // unqualified type name
     2043                {
     2044                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
    20442045                        forall = false;                                                         // reset
    20452046                }
    20462047          '{' field_declaration_list_opt '}' type_parameters_opt
    2047                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $8, $6, true )->addQualifiers( $2 ); }
     2048                {
     2049                        DeclarationNode::newFromTypedef( $3 );
     2050                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     2051                }
     2052        | aggregate_key attribute_list_opt TYPEGENname          // unqualified type name
     2053                {
     2054                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
     2055                        forall = false;                                                         // reset
     2056                }
     2057          '{' field_declaration_list_opt '}' type_parameters_opt
     2058                {
     2059                        DeclarationNode::newFromTypeGen( $3, nullptr );
     2060                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     2061                }
    20482062        | aggregate_type_nobody
    20492063        ;
     
    22012215        ;
    22022216
    2203 // Cannot use attribute_list_opt because of ambiguity with enum_specifier_nobody, which already parses attribute.
    2204 // Hence, only a single attribute is allowed after the "ENUM".
    22052217enum_type:                                                                                              // enum
    2206         ENUM attribute_opt '{' enumerator_list comma_opt '}'
     2218        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    22072219                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    2208         | ENUM attribute_opt identifier
     2220        | ENUM attribute_list_opt identifier
    22092221                { typedefTable.makeTypedef( *$3 ); }
    22102222          '{' enumerator_list comma_opt '}'
    22112223                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
    2212         | ENUM attribute_opt typedef                                            // enum cannot be generic
     2224        | ENUM attribute_list_opt typedef_name                          // unqualified type name
    22132225          '{' enumerator_list comma_opt '}'
    22142226                { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
    2215         | ENUM enum_specifier_nobody '{' enumerator_list comma_opt '}'
    2216                 // { $$ = DeclarationNode::newEnum( nullptr, $4, true ); }
    2217                 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
    2218         | ENUM enum_specifier_nobody declarator '{' enumerator_list comma_opt '}'
    2219                 // {
    2220                 //      typedefTable.makeTypedef( *$3->name );
    2221                 //      $$ = DeclarationNode::newEnum( nullptr, $5, true );
    2222                 // }
    2223                 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2227        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
     2228                // { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2229                { $$ = nullptr; }
     2230        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt '{' enumerator_list comma_opt '}'
     2231                // { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2232                { typedefTable.makeTypedef( *$6 ); }
     2233        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     2234                // { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2235                { typedefTable.makeTypedef( *$6->name ); }
    22242236        | enum_type_nobody
    22252237        ;
    22262238
    22272239enum_type_nobody:                                                                               // enum - {...}
    2228         ENUM attribute_opt identifier
    2229                 {
    2230                         typedefTable.makeTypedef( *$3 );
    2231                         $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
    2232                 }
    2233         | ENUM attribute_opt type_name                                          // enum cannot be generic
    2234                 {
    2235                         typedefTable.makeTypedef( *$3->type->symbolic.name );
    2236                         $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 );
    2237                 }
     2240        ENUM attribute_list_opt identifier
     2241                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }
     2242        | ENUM attribute_list_opt type_name                                     // qualified type name
     2243                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }
    22382244        ;
    22392245
     
    22412247        identifier_or_type_name enumerator_value_opt
    22422248                { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
     2249        | INLINE type_name
     2250                { $$ = DeclarationNode::newEnumConstant( new string("inline"), nullptr ); }
    22432251        | enumerator_list ',' identifier_or_type_name enumerator_value_opt
    22442252                { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
     2253        | enumerator_list ',' INLINE type_name enumerator_value_opt
     2254                { $$ = $1->appendList( DeclarationNode::newEnumConstant( new string("inline"), nullptr ) ); }
    22452255        ;
    22462256
     
    22502260        // | '=' constant_expression
    22512261        //      { $$ = $2; }
    2252         | '=' initializer
     2262        | simple_assignment_operator initializer
    22532263                { $$ = $2->get_expression(); }                                  // FIX ME: enum only deals with constant_expression
    22542264        ;
     
    23782388        // empty
    23792389                { $$ = nullptr; }
    2380         | '=' initializer
    2381                 { $$ = $2; }
    2382         | '=' VOID
    2383                 { $$ = new InitializerNode( true ); }
    2384         | ATassign initializer
    2385                 { $$ = $2->set_maybeConstructed( false ); }
     2390        | simple_assignment_operator initializer        { $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); }
     2391        | '=' VOID                                                                      { $$ = new InitializerNode( true ); }
    23862392        ;
    23872393
     
    27932799        | attribute_list attribute
    27942800                { $$ = $2->addQualifiers( $1 ); }
    2795         ;
    2796 
    2797 attribute_opt:
    2798         // empty
    2799                 { $$ = nullptr; }
    2800         | attribute
    28012801        ;
    28022802
     
    30323032
    30333033paren_type:
    3034         typedef
    3035                 // hide type name in enclosing scope by variable name
    3036                 {
    3037                         // if ( ! typedefTable.existsCurr( *$1->name ) ) {
    3038                                 typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" );
    3039                         // } else {
    3040                         //      SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr;
    3041                         // } // if
     3034        typedef_name
     3035                {
     3036                        // hide type name in enclosing scope by variable name
     3037                        typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" );
    30423038                }
    30433039        | '(' paren_type ')'
     
    31523148
    31533149type_parameter_redeclarator:
    3154         typedef attribute_list_opt
     3150        typedef_name attribute_list_opt
    31553151                { $$ = $1->addQualifiers( $2 ); }
    3156         | '&' MUTEX typedef attribute_list_opt
     3152        | '&' MUTEX typedef_name attribute_list_opt
    31573153                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    31583154        | type_parameter_ptr
     
    31633159        ;
    31643160
    3165 typedef:
     3161typedef_name:
    31663162        TYPEDEFname
    31673163                { $$ = DeclarationNode::newName( $1 ); }
     
    31803176
    31813177type_parameter_array:
    3182         typedef array_parameter_dimension
     3178        typedef_name array_parameter_dimension
    31833179                { $$ = $1->addArray( $2 ); }
    31843180        | '(' type_parameter_ptr ')' array_parameter_dimension
     
    31873183
    31883184type_parameter_function:
    3189         typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3)
     3185        typedef_name '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    31903186                { $$ = $1->addParamList( $4 ); }
    31913187        | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
Note: See TracChangeset for help on using the changeset viewer.