Changeset c0d00b6 for src/InitTweak


Ignore:
Timestamp:
Nov 25, 2017, 3:22:18 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c6e2c18
Parents:
9d06142 (diff), 3de176d (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 cleanup-dtors

Location:
src/InitTweak
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r9d06142 rc0d00b6  
    396396                        if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types
    397397
    398                         // type may involve type variables, so apply type substitution to get temporary variable's actual type.
     398                        // type may involve type variables, so apply type substitution to get temporary variable's actual type,
     399                        // since result type may not be substituted (e.g., if the type does not appear in the parameter list)
    399400                        // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T).
    400                         result = result->clone();
    401401                        env->applyFree( result );
    402402                        ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr );
     
    573573
    574574                        if ( returnDecl ) {
    575                                 UntypedExpr * assign = new UntypedExpr( new NameExpr( "?=?" ) );
    576                                 assign->get_args().push_back( new VariableExpr( returnDecl ) );
    577                                 assign->get_args().push_back( callExpr );
    578                                 // know the result type of the assignment is the type of the LHS (minus the pointer), so
    579                                 // add that onto the assignment expression so that later steps have the necessary information
    580                                 assign->set_result( returnDecl->get_type()->clone() );
    581 
     575                                ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr );
    582576                                Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
    583577                                // move env from callExpr to retExpr
     
    937931                }
    938932
    939                 void addIds( SymTab::Indexer & indexer, const std::list< DeclarationWithType * > & decls ) {
    940                         for ( auto d : decls ) {
    941                                 indexer.addId( d );
    942                         }
    943                 }
    944 
    945                 void addTypes( SymTab::Indexer & indexer, const std::list< TypeDecl * > & tds ) {
    946                         for ( auto td : tds ) {
    947                                 indexer.addType( td );
    948                                 addIds( indexer, td->assertions );
    949                         }
    950                 }
    951 
    952933                void GenStructMemberCalls::previsit( StructDecl * structDecl ) {
    953934                        if ( ! dtorStruct && structDecl->name == "__Destructor" ) {
     
    1018999                                // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors
    10191000                                auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } );
    1020                                 addTypes( indexer, function->type->forall );
    1021                                 addIds( indexer, function->type->returnVals );
    1022                                 addIds( indexer, function->type->parameters );
     1001                                indexer.addFunctionType( function->type );
    10231002
    10241003                                // need to iterate through members in reverse in order for
     
    10351014                                        // insert and resolve default/copy constructor call for each field that's unhandled
    10361015                                        std::list< Statement * > stmt;
    1037                                         Expression * arg2 = 0;
     1016                                        Expression * arg2 = nullptr;
    10381017                                        if ( isCopyConstructor( function ) ) {
    10391018                                                // if copy ctor, need to pass second-param-of-this-function.field
     
    11881167                        assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 );
    11891168
    1190                         // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
    1191                         ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr );
    1192                         declsToAddBefore.push_back( tmp );
    1193 
    11941169                        // xxx - this can be TupleAssignExpr now. Need to properly handle this case.
    11951170                        ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() );
     
    11971172                        ctorExpr->set_callExpr( nullptr );
    11981173                        ctorExpr->set_env( nullptr );
     1174
     1175                        // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
     1176                        ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr );
     1177                        declsToAddBefore.push_back( tmp );
    11991178                        delete ctorExpr;
    12001179
  • src/InitTweak/InitTweak.cc

    r9d06142 rc0d00b6  
    1212#include "Parser/LinkageSpec.h"    // for Spec, isBuiltin, Intrinsic
    1313#include "ResolvExpr/typeops.h"    // for typesCompatibleIgnoreQualifiers
     14#include "SymTab/Autogen.h"
    1415#include "SymTab/Indexer.h"        // for Indexer
    1516#include "SynTree/Attribute.h"     // for Attribute
     
    9899        class InitExpander::ExpanderImpl {
    99100        public:
     101                virtual ~ExpanderImpl() = default;
    100102                virtual std::list< Expression * > next( std::list< Expression * > & indices ) = 0;
    101103                virtual Statement * buildListInit( UntypedExpr * callExpr, std::list< Expression * > & indices ) = 0;
     
    105107        public:
    106108                InitImpl( Initializer * init ) : init( init ) {}
     109                virtual ~InitImpl() = default;
    107110
    108111                virtual std::list< Expression * > next( __attribute((unused)) std::list< Expression * > & indices ) {
     
    121124        public:
    122125                ExprImpl( Expression * expr ) : arg( expr ) {}
    123 
    124                 ~ExprImpl() { delete arg; }
     126                virtual ~ExprImpl() { delete arg; }
    125127
    126128                virtual std::list< Expression * > next( std::list< Expression * > & indices ) {
     
    523525        }
    524526
     527        ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src ) {
     528                static FunctionDecl * assign = nullptr;
     529                if ( ! assign ) {
     530                        // temporary? Generate a fake assignment operator to represent bitwise assignments.
     531                        // This operator could easily exist as a real function, but it's tricky because nothing should resolve to this function.
     532                        TypeDecl * td = new TypeDecl( "T", noStorageClasses, nullptr, TypeDecl::Dtype, true );
     533                        assign = new FunctionDecl( "?=?", noStorageClasses, LinkageSpec::Intrinsic, SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr );
     534                }
     535                if ( dynamic_cast< ReferenceType * >( dst->result ) ) {
     536                        dst = new AddressExpr( dst );
     537                } else {
     538                        dst = new CastExpr( dst, new ReferenceType( noQualifiers, dst->result->clone() ) );
     539                }
     540                if ( dynamic_cast< ReferenceType * >( src->result ) ) {
     541                        src = new CastExpr( src, new ReferenceType( noQualifiers, src->result->stripReferences()->clone() ) );
     542                }
     543                return new ApplicationExpr( VariableExpr::functionPointer( assign ), { dst, src } );
     544        }
     545
    525546        class ConstExprChecker : public Visitor {
    526547        public:
  • src/InitTweak/InitTweak.h

    r9d06142 rc0d00b6  
    3535        /// returns the first parameter of a constructor/destructor/assignment function
    3636        ObjectDecl * getParamThis( FunctionType * ftype );
     37
     38        /// generate a bitwise assignment operation.
     39        ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src );
    3740
    3841        /// transform Initializer into an argument list that can be passed to a call expression
Note: See TracChangeset for help on using the changeset viewer.