Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rd8454b9 r86b8d16  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 14 09:16:22 2022
    13 // Update Count     : 5401
     12// Last Modified On : Wed May  4 17:22:48 2022
     13// Update Count     : 5279
    1414//
    1515
     
    5454#include "Common/SemanticError.h"                                               // error_str
    5555#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
    56 
    57 #include "SynTree/Attribute.h"     // for Attribute
    5856
    5957extern DeclarationNode * parseTree;
     
    9593} // appendStr
    9694
    97 DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
    98         // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
    99         assert( declList );
    100 //      printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
    101         DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec );
    102 //      printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
    103 //      cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
    104 
     95DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) {
     96        // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
     97        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
    10598        for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    10699                cl->cloneBaseType( cur );
    107100        } // for
    108101        declList->addType( cl );
    109 //      printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
    110102        return declList;
    111103} // distAttr
     
    179171                if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) {
    180172                        stringstream ss;
    181                         // printf( "fieldDecl1 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
     173                        typeSpec->type->print( ss );
    182174                        SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
    183175                        return nullptr;
    184176                } // if
    185                 // printf( "fieldDecl2 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
    186177                fieldList = DeclarationNode::newName( nullptr );
    187178        } // if
    188 //      return distAttr( typeSpec, fieldList );                         // mark all fields in list
    189 
    190         // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
    191         DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
    192         // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
    193         return temp;
     179        return distAttr( typeSpec, fieldList );                         // mark all fields in list
    194180} // fieldDecl
    195181
     
    16341620declaration:                                                                                    // old & new style declarations
    16351621        c_declaration ';'
    1636                 {
    1637                         // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
    1638                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    1639                         //   printf( "\tattr %s\n", attr->name.c_str() );
    1640                         // } // for
    1641                 }
    16421622        | cfa_declaration ';'                                                           // CFA
    16431623        | static_assert                                                                         // C11
     
    18451825        basic_type_specifier
    18461826        | sue_type_specifier
    1847                 {
    1848                         // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    1849                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    1850                         //   printf( "\tattr %s\n", attr->name.c_str() );
    1851                         // } // for
    1852                 }
    18531827        | type_type_specifier
    18541828        ;
     
    20672041sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
    20682042        sue_type_specifier
    2069                 {
    2070                         // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2071                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2072                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2073                         // } // for
    2074                 }
    20752043        | declaration_qualifier_list sue_type_specifier
    20762044                { $$ = $2->addQualifiers( $1 ); }
     
    20832051sue_type_specifier:                                                                             // struct, union, enum + type specifier
    20842052        elaborated_type
    2085                 {
    2086                         // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2087                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2088                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2089                         // } // for
    2090                 }
    20912053        | type_qualifier_list
    20922054                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     
    21612123elaborated_type:                                                                                // struct, union, enum
    21622124        aggregate_type
    2163                 {
    2164                         // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2165                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2166                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2167                         // } // for
    2168                 }
    21692125        | enum_type
    21702126        ;
     
    21862142                }
    21872143          '{' field_declaration_list_opt '}' type_parameters_opt
    2188                 {
    2189                         // printf( "aggregate_type1 %s\n", $3.str->c_str() );
    2190                         // if ( $2 )
    2191                         //      for ( Attribute * attr: reverseIterate( $2->attributes ) ) {
    2192                         //              printf( "copySpecifiers12 %s\n", attr->name.c_str() );
    2193                         //      } // for
    2194                         $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
    2195                         // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2196                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2197                         //      printf( "aggregate_type3 %s\n", attr->name.c_str() );
    2198                         // } // for
    2199                 }
     2144                { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); }
    22002145        | aggregate_key attribute_list_opt TYPEDEFname          // unqualified type name
    22012146                {
     
    22052150          '{' field_declaration_list_opt '}' type_parameters_opt
    22062151                {
    2207                         // printf( "AGG3\n" );
    22082152                        DeclarationNode::newFromTypedef( $3 );
    22092153                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    22162160          '{' field_declaration_list_opt '}' type_parameters_opt
    22172161                {
    2218                         // printf( "AGG4\n" );
    22192162                        DeclarationNode::newFromTypeGen( $3, nullptr );
    22202163                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    22932236field_declaration:
    22942237        type_specifier field_declaring_list_opt ';'
    2295                 {
    2296                         // printf( "type_specifier1 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2297                         $$ = fieldDecl( $1, $2 );
    2298                         // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2299                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2300                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2301                         // } // for
    2302                 }
     2238                { $$ = fieldDecl( $1, $2 ); }
    23032239        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    23042240                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     
    29092845        // empty
    29102846                { $$ = nullptr; forall = false; }
    2911         | WITH '(' tuple_expression_list ')' attribute_list_opt
    2912                 {
    2913                         $$ = $3; forall = false;
    2914                         if ( $5 ) {
    2915                                 SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
    2916                                 $$ = nullptr;
    2917                         } // if
    2918                 }
     2847        | WITH '(' tuple_expression_list ')'
     2848                { $$ = $3; forall = false; }
    29192849        ;
    29202850
Note: See TracChangeset for help on using the changeset viewer.