Changeset 0f9e4403 for src/SymTab


Ignore:
Timestamp:
Apr 15, 2016, 12:03:11 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
29ad0ac
Parents:
c5833e8 (diff), 37f0da8 (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' into gc_noraii

Location:
src/SymTab
Files:
6 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/AddVisit.h

    rc5833e8 r0f9e4403  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 16:14:32 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:26:17 2015
    13 // Update Count     : 4
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Apr  7 14:42:21 2016
     13// Update Count     : 5
    1414//
    1515
     
    2727
    2828        template< typename Visitor >
    29         inline void addVisitStatement( Statement *stmt, Visitor &visitor ) {
    30                 maybeAccept( stmt, visitor );
    31 ///   if ( ! declsToAdd.empty() ) {
    32 ///     CompoundStmt *compound = new CompoundStmt( noLabels );
    33 ///     compound->get_kids().push_back( stmt );
    34 ///     addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() );
    35 ///   }
    36         }
    37 
    38         template< typename Visitor >
    3929        inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
    4030                addVisitStatementList( compoundStmt->get_kids(), visitor );
    41         }
    42 
    43         template< typename Visitor >
    44         inline void addVisit(IfStmt *ifStmt, Visitor &visitor) {
    45                 addVisitStatement( ifStmt->get_thenPart(), visitor );
    46                 addVisitStatement( ifStmt->get_elsePart(), visitor );
    47                 maybeAccept( ifStmt->get_condition(), visitor );
    48         }
    49 
    50         template< typename Visitor >
    51         inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) {
    52                 addVisitStatement( whileStmt->get_body(), visitor );
    53                 maybeAccept( whileStmt->get_condition(), visitor );
    54         }
    55 
    56         template< typename Visitor >
    57         inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
    58                 addVisitStatement( forStmt->get_body(), visitor );
    59                 acceptAll( forStmt->get_initialization(), visitor );
    60                 maybeAccept( forStmt->get_condition(), visitor );
    61                 maybeAccept( forStmt->get_increment(), visitor );
    6231        }
    6332
     
    7443        }
    7544
    76         template< typename Visitor >
    77         inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
    78                 addVisitStatementList( caseStmt->get_statements(), visitor );
    79                 maybeAccept( caseStmt->get_condition(), visitor );
    80         }
    81 
    82         template< typename Visitor >
    83         inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) {
    84                 addVisitStatement( cathStmt->get_body(), visitor );
    85                 maybeAccept( cathStmt->get_decl(), visitor );
    86         }
     45        // template< typename Visitor >
     46        // inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
     47        //      addVisitStatementList( caseStmt->get_statements(), visitor );
     48        //      maybeAccept( caseStmt->get_condition(), visitor );
     49        // }
    8750} // namespace SymTab
    8851
  • src/SymTab/FixFunction.cc

    rc5833e8 r0f9e4403  
    1010// Created On       : Sun May 17 16:19:49 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 16:22:54 2015
    13 // Update Count     : 2
     12// Last Modified On : Wed Mar  2 17:31:10 2016
     13// Update Count     : 3
    1414//
    1515
     
    6161        }
    6262
    63         Type * FixFunction::mutate(ContextInstType *aggregateUseType) {
     63        Type * FixFunction::mutate(TraitInstType *aggregateUseType) {
    6464                return aggregateUseType;
    6565        }
     
    7272                return tupleType;
    7373        }
     74
     75        Type * FixFunction::mutate(VarArgsType *varArgsType) {
     76                return varArgsType;
     77        }
    7478} // namespace SymTab
    7579
  • src/SymTab/FixFunction.h

    rc5833e8 r0f9e4403  
    1010// Created On       : Sun May 17 17:02:08 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 17:03:43 2015
    13 // Update Count     : 2
     12// Last Modified On : Wed Mar  2 17:34:06 2016
     13// Update Count     : 3
    1414//
    1515
     
    3838                virtual Type* mutate(UnionInstType *aggregateUseType);
    3939                virtual Type* mutate(EnumInstType *aggregateUseType);
    40                 virtual Type* mutate(ContextInstType *aggregateUseType);
     40                virtual Type* mutate(TraitInstType *aggregateUseType);
    4141                virtual Type* mutate(TypeInstType *aggregateUseType);
    4242                virtual Type* mutate(TupleType *tupleType);
     43                virtual Type* mutate(VarArgsType *varArgsType);
    4344 
    4445                bool isVoid;
  • src/SymTab/ImplementationType.cc

    rc5833e8 r0f9e4403  
    1010// Created On       : Sun May 17 21:32:01 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 21:34:40 2015
    13 // Update Count     : 2
     12// Last Modified On : Wed Mar  2 17:31:20 2016
     13// Update Count     : 3
    1414//
    1515
     
    3737                virtual void visit(UnionInstType *aggregateUseType);
    3838                virtual void visit(EnumInstType *aggregateUseType);
    39                 virtual void visit(ContextInstType *aggregateUseType);
     39                virtual void visit(TraitInstType *aggregateUseType);
    4040                virtual void visit(TypeInstType *aggregateUseType);
    4141                virtual void visit(TupleType *tupleType);
     42                virtual void visit(VarArgsType *varArgsType);
    4243
    4344                Type *result;                   // synthesized
     
    9596        }
    9697
    97         void ImplementationType::visit(ContextInstType *aggregateUseType) {
     98        void ImplementationType::visit(TraitInstType *aggregateUseType) {
    9899        }
    99100
     
    116117                result = newType;
    117118        }
     119
     120        void ImplementationType::visit(VarArgsType *varArgsType) {
     121        }
    118122} // namespace SymTab
    119123
  • src/SymTab/Indexer.cc

    rc5833e8 r0f9e4403  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:37:33 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 05 13:52:42 2015
    13 // Update Count     : 10
    14 //
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Mar  2 17:31:29 2016
     13// Update Count     : 11
     14//
     15
     16#include "Indexer.h"
     17
     18#include <string>
     19#include <typeinfo>
     20#include <unordered_map>
     21#include <unordered_set>
     22#include <utility>
     23
     24#include "Mangler.h"
     25
     26#include "Common/utility.h"
     27
     28#include "ResolvExpr/typeops.h"
    1529
    1630#include "SynTree/Declaration.h"
     
    1933#include "SynTree/Initializer.h"
    2034#include "SynTree/Statement.h"
    21 #include "Indexer.h"
    22 #include <typeinfo>
    23 #include "Common/utility.h"
    2435
    2536#define debugPrint(x) if ( doDebug ) { std::cout << x; }
     
    3344        }
    3445
    35         Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}
    36 
    37         Indexer::~Indexer() {}
     46        typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable;
     47        typedef std::unordered_map< std::string, MangleTable > IdTable;
     48        typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable;
     49        typedef std::unordered_map< std::string, StructDecl* > StructTable;
     50        typedef std::unordered_map< std::string, EnumDecl* > EnumTable;
     51        typedef std::unordered_map< std::string, UnionDecl* > UnionTable;
     52        typedef std::unordered_map< std::string, TraitDecl* > TraitTable;
     53
     54        void dump( const IdTable &table, std::ostream &os ) {
     55                for ( IdTable::const_iterator id = table.begin(); id != table.end(); ++id ) {
     56                        for ( MangleTable::const_iterator mangle = id->second.begin(); mangle != id->second.end(); ++mangle ) {
     57                                os << mangle->second << std::endl;
     58                        }
     59                }
     60        }
     61       
     62        template< typename Decl >
     63        void dump( const std::unordered_map< std::string, Decl* > &table, std::ostream &os ) {
     64                for ( typename std::unordered_map< std::string, Decl* >::const_iterator it = table.begin(); it != table.end(); ++it ) {
     65                        os << it->second << std::endl;
     66                } // for
     67        }
     68       
     69        struct Indexer::Impl {
     70                Impl( unsigned long _scope ) : refCount(1), scope( _scope ), size( 0 ), base(),
     71                                idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable() {}
     72                Impl( unsigned long _scope, Indexer &&_base ) : refCount(1), scope( _scope ), size( 0 ), base( _base ),
     73                                idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable() {}
     74                unsigned long refCount;   ///< Number of references to these tables
     75                unsigned long scope;      ///< Scope these tables are associated with
     76                unsigned long size;       ///< Number of elements stored in this table
     77                const Indexer base;       ///< Base indexer this extends
     78               
     79                IdTable idTable;          ///< Identifier namespace
     80                TypeTable typeTable;      ///< Type namespace
     81                StructTable structTable;  ///< Struct namespace
     82                EnumTable enumTable;      ///< Enum namespace
     83                UnionTable unionTable;    ///< Union namespace
     84                TraitTable traitTable;    ///< Trait namespace
     85        };
     86
     87        Indexer::Impl *Indexer::newRef( Indexer::Impl *toClone ) {
     88                if ( ! toClone ) return 0;
     89
     90                // shorten the search chain by skipping empty links
     91                Indexer::Impl *ret = toClone->size == 0 ? toClone->base.tables : toClone;
     92                if ( ret ) { ++ret->refCount; }
     93
     94                return ret;
     95        }
     96
     97        void Indexer::deleteRef( Indexer::Impl *toFree ) {
     98                if ( ! toFree ) return;
     99
     100                if ( --toFree->refCount == 0 ) delete toFree;
     101        }
     102
     103        void Indexer::makeWritable() {
     104                if ( ! tables ) {
     105                        // create indexer if not yet set
     106                        tables = new Indexer::Impl( scope );
     107                } else if ( tables->refCount > 1 || tables->scope != scope ) {
     108                        // make this indexer the base of a fresh indexer at the current scope
     109                        tables = new Indexer::Impl( scope, std::move( *this ) );
     110                }
     111        }
     112
     113        Indexer::Indexer( bool _doDebug ) : tables( 0 ), scope( 0 ), doDebug( _doDebug ) {}
     114
     115        Indexer::Indexer( const Indexer &that ) : tables( newRef( that.tables ) ), scope( that.scope ), doDebug( that.doDebug ) {}
     116
     117        Indexer::Indexer( Indexer &&that ) : tables( that.tables ), scope( that.scope ), doDebug( that.doDebug ) {
     118                that.tables = 0;
     119        }
     120
     121        Indexer::~Indexer() {
     122                deleteRef( tables );
     123        }
     124
     125        Indexer& Indexer::operator= ( const Indexer &that ) {
     126                deleteRef( tables );
     127
     128                tables = newRef( that.tables );
     129                scope = that.scope;
     130                doDebug = that.doDebug;
     131
     132                return *this;
     133        }
     134
     135        Indexer& Indexer::operator= ( Indexer &&that ) {
     136                deleteRef( tables );
     137
     138                tables = that.tables;
     139                scope = that.scope;
     140                doDebug = that.doDebug;
     141
     142                that.tables = 0;
     143
     144                return *this;
     145        }
    38146
    39147        void Indexer::visit( ObjectDecl *objectDecl ) {
     
    45153                if ( objectDecl->get_name() != "" ) {
    46154                        debugPrint( "Adding object " << objectDecl->get_name() << std::endl );
    47                         idTable.addDecl( objectDecl );
     155                        addId( objectDecl );
    48156                } // if
    49157        }
     
    52160                if ( functionDecl->get_name() == "" ) return;
    53161                debugPrint( "Adding function " << functionDecl->get_name() << std::endl );
    54                 idTable.addDecl( functionDecl );
     162                addId( functionDecl );
    55163                enterScope();
    56164                maybeAccept( functionDecl->get_functionType(), *this );
     
    90198                leaveScope();
    91199                debugPrint( "Adding type " << typeDecl->get_name() << std::endl );
    92                 typeTable.add( typeDecl );
     200                addType( typeDecl );
    93201                acceptAll( typeDecl->get_assertions(), *this );
    94202        }
     
    100208                leaveScope();
    101209                debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );
    102                 typeTable.add( typeDecl );
     210                addType( typeDecl );
    103211        }
    104212
     
    108216                cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    109217                debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
    110                 structTable.add( &fwdDecl );
     218                addStruct( &fwdDecl );
    111219 
    112220                enterScope();
     
    117225                debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
    118226                // this addition replaces the forward declaration
    119                 structTable.add( aggregateDecl );
     227                addStruct( aggregateDecl );
    120228        }
    121229
     
    125233                cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    126234                debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
    127                 unionTable.add( &fwdDecl );
     235                addUnion( &fwdDecl );
    128236 
    129237                enterScope();
     
    133241 
    134242                debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
    135                 unionTable.add( aggregateDecl );
     243                addUnion( aggregateDecl );
    136244        }
    137245
    138246        void Indexer::visit( EnumDecl *aggregateDecl ) {
    139247                debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );
    140                 enumTable.add( aggregateDecl );
     248                addEnum( aggregateDecl );
    141249                // unlike structs, contexts, and unions, enums inject their members into the global scope
    142250                acceptAll( aggregateDecl->get_members(), *this );
    143251        }
    144252
    145         void Indexer::visit( ContextDecl *aggregateDecl ) {
     253        void Indexer::visit( TraitDecl *aggregateDecl ) {
    146254                enterScope();
    147255                acceptAll( aggregateDecl->get_parameters(), *this );
     
    150258 
    151259                debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
    152                 contextTable.add( aggregateDecl );
     260                addTrait( aggregateDecl );
    153261        }
    154262
     
    236344                maybeAccept( offsetofExpr->get_type(), *this );
    237345                maybeAccept( offsetofExpr->get_member(), *this );
     346        }
     347
     348        void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
     349                acceptAllNewScope( offsetPackExpr->get_results(), *this );
     350                maybeAccept( offsetPackExpr->get_type(), *this );
    238351        }
    239352
     
    293406
    294407
    295         void Indexer::visit( ContextInstType *contextInst ) {
     408        void Indexer::visit( TraitInstType *contextInst ) {
    296409                acceptAll( contextInst->get_parameters(), *this );
    297410                acceptAll( contextInst->get_members(), *this );
     
    299412
    300413        void Indexer::visit( StructInstType *structInst ) {
    301                 if ( ! structTable.lookup( structInst->get_name() ) ) {
     414                if ( ! lookupStruct( structInst->get_name() ) ) {
    302415                        debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl );
    303                         structTable.add( structInst->get_name() );
     416                        addStruct( structInst->get_name() );
    304417                }
    305418                enterScope();
     
    309422
    310423        void Indexer::visit( UnionInstType *unionInst ) {
    311                 if ( ! unionTable.lookup( unionInst->get_name() ) ) {
     424                if ( ! lookupUnion( unionInst->get_name() ) ) {
    312425                        debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl );
    313                         unionTable.add( unionInst->get_name() );
     426                        addUnion( unionInst->get_name() );
    314427                }
    315428                enterScope();
     
    325438        }
    326439
    327 
    328         void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {
    329                 idTable.lookupId( id, list );
    330         }
    331 
    332         DeclarationWithType* Indexer::lookupId( const std::string &id) const {
    333                 return idTable.lookupId(id);
     440       
     441
     442        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
     443                std::unordered_set< std::string > foundMangleNames;
     444               
     445                Indexer::Impl *searchTables = tables;
     446                while ( searchTables ) {
     447
     448                        IdTable::const_iterator decls = searchTables->idTable.find( id );
     449                        if ( decls != searchTables->idTable.end() ) {
     450                                const MangleTable &mangleTable = decls->second;
     451                                for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
     452                                        // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found
     453                                        if ( foundMangleNames.insert( decl->first ).second == false ) continue;
     454                                       
     455                                        out.push_back( decl->second );
     456                                }
     457                        }
     458                       
     459                        // get declarations from base indexers
     460                        searchTables = searchTables->base.tables;
     461                }
    334462        }
    335463
    336464        NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
    337                 return typeTable.lookup( id );
     465                if ( ! tables ) return 0;
     466
     467                TypeTable::const_iterator ret = tables->typeTable.find( id );
     468                return ret != tables->typeTable.end() ? ret->second : tables->base.lookupType( id );
    338469        }
    339470
    340471        StructDecl *Indexer::lookupStruct( const std::string &id ) const {
    341                 return structTable.lookup( id );
     472                if ( ! tables ) return 0;
     473
     474                StructTable::const_iterator ret = tables->structTable.find( id );
     475                return ret != tables->structTable.end() ? ret->second : tables->base.lookupStruct( id );
    342476        }
    343477
    344478        EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
    345                 return enumTable.lookup( id );
     479                if ( ! tables ) return 0;
     480
     481                EnumTable::const_iterator ret = tables->enumTable.find( id );
     482                return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnum( id );
    346483        }
    347484
    348485        UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
    349                 return unionTable.lookup( id );
    350         }
    351 
    352         ContextDecl  * Indexer::lookupContext( const std::string &id ) const {
    353                 return contextTable.lookup( id );
     486                if ( ! tables ) return 0;
     487
     488                UnionTable::const_iterator ret = tables->unionTable.find( id );
     489                return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnion( id );
     490        }
     491
     492        TraitDecl *Indexer::lookupTrait( const std::string &id ) const {
     493                if ( ! tables ) return 0;
     494
     495                TraitTable::const_iterator ret = tables->traitTable.find( id );
     496                return ret != tables->traitTable.end() ? ret->second : tables->base.lookupTrait( id );
     497        }
     498
     499        DeclarationWithType *Indexer::lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const {
     500                if ( ! tables ) return 0;
     501                if ( tables->scope < scope ) return 0;
     502
     503                IdTable::const_iterator decls = tables->idTable.find( id );
     504                if ( decls != tables->idTable.end() ) {
     505                        const MangleTable &mangleTable = decls->second;
     506                        MangleTable::const_iterator decl = mangleTable.find( mangleName );
     507                        if ( decl != mangleTable.end() ) return decl->second;
     508                }
     509
     510                return tables->base.lookupIdAtScope( id, mangleName, scope );
     511        }
     512
     513        bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
     514                if ( ! tables ) return false;
     515
     516                IdTable::const_iterator decls = tables->idTable.find( id );
     517                if ( decls != tables->idTable.end() ) {
     518                        const MangleTable &mangleTable = decls->second;
     519                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
     520                                // check for C decls with the same name, skipping
     521                                // those with a compatible type (by mangleName)
     522                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
     523                        }
     524                }
     525
     526                return tables->base.hasIncompatibleCDecl( id, mangleName );
     527        }
     528       
     529        NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
     530                if ( ! tables ) return 0;
     531                if ( tables->scope < scope ) return 0;
     532
     533                TypeTable::const_iterator ret = tables->typeTable.find( id );
     534                return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope );
     535        }
     536       
     537        StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const {
     538                if ( ! tables ) return 0;
     539                if ( tables->scope < scope ) return 0;
     540
     541                StructTable::const_iterator ret = tables->structTable.find( id );
     542                return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope );
     543        }
     544       
     545        EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const {
     546                if ( ! tables ) return 0;
     547                if ( tables->scope < scope ) return 0;
     548
     549                EnumTable::const_iterator ret = tables->enumTable.find( id );
     550                return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope );
     551        }
     552       
     553        UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const {
     554                if ( ! tables ) return 0;
     555                if ( tables->scope < scope ) return 0;
     556
     557                UnionTable::const_iterator ret = tables->unionTable.find( id );
     558                return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope );
     559        }
     560       
     561        TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const {
     562                if ( ! tables ) return 0;
     563                if ( tables->scope < scope ) return 0;
     564
     565                TraitTable::const_iterator ret = tables->traitTable.find( id );
     566                return ret != tables->traitTable.end() ? ret->second : tables->base.lookupTraitAtScope( id, scope );
     567        }
     568
     569        bool addedIdConflicts( DeclarationWithType *existing, DeclarationWithType *added ) {
     570                // if we're giving the same name mangling to things of different types then there is something wrong
     571                assert( (dynamic_cast<ObjectDecl*>( added ) && dynamic_cast<ObjectDecl*>( existing ) )
     572                        || (dynamic_cast<FunctionDecl*>( added ) && dynamic_cast<FunctionDecl*>( existing ) ) );
     573
     574                if ( LinkageSpec::isOverridable( existing->get_linkage() ) ) {
     575                        // new definition shadows the autogenerated one, even at the same scope
     576                        return false;
     577                } else if ( added->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( added->get_type(), existing->get_type(), Indexer() ) ) {
     578                        // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
     579                        // we should ignore outermost pointer qualifiers, except _Atomic?
     580                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( added );
     581                        FunctionDecl *oldentry = dynamic_cast< FunctionDecl* >( existing );
     582                        if ( newentry && oldentry ) {
     583                                if ( newentry->get_statements() && oldentry->get_statements() ) {
     584                                        throw SemanticError( "duplicate function definition for ", added );
     585                                } // if
     586                        } else {
     587                                // two objects with the same mangled name defined in the same scope.
     588                                // both objects must be marked extern or both must be intrinsic for this to be okay
     589                                // xxx - perhaps it's actually if either is intrinsic then this is okay?
     590                                //       might also need to be same storage class?
     591                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( added );
     592                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( existing );
     593                                if ( newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
     594                                        throw SemanticError( "duplicate object definition for ", added );
     595                                } // if
     596                        } // if
     597                } else {
     598                        throw SemanticError( "duplicate definition for ", added );
     599                } // if
     600
     601                return true;
     602        }
     603       
     604        void Indexer::addId( DeclarationWithType *decl ) {
     605                makeWritable();
     606
     607                const std::string &name = decl->get_name();
     608                std::string mangleName;
     609                if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
     610                        // mangle the name without including the appropriate suffix, so overridable routines are placed into the
     611                        // same "bucket" as their user defined versions.
     612                        mangleName = Mangler::mangle( decl, false );
     613                } else {
     614                        mangleName = Mangler::mangle( decl );
     615                } // if
     616
     617                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
     618                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
     619                        // this ensures that no two declarations with the same unmangled name both have C linkage
     620                        if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) {
     621                                throw SemanticError( "invalid overload of C function ", decl );
     622                        } // NOTE this is broken in Richard's original code in such a way that it never triggers (it
     623                          // doesn't check decls that have the same manglename, and all C-linkage decls are defined to
     624                          // have their name as their manglename, hence the error can never trigger).
     625                          // The code here is closer to correct, but name mangling would have to be completely
     626                          // isomorphic to C type-compatibility, which it may not be.
     627                       
     628                        tables->idTable[ name ][ mangleName ] = decl;
     629                        ++tables->size;
     630                }
     631        }
     632
     633        bool addedTypeConflicts( NamedTypeDecl *existing, NamedTypeDecl *added ) {
     634                if ( existing->get_base() == 0 ) {
     635                        return false;
     636                } else if ( added->get_base() == 0 ) {
     637                        return true;
     638                } else {
     639                        throw SemanticError( "redeclaration of ", added );
     640                }
     641        }
     642       
     643        void Indexer::addType( NamedTypeDecl *decl ) {
     644                makeWritable();
     645
     646                const std::string &id = decl->get_name();
     647                TypeTable::iterator existing = tables->typeTable.find( id );
     648                if ( existing == tables->typeTable.end() ) {
     649                        NamedTypeDecl *parent = tables->base.lookupTypeAtScope( id, scope );
     650                        if ( ! parent || ! addedTypeConflicts( parent, decl ) ) {
     651                                tables->typeTable.insert( existing, std::make_pair( id, decl ) );
     652                                ++tables->size;
     653                        }
     654                } else {
     655                        if ( ! addedTypeConflicts( existing->second, decl ) ) {
     656                                existing->second = decl;
     657                        }
     658                }
     659        }
     660
     661        bool addedDeclConflicts( AggregateDecl *existing, AggregateDecl *added ) {
     662                if ( existing->get_members().empty() ) {
     663                        return false;
     664                } else if ( ! added->get_members().empty() ) {
     665                        throw SemanticError( "redeclaration of ", added );
     666                } // if
     667                return true;
     668        }
     669
     670        void Indexer::addStruct( const std::string &id ) {
     671                addStruct( new StructDecl( id ) );
     672        }
     673       
     674        void Indexer::addStruct( StructDecl *decl ) {
     675                makeWritable();
     676
     677                const std::string &id = decl->get_name();
     678                StructTable::iterator existing = tables->structTable.find( id );
     679                if ( existing == tables->structTable.end() ) {
     680                        StructDecl *parent = tables->base.lookupStructAtScope( id, scope );
     681                        if ( ! parent || ! addedDeclConflicts( parent, decl ) ) {
     682                                tables->structTable.insert( existing, std::make_pair( id, decl ) );
     683                                ++tables->size;
     684                        }
     685                } else {
     686                        if ( ! addedDeclConflicts( existing->second, decl ) ) {
     687                                existing->second = decl;
     688                        }
     689                }
     690        }
     691       
     692        void Indexer::addEnum( EnumDecl *decl ) {
     693                makeWritable();
     694
     695                const std::string &id = decl->get_name();
     696                EnumTable::iterator existing = tables->enumTable.find( id );
     697                if ( existing == tables->enumTable.end() ) {
     698                        EnumDecl *parent = tables->base.lookupEnumAtScope( id, scope );
     699                        if ( ! parent || ! addedDeclConflicts( parent, decl ) ) {
     700                                tables->enumTable.insert( existing, std::make_pair( id, decl ) );
     701                                ++tables->size;
     702                        }
     703                } else {
     704                        if ( ! addedDeclConflicts( existing->second, decl ) ) {
     705                                existing->second = decl;
     706                        }
     707                }
     708        }
     709
     710        void Indexer::addUnion( const std::string &id ) {
     711                addUnion( new UnionDecl( id ) );
     712        }
     713       
     714        void Indexer::addUnion( UnionDecl *decl ) {
     715                makeWritable();
     716
     717                const std::string &id = decl->get_name();
     718                UnionTable::iterator existing = tables->unionTable.find( id );
     719                if ( existing == tables->unionTable.end() ) {
     720                        UnionDecl *parent = tables->base.lookupUnionAtScope( id, scope );
     721                        if ( ! parent || ! addedDeclConflicts( parent, decl ) ) {
     722                                tables->unionTable.insert( existing, std::make_pair( id, decl ) );
     723                                ++tables->size;
     724                        }
     725                } else {
     726                        if ( ! addedDeclConflicts( existing->second, decl ) ) {
     727                                existing->second = decl;
     728                        }
     729                }
     730        }
     731       
     732        void Indexer::addTrait( TraitDecl *decl ) {
     733                makeWritable();
     734
     735                const std::string &id = decl->get_name();
     736                TraitTable::iterator existing = tables->traitTable.find( id );
     737                if ( existing == tables->traitTable.end() ) {
     738                        TraitDecl *parent = tables->base.lookupTraitAtScope( id, scope );
     739                        if ( ! parent || ! addedDeclConflicts( parent, decl ) ) {
     740                                tables->traitTable.insert( existing, std::make_pair( id, decl ) );
     741                                ++tables->size;
     742                        }
     743                } else {
     744                        if ( ! addedDeclConflicts( existing->second, decl ) ) {
     745                                existing->second = decl;
     746                        }
     747                }
    354748        }
    355749
    356750        void Indexer::enterScope() {
     751                ++scope;
     752               
    357753                if ( doDebug ) {
    358                         std::cout << "--- Entering scope" << std::endl;
    359                 }
    360                 idTable.enterScope();
    361                 typeTable.enterScope();
    362                 structTable.enterScope();
    363                 enumTable.enterScope();
    364                 unionTable.enterScope();
    365                 contextTable.enterScope();
     754                        std::cout << "--- Entering scope " << scope << std::endl;
     755                }
    366756        }
    367757
    368758        void Indexer::leaveScope() {
    369759                using std::cout;
    370                 using std::endl;
    371  
    372                 if ( doDebug ) {
    373                         cout << "--- Leaving scope containing" << endl;
    374                         idTable.dump( cout );
    375                         typeTable.dump( cout );
    376                         structTable.dump( cout );
    377                         enumTable.dump( cout );
    378                         unionTable.dump( cout );
    379                         contextTable.dump( cout );
    380                 }
    381                 idTable.leaveScope();
    382                 typeTable.leaveScope();
    383                 structTable.leaveScope();
    384                 enumTable.leaveScope();
    385                 unionTable.leaveScope();
    386                 contextTable.leaveScope();
     760
     761                assert( scope > 0 && "cannot leave initial scope" );
     762                --scope;
     763
     764                while ( tables && tables->scope > scope ) {
     765                        if ( doDebug ) {
     766                                cout << "--- Leaving scope " << tables->scope << " containing" << std::endl;
     767                                dump( tables->idTable, cout );
     768                                dump( tables->typeTable, cout );
     769                                dump( tables->structTable, cout );
     770                                dump( tables->enumTable, cout );
     771                                dump( tables->unionTable, cout );
     772                                dump( tables->traitTable, cout );
     773                        }
     774
     775                        // swap tables for base table until we find one at an appropriate scope
     776                        Indexer::Impl *base = newRef( tables->base.tables );
     777                        deleteRef( tables );
     778                        tables = base;
     779                }
    387780        }
    388781
    389782        void Indexer::print( std::ostream &os, int indent ) const {
    390783            using std::cerr;
    391             using std::endl;
    392 
    393             cerr << "===idTable===" << endl;
    394             idTable.dump( os );
    395             cerr << "===typeTable===" << endl;
    396             typeTable.dump( os );
    397             cerr << "===structTable===" << endl;
    398             structTable.dump( os );
    399             cerr << "===enumTable===" << endl;
    400             enumTable.dump( os );
    401             cerr << "===unionTable===" << endl;
    402             unionTable.dump( os );
    403             cerr << "===contextTable===" << endl;
    404             contextTable.dump( os );
    405 #if 0
    406                 idTable.dump( os );
    407                 typeTable.dump( os );
    408                 structTable.dump( os );
    409                 enumTable.dump( os );
    410                 unionTable.dump( os );
    411                 contextTable.dump( os );
    412 #endif
     784
     785            cerr << "===idTable===" << std::endl;
     786            if ( tables ) dump( tables->idTable, os );
     787            cerr << "===typeTable===" << std::endl;
     788            if ( tables ) dump( tables->typeTable, os );
     789            cerr << "===structTable===" << std::endl;
     790            if ( tables ) dump( tables->structTable, os );
     791            cerr << "===enumTable===" << std::endl;
     792            if ( tables ) dump( tables->enumTable, os );
     793            cerr << "===unionTable===" << std::endl;
     794            if ( tables ) dump( tables->unionTable, os );
     795            cerr << "===contextTable===" << std::endl;
     796            if ( tables ) dump( tables->traitTable, os );
    413797        }
    414798} // namespace SymTab
  • src/SymTab/Indexer.h

    rc5833e8 r0f9e4403  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:38:55 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Sep 17 16:05:38 2015
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Mar  2 17:34:14 2016
     13// Update Count     : 6
    1414//
    1515
     
    2121
    2222#include "SynTree/Visitor.h"
    23 #include "IdTable.h"
    24 #include "AggregateTable.h"
    25 #include "TypeTable.h"
    2623
    2724namespace SymTab {
     
    2926          public:
    3027                Indexer( bool useDebug = false );
     28
     29                Indexer( const Indexer &that );
     30                Indexer( Indexer &&that );
    3131                virtual ~Indexer();
     32                Indexer& operator= ( const Indexer &that );
     33                Indexer& operator= ( Indexer &&that );
    3234
    3335                //using Visitor::visit;
     
    3941                virtual void visit( UnionDecl *aggregateDecl );
    4042                virtual void visit( EnumDecl *aggregateDecl );
    41                 virtual void visit( ContextDecl *aggregateDecl );
     43                virtual void visit( TraitDecl *aggregateDecl );
    4244
    4345                virtual void visit( CompoundStmt *compoundStmt );
     
    5759                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    5860                virtual void visit( OffsetofExpr *offsetofExpr );
     61                virtual void visit( OffsetPackExpr *offsetPackExpr );
    5962                virtual void visit( AttrExpr *attrExpr );
    6063                virtual void visit( LogicalExpr *logicalExpr );
     
    6770                virtual void visit( UntypedValofExpr *valofExpr );
    6871
    69                 virtual void visit( ContextInstType *contextInst );
     72                virtual void visit( TraitInstType *contextInst );
    7073                virtual void visit( StructInstType *contextInst );
    7174                virtual void visit( UnionInstType *contextInst );
     
    7881                void leaveScope();
    7982
    80                 void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const;
    81                 DeclarationWithType* lookupId( const std::string &id) const;
     83                /// Gets all declarations with the given ID
     84                void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const;
     85                /// Gets the top-most type declaration with the given ID
    8286                NamedTypeDecl *lookupType( const std::string &id ) const;
     87                /// Gets the top-most struct declaration with the given ID
    8388                StructDecl *lookupStruct( const std::string &id ) const;
     89                /// Gets the top-most enum declaration with the given ID
    8490                EnumDecl *lookupEnum( const std::string &id ) const;
     91                /// Gets the top-most union declaration with the given ID
    8592                UnionDecl *lookupUnion( const std::string &id ) const;
    86                 ContextDecl *lookupContext( const std::string &id ) const;
     93                /// Gets the top-most trait declaration with the given ID
     94                TraitDecl *lookupTrait( const std::string &id ) const;
    8795 
    8896                void print( std::ostream &os, int indent = 0 ) const;
    8997          private:
    90                 IdTable idTable;
    91                 TypeTable typeTable;
    92                 StructTable structTable;
    93                 EnumTable enumTable;
    94                 UnionTable unionTable;
    95                 ContextTable contextTable;
    96  
    97                 bool doDebug;                                   // display debugging trace
     98                /// looks up a specific mangled ID at the given scope
     99                DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
     100                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
     101                bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     102                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
     103                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
     104                StructDecl *lookupStructAtScope( const std::string &id, unsigned long scope ) const;
     105                EnumDecl *lookupEnumAtScope( const std::string &id, unsigned long scope ) const;
     106                UnionDecl *lookupUnionAtScope( const std::string &id, unsigned long scope ) const;
     107                TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const;
     108               
     109                void addId( DeclarationWithType *decl );
     110                void addType( NamedTypeDecl *decl );
     111                void addStruct( const std::string &id );
     112                void addStruct( StructDecl *decl );
     113                void addEnum( EnumDecl *decl );
     114                void addUnion( const std::string &id );
     115                void addUnion( UnionDecl *decl );
     116                void addTrait( TraitDecl *decl );
     117               
     118                struct Impl;
     119                Impl *tables;         ///< Copy-on-write instance of table data structure
     120                unsigned long scope;  ///< Scope index of this pointer
     121                bool doDebug;         ///< Display debugging trace?
     122
     123                /// Takes a new ref to a table (returns null if null)
     124                static Impl *newRef( Impl *toClone );
     125                /// Clears a ref to a table (does nothing if null)
     126                static void deleteRef( Impl *toFree );
     127
     128                /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
     129                void makeWritable();
    98130        };
    99131} // namespace SymTab
  • src/SymTab/Mangler.cc

    rc5833e8 r0f9e4403  
    224224                acceptAll( tupleType->get_types(), *this );
    225225                mangleName << "_";
     226        }
     227
     228        void Mangler::visit( VarArgsType *varArgsType ) {
     229                printQualifiers( varArgsType );
     230                mangleName << "VARGS";
    226231        }
    227232
  • src/SymTab/Mangler.h

    rc5833e8 r0f9e4403  
    4545                virtual void visit( TypeInstType *aggregateUseType );
    4646                virtual void visit( TupleType *tupleType );
     47                virtual void visit( VarArgsType *varArgsType );
    4748 
    4849                std::string get_mangleName() { return mangleName.str(); }
  • src/SymTab/TypeEquality.cc

    rc5833e8 r0f9e4403  
    4141                virtual void visit( EnumInstType *enumInst );
    4242                virtual void visit( TypeInstType *typeInst );
     43                virtual void visit( VarArgsType *varArgsType );
    4344
    4445                void handleQualifiers( Type * t );
     
    191192                }
    192193        }
     194
     195        void TypeEquality::visit( VarArgsType *varArgsType ) {
     196                handleQualifiers( varArgsType );
     197                if ( ! dynamic_cast< VarArgsType * >( other ) ) {
     198                        result = false;
     199                }
     200        }
    193201} // namespace SymTab
  • src/SymTab/Validate.cc

    rc5833e8 r0f9e4403  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 27 22:03:12 2016
    13 // Update Count     : 225
     12// Last Modified On : Wed Apr 13 16:39:30 2016
     13// Update Count     : 251
    1414//
    1515
     
    4040#include <list>
    4141#include <iterator>
     42#include "Common/utility.h"
     43#include "Common/UniqueName.h"
    4244#include "Validate.h"
    4345#include "SynTree/Visitor.h"
    4446#include "SynTree/Mutator.h"
    4547#include "SynTree/Type.h"
     48#include "SynTree/Expression.h"
    4649#include "SynTree/Statement.h"
    4750#include "SynTree/TypeSubstitution.h"
     
    4952#include "FixFunction.h"
    5053// #include "ImplementationType.h"
    51 #include "Common/utility.h"
    52 #include "Common/UniqueName.h"
     54#include "GenPoly/DeclMutator.h"
    5355#include "AddVisit.h"
    5456#include "MakeLibCfa.h"
     
    7072
    7173                virtual void visit( CompoundStmt *compoundStmt );
    72                 virtual void visit( IfStmt *ifStmt );
    73                 virtual void visit( WhileStmt *whileStmt );
    74                 virtual void visit( ForStmt *forStmt );
    7574                virtual void visit( SwitchStmt *switchStmt );
    7675                virtual void visit( ChooseStmt *chooseStmt );
    77                 virtual void visit( CaseStmt *caseStmt );
    78                 virtual void visit( CatchStmt *catchStmt );
     76                // virtual void visit( CaseStmt *caseStmt );
    7977          private:
    8078                HoistStruct();
     
    10199                virtual void visit( StructInstType *structInst );
    102100                virtual void visit( UnionInstType *unionInst );
    103                 virtual void visit( ContextInstType *contextInst );
     101                virtual void visit( TraitInstType *contextInst );
    104102                virtual void visit( StructDecl *structDecl );
    105103                virtual void visit( UnionDecl *unionDecl );
     
    137135                virtual void visit( UnionDecl *structDecl );
    138136                virtual void visit( TypeDecl *typeDecl );
    139                 virtual void visit( ContextDecl *ctxDecl );
     137                virtual void visit( TraitDecl *ctxDecl );
    140138                virtual void visit( FunctionDecl *functionDecl );
    141139
     
    144142
    145143                virtual void visit( CompoundStmt *compoundStmt );
    146                 virtual void visit( IfStmt *ifStmt );
    147                 virtual void visit( WhileStmt *whileStmt );
    148                 virtual void visit( ForStmt *forStmt );
    149144                virtual void visit( SwitchStmt *switchStmt );
    150145                virtual void visit( ChooseStmt *chooseStmt );
    151                 virtual void visit( CaseStmt *caseStmt );
    152                 virtual void visit( CatchStmt *catchStmt );
     146                // virtual void visit( CaseStmt *caseStmt );
    153147
    154148                AutogenerateRoutines() : functionNesting( 0 ) {}
     
    166160                /// and return something if the return type is non-void.
    167161                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    168 
    169162          private:
    170163                virtual void visit( FunctionDecl * functionDecl );
     
    192185                virtual Declaration *mutate( UnionDecl * unionDecl );
    193186                virtual Declaration *mutate( EnumDecl * enumDecl );
    194                 virtual Declaration *mutate( ContextDecl * contextDecl );
     187                virtual Declaration *mutate( TraitDecl * contextDecl );
    195188
    196189                template<typename AggDecl>
    197190                AggDecl *handleAggregate( AggDecl * aggDecl );
    198191
     192                template<typename AggDecl>
     193                void addImplicitTypedef( AggDecl * aggDecl );
     194               
    199195                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
    200196                TypedefMap typedefNames;
     
    202198        };
    203199
     200        class CompoundLiteral : public GenPoly::DeclMutator {
     201                DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;
     202
     203                virtual DeclarationWithType * mutate( ObjectDecl *objectDecl );
     204                virtual Expression *mutate( CompoundLiteralExpr *compLitExpr );
     205        };
     206
    204207        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    205208                Pass1 pass1;
    206209                Pass2 pass2( doDebug, 0 );
    207210                Pass3 pass3( 0 );
     211                CompoundLiteral compoundliteral;
     212
    208213                EliminateTypedef::eliminateTypedef( translationUnit );
    209214                HoistStruct::hoistStruct( translationUnit );
     
    211216                acceptAll( translationUnit, pass2 );
    212217                ReturnChecker::checkFunctionReturns( translationUnit );
     218                mutateAll( translationUnit, compoundliteral );
    213219                AutogenerateRoutines::autogenerateRoutines( translationUnit );
    214220                acceptAll( translationUnit, pass3 );
     
    292298        }
    293299
    294         void HoistStruct::visit( IfStmt *ifStmt ) {
    295                 addVisit( ifStmt, *this );
    296         }
    297 
    298         void HoistStruct::visit( WhileStmt *whileStmt ) {
    299                 addVisit( whileStmt, *this );
    300         }
    301 
    302         void HoistStruct::visit( ForStmt *forStmt ) {
    303                 addVisit( forStmt, *this );
    304         }
    305 
    306300        void HoistStruct::visit( SwitchStmt *switchStmt ) {
    307301                addVisit( switchStmt, *this );
     
    312306        }
    313307
    314         void HoistStruct::visit( CaseStmt *caseStmt ) {
    315                 addVisit( caseStmt, *this );
    316         }
    317 
    318         void HoistStruct::visit( CatchStmt *cathStmt ) {
    319                 addVisit( cathStmt, *this );
    320         }
     308        // void HoistStruct::visit( CaseStmt *caseStmt ) {
     309        //      addVisit( caseStmt, *this );
     310        // }
    321311
    322312        void Pass1::visit( EnumDecl *enumDecl ) {
     
    404394        }
    405395
    406         void Pass2::visit( ContextInstType *contextInst ) {
     396        void Pass2::visit( TraitInstType *contextInst ) {
    407397                Parent::visit( contextInst );
    408                 ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() );
     398                TraitDecl *ctx = indexer->lookupTrait( contextInst->get_name() );
    409399                if ( ! ctx ) {
    410400                        throw SemanticError( "use of undeclared context " + contextInst->get_name() );
     
    412402                for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
    413403                        for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    414                                 if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) {
     404                                if ( TraitInstType *otherCtx = dynamic_cast< TraitInstType * >(*assert ) ) {
    415405                                        cloneAll( otherCtx->get_members(), contextInst->get_members() );
    416406                                } else {
     
    476466                        while ( ! toBeDone.empty() ) {
    477467                                for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
    478                                         if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) {
     468                                        if ( TraitInstType *ctx = dynamic_cast< TraitInstType * >( (*assertion )->get_type() ) ) {
    479469                                                for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
    480470                                                        DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );
     
    851841        }
    852842
    853         void AutogenerateRoutines::visit( ContextDecl *) {
     843        void AutogenerateRoutines::visit( TraitDecl *) {
    854844                // ensure that we don't add assignment ops for types defined as part of the context
    855845        }
     
    874864        }
    875865
    876         void AutogenerateRoutines::visit( IfStmt *ifStmt ) {
    877                 visitStatement( ifStmt );
    878         }
    879 
    880         void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {
    881                 visitStatement( whileStmt );
    882         }
    883 
    884         void AutogenerateRoutines::visit( ForStmt *forStmt ) {
    885                 visitStatement( forStmt );
    886         }
    887 
    888866        void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) {
    889867                visitStatement( switchStmt );
     
    894872        }
    895873
    896         void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
    897                 visitStatement( caseStmt );
    898         }
    899 
    900         void AutogenerateRoutines::visit( CatchStmt *cathStmt ) {
    901                 visitStatement( cathStmt );
    902         }
     874        // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
     875        //      visitStatement( caseStmt );
     876        // }
    903877
    904878        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
     
    10431017        }
    10441018
    1045         // there may be typedefs nested within aggregates
    1046         // in order for everything to work properly, these
    1047         // should be removed as well
     1019        // there may be typedefs nested within aggregates in order for everything to work properly, these should be removed
     1020        // as well
    10481021        template<typename AggDecl>
    10491022        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
     
    10591032                return aggDecl;
    10601033        }
    1061 
     1034       
     1035        template<typename AggDecl>
     1036        void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
     1037                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
     1038                        Type *type;
     1039                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
     1040                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
     1041                        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) {
     1042                                type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() );
     1043                        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl )  ) {
     1044                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
     1045                        } // if
     1046                        TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type );
     1047                        typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     1048                } // if
     1049        }
    10621050        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
     1051                addImplicitTypedef( structDecl );
    10631052                Mutator::mutate( structDecl );
    10641053                return handleAggregate( structDecl );
     
    10661055
    10671056        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
     1057                addImplicitTypedef( unionDecl );
    10681058                Mutator::mutate( unionDecl );
    10691059                return handleAggregate( unionDecl );
     
    10711061
    10721062        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
     1063                addImplicitTypedef( enumDecl );
    10731064                Mutator::mutate( enumDecl );
    10741065                return handleAggregate( enumDecl );
    10751066        }
    10761067
    1077                 Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
     1068        Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) {
    10781069                Mutator::mutate( contextDecl );
    10791070                return handleAggregate( contextDecl );
    10801071        }
    10811072
     1073        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
     1074                storageclass = objectDecl->get_storageClass();
     1075                DeclarationWithType * temp = Mutator::mutate( objectDecl );
     1076                storageclass = DeclarationNode::NoStorageClass;
     1077                return temp;
     1078        }
     1079
     1080        Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
     1081                // transform [storage_class] ... (struct S){ 3, ... };
     1082                // into [storage_class] struct S temp =  { 3, ... };
     1083                static UniqueName indexName( "_compLit" );
     1084
     1085                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() );
     1086                compLitExpr->set_type( 0 );
     1087                compLitExpr->set_initializer( 0 );
     1088                delete compLitExpr;
     1089                DeclarationWithType * newtempvar = mutate( tempvar );
     1090                addDeclaration( newtempvar );                                   // add modified temporary to current block
     1091                return new VariableExpr( newtempvar );
     1092        }
    10821093} // namespace SymTab
    10831094
  • src/SymTab/module.mk

    rc5833e8 r0f9e4403  
    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.