Ignore:
Timestamp:
Mar 6, 2024, 10:59:19 AM (2 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
56b47b9
Parents:
7a29392f
Message:

documentations, support CFA declaration syntax in sizeof/alignof

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r7a29392f r7e13b11  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  4 08:44:25 2024
    13 // Update Count     : 6562
     12// Last Modified On : Wed Mar  6 10:51:55 2024
     13// Update Count     : 6588
    1414//
    1515
     
    938938        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    939939                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
     940
     941                // Cannot use rule "type", which includes cfa_abstract_function, for sizeof/alignof, because of S/R problems on
     942                // look ahead, so the cfa_abstract_function is factored out.
     943        | SIZEOF '(' cfa_abstract_function ')'
     944                { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
     945        | ALIGNOF '(' cfa_abstract_function ')'                         // GCC, type alignment
     946                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
     947
    940948        | OFFSETOF '(' type_no_function ',' identifier ')'
    941949                { $$ = new ExpressionNode( build_offsetOf( yylloc, $3, build_varref( yylloc, $5 ) ) ); }
    942         | TYPEID '(' type_no_function ')'
     950        | TYPEID '(' type ')'
    943951                {
    944952                        SemanticError( yylloc, "typeid name is currently unimplemented." ); $$ = nullptr;
     
    12381246                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    12391247        | statement_list_nodecl error                                           // invalid syntax rule
    1240                 { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
     1248                { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body,"
     1249                                                 " i.e., after the '{'." ); $$ = nullptr; }
    12411250        ;
    12421251
     
    12461255        ;
    12471256
    1248 // if, switch, and choose require parenthesis around the conditional because it can be followed by a statement.
    1249 // For example, without parenthesis:
    1250 //
    1251 //    if x + y + z; => "if ( x + y ) + z" or "if ( x ) + y + z"
    1252 //    switch ( S ) { ... } => switch ( S ) { compound literal... } ... or
     1257// "if", "switch", and "choose" require parenthesis around the conditional. See the following ambiguities without
     1258// parenthesis:
     1259//
     1260//   if x + y + z; => "if ( x + y ) + z" or "if ( x ) + y + z"
     1261//
     1262//   switch O { }
     1263//
     1264//     O{} => object-constructor for conditional, switch body ???
     1265//     O{} => O for conditional followed by switch body
     1266//
     1267//     C++ has this problem, as it has the same constructor syntax.
     1268//
     1269//   switch sizeof ( T ) { }
     1270//
     1271//     sizeof ( T ) => sizeof of T for conditional followed by switch body
     1272//     sizeof ( T ) => sizeof of compound literal (T){ }, closing parenthesis ???
     1273//
     1274//     Note the two grammar rules for sizeof (alignof)
     1275//
     1276//       | SIZEOF unary_expression
     1277//       | SIZEOF '(' type_no_function ')'
     1278//
     1279//     where the first DOES NOT require parenthesis! And C++ inherits this problem from C.
    12531280
    12541281selection_statement:
     
    22002227        | ATOMIC
    22012228                { $$ = DeclarationNode::newTypeQualifier( ast::CV::Atomic ); }
     2229
     2230                // forall must be a CV qualifier because it can appear in places where SC qualifiers are disallowed.
     2231                //
     2232                //   void foo( forall( T ) T (*)( T ) ); // forward declaration
     2233                //   void bar( static int ); // static disallowed (gcc/CFA)
    22022234        | forall
    22032235                { $$ = DeclarationNode::newForall( $1 ); }
     
    24642496        ;
    24652497
     2498// ************************** AGGREGATE *******************************
     2499
    24662500aggregate_type:                                                                                 // struct, union
    24672501        aggregate_key attribute_list_opt
     
    25442578        | EXCEPTION                                                                                     // CFA
    25452579                { $$ = ast::AggregateDecl::Exception; }
    2546           //            { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = ast::AggregateDecl::NoAggregate; }
    25472580        ;
    25482581
     
    26832716        ;
    26842717
    2685 // ***********
    2686 // Enumeration
    2687 // ***********
     2718// ************************** ENUMERATION *******************************
    26882719
    26892720enum_type:
     
    27852816        ;
    27862817
    2787 // *******************
    2788 // Function parameters
    2789 // *******************
     2818// ************************** FUNCTION PARAMETERS *******************************
    27902819
    27912820parameter_list_ellipsis_opt:
     
    28682897        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initializer_opt
    28692898                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    2870         | cfa_function_specifier
     2899        | cfa_function_specifier                                                        // int f( "int fp()" );
    28712900        ;
    28722901
     
    28782907        | type_qualifier_list cfa_abstract_tuple
    28792908                { $$ = $2->addQualifiers( $1 ); }
    2880         | cfa_abstract_function
     2909        | cfa_abstract_function                                                         // int f( "int ()" );
    28812910        ;
    28822911
     
    30363065                { $$ = ast::TypeDecl::Dtype; }
    30373066        | '*'
    3038                 { $$ = ast::TypeDecl::DStype; }                                         // dtype + sized
    3039         // | '(' '*' ')'
    3040         //      { $$ = ast::TypeDecl::Ftype; }
     3067                { $$ = ast::TypeDecl::DStype; }                                 // Dtype + sized
     3068        // | '(' '*' ')'                                                                        // Gregor made me do it
     3069        //      { $$ = ast::TypeDecl::Ftype; }
    30413070        | ELLIPSIS
    30423071                { $$ = ast::TypeDecl::Ttype; }
     
    32443273                        $$ = $6;
    32453274                }
    3246         // global distribution
     3275                // global distribution
    32473276        | type_qualifier_list
    32483277                {
     
    33693398        ;
    33703399
     3400// **************************** ASM *****************************
     3401
    33713402asm_name_opt:                                                                                   // GCC
    33723403        // empty
     
    33793410                }
    33803411        ;
     3412
     3413// **************************** ATTRIBUTE *****************************
    33813414
    33823415attribute_list_opt:                                                                             // GCC
     
    38263859
    38273860type_parameter_function:
    3828         typedef_name '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     3861        typedef_name '(' parameter_list_ellipsis_opt ')'        // empty parameter list OBSOLESCENT (see 3)
    38293862                { $$ = $1->addParamList( $3 ); }
    38303863        | '(' type_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     
    38763909
    38773910abstract_function:
    3878         '(' parameter_list_ellipsis_opt ')'                     // empty parameter list OBSOLESCENT (see 3)
     3911        '(' parameter_list_ellipsis_opt ')'                                     // empty parameter list OBSOLESCENT (see 3)
    38793912                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    38803913        | '(' abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     
    40084041
    40094042abstract_parameter_function:
    4010         '(' parameter_list_ellipsis_opt ')'                     // empty parameter list OBSOLESCENT (see 3)
     4043        '(' parameter_list_ellipsis_opt ')'                                     // empty parameter list OBSOLESCENT (see 3)
    40114044                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    40124045        | '(' abstract_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)
     
    42804313// mode: c++ //
    42814314// tab-width: 4 //
    4282 // compile-command: "make install" //
     4315// compile-command: "bison -Wcounterexamples parser.yy" //
    42834316// End: //
Note: See TracChangeset for help on using the changeset viewer.