Changeset 4d4882a


Ignore:
Timestamp:
Sep 1, 2016, 4:53:22 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, 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:
44f6341
Parents:
fba44f8
Message:

implicitly insert missing copy constructors when appropriate, update test output

Location:
src
Files:
3 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    rfba44f8 r4d4882a  
    787787                                        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    788788                                        deref->get_args().push_back( new VariableExpr( thisParam ) );
    789                                         InitExpander srcParam( (Initializer *)NULL ); // xxx - if copy ctor, need to pass appropriate argument - second param of this function dot member
     789
     790                                        Expression * arg2 = 0;
     791                                        if ( isCopyConstructor( function ) ) {
     792                                                // if copy ctor, need to pass second-param-of-this-function.member
     793                                                std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters();
     794                                                assert( params.size() == 2 );
     795                                                arg2 = new MemberExpr( member, new VariableExpr( params.back() ) );
     796                                        }
     797                                        InitExpander srcParam( arg2 );
    790798                                        SymTab::genImplicitCall( srcParam, new MemberExpr( member, deref ), function->get_name(), back_inserter( stmt ), member, isCtor );
    791799
     
    832840                                        handleFirstParam( firstParam );
    833841                                }
    834                         } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) {
    835                                 // forgive use of intrinsic assignment to construct, since instrinsic constructors
    836                                 // codegen as assignment anyway.
    837                                 assert( appExpr->get_args().size() == 2 );
    838                                 handleFirstParam( appExpr->get_args().front() );
    839842                        }
    840843
  • src/InitTweak/InitTweak.cc

    rfba44f8 r4d4882a  
    77#include "SynTree/Attribute.h"
    88#include "GenPoly/GenPoly.h"
     9#include "ResolvExpr/typeops.h"
    910
    1011namespace InitTweak {
     
    439440        bool isDestructor( const std::string & str ) { return str == "^?{}"; }
    440441        bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); }
     442
     443        FunctionDecl * isCopyConstructor( Declaration * decl ) {
     444                FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl );
     445                if ( ! function ) return 0;
     446                if ( ! isConstructor( function->get_name() ) ) return 0;
     447                FunctionType * ftype = function->get_functionType();
     448                if ( ftype->get_parameters().size() != 2 ) return 0;
     449
     450                Type * t1 = ftype->get_parameters().front()->get_type();
     451                Type * t2 = ftype->get_parameters().back()->get_type();
     452                PointerType * ptrType = dynamic_cast< PointerType * > ( t1 );
     453                assert( ptrType );
     454
     455                if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) {
     456                        return function;
     457                } else {
     458                        return 0;
     459                }
     460        }
    441461}
  • src/InitTweak/InitTweak.h

    rfba44f8 r4d4882a  
    2929        bool isDestructor( const std::string & );
    3030        bool isCtorDtor( const std::string & );
     31
     32        FunctionDecl * isCopyConstructor( Declaration * decl );
    3133
    3234        /// transform Initializer into an argument list that can be passed to a call expression
  • src/SynTree/FunctionDecl.cc

    rfba44f8 r4d4882a  
    2121#include "Attribute.h"
    2222#include "Common/utility.h"
     23#include "InitTweak/InitTweak.h"
    2324
    2425FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
  • src/tests/Makefile.am

    rfba44f8 r4d4882a  
    6262        ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
    6363
    64 ctorWarnings: ctorWarnings.c
    65         ${CC} ${CFALGS} -CFA -XCFA -p ${<} -o ${@}
     64memberCtors-ERR1: memberCtors.c
     65        ${CC} ${CFALGS} -DERR1 ${<} -o ${@}
    6666
  • src/tests/Makefile.in

    rfba44f8 r4d4882a  
    670670        ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
    671671
    672 ctorWarnings: ctorWarnings.c
    673         ${CC} ${CFALGS} -CFA -XCFA -p ${<} -o ${@}
     672memberCtors-ERR1: memberCtors.c
     673        ${CC} ${CFALGS} -DERR1 ${<} -o ${@}
    674674
    675675# Tell versions [3.59,3.63) of GNU make to not export all variables.
Note: See TracChangeset for help on using the changeset viewer.