Changeset 77971f6 for src/ResolvExpr


Ignore:
Timestamp:
Oct 27, 2016, 3:24:02 PM (9 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:
3f0c6a5
Parents:
a1e67dd
git-author:
Rob Schluntz <rschlunt@…> (10/27/16 15:11:00)
git-committer:
Rob Schluntz <rschlunt@…> (10/27/16 15:24:02)
Message:

resolve ctor/dtors for UniqueExprs

Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    ra1e67dd r77971f6  
    4141#include "Common/utility.h"
    4242#include "InitTweak/InitTweak.h"
     43#include "InitTweak/GenInit.h"
    4344#include "ResolveTypeof.h"
    4445
     
    207208        }
    208209
     210        // std::unordered_map< Expression *, UniqueExpr * > ;
     211
    209212        template< typename StructOrUnionType >
    210213        void AlternativeFinder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) {
    211 
    212214                // by this point, member must be a name expr
    213215                NameExpr * nameExpr = safe_dynamic_cast< NameExpr * >( member );
     
    434436                // flatten actuals so that each actual has an atomic (non-tuple) type
    435437                AltList exploded;
    436                 Tuples::explode( actuals, back_inserter( exploded ) );
     438                Tuples::explode( actuals, indexer, back_inserter( exploded ) );
    437439
    438440                AltList::iterator actualExpr = exploded.begin();
     
    10551057
    10561058        void AlternativeFinder::visit( UniqueExpr *unqExpr ) {
     1059                // this won't work because the unqExprs wont share an expression anymore...
    10571060                AlternativeFinder finder( indexer, env );
    10581061                finder.findWithAdjustment( unqExpr->get_expr() );
    10591062                for ( Alternative & alt : finder.alternatives ) {
    1060                         // xxx - it's possible that this won't always do the right thing, i.e. two UniqueExprs
    1061                         // with the same ID may resolve to different expressions. If this ever happens, it might be necessary
    1062                         // to try to select an alternative here (i.e. error is there is not a unique min-cost expression).
    1063                         // One other thought is to to resolve each ID once and map the IDs to resolved expressions,
    1064                         // but this isn't as simple as it sounds since the alternative is not selected here, meaning it might
    1065                         // require complicated tracking throughout the system.
    1066 
    1067                         // brand the new UniqueExprs with the same id so that they are recognized as the same expression by the expansion pass
    1068                         alternatives.push_back( Alternative( new UniqueExpr( alt.expr->clone(), unqExpr->get_id() ), env, Cost::zero ) );
     1063                        // xxx - attach a resolved ConstructorInit node?
     1064                        // xxx - is it possible to make the objDecl's type const?
     1065                        static UniqueName tempNamer( "_unq_expr_" );
     1066                        ObjectDecl * objDecl = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, alt.expr->get_result()->clone(), nullptr );
     1067                        // must be done on two lines because genCtorInit accesses objDecl's fields
     1068                        objDecl->set_init( InitTweak::genCtorInit( objDecl ) );
     1069
     1070                        UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr->clone(), unqExpr->get_id() );
     1071                        newUnqExpr->set_object( objDecl );
     1072
     1073                        resolveObject( indexer, objDecl );
     1074
     1075                        alternatives.push_back( Alternative( newUnqExpr, env, Cost::zero ) );
    10691076                }
    10701077        }
  • src/ResolvExpr/AlternativeFinder.h

    ra1e67dd r77971f6  
    9595        Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer, TypeEnvironment &env );
    9696
     97        void resolveObject( const SymTab::Indexer & indexer, ObjectDecl * objectDecl );
     98
    9799        template< typename InputIterator, typename OutputIterator >
    98100        void findMinCost( InputIterator begin, InputIterator end, OutputIterator out ) {
  • src/ResolvExpr/Resolver.cc

    ra1e67dd r77971f6  
    3535        class Resolver : public SymTab::Indexer {
    3636          public:
    37                 Resolver() : SymTab::Indexer( false ), switchType( 0 ) {}
     37                Resolver() : SymTab::Indexer( false ) {}
     38                Resolver( const SymTab::Indexer & indexer ) : SymTab::Indexer( indexer ) {}
    3839
    3940                virtual void visit( FunctionDecl *functionDecl );
     
    6869          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
    6970          void fallbackInit( ConstructorInit * ctorInit );
    70                 Type * functionReturn;
    71                 Type *initContext;
    72                 Type *switchType;
     71                Type * functionReturn = nullptr;
     72                Type *initContext = nullptr;
     73                Type *switchType = nullptr;
    7374                bool inEnumDecl = false;
    7475        };
     
    532533        }
    533534
     535        void resolveObject( const SymTab::Indexer & indexer, ObjectDecl * objectDecl ) {
     536                Resolver resolver( indexer );
     537                objectDecl->accept( resolver );
     538        }
     539
    534540        void Resolver::visit( ConstructorInit *ctorInit ) {
    535541                // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
Note: See TracChangeset for help on using the changeset viewer.