Changeset f7a4f89 for src/InitTweak


Ignore:
Timestamp:
Nov 24, 2017, 9:02:40 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
cf966b5
Parents:
88ef2af (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/InitTweak
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r88ef2af rf7a4f89  
    393393                        if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types
    394394
    395                         // type may involve type variables, so apply type substitution to get temporary variable's actual type.
     395                        // type may involve type variables, so apply type substitution to get temporary variable's actual type,
     396                        // since result type may not be substituted (e.g., if the type does not appear in the parameter list)
    396397                        // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T).
    397                         result = result->clone();
    398398                        env->applyFree( result );
    399399                        ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr );
     
    570570
    571571                        if ( returnDecl ) {
    572                                 UntypedExpr * assign = new UntypedExpr( new NameExpr( "?=?" ) );
    573                                 assign->get_args().push_back( new VariableExpr( returnDecl ) );
    574                                 assign->get_args().push_back( callExpr );
    575                                 // know the result type of the assignment is the type of the LHS (minus the pointer), so
    576                                 // add that onto the assignment expression so that later steps have the necessary information
    577                                 assign->set_result( returnDecl->get_type()->clone() );
    578 
     572                                ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr );
    579573                                Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
    580574                                // move env from callExpr to retExpr
     
    943937                }
    944938
    945                 void addIds( SymTab::Indexer & indexer, const std::list< DeclarationWithType * > & decls ) {
    946                         for ( auto d : decls ) {
    947                                 indexer.addId( d );
    948                         }
    949                 }
    950 
    951                 void addTypes( SymTab::Indexer & indexer, const std::list< TypeDecl * > & tds ) {
    952                         for ( auto td : tds ) {
    953                                 indexer.addType( td );
    954                                 addIds( indexer, td->assertions );
    955                         }
    956                 }
    957 
    958939                void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
    959940                        GuardValue( function );
     
    1012993                                // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors
    1013994                                auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } );
    1014                                 addTypes( indexer, function->type->forall );
    1015                                 addIds( indexer, function->type->returnVals );
    1016                                 addIds( indexer, function->type->parameters );
     995                                indexer.addFunctionType( function->type );
    1017996
    1018997                                // need to iterate through members in reverse in order for
     
    10291008                                        // insert and resolve default/copy constructor call for each field that's unhandled
    10301009                                        std::list< Statement * > stmt;
    1031                                         Expression * arg2 = 0;
     1010                                        Expression * arg2 = nullptr;
    10321011                                        if ( isCopyConstructor( function ) ) {
    10331012                                                // if copy ctor, need to pass second-param-of-this-function.field
     
    11611140                        assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 );
    11621141
    1163                         // 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.
    1164                         ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr );
    1165                         declsToAddBefore.push_back( tmp );
    1166 
    11671142                        // xxx - this can be TupleAssignExpr now. Need to properly handle this case.
    11681143                        ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() );
     
    11701145                        ctorExpr->set_callExpr( nullptr );
    11711146                        ctorExpr->set_env( nullptr );
     1147
     1148                        // 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.
     1149                        ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr );
     1150                        declsToAddBefore.push_back( tmp );
    11721151                        delete ctorExpr;
    11731152
  • src/InitTweak/InitTweak.cc

    r88ef2af rf7a4f89  
    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
     
    524525        }
    525526
     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
    526546        class ConstExprChecker : public Visitor {
    527547        public:
  • src/InitTweak/InitTweak.h

    r88ef2af rf7a4f89  
    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.