Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r67cf18c rfdca7c6  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 25 15:21:59 2017
    13 // Update Count     : 2398
     12// Last Modified On : Thu May 18 18:06:17 2017
     13// Update Count     : 2338
    1414//
    1515
     
    159159}
    160160
    161 %type<tok> identifier  no_attr_identifier zero_one
    162 %type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
     161%type<tok> identifier  no_01_identifier  no_attr_identifier zero_one
     162%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name  attr_name
    163163%type<constant> string_literal
    164164%type<str> string_literal_list
     
    207207%type<en>   bit_subrange_size_opt bit_subrange_size
    208208
    209 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
     209%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type_name indirect_type_name
    210210
    211211%type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier
     
    261261%type<decl> type_declarator type_declarator_name type_declaring_list
    262262
    263 %type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
    264 %type<decl> typedef typedef_declaration typedef_expression
     263%type<decl> typedef typedef_type_specifier typedef_declaration typedef_declaration_specifier typedef_expression
    265264
    266265%type<decl> variable_type_redeclarator type_ptr type_array type_function
    267266
    268267%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
    269 
    270 %type<decl> type type_no_function
    271 %type<decl> type_parameter type_parameter_list type_initializer_opt
    272 
    273 %type<en> type_list
     268%type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
     269
     270%type<decl> type_name type_name_no_function
     271%type<decl> type_parameter type_parameter_list
     272
     273%type<en> type_name_list
    274274
    275275%type<decl> type_qualifier type_qualifier_name type_qualifier_list_opt type_qualifier_list
     
    351351        IDENTIFIER
    352352        | ATTR_IDENTIFIER                                                                       // CFA
     353        | zero_one                                                                                      // CFA
     354        ;
     355
     356no_01_identifier:
     357        IDENTIFIER
     358        | ATTR_IDENTIFIER                                                                       // CFA
    353359        ;
    354360
    355361no_attr_identifier:
    356362        IDENTIFIER
     363        | zero_one                                                                                      // CFA
    357364        ;
    358365
     
    360367        ZERO
    361368        | ONE
    362         ;
     369        ;
    363370
    364371string_literal:
     
    388395        | '(' compound_statement ')'                                            // GCC, lambda expression
    389396                { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
    390         | primary_expression '{' argument_expression_list '}' // CFA, constructor call
     397        | primary_expression '{' argument_expression_list '}' // CFA
    391398                {
    392399                        Token fn;
     
    394401                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    395402                }
    396         | type_name '.' no_attr_identifier                                      // CFA, nested type
    397                 { $$ = nullptr; }                                                               // FIX ME
    398         | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    399                 { $$ = nullptr; }                                                               // FIX ME
    400403        ;
    401404
     
    428431        | postfix_expression DECR
    429432                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    430         | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
     433        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    431434                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    432435        | '^' primary_expression '{' argument_expression_list '}' // CFA
     
    480483        | no_attr_identifier fraction_constants
    481484                {
    482                         $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
    483                 }
    484         | zero_one fraction_constants
    485                 {
    486                         $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );
     485                        if( (*$1) == "0" || (*$1) == "1" ) {
     486                                $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );
     487                        } else {
     488                                $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     489                        }
    487490                }
    488491        ;
     
    532535        | SIZEOF unary_expression
    533536                { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
    534         | SIZEOF '(' type_no_function ')'
     537        | SIZEOF '(' type_name_no_function ')'
    535538                { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
    536539        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    537540                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
    538         | ALIGNOF '(' type_no_function ')'                              // GCC, type alignment
     541        | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
    539542                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    540         | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
     543        | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')'
    541544                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
    542545        | ATTR_IDENTIFIER
     
    544547        | ATTR_IDENTIFIER '(' argument_expression ')'
    545548                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
    546         | ATTR_IDENTIFIER '(' type ')'
     549        | ATTR_IDENTIFIER '(' type_name ')'
    547550                { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
    548551//      | ANDAND IDENTIFIER                                                                     // GCC, address of label
     
    566569cast_expression:
    567570        unary_expression
    568         | '(' type_no_function ')' cast_expression
     571        | '(' type_name_no_function ')' cast_expression
    569572                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    570 //      | '(' type_no_function ')' tuple
     573//      | '(' type_name_no_function ')' tuple
    571574//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    572575        ;
     
    655658        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    656659                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
     660//      | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
     661//              { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
    657662        ;
    658663
     
    666671        | unary_expression assignment_operator assignment_expression
    667672                { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); }
     673//      | tuple assignment_opt                                                          // CFA, tuple expression
     674//              { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); }
    668675        ;
    669676
     
    13451352        basic_declaration_specifier
    13461353        | sue_declaration_specifier
    1347         | type_declaration_specifier
     1354        | typedef_declaration_specifier
     1355        | typegen_declaration_specifier
    13481356        ;
    13491357
     
    13561364        basic_declaration_specifier
    13571365        | sue_declaration_specifier_nobody
    1358         | type_declaration_specifier
     1366        | typedef_declaration_specifier
     1367        | typegen_declaration_specifier
    13591368        ;
    13601369
     
    13621371        basic_type_specifier
    13631372        | sue_type_specifier
    1364         | type_type_specifier
     1373        | typedef_type_specifier
     1374        | typegen_type_specifier
    13651375        ;
    13661376
     
    13731383        basic_type_specifier
    13741384        | sue_type_specifier_nobody
    1375         | type_type_specifier
     1385        | typedef_type_specifier
     1386        | typegen_type_specifier
    13761387        ;
    13771388
     
    15081519
    15091520basic_type_specifier:
    1510         direct_type
    1511         | type_qualifier_list_opt indirect_type type_qualifier_list_opt
     1521        direct_type_name
     1522        | type_qualifier_list_opt indirect_type_name type_qualifier_list_opt
    15121523                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
    15131524        ;
    15141525
    1515 direct_type:
     1526direct_type_name:
    15161527                // A semantic check is necessary for conflicting type qualifiers.
    15171528        basic_type_name
    15181529        | type_qualifier_list basic_type_name
    15191530                { $$ = $2->addQualifiers( $1 ); }
    1520         | direct_type type_qualifier
    1521                 { $$ = $1->addQualifiers( $2 ); }
    1522         | direct_type basic_type_name
     1531        | direct_type_name type_qualifier
     1532                { $$ = $1->addQualifiers( $2 ); }
     1533        | direct_type_name basic_type_name
    15231534                { $$ = $1->addType( $2 ); }
    15241535        ;
    15251536
    1526 indirect_type:
    1527         TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
     1537indirect_type_name:
     1538        TYPEOF '(' type_name ')'                                                        // GCC: typeof(x) y;
    15281539                { $$ = $3; }
    15291540        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
    15301541                { $$ = DeclarationNode::newTypeof( $3 ); }
    1531         | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
     1542        | ATTR_TYPEGENname '(' type_name ')'                            // CFA: e.g., @type(x) y;
    15321543                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    15331544        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     
    15731584        ;
    15741585
    1575 type_declaration_specifier:
    1576         type_type_specifier
    1577         | declaration_qualifier_list type_type_specifier
     1586typedef_declaration_specifier:
     1587        typedef_type_specifier
     1588        | declaration_qualifier_list typedef_type_specifier
    15781589                { $$ = $2->addQualifiers( $1 ); }
    1579         | type_declaration_specifier storage_class                      // remaining OBSOLESCENT (see 2)
    1580                 { $$ = $1->addQualifiers( $2 ); }
    1581         | type_declaration_specifier storage_class type_qualifier_list
     1590        | typedef_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
     1591                { $$ = $1->addQualifiers( $2 ); }
     1592        | typedef_declaration_specifier storage_class type_qualifier_list
    15821593                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
    15831594        ;
    15841595
    1585 type_type_specifier:                                                                    // typedef types
    1586         type_name
    1587         | type_qualifier_list type_name
    1588                 { $$ = $2->addQualifiers( $1 ); }
    1589         | type_type_specifier type_qualifier
    1590                 { $$ = $1->addQualifiers( $2 ); }
    1591         ;
    1592 
    1593 type_name:
     1596typedef_type_specifier:                                                                 // typedef types
    15941597        TYPEDEFname
    15951598                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    1596         | '.' TYPEDEFname
    1597                 { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
    1598         | type_name '.' TYPEDEFname
    1599                 { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
    1600         | typegen_name
    1601         | '.' typegen_name
    1602                 { $$ = $2; }                                                                    // FIX ME
    1603         | type_name '.' typegen_name
    1604                 { $$ = $3; }                                                                    // FIX ME
    1605         ;
    1606 
    1607 typegen_name:                                                                                   // CFA
    1608         TYPEGENname '(' ')'
    1609                 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
    1610         | TYPEGENname '(' type_list ')'
    1611                 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
     1599        | type_qualifier_list TYPEDEFname
     1600                { $$ = DeclarationNode::newFromTypedef( $2 )->addQualifiers( $1 ); }
     1601        | typedef_type_specifier type_qualifier
     1602                { $$ = $1->addQualifiers( $2 ); }
    16121603        ;
    16131604
     
    16331624          '{' field_declaration_list '}'
    16341625                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1635         | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
     1626        | aggregate_key attribute_list_opt '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    16361627                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    16371628        | aggregate_type_nobody
     
    16391630
    16401631aggregate_type_nobody:                                                                  // struct, union - {...}
    1641         aggregate_key attribute_list_opt no_attr_identifier
     1632        aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    16421633                {
    16431634                        typedefTable.makeTypedef( *$3 );
    16441635                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    16451636                }
    1646         | aggregate_key attribute_list_opt TYPEDEFname
    1647                 {
    1648                         typedefTable.makeTypedef( *$3 );
    1649                         $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    1650                 }
    1651         | aggregate_key attribute_list_opt typegen_name         // CFA
     1637        | aggregate_key attribute_list_opt typegen_name         // CFA, S/R conflict
    16521638                { $$ = $3->addQualifiers( $2 ); }
    16531639        ;
     
    18871873        ;
    18881874
     1875no_01_identifier_or_type_name:
     1876        no_01_identifier
     1877        | TYPEDEFname
     1878        | TYPEGENname
     1879        ;
     1880
    18891881no_attr_identifier_or_type_name:
    18901882        no_attr_identifier
     
    18931885        ;
    18941886
    1895 type_no_function:                                                                               // sizeof, alignof, cast (constructor)
     1887type_name_no_function:                                                                  // sizeof, alignof, cast (constructor)
    18961888        cfa_abstract_declarator_tuple                                           // CFA
    18971889        | type_specifier
     
    19001892        ;
    19011893
    1902 type:                                                                                                   // typeof, assertion
    1903         type_no_function
     1894type_name:                                                                                              // typeof, assertion
     1895        type_name_no_function
    19041896        | cfa_abstract_function                                                         // CFA
    19051897        ;
     
    19411933designation:
    19421934        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    1943         | no_attr_identifier ':'                                                        // GCC, field name
     1935        | no_attr_identifier_or_type_name ':'                           // GCC, field name
    19441936                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    19451937        ;
     
    19531945
    19541946designator:
    1955         '.' no_attr_identifier                                                          // C99, field name
     1947        '.' no_attr_identifier_or_type_name                                     // C99, field name
    19561948                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    19571949        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    19841976//     on type arguments of polymorphic functions.
    19851977
     1978typegen_declaration_specifier:                                                  // CFA
     1979        typegen_type_specifier
     1980        | declaration_qualifier_list typegen_type_specifier
     1981                { $$ = $2->addQualifiers( $1 ); }
     1982        | typegen_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
     1983                { $$ = $1->addQualifiers( $2 ); }
     1984        | typegen_declaration_specifier storage_class type_qualifier_list
     1985                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
     1986        ;
     1987
     1988typegen_type_specifier:                                                                 // CFA
     1989        typegen_name
     1990        | type_qualifier_list typegen_name
     1991                { $$ = $2->addQualifiers( $1 ); }
     1992        | typegen_type_specifier type_qualifier
     1993                { $$ = $1->addQualifiers( $2 ); }
     1994        ;
     1995
     1996typegen_name:                                                                                   // CFA
     1997        TYPEGENname '(' type_name_list ')'
     1998                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
     1999        ;
     2000
    19862001type_parameter_list:                                                                    // CFA
    1987         type_parameter
    1988                 { $$ = $1; }
    1989         | type_parameter_list ',' type_parameter
     2002        type_parameter assignment_opt
     2003        | type_parameter_list ',' type_parameter assignment_opt
    19902004                { $$ = $1->appendList( $3 ); }
    1991         ;
    1992 
    1993 type_initializer_opt:                                                                   // CFA
    1994         // empty
    1995                 { $$ = nullptr; }
    1996         | '=' type
    1997                 { $$ = $2; }
    19982005        ;
    19992006
     
    20012008        type_class no_attr_identifier_or_type_name
    20022009                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
    2003           type_initializer_opt assertion_list_opt
    2004                 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     2010          assertion_list_opt
     2011                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); }
    20052012        | type_specifier identifier_parameter_declarator
    20062013        ;
     
    20252032
    20262033assertion:                                                                                              // CFA
    2027         '|' no_attr_identifier_or_type_name '(' type_list ')'
     2034        '|' no_attr_identifier_or_type_name '(' type_name_list ')'
    20282035                {
    20292036                        typedefTable.openTrait( *$2 );
     
    20322039        | '|' '{' push trait_declaration_list '}'
    20332040                { $$ = $4; }
    2034         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
     2041        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_name_list ')'
    20352042                { $$ = nullptr; }
    20362043        ;
    20372044
    2038 type_list:                                                                                              // CFA
    2039         type
     2045type_name_list:                                                                                 // CFA
     2046        type_name
    20402047                { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
    20412048        | assignment_expression
    2042         | type_list ',' type
     2049        | type_name_list ',' type_name
    20432050                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
    2044         | type_list ',' assignment_expression
     2051        | type_name_list ',' assignment_expression
    20452052                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    20462053        ;
     
    20582065        type_declarator_name assertion_list_opt
    20592066                { $$ = $1->addAssertions( $2 ); }
    2060         | type_declarator_name assertion_list_opt '=' type
     2067        | type_declarator_name assertion_list_opt '=' type_name
    20612068                { $$ = $1->addAssertions( $2 )->addType( $4 ); }
    20622069        ;
     
    20682075                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    20692076                }
    2070         | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
     2077        | no_01_identifier_or_type_name '(' push type_parameter_list pop ')'
    20712078                {
    20722079                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
     
    20942101        ;
    20952102
    2096 trait_declaration_list:                                                                 // CFA
     2103trait_declaration_list:                                                         // CFA
    20972104        trait_declaration
    20982105        | trait_declaration_list push trait_declaration
     
    21002107        ;
    21012108
    2102 trait_declaration:                                                                              // CFA
     2109trait_declaration:                                                                      // CFA
    21032110        cfa_trait_declaring_list pop ';'
    21042111        | trait_declaring_list pop ';'
Note: See TracChangeset for help on using the changeset viewer.