Changeset f5e81d1


Ignore:
Timestamp:
Sep 8, 2016, 4:50:55 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
add7117
Parents:
cd14861 (diff), 4563a95 (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' into tuples

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    rcd14861 rf5e81d1  
    1818
    1919#include <cctype>
     20#include <algorithm>
    2021#include <iostream>
    2122#include <iterator>
     
    111112                return tmp;
    112113        } // if
    113 }
    114 
    115 template< class T, typename ResultType, ResultType( T::* memfunc )() >
    116 ResultType dispatch( T *pT ) {
    117         return (pT->*memfunc)();
    118114}
    119115
     
    162158}
    163159
    164 template< class Constructed, typename Arg >
    165 Constructed *ctor( Arg arg ) {
    166         Constructed *c = new Constructed( arg );
    167         return c;
    168 }
    169 
    170 template< class Constructed, typename Arg >
    171 Constructed ctor_noptr( Arg arg ) {
    172         return Constructed( arg );
    173 }
    174 
    175160template< typename T >
    176161void replace( std::list< T > &org, typename std::list< T >::iterator pos, std::list< T > &with ) {
     
    185170}
    186171
    187 template< typename T1, typename T2 >
    188 T2 *cast_ptr( T1 *from ) {
    189         return dynamic_cast< T2 * >( from );
    190 }
    191 
    192 template< class Exception, typename Arg >
    193 void inline assert_throw( bool pred, Arg arg ) {
    194         if (pred) throw Exception( arg );
    195 }
    196 
    197 template< typename T >
    198 struct is_null_pointer {
    199         bool operator()( const T *ptr ) { return ( ptr == 0 ); }
    200 };
    201 
    202 template< class InputIterator, class OutputIterator, class Predicate >
    203 void filter(InputIterator begin, InputIterator end, OutputIterator out, Predicate pred) {
    204         while ( begin++ != end )
    205                 if ( pred(*begin) ) *out++ = *begin;
    206 
    207         return;
    208 }
    209 
    210 template< class InputIterator1, class InputIterator2, class OutputIterator >
    211 void zip( InputIterator1 b1, InputIterator1 e1, InputIterator2 b2, InputIterator2 e2, OutputIterator out ) {
    212         while ( b1 != e1 && b2 != e2 )
    213                 *out++ = std::pair<typename InputIterator1::value_type, typename InputIterator2::value_type>(*b1++, *b2++);
     172template< typename... Args >
     173auto filter(Args&&... args) -> decltype(std::copy_if(std::forward<Args>(args)...)) {
     174  return std::copy_if(std::forward<Args>(args)...);
     175}
     176
     177template< typename... Args >
     178auto zip(Args&&... args) -> decltype(zipWith(std::forward<Args>(args)..., std::make_pair)) {
     179  return zipWith(std::forward<Args>(args)..., std::make_pair);
    214180}
    215181
     
    221187
    222188// it's nice to actually be able to increment iterators by an arbitrary amount
    223 template< typename Iterator >
    224 Iterator operator+(Iterator i, int inc) {
    225         while ( inc > 0 ) {
    226                 ++i;
    227                 --inc;
    228         }
    229         return i;
     189template< class InputIt, class Distance >
     190InputIt operator+( InputIt it, Distance n ) {
     191        advance(it, n);
     192        return it;
    230193}
    231194
     
    246209        warn_single( params... );
    247210}
     211
     212// -----------------------------------------------------------------------------
     213// Ref Counted Singleton class
     214// Objects that inherit from this class will have at most one reference to it
     215// but if all references die, the object will be deleted.
    248216
    249217template< typename ThisType >
     
    265233std::weak_ptr<ThisType> RefCountSingleton<ThisType>::global_instance;
    266234
     235// -----------------------------------------------------------------------------
    267236// RAII object to regulate "save and restore" behaviour, e.g.
    268237// void Foo::bar() {
     
    279248};
    280249
     250// -----------------------------------------------------------------------------
     251// Helper struct and function to support
     252// for ( val : reverseIterate( container ) ) {}
     253// syntax to have a for each that iterates backwards
     254
    281255template< typename T >
    282256struct reverseIterate_t {
  • src/InitTweak/InitTweak.cc

    rcd14861 rf5e81d1  
    304304
    305305        namespace {
    306                 VariableExpr * getCalledFunction( ApplicationExpr * appExpr ) {
    307                         assert( appExpr );
    308                         // xxx - it's possible this can be other things, e.g. MemberExpr, so this is insufficient
    309                         return dynamic_cast< VariableExpr * >( appExpr->get_function() );
     306                DeclarationWithType * getCalledFunction( Expression * expr ) {
     307                        assert( expr );
     308                        if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) {
     309                                return varExpr->get_var();
     310                        } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( expr ) ) {
     311                                return memberExpr->get_member();
     312                        } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
     313                                return getCalledFunction( castExpr->get_arg() );
     314                        }
     315                        return nullptr;
    310316                }
    311317        }
     
    314320                ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr );
    315321                if ( ! appExpr ) return NULL;
    316                 VariableExpr * function = getCalledFunction( appExpr );
     322                DeclarationWithType * function = getCalledFunction( appExpr->get_function() );
    317323                assert( function );
    318324                // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor
    319325                // will call all member dtors, and some members may have a user defined dtor.
    320                 return function->get_var()->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL;
     326                return function->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL;
    321327        }
    322328
     
    379385                        }       else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( func ) ) {
    380386                                return funcName( castExpr->get_arg() );
     387                        } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( func ) ) {
     388                                return memberExpr->get_member()->get_name();
    381389                        } else {
    382390                                assert( false && "Unexpected expression type being called as a function in call expression" );
     
    472480        bool isConstructor( const std::string & str ) { return str == "?{}"; }
    473481        bool isDestructor( const std::string & str ) { return str == "^?{}"; }
     482        bool isAssignment( const std::string & str ) { return str == "?=?"; }
    474483        bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); }
    475 
    476         FunctionDecl * isCopyConstructor( Declaration * decl ) {
     484        bool isCtorDtorAssign( const std::string & str ) { return isCtorDtor( str ) || isAssignment( str ); }
     485
     486        FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ) {
    477487                FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl );
    478488                if ( ! function ) return 0;
    479                 if ( ! isConstructor( function->get_name() ) ) return 0;
     489                if ( function->get_name() != fname ) return 0;
    480490                FunctionType * ftype = function->get_functionType();
    481491                if ( ftype->get_parameters().size() != 2 ) return 0;
     
    486496                assert( ptrType );
    487497
    488                 if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) {
     498                if ( ResolvExpr::typesCompatibleIgnoreQualifiers( ptrType->get_base(), t2, SymTab::Indexer() ) ) {
    489499                        return function;
    490500                } else {
    491                         return 0;
    492                 }
     501                        return nullptr;
     502                }
     503        }
     504
     505        FunctionDecl * isCopyConstructor( Declaration * decl ) {
     506                return isCopyFunction( decl, "?{}" );
    493507        }
    494508}
  • src/InitTweak/InitTweak.h

    rcd14861 rf5e81d1  
    2828        bool isConstructor( const std::string & );
    2929        bool isDestructor( const std::string & );
     30        bool isAssignment( const std::string & );
    3031        bool isCtorDtor( const std::string & );
     32        bool isCtorDtorAssign( const std::string & );
    3133
    3234        FunctionDecl * isCopyConstructor( Declaration * decl );
     35        FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
    3336
    3437        /// transform Initializer into an argument list that can be passed to a call expression
  • src/SymTab/Indexer.cc

    rcd14861 rf5e81d1  
    105105
    106106        void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const {
    107                 // only need to perform this step for constructors and destructors
    108                 if ( ! InitTweak::isCtorDtor( id ) ) return;
     107                // only need to perform this step for constructors, destructors, and assignment functions
     108                if ( ! InitTweak::isCtorDtorAssign( id ) ) return;
    109109
    110110                // helpful data structure
     
    127127                                bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() );
    128128                                bool isDefaultFunc = function->get_functionType()->get_parameters().size() == 1;
    129                                 bool isCopyFunc = InitTweak::isCopyConstructor( function );
     129                                bool isCopyFunc = InitTweak::isCopyFunction( function, function->get_name() );
    130130                                decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultFunc, isCopyFunc } );
    131131                                userDefinedFunc = userDefinedFunc || isUserDefinedFunc;
Note: See TracChangeset for help on using the changeset viewer.