Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r4c3ee8d r3fd8b0e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul  2 20:23:14 2018
    13 // Update Count     : 3607
     12// Last Modified On : Thu Jun  7 10:07:12 2018
     13// Update Count     : 3527
    1414//
    1515
     
    115115} // distExt
    116116
    117 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {
    118         // distribute qualifiers across all declarations in a distribution statemement
    119         for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    120                 if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    121                         iter->addQualifiers( qualifiers->clone() );
    122                 } // if
    123         } // for
    124 } // distExt
    125 
    126117// There is an ambiguity for inline generic-routine return-types and generic routines.
    127118//   forall( otype T ) struct S { int i; } bar( T ) {}
     
    145136} // build_postfix_name
    146137
    147 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 ?
    148139
    149140// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    313304%type<en> enumerator_value_opt
    314305
    315 %type<decl> external_definition external_definition_list external_definition_list_opt
    316 
    317 %type<decl> exception_declaration
     306%type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
    318307
    319308%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    514503                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    515504        | type_name '.' no_attr_identifier                                      // CFA, nested type
    516                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     505                // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     506                { $$ = nullptr; }
    517507        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    518                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     508                // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     509                { $$ = nullptr; }
    519510        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    520511                {
     
    11451136
    11461137waitfor:
    1147         WAITFOR '(' cast_expression ')'
    1148                 { $$ = $3; }
    1149         | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1150                 { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     1138        WAITFOR '(' identifier ')'
     1139                {
     1140                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
     1141                        delete $3;
     1142                }
     1143        | WAITFOR '(' identifier ',' argument_expression_list ')'
     1144                {
     1145                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
     1146                        $$->set_last( $5 );
     1147                        delete $3;
     1148                }
    11511149        ;
    11521150
     
    11651163                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    11661164                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1167         | when_clause_opt timeout statement WOR ELSE statement
    1168                 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    11691165        | when_clause_opt timeout statement WOR when_clause ELSE statement
    11701166                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
     
    17961792                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17971793        | '.' TYPEDEFname
    1798                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1794                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
    17991795        | type_name '.' TYPEDEFname
    1800                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1796                { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
    18011797        | typegen_name
    18021798        | '.' typegen_name
    1803                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1799                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
    18041800        | type_name '.' typegen_name
    1805                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1801                { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
    18061802        ;
    18071803
     
    18251821        ;
    18261822
    1827 fred:
    1828         // empty
    1829                 { yyy = false; }
    1830         ;
    1831 
    18321823aggregate_type:                                                                                 // struct, union
    18331824        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18341825                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1835         | aggregate_key attribute_list_opt no_attr_identifier fred
     1826        | aggregate_key attribute_list_opt no_attr_identifier
    18361827                {
    18371828                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1829                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18381830                        forall = false;                                                         // reset
    18391831                }
    18401832          '{' field_declaration_list_opt '}'
    1841                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
    1842         | 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
    18431835                {
    18441836                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1837                        //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
    18451838                        forall = false;                                                         // reset
    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 );
     1851                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18581852                        forall = false;                                                         // reset
    18591853                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18601854                }
    1861         | aggregate_key attribute_list_opt type_name fred
     1855        | aggregate_key attribute_list_opt type_name
    18621856                {
    18631857                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18731867aggregate_key:
    18741868        STRUCT
    1875                 { yyy = true; $$ = DeclarationNode::Struct; }
     1869                { $$ = DeclarationNode::Struct; }
    18761870        | UNION
    1877                 { yyy = true; $$ = DeclarationNode::Union; }
     1871                { $$ = DeclarationNode::Union; }
    18781872        | EXCEPTION
    1879                 { yyy = true; $$ = DeclarationNode::Exception; }
     1873                { $$ = DeclarationNode::Exception; }
    18801874        | COROUTINE
    1881                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1875                { $$ = DeclarationNode::Coroutine; }
    18821876        | MONITOR
    1883                 { yyy = true; $$ = DeclarationNode::Monitor; }
     1877                { $$ = DeclarationNode::Monitor; }
    18841878        | THREAD
    1885                 { yyy = true; $$ = DeclarationNode::Thread; }
     1879                { $$ = DeclarationNode::Thread; }
    18861880        ;
    18871881
     
    18991893                { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
    19001894        | typedef_declaration ';'                                                       // CFA
    1901                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    19021895        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    19031896        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    19041897                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
    19051898        | cfa_typedef_declaration ';'                                           // CFA
    1906                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    19071899        | static_assert                                                                         // C11
    19081900        ;
     
    23282320
    23292321translation_unit:
    2330         // empty, input file
     2322        // empty
     2323                {}                                                                                              // empty input file
    23312324        | external_definition_list
    23322325                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23422335        ;
    23432336
     2337        // SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope.
     2338        // However, external_definition_list creates a new scope around each external_definition, but the pop loses all the
     2339        // types in the extern "X" and distribution at the end of the block. This version of external_definition_list does
     2340
     2341        // not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of
     2342        // external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level.
     2343external_definition_list_no_pop_push:
     2344        external_definition
     2345        | external_definition_list_no_pop_push
     2346                { forall = xxx; }
     2347          external_definition
     2348                { $$ = $1 ? $1->appendList( $3 ) : $3; }
     2349        ;
     2350
    23442351external_definition_list_opt:
    23452352        // empty
    23462353                { $$ = nullptr; }
    2347         | external_definition_list
    2348         ;
    2349 
    2350 up:
    2351                 { typedefTable.up(); }
    2352         ;
    2353 
    2354 down:
    2355                 { typedefTable.down(); }
     2354        | external_definition_list_no_pop_push
    23562355        ;
    23572356
     
    23732372                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23742373                }
    2375           '{' up external_definition_list_opt down '}'
     2374          '{' external_definition_list_opt '}'
    23762375                {
    23772376                        linkage = linkageStack.top();
    23782377                        linkageStack.pop();
    2379                         $$ = $6;
     2378                        $$ = $5;
    23802379                }
    23812380        | type_qualifier_list
    2382                 {
    2383                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2384                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2385                 }
    2386           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2387                 {
    2388                         distQual( $5, $1 );
     2381                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2382          '{' external_definition_list_opt '}'                          // CFA, namespace
     2383                {
     2384                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2385                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
     2386                                        iter->addQualifiers( $1->clone() );
     2387                                } // if
     2388                        } // for
    23892389                        xxx = false;
    23902390                        delete $1;
    2391                         $$ = $5;
     2391                        $$ = $4;
    23922392                }
    23932393        | declaration_qualifier_list
    2394                 {
    2395                         if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2396                         if ( $1->type && $1->type->forall ) xxx = forall = true; // remember generic type
    2397                 }
    2398           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2399                 {
    2400                         distQual( $5, $1 );
     2394                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
     2395          '{' external_definition_list_opt '}'                          // CFA, namespace
     2396                {
     2397                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2398                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
     2399                                        iter->addQualifiers( $1->clone() );
     2400                                } // if
     2401                        } // for
    24012402                        xxx = false;
    24022403                        delete $1;
    2403                         $$ = $5;
     2404                        $$ = $4;
    24042405                }
    24052406        | declaration_qualifier_list type_qualifier_list
    24062407                {
    2407                         if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2408                         if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type
    2409                 }
    2410           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2411                 {
    2412                         distQual( $6, $2 );
    2413                         distQual( $6, $1 );
     2408                        // forall must be in the type_qualifier_list
     2409                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
     2410                }
     2411          '{' external_definition_list_opt '}'                          // CFA, namespace
     2412                {
     2413                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2414                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
     2415                                        iter->addQualifiers( $1->clone() );
     2416                                        iter->addQualifiers( $2->clone() );
     2417                                } // if
     2418                        } // for
    24142419                        xxx = false;
    24152420                        delete $1;
    24162421                        delete $2;
    2417                         $$ = $6;
     2422                        $$ = $5;
    24182423                }
    24192424        ;
Note: See TracChangeset for help on using the changeset viewer.