Changeset 84d58c5 for src


Ignore:
Timestamp:
May 25, 2017, 3:32:42 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
7f612112
Parents:
a4943d8c
Message:

parse default values for generic type parameters and nested type names

Location:
src
Files:
5 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ra4943d8c r84d58c5  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 18 18:06:17 2017
    13 // Update Count     : 2338
     12// Last Modified On : Thu May 25 15:21:59 2017
     13// Update Count     : 2398
    1414//
    1515
     
    159159}
    160160
    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
     161%type<tok> identifier  no_attr_identifier zero_one
     162%type<tok> identifier_or_type_name  no_attr_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_name indirect_type_name
     209%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
    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> typedef typedef_type_specifier typedef_declaration typedef_declaration_specifier typedef_expression
     263%type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
     264%type<decl> typedef typedef_declaration typedef_expression
    264265
    265266%type<decl> variable_type_redeclarator type_ptr type_array type_function
    266267
    267268%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
    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
     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
    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 
    356 no_01_identifier:
    357         IDENTIFIER
    358         | ATTR_IDENTIFIER                                                                       // CFA
    359353        ;
    360354
    361355no_attr_identifier:
    362356        IDENTIFIER
    363         | zero_one                                                                                      // CFA
    364357        ;
    365358
     
    367360        ZERO
    368361        | ONE
    369         ;
     362        ;
    370363
    371364string_literal:
     
    395388        | '(' compound_statement ')'                                            // GCC, lambda expression
    396389                { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
    397         | primary_expression '{' argument_expression_list '}' // CFA
     390        | primary_expression '{' argument_expression_list '}' // CFA, constructor call
    398391                {
    399392                        Token fn;
     
    401394                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    402395                }
     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
    403400        ;
    404401
     
    431428        | postfix_expression DECR
    432429                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    433         | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
     430        | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    434431                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    435432        | '^' primary_expression '{' argument_expression_list '}' // CFA
     
    483480        | no_attr_identifier fraction_constants
    484481                {
    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                         }
     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 ) );
    490487                }
    491488        ;
     
    535532        | SIZEOF unary_expression
    536533                { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
    537         | SIZEOF '(' type_name_no_function ')'
     534        | SIZEOF '(' type_no_function ')'
    538535                { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
    539536        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    540537                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
    541         | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
     538        | ALIGNOF '(' type_no_function ')'                              // GCC, type alignment
    542539                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    543         | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')'
     540        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
    544541                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
    545542        | ATTR_IDENTIFIER
     
    547544        | ATTR_IDENTIFIER '(' argument_expression ')'
    548545                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
    549         | ATTR_IDENTIFIER '(' type_name ')'
     546        | ATTR_IDENTIFIER '(' type ')'
    550547                { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
    551548//      | ANDAND IDENTIFIER                                                                     // GCC, address of label
     
    569566cast_expression:
    570567        unary_expression
    571         | '(' type_name_no_function ')' cast_expression
     568        | '(' type_no_function ')' cast_expression
    572569                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    573 //      | '(' type_name_no_function ')' tuple
     570//      | '(' type_no_function ')' tuple
    574571//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    575572        ;
     
    658655        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    659656                { $$ = 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 ) ); }
    662657        ;
    663658
     
    671666        | unary_expression assignment_operator assignment_expression
    672667                { $$ = 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 ) ); }
    675668        ;
    676669
     
    13521345        basic_declaration_specifier
    13531346        | sue_declaration_specifier
    1354         | typedef_declaration_specifier
    1355         | typegen_declaration_specifier
     1347        | type_declaration_specifier
    13561348        ;
    13571349
     
    13641356        basic_declaration_specifier
    13651357        | sue_declaration_specifier_nobody
    1366         | typedef_declaration_specifier
    1367         | typegen_declaration_specifier
     1358        | type_declaration_specifier
    13681359        ;
    13691360
     
    13711362        basic_type_specifier
    13721363        | sue_type_specifier
    1373         | typedef_type_specifier
    1374         | typegen_type_specifier
     1364        | type_type_specifier
    13751365        ;
    13761366
     
    13831373        basic_type_specifier
    13841374        | sue_type_specifier_nobody
    1385         | typedef_type_specifier
    1386         | typegen_type_specifier
     1375        | type_type_specifier
    13871376        ;
    13881377
     
    15191508
    15201509basic_type_specifier:
    1521         direct_type_name
    1522         | type_qualifier_list_opt indirect_type_name type_qualifier_list_opt
     1510        direct_type
     1511        | type_qualifier_list_opt indirect_type type_qualifier_list_opt
    15231512                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
    15241513        ;
    15251514
    1526 direct_type_name:
     1515direct_type:
    15271516                // A semantic check is necessary for conflicting type qualifiers.
    15281517        basic_type_name
    15291518        | type_qualifier_list basic_type_name
    15301519                { $$ = $2->addQualifiers( $1 ); }
    1531         | direct_type_name type_qualifier
     1520        | direct_type type_qualifier
    15321521                { $$ = $1->addQualifiers( $2 ); }
    1533         | direct_type_name basic_type_name
     1522        | direct_type basic_type_name
    15341523                { $$ = $1->addType( $2 ); }
    15351524        ;
    15361525
    1537 indirect_type_name:
    1538         TYPEOF '(' type_name ')'                                                        // GCC: typeof(x) y;
     1526indirect_type:
     1527        TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
    15391528                { $$ = $3; }
    15401529        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
    15411530                { $$ = DeclarationNode::newTypeof( $3 ); }
    1542         | ATTR_TYPEGENname '(' type_name ')'                            // CFA: e.g., @type(x) y;
     1531        | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
    15431532                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    15441533        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     
    15841573        ;
    15851574
    1586 typedef_declaration_specifier:
    1587         typedef_type_specifier
    1588         | declaration_qualifier_list typedef_type_specifier
     1575type_declaration_specifier:
     1576        type_type_specifier
     1577        | declaration_qualifier_list type_type_specifier
    15891578                { $$ = $2->addQualifiers( $1 ); }
    1590         | typedef_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
     1579        | type_declaration_specifier storage_class                      // remaining OBSOLESCENT (see 2)
    15911580                { $$ = $1->addQualifiers( $2 ); }
    1592         | typedef_declaration_specifier storage_class type_qualifier_list
     1581        | type_declaration_specifier storage_class type_qualifier_list
    15931582                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
    15941583        ;
    15951584
    1596 typedef_type_specifier:                                                                 // typedef types
     1585type_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
     1593type_name:
    15971594        TYPEDEFname
    15981595                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    1599         | type_qualifier_list TYPEDEFname
    1600                 { $$ = DeclarationNode::newFromTypedef( $2 )->addQualifiers( $1 ); }
    1601         | typedef_type_specifier type_qualifier
    1602                 { $$ = $1->addQualifiers( $2 ); }
     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
     1607typegen_name:                                                                                   // CFA
     1608        TYPEGENname '(' type_list ')'
     1609                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    16031610        ;
    16041611
     
    16241631          '{' field_declaration_list '}'
    16251632                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1626         | aggregate_key attribute_list_opt '(' type_name_list ')' '{' field_declaration_list '}' // CFA
     1633        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
    16271634                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    16281635        | aggregate_type_nobody
     
    16301637
    16311638aggregate_type_nobody:                                                                  // struct, union - {...}
    1632         aggregate_key attribute_list_opt no_attr_identifier_or_type_name
     1639        aggregate_key attribute_list_opt no_attr_identifier
    16331640                {
    16341641                        typedefTable.makeTypedef( *$3 );
    16351642                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    16361643                }
    1637         | aggregate_key attribute_list_opt typegen_name         // CFA, S/R conflict
     1644        | aggregate_key attribute_list_opt TYPEDEFname
     1645                {
     1646                        typedefTable.makeTypedef( *$3 );
     1647                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     1648                }
     1649        | aggregate_key attribute_list_opt typegen_name         // CFA
    16381650                { $$ = $3->addQualifiers( $2 ); }
    16391651        ;
     
    18731885        ;
    18741886
    1875 no_01_identifier_or_type_name:
    1876         no_01_identifier
    1877         | TYPEDEFname
    1878         | TYPEGENname
    1879         ;
    1880 
    18811887no_attr_identifier_or_type_name:
    18821888        no_attr_identifier
     
    18851891        ;
    18861892
    1887 type_name_no_function:                                                                  // sizeof, alignof, cast (constructor)
     1893type_no_function:                                                                               // sizeof, alignof, cast (constructor)
    18881894        cfa_abstract_declarator_tuple                                           // CFA
    18891895        | type_specifier
     
    18921898        ;
    18931899
    1894 type_name:                                                                                              // typeof, assertion
    1895         type_name_no_function
     1900type:                                                                                                   // typeof, assertion
     1901        type_no_function
    18961902        | cfa_abstract_function                                                         // CFA
    18971903        ;
     
    19331939designation:
    19341940        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    1935         | no_attr_identifier_or_type_name ':'                           // GCC, field name
     1941        | no_attr_identifier ':'                                                        // GCC, field name
    19361942                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    19371943        ;
     
    19451951
    19461952designator:
    1947         '.' no_attr_identifier_or_type_name                                     // C99, field name
     1953        '.' no_attr_identifier                                                          // C99, field name
    19481954                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    19491955        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    19761982//     on type arguments of polymorphic functions.
    19771983
    1978 typegen_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 
    1988 typegen_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 
    1996 typegen_name:                                                                                   // CFA
    1997         TYPEGENname '(' type_name_list ')'
    1998                 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    1999         ;
    2000 
    20011984type_parameter_list:                                                                    // CFA
    2002         type_parameter assignment_opt
    2003         | type_parameter_list ',' type_parameter assignment_opt
     1985        type_parameter type_initializer_opt
     1986        | type_parameter_list ',' type_parameter type_initializer_opt
    20041987                { $$ = $1->appendList( $3 ); }
     1988        ;
     1989
     1990type_initializer_opt:                                                                   // CFA
     1991        // empty
     1992                { $$ = nullptr; }
     1993        | '=' type
     1994                { $$ = $2; }
    20051995        ;
    20061996
     
    20322022
    20332023assertion:                                                                                              // CFA
    2034         '|' no_attr_identifier_or_type_name '(' type_name_list ')'
     2024        '|' no_attr_identifier_or_type_name '(' type_list ')'
    20352025                {
    20362026                        typedefTable.openTrait( *$2 );
     
    20392029        | '|' '{' push trait_declaration_list '}'
    20402030                { $$ = $4; }
    2041         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_name_list ')'
     2031        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    20422032                { $$ = nullptr; }
    20432033        ;
    20442034
    2045 type_name_list:                                                                                 // CFA
    2046         type_name
     2035type_list:                                                                                              // CFA
     2036        type
    20472037                { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
    20482038        | assignment_expression
    2049         | type_name_list ',' type_name
     2039        | type_list ',' type
    20502040                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
    2051         | type_name_list ',' assignment_expression
     2041        | type_list ',' assignment_expression
    20522042                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    20532043        ;
     
    20652055        type_declarator_name assertion_list_opt
    20662056                { $$ = $1->addAssertions( $2 ); }
    2067         | type_declarator_name assertion_list_opt '=' type_name
     2057        | type_declarator_name assertion_list_opt '=' type
    20682058                { $$ = $1->addAssertions( $2 )->addType( $4 ); }
    20692059        ;
     
    20752065                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    20762066                }
    2077         | no_01_identifier_or_type_name '(' push type_parameter_list pop ')'
     2067        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    20782068                {
    20792069                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
     
    21012091        ;
    21022092
    2103 trait_declaration_list:                                                         // CFA
     2093trait_declaration_list:                                                                 // CFA
    21042094        trait_declaration
    21052095        | trait_declaration_list push trait_declaration
     
    21072097        ;
    21082098
    2109 trait_declaration:                                                                      // CFA
     2099trait_declaration:                                                                              // CFA
    21102100        cfa_trait_declaring_list pop ';'
    21112101        | trait_declaring_list pop ';'
Note: See TracChangeset for help on using the changeset viewer.