Changeset aaeacf4 for src/SynTree


Ignore:
Timestamp:
Jun 12, 2019, 4:06:32 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
21300d7
Parents:
6e3e0717
Message:

Removed global look-up table from UniqueId to Decl

Location:
src/SynTree
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/ApplicationExpr.cc

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

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

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

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

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