Changeset 7fc7cdb


Ignore:
Timestamp:
Sep 27, 2017, 4:24:16 PM (7 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:
75626a1
Parents:
5ea7a22
git-author:
Rob Schluntz <rschlunt@…> (09/27/17 15:51:01)
git-committer:
Rob Schluntz <rschlunt@…> (09/27/17 16:24:16)
Message:

Add getThisParam and getThisType helpers for constructors and destructors

Location:
src/InitTweak
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r5ea7a22 r7fc7cdb  
    270270        }
    271271
     272        Type * getThisType( FunctionType * ftype ) {
     273                assertf( ftype, "getThisType: nullptr ftype" );
     274                ObjectDecl * thisParam = getThisParam( ftype );
     275                ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( thisParam->type );
     276                return refType->base;
     277        }
     278
     279        ObjectDecl * getThisParam( FunctionType * ftype ) {
     280                assertf( ftype, "getThisParam: nullptr ftype" );
     281                auto & params = ftype->parameters;
     282                assertf( ! params.empty(), "getThisParam: ftype with 0 parameters: %s", toString( ftype ).c_str() );
     283                return strict_dynamic_cast< ObjectDecl * >( params.front() );
     284        }
     285
    272286        bool tryConstruct( DeclarationWithType * dwt ) {
    273287                ObjectDecl * objDecl = dynamic_cast< ObjectDecl * >( dwt );
  • src/InitTweak/InitTweak.h

    r5ea7a22 r7fc7cdb  
    2929        FunctionDecl * isCopyConstructor( Declaration * decl );
    3030        FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
     31
     32        /// returns the base type of the first parameter to a constructor/destructor/assignment function
     33        Type * getThisType( FunctionType * ftype );
     34
     35        /// returns the first parameter of a constructor/destructor/assignment function
     36        ObjectDecl * getThisParam( FunctionType * ftype );
    3137
    3238        /// transform Initializer into an argument list that can be passed to a call expression
Note: See TracChangeset for help on using the changeset viewer.