Ignore:
Timestamp:
Mar 9, 2023, 2:37:53 PM (16 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
fed03b3
Parents:
a29477f
Message:

Pre-translation pass on the parser. Entirely code readability improvements, no behaviour (on a larger scale) should be effected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ra29477f r702e826  
    223223        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
    224224        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    225                 type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     225                type = new ExpressionNode( new CastExpr( maybeMoveBuild( type ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    226226        } // if
    227227//      type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) );
     
    649649                { $$ = $2; }
    650650        | '(' compound_statement ')'                                            // GCC, lambda expression
    651                 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
     651                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild( $2 ) ) ) ); }
    652652        | type_name '.' identifier                                                      // CFA, nested type
    653653                { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); }
     
    657657                {
    658658                        // add the missing control expression to the GenericExpr and return it
    659                         $5->control = maybeMoveBuild<Expression>( $3 );
     659                        $5->control = maybeMoveBuild( $3 );
    660660                        $$ = new ExpressionNode( $5 );
    661661                }
     
    693693                {
    694694                        // create a GenericExpr wrapper with one association pair
    695                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } );
     695                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild( $3 ) } } );
    696696                }
    697697        | DEFAULT ':' assignment_expression
    698                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); }
     698                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild( $3 ) } } ); }
    699699        ;
    700700
     
    751751                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    752752        | postfix_expression ICR
    753                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
     753                { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }
    754754        | postfix_expression DECR
    755                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
     755                { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }
    756756        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
    757757                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
     
    793793        field_name
    794794        | FLOATING_DECIMALconstant field
    795                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
     795                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild( $2 ) ) ); }
    796796        | FLOATING_DECIMALconstant '[' field_name_list ']'
    797797                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    798798        | field_name '.' field
    799                 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     799                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild( $3 ) ) ); }
    800800        | field_name '.' '[' field_name_list ']'
    801801                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    802802        | field_name ARROW field
    803                 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     803                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild( $3 ) ) ); }
    804804        | field_name ARROW '[' field_name_list ']'
    805805                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     
    843843                        switch ( $1 ) {
    844844                          case OperKinds::AddressOf:
    845                                 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) );
     845                                $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild( $2 ) ) );
    846846                                break;
    847847                          case OperKinds::PointTo:
     
    849849                                break;
    850850                          case OperKinds::And:
    851                                 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) );
     851                                $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild( $2 ) ) ) );
    852852                                break;
    853853                          default:
     
    858858                { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
    859859        | ICR unary_expression
    860                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); }
     860                { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }
    861861        | DECR unary_expression
    862                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
     862                { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }
    863863        | SIZEOF unary_expression
    864                 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
     864                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); }
    865865        | SIZEOF '(' type_no_function ')'
    866866                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); }
    867867        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    868                 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
     868                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild( $2 ) ) ); }
    869869        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    870870                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
     
    901901                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    902902        | '(' VIRTUAL ')' cast_expression                                       // CFA
    903                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     903                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    904904        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    905                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }
     905                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); }
    906906        | '(' RETURN type_no_function ')' cast_expression       // CFA
    907907                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     
    10921092        assignment_expression
    10931093        | comma_expression ',' assignment_expression
    1094                 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     1094                { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    10951095        ;
    10961096
     
    12301230        constant_expression                                                     { $$ = $1; }
    12311231        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    1232                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     1232                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    12331233        | subrange                                                                                      // CFA, subrange
    12341234        ;
     
    17321732asm_operand:                                                                                    // GCC
    17331733        string_literal '(' constant_expression ')'
    1734                 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     1734                { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild( $3 ) ) ); }
    17351735        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    1736                 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); }
     1736                { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild( $6 ) ) ); }
    17371737        ;
    17381738
     
    28432843                { $$ = $3; }
    28442844        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    2845                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }
     2845                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); }
    28462846        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    28472847                { $$ = $4; }
     
    32313231subrange:
    32323232        constant_expression '~' constant_expression                     // CFA, integer subrange
    3233                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     3233                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    32343234        ;
    32353235
Note: See TracChangeset for help on using the changeset viewer.