Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rc4f68dc r26ef3b2  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 25 15:54:35 2018
    13 // Update Count     : 3841
     12// Last Modified On : Thu Jul 12 16:16:25 2018
     13// Update Count     : 3756
    1414//
    1515
     
    114114        } // for
    115115} // distExt
    116 
    117 void distInl( DeclarationNode * declaration ) {
    118         // distribute EXTENSION across all declarations
    119         for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    120                 iter->set_inLine( true );
    121         } // for
    122 } // distInl
    123116
    124117void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
     
    173166} // build_postfix_name
    174167
    175 DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) {
    176         if ( ! fieldList ) {                                                            // field declarator ?
    177                 if ( ! ( typeSpec->type && typeSpec->type->kind == TypeData::Aggregate ) ) {
    178                         stringstream ss;
    179                         typeSpec->type->print( ss );
    180                         SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
    181                         return nullptr;
    182                 } // if
    183                 fieldList = DeclarationNode::newName( nullptr );
    184         } // if
    185         return distAttr( typeSpec, fieldList );                         // mark all fields in list
    186 } // fieldDecl
    187 
    188168bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
    189169
     
    358338%type<decl> exception_declaration
    359339
    360 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract
    361 %type<en> field field_name_list field_name fraction_constants_opt
     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
    362342
    363343%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    372352%type<decl> cfa_array_parameter_1st_dimension
    373353
    374 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list
     354%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
    375355%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
    376356
     
    512492        ;
    513493
     494identifier:
     495        IDENTIFIER
     496        | ATTR_IDENTIFIER                                                                       // CFA
     497        | quasi_keyword
     498        ;
     499
    514500no_attr_identifier:
    515501        IDENTIFIER
    516502        | quasi_keyword
    517         | '@'                                                                                           // CFA
    518                 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
    519         ;
    520 
    521 identifier:
    522         no_attr_identifier
    523         | ATTR_IDENTIFIER                                                                       // CFA
    524503        ;
    525504
     
    562541        | type_name '.' no_attr_identifier                                      // CFA, nested type
    563542                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    564         | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
     543        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    565544                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    566545        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
     
    615594        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    616595                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    617         | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
     596        | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
    618597                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    619598        | postfix_expression ARROW no_attr_identifier
     
    623602        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    624603                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    625         | postfix_expression ARROW '[' field_name_list ']'      // CFA, tuple field selector
     604        | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
    626605                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    627606        | postfix_expression ICR
     
    650629        // empty
    651630                { $$ = nullptr; }
    652         | '?'                                                                                           // CFA, default parameter
    653                 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    654                 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     631        // | '@'                                                                                                // use default argument
     632        //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    655633        | assignment_expression
    656634        ;
    657635
    658 field_name_list:                                                                                // CFA, tuple field selector
     636field_list:                                                                                             // CFA, tuple field selector
    659637        field
    660         | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     638        | field_list ',' field                                          { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    661639        ;
    662640
     
    665643        | FLOATING_DECIMALconstant field
    666644                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    667         | FLOATING_DECIMALconstant '[' field_name_list ']'
     645        | FLOATING_DECIMALconstant '[' field_list ']'
    668646                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    669647        | field_name '.' field
    670648                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    671         | field_name '.' '[' field_name_list ']'
     649        | field_name '.' '[' field_list ']'
    672650                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    673651        | field_name ARROW field
    674652                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    675         | field_name ARROW '[' field_name_list ']'
     653        | field_name ARROW '[' field_list ']'
    676654                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    677655        ;
     
    19541932
    19551933field_declaration:
    1956         type_specifier field_declaring_list_opt ';'
    1957                 { $$ = fieldDecl( $1, $2 ); }
    1958         | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    1959                 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
    1960         | INLINE type_specifier field_abstract_list_opt ';'     // CFA
    1961                 {
    1962                         if ( ! $3 ) {                                                           // field declarator ?
    1963                                 $3 = DeclarationNode::newName( nullptr );
    1964                         } // if
    1965                         $3->inLine = true;
    1966                         $$ = distAttr( $2, $3 );                                        // mark all fields in list
    1967                         distInl( $3 );
     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 );
     1947                        } else {
     1948                                SemanticError( yylloc, "inline qualifier only allowed for aggregate field declarations." ); $$ = nullptr;
     1949                        } // if
    19681950                }
    19691951        | typedef_declaration ';'                                                       // CFA
     
    19711953        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    19721954                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
    1973         | INLINE cfa_field_abstract_list ';'                            // CFA, new style field declaration
    1974                 { $$ = $2; }                                                                    // mark all fields in list
    19751955        | cfa_typedef_declaration ';'                                           // CFA
    19761956        | static_assert                                                                         // C11
    19771957        ;
    19781958
    1979 field_declaring_list_opt:
    1980         // empty
    1981                 { $$ = nullptr; }
    1982         | field_declarator
    1983         | field_declaring_list_opt ',' attribute_list_opt field_declarator
    1984                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    1985         ;
    1986 
    1987 field_declarator:
    1988         bit_subrange_size                                                                       // C special case, no field name
    1989                 { $$ = DeclarationNode::newBitfield( $1 ); }
    1990         | variable_declarator bit_subrange_size_opt
    1991                 // A semantic check is required to ensure bit_subrange only appears on integral types.
    1992                 { $$ = $1->addBitfield( $2 ); }
    1993         | variable_type_redeclarator bit_subrange_size_opt
    1994                 // A semantic check is required to ensure bit_subrange only appears on integral types.
    1995                 { $$ = $1->addBitfield( $2 ); }
    1996         ;
    1997 
    1998 field_abstract_list_opt:
    1999         // empty
    2000                 { $$ = nullptr; }
    2001         | field_abstract
    2002         | field_abstract_list_opt ',' attribute_list_opt field_abstract
    2003                 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    2004         ;
    2005 
    2006 field_abstract:
    2007                 //      no bit fields
    2008         variable_abstract_declarator
    2009         ;
    2010 
    20111959cfa_field_declaring_list:                                                               // CFA, new style field declaration
    2012         // bit-fields are handled by C declarations
    2013         cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
     1960        cfa_abstract_declarator_tuple                                           // CFA, no field name
     1961        | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
    20141962                { $$ = $1->addName( $2 ); }
    20151963        | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
    20161964                { $$ = $1->appendList( $1->cloneType( $3 ) ); }
    2017         ;
    2018 
    2019 cfa_field_abstract_list:                                                                // CFA, new style field declaration
    2020         // bit-fields are handled by C declarations
    2021         cfa_abstract_declarator_tuple
    2022         | cfa_field_abstract_list ','
     1965        | cfa_field_declaring_list ','                                          // CFA, no field name
    20231966                { $$ = $1->appendList( $1->cloneType( 0 ) ); }
     1967        ;
     1968
     1969field_declaring_list:
     1970        field_declarator_opt
     1971        | field_declaring_list ',' attribute_list_opt field_declarator_opt
     1972                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
     1973        ;
     1974
     1975field_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
    20241989        ;
    20251990
     
    22612226        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    22622227                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    2263         | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
     2228        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    22642229                { $$ = $4; }
    22652230        ;
     
    23422307                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    23432308        | assignment_expression
    2344                 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    23452309        | type_list ',' type
    23462310                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    23472311        | type_list ',' assignment_expression
    2348                 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
    2349                 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     2312                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    23502313        ;
    23512314
     
    28042767        typedef
    28052768                // hide type name in enclosing scope by variable name
    2806                 {
    2807                         // if ( ! typedefTable.existsCurr( *$1->name ) ) {
    2808                                 typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" );
    2809                         // } else {
    2810                         //      SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr;
    2811                         // } // if
    2812                 }
     2769                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); }
    28132770        | '(' paren_type ')'
    28142771                { $$ = $2; }
     
    28212778                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
    28222779        | '(' type_ptr ')' attribute_list_opt
    2823                 { $$ = $2->addQualifiers( $4 ); }                               // redundant parenthesis
     2780                { $$ = $2->addQualifiers( $4 ); }
    28242781        ;
    28252782
Note: See TracChangeset for help on using the changeset viewer.