Changes in / [597c34a3:41e16b1]


Ignore:
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/Mutate.cc

    r597c34a3 r41e16b1  
    2727#include "SynTree/Visitor.h"       // for acceptAll
    2828
    29 using namespace std;
     29namespace ControlStruct {
     30        void fixLabels( std::list< Declaration * > & translationUnit ) {
     31                PassVisitor<LabelFixer> lfix;
     32                acceptAll( translationUnit, lfix );
     33        }
    3034
    31 namespace ControlStruct {
    32         void mutate( std::list< Declaration * > translationUnit ) {
    33                 // hoist initialization out of for statements
     35        void hoistControlDecls( std::list< Declaration * > & translationUnit ) {
    3436                PassVisitor<ForExprMutator> formut;
    35 
    36                 // normalizes label definitions and generates multi-level exit labels
    37                 PassVisitor<LabelFixer> lfix;
    38 
    3937                mutateAll( translationUnit, formut );
    40                 acceptAll( translationUnit, lfix );
    4138        }
    4239} // namespace CodeGen
  • src/ControlStruct/Mutate.h

    r597c34a3 r41e16b1  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Mutate.h -- 
     7// Mutate.h --
    88//
    99// Author           : Rodolfo G. Esteves
     
    2020class Declaration;
    2121
     22/// Desugars Cforall control structures
    2223namespace ControlStruct {
    23         /// Desugars Cforall control structures
    24         void mutate( std::list< Declaration* > translationUnit );
     24        /// normalizes label definitions and generates multi-level exit labels
     25        void fixLabels( std::list< Declaration * > & translationUnit );
     26
     27        /// hoist initialization out of for statements
     28        void hoistControlDecls( std::list< Declaration * > & translationUnit );
    2529} // namespace ControlStruct
    2630
  • src/Parser/TypedefTable.cc

    r597c34a3 r41e16b1  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 22 08:40:01 2018
    13 // Update Count     : 121
     12// Last Modified On : Wed May 30 18:04:38 2018
     13// Update Count     : 148
    1414//
    1515
     
    2020#if 0
    2121#include <iostream>
    22 #define debugPrint( x ) cerr << x
     22#define debugPrint( code ) code
    2323#else
    24 #define debugPrint( x )
     24#define debugPrint( code )
    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 );
     56                typedefTable.addToEnclosingScope( name, TYPEDEFname /*, "MTD"*/ );
    5757        } // if
    5858} // TypedefTable::makeTypedef
    5959
    60 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) {
     60void 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
     67void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
    6168        assert( kindTable.currentScope() >= 1 );
    6269        auto scope = kindTable.currentScope() - 1;
    63         debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl );
     70        debugPrint( cerr << "Adding2 at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
    6471        auto ret = kindTable.insertAt( scope, identifier, kind );
    6572        if ( ! ret.second ) ret.first->second = kind;           // exists => update
     
    6875void TypedefTable::enterScope() {
    6976        kindTable.beginScope();
    70         debugPrint( "Entering scope " << kindTable.currentScope() << endl );
     77        debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl );
     78        debugPrint( print() );
    7179} // TypedefTable::enterScope
    7280
    7381void TypedefTable::leaveScope() {
    74         debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
     82        debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl );
     83        debugPrint( print() );
    7584        kindTable.endScope();
    7685} // TypedefTable::leaveScope
    7786
    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 // }
     87void 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}
    88103
    89104// Local Variables: //
  • src/Parser/TypedefTable.h

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

    r597c34a3 r41e16b1  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 28 17:01:36 2018
    13 // Update Count     : 3383
     12// Last Modified On : Thu May 31 15:11:40 2018
     13// Update Count     : 3444
    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
     267%type<sn> selection_statement                   if_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_declaration_list KR_declaration_list_opt
     334%type<decl> KR_parameter_list KR_parameter_list_opt
    335335
    336336%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    404404//************************* Namespace Management ********************************
    405405
    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.
     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
    428432
    429433push:
     
    854858//      | '[' push assignment_expression pop ']'
    855859//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    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 ) ) ); }
     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 ) ) ); }
    860864        ;
    861865
     
    909913        '{' '}'
    910914                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    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
     915        | '{' push
    915916          local_label_declaration_opt                                           // GCC, local labels
    916917          statement_decl_list                                                           // C99, intermix declarations and statements
    917918          pop '}'
    918                 { $$ = new StatementNode( build_compound( $5 ) ); }
     919                { $$ = new StatementNode( build_compound( $4 ) ); }
    919920        ;
    920921
    921922statement_decl_list:                                                                    // C99
    922923        statement_decl
    923         | statement_decl_list push statement_decl
    924                 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
     924        | statement_decl_list statement_decl
     925                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    925926        ;
    926927
     
    940941                        $$ = new StatementNode( $2 );
    941942                }
    942         | statement pop
     943        | statement
    943944        ;
    944945
     
    955956
    956957selection_statement:
    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 ) ); }
     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; }
    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 '}' // CFA
     964        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // 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 '}' // CFA
     976        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    977977                {
    978978                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    981981        ;
    982982
     983if_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
    983992if_control_expression:
    984         comma_expression pop
     993        comma_expression
    985994                { $$ = new IfCtl( nullptr, $1 ); }
    986         | c_declaration pop                                                                     // no semi-colon
     995        | c_declaration                                                                         // no semi-colon
    987996                { $$ = new IfCtl( $1, nullptr ); }
    988         | cfa_declaration pop                                                           // no semi-colon
     997        | cfa_declaration                                                                       // no semi-colon
    989998                { $$ = new IfCtl( $1, nullptr ); }
    990999        | declaration comma_expression                                          // semi-colon separated
     
    10471056        | DO statement WHILE '(' comma_expression ')' ';'
    10481057                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1049         | FOR '(' push for_control_expression ')' statement
     1058        | FOR '(' push for_control_expression ')' statement pop
    10501059                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10511060        ;
    10521061
    10531062for_control_expression:
    1054         comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    1055                 { $$ = new ForCtl( $1, $4, $6 ); }
     1063        comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
     1064                { $$ = new ForCtl( $1, $3, $5 ); }
    10561065        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10571066                { $$ = new ForCtl( $1, $2, $4 ); }
     
    11751184
    11761185handler_clause:
    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 ) ) ); }
     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 ) ) ); }
    11811190        ;
    11821191
     
    12821291
    12831292declaration_list_opt:                                                                   // used at beginning of switch statement
    1284         pop     // empty
     1293        // empty
    12851294                { $$ = nullptr; }
    12861295        | declaration_list
     
    12891298declaration_list:
    12901299        declaration
    1291         | declaration_list push declaration
    1292                 { $$ = $1->appendList( $3 ); }
    1293         ;
    1294 
    1295 KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
     1300        | declaration_list declaration
     1301                { $$ = $1->appendList( $2 ); }
     1302        ;
     1303
     1304KR_parameter_list_opt:                                                          // used to declare parameter types in K&R style functions
    12961305        // empty
    12971306                { $$ = nullptr; }
    1298         | KR_declaration_list
    1299         ;
    1300 
    1301 KR_declaration_list:
     1307        | KR_parameter_list
     1308        ;
     1309
     1310KR_parameter_list:
    13021311        push c_declaration pop ';'
    13031312                { $$ = $2; }
    1304         | KR_declaration_list push c_declaration pop ';'
     1313        | KR_parameter_list push c_declaration pop ';'
    13051314                { $$ = $1->appendList( $3 ); }
    13061315        ;
     
    13221331
    13231332declaration:                                                                                    // old & new style declarations
    1324         c_declaration pop ';'
    1325         | cfa_declaration pop ';'                                                       // CFA
     1333        c_declaration ';'
     1334        | cfa_declaration ';'                                                           // CFA
    13261335        | static_assert
    13271336        ;
     
    14311440        TYPEDEF cfa_variable_specifier
    14321441                {
    1433                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1442                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
    14341443                        $$ = $2->addTypedef();
    14351444                }
    14361445        | TYPEDEF cfa_function_specifier
    14371446                {
    1438                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1447                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
    14391448                        $$ = $2->addTypedef();
    14401449                }
    14411450        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14421451                {
    1443                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
     1452                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
    14441453                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14451454                }
     
    14521461        TYPEDEF type_specifier declarator
    14531462                {
    1454                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1463                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
    14551464                        $$ = $3->addType( $2 )->addTypedef();
    14561465                }
    14571466        | typedef_declaration pop ',' push declarator
    14581467                {
    1459                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
     1468                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
    14601469                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14611470                }
    14621471        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14631472                {
    1464                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1473                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
    14651474                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14661475                }
    14671476        | type_specifier TYPEDEF declarator
    14681477                {
    1469                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1478                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
    14701479                        $$ = $3->addType( $1 )->addTypedef();
    14711480                }
    14721481        | type_specifier TYPEDEF type_qualifier_list declarator
    14731482                {
    1474                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1483                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
    14751484                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14761485                }
     
    15991608
    16001609forall:
    1601         FORALL '(' push type_parameter_list pop ')'                                     // CFA
    1602                 { $$ = DeclarationNode::newForall( $4 ); }
     1610        FORALL '(' type_parameter_list ')'                                      // CFA
     1611                { $$ = DeclarationNode::newForall( $3 ); }
    16031612        ;
    16041613
     
    21922201type_parameter:                                                                                 // CFA
    21932202        type_class no_attr_identifier_or_type_name
    2194                 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
     2203                { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
    21952204          type_initializer_opt assertion_list_opt
    21962205                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22282237        | '|' '{' push trait_declaration_list pop '}'
    22292238                { $$ = $4; }
    2230         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
    2231                 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2239        // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2240        //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22322241        ;
    22332242
     
    22612270        no_attr_identifier_or_type_name
    22622271                {
    2263                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
     2272                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
    22642273                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22652274                }
    2266         | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    2267                 {
    2268                         typedefTable.addToEnclosingScope( *$1, TYPEGENname );
    2269                         $$ = DeclarationNode::newTypeDecl( $1, $4 );
     2275        | no_attr_identifier_or_type_name '(' type_parameter_list ')'
     2276                {
     2277                        typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
     2278                        $$ = DeclarationNode::newTypeDecl( $1, $3 );
    22702279                }
    22712280        ;
    22722281
    22732282trait_specifier:                                                                                // CFA
    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 ); }
     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 ); }
    22782287        ;
    22792288
     
    23132322
    23142323external_definition_list:
    2315         external_definition
     2324        push external_definition pop
     2325                { $$ = $2; }
    23162326        | external_definition_list
    23172327                { forall = xxx; }
    2318           push external_definition
     2328          push external_definition pop
    23192329                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23202330        ;
     
    23382348                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23392349                }
    2340           '{' external_definition_list_opt '}'
     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 '}'
    23412355                {
    23422356                        linkage = linkageStack.top();
    23432357                        linkageStack.pop();
    2344                         $$ = $5;
     2358                        $$ = $6;
    23452359                }
    23462360        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     
    23512365        | type_qualifier_list
    23522366                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2353           push '{' external_definition_list '}'                         // CFA, namespace
    2354                 {
    2355                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2367          '{' external_definition_list push '}'                  // CFA, namespace
     2368                {
     2369                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23562370                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23572371                                        iter->addQualifiers( $1->clone() );
     
    23602374                        xxx = false;
    23612375                        delete $1;
    2362                         $$ = $5;
     2376                        $$ = $4;
    23632377                }
    23642378        | declaration_qualifier_list
    23652379                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2366           push '{' external_definition_list '}'                         // CFA, namespace
    2367                 {
    2368                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2380          '{' external_definition_list '}'                                       // CFA, namespace
     2381                {
     2382                        for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23692383                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23702384                                        iter->addQualifiers( $1->clone() );
     
    23732387                        xxx = false;
    23742388                        delete $1;
    2375                         $$ = $5;
     2389                        $$ = $4;
    23762390                }
    23772391        | declaration_qualifier_list type_qualifier_list
     
    23802394                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
    23812395                }
    2382           push '{' external_definition_list '}'                         // CFA, namespace
    2383                 {
    2384                         for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2396          '{' external_definition_list '}'                                      // CFA, namespace
     2397                {
     2398                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23852399                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    23862400                                        iter->addQualifiers( $1->clone() );
     
    23912405                        delete $1;
    23922406                        delete $2;
    2393                         $$ = $6;
     2407                        $$ = $5;
    23942408                }
    23952409        ;
     
    24042418        | function_declarator compound_statement
    24052419                { $$ = $1->addFunctionBody( $2 ); }
    2406         | KR_function_declarator KR_declaration_list_opt compound_statement
     2420        | KR_function_declarator KR_parameter_list_opt compound_statement
    24072421                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24082422        ;
     
    24442458
    24452459                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2446         | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2460        | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24472461                {
    24482462                        rebindForall( $1, $2 );
     
    24502464                }
    24512465                // handles default int return type, OBSOLESCENT (see 1)
    2452         | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2466        | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24532467                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24542468                // handles default int return type, OBSOLESCENT (see 1)
    2455         | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2469        | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24562470                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24572471                // handles default int return type, OBSOLESCENT (see 1)
    2458         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2472        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24592473                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24602474        ;
     
    27012715        typedef
    27022716                // hide type name in enclosing scope by variable name
    2703                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
     2717                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
    27042718        | '(' paren_type ')'
    27052719                { $$ = $2; }
     
    31913205        '[' push cfa_abstract_parameter_list pop ']'
    31923206                { $$ = DeclarationNode::newTuple( $3 ); }
    3193         | '[' push type_specifier_nobody ELLIPSIS ']'
     3207        | '[' push type_specifier_nobody ELLIPSIS pop ']'
    31943208                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    3195         | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'
     3209        | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
    31963210                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    31973211        ;
  • src/ResolvExpr/Alternative.cc

    r597c34a3 r41e16b1  
    2727
    2828namespace ResolvExpr {
    29         Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
     29        Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {}
    3030
    3131        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
     
    4848        }
    4949
    50         Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
     50        Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) {
    5151                other.expr = nullptr;
    5252        }
     
    5858                cvtCost = other.cvtCost;
    5959                expr = other.expr;
    60                 env = other.env;
     60                env = std::move( other.env );
    6161                other.expr = nullptr;
    6262                return *this;
  • src/ResolvExpr/AlternativeFinder.cc

    r597c34a3 r41e16b1  
    299299                // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value
    300300                std::unique_ptr<Expression> aggrExpr( alt.expr->clone() );
    301                 alt.env.apply( aggrExpr->get_result() );
    302                 Type * aggrType = aggrExpr->get_result();
     301                alt.env.apply( aggrExpr->result );
     302                Type * aggrType = aggrExpr->result;
    303303                if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
    304304                        aggrType = aggrType->stripReferences();
     
    306306                }
    307307
    308                 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
     308                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->result ) ) {
    309309                        NameExpr nameExpr( "" );
    310310                        addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
    311                 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
     311                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->result ) ) {
    312312                        NameExpr nameExpr( "" );
    313313                        addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
     
    320320                NameExpr * nameExpr = dynamic_cast< NameExpr * >( member );
    321321                if ( ! nameExpr ) return;
    322                 const std::string & name = nameExpr->get_name();
     322                const std::string & name = nameExpr->name;
    323323                std::list< Declaration* > members;
    324324                aggInst->lookup( name, members );
    325325
    326                 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    327                         if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
    328                                 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) );
    329                                 renameTypes( alternatives.back().expr );
    330                                 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.
     326                for ( Declaration * decl : members ) {
     327                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {
     328                                // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so
     329                                // can't construct in place and use vector::back
     330                                Alternative newAlt( new MemberExpr( dwt, expr->clone() ), env, newCost );
     331                                renameTypes( newAlt.expr );
     332                                addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.
     333                                alternatives.push_back( std::move(newAlt) );
    331334                        } else {
    332335                                assert( false );
     
    13791382                        Cost cost = Cost::zero;
    13801383                        Expression * newExpr = data.combine( cost );
    1381                         alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) );
     1384
     1385                        // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so
     1386                        // can't construct in place and use vector::back
     1387                        Alternative newAlt( newExpr, env, Cost::zero, cost );
    13821388                        PRINT(
    13831389                                std::cerr << "decl is ";
     
    13881394                                std::cerr << std::endl;
    13891395                        )
    1390                         renameTypes( alternatives.back().expr );
    1391                         addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression.
     1396                        renameTypes( newAlt.expr );
     1397                        addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression.
     1398                        alternatives.push_back( std::move(newAlt) );
    13921399                } // for
    13931400        }
  • src/ResolvExpr/TypeEnvironment.cc

    r597c34a3 r41e16b1  
    5050        }
    5151
    52         EqvClass::EqvClass() : type( 0 ), allowWidening( true ) {
     52        EqvClass::EqvClass() : type( nullptr ), allowWidening( true ) {
    5353        }
    5454
     
    159159
    160160        void TypeEnvironment::print( std::ostream &os, Indenter indent ) const {
    161                 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) {
    162                         i->print( os, indent );
     161                for ( const EqvClass & theClass : env ) {
     162                        theClass.print( os, indent );
    163163                } // for
    164164        }
  • src/SymTab/Validate.cc

    r597c34a3 r41e16b1  
    4848#include "CodeGen/CodeGenerator.h"     // for genName
    4949#include "CodeGen/OperatorTable.h"     // for isCtorDtor, isCtorDtorAssign
     50#include "ControlStruct/Mutate.h"      // for ForExprMutator
    5051#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
    5152#include "Common/ScopedMap.h"          // for ScopedMap
     
    7677class SwitchStmt;
    7778
    78 
    7979#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
    8080
     
    275275                Concurrency::applyKeywords( translationUnit );
    276276                acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
     277                ControlStruct::hoistControlDecls( translationUnit );  // hoist initialization out of for statements; must happen before autogenerateRoutines
    277278                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
    278279                Concurrency::implementMutexFuncs( translationUnit );
  • src/SynTree/ReferenceToType.cc

    r597c34a3 r41e16b1  
    5050
    5151namespace {
    52         void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
    53                 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    54                         if ( (*i)->get_name() == name ) {
    55                                 foundDecls.push_back( *i );
     52        void doLookup( const std::list< Declaration * > & members, const std::string & name, std::list< Declaration* > & foundDecls ) {
     53                for ( Declaration * decl : members ) {
     54                        if ( decl->name == name ) {
     55                                foundDecls.push_back( decl );
    5656                        } // if
    5757                } // for
     
    6060
    6161StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
    62                 Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
     62                Parent( tq, baseStruct->name, attributes ), baseStruct( baseStruct ) {}
    6363
    6464std::string StructInstType::typeString() const { return "struct"; }
     
    8484void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    8585        assert( baseStruct );
    86         doLookup( baseStruct->get_members(), name, foundDecls );
     86        doLookup( baseStruct->members, name, foundDecls );
    8787}
    8888
     
    103103
    104104UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
    105                 Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
     105                Parent( tq, baseUnion->name, attributes ), baseUnion( baseUnion ) {}
    106106
    107107std::string UnionInstType::typeString() const { return "union"; }
     
    127127void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    128128        assert( baseUnion );
    129         doLookup( baseUnion->get_members(), name, foundDecls );
     129        doLookup( baseUnion->members, name, foundDecls );
    130130}
    131131
  • src/main.cc

    r597c34a3 r41e16b1  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May  7 14:35:57 2018
    13 // Update Count     : 492
     12// Last Modified On : Wed May 30 17:53:14 2018
     13// Update Count     : 496
    1414//
    1515
     
    264264                } // if
    265265
    266                 PASS( "mutate", ControlStruct::mutate( translationUnit ) );
     266                PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) );
    267267                PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
    268268                PASS( "genInit", InitTweak::genInit( translationUnit ) );
     
    573573        yyin = input;
    574574        yylineno = 1;
    575         typedefTable.enterScope();
    576575        int parseStatus = yyparse();
    577576
  • tools/prettyprinter/lex.ll

    r597c34a3 r41e16b1  
    1010 * Created On       : Sat Dec 15 11:45:59 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sun Apr 15 21:28:33 2018
    13  * Update Count     : 271
     12 * Last Modified On : Thu May 31 08:49:58 2018
     13 * Update Count     : 274
    1414 */
    1515
     
    7777}
    7878
    79 <INITIAL,C_CODE>"//"[^\n]*"\n" {                                                // C++ style comments
     79<INITIAL,C_CODE>"//"[^\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.