Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r51b1202 r2871210  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 16:01:49 2015
    13 // Update Count     : 1350
     12// Last Modified On : Fri Jul  3 13:53:45 2015
     13// Update Count     : 1220
    1414//
    1515
     
    5454#include "lex.h"
    5555#include "ParseNode.h"
    56 #include "TypeData.h"
    5756#include "LinkageSpec.h"
    5857
     
    115114        StatementNode *sn;
    116115        ConstantNode *constant;
    117         LabelNode *label;
    118116        InitializerNode *in;
    119         bool flag;
    120117}
    121118
     
    136133%type<en> argument_expression_list              argument_expression                     for_control_expression          assignment_opt
    137134%type<en> subrange
    138 %type<en> asm_operands_opt asm_operands_list asm_operand
    139 %type<label> label_list
    140 %type<constant> asm_clobbers_list_opt
    141 %type<flag> asm_volatile_opt
    142135
    143136// statements
     
    235228%type<decl> variable_abstract_ptr variable_array variable_declarator variable_function variable_ptr
    236229
    237 %type<decl> attribute_list_opt attribute_list attribute
    238 
    239230// initializers
    240231%type<in>  initializer initializer_list initializer_opt
     
    338329        | zero_one
    339330                { $$ = new VarRefNode( $1 ); }
     331        | constant
     332                { $$ = $1; }
     333        | string_literal_list
     334                { $$ = $1; }
    340335        | '(' comma_expression ')'
    341336                { $$ = $2; }
     
    380375        | assignment_expression
    381376        | no_attr_identifier ':' assignment_expression
    382                 { $$ = $3->set_argName( $1 ); }
     377                { $$ = $3->set_asArgName( $1 ); }
    383378                // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient
    384379                // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used
    385380                // with an appropriate semantic check.
    386381        | '[' push assignment_expression pop ']' ':' assignment_expression
    387                 { $$ = $7->set_argName( $3 ); }
     382                { $$ = $7->set_asArgName( $3 ); }
    388383        | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression
    389                 { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }
     384                { $$ = $9->set_asArgName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }
    390385        ;
    391386
     
    410405unary_expression:
    411406        postfix_expression
    412         // first location where constant/string can have operator applied: sizeof 3/sizeof "abc"
    413         // still requires semantics checks, e.g., ++3, 3--, *3, &&3
    414         | constant
    415                 { $$ = $1; }
    416         | string_literal_list
    417                 { $$ = $1; }
    418407        | ICR unary_expression
    419408                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); }
     
    631620labeled_statement:
    632621        no_attr_identifier ':' attribute_list_opt statement
    633                 {
    634                         $$ = $4->add_label( $1 );
    635                 }
     622                { $$ = $4->add_label( $1 );}
    636623        ;
    637624
     
    643630                // requires its own scope
    644631          push push
    645           local_label_declaration_opt                                           // GCC, local labels
     632          label_declaration_opt                                                         // GCC, local labels
    646633          block_item_list pop '}'                                                       // C99, intermix declarations and statements
    647634                { $$ = new CompoundStmtNode( $5 ); }
     
    762749
    763750fall_through:                                                                                   // CFA
    764         FALLTHRU                                                                        { $$ = new StatementNode( StatementNode::Fallthru ); }
    765         | FALLTHRU ';'                                                          { $$ = new StatementNode( StatementNode::Fallthru ); }
     751        FALLTHRU                                                                        { $$ = new StatementNode( StatementNode::Fallthru, 0, 0 ); }
     752        | FALLTHRU ';'                                                          { $$ = new StatementNode( StatementNode::Fallthru, 0, 0 ); }
    766753        ;
    767754
     
    791778        | CONTINUE ';'
    792779                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    793                 { $$ = new StatementNode( StatementNode::Continue ); }
     780                { $$ = new StatementNode( StatementNode::Continue, 0, 0 ); }
    794781        | CONTINUE no_attr_identifier ';'                                       // CFA, multi-level continue
    795782                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
     
    798785        | BREAK ';'
    799786                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    800                 { $$ = new StatementNode( StatementNode::Break ); }
     787                { $$ = new StatementNode( StatementNode::Break, 0, 0 ); }
    801788        | BREAK no_attr_identifier ';'                                          // CFA, multi-level exit
    802789                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
     
    808795                { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); }
    809796        | THROW ';'
    810                 { $$ = new StatementNode( StatementNode::Throw ); }
     797                { $$ = new StatementNode( StatementNode::Throw, 0, 0 ); }
    811798        ;
    812799
     
    871858
    872859asm_statement:
    873         ASM asm_volatile_opt '(' string_literal_list ')' ';'
    874                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); }
    875         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
    876                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); }
    877         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    878                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); }
    879         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    880                 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); }
    881         | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    882         { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); }
    883         ;
    884 
    885 asm_volatile_opt:                                                                               // GCC
    886         // empty
    887                 { $$ = false; }
    888         | VOLATILE
    889                 { $$ = true; }
     860        ASM type_qualifier_list_opt '(' constant_expression ')' ';'
     861                { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); }
     862        | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ')' ';' // remaining GCC
     863                { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); }
     864        | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ')' ';'
     865                { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); }
     866        | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list ')' ';'
     867                { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); }
    890868        ;
    891869
    892870asm_operands_opt:                                                                               // GCC
    893871        // empty
    894                 { $$ = 0; }                                                                             // use default argument
    895872        | asm_operands_list
    896873        ;
     
    899876        asm_operand
    900877        | asm_operands_list ',' asm_operand
    901                 { $$ = (ExpressionNode *)$1->set_link( $3 ); }
    902878        ;
    903879
    904880asm_operand:                                                                                    // GCC
    905         string_literal_list '(' constant_expression ')'
    906                 { $$ = new AsmExprNode( 0, $1, $3 ); }
    907         | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
    908                 { $$ = new AsmExprNode( $2, $4, $6 ); }
    909         ;
    910 
    911 asm_clobbers_list_opt:                                                                          // GCC
    912         // empty
    913                 { $$ = 0; }                                                                             // use default argument
    914         | string_literal_list
    915                 { $$ = $1; }
    916         | asm_clobbers_list_opt ',' string_literal_list
    917                 { $$ = (ConstantNode *)$1->set_link( $3 ); }
    918         ;
    919 
    920 label_list:
    921         no_attr_identifier
    922                 { $$ = new LabelNode(); $$->append_label( $1 ); }
    923         | label_list ',' no_attr_identifier
    924                 { $$ = $1; $1->append_label( $3 ); }
     881        STRINGliteral '(' constant_expression ')'       {}
     882        ;
     883
     884asm_clobbers_list:                                                                              // GCC
     885        STRINGliteral                                                           {}
     886        | asm_clobbers_list ',' STRINGliteral
    925887        ;
    926888
     
    951913        ;
    952914
    953 local_label_declaration_opt:                                                    // GCC, local label
     915label_declaration_opt:                                                                  // GCC, local label
    954916        // empty
    955         | local_label_declaration_list
    956         ;
    957 
    958 local_label_declaration_list:                                                   // GCC, local label
    959         LABEL local_label_list ';'
    960         | local_label_declaration_list LABEL local_label_list ';'
    961         ;
    962 
    963 local_label_list:                                                                               // GCC, local label
    964         no_attr_identifier_or_type_name                         {}
    965         | local_label_list ',' no_attr_identifier_or_type_name {}
     917        | label_declaration_list
     918        ;
     919
     920label_declaration_list:                                                                 // GCC, local label
     921        LABEL label_list ';'
     922        | label_declaration_list LABEL label_list ';'
     923        ;
     924
     925label_list:                                                                                             // GCC, local label
     926        no_attr_identifier_or_type_name                 {}
     927        | label_list ',' no_attr_identifier_or_type_name {}
    966928        ;
    967929
     
    12201182        type_qualifier_name
    12211183        | attribute
    1222         //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
     1184                { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
    12231185        ;
    12241186
     
    16931655
    16941656designator:
    1695         // only ".0" and ".1" allowed => semantic check
    1696         FLOATINGconstant
    1697                 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); }
    1698         | '.' no_attr_identifier_or_type_name                           // C99, field name
    1699                 { $$ = new DesignatorNode( new VarRefNode( $2 ) ); }
     1657        '.' no_attr_identifier_or_type_name                                     // C99, field name
     1658                { $$ = new VarRefNode( $2 ); }
    17001659        | '[' push assignment_expression pop ']'                        // C99, single array element
    17011660                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
    1702                 { $$ = new DesignatorNode( $3, true ); }
     1661                { $$ = $3; }
    17031662        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
    1704                 { $$ = new DesignatorNode( $3, true ); }
     1663                { $$ = $3; }
    17051664        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    1706                 { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true ); }
     1665                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ); }
    17071666        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    1708                 { $$ = new DesignatorNode( $4 ); }
     1667                { $$ = $4; }
    17091668        ;
    17101669
     
    20381997attribute_list_opt:                                                                             // GCC
    20391998        // empty
    2040                 { $$ = 0; }
    20411999        | attribute_list
    20422000        ;
     
    20452003        attribute
    20462004        | attribute_list attribute
    2047                 { $$ = $2->addQualifiers( $1 ); }
    20482005        ;
    20492006
    20502007attribute:                                                                                              // GCC
    20512008        ATTRIBUTE '(' '(' attribute_parameter_list ')' ')'
    2052         //              { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }
    2053                 { $$ = 0; }
    20542009        ;
    20552010
     
    21042059variable_declarator:
    21052060        paren_identifier attribute_list_opt
    2106                 { $$ = $1->addQualifiers( $2 ); }
    21072061        | variable_ptr
    21082062        | variable_array attribute_list_opt
    2109                 { $$ = $1->addQualifiers( $2 ); }
    21102063        | variable_function attribute_list_opt
    2111                 { $$ = $1->addQualifiers( $2 ); }
    21122064        ;
    21132065
     
    21562108function_declarator:
    21572109        function_no_ptr attribute_list_opt
    2158                 { $$ = $1->addQualifiers( $2 ); }
    21592110        | function_ptr
    21602111        | function_array attribute_list_opt
    2161                 { $$ = $1->addQualifiers( $2 ); }
    21622112        ;
    21632113
     
    22382188type_redeclarator:
    22392189        paren_type attribute_list_opt
    2240                 { $$ = $1->addQualifiers( $2 ); }
    22412190        | type_ptr
    22422191        | type_array attribute_list_opt
    2243                 { $$ = $1->addQualifiers( $2 ); }
    22442192        | type_function attribute_list_opt
    2245                 { $$ = $1->addQualifiers( $2 ); }
    22462193        ;
    22472194
     
    22882235identifier_parameter_declarator:
    22892236        paren_identifier attribute_list_opt
    2290                 { $$ = $1->addQualifiers( $2 ); }
    22912237        | identifier_parameter_ptr
    22922238        | identifier_parameter_array attribute_list_opt
    2293                 { $$ = $1->addQualifiers( $2 ); }
    22942239        | identifier_parameter_function attribute_list_opt
    2295                 { $$ = $1->addQualifiers( $2 ); }
    22962240        ;
    22972241
     
    23532297type_parameter_redeclarator:
    23542298        typedef attribute_list_opt
    2355                 { $$ = $1->addQualifiers( $2 ); }
    23562299        | type_parameter_ptr
    23572300        | type_parameter_array attribute_list_opt
    2358                 { $$ = $1->addQualifiers( $2 ); }
    23592301        | type_parameter_function attribute_list_opt
    2360                 { $$ = $1->addQualifiers( $2 ); }
    23612302        ;
    23622303
     
    24092350        abstract_ptr
    24102351        | abstract_array attribute_list_opt
    2411                 { $$ = $1->addQualifiers( $2 ); }
    24122352        | abstract_function attribute_list_opt
    2413                 { $$ = $1->addQualifiers( $2 ); }
    24142353        ;
    24152354
     
    24782417        abstract_parameter_ptr
    24792418        | abstract_parameter_array attribute_list_opt
    2480                 { $$ = $1->addQualifiers( $2 ); }
    24812419        | abstract_parameter_function attribute_list_opt
    2482                 { $$ = $1->addQualifiers( $2 ); }
    24832420        ;
    24842421
     
    25562493        variable_abstract_ptr
    25572494        | variable_abstract_array attribute_list_opt
    2558                 { $$ = $1->addQualifiers( $2 ); }
    25592495        | variable_abstract_function attribute_list_opt
    2560                 { $$ = $1->addQualifiers( $2 ); }
    25612496        ;
    25622497
Note: See TracChangeset for help on using the changeset viewer.