Changeset f13ee31 for src


Ignore:
Timestamp:
Jun 16, 2017, 12:01:25 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1a42132
Parents:
816d61c (diff), 974bcdd (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 plg2:software/cfa/cfa-cc

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r816d61c rf13ee31  
    5454        virtual void visit( BranchStmt *branchStmt ) override final;
    5555        virtual void visit( ReturnStmt *returnStmt ) override final;
     56        virtual void visit( ThrowStmt *throwStmt ) override final;
    5657        virtual void visit( TryStmt *tryStmt ) override final;
    5758        virtual void visit( CatchStmt *catchStmt ) override final;
     
    139140        virtual Statement* mutate( BranchStmt *branchStmt ) override final;
    140141        virtual Statement* mutate( ReturnStmt *returnStmt ) override final;
     142        virtual Statement* mutate( ThrowStmt *throwStmt ) override final;
    141143        virtual Statement* mutate( TryStmt *returnStmt ) override final;
    142144        virtual Statement* mutate( CatchStmt *catchStmt ) override final;
     
    230232        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
    231233        bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); }
     234        void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; }
     235
     236        guard_value_impl init_guard() {
     237                guard_value_impl guard;
     238                auto at_cleanup = at_cleanup_impl(pass, 0);
     239                if( at_cleanup ) {
     240                        *at_cleanup = [&guard]( cleanup_func_t && func, void* val ) {
     241                                guard.push( std::move( func ), val );
     242                        };
     243                }
     244                return guard;
     245        }
    232246};
    233247
     248template<typename pass_type, typename T>
     249void GuardValue( pass_type * pass, T& val ) {
     250        pass->at_cleanup( [ val ]( void * newVal ) {
     251                * static_cast< T * >( newVal ) = val;
     252        }, static_cast< void * >( & val ) );
     253}
     254
    234255#include "PassVisitor.impl.h"
  • src/Common/PassVisitor.impl.h

    r816d61c rf13ee31  
    11#pragma once
    22
    3 #define VISIT_START( node )  \
    4         call_previsit( node ); \
    5         if( visit_children() ) { \
    6 
    7 #define VISIT_END( node )            \
    8         }                              \
    9         return call_postvisit( node ); \
    10 
    11 #define MUTATE_START( node )  \
    12         call_premutate( node ); \
    13         if( visit_children() ) { \
     3#define VISIT_START( node )                     \
     4        __attribute__((unused))                   \
     5        const auto & guard = init_guard();        \
     6        call_previsit( node );                    \
     7        if( visit_children() ) {                  \
     8                reset_visit();                      \
     9
     10#define VISIT_END( node )                       \
     11        }                                         \
     12        call_postvisit( node );                   \
     13
     14#define MUTATE_START( node )                    \
     15        __attribute__((unused))                   \
     16        const auto & guard = init_guard();        \
     17        call_premutate( node );                   \
     18        if( visit_children() ) {                  \
     19                reset_visit();                      \
    1420
    1521#define MUTATE_END( type, node )                \
     
    1824
    1925
    20 #define VISIT_BODY( node )    \
    21         VISIT_START( node );  \
    22         Visitor::visit( node ); \
    23         VISIT_END( node ); \
     26#define VISIT_BODY( node )        \
     27        VISIT_START( node );        \
     28        Visitor::visit( node );     \
     29        VISIT_END( node );          \
    2430
    2531
     
    389395
    390396//--------------------------------------------------------------------------
     397// ThrowStmt
     398
     399template< typename pass_type >
     400void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
     401        VISIT_BODY( node );
     402}
     403
     404template< typename pass_type >
     405Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
     406        MUTATE_BODY( Statement, node );
     407}
     408
     409//--------------------------------------------------------------------------
    391410// TryStmt
    392411template< typename pass_type >
  • src/Common/PassVisitor.proto.h

    r816d61c rf13ee31  
    11#pragma once
     2
     3typedef std::function<void( void * )> cleanup_func_t;
     4
     5class guard_value_impl {
     6public:
     7        guard_value_impl() = default;
     8
     9        ~guard_value_impl() {
     10                while( !cleanups.empty() ) {
     11                        auto& cleanup = cleanups.top();
     12                        cleanup.func( cleanup.val );
     13                        cleanups.pop();
     14                }
     15        }
     16
     17        void push( cleanup_func_t && func, void* val ) {
     18                cleanups.emplace( std::move(func), val );
     19        }
     20
     21private:
     22        struct cleanup_t {
     23                cleanup_func_t func;
     24                void * val;
     25
     26                cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {}
     27        };
     28
     29        std::stack< cleanup_t > cleanups;
     30};
     31
     32typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;
    233
    334//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    73104#define FIELD_PTR( type, name )                                                                                                        \
    74105template<typename pass_type>                                                                                                           \
    75 static inline auto name##_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( &pass.name ) { return &pass.name; }  \
     106static inline auto name##_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( &pass.name ) { return &pass.name; } \
    76107                                                                                                                                       \
    77108template<typename pass_type>                                                                                                           \
     
    82113FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
    83114FIELD_PTR( bool, skip_children )
     115FIELD_PTR( at_cleanup_t, at_cleanup )
  • src/InitTweak/GenInit.cc

    r816d61c rf13ee31  
    1616#include <stack>
    1717#include <list>
     18
     19#include "InitTweak.h"
    1820#include "GenInit.h"
    19 #include "InitTweak.h"
     21
     22#include "Common/PassVisitor.h"
     23
    2024#include "SynTree/Declaration.h"
    21 #include "SynTree/Type.h"
    2225#include "SynTree/Expression.h"
    23 #include "SynTree/Statement.h"
    2426#include "SynTree/Initializer.h"
    2527#include "SynTree/Mutator.h"
     28#include "SynTree/Statement.h"
     29#include "SynTree/Type.h"
     30
    2631#include "SymTab/Autogen.h"
    2732#include "SymTab/Mangler.h"
     33
     34#include "GenPoly/DeclMutator.h"
    2835#include "GenPoly/PolyMutator.h"
    29 #include "GenPoly/DeclMutator.h"
    3036#include "GenPoly/ScopedSet.h"
     37
    3138#include "ResolvExpr/typeops.h"
    3239
     
    3744        }
    3845
    39         class ReturnFixer final : public GenPoly::PolyMutator {
     46        class ReturnFixer {
    4047          public:
    4148                /// consistently allocates a temporary variable for the return value
     
    4451                static void makeReturnTemp( std::list< Declaration * > &translationUnit );
    4552
    46                 typedef GenPoly::PolyMutator Parent;
    47                 using Parent::mutate;
    48                 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override;
    49                 virtual Statement * mutate( ReturnStmt * returnStmt ) override;
     53                void premutate( FunctionDecl *functionDecl );
     54                void premutate( ReturnStmt * returnStmt );
     55
     56                at_cleanup_t at_cleanup;
     57                std::list< Statement * > stmtsToAddBefore;
    5058
    5159          protected:
     
    129137
    130138        void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) {
    131                 ReturnFixer fixer;
     139                PassVisitor<ReturnFixer> fixer;
    132140                mutateAll( translationUnit, fixer );
    133141        }
    134142
    135         Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) {
     143        void ReturnFixer::premutate( ReturnStmt *returnStmt ) {
    136144                std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();
    137145                assert( returnVals.size() == 0 || returnVals.size() == 1 );
     
    144152                        construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) );
    145153                        construct->get_args().push_back( returnStmt->get_expr() );
    146                         stmtsToAdd.push_back(new ExprStmt(noLabels, construct));
     154                        stmtsToAddBefore.push_back(new ExprStmt(noLabels, construct));
    147155
    148156                        // return the retVal object
    149157                        returnStmt->set_expr( new VariableExpr( returnVals.front() ) );
    150158                } // if
    151                 return returnStmt;
    152         }
    153 
    154         DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) {
    155                 ValueGuard< FunctionType * > oldFtype( ftype );
    156                 ValueGuard< std::string > oldFuncName( funcName );
     159        }
     160
     161        void ReturnFixer::premutate( FunctionDecl *functionDecl ) {
     162                GuardValue( this, ftype );
     163                GuardValue( this, funcName );
    157164
    158165                ftype = functionDecl->get_functionType();
    159166                funcName = functionDecl->get_name();
    160                 return Parent::mutate( functionDecl );
    161167        }
    162168
Note: See TracChangeset for help on using the changeset viewer.