Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r3fd8b0e r4c3ee8d  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 10:07:12 2018
    13 // Update Count     : 3527
     12// Last Modified On : Mon Jul  2 20:23:14 2018
     13// Update Count     : 3607
    1414//
    1515
     
    115115} // distExt
    116116
     117void 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
    117126// There is an ambiguity for inline generic-routine return-types and generic routines.
    118127//   forall( otype T ) struct S { int i; } bar( T ) {}
     
    136145} // build_postfix_name
    137146
    138 bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
     147bool forall = false, xxx = false, yyy = false;                  // aggregate have one or more forall qualifiers ?
    139148
    140149// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    304313%type<en> enumerator_value_opt
    305314
    306 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
     315%type<decl> external_definition external_definition_list external_definition_list_opt
     316
     317%type<decl> exception_declaration
    307318
    308319%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    503514                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    504515        | type_name '.' no_attr_identifier                                      // CFA, nested type
    505                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    506                 { $$ = nullptr; }
     516                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    507517        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    508                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    509                 { $$ = nullptr; }
     518                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    510519        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    511520                {
     
    11361145
    11371146waitfor:
    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                 }
     1147        WAITFOR '(' cast_expression ')'
     1148                { $$ = $3; }
     1149        | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1150                { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    11491151        ;
    11501152
     
    11631165                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    11641166                // "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; }
    11651169        | when_clause_opt timeout statement WOR when_clause ELSE statement
    11661170                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
     
    17921796                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17931797        | '.' TYPEDEFname
    1794                 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
     1798                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    17951799        | type_name '.' TYPEDEFname
    1796                 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
     1800                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    17971801        | typegen_name
    17981802        | '.' typegen_name
    1799                 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
     1803                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    18001804        | type_name '.' typegen_name
    1801                 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
     1805                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    18021806        ;
    18031807
     
    18211825        ;
    18221826
     1827fred:
     1828        // empty
     1829                { yyy = false; }
     1830        ;
     1831
    18231832aggregate_type:                                                                                 // struct, union
    18241833        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18251834                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1826         | aggregate_key attribute_list_opt no_attr_identifier
     1835        | aggregate_key attribute_list_opt no_attr_identifier fred
    18271836                {
    18281837                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1829                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18301838                        forall = false;                                                         // reset
    18311839                }
    18321840          '{' field_declaration_list_opt '}'
    1833                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1834         | aggregate_key attribute_list_opt type_name
     1841                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
     1842        | aggregate_key attribute_list_opt type_name fred
    18351843                {
    18361844                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1837                         //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
    18381845                        forall = false;                                                         // reset
    18391846                }
    18401847          '{' field_declaration_list_opt '}'
    1841                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $6, true )->addQualifiers( $2 ); }
     1848                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); }
    18421849        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18431850                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     
    18461853
    18471854aggregate_type_nobody:                                                                  // struct, union - {...}
    1848         aggregate_key attribute_list_opt no_attr_identifier
     1855        aggregate_key attribute_list_opt no_attr_identifier fred
    18491856                {
    18501857                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
    1851                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18521858                        forall = false;                                                         // reset
    18531859                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18541860                }
    1855         | aggregate_key attribute_list_opt type_name
     1861        | aggregate_key attribute_list_opt type_name fred
    18561862                {
    18571863                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18671873aggregate_key:
    18681874        STRUCT
    1869                 { $$ = DeclarationNode::Struct; }
     1875                { yyy = true; $$ = DeclarationNode::Struct; }
    18701876        | UNION
    1871                 { $$ = DeclarationNode::Union; }
     1877                { yyy = true; $$ = DeclarationNode::Union; }
    18721878        | EXCEPTION
    1873                 { $$ = DeclarationNode::Exception; }
     1879                { yyy = true; $$ = DeclarationNode::Exception; }
    18741880        | COROUTINE
    1875                 { $$ = DeclarationNode::Coroutine; }
     1881                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18761882        | MONITOR
    1877                 { $$ = DeclarationNode::Monitor; }
     1883                { yyy = true; $$ = DeclarationNode::Monitor; }
    18781884        | THREAD
    1879                 { $$ = DeclarationNode::Thread; }
     1885                { yyy = true; $$ = DeclarationNode::Thread; }
    18801886        ;
    18811887
     
    18931899                { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
    18941900        | typedef_declaration ';'                                                       // CFA
     1901                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    18951902        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    18961903        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    18971904                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
    18981905        | cfa_typedef_declaration ';'                                           // CFA
     1906                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
    18991907        | static_assert                                                                         // C11
    19001908        ;
     
    23202328
    23212329translation_unit:
    2322         // empty
    2323                 {}                                                                                              // empty input file
     2330        // empty, input file
    23242331        | external_definition_list
    23252332                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23352342        ;
    23362343
    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.
    2343 external_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 
    23512344external_definition_list_opt:
    23522345        // empty
    23532346                { $$ = nullptr; }
    2354         | external_definition_list_no_pop_push
     2347        | external_definition_list
     2348        ;
     2349
     2350up:
     2351                { typedefTable.up(); }
     2352        ;
     2353
     2354down:
     2355                { typedefTable.down(); }
    23552356        ;
    23562357
     
    23722373                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23732374                }
    2374           '{' external_definition_list_opt '}'
     2375          '{' up external_definition_list_opt down '}'
    23752376                {
    23762377                        linkage = linkageStack.top();
    23772378                        linkageStack.pop();
    2378                         $$ = $5;
     2379                        $$ = $6;
    23792380                }
    23802381        | type_qualifier_list
    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
     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 );
    23892389                        xxx = false;
    23902390                        delete $1;
    2391                         $$ = $4;
     2391                        $$ = $5;
    23922392                }
    23932393        | declaration_qualifier_list
    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
     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 );
    24022401                        xxx = false;
    24032402                        delete $1;
    2404                         $$ = $4;
     2403                        $$ = $5;
    24052404                }
    24062405        | declaration_qualifier_list type_qualifier_list
    24072406                {
    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
     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 );
    24192414                        xxx = false;
    24202415                        delete $1;
    24212416                        delete $2;
    2422                         $$ = $5;
     2417                        $$ = $6;
    24232418                }
    24242419        ;
Note: See TracChangeset for help on using the changeset viewer.