Changeset 3d56d15b for src


Ignore:
Timestamp:
Jun 22, 2018, 2:58:30 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
203c667, 63238a4
Parents:
6d43cc57
git-author:
Peter A. Buhr <pabuhr@…> (06/22/18 13:56:53)
git-committer:
Peter A. Buhr <pabuhr@…> (06/22/18 14:58:30)
Message:

add push/pop up/down, semantic check for CV in distribution, initial check for structure names

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypedefTable.cc

    r6d43cc57 r3d56d15b  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 13:17:56 2018
    13 // Update Count     : 192
     12// Last Modified On : Fri Jun 22 06:14:39 2018
     13// Update Count     : 206
    1414//
    1515
     
    7878        debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
    7979        auto ret = kindTable.insertAt( scope, identifier, kind );
    80         if ( ! ret.second ) ret.first->second = kind;           // exists => update
     80        //if ( ! ret.second ) ret.first->second = kind;         // exists => update
     81        assert( ret.first->second == kind );                            // exists
    8182} // TypedefTable::addToScope
    8283
    8384void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) {
    84         assert( kindTable.currentScope() >= 1 );
    85         auto scope = kindTable.currentScope() - 1;
    86         debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
     85        assert( kindTable.currentScope() >= 1 + level );
     86        auto scope = kindTable.currentScope() - 1 - level;
     87        debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << endl );
    8788        auto ret = kindTable.insertAt( scope, identifier, kind );
    8889        if ( ! ret.second ) ret.first->second = kind;           // exists => update
     
    9192void TypedefTable::enterScope() {
    9293        kindTable.beginScope();
    93         debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl );
    94         debugPrint( print() );
     94        debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() );
    9595} // TypedefTable::enterScope
    9696
    9797void TypedefTable::leaveScope() {
    98         debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl );
    99         debugPrint( print() );
     98        debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl; print() );
    10099        kindTable.endScope();
    101100} // TypedefTable::leaveScope
     
    114113                --scope;
    115114                debugPrint( cerr << endl << "[" << scope << "]" );
    116         }
     115        } // while
    117116        debugPrint( cerr << endl );
    118 }
     117} // TypedefTable::print
    119118
    120119// Local Variables: //
  • src/Parser/TypedefTable.h

    r6d43cc57 r3d56d15b  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 12:10:17 2018
    13 // Update Count     : 85
     12// Last Modified On : Fri Jun 22 05:29:58 2018
     13// Update Count     : 86
    1414//
    1515
     
    2525        typedef ScopedMap< std::string, int > KindTable;
    2626        KindTable kindTable;   
     27        unsigned int level = 0;
    2728  public:
    2829        ~TypedefTable();
     
    3738        void leaveScope();
    3839
     40        void up() { level += 1; }
     41        void down() { level -= 1; }
     42
    3943        void print( void ) const;
    4044}; // TypedefTable
  • src/Parser/parser.yy

    r6d43cc57 r3d56d15b  
    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 : Fri Jun 22 13:59:11 2018
     13// Update Count     : 3586
    1414//
    1515
     
    136136} // build_postfix_name
    137137
    138 bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
     138bool forall = false, xxx = false, yyy = 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> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
     306%type<decl> external_definition external_definition_list external_definition_list_opt
     307
     308%type<decl> exception_declaration
    307309
    308310%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    18211823        ;
    18221824
     1825fred:
     1826        // empty
     1827                { yyy = false; }
     1828        ;
     1829
    18231830aggregate_type:                                                                                 // struct, union
    18241831        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18251832                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1826         | aggregate_key attribute_list_opt no_attr_identifier
     1833        | aggregate_key attribute_list_opt no_attr_identifier fred
    18271834                {
    18281835                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     
    18311838                }
    18321839          '{' field_declaration_list_opt '}'
    1833                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1834         | aggregate_key attribute_list_opt type_name
     1840                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
     1841        | aggregate_key attribute_list_opt type_name fred
    18351842                {
    18361843                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     
    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 );
     
    18531860                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18541861                }
    1855         | aggregate_key attribute_list_opt type_name
     1862        | aggregate_key attribute_list_opt type_name fred
    18561863                {
    18571864                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18671874aggregate_key:
    18681875        STRUCT
    1869                 { $$ = DeclarationNode::Struct; }
     1876                { yyy = true; $$ = DeclarationNode::Struct; }
    18701877        | UNION
    1871                 { $$ = DeclarationNode::Union; }
     1878                { yyy = true; $$ = DeclarationNode::Union; }
    18721879        | EXCEPTION
    1873                 { $$ = DeclarationNode::Exception; }
     1880                { yyy = true; $$ = DeclarationNode::Exception; }
    18741881        | COROUTINE
    1875                 { $$ = DeclarationNode::Coroutine; }
     1882                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18761883        | MONITOR
    1877                 { $$ = DeclarationNode::Monitor; }
     1884                { yyy = true; $$ = DeclarationNode::Monitor; }
    18781885        | THREAD
    1879                 { $$ = DeclarationNode::Thread; }
     1886                { yyy = true; $$ = DeclarationNode::Thread; }
    18801887        ;
    18811888
     
    23222329
    23232330translation_unit:
    2324         // empty
    2325                 {}                                                                                              // empty input file
     2331        // empty, input file
    23262332        | external_definition_list
    23272333                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23372343        ;
    23382344
    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.
    2345 external_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 
    23532345external_definition_list_opt:
    23542346        // empty
    23552347                { $$ = nullptr; }
    2356         | external_definition_list_no_pop_push
     2348        | external_definition_list
     2349        ;
     2350
     2351up:
     2352                { typedefTable.up(); }
     2353        ;
     2354
     2355down:
     2356                { typedefTable.down(); }
    23572357        ;
    23582358
     
    23742374                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23752375                }
    2376           '{' external_definition_list_opt '}'
     2376          '{' up external_definition_list_opt down '}'
    23772377                {
    23782378                        linkage = linkageStack.top();
    23792379                        linkageStack.pop();
    2380                         $$ = $5;
     2380                        $$ = $6;
    23812381                }
    23822382        | type_qualifier_list
    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() ) {
     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() ) {
    23872390                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23882391                                        iter->addQualifiers( $1->clone() );
     
    23912394                        xxx = false;
    23922395                        delete $1;
    2393                         $$ = $4;
     2396                        $$ = $5;
    23942397                }
    23952398        | declaration_qualifier_list
    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() ) {
     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() ) {
    24002406                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    24012407                                        iter->addQualifiers( $1->clone() );
     
    24042410                        xxx = false;
    24052411                        delete $1;
    2406                         $$ = $4;
     2412                        $$ = $5;
    24072413                }
    24082414        | declaration_qualifier_list type_qualifier_list
    24092415                {
    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() ) {
     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() ) {
    24162422                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    24172423                                        iter->addQualifiers( $1->clone() );
     
    24222428                        delete $1;
    24232429                        delete $2;
    2424                         $$ = $5;
     2430                        $$ = $6;
    24252431                }
    24262432        ;
Note: See TracChangeset for help on using the changeset viewer.