Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r3d56d15b ra1c9ddd  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 22 13:59:11 2018
    13 // Update Count     : 3586
     12// Last Modified On : Thu Jun  7 10:07:12 2018
     13// Update Count     : 3527
    1414//
    1515
     
    136136} // build_postfix_name
    137137
    138 bool forall = false, xxx = false, yyy = false;                  // aggregate have one or more forall qualifiers ?
     138bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
    139139
    140140// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    304304%type<en> enumerator_value_opt
    305305
    306 %type<decl> external_definition external_definition_list external_definition_list_opt
    307 
    308 %type<decl> exception_declaration
     306%type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
    309307
    310308%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    18231821        ;
    18241822
    1825 fred:
    1826         // empty
    1827                 { yyy = false; }
    1828         ;
    1829 
    18301823aggregate_type:                                                                                 // struct, union
    18311824        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18321825                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1833         | aggregate_key attribute_list_opt no_attr_identifier fred
     1826        | aggregate_key attribute_list_opt no_attr_identifier
    18341827                {
    18351828                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     
    18381831                }
    18391832          '{' field_declaration_list_opt '}'
    1840                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
    1841         | aggregate_key attribute_list_opt type_name fred
     1833                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
     1834        | aggregate_key attribute_list_opt type_name
    18421835                {
    18431836                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     
    18461839                }
    18471840          '{' field_declaration_list_opt '}'
    1848                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); }
     1841                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $6, true )->addQualifiers( $2 ); }
    18491842        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18501843                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     
    18531846
    18541847aggregate_type_nobody:                                                                  // struct, union - {...}
    1855         aggregate_key attribute_list_opt no_attr_identifier fred
     1848        aggregate_key attribute_list_opt no_attr_identifier
    18561849                {
    18571850                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
     
    18601853                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18611854                }
    1862         | aggregate_key attribute_list_opt type_name fred
     1855        | aggregate_key attribute_list_opt type_name
    18631856                {
    18641857                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18741867aggregate_key:
    18751868        STRUCT
    1876                 { yyy = true; $$ = DeclarationNode::Struct; }
     1869                { $$ = DeclarationNode::Struct; }
    18771870        | UNION
    1878                 { yyy = true; $$ = DeclarationNode::Union; }
     1871                { $$ = DeclarationNode::Union; }
    18791872        | EXCEPTION
    1880                 { yyy = true; $$ = DeclarationNode::Exception; }
     1873                { $$ = DeclarationNode::Exception; }
    18811874        | COROUTINE
    1882                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1875                { $$ = DeclarationNode::Coroutine; }
    18831876        | MONITOR
    1884                 { yyy = true; $$ = DeclarationNode::Monitor; }
     1877                { $$ = DeclarationNode::Monitor; }
    18851878        | THREAD
    1886                 { yyy = true; $$ = DeclarationNode::Thread; }
     1879                { $$ = DeclarationNode::Thread; }
    18871880        ;
    18881881
     
    23292322
    23302323translation_unit:
    2331         // empty, input file
     2324        // empty
     2325                {}                                                                                              // empty input file
    23322326        | external_definition_list
    23332327                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23432337        ;
    23442338
     2339        // SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope.
     2340        // However, external_definition_list creates a new scope around each external_definition, but the pop loses all the
     2341        // types in the extern "X" and distribution at the end of the block. This version of external_definition_list does
     2342
     2343        // not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of
     2344        // external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level.
     2345external_definition_list_no_pop_push:
     2346        external_definition
     2347        | external_definition_list_no_pop_push
     2348                { forall = xxx; }
     2349          external_definition
     2350                { $$ = $1 ? $1->appendList( $3 ) : $3; }
     2351        ;
     2352
    23452353external_definition_list_opt:
    23462354        // empty
    23472355                { $$ = nullptr; }
    2348         | external_definition_list
    2349         ;
    2350 
    2351 up:
    2352                 { typedefTable.up(); }
    2353         ;
    2354 
    2355 down:
    2356                 { typedefTable.down(); }
     2356        | external_definition_list_no_pop_push
    23572357        ;
    23582358
     
    23742374                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23752375                }
    2376           '{' up external_definition_list_opt down '}'
     2376          '{' external_definition_list_opt '}'
    23772377                {
    23782378                        linkage = linkageStack.top();
    23792379                        linkageStack.pop();
    2380                         $$ = $6;
     2380                        $$ = $5;
    23812381                }
    23822382        | type_qualifier_list
    2383                 {
    2384                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2385                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2386                 }
    2387           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2388                 {
    2389                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2383                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2384          '{' external_definition_list_opt '}'                          // CFA, namespace
     2385                {
     2386                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23902387                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23912388                                        iter->addQualifiers( $1->clone() );
     
    23942391                        xxx = false;
    23952392                        delete $1;
    2396                         $$ = $5;
     2393                        $$ = $4;
    23972394                }
    23982395        | declaration_qualifier_list
    2399                 {
    2400                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2401                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2402                 }
    2403           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2404                 {
    2405                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2396                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2397          '{' external_definition_list_opt '}'                          // CFA, namespace
     2398                {
     2399                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    24062400                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    24072401                                        iter->addQualifiers( $1->clone() );
     
    24102404                        xxx = false;
    24112405                        delete $1;
    2412                         $$ = $5;
     2406                        $$ = $4;
    24132407                }
    24142408        | declaration_qualifier_list type_qualifier_list
    24152409                {
    2416                         if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2417                         if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type
    2418                 }
    2419           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2420                 {
    2421                         for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2410                        // forall must be in the type_qualifier_list
     2411                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
     2412                }
     2413          '{' external_definition_list_opt '}'                          // CFA, namespace
     2414                {
     2415                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    24222416                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    24232417                                        iter->addQualifiers( $1->clone() );
     
    24282422                        delete $1;
    24292423                        delete $2;
    2430                         $$ = $6;
     2424                        $$ = $5;
    24312425                }
    24322426        ;
Note: See TracChangeset for help on using the changeset viewer.