Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r203c667 r3fd8b0e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jun 24 10:41:10 2018
    13 // Update Count     : 3587
     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
     
    505503                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    506504        | type_name '.' no_attr_identifier                                      // CFA, nested type
    507                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     505                // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     506                { $$ = nullptr; }
    508507        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    509                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     508                // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     509                { $$ = nullptr; }
    510510        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    511511                {
     
    17921792                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17931793        | '.' TYPEDEFname
    1794                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1794                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
    17951795        | type_name '.' TYPEDEFname
    1796                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1796                { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
    17971797        | typegen_name
    17981798        | '.' typegen_name
    1799                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1799                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
    18001800        | type_name '.' typegen_name
    1801                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1801                { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
    18021802        ;
    18031803
     
    18211821        ;
    18221822
    1823 fred:
    1824         // empty
    1825                 { yyy = false; }
    1826         ;
    1827 
    18281823aggregate_type:                                                                                 // struct, union
    18291824        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18301825                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1831         | aggregate_key attribute_list_opt no_attr_identifier fred
     1826        | aggregate_key attribute_list_opt no_attr_identifier
    18321827                {
    18331828                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1829                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18341830                        forall = false;                                                         // reset
    18351831                }
    18361832          '{' field_declaration_list_opt '}'
    1837                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
    1838         | 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
    18391835                {
    18401836                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1837                        //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
    18411838                        forall = false;                                                         // reset
    18421839                }
    18431840          '{' field_declaration_list_opt '}'
    1844                 { $$ = 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 ); }
    18451842        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18461843                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     
    18491846
    18501847aggregate_type_nobody:                                                                  // struct, union - {...}
    1851         aggregate_key attribute_list_opt no_attr_identifier fred
     1848        aggregate_key attribute_list_opt no_attr_identifier
    18521849                {
    18531850                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
     1851                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18541852                        forall = false;                                                         // reset
    18551853                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18561854                }
    1857         | aggregate_key attribute_list_opt type_name fred
     1855        | aggregate_key attribute_list_opt type_name
    18581856                {
    18591857                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18691867aggregate_key:
    18701868        STRUCT
    1871                 { yyy = true; $$ = DeclarationNode::Struct; }
     1869                { $$ = DeclarationNode::Struct; }
    18721870        | UNION
    1873                 { yyy = true; $$ = DeclarationNode::Union; }
     1871                { $$ = DeclarationNode::Union; }
    18741872        | EXCEPTION
    1875                 { yyy = true; $$ = DeclarationNode::Exception; }
     1873                { $$ = DeclarationNode::Exception; }
    18761874        | COROUTINE
    1877                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     1875                { $$ = DeclarationNode::Coroutine; }
    18781876        | MONITOR
    1879                 { yyy = true; $$ = DeclarationNode::Monitor; }
     1877                { $$ = DeclarationNode::Monitor; }
    18801878        | THREAD
    1881                 { yyy = true; $$ = DeclarationNode::Thread; }
     1879                { $$ = DeclarationNode::Thread; }
    18821880        ;
    18831881
     
    18951893                { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
    18961894        | typedef_declaration ';'                                                       // CFA
    1897                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    18981895        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    18991896        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    19001897                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
    19011898        | cfa_typedef_declaration ';'                                           // CFA
    1902                 { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    19031899        | static_assert                                                                         // C11
    19041900        ;
     
    23242320
    23252321translation_unit:
    2326         // empty, input file
     2322        // empty
     2323                {}                                                                                              // empty input file
    23272324        | external_definition_list
    23282325                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23382335        ;
    23392336
     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
    23402351external_definition_list_opt:
    23412352        // empty
    23422353                { $$ = nullptr; }
    2343         | external_definition_list
    2344         ;
    2345 
    2346 up:
    2347                 { typedefTable.up(); }
    2348         ;
    2349 
    2350 down:
    2351                 { typedefTable.down(); }
     2354        | external_definition_list_no_pop_push
    23522355        ;
    23532356
     
    23692372                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23702373                }
    2371           '{' up external_definition_list_opt down '}'
     2374          '{' external_definition_list_opt '}'
    23722375                {
    23732376                        linkage = linkageStack.top();
    23742377                        linkageStack.pop();
    2375                         $$ = $6;
     2378                        $$ = $5;
    23762379                }
    23772380        | type_qualifier_list
    2378                 {
    2379                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2380                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2381                 }
    2382           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2383                 {
    2384                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     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() ) {
    23852385                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23862386                                        iter->addQualifiers( $1->clone() );
     
    23892389                        xxx = false;
    23902390                        delete $1;
    2391                         $$ = $5;
     2391                        $$ = $4;
    23922392                }
    23932393        | declaration_qualifier_list
    2394                 {
    2395                         if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2396                         if ( $1->type->forall ) xxx = forall = true; // remember generic type
    2397                 }
    2398           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2399                 {
    2400                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     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() ) {
    24012398                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    24022399                                        iter->addQualifiers( $1->clone() );
     
    24052402                        xxx = false;
    24062403                        delete $1;
    2407                         $$ = $5;
     2404                        $$ = $4;
    24082405                }
    24092406        | declaration_qualifier_list type_qualifier_list
    24102407                {
    2411                         if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
    2412                         if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type
    2413                 }
    2414           '{' up external_definition_list_opt down '}'          // CFA, namespace
    2415                 {
    2416                         for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     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() ) {
    24172414                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    24182415                                        iter->addQualifiers( $1->clone() );
     
    24232420                        delete $1;
    24242421                        delete $2;
    2425                         $$ = $6;
     2422                        $$ = $5;
    24262423                }
    24272424        ;
Note: See TracChangeset for help on using the changeset viewer.