Ignore:
Timestamp:
Jun 23, 2026, 1:57:51 PM (31 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
9d7a19f
Parents:
45d0e65
Message:

differentiate between C _Alignof and gcc alignof

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r45d0e65 r366f5cd  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri May  1 11:01:45 2026
    13 // Update Count     : 7320
     12// Last Modified On : Tue Jun 23 12:37:08 2026
     13// Update Count     : 7350
    1414//
    1515
     
    393393%token DISABLE ENABLE TRY THROW THROWRESUME AT                  // CFA
    394394%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    395 %token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     395%token ALIGNAS ALIGNOF __ALIGNOF GENERIC STATICASSERT   // C11/C23
    396396
    397397// names and constants: lexer differentiates between identifier and typedef names
     
    432432%type<expr> constant
    433433%type<expr> tuple                                               tuple_expression_list
    434 %type<oper> ptrref_operator                             unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
     434%type<oper> ptrref_operator                             alignof_operator                        unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
    435435%type<expr> primary_expression                  postfix_expression                      unary_expression
    436436%type<expr> cast_expression_list                cast_expression                         exponential_expression          multiplicative_expression       additive_expression
     
    933933        | SIZEOF '(' attribute_list type_no_function ')'
    934934                { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $4->addQualifiers( $3 ) ) ) ); }
    935         | ALIGNOF unary_expression                                                      // GCC, variable alignment
    936                 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, new ast::TypeofType( maybeMoveBuild( $2 ) ) ) ); }
    937         | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    938                 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
     935        | alignof_operator unary_expression                                             // GCC, variable alignment
     936                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, new ast::TypeofType( maybeMoveBuild( $2 ) ),
     937                                        $1 == OperKinds::AlignOf ? ast::AlignofExpr::Alignof : ast::AlignofExpr::__Alignof ) ); }
     938        | alignof_operator '(' type_no_function ')'                                     // GCC, type alignment
     939                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ),
     940                                        $1 == OperKinds::AlignOf ? ast::AlignofExpr::Alignof : ast::AlignofExpr::__Alignof ) ); }
    939941
    940942                // Cannot use rule "type", which includes cfa_abstract_function, for sizeof/alignof, because of S/R problems on
     
    942944        | SIZEOF '(' cfa_abstract_function ')'
    943945                { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
    944         | ALIGNOF '(' cfa_abstract_function ')'                         // GCC, type alignment
    945                 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
    946 
     946        | alignof_operator '(' cfa_abstract_function ')'                        // GCC, type alignment
     947                { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ),
     948                                        $1 == OperKinds::AlignOf ? ast::AlignofExpr::Alignof : ast::AlignofExpr::__Alignof ) ); }
    947949        | OFFSETOF '(' type_no_function ',' identifier ')'
    948950                { $$ = new ExpressionNode( build_offsetOf( yylloc, $3, build_varref( yylloc, $5 ) ) ); }
     
    956958        | COUNTOF '(' type_no_function ')'
    957959                { $$ = new ExpressionNode( new ast::CountofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
     960        ;
     961
     962alignof_operator:
     963        ALIGNOF                                                                         { $$ = OperKinds::AlignOf; }
     964        | __ALIGNOF                                                                     { $$ = OperKinds::__AlignOf; }
    958965        ;
    959966
Note: See TracChangeset for help on using the changeset viewer.