Changeset 4ae78c1 for src


Ignore:
Timestamp:
Oct 30, 2020, 12:01:23 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
969e7ee7, f7e4f8e8
Parents:
6a77224 (diff), 3100754 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    r6a77224 r4ae78c1  
    296296private:
    297297        bool inFunction = false;
     298        bool atFunctionTop = false;
    298299};
    299300
  • src/AST/Pass.impl.hpp

    r6a77224 r4ae78c1  
    502502                                // foralls are still in function type
    503503                                maybe_accept( node, &FunctionDecl::type );
    504                                 // function body needs to have the same scope as parameters - CompoundStmt will not enter
    505                                 // a new scope if inFunction is true
     504                                // First remember that we are now within a function.
    506505                                ValueGuard< bool > oldInFunction( inFunction );
    507506                                inFunction = true;
     507                                // The function body needs to have the same scope as parameters.
     508                                // A CompoundStmt will not enter a new scope if atFunctionTop is true.
     509                                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     510                                atFunctionTop = true;
    508511                                maybe_accept( node, &FunctionDecl::stmts );
    509512                                maybe_accept( node, &FunctionDecl::attributes );
     
    672675        VISIT_START( node );
    673676        VISIT({
    674                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    675                 auto guard1 = makeFuncGuard( [this, inFunctionCpy = this->inFunction]() {
    676                         if ( ! inFunctionCpy ) __pass::symtab::enter(core, 0);
    677                 }, [this, inFunctionCpy = this->inFunction]() {
    678                         if ( ! inFunctionCpy ) __pass::symtab::leave(core, 0);
     677                // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.
     678                auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {
     679                        if ( enterScope ) __pass::symtab::enter(core, 0);
     680                }, [this, leaveScope = !this->atFunctionTop]() {
     681                        if ( leaveScope ) __pass::symtab::leave(core, 0);
    679682                });
    680683                ValueGuard< bool > guard2( inFunction );
  • src/Common/PassVisitor.h

    r6a77224 r4ae78c1  
    360360private:
    361361        bool inFunction = false;
     362        bool atFunctionTop = false;
    362363
    363364        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     
    532533
    533534        bool isInFunction() const {
    534                 return visitor->inFunction;
     535                return visitor->isInFunction();
    535536        }
    536537};
  • src/Common/PassVisitor.impl.h

    r6a77224 r4ae78c1  
    532532                        indexerAddId( &func );
    533533                        maybeAccept_impl( node->type, *this );
    534                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    535                         // a new scope if inFunction is true
     534                        // First remember that we are now within a function.
    536535                        ValueGuard< bool > oldInFunction( inFunction );
    537536                        inFunction = true;
     537                        // The function body needs to have the same scope as parameters.
     538                        // A CompoundStmt will not enter a new scope if atFunctionTop is true.
     539                        ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     540                        atFunctionTop = true;
    538541                        maybeAccept_impl( node->statements, *this );
    539542                        maybeAccept_impl( node->attributes, *this );
     
    567570                        indexerAddId( &func );
    568571                        maybeAccept_impl( node->type, *this );
    569                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    570                         // a new scope if inFunction is true
     572                        // First remember that we are now within a function.
    571573                        ValueGuard< bool > oldInFunction( inFunction );
    572574                        inFunction = true;
     575                        // The function body needs to have the same scope as parameters.
     576                        // A CompoundStmt will not enter a new scope if atFunctionTop is true.
     577                        ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     578                        atFunctionTop = true;
    573579                        maybeAccept_impl( node->statements, *this );
    574580                        maybeAccept_impl( node->attributes, *this );
     
    601607                        indexerAddId( &func );
    602608                        maybeMutate_impl( node->type, *this );
    603                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    604                         // a new scope if inFunction is true
     609                        // First remember that we are now within a function.
    605610                        ValueGuard< bool > oldInFunction( inFunction );
    606611                        inFunction = true;
     612                        // The function body needs to have the same scope as parameters.
     613                        // A CompoundStmt will not enter a new scope if atFunctionTop is true.
     614                        ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     615                        atFunctionTop = true;
    607616                        maybeMutate_impl( node->statements, *this );
    608617                        maybeMutate_impl( node->attributes, *this );
     
    10071016        VISIT_START( node );
    10081017        {
    1009                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    1010                 ValueGuard< bool > oldInFunction( inFunction );
    1011                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     1018                // Do not enter a new scope if atFunctionTop is true, don't leave one either.
     1019                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     1020                auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
    10121021                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    1013                 inFunction = false;
     1022                atFunctionTop = false;
    10141023                visitStatementList( node->kids );
    10151024        }
     
    10211030        VISIT_START( node );
    10221031        {
    1023                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    1024                 ValueGuard< bool > oldInFunction( inFunction );
    1025                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     1032                // Do not enter a new scope if atFunctionTop is true, don't leave one either.
     1033                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     1034                auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
    10261035                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    1027                 inFunction = false;
     1036                atFunctionTop = false;
    10281037                visitStatementList( node->kids );
    10291038        }
     
    10351044        MUTATE_START( node );
    10361045        {
    1037                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    1038                 ValueGuard< bool > oldInFunction( inFunction );
    1039                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     1046                // Do not enter a new scope if atFunctionTop is true, don't leave one either.
     1047                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     1048                auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
    10401049                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    1041                 inFunction = false;
     1050                atFunctionTop = false;
    10421051                mutateStatementList( node->kids );
    10431052        }
  • src/GenPoly/Specialize.cc

    r6a77224 r4ae78c1  
    218218                thunkFunc->get_attributes().push_back( new Attribute( "unused" ) );
    219219
     220                // Thunks at the global level must be static to avoid collisions between files.
     221                // (Conversly thunks inside a function must be unique and not static.)
     222                thunkFunc->storageClasses.is_static = !isInFunction();
     223
    220224                // thread thunk parameters into call to actual function, naming thunk parameters as we go
    221225                UniqueName paramNamer( paramPrefix );
     
    321325        }
    322326
    323         // Fold it into Specialize if we find a good way.
    324         struct StaticThunks final : public WithShortCircuiting {
    325                 void previsit( Declaration * ) {
    326                         visit_children = false;
    327                 }
    328                 void postvisit( FunctionDecl * decl ) {
    329                         if ( isPrefix( decl->name, "_thunk" ) ) {
    330                                 decl->storageClasses.is_static = true;
    331                         }
    332                 }
    333         };
    334 
    335327        void convertSpecializations( std::list< Declaration* >& translationUnit ) {
    336328                PassVisitor<Specialize> spec;
    337329                mutateAll( translationUnit, spec );
    338                 PassVisitor<StaticThunks> staticThunks;
    339                 acceptAll( translationUnit, staticThunks );
    340330        }
    341331} // namespace GenPoly
Note: See TracChangeset for help on using the changeset viewer.