Changeset 65197c2 for src/SymTab


Ignore:
Timestamp:
Dec 5, 2017, 2:17:17 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:
971d9f2, a85e44c, c13e8dc8
Parents:
12d2dc8 (diff), 866f560 (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/SymTab
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r12d2dc8 r65197c2  
    4040
    4141namespace SymTab {
    42         typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable;
     42        std::ostream & operator<<( std::ostream & out, const Indexer::IdData & data ) {
     43                return out << "(" << data.id << "," << data.baseExpr << ")";
     44        }
     45
     46        typedef std::unordered_map< std::string, Indexer::IdData > MangleTable;
    4347        typedef std::unordered_map< std::string, MangleTable > IdTable;
    4448        typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable;
     
    97101        }
    98102
    99         void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const {
     103        void Indexer::removeSpecialOverrides( const std::string &id, std::list< IdData > & out ) const {
    100104                // only need to perform this step for constructors, destructors, and assignment functions
    101105                if ( ! CodeGen::isCtorDtorAssign( id ) ) return;
     
    104108                struct ValueType {
    105109                        struct DeclBall {
    106                                 FunctionDecl * decl;
     110                                IdData decl;
    107111                                bool isUserDefinedFunc; // properties for this particular decl
    108112                                bool isDefaultCtor;
     
    120124                        // another FunctionDecl for the current type was found - determine
    121125                        // if it has special properties and update data structure accordingly
    122                         ValueType & operator+=( FunctionDecl * function ) {
     126                        ValueType & operator+=( IdData data ) {
     127                                DeclarationWithType * function = data.id;
    123128                                bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() );
    124129                                bool isDefaultCtor = InitTweak::isDefaultConstructor( function );
    125130                                bool isDtor = InitTweak::isDestructor( function );
    126131                                bool isCopyFunc = InitTweak::isCopyFunction( function, function->get_name() );
    127                                 decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } );
     132                                decls.push_back( DeclBall{ data, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } );
    128133                                existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc;
    129134                                existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) );
     
    135140                }; // ValueType
    136141
    137                 std::list< DeclarationWithType * > copy;
     142                std::list< IdData > copy;
    138143                copy.splice( copy.end(), out );
    139144
    140145                // organize discovered declarations by type
    141146                std::unordered_map< std::string, ValueType > funcMap;
    142                 for ( DeclarationWithType * decl : copy ) {
    143                         if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) {
     147                for ( auto decl : copy ) {
     148                        if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl.id ) ) {
    144149                                std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters();
    145150                                assert( ! params.empty() );
     
    147152                                Type * base = InitTweak::getPointerBase( params.front()->get_type() );
    148153                                assert( base );
    149                                 funcMap[ Mangler::mangle( base ) ] += function;
     154                                funcMap[ Mangler::mangle( base ) ] += decl;
    150155                        } else {
    151156                                out.push_back( decl );
     
    164169                                bool noUserDefinedFunc = ! val.existsUserDefinedFunc;
    165170                                bool isUserDefinedFunc = ball.isUserDefinedFunc;
    166                                 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides
     171                                bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl.id->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides
    167172                                bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator
    168173                                bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor;
     
    219224        }
    220225
    221         void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
     226        void Indexer::lookupId( const std::string &id, std::list< IdData > &out ) const {
    222227                std::unordered_set< std::string > foundMangleNames;
    223228
     
    289294                        const MangleTable &mangleTable = decls->second;
    290295                        MangleTable::const_iterator decl = mangleTable.find( mangleName );
    291                         if ( decl != mangleTable.end() ) return decl->second;
     296                        if ( decl != mangleTable.end() ) return decl->second.id;
    292297                }
    293298
     
    304309                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    305310                                // check for C decls with the same name, skipping those with a compatible type (by mangleName)
    306                                 if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first != mangleName ) return true;
     311                                if ( ! LinkageSpec::isMangled( decl->second.id->get_linkage() ) && decl->first != mangleName ) return true;
    307312                        }
    308313                }
     
    321326                                // check for C decls with the same name, skipping
    322327                                // those with an incompatible type (by mangleName)
    323                                 if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first == mangleName ) return true;
     328                                if ( ! LinkageSpec::isMangled( decl->second.id->get_linkage() ) && decl->first == mangleName ) return true;
    324329                        }
    325330                }
     
    403408        }
    404409
    405         void Indexer::addId( DeclarationWithType *decl ) {
     410        void Indexer::addId( DeclarationWithType *decl, Expression * baseExpr ) {
    406411                debugPrint( "Adding Id " << decl->name << std::endl );
    407412                makeWritable();
     
    439444
    440445                // add to indexer
    441                 tables->idTable[ name ][ mangleName ] = decl;
     446                tables->idTable[ name ][ mangleName ] = { decl, baseExpr };
    442447                ++tables->size;
    443448        }
     
    563568                        if ( ! addedDeclConflicts( existing->second, decl ) ) {
    564569                                existing->second = decl;
     570                        }
     571                }
     572        }
     573
     574        void Indexer::addWith( WithStmt * stmt ) {
     575                for ( Expression * expr : stmt->exprs ) {
     576                        if ( expr->result ) {
     577                                AggregateDecl * aggr = expr->result->stripReferences()->getAggr();
     578                                assertf( aggr, "WithStmt expr has non-aggregate type: %s", toString( expr->result ).c_str() );
     579
     580                                for ( Declaration * decl : aggr->members ) {
     581                                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     582                                                addId( dwt, expr );
     583                                        }
     584                                }
    565585                        }
    566586                }
     
    645665
    646666        }
     667
     668        Expression * Indexer::IdData::combine() const {
     669                if ( baseExpr ) {
     670                        Expression * base = baseExpr->clone();
     671                        ResolvExpr::referenceToRvalueConversion( base );
     672                        Expression * ret = new MemberExpr( id, base );
     673                        // xxx - this introduces hidden environments, for now remove them.
     674                        // std::swap( base->env, ret->env );
     675                        delete base->env;
     676                        base->env = nullptr;
     677                        return ret;
     678                } else {
     679                        return new VariableExpr( id );
     680                }
     681        }
    647682} // namespace SymTab
    648683
  • src/SymTab/Indexer.h

    r12d2dc8 r65197c2  
    3939                void leaveScope();
    4040
     41                struct IdData {
     42                        DeclarationWithType * id;
     43                        Expression * baseExpr; // WithExpr
     44
     45                        Expression * combine() const;
     46                };
     47
    4148                /// Gets all declarations with the given ID
    42                 void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const;
     49                void lookupId( const std::string &id, std::list< IdData > &out ) const;
    4350                /// Gets the top-most type declaration with the given ID
    4451                NamedTypeDecl *lookupType( const std::string &id ) const;
     
    6774                TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const;
    6875
    69                 void addId( DeclarationWithType *decl );
     76                void addId( DeclarationWithType *decl, Expression * baseExpr = nullptr );
    7077                void addType( NamedTypeDecl *decl );
    7178                void addStruct( const std::string &id );
     
    7582                void addUnion( UnionDecl *decl );
    7683                void addTrait( TraitDecl *decl );
     84
     85                /// adds all of the IDs from WithStmt exprs
     86                void addWith( WithStmt * );
    7787
    7888                /// convenience function for adding a list of Ids to the indexer
     
    100110                // so that they will not be selected
    101111                // void removeSpecialOverrides( FunctionDecl *decl );
    102                 void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const;
     112                void removeSpecialOverrides( const std::string &id, std::list< IdData > & out ) const;
    103113
    104114                /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
Note: See TracChangeset for help on using the changeset viewer.