Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rc86b08d r04c78215  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr  4 14:02:00 2023
    13 // Update Count     : 6329
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Apr 26 16:45:37 2023
     13// Update Count     : 6330
    1414//
    1515
     
    4848using namespace std;
    4949
    50 #include "SynTree/Declaration.h"
    51 #include "ParseNode.h"
     50#include "SynTree/Type.h"                               // for Type
     51#include "DeclarationNode.h"                            // for DeclarationNode, ...
     52#include "ExpressionNode.h"                             // for ExpressionNode, ...
     53#include "InitializerNode.h"                            // for InitializerNode, ...
     54#include "ParserTypes.h"
     55#include "StatementNode.h"                              // for build_...
    5256#include "TypedefTable.h"
    5357#include "TypeData.h"
    54 #include "SynTree/LinkageSpec.h"
    5558#include "Common/SemanticError.h"                                               // error_str
    5659#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     
    297300%union {
    298301        Token tok;
    299         ParseNode * pn;
    300         ExpressionNode * en;
     302        ExpressionNode * expr;
    301303        DeclarationNode * decl;
    302304        ast::AggregateDecl::Aggregate aggKey;
    303305        ast::TypeDecl::Kind tclass;
    304         StatementNode * sn;
     306        StatementNode * stmt;
     307        ClauseNode * clause;
    305308        ast::WaitForStmt * wfs;
    306     ast::WaitUntilStmt::ClauseNode * wuscn;
    307         ast::Expr * constant;
    308309        CondCtl * ifctl;
    309         ForCtrl * fctl;
    310         OperKinds compop;
    311         LabelNode * label;
    312         InitializerNode * in;
    313         OperKinds op;
     310        ForCtrl * forctl;
     311        LabelNode * labels;
     312        InitializerNode * init;
     313        OperKinds oper;
    314314        std::string * str;
    315         bool flag;
    316         EnumHiding hide;
    317         ast::ExceptionKind catch_kind;
     315        bool is_volatile;
     316        EnumHiding enum_hiding;
     317        ast::ExceptionKind except_kind;
    318318        ast::GenericExpr * genexpr;
    319319}
     
    381381%type<tok> identifier                                   identifier_at                           identifier_or_type_name         attr_name
    382382%type<tok> quasi_keyword
    383 %type<constant> string_literal
     383%type<expr> string_literal
    384384%type<str> string_literal_list
    385385
    386 %type<hide> hide_opt                                    visible_hide_opt
     386%type<enum_hiding> hide_opt                                     visible_hide_opt
    387387
    388388// expressions
    389 %type<en> constant
    390 %type<en> tuple                                                 tuple_expression_list
    391 %type<op> ptrref_operator                               unary_operator                          assignment_operator                     simple_assignment_operator      compound_assignment_operator
    392 %type<en> primary_expression                    postfix_expression                      unary_expression
    393 %type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
    394 %type<en> shift_expression                              relational_expression           equality_expression
    395 %type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
    396 %type<en> logical_AND_expression                logical_OR_expression
    397 %type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    398 %type<en> comma_expression                              comma_expression_opt
    399 %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
    400400%type<ifctl> conditional_declaration
    401 %type<fctl> for_control_expression              for_control_expression_list
    402 %type<compop> upupeq updown updowneq downupdowneq
    403 %type<en> subrange
     401%type<forctl> for_control_expression            for_control_expression_list
     402%type<oper> upupeq updown updowneq downupdowneq
     403%type<expr> subrange
    404404%type<decl> asm_name_opt
    405 %type<en> asm_operands_opt                              asm_operands_list                       asm_operand
    406 %type<label> label_list
    407 %type<en> asm_clobbers_list_opt
    408 %type<flag> asm_volatile_opt
    409 %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
    410410%type<genexpr> generic_association              generic_assoc_list
    411411
    412412// statements
    413 %type<sn> statement                                             labeled_statement                       compound_statement
    414 %type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    415 %type<sn> selection_statement                   if_statement
    416 %type<sn> switch_clause_list_opt                switch_clause_list
    417 %type<en> case_value
    418 %type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    419 %type<sn> iteration_statement                   jump_statement
    420 %type<sn> expression_statement                  asm_statement
    421 %type<sn> with_statement
    422 %type<en> with_clause_opt
    423 %type<sn> exception_statement                   handler_clause                          finally_clause
    424 %type<catch_kind> handler_key
    425 %type<sn> mutex_statement
    426 %type<en> when_clause                                   when_clause_opt                         waitfor         waituntil               timeout
    427 %type<sn> waitfor_statement                             waituntil_statement
    428 %type<wfs> wor_waitfor_clause
    429 %type<wuscn> waituntil_clause                   wand_waituntil_clause       wor_waituntil_clause
     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
     416%type<clause> switch_clause_list_opt            switch_clause_list
     417%type<expr> case_value
     418%type<clause> case_clause                               case_value_list                         case_label                                      case_label_list
     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
     424%type<clause> handler_clause                    finally_clause
     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
     429%type<wfs> wor_waitfor_clause                   waituntil_clause                        wand_waituntil_clause   wor_waituntil_clause
    430430
    431431// declarations
     
    439439%type<decl> assertion assertion_list assertion_list_opt
    440440
    441 %type<en> bit_subrange_size_opt bit_subrange_size
     441%type<expr> bit_subrange_size_opt bit_subrange_size
    442442
    443443%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
     
    452452
    453453%type<decl> enumerator_list enum_type enum_type_nobody
    454 %type<in> enumerator_value_opt
     454%type<init> enumerator_value_opt
    455455
    456456%type<decl> external_definition external_definition_list external_definition_list_opt
     
    459459
    460460%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
    461 %type<en> field field_name_list field_name fraction_constants_opt
     461%type<expr> field field_name_list field_name fraction_constants_opt
    462462
    463463%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    508508%type<decl> type_parameter type_parameter_list type_initializer_opt
    509509
    510 %type<en> type_parameters_opt type_list array_type_list
     510%type<expr> type_parameters_opt type_list array_type_list
    511511
    512512%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
     
    519519
    520520// initializers
    521 %type<in>  initializer initializer_list_opt initializer_opt
     521%type<init>  initializer initializer_list_opt initializer_opt
    522522
    523523// designators
    524 %type<en>  designator designator_list designation
     524%type<expr>  designator designator_list designation
    525525
    526526
     
    644644
    645645string_literal:
    646         string_literal_list                                                     { $$ = build_constantStr( yylloc, *$1 ); }
     646        string_literal_list                                                     { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); }
    647647        ;
    648648
     
    739739                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
    740740        | string_literal '[' assignment_expression ']'          // "abc"[3], 3["abc"]
    741                 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }
     741                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
    742742        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
    743743                {
     
    757757                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
    758758        | string_literal '`' identifier                                         // CFA, postfix call
    759                 { $$ = 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 ) ); }
    760760        | postfix_expression '.' identifier
    761761                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     
    857857        | constant
    858858        | string_literal
    859                 { $$ = new ExpressionNode( $1 ); }
     859                { $$ = $1; }
    860860        | EXTENSION cast_expression                                                     // GCC
    861861                { $$ = $2->set_extension( true ); }
     
    12601260
    12611261case_value_list:                                                                                // CFA
    1262         case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
     1262        case_value                                                                      { $$ = new ClauseNode( build_case( yylloc, $1 ) ); }
    12631263                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
    1264         | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
     1264        | case_value_list ',' case_value                        { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3 ) ) ); }
    12651265        ;
    12661266
     
    12711271        | CASE case_value_list error                                            // syntax error
    12721272                { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
    1273         | DEFAULT ':'                                                           { $$ = new StatementNode( build_default( yylloc ) ); }
     1273        | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
    12741274                // A semantic check is required to ensure only one default clause per switch/choose statement.
    12751275        | DEFAULT error                                                                         //  syntax error
     
    12791279case_label_list:                                                                                // CFA
    12801280        case_label
    1281         | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
     1281        | case_label_list case_label                            { $$ = $1->set_last( $2 ); }
    12821282        ;
    12831283
     
    12961296                { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); }
    12971297        | switch_clause_list case_label_list statement_list_nodecl
    1298                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ) ); }
     1298                { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); }
    12991299        ;
    13001300
     
    16791679
    16801680waituntil:
    1681         WAITUNTIL '(' cast_expression ')'
     1681        WAITUNTIL '(' comma_expression ')'
    16821682                { $$ = $3; }
    16831683        ;
     
    16851685waituntil_clause:
    16861686        when_clause_opt waituntil statement
    1687                 { $$ = build_waituntil_clause( yylloc, $1, $2, maybe_build_compound( yylloc, $3 ) ); }
     1687                { printf( "waituntil_clause 1\n" ); $$ = nullptr; }
    16881688        | '(' wor_waituntil_clause ')'
    1689                 { $$ = $2; }
     1689                { printf( "waituntil_clause 2\n" ); $$ = nullptr; }
    16901690        ;
    16911691
    16921692wand_waituntil_clause:
    16931693        waituntil_clause                                                                        %prec THEN
    1694                 { $$ = $1; }
     1694                { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; }
    16951695        | waituntil_clause wand wand_waituntil_clause
    1696                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::AND, $1, $3 ); }
     1696                { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; }
    16971697        ;
    16981698
    16991699wor_waituntil_clause:
    17001700        wand_waituntil_clause
    1701                 { $$ = $1; }
     1701                { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; }
    17021702        | wor_waituntil_clause wor wand_waituntil_clause
    1703                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, $1, $3 ); }
     1703                { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; }
    17041704        | wor_waituntil_clause wor when_clause_opt ELSE statement
    1705                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
     1705                { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; }
    17061706        | wor_waituntil_clause wor when_clause_opt timeout statement    %prec THEN
    1707                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); }
     1707                { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; }
    17081708        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    17091709        | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    17101710                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    17111711        | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    1712                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1,
    1713                 new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR,
    1714                     build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ),
    1715                     build_waituntil_else( yylloc, $7, maybe_build_compound( yylloc, $9 ) ) ) ); }
     1712                { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; }
    17161713        ;
    17171714
     
    17191716        wor_waituntil_clause                                                            %prec THEN
    17201717                // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement.
    1721                 {
    1722             $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) );
    1723             // $$ = new StatementNode( build_compound( yylloc, nullptr ) );
    1724         }
     1718                { $$ = new StatementNode( build_compound( yylloc, nullptr ) ); }
    17251719        ;
    17261720
     
    17361730handler_clause:
    17371731        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    1738                 { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
     1732                { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
    17391733        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    1740                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
     1734                { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
    17411735        ;
    17421736
     
    17551749
    17561750finally_clause:
    1757         FINALLY compound_statement                                      { $$ = new StatementNode( build_finally( yylloc, $2 ) ); }
     1751        FINALLY compound_statement                                      { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); }
    17581752        ;
    17591753
     
    18131807asm_operand:                                                                                    // GCC
    18141808        string_literal '(' constant_expression ')'
    1815                 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); }
     1809                { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    18161810        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    18171811                {
    1818                         $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) );
     1812                        $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) );
    18191813                        delete $2.str;
    18201814                }
     
    18251819                { $$ = nullptr; }                                                               // use default argument
    18261820        | string_literal
    1827                 { $$ = new ExpressionNode( $1 ); }
     1821                { $$ = $1; }
    18281822        | asm_clobbers_list_opt ',' string_literal
    1829                 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
     1823                { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); }
    18301824        ;
    18311825
     
    18991893static_assert:
    19001894        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1901                 { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
     1895                { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); }
    19021896        | STATICASSERT '(' constant_expression ')' ';'          // CFA
    19031897                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); }
     
    33293323                {
    33303324                        DeclarationNode * name = new DeclarationNode();
    3331                         name->asmName = $3;
     3325                        name->asmName = maybeMoveBuild( $3 );
    33323326                        $$ = name->addQualifiers( $5 );
    33333327                }
Note: See TracChangeset for help on using the changeset viewer.