Changes in / [b368dd8:cf5e5b1]


Ignore:
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypedefTable.cc

    rb368dd8 rcf5e5b1  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 30 18:04:38 2018
    13 // Update Count     : 148
     12// Last Modified On : Tue May 22 08:40:01 2018
     13// Update Count     : 121
    1414//
    1515
     
    2020#if 0
    2121#include <iostream>
    22 #define debugPrint( code ) code
     22#define debugPrint( x ) cerr << x
    2323#else
    24 #define debugPrint( code )
     24#define debugPrint( x )
    2525#endif
    2626
     
    2929TypedefTable::~TypedefTable() {
    3030        if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) {
    31                 std::cerr << "scope failure " << kindTable.currentScope() << endl;
     31                // std::cerr << "scope failure " << kindTable.currentScope() << endl;
    3232        } // if
    3333} // TypedefTable::~TypedefTable
     
    5454void TypedefTable::makeTypedef( const string & name ) {
    5555        if ( ! typedefTable.exists( name ) ) {
    56                 typedefTable.addToEnclosingScope( name, TYPEDEFname /*, "MTD"*/ );
     56                typedefTable.addToEnclosingScope( name, TYPEDEFname );
    5757        } // if
    5858} // TypedefTable::makeTypedef
    5959
    60 void TypedefTable::addToScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
    61         auto scope = kindTable.currentScope();
    62         debugPrint( cerr << "Adding at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
    63         auto ret = kindTable.insertAt( scope, identifier, kind );
    64         if ( ! ret.second ) ret.first->second = kind;           // exists => update
    65 } // TypedefTable::addToScope
    66 
    67 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
     60void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) {
    6861        assert( kindTable.currentScope() >= 1 );
    6962        auto scope = kindTable.currentScope() - 1;
    70         debugPrint( cerr << "Adding2 at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
     63        debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl );
    7164        auto ret = kindTable.insertAt( scope, identifier, kind );
    7265        if ( ! ret.second ) ret.first->second = kind;           // exists => update
     
    7568void TypedefTable::enterScope() {
    7669        kindTable.beginScope();
    77         debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl );
    78         debugPrint( print() );
     70        debugPrint( "Entering scope " << kindTable.currentScope() << endl );
    7971} // TypedefTable::enterScope
    8072
    8173void TypedefTable::leaveScope() {
    82         debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl );
    83         debugPrint( print() );
     74        debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
    8475        kindTable.endScope();
    8576} // TypedefTable::leaveScope
    8677
    87 void TypedefTable::print( void ) const {
    88         KindTable::size_type scope = kindTable.currentScope();
    89         debugPrint( cerr << "[" << scope << "]" );
    90         for ( KindTable::const_iterator i = kindTable.begin(); i != kindTable.end(); i++ ) {
    91                 while ( i.get_level() != scope ) {
    92                         --scope;
    93                         debugPrint( cerr << endl << "[" << scope << "]" );
    94                 } // while
    95                 debugPrint( cerr << " " << (*i).first << ":" << (*i).second );
    96         } // for
    97         while ( scope > 0 ) {
    98                 --scope;
    99                 debugPrint( cerr << endl << "[" << scope << "]" );
    100         }
    101         debugPrint( cerr << endl );
    102 }
     78// void TypedefTable::print( void ) const {
     79//      for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) {
     80//              debugPrint( (*i ).first << ": " );
     81//              list< Entry > declList = (*i).second;
     82//              for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
     83//                      debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
     84//              }
     85//              debugPrint( endl );
     86//      } // for
     87// }
    10388
    10489// Local Variables: //
  • src/Parser/TypedefTable.h

    rb368dd8 rcf5e5b1  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 30 17:02:49 2018
    13 // Update Count     : 82
     12// Last Modified On : Tue May 22 08:39:29 2018
     13// Update Count     : 77
    1414//
    1515
     
    3232        void changeKind( const std::string & identifier, int kind );
    3333        void makeTypedef( const std::string & name );
    34         void addToScope( const std::string & identifier, int kind /*, const char **/ );
    35         void addToEnclosingScope( const std::string & identifier, int kind /*, const char */ );
     34        void addToEnclosingScope( const std::string & identifier, int kind );
    3635
    3736        void enterScope();
    3837        void leaveScope();
    39 
    40         void print( void ) const;
    4138}; // TypedefTable
    4239
  • src/Parser/parser.yy

    rb368dd8 rcf5e5b1  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 31 15:11:40 2018
    13 // Update Count     : 3444
     12// Last Modified On : Mon May 28 17:01:36 2018
     13// Update Count     : 3383
    1414//
    1515
     
    265265%type<sn> statement                                             labeled_statement                       compound_statement
    266266%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    267 %type<sn> selection_statement                   if_statement
     267%type<sn> selection_statement
    268268%type<sn> switch_clause_list_opt                switch_clause_list
    269269%type<en> case_value
     
    332332%type<decl> c_declaration static_assert
    333333%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    334 %type<decl> KR_parameter_list KR_parameter_list_opt
     334%type<decl> KR_declaration_list KR_declaration_list_opt
    335335
    336336%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    404404//************************* Namespace Management ********************************
    405405
    406 // The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",
    407 // which are lexically identical.
    408 //
    409 //   typedef int foo; // identifier foo must now be scanned as TYPEDEFname
    410 //   foo f;           // to allow it to appear in this context
    411 //
    412 // While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship
    413 // between syntactic and semantic constructs.  Cforall compounds this problem by introducing type names local to the
    414 // scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type
    415 // generators" -- parameterized types.  This latter type name creates a third class of identifiers, "TYPEGENname", which
    416 // must be distinguished by the lexical scanner.
    417 //
    418 // Since the scanner cannot distinguish among the different classes of identifiers without some context information,
    419 // there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named
    420 // scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For
    421 // each context that introduces a name scope, a new level is created in the type table and that level is popped on
    422 // exiting the scope.  Since type names can be local to a particular declaration, each declaration is itself a scope.
    423 // This requires distinguishing between type names that are local to the current declaration scope and those that
    424 // persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).
    425 //
    426 // The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in
    427 // the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push
    428 // around the list separator.
    429 //
    430 //  int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) );
    431 //      push               pop   push                   pop
     406// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
     407// "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
     408// context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
     409// Hence, this grammar uses the ANSI style.
     410//
     411// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
     412// introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types.  This latter
     413// type name creates a third class of identifiers that must be distinguished by the scanner.
     414//
     415// Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
     416// accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read.  Semantic
     417// actions during the parser update this data structure when the class of identifiers change.
     418//
     419// Because the Cforall language is block-scoped, an identifier can change its class in a local scope; it must revert to
     420// its original class at the end of the block.  Since type names can be local to a particular declaration, each
     421// declaration is itself a scope.  This requires distinguishing between type names that are local to the current
     422// declaration scope and those that persist past the end of the declaration (i.e., names defined in "typedef" or "otype"
     423// declarations).
     424//
     425// The non-terminals "push" and "pop" denote the opening and closing of scopes.  Every push must have a matching pop,
     426// although it is regrettable the matching pairs do not always occur within the same rule.  These non-terminals may
     427// appear in more contexts than strictly necessary from a semantic point of view.
    432428
    433429push:
     
    858854//      | '[' push assignment_expression pop ']'
    859855//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    860         '[' ',' tuple_expression_list ']'
    861                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    862         | '[' push assignment_expression pop ',' tuple_expression_list ']'
    863                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
     856        '[' push ',' tuple_expression_list pop ']'
     857                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
     858        | '[' push assignment_expression ',' tuple_expression_list pop ']'
     859                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
    864860        ;
    865861
     
    913909        '{' '}'
    914910                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    915         | '{' push
     911        | '{'
     912                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     913                // requires its own scope.
     914          push push
    916915          local_label_declaration_opt                                           // GCC, local labels
    917916          statement_decl_list                                                           // C99, intermix declarations and statements
    918917          pop '}'
    919                 { $$ = new StatementNode( build_compound( $4 ) ); }
     918                { $$ = new StatementNode( build_compound( $5 ) ); }
    920919        ;
    921920
    922921statement_decl_list:                                                                    // C99
    923922        statement_decl
    924         | statement_decl_list statement_decl
    925                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     923        | statement_decl_list push statement_decl
     924                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    926925        ;
    927926
     
    941940                        $$ = new StatementNode( $2 );
    942941                }
    943         | statement
     942        | statement pop
    944943        ;
    945944
     
    956955
    957956selection_statement:
    958                         // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
    959                         // the inherent S/R conflict with THEN/ELSE.
    960         push if_statement pop
    961                 { $$ = $2; }
     957        IF '(' push if_control_expression ')' statement         %prec THEN
     958                // explicitly deal with the shift/reduce conflict on if/else
     959                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     960        | IF '(' push if_control_expression ')' statement ELSE statement
     961                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    962962        | SWITCH '(' comma_expression ')' case_clause
    963963                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    964         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     964        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    965965                {
    966966                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
     
    974974        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    975975                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
    976         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     976        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    977977                {
    978978                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    981981        ;
    982982
    983 if_statement:
    984         IF '(' if_control_expression ')' statement                      %prec THEN
    985                 // explicitly deal with the shift/reduce conflict on if/else
    986                 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    987         | IF '(' if_control_expression ')' statement ELSE statement
    988                 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    989         ;
    990 
    991 
    992983if_control_expression:
    993         comma_expression
     984        comma_expression pop
    994985                { $$ = new IfCtl( nullptr, $1 ); }
    995         | c_declaration                                                                         // no semi-colon
     986        | c_declaration pop                                                                     // no semi-colon
    996987                { $$ = new IfCtl( $1, nullptr ); }
    997         | cfa_declaration                                                                       // no semi-colon
     988        | cfa_declaration pop                                                           // no semi-colon
    998989                { $$ = new IfCtl( $1, nullptr ); }
    999990        | declaration comma_expression                                          // semi-colon separated
     
    10561047        | DO statement WHILE '(' comma_expression ')' ';'
    10571048                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1058         | FOR '(' push for_control_expression ')' statement pop
     1049        | FOR '(' push for_control_expression ')' statement
    10591050                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10601051        ;
    10611052
    10621053for_control_expression:
    1063         comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
    1064                 { $$ = new ForCtl( $1, $3, $5 ); }
     1054        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
     1055                { $$ = new ForCtl( $1, $4, $6 ); }
    10651056        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10661057                { $$ = new ForCtl( $1, $2, $4 ); }
     
    11841175
    11851176handler_clause:
    1186         handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1187                 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
    1188         | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1189                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
     1177        handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1178                { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
     1179        | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1180                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
    11901181        ;
    11911182
     
    12911282
    12921283declaration_list_opt:                                                                   // used at beginning of switch statement
     1284        pop     // empty
     1285                { $$ = nullptr; }
     1286        | declaration_list
     1287        ;
     1288
     1289declaration_list:
     1290        declaration
     1291        | declaration_list push declaration
     1292                { $$ = $1->appendList( $3 ); }
     1293        ;
     1294
     1295KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    12931296        // empty
    12941297                { $$ = nullptr; }
    1295         | declaration_list
    1296         ;
    1297 
    1298 declaration_list:
    1299         declaration
    1300         | declaration_list declaration
    1301                 { $$ = $1->appendList( $2 ); }
    1302         ;
    1303 
    1304 KR_parameter_list_opt:                                                          // used to declare parameter types in K&R style functions
    1305         // empty
    1306                 { $$ = nullptr; }
    1307         | KR_parameter_list
    1308         ;
    1309 
    1310 KR_parameter_list:
     1298        | KR_declaration_list
     1299        ;
     1300
     1301KR_declaration_list:
    13111302        push c_declaration pop ';'
    13121303                { $$ = $2; }
    1313         | KR_parameter_list push c_declaration pop ';'
     1304        | KR_declaration_list push c_declaration pop ';'
    13141305                { $$ = $1->appendList( $3 ); }
    13151306        ;
     
    13311322
    13321323declaration:                                                                                    // old & new style declarations
    1333         c_declaration ';'
    1334         | cfa_declaration ';'                                                           // CFA
     1324        c_declaration pop ';'
     1325        | cfa_declaration pop ';'                                                       // CFA
    13351326        | static_assert
    13361327        ;
     
    14401431        TYPEDEF cfa_variable_specifier
    14411432                {
    1442                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
     1433                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14431434                        $$ = $2->addTypedef();
    14441435                }
    14451436        | TYPEDEF cfa_function_specifier
    14461437                {
    1447                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
     1438                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14481439                        $$ = $2->addTypedef();
    14491440                }
    14501441        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14511442                {
    1452                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
     1443                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
    14531444                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14541445                }
     
    14611452        TYPEDEF type_specifier declarator
    14621453                {
    1463                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
     1454                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14641455                        $$ = $3->addType( $2 )->addTypedef();
    14651456                }
    14661457        | typedef_declaration pop ',' push declarator
    14671458                {
    1468                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
     1459                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
    14691460                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14701461                }
    14711462        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14721463                {
    1473                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
     1464                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14741465                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14751466                }
    14761467        | type_specifier TYPEDEF declarator
    14771468                {
    1478                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
     1469                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14791470                        $$ = $3->addType( $1 )->addTypedef();
    14801471                }
    14811472        | type_specifier TYPEDEF type_qualifier_list declarator
    14821473                {
    1483                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
     1474                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14841475                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14851476                }
     
    16081599
    16091600forall:
    1610         FORALL '(' type_parameter_list ')'                                      // CFA
    1611                 { $$ = DeclarationNode::newForall( $3 ); }
     1601        FORALL '(' push type_parameter_list pop ')'                                     // CFA
     1602                { $$ = DeclarationNode::newForall( $4 ); }
    16121603        ;
    16131604
     
    22012192type_parameter:                                                                                 // CFA
    22022193        type_class no_attr_identifier_or_type_name
    2203                 { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
     2194                { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
    22042195          type_initializer_opt assertion_list_opt
    22052196                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22372228        | '|' '{' push trait_declaration_list pop '}'
    22382229                { $$ = $4; }
    2239         // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
    2240         //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2230        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2231                { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22412232        ;
    22422233
     
    22702261        no_attr_identifier_or_type_name
    22712262                {
    2272                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
     2263                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
    22732264                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22742265                }
    2275         | no_attr_identifier_or_type_name '(' type_parameter_list ')'
    2276                 {
    2277                         typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
    2278                         $$ = DeclarationNode::newTypeDecl( $1, $3 );
     2266        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
     2267                {
     2268                        typedefTable.addToEnclosingScope( *$1, TYPEGENname );
     2269                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
    22792270                }
    22802271        ;
    22812272
    22822273trait_specifier:                                                                                // CFA
    2283         TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
    2284                 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
    2285         | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
    2286                 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
     2274        TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
     2275                { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
     2276        | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}'
     2277                { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
    22872278        ;
    22882279
     
    23222313
    23232314external_definition_list:
    2324         push external_definition pop
    2325                 { $$ = $2; }
     2315        external_definition
    23262316        | external_definition_list
    23272317                { forall = xxx; }
    2328           push external_definition pop
     2318          push external_definition
    23292319                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23302320        ;
     
    23482338                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23492339                }
    2350                         // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope.  However,
    2351                         // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The
    2352                         // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt.  This
    2353                         // trick works for nested extern "X"s, as each one undoes itself in the nesting.
    2354           '{' pop external_definition_list_opt push '}'
     2340          '{' external_definition_list_opt '}'
    23552341                {
    23562342                        linkage = linkageStack.top();
    23572343                        linkageStack.pop();
    2358                         $$ = $6;
     2344                        $$ = $5;
    23592345                }
    23602346        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     
    23652351        | type_qualifier_list
    23662352                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2367           '{' external_definition_list push '}'                  // CFA, namespace
    2368                 {
    2369                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2353          push '{' external_definition_list '}'                         // CFA, namespace
     2354                {
     2355                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23702356                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23712357                                        iter->addQualifiers( $1->clone() );
     
    23742360                        xxx = false;
    23752361                        delete $1;
    2376                         $$ = $4;
     2362                        $$ = $5;
    23772363                }
    23782364        | declaration_qualifier_list
    23792365                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2380           '{' external_definition_list '}'                                       // CFA, namespace
    2381                 {
    2382                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2366          push '{' external_definition_list '}'                         // CFA, namespace
     2367                {
     2368                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23832369                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23842370                                        iter->addQualifiers( $1->clone() );
     
    23872373                        xxx = false;
    23882374                        delete $1;
    2389                         $$ = $4;
     2375                        $$ = $5;
    23902376                }
    23912377        | declaration_qualifier_list type_qualifier_list
     
    23942380                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
    23952381                }
    2396           '{' external_definition_list '}'                                      // CFA, namespace
    2397                 {
    2398                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2382          push '{' external_definition_list '}'                         // CFA, namespace
     2383                {
     2384                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23992385                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    24002386                                        iter->addQualifiers( $1->clone() );
     
    24052391                        delete $1;
    24062392                        delete $2;
    2407                         $$ = $5;
     2393                        $$ = $6;
    24082394                }
    24092395        ;
     
    24182404        | function_declarator compound_statement
    24192405                { $$ = $1->addFunctionBody( $2 ); }
    2420         | KR_function_declarator KR_parameter_list_opt compound_statement
     2406        | KR_function_declarator KR_declaration_list_opt compound_statement
    24212407                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24222408        ;
     
    24582444
    24592445                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2460         | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2446        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24612447                {
    24622448                        rebindForall( $1, $2 );
     
    24642450                }
    24652451                // handles default int return type, OBSOLESCENT (see 1)
    2466         | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2452        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24672453                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24682454                // handles default int return type, OBSOLESCENT (see 1)
    2469         | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2455        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24702456                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24712457                // handles default int return type, OBSOLESCENT (see 1)
    2472         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2458        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24732459                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24742460        ;
     
    27152701        typedef
    27162702                // hide type name in enclosing scope by variable name
    2717                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
     2703                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
    27182704        | '(' paren_type ')'
    27192705                { $$ = $2; }
     
    32053191        '[' push cfa_abstract_parameter_list pop ']'
    32063192                { $$ = DeclarationNode::newTuple( $3 ); }
    3207         | '[' push type_specifier_nobody ELLIPSIS pop ']'
     3193        | '[' push type_specifier_nobody ELLIPSIS ']'
    32083194                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    3209         | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
     3195        | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'
    32103196                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    32113197        ;
  • src/main.cc

    rb368dd8 rcf5e5b1  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 30 17:53:14 2018
    13 // Update Count     : 496
     12// Last Modified On : Mon May  7 14:35:57 2018
     13// Update Count     : 492
    1414//
    1515
     
    573573        yyin = input;
    574574        yylineno = 1;
     575        typedefTable.enterScope();
    575576        int parseStatus = yyparse();
    576577
  • tools/prettyprinter/lex.ll

    rb368dd8 rcf5e5b1  
    1010 * Created On       : Sat Dec 15 11:45:59 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu May 31 08:49:58 2018
    13  * Update Count     : 274
     12 * Last Modified On : Sun Apr 15 21:28:33 2018
     13 * Update Count     : 271
    1414 */
    1515
     
    7777}
    7878
    79 <INITIAL,C_CODE>"//"[^\n]* {                                                    // C++ style comments
     79<INITIAL,C_CODE>"//"[^\n]*"\n" {                                                // C++ style comments
    8080#if defined(DEBUG_ALL) | defined(DEBUG_COMMENT)
    8181        cerr << "\"//\"[^\\n]*\"\n\" : " << yytext << endl;
Note: See TracChangeset for help on using the changeset viewer.