Changeset d60780c


Ignore:
Timestamp:
Jun 13, 2019, 8:28:13 AM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d76f32c, dc5072f
Parents:
d7a02ae (diff), 21300d7 (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
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rd7a02ae rd60780c  
    579579                                tgtInferParams[srcParam.first] = ParamEntry(
    580580                                        srcParam.second.decl,
     581                                        get<Declaration>().accept1(srcParam.second.declptr),
    581582                                        get<Type>().accept1(srcParam.second.actualType),
    582583                                        get<Type>().accept1(srcParam.second.formalType),
     
    20042005                                tgt[old.first] = ast::ParamEntry(
    20052006                                        old.second.decl,
     2007                                        getAccept1<ast::Decl>(old.second.declptr),
    20062008                                        getAccept1<ast::Type>(old.second.actualType),
    20072009                                        getAccept1<ast::Type>(old.second.formalType),
  • src/AST/Expr.hpp

    rd7a02ae rd60780c  
    3939struct ParamEntry {
    4040        UniqueId decl;
     41        ptr<Decl> declptr;
    4142        ptr<Type> actualType;
    4243        ptr<Type> formalType;
    4344        ptr<Expr> expr;
    4445
    45         ParamEntry() : decl( 0 ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}
    46         ParamEntry( UniqueId id, Type* actual, Type* formal, Expr* e )
    47         : decl( id ), actualType( actual ), formalType( formal ), expr( e ) {}
     46        ParamEntry() : decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}
     47        ParamEntry( UniqueId id, Decl * declptr, Type* actual, Type* formal, Expr* e )
     48        : decl( id ), declptr( declptr ), actualType( actual ), formalType( formal ), expr( e ) {}
    4849};
    4950
     
    137138                }
    138139
    139                 /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode 
     140                /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode
    140141                /// and the other is in `Params`.
    141142                void splice( InferUnion && o ) {
     
    145146
    146147                        if ( mode == Slots ){
    147                                 data.resnSlots.insert( 
     148                                data.resnSlots.insert(
    148149                                        data.resnSlots.end(), o.data.resnSlots.begin(), o.data.resnSlots.end() );
    149150                        } else if ( mode == Params ) {
  • src/GenPoly/Lvalue.cc

    rd7a02ae rd60780c  
    200200                                if(i == end) { return appExpr; }
    201201                                for ( auto p : unsafe_group_iterate( appExpr->args, ftype->parameters ) ) {
    202                                         if (i == end) break;
    203202                                        Expression *& arg = std::get<0>( p );
    204203                                        Type * formal = std::get<1>( p )->get_type();
     
    245244                                        }
    246245                                        ++i;
     246                                        if (i == end) break;
    247247                                }
    248248                        }
  • src/InitTweak/FixInit.cc

    rd7a02ae rd60780c  
    995995                        )
    996996
     997
     998                        // std::set_difference requires that the inputs be sorted.
     999                        lvars.sort();
     1000                        curVars.sort();
     1001
    9971002                        ObjectSet diff;
    9981003                        // S_L-S_G results in set of objects whose construction is skipped - it's an error if this set is non-empty
  • src/ResolvExpr/ResolveAssertions.cc

    rd7a02ae rd60780c  
    5050                UniqueId resnSlot;              ///< Slot for any recursive assertion IDs
    5151
    52                 AssnCandidate( const SymTab::Indexer::IdData& cdata, Type* adjType, TypeEnvironment&& env, 
    53                         AssertionSet&& have, AssertionSet&& need, OpenVarSet&& openVars, UniqueId resnSlot ) 
    54                 : cdata(cdata), adjType(adjType), env(std::move(env)), have(std::move(have)), 
     52                AssnCandidate( const SymTab::Indexer::IdData& cdata, Type* adjType, TypeEnvironment&& env,
     53                        AssertionSet&& have, AssertionSet&& need, OpenVarSet&& openVars, UniqueId resnSlot )
     54                : cdata(cdata), adjType(adjType), env(std::move(env)), have(std::move(have)),
    5555                        need(std::move(need)), openVars(std::move(openVars)), resnSlot(resnSlot) {}
    5656        };
     
    8686        using DeferList = std::vector<DeferItem>;
    8787
    88         /// Combo iterator that combines candidates into an output list, merging their environments. 
     88        /// Combo iterator that combines candidates into an output list, merging their environments.
    8989        /// Rejects an appended candidate if the environments cannot be merged.
    9090        class CandidateEnvMerger {
     
    9797                /// Indexer to use for merges
    9898                const SymTab::Indexer& indexer;
    99        
     99
    100100        public:
    101101                /// The merged environment/open variables and the list of candidates
     
    106106                        Cost cost;
    107107
    108                         OutType( const TypeEnvironment& env, const OpenVarSet& openVars, 
     108                        OutType( const TypeEnvironment& env, const OpenVarSet& openVars,
    109109                                const std::vector<DeferRef>& assns )
    110110                        : env(env), openVars(openVars), assns(assns), cost(Cost::infinity) {}
    111111                };
    112112
    113                 CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars, 
     113                CandidateEnvMerger( const TypeEnvironment& env, const OpenVarSet& openVars,
    114114                        const SymTab::Indexer& indexer )
    115115                : crnt(), envs{ env }, varSets{ openVars }, indexer(indexer) {}
     
    137137        };
    138138
    139         /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored 
     139        /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored
    140140        /// sums
    141141        struct CandidateCost {
     
    156156                        for ( const auto& assn : x.assns ) {
    157157                                // compute conversion cost from satisfying decl to assertion
    158                                 k += computeConversionCost( 
     158                                k += computeConversionCost(
    159159                                        assn.match.adjType, assn.decl->get_type(), indexer, x.env );
    160                                
     160
    161161                                // mark vars+specialization cost on function-type assertions
    162162                                FunctionType* func = GenPoly::getFunctionType( assn.match.cdata.id->get_type() );
    163163                                if ( ! func ) continue;
    164                                
     164
    165165                                for ( DeclarationWithType* formal : func->parameters ) {
    166166                                        k.decSpec( specCost( formal->get_type() ) );
     
    176176                        return k;
    177177                }
    178                
     178
    179179                /// compares elements by cost
    180180                bool operator() ( Element& a, Element& b ) const {
     
    206206                /// Updated resolution state with new need-list
    207207                ResnState( ResnState&& o, IterateFlag )
    208                 : alt(std::move(o.alt)), need(o.newNeed.begin(), o.newNeed.end()), newNeed(), deferred(), 
     208                : alt(std::move(o.alt)), need(o.newNeed.begin(), o.newNeed.end()), newNeed(), deferred(),
    209209                  inferred(std::move(o.inferred)), indexer(o.indexer) {}
    210210        };
    211211
    212212        /// Binds a single assertion, updating resolution state
    213         void bindAssertion( const DeclarationWithType* decl, AssertionSetValue info, Alternative& alt, 
     213        void bindAssertion( const DeclarationWithType* decl, AssertionSetValue info, Alternative& alt,
    214214                        AssnCandidate& match, InferCache& inferred ) {
    215                
     215
    216216                DeclarationWithType* candidate = match.cdata.id;
    217217                assertf( candidate->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() );
     
    224224                // place newly-inferred assertion in proper place in cache
    225225                inferred[ info.resnSlot ][ decl->get_uniqueId() ] = ParamEntry{
    226                                 candidate->get_uniqueId(), match.adjType->clone(), decl->get_type()->clone(),
     226                                candidate->get_uniqueId(), candidate->clone(), match.adjType->clone(), decl->get_type()->clone(),
    227227                                varExpr };
    228228        }
     
    263263
    264264                        // keep unifying candidates
    265                         if ( unify( assn.decl->get_type(), adjType, newEnv, newNeed, have, newOpenVars, 
     265                        if ( unify( assn.decl->get_type(), adjType, newEnv, newNeed, have, newOpenVars,
    266266                                        resn.indexer ) ) {
    267267                                // set up binding slot for recursive assertions
     
    274274                                }
    275275
    276                                 matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have), 
     276                                matches.emplace_back( cdata, adjType, std::move(newEnv), std::move(have),
    277277                                        std::move(newNeed), std::move(newOpenVars), crntResnSlot );
    278278                        } else {
     
    319319                                }
    320320                                InferredParams& inferParams = it->second;
    321                                
     321
    322322                                // place inferred parameters into proper place in expression
    323323                                for ( auto& entry : inferParams ) {
     
    373373                                                ss << (tabs-1) << "Could not satisfy assertion:\n";
    374374                                                assn.decl->print( ss, tabs );
    375                                                
     375
    376376                                                errors.emplace_back( ss.str() );
    377377                                                goto nextResn;
     
    403403                                        // resolve deferred assertions by mutual compatibility
    404404                                        std::vector<CandidateEnvMerger::OutType> compatible = filterCombos(
    405                                                 resn.deferred, 
     405                                                resn.deferred,
    406406                                                CandidateEnvMerger{ resn.alt.env, resn.alt.openVars, resn.indexer } );
    407407                                        // fail early if no mutually-compatible assertion satisfaction
     
    466466                        new_resns.clear();
    467467                }
    468                
     468
    469469                // exceeded recursion limit if reaches here
    470470                if ( out.empty() ) {
  • src/SynTree/ApplicationExpr.cc

    rd7a02ae rd60780c  
    2929
    3030ParamEntry::ParamEntry( const ParamEntry &other ) :
    31                 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )/*, inferParams( new InferredParams( *other.inferParams ) )*/ {
     31                decl( other.decl ), declptr( maybeClone( other.declptr ) ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )/*, inferParams( new InferredParams( *other.inferParams ) )*/ {
    3232}
    3333
    3434ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
    3535        if ( &other == this ) return *this;
    36         decl = other.decl;
     36        const_cast<UniqueId &>(decl) = other.decl;
     37        const_cast<Declaration * &>(declptr) = maybeClone( other.declptr );
    3738        // xxx - this looks like a memory leak
    38         actualType = maybeClone( other.actualType );
    39         formalType = maybeClone( other.formalType );
     39        const_cast<Type * &>(actualType) = maybeClone( other.actualType );
     40        const_cast<Type * &>(formalType) = maybeClone( other.formalType );
    4041        expr = maybeClone( other.expr );
    4142        // *inferParams = *other.inferParams;
     
    4445
    4546ParamEntry::~ParamEntry() {
     47        delete declptr;
    4648        delete actualType;
    4749        delete formalType;
     
    5052
    5153ParamEntry::ParamEntry( ParamEntry && other ) :
    52                 decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr )/*, inferParams( std::move( other.inferParams ) )*/ {
    53         other.actualType = nullptr;
    54         other.formalType = nullptr;
     54                decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr )/*, inferParams( std::move( other.inferParams ) )*/ {
     55        const_cast<Declaration * &>(other.declptr) = nullptr;
     56        const_cast<Type * &>(other.actualType) = nullptr;
     57        const_cast<Type * &>(other.formalType) = nullptr;
    5558        other.expr = nullptr;
    5659}
     
    5861ParamEntry & ParamEntry::operator=( ParamEntry && other ) {
    5962        if ( &other == this ) return *this;
     63        delete declptr;
    6064        delete actualType;
    6165        delete formalType;
    6266        delete expr;
    63         decl = other.decl;
    64         actualType = other.actualType;
    65         formalType = other.formalType;
     67        const_cast<UniqueId &>(decl) = other.decl;
     68        const_cast<Declaration * &>(declptr) = other.declptr;
     69        const_cast<Type * &>(actualType) = other.actualType;
     70        const_cast<Type * &>(formalType) = other.formalType;
    6671        expr = other.expr;
    67         other.actualType = nullptr;
    68         other.formalType = nullptr;
     72        const_cast<Declaration * &>(other.declptr) = nullptr;
     73        const_cast<Type * &>(other.actualType) = nullptr;
     74        const_cast<Type * &>(other.formalType) = nullptr;
    6975        other.expr = nullptr;
    7076        // inferParams = std::move( other.inferParams );
  • src/SynTree/Declaration.cc

    rd7a02ae rd60780c  
    2727
    2828static UniqueId lastUniqueId = 0;
    29 typedef std::map< UniqueId, Declaration* > IdMapType;
    30 static IdMapType idMap;
    3129
    3230Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
     
    4543        if ( uniqueId ) return;
    4644        uniqueId = ++lastUniqueId;
    47         idMap[ uniqueId ] = this;
    4845}
    49 
    50 Declaration *Declaration::declFromId( UniqueId id ) {
    51         IdMapType::const_iterator i = idMap.find( id );
    52         return i != idMap.end() ? i->second : 0;
    53 }
    54 
    55 void Declaration::dumpIds( std::ostream &os ) {
    56         for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {
    57                 os << i->first << " -> ";
    58                 i->second->printShort( os );
    59                 os << std::endl;
    60         } // for
    61 }
    62 
    6346
    6447AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
  • src/SynTree/Declaration.h

    rd7a02ae rd60780c  
    6868        virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0;
    6969
    70         static void dumpIds( std::ostream &os );
    71         static Declaration *declFromId( UniqueId id );
    72 
    7370        UniqueId uniqueId;
    7471        Type::StorageClasses storageClasses;
  • src/SynTree/Expression.cc

    rd7a02ae rd60780c  
    3838                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
    3939                        os << indent+1;
    40                         Declaration::declFromId( i->second.decl )->printShort( os, indent+1 );
     40                        assert(i->second.declptr);
     41                        i->second.declptr->printShort( os, indent+1 );
    4142                        os << std::endl;
    4243                        printInferParams( i->second.expr->inferParams, os, indent+1, level+1 );
  • src/SynTree/Expression.h

    rd7a02ae rd60780c  
    3939/// but subject to decay-to-pointer and type parameter renaming
    4040struct ParamEntry {
    41         ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 )/*, inferParams( new InferredParams )*/ {}
    42         ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr )/*, inferParams( new InferredParams )*/ {}
     41        ParamEntry(): decl( 0 ), declptr(nullptr), actualType( 0 ), formalType( 0 ), expr( 0 )/*, inferParams( new InferredParams )*/ {}
     42        ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr )
     43                : decl( decl ), declptr( declptr ), actualType( actualType ), formalType( formalType ), expr( expr )/*, inferParams( new InferredParams )*/ {
     44        }
    4345        ParamEntry( const ParamEntry & other );
    4446        ParamEntry( ParamEntry && other );
     
    4749        ParamEntry & operator=( ParamEntry && other );
    4850
    49         UniqueId decl;
    50         Type * actualType;
    51         Type * formalType;
     51        UniqueId const decl;
     52        Declaration * const declptr;
     53        Type * const actualType;
     54        Type * const formalType;
    5255        Expression * expr;
    5356        // std::unique_ptr< InferredParams > inferParams;
Note: See TracChangeset for help on using the changeset viewer.