Changeset 32d6fdc


Ignore:
Timestamp:
Apr 13, 2023, 10:28:47 AM (13 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
1b8fc06c
Parents:
52f9804
Message:

Clean-up in the parser %union.

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r52f9804 r32d6fdc  
    387387
    388388// Question
    389 ast::Stmt * build_asm( const CodeLocation & location, bool voltile, ast::Expr * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
     389ast::Stmt * build_asm( const CodeLocation & location, bool is_volatile, ExpressionNode * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
    390390        std::vector<ast::ptr<ast::Expr>> out, in;
    391391        std::vector<ast::ptr<ast::ConstantExpr>> clob;
     
    395395        buildMoveList( clobber, clob );
    396396        return new ast::AsmStmt( location,
    397                 voltile,
    398                 instruction,
     397                is_volatile,
     398                maybeMoveBuild( instruction ),
    399399                std::move( out ),
    400400                std::move( in ),
  • src/Parser/StatementNode.h

    r52f9804 r32d6fdc  
    9494ast::Stmt * build_compound( const CodeLocation &, StatementNode * first );
    9595StatementNode * maybe_build_compound( const CodeLocation &, StatementNode * first );
    96 ast::Stmt * build_asm( const CodeLocation &, bool voltile, ast::Expr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
     96ast::Stmt * build_asm( const CodeLocation &, bool is_volatile, ExpressionNode * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    9797ast::Stmt * build_directive( const CodeLocation &, std::string * directive );
    9898ast::SuspendStmt * build_suspend( const CodeLocation &, StatementNode *, ast::SuspendStmt::Kind );
  • src/Parser/parser.yy

    r52f9804 r32d6fdc  
    300300%union {
    301301        Token tok;
    302         ParseNode * pn;
    303         ExpressionNode * en;
     302        ExpressionNode * expr;
    304303        DeclarationNode * decl;
    305304        ast::AggregateDecl::Aggregate aggKey;
    306305        ast::TypeDecl::Kind tclass;
    307         StatementNode * sn;
     306        StatementNode * stmt;
    308307        ClauseNode * clause;
    309308        ast::WaitForStmt * wfs;
    310         ast::Expr * constant;
    311309        CondCtl * ifctl;
    312         ForCtrl * fctl;
    313         OperKinds compop;
    314         LabelNode * label;
    315         InitializerNode * in;
    316         OperKinds op;
     310        ForCtrl * forctl;
     311        LabelNode * labels;
     312        InitializerNode * init;
     313        OperKinds oper;
    317314        std::string * str;
    318         bool flag;
    319         EnumHiding hide;
    320         ast::ExceptionKind catch_kind;
     315        bool is_volatile;
     316        EnumHiding enum_hiding;
     317        ast::ExceptionKind except_kind;
    321318        ast::GenericExpr * genexpr;
    322319}
     
    384381%type<tok> identifier                                   identifier_at                           identifier_or_type_name         attr_name
    385382%type<tok> quasi_keyword
    386 %type<constant> string_literal
     383%type<expr> string_literal
    387384%type<str> string_literal_list
    388385
    389 %type<hide> hide_opt                                    visible_hide_opt
     386%type<enum_hiding> hide_opt                                     visible_hide_opt
    390387
    391388// expressions
    392 %type<en> constant
    393 %type<en> tuple                                                 tuple_expression_list
    394 %type<op> ptrref_operator                               unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
    395 %type<en> primary_expression                    postfix_expression                      unary_expression
    396 %type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
    397 %type<en> shift_expression                              relational_expression           equality_expression
    398 %type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
    399 %type<en> logical_AND_expression                logical_OR_expression
    400 %type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    401 %type<en> comma_expression                              comma_expression_opt
    402 %type<en> argument_expression_list_opt  argument_expression_list        argument_expression                     default_initializer_opt
     389%type<expr> constant
     390%type<expr> tuple                                                       tuple_expression_list
     391%type<oper> ptrref_operator                             unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
     392%type<expr> primary_expression                  postfix_expression                      unary_expression
     393%type<expr> cast_expression_list                        cast_expression                         exponential_expression          multiplicative_expression       additive_expression
     394%type<expr> shift_expression                            relational_expression           equality_expression
     395%type<expr> AND_expression                              exclusive_OR_expression         inclusive_OR_expression
     396%type<expr> logical_AND_expression              logical_OR_expression
     397%type<expr> conditional_expression              constant_expression                     assignment_expression           assignment_expression_opt
     398%type<expr> comma_expression                            comma_expression_opt
     399%type<expr> argument_expression_list_opt        argument_expression_list        argument_expression                     default_initializer_opt
    403400%type<ifctl> conditional_declaration
    404 %type<fctl> for_control_expression              for_control_expression_list
    405 %type<compop> upupeq updown updowneq downupdowneq
    406 %type<en> subrange
     401%type<forctl> for_control_expression            for_control_expression_list
     402%type<oper> upupeq updown updowneq downupdowneq
     403%type<expr> subrange
    407404%type<decl> asm_name_opt
    408 %type<en> asm_operands_opt                              asm_operands_list                       asm_operand
    409 %type<label> label_list
    410 %type<en> asm_clobbers_list_opt
    411 %type<flag> asm_volatile_opt
    412 %type<en> handler_predicate_opt
     405%type<expr> asm_operands_opt                            asm_operands_list                       asm_operand
     406%type<labels> label_list
     407%type<expr> asm_clobbers_list_opt
     408%type<is_volatile> asm_volatile_opt
     409%type<expr> handler_predicate_opt
    413410%type<genexpr> generic_association              generic_assoc_list
    414411
    415412// statements
    416 %type<sn> statement                                             labeled_statement                       compound_statement
    417 %type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    418 %type<sn> selection_statement                   if_statement
     413%type<stmt> statement                                           labeled_statement                       compound_statement
     414%type<stmt> statement_decl                              statement_decl_list                     statement_list_nodecl
     415%type<stmt> selection_statement                 if_statement
    419416%type<clause> switch_clause_list_opt            switch_clause_list
    420 %type<en> case_value
     417%type<expr> case_value
    421418%type<clause> case_clause                               case_value_list                         case_label                                      case_label_list
    422 %type<sn> iteration_statement                   jump_statement
    423 %type<sn> expression_statement                  asm_statement
    424 %type<sn> with_statement
    425 %type<en> with_clause_opt
    426 %type<sn> exception_statement
     419%type<stmt> iteration_statement                 jump_statement
     420%type<stmt> expression_statement                        asm_statement
     421%type<stmt> with_statement
     422%type<expr> with_clause_opt
     423%type<stmt> exception_statement
    427424%type<clause> handler_clause                    finally_clause
    428 %type<catch_kind> handler_key
    429 %type<sn> mutex_statement
    430 %type<en> when_clause                                   when_clause_opt                         waitfor         waituntil               timeout
    431 %type<sn> waitfor_statement                             waituntil_statement
     425%type<except_kind> handler_key
     426%type<stmt> mutex_statement
     427%type<expr> when_clause                                 when_clause_opt                         waitfor         waituntil               timeout
     428%type<stmt> waitfor_statement                           waituntil_statement
    432429%type<wfs> wor_waitfor_clause                   waituntil_clause                        wand_waituntil_clause   wor_waituntil_clause
    433430
     
    442439%type<decl> assertion assertion_list assertion_list_opt
    443440
    444 %type<en> bit_subrange_size_opt bit_subrange_size
     441%type<expr> bit_subrange_size_opt bit_subrange_size
    445442
    446443%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
     
    455452
    456453%type<decl> enumerator_list enum_type enum_type_nobody
    457 %type<in> enumerator_value_opt
     454%type<init> enumerator_value_opt
    458455
    459456%type<decl> external_definition external_definition_list external_definition_list_opt
     
    462459
    463460%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
    464 %type<en> field field_name_list field_name fraction_constants_opt
     461%type<expr> field field_name_list field_name fraction_constants_opt
    465462
    466463%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    511508%type<decl> type_parameter type_parameter_list type_initializer_opt
    512509
    513 %type<en> type_parameters_opt type_list array_type_list
     510%type<expr> type_parameters_opt type_list array_type_list
    514511
    515512%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    522519
    523520// initializers
    524 %type<in>  initializer initializer_list_opt initializer_opt
     521%type<init>  initializer initializer_list_opt initializer_opt
    525522
    526523// designators
    527 %type<en>  designator designator_list designation
     524%type<expr>  designator designator_list designation
    528525
    529526
     
    647644
    648645string_literal:
    649         string_literal_list                                                     { $$ = build_constantStr( yylloc, *$1 ); }
     646        string_literal_list                                                     { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); }
    650647        ;
    651648
     
    742739                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
    743740        | string_literal '[' assignment_expression ']'          // "abc"[3], 3["abc"]
    744                 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }
     741                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
    745742        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
    746743                {
     
    760757                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
    761758        | string_literal '`' identifier                                         // CFA, postfix call
    762                 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
     759                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
    763760        | postfix_expression '.' identifier
    764761                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     
    860857        | constant
    861858        | string_literal
    862                 { $$ = new ExpressionNode( $1 ); }
     859                { $$ = $1; }
    863860        | EXTENSION cast_expression                                                     // GCC
    864861                { $$ = $2->set_extension( true ); }
     
    18101807asm_operand:                                                                                    // GCC
    18111808        string_literal '(' constant_expression ')'
    1812                 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); }
     1809                { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    18131810        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    18141811                {
    1815                         $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) );
     1812                        $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) );
    18161813                        delete $2.str;
    18171814                }
     
    18221819                { $$ = nullptr; }                                                               // use default argument
    18231820        | string_literal
    1824                 { $$ = new ExpressionNode( $1 ); }
     1821                { $$ = $1; }
    18251822        | asm_clobbers_list_opt ',' string_literal
    1826                 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
     1823                { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); }
    18271824        ;
    18281825
     
    18961893static_assert:
    18971894        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1898                 { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
     1895                { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); }
    18991896        | STATICASSERT '(' constant_expression ')' ';'          // CFA
    19001897                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); }
     
    33263323                {
    33273324                        DeclarationNode * name = new DeclarationNode();
    3328                         name->asmName = $3;
     3325                        name->asmName = maybeMoveBuild( $3 );
    33293326                        $$ = name->addQualifiers( $5 );
    33303327                }
Note: See TracChangeset for help on using the changeset viewer.