Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r4eb3a7c5 r0522ebe  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 23 18:25:46 2024
    13 // Update Count     : 6484
     12// Last Modified On : Sun Nov 26 13:18:06 2023
     13// Update Count     : 6398
    1414//
    1515
     
    102102
    103103DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
    104         // Distribute type specifier across all declared variables, e.g., static, const, __attribute__.
     104        // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
    105105        assert( declList );
    106 
    107         // Do not distribute attributes for aggregates because the attributes surrounding the aggregate belong it not the
    108         // variables in the declaration list, e.g.,
    109         //
    110         //   struct __attribute__(( aligned(128) )) S { ...
    111         //   } v1 __attribute__(( aligned(64) )), v2 __attribute__(( aligned(32) )), v3;
    112         //   struct S v4;
    113         //
    114         // v1 => 64, v2 =>32, v3 => 128, v2 => 128
    115         //
    116         // Anonymous aggregates are a special case because there is no aggregate to bind the attribute to; hence it floats
    117         // to the declaration list.
    118         //
    119         //   struct __attribute__(( aligned(128) )) /*anonymous */ { ... } v1;
    120         //
    121         // v1 => 128
    122 
    123         bool copyattr = ! (typeSpec->type && typeSpec->type->kind == TypeData::Aggregate && ! typeSpec->type->aggregate.anon );
    124 
    125         // addType copies the type information for the aggregate instances from typeSpec into cl's aggInst.aggregate.
    126         DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); // typeSpec IS DELETED!!!
    127 
    128         // Start at second variable in declaration list and clone the type specifiers for each variable..
     106        // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
     107        DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
     108        // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
     109        // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
     110
    129111        for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    130                 cl->cloneBaseType( cur, copyattr );                             // cur is modified
     112                cl->cloneBaseType( cur );
    131113        } // for
    132 
    133         // Add first variable in declaration list with hidden type information in aggInst.aggregate, which is used by
    134         // extractType to recover the type for the aggregate instances.
    135         declList->addType( cl, copyattr );                                      // cl IS DELETED!!!
     114        declList->addType( cl );
     115        // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
    136116        return declList;
    137117} // distAttr
     
    212192                fieldList = DeclarationNode::newName( nullptr );
    213193        } // if
     194//      return distAttr( typeSpec, fieldList );                         // mark all fields in list
    214195
    215196        // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
    216         DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list
     197        DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
    217198        // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
    218199        return temp;
     
    780761        | string_literal '`' identifier                                         // CFA, postfix call
    781762                { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
    782 
    783                 // SKULLDUGGERY: The typedef table used for parsing does not store fields in structures. To parse a qualified
    784                 // name, it is assumed all name-tokens after the first are identifiers, regardless of how the lexer identifies
    785         // them. For example:
    786                 //   
    787                 //   struct S;
    788                 //   forall(T) struct T;
    789                 //   union U;
    790                 //   enum E { S, T, E };
    791                 //   struct Z { int S, T, Z, E, U; };
    792                 //   void fred () {
    793                 //       Z z;
    794                 //       z.S;  // lexer returns S is TYPEDEFname
    795                 //       z.T;  // lexer returns T is TYPEGENname
    796                 //       z.Z;  // lexer returns Z is TYPEDEFname
    797                 //       z.U;  // lexer returns U is TYPEDEFname
    798                 //       z.E;  // lexer returns E is TYPEDEFname
    799                 //   }
    800763        | postfix_expression '.' identifier
    801764                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
    802         | postfix_expression '.' TYPEDEFname                            // CFA, SKULLDUGGERY
    803                 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
    804         | postfix_expression '.' TYPEGENname                            // CFA, SKULLDUGGERY
    805                 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
    806 
    807765        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
    808766                { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); }
     
    18981856declaration_list:
    18991857        declaration
    1900         | declaration_list declaration          { $$ = $1->appendList( $2 ); }
     1858        | declaration_list declaration
     1859                { $$ = $1->appendList( $2 ); }
    19011860        ;
    19021861
     
    19311890declaration:                                                                                    // old & new style declarations
    19321891        c_declaration ';'
     1892                {
     1893                        // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
     1894                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1895                        //   printf( "\tattr %s\n", attr->name.c_str() );
     1896                        // } // for
     1897                }
    19331898        | cfa_declaration ';'                                                           // CFA
    19341899        | static_assert                                                                         // C11
     
    23832348sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
    23842349        sue_type_specifier
     2350                {
     2351                        // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2352                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2353                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2354                        // } // for
     2355                }
    23852356        | declaration_qualifier_list sue_type_specifier
    23862357                { $$ = $2->addQualifiers( $1 ); }
     
    23932364sue_type_specifier:                                                                             // struct, union, enum + type specifier
    23942365        elaborated_type
     2366                {
     2367                        // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2368                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2369                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2370                        // } // for
     2371                }
    23952372        | type_qualifier_list
    23962373                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     
    24652442elaborated_type:                                                                                // struct, union, enum
    24662443        aggregate_type
     2444                {
     2445                        // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2446                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2447                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2448                        // } // for
     2449                }
    24672450        | enum_type
    24682451        ;
     
    26962679                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    26972680        | ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
    2698                 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2681                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    26992682        | ENUM attribute_list_opt identifier
    27002683                { typedefTable.makeTypedef( *$3, "enum_type 1" ); }
     
    27112694                }
    27122695        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name
    2713                 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2696                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    27142697        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    27152698                {
     
    27172700                }
    27182701        | ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule
    2719                 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
     2702                { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
    27202703        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    27212704                {
     
    30233006        | assertion_list
    30243007                { $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
     3008        | ENUM '(' identifier_or_type_name ')' identifier_or_type_name new_type_class type_initializer_opt assertion_list_opt
     3009                {       
     3010                        typedefTable.addToScope( *$3, TYPEDIMname, "type_parameter 4" );
     3011                        typedefTable.addToScope( *$5, TYPEDIMname, "type_parameter 5" );
     3012                        $$ = DeclarationNode::newTypeParam( $6, $5 )->addTypeInitializer( $7 )->addAssertions( $8 );
     3013                }
    30253014        ;
    30263015
     
    31883177                        // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is
    31893178                        // disallowed at the moment.
    3190                         if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static &&
    3191                                  $1->type && $1->type->kind == TypeData::AggregateInst ) {
     3179                        if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {
    31923180                                if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) {
    31933181                                        SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr;
Note: See TracChangeset for help on using the changeset viewer.