Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r561354f rc86b08d  
    4848using namespace std;
    4949
    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_...
     50#include "SynTree/Declaration.h"
     51#include "ParseNode.h"
    5652#include "TypedefTable.h"
    5753#include "TypeData.h"
     54#include "SynTree/LinkageSpec.h"
    5855#include "Common/SemanticError.h"                                               // error_str
    5956#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     
    300297%union {
    301298        Token tok;
    302         ExpressionNode * expr;
     299        ParseNode * pn;
     300        ExpressionNode * en;
    303301        DeclarationNode * decl;
    304302        ast::AggregateDecl::Aggregate aggKey;
    305303        ast::TypeDecl::Kind tclass;
    306         StatementNode * stmt;
    307         ClauseNode * clause;
     304        StatementNode * sn;
    308305        ast::WaitForStmt * wfs;
     306    ast::WaitUntilStmt::ClauseNode * wuscn;
     307        ast::Expr * constant;
    309308        CondCtl * ifctl;
    310         ForCtrl * forctl;
    311         LabelNode * labels;
    312         InitializerNode * init;
    313         OperKinds oper;
     309        ForCtrl * fctl;
     310        OperKinds compop;
     311        LabelNode * label;
     312        InitializerNode * in;
     313        OperKinds op;
    314314        std::string * str;
    315         bool is_volatile;
    316         EnumHiding enum_hiding;
    317         ast::ExceptionKind except_kind;
     315        bool flag;
     316        EnumHiding hide;
     317        ast::ExceptionKind catch_kind;
    318318        ast::GenericExpr * genexpr;
    319319}
     
    339339%token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE                   // GCC
    340340%token OFFSETOF BASETYPEOF TYPEID                                               // CFA
    341 %token ENUM STRUCT UNION DATA
     341%token ENUM STRUCT UNION
    342342%token EXCEPTION                                                                                // CFA
    343343%token GENERATOR COROUTINE MONITOR THREAD                               // CFA
     
    381381%type<tok> identifier                                   identifier_at                           identifier_or_type_name         attr_name
    382382%type<tok> quasi_keyword
    383 %type<expr> string_literal
     383%type<constant> string_literal
    384384%type<str> string_literal_list
    385385
    386 %type<enum_hiding> hide_opt                                     visible_hide_opt
     386%type<hide> hide_opt                                    visible_hide_opt
    387387
    388388// expressions
    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
     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
    400400%type<ifctl> conditional_declaration
    401 %type<forctl> for_control_expression            for_control_expression_list
    402 %type<oper> upupeq updown updowneq downupdowneq
    403 %type<expr> subrange
     401%type<fctl> for_control_expression              for_control_expression_list
     402%type<compop> upupeq updown updowneq downupdowneq
     403%type<en> subrange
    404404%type<decl> asm_name_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
     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
    410410%type<genexpr> generic_association              generic_assoc_list
    411411
    412412// statements
    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
     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
    430430
    431431// declarations
     
    439439%type<decl> assertion assertion_list assertion_list_opt
    440440
    441 %type<expr> bit_subrange_size_opt bit_subrange_size
     441%type<en> 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<init> enumerator_value_opt
    455 
    456 %type<decl> value_list
    457 %type<decl> data_constructor type_specifier_list
     454%type<in> 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<expr> field field_name_list field_name fraction_constants_opt
     461%type<en> 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<expr> type_parameters_opt type_list array_type_list
     510%type<en> 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<init>  initializer initializer_list_opt initializer_opt
     521%type<in>  initializer initializer_list_opt initializer_opt
    525522
    526523// designators
    527 %type<expr>  designator designator_list designation
     524%type<en>  designator designator_list designation
    528525
    529526
     
    647644
    648645string_literal:
    649         string_literal_list                                                     { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); }
     646        string_literal_list                                                     { $$ = 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, $1, $3 ) ); }
     741                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $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 ) ) ), $1 ) ); }
     759                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
    763760        | postfix_expression '.' identifier
    764761                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
     
    860857        | constant
    861858        | string_literal
    862                 { $$ = $1; }
     859                { $$ = new ExpressionNode( $1 ); }
    863860        | EXTENSION cast_expression                                                     // GCC
    864861                { $$ = $2->set_extension( true ); }
     
    12631260
    12641261case_value_list:                                                                                // CFA
    1265         case_value                                                                      { $$ = new ClauseNode( build_case( yylloc, $1 ) ); }
     1262        case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
    12661263                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
    1267         | case_value_list ',' case_value                        { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3 ) ) ); }
     1264        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
    12681265        ;
    12691266
     
    12741271        | CASE case_value_list error                                            // syntax error
    12751272                { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
    1276         | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
     1273        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default( yylloc ) ); }
    12771274                // A semantic check is required to ensure only one default clause per switch/choose statement.
    12781275        | DEFAULT error                                                                         //  syntax error
     
    12821279case_label_list:                                                                                // CFA
    12831280        case_label
    1284         | case_label_list case_label                            { $$ = $1->set_last( $2 ); }
     1281        | case_label_list case_label                            { $$ = (StatementNode *)( $1->set_last( $2 )); }
    12851282        ;
    12861283
     
    12991296                { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); }
    13001297        | switch_clause_list case_label_list statement_list_nodecl
    1301                 { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); }
     1298                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ) ); }
    13021299        ;
    13031300
     
    16881685waituntil_clause:
    16891686        when_clause_opt waituntil statement
    1690                 { printf( "waituntil_clause 1\n" ); $$ = nullptr; }
     1687                { $$ = build_waituntil_clause( yylloc, $1, $2, maybe_build_compound( yylloc, $3 ) ); }
    16911688        | '(' wor_waituntil_clause ')'
    1692                 { printf( "waituntil_clause 2\n" ); $$ = nullptr; }
     1689                { $$ = $2; }
    16931690        ;
    16941691
    16951692wand_waituntil_clause:
    16961693        waituntil_clause                                                                        %prec THEN
    1697                 { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; }
     1694                { $$ = $1; }
    16981695        | waituntil_clause wand wand_waituntil_clause
    1699                 { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; }
     1696                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::AND, $1, $3 ); }
    17001697        ;
    17011698
    17021699wor_waituntil_clause:
    17031700        wand_waituntil_clause
    1704                 { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; }
     1701                { $$ = $1; }
    17051702        | wor_waituntil_clause wor wand_waituntil_clause
    1706                 { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; }
     1703                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, $1, $3 ); }
    17071704        | wor_waituntil_clause wor when_clause_opt ELSE statement
    1708                 { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; }
     1705                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
    17091706        | wor_waituntil_clause wor when_clause_opt timeout statement    %prec THEN
    1710                 { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; }
     1707                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); }
    17111708        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    17121709        | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    17131710                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    17141711        | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    1715                 { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; }
     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 ) ) ) ); }
    17161716        ;
    17171717
     
    17191719        wor_waituntil_clause                                                            %prec THEN
    17201720                // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement.
    1721                 { $$ = new StatementNode( build_compound( yylloc, nullptr ) ); }
     1721                {
     1722            $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) );
     1723            // $$ = new StatementNode( build_compound( yylloc, nullptr ) );
     1724        }
    17221725        ;
    17231726
     
    17331736handler_clause:
    17341737        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    1735                 { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
     1738                { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }
    17361739        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement
    1737                 { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
     1740                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }
    17381741        ;
    17391742
     
    17521755
    17531756finally_clause:
    1754         FINALLY compound_statement                                      { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); }
     1757        FINALLY compound_statement                                      { $$ = new StatementNode( build_finally( yylloc, $2 ) ); }
    17551758        ;
    17561759
     
    18101813asm_operand:                                                                                    // GCC
    18111814        string_literal '(' constant_expression ')'
    1812                 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
     1815                { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); }
    18131816        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    18141817                {
    1815                         $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) );
     1818                        $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) );
    18161819                        delete $2.str;
    18171820                }
     
    18221825                { $$ = nullptr; }                                                               // use default argument
    18231826        | string_literal
    1824                 { $$ = $1; }
     1827                { $$ = new ExpressionNode( $1 ); }
    18251828        | asm_clobbers_list_opt ',' string_literal
    1826                 { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); }
     1829                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
    18271830        ;
    18281831
     
    18961899static_assert:
    18971900        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    1898                 { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); }
     1901                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
    18991902        | STATICASSERT '(' constant_expression ')' ';'          // CFA
    19001903                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); }
     
    24442447                }
    24452448        | enum_type
    2446         /* | algebric_data_type */
    24472449        ;
    24482450
     
    26832685                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
    26842686                }
     2687        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
     2688                {
     2689                        $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 );
     2690                }
    26852691        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    26862692                {
     
    26922698                        $$ = DeclarationNode::newEnum( $6, $11, true, true, $3, $9 )->addQualifiers( $5 )->addQualifiers( $7 );
    26932699                }
     2700        | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt
     2701          hide_opt '{' enumerator_list comma_opt '}'
     2702                {
     2703                        $$ = DeclarationNode::newEnum( $5, $9, true, true, nullptr, $7 )->addQualifiers( $4 )->addQualifiers( $6 );
     2704                }
    26942705        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt
    26952706          hide_opt '{' enumerator_list comma_opt '}'
     
    26972708                        $$ = DeclarationNode::newEnum( $6->name, $10, true, true, $3, $8 )->addQualifiers( $5 )->addQualifiers( $7 );
    26982709                }
     2710        | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt
     2711          hide_opt '{' enumerator_list comma_opt '}'
     2712                {
     2713                        $$ = DeclarationNode::newEnum( $5->name, $9, true, true, nullptr, $7 )->addQualifiers( $4 )->addQualifiers( $6 );
     2714                }
    26992715        | enum_type_nobody
    2700         | DATA identifier
    2701         { typedefTable.makeTypedef( *$2 ); }
    2702          '{' value_list '}'
    2703          {
    2704                 $$ = DeclarationNode::newAdt( $2, $5 );
    2705          }
    2706         ;
    2707 
    2708 value_list:
    2709         data_constructor
    2710         {
    2711                 $$ = $1;
    2712         }
    2713         /* | identifier_or_type_name '(' type_specifier ')'
    2714         {
    2715                 $$ = DeclarationNode::newEnumValueGeneric( $1, nullptr );
    2716         } */
    2717         /* | data_constructor '|' value_list   */
    2718         | value_list '|' data_constructor
    2719         {
    2720                  { $$ = $1->appendList( $3 ); }
    2721         }
    2722         ;
    2723 
    2724 data_constructor:
    2725         identifier_or_type_name
    2726         {
    2727                 typedefTable.makeTypedef( *$1 );
    2728                 $$ =  DeclarationNode::newTypeDecl( $1, nullptr );;
    2729         }
    2730         | identifier_or_type_name '(' type_specifier_list ')'
    2731         {
    2732                 typedefTable.makeTypedef( *$1 );
    2733                 $$ = DeclarationNode::newTypeDecl( $1, $3 );
    2734         }
    2735 
    2736 type_specifier_list:
    2737         type_specifier
    2738         /* | type_specifier ',' type_specifier_list  */
    2739         | type_specifier_list ',' type_specifier
    2740         {
    2741                 $$ = $1->appendList($3);
    2742         }
    2743         ;
    2744 
     2716        ;
    27452717
    27462718hide_opt:
     
    28522824
    28532825cfa_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
    2854         // empty
    2855                 { $$ = nullptr; }
    2856         | abstract_parameter_declaration
     2826        abstract_parameter_declaration
    28572827        | cfa_identifier_parameter_declarator_no_tuple
    28582828        | cfa_abstract_tuple
     
    33593329                {
    33603330                        DeclarationNode * name = new DeclarationNode();
    3361                         name->asmName = maybeMoveBuild( $3 );
     3331                        name->asmName = $3;
    33623332                        $$ = name->addQualifiers( $5 );
    33633333                }
Note: See TracChangeset for help on using the changeset viewer.