Ignore:
Timestamp:
Jul 19, 2018, 10:30:56 AM (6 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, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
679a260
Parents:
2f84692
Message:

extend plan 9, anonymous declarations, change token for default argument

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r2f84692 r679e644  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 12 16:16:25 2018
    13 // Update Count     : 3756
     12// Last Modified On : Thu Jul 19 10:21:43 2018
     13// Update Count     : 3808
    1414//
    1515
     
    338338%type<decl> exception_declaration
    339339
    340 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
    341 %type<en> field field_list field_name fraction_constants_opt
     340%type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list field_abstract_opt
     341%type<en> field field_name_list field_name fraction_constants_opt
    342342
    343343%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    352352%type<decl> cfa_array_parameter_1st_dimension
    353353
    354 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
     354%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
    355355%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
    356356
     
    492492        ;
    493493
    494 identifier:
    495         IDENTIFIER
    496         | ATTR_IDENTIFIER                                                                       // CFA
    497         | quasi_keyword
    498         ;
    499 
    500494no_attr_identifier:
    501495        IDENTIFIER
    502496        | quasi_keyword
     497        | '@'                                                                                           // CFA
     498                { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
     499        ;
     500
     501identifier:
     502        no_attr_identifier
     503        | ATTR_IDENTIFIER                                                                       // CFA
    503504        ;
    504505
     
    541542        | type_name '.' no_attr_identifier                                      // CFA, nested type
    542543                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    543         | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
     544        | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
    544545                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    545546        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
     
    594595        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    595596                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    596         | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
     597        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
    597598                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    598599        | postfix_expression ARROW no_attr_identifier
     
    602603        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    603604                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    604         | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
     605        | postfix_expression ARROW '[' field_name_list ']'      // CFA, tuple field selector
    605606                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    606607        | postfix_expression ICR
     
    629630        // empty
    630631                { $$ = nullptr; }
    631         // | '@'                                                                                                // use default argument
    632         //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     632        | '?'                                                                                           // CFA, default parameter
     633                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
     634                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    633635        | assignment_expression
    634636        ;
    635637
    636 field_list:                                                                                             // CFA, tuple field selector
     638field_name_list:                                                                                // CFA, tuple field selector
    637639        field
    638         | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     640        | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    639641        ;
    640642
     
    643645        | FLOATING_DECIMALconstant field
    644646                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    645         | FLOATING_DECIMALconstant '[' field_list ']'
     647        | FLOATING_DECIMALconstant '[' field_name_list ']'
    646648                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    647649        | field_name '.' field
    648650                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    649         | field_name '.' '[' field_list ']'
     651        | field_name '.' '[' field_name_list ']'
    650652                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    651653        | field_name ARROW field
    652654                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    653         | field_name ARROW '[' field_list ']'
     655        | field_name ARROW '[' field_name_list ']'
    654656                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    655657        ;
     
    19321934
    19331935field_declaration:
    1934         type_specifier field_declaring_list ';'
    1935                 { $$ = distAttr( $1, $2 ); }
    1936         | EXTENSION type_specifier field_declaring_list ';'     // GCC
    1937                 { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
    1938         | INLINE type_specifier field_declaring_list ';'        // CFA
    1939                 {
    1940                         if ( $2->type && ( $2->type->kind == TypeData::Aggregate || $2->type->kind == TypeData::AggregateInst ) ) {
    1941                                 if ( $2->type->kind == TypeData::Aggregate ) {
    1942                                         $2->type->aggregate.inLine = true;
    1943                                 } else {
    1944                                         $2->type->aggInst.inLine = true;
    1945                                 } // if
    1946                                 $$ = distAttr( $2, $3 );
     1936        type_specifier field_declaring_list_opt ';'
     1937                {
     1938                        if ( $2 ) {                                                                     // field declarator ?
     1939                                $$ = distAttr( $1, $2 );
     1940                        } else if ( $1->type && $1->type->kind == TypeData::Aggregate && $1->type->aggregate.anon ) {
     1941                                $$ = DeclarationNode::newName( nullptr );
     1942                                $$ = distAttr( $1, $$ );                                // mark all fields in list
    19471943                        } else {
    1948                                 SemanticError( yylloc, "inline qualifier only allowed for aggregate field declarations." ); $$ = nullptr;
    1949                         } // if
     1944                                //SemanticError( yylloc, "Superfluous declaration, does not allocate storage." ); $$ = nullptr;
     1945                                SemanticWarning( yylloc, Warning::SuperfluousDecl, "" );
     1946                        } // if
     1947                }
     1948        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
     1949                {
     1950                        if ( $3 ) {                                                                     // field declarator ?
     1951                                $$ = distAttr( $2, $3 );                                // mark all fields in list
     1952                                distExt( $3 );
     1953                        } else if ( $2->type && $2->type->kind == TypeData::Aggregate && $2->type->aggregate.anon ) {
     1954                                $$ = DeclarationNode::newName( nullptr );
     1955                                $$ = distAttr( $2, $$ );                                // mark all fields in list
     1956                                distExt( $$ );
     1957                        } else {
     1958                                // SemanticError( yylloc, "Superfluous declaration, does not allocate storage." ); $$ = nullptr;
     1959                                SemanticWarning( yylloc, Warning::SuperfluousDecl, "" );
     1960                        } // if
     1961                }
     1962        | INLINE type_specifier field_abstract_list ';'         // CFA
     1963                {
     1964                        $2->inLine = true;
     1965                        $$ = distAttr( $2, $3 );                                        // mark all fields in list
    19501966                }
    19511967        | typedef_declaration ';'                                                       // CFA
     
    19531969        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    19541970                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
     1971        | INLINE cfa_field_abstract_list ';'                            // CFA, new style field declaration
     1972                { $$ = $2; }                                                                    // mark all fields in list
    19551973        | cfa_typedef_declaration ';'                                           // CFA
    19561974        | static_assert                                                                         // C11
    19571975        ;
    19581976
     1977field_declaring_list_opt:
     1978        // empty
     1979                { $$ = nullptr; }
     1980        | field_declarator
     1981        | field_declaring_list_opt ',' attribute_list_opt field_declarator
     1982                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     1983        ;
     1984
     1985field_declarator:
     1986        bit_subrange_size                                                                       // no field name
     1987                { $$ = DeclarationNode::newBitfield( $1 ); }
     1988        | variable_declarator bit_subrange_size_opt
     1989                // A semantic check is required to ensure bit_subrange only appears on integral types.
     1990                { $$ = $1->addBitfield( $2 ); }
     1991        | variable_type_redeclarator bit_subrange_size_opt
     1992                // A semantic check is required to ensure bit_subrange only appears on integral types.
     1993                { $$ = $1->addBitfield( $2 ); }
     1994        ;
     1995
     1996field_abstract_list:
     1997        field_abstract_opt
     1998        | field_abstract_list ',' attribute_list_opt field_abstract_opt
     1999                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     2000        ;
     2001
     2002field_abstract_opt:
     2003        // empty
     2004                { $$ = DeclarationNode::newName( nullptr ); }
     2005        | bit_subrange_size                                                                     // no field name
     2006                // A semantic check is required to ensure bit_subrange only appears on integral types.
     2007                { $$ = DeclarationNode::newBitfield( $1 ); }
     2008        | variable_abstract_declarator
     2009        ;
     2010
    19592011cfa_field_declaring_list:                                                               // CFA, new style field declaration
    1960         cfa_abstract_declarator_tuple                                           // CFA, no field name
    1961         | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
     2012        cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
    19622013                { $$ = $1->addName( $2 ); }
    19632014        | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
    19642015                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    1965         | cfa_field_declaring_list ','                                          // CFA, no field name
     2016        ;
     2017
     2018cfa_field_abstract_list:                                                                // CFA, new style field declaration
     2019        cfa_abstract_declarator_tuple
     2020        | cfa_field_abstract_list ','
    19662021                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
    1967         ;
    1968 
    1969 field_declaring_list:
    1970         field_declarator_opt
    1971         | field_declaring_list ',' attribute_list_opt field_declarator_opt
    1972                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    1973         ;
    1974 
    1975 field_declarator_opt:
    1976         // empty
    1977                 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
    1978         // '@'
    1979         //      { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name
    1980         | bit_subrange_size                                                                     // no field name
    1981                 { $$ = DeclarationNode::newBitfield( $1 ); }
    1982         | variable_declarator bit_subrange_size_opt
    1983                 // A semantic check is required to ensure bit_subrange only appears on base type int.
    1984                 { $$ = $1->addBitfield( $2 ); }
    1985         | variable_type_redeclarator bit_subrange_size_opt
    1986                 // A semantic check is required to ensure bit_subrange only appears on base type int.
    1987                 { $$ = $1->addBitfield( $2 ); }
    1988         | variable_abstract_declarator                                          // CFA, no field name
    19892022        ;
    19902023
     
    22262259        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    22272260                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    2228         | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
     2261        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    22292262                { $$ = $4; }
    22302263        ;
Note: See TracChangeset for help on using the changeset viewer.