Changeset bed4c63e


Ignore:
Timestamp:
Mar 8, 2016, 5:52:39 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, string, with_gc
Children:
ac633d0, ae357ec
Parents:
52c2a72
Message:

Fold IdTable? into indexer

Location:
src
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.in

    r52c2a72 rbed4c63e  
    153153        ResolvExpr/driver_cfa_cpp-Occurs.$(OBJEXT) \
    154154        ResolvExpr/driver_cfa_cpp-TypeEnvironment.$(OBJEXT) \
    155         SymTab/driver_cfa_cpp-IdTable.$(OBJEXT) \
    156155        SymTab/driver_cfa_cpp-Indexer.$(OBJEXT) \
    157156        SymTab/driver_cfa_cpp-Mangler.$(OBJEXT) \
     
    360359        ResolvExpr/RenameVars.cc ResolvExpr/FindOpenVars.cc \
    361360        ResolvExpr/PolyCost.cc ResolvExpr/Occurs.cc \
    362         ResolvExpr/TypeEnvironment.cc SymTab/IdTable.cc \
    363         SymTab/Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \
    364         SymTab/FixFunction.cc SymTab/ImplementationType.cc \
    365         SymTab/TypeEquality.cc SynTree/Type.cc SynTree/VoidType.cc \
    366         SynTree/BasicType.cc SynTree/PointerType.cc \
    367         SynTree/ArrayType.cc SynTree/FunctionType.cc \
    368         SynTree/ReferenceToType.cc SynTree/TupleType.cc \
    369         SynTree/TypeofType.cc SynTree/AttrType.cc \
     361        ResolvExpr/TypeEnvironment.cc SymTab/Indexer.cc \
     362        SymTab/Mangler.cc SymTab/Validate.cc SymTab/FixFunction.cc \
     363        SymTab/ImplementationType.cc SymTab/TypeEquality.cc \
     364        SynTree/Type.cc SynTree/VoidType.cc SynTree/BasicType.cc \
     365        SynTree/PointerType.cc SynTree/ArrayType.cc \
     366        SynTree/FunctionType.cc SynTree/ReferenceToType.cc \
     367        SynTree/TupleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \
    370368        SynTree/VarArgsType.cc SynTree/Constant.cc \
    371369        SynTree/Expression.cc SynTree/TupleExpr.cc \
     
    660658        @$(MKDIR_P) SymTab/$(DEPDIR)
    661659        @: > SymTab/$(DEPDIR)/$(am__dirstamp)
    662 SymTab/driver_cfa_cpp-IdTable.$(OBJEXT): SymTab/$(am__dirstamp) \
    663         SymTab/$(DEPDIR)/$(am__dirstamp)
    664660SymTab/driver_cfa_cpp-Indexer.$(OBJEXT): SymTab/$(am__dirstamp) \
    665661        SymTab/$(DEPDIR)/$(am__dirstamp)
     
    827823        -rm -f ResolvExpr/driver_cfa_cpp-Unify.$(OBJEXT)
    828824        -rm -f SymTab/driver_cfa_cpp-FixFunction.$(OBJEXT)
    829         -rm -f SymTab/driver_cfa_cpp-IdTable.$(OBJEXT)
    830825        -rm -f SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT)
    831826        -rm -f SymTab/driver_cfa_cpp-Indexer.$(OBJEXT)
     
    933928@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-Unify.Po@am__quote@
    934929@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-FixFunction.Po@am__quote@
    935 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Po@am__quote@
    936930@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po@am__quote@
    937931@AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Po@am__quote@
     
    17921786@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-TypeEnvironment.obj `if test -f 'ResolvExpr/TypeEnvironment.cc'; then $(CYGPATH_W) 'ResolvExpr/TypeEnvironment.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/TypeEnvironment.cc'; fi`
    17931787
    1794 SymTab/driver_cfa_cpp-IdTable.o: SymTab/IdTable.cc
    1795 @am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-IdTable.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Tpo -c -o SymTab/driver_cfa_cpp-IdTable.o `test -f 'SymTab/IdTable.cc' || echo '$(srcdir)/'`SymTab/IdTable.cc
    1796 @am__fastdepCXX_TRUE@   $(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Po
    1797 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='SymTab/IdTable.cc' object='SymTab/driver_cfa_cpp-IdTable.o' libtool=no @AMDEPBACKSLASH@
    1798 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1799 @am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-IdTable.o `test -f 'SymTab/IdTable.cc' || echo '$(srcdir)/'`SymTab/IdTable.cc
    1800 
    1801 SymTab/driver_cfa_cpp-IdTable.obj: SymTab/IdTable.cc
    1802 @am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-IdTable.obj -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Tpo -c -o SymTab/driver_cfa_cpp-IdTable.obj `if test -f 'SymTab/IdTable.cc'; then $(CYGPATH_W) 'SymTab/IdTable.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/IdTable.cc'; fi`
    1803 @am__fastdepCXX_TRUE@   $(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-IdTable.Po
    1804 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='SymTab/IdTable.cc' object='SymTab/driver_cfa_cpp-IdTable.obj' libtool=no @AMDEPBACKSLASH@
    1805 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1806 @am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-IdTable.obj `if test -f 'SymTab/IdTable.cc'; then $(CYGPATH_W) 'SymTab/IdTable.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/IdTable.cc'; fi`
    1807 
    18081788SymTab/driver_cfa_cpp-Indexer.o: SymTab/Indexer.cc
    18091789@am__fastdepCXX_TRUE@   $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-Indexer.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Tpo -c -o SymTab/driver_cfa_cpp-Indexer.o `test -f 'SymTab/Indexer.cc' || echo '$(srcdir)/'`SymTab/Indexer.cc
  • src/SymTab/Indexer.cc

    r52c2a72 rbed4c63e  
    2121#include <utility>
    2222
    23 #include "IdTable.h"
     23#include "Mangler.h"
     24
     25#include "Common/utility.h"
     26
     27#include "ResolvExpr/typeops.h"
    2428
    2529#include "SynTree/Declaration.h"
     
    2832#include "SynTree/Initializer.h"
    2933#include "SynTree/Statement.h"
    30 
    31 #include "Common/utility.h"
    3234
    3335#define debugPrint(x) if ( doDebug ) { std::cout << x; }
     
    4143        }
    4244
     45        typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable;
     46        typedef std::unordered_map< std::string, MangleTable > IdTable;
    4347        typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable;
    4448        typedef std::unordered_map< std::string, StructDecl* > StructTable;
     
    4751        typedef std::unordered_map< std::string, TraitDecl* > TraitTable;
    4852
     53        void dump( const IdTable &table, std::ostream &os ) {
     54                for ( IdTable::const_iterator id = table.begin(); id != table.end(); ++id ) {
     55                        for ( MangleTable::const_iterator mangle = id->second.begin(); mangle != id->second.end(); ++mangle ) {
     56                                os << mangle->second << std::endl;
     57                        }
     58                }
     59        }
     60       
    4961        template< typename Decl >
    5062        void dump( const std::unordered_map< std::string, Decl* > &table, std::ostream &os ) {
     
    420432        }
    421433
    422 
    423         void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {
     434       
     435
     436        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
    424437                if ( ! tables ) return;
     438
     439                IdTable::const_iterator decls = tables->idTable.find( id );
     440                if ( decls != tables->idTable.end() ) {
     441                        const MangleTable &mangleTable = decls->second;
     442                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
     443                                out.push_back( decl->second );
     444                        }
     445                }
    425446               
    426                 tables->idTable.lookupId( id, list );
    427                 tables->base.lookupId( id, list );
    428         }
    429 
    430         DeclarationWithType* Indexer::lookupId( const std::string &id) const {
    431                 if ( ! tables ) return 0;
    432                
    433                 DeclarationWithType *ret = tables->idTable.lookupId(id);
    434                 return ret ? ret : tables->base.lookupId(id);
     447                // get declarations from base indexers
     448                tables->base.lookupId( id, out );
    435449        }
    436450
     
    470484        }
    471485
     486        DeclarationWithType *Indexer::lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const {
     487                if ( ! tables ) return 0;
     488                if ( tables->scope < scope ) return 0;
     489
     490                IdTable::const_iterator decls = tables->idTable.find( id );
     491                if ( decls != tables->idTable.end() ) {
     492                        const MangleTable &mangleTable = decls->second;
     493                        MangleTable::const_iterator decl = mangleTable.find( mangleName );
     494                        if ( decl != mangleTable.end() ) return decl->second;
     495                }
     496
     497                return tables->base.lookupIdAtScope( id, mangleName, scope );
     498        }
     499
     500        bool Indexer::hasCDeclWithName( const std::string &id ) const {
     501                if ( ! tables ) return false;
     502
     503                IdTable::const_iterator decls = tables->idTable.find( id );
     504                if ( decls != tables->idTable.end() ) {
     505                        const MangleTable &mangleTable = decls->second;
     506                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
     507                                if ( decl->second->get_linkage() == LinkageSpec::C ) return true;
     508                        }
     509                }
     510
     511                return tables->base.hasCDeclWithName( id );
     512        }
     513       
    472514        NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
    473515                if ( ! tables ) return 0;
     
    510552        }
    511553
     554        bool addedIdConflicts( DeclarationWithType *existing, DeclarationWithType *added ) {
     555                // if we're giving the same name mangling to things of different types then there is something wrong
     556                assert( (dynamic_cast<ObjectDecl*>( added ) && dynamic_cast<ObjectDecl*>( existing ) )
     557                        || (dynamic_cast<FunctionDecl*>( added ) && dynamic_cast<FunctionDecl*>( existing ) ) );
     558
     559                if ( LinkageSpec::isOverridable( existing->get_linkage() ) ) {
     560                        // new definition shadows the autogenerated one, even at the same scope
     561                        return false;
     562                } else if ( added->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( added->get_type(), existing->get_type(), Indexer() ) ) {
     563                        // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
     564                        // we should ignore outermost pointer qualifiers, except _Atomic?
     565                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( added );
     566                        FunctionDecl *oldentry = dynamic_cast< FunctionDecl* >( existing );
     567                        if ( newentry && oldentry ) {
     568                                if ( newentry->get_statements() && oldentry->get_statements() ) {
     569                                        throw SemanticError( "duplicate function definition for ", added );
     570                                } // if
     571                        } else {
     572                                // two objects with the same mangled name defined in the same scope.
     573                                // both objects must be marked extern or both must be intrinsic for this to be okay
     574                                // xxx - perhaps it's actually if either is intrinsic then this is okay?
     575                                //       might also need to be same storage class?
     576                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( added );
     577                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( existing );
     578                                if ( newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
     579                                        throw SemanticError( "duplicate object definition for ", added );
     580                                } // if
     581                        } // if
     582                } else {
     583                        throw SemanticError( "duplicate definition for ", added );
     584                } // if
     585
     586                return true;
     587        }
     588       
    512589        void Indexer::addId( DeclarationWithType *decl ) {
    513590                makeWritable();
    514                 tables->idTable.addDecl( decl );
    515                 ++tables->size;
     591
     592                const std::string &name = decl->get_name();
     593                std::string mangleName;
     594                if ( decl->get_linkage() == LinkageSpec::C ) {
     595                        mangleName = name;
     596                } else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
     597                        // mangle the name without including the appropriate suffix, so overridable routines are placed into the
     598                        // same "bucket" as their user defined versions.
     599                        mangleName = Mangler::mangle( decl, false );
     600                } else {
     601                        mangleName = Mangler::mangle( decl );
     602                } // if
     603
     604                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
     605                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
     606                        // this ensures that no two declarations with the same unmangled name both have C linkage
     607                        if ( decl->get_linkage() == LinkageSpec::C && hasCDeclWithName( name ) ) {
     608                                throw SemanticError( "invalid overload of C function ", decl );
     609                        }
     610                       
     611                        tables->idTable[ name ][ mangleName ] = decl;
     612                        ++tables->size;
     613                }
    516614        }
    517615
     
    650748                        if ( doDebug ) {
    651749                                cout << "--- Leaving scope " << tables->scope << " containing" << std::endl;
    652                                 tables->idTable.dump( cout );
     750                                dump( tables->idTable, cout );
    653751                                dump( tables->typeTable, cout );
    654752                                dump( tables->structTable, cout );
     
    669767
    670768            cerr << "===idTable===" << std::endl;
    671             if ( tables ) tables->idTable.dump( os );
     769            if ( tables ) dump( tables->idTable, os );
    672770            cerr << "===typeTable===" << std::endl;
    673771            if ( tables ) dump( tables->typeTable, os );
  • src/SymTab/Indexer.h

    r52c2a72 rbed4c63e  
    8080                void leaveScope();
    8181
     82                /// Gets all declarations with the given ID
    8283                void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const;
    83                 DeclarationWithType* lookupId( const std::string &id ) const;
     84                /// Gets the top-most type declaration with the given ID
    8485                NamedTypeDecl *lookupType( const std::string &id ) const;
     86                /// Gets the top-most struct declaration with the given ID
    8587                StructDecl *lookupStruct( const std::string &id ) const;
     88                /// Gets the top-most enum declaration with the given ID
    8689                EnumDecl *lookupEnum( const std::string &id ) const;
     90                /// Gets the top-most union declaration with the given ID
    8791                UnionDecl *lookupUnion( const std::string &id ) const;
     92                /// Gets the top-most trait declaration with the given ID
    8893                TraitDecl *lookupTrait( const std::string &id ) const;
    8994 
    9095                void print( std::ostream &os, int indent = 0 ) const;
    9196          private:
     97                /// looks up a specific mangled ID at the given scope
     98                DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
     99                /// returns true if there exists a declaration with C linkage and the given name
     100                bool hasCDeclWithName( const std::string &id ) const;
    92101                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
    93102                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
  • src/SymTab/module.mk

    r52c2a72 rbed4c63e  
    1515###############################################################################
    1616
    17 SRC += SymTab/IdTable.cc \
    18        SymTab/Indexer.cc \
     17SRC += SymTab/Indexer.cc \
    1918       SymTab/Mangler.cc \
    2019       SymTab/Validate.cc \
Note: See TracChangeset for help on using the changeset viewer.