Changeset 6f096d2 for src/SymTab


Ignore:
Timestamp:
Jul 12, 2019, 4:34:56 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:
e3d7f9f
Parents:
8fd52e90
Message:

Resolver now uses constant interface

Location:
src/SymTab
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/SymTab/Indexer.cc

    r8fd52e90 r6f096d2  
    188188        }
    189189
    190         bool isFunction( DeclarationWithType * decl ) {
     190        bool isFunction( const DeclarationWithType * decl ) {
    191191                return GenPoly::getFunctionType( decl->get_type() );
    192192        }
    193193
    194         bool isObject( DeclarationWithType * decl ) {
     194        bool isObject( const DeclarationWithType * decl ) {
    195195                return ! isFunction( decl );
    196196        }
    197197
    198         bool isDefinition( DeclarationWithType * decl ) {
    199                 if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) {
     198        bool isDefinition( const DeclarationWithType * decl ) {
     199                if ( const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ) ) {
    200200                        // a function is a definition if it has a body
    201201                        return func->statements;
     
    209209
    210210        bool Indexer::addedIdConflicts(
    211                         const Indexer::IdData & existing, DeclarationWithType * added,
    212                         Indexer::OnConflict handleConflicts, BaseSyntaxNode * deleteStmt ) {
     211                        const Indexer::IdData & existing, const DeclarationWithType * added,
     212                        Indexer::OnConflict handleConflicts, const BaseSyntaxNode * deleteStmt ) {
    213213                // if we're giving the same name mangling to things of different types then there is
    214214                // something wrong
     
    274274        }
    275275
    276         bool Indexer::hasIncompatibleCDecl(
    277                         const std::string & id, const std::string &mangleName ) const {
     276        bool Indexer::hasIncompatibleCDecl(const std::string & id, const std::string &mangleName ) const {
    278277                if ( ! idTable ) return false;
    279278
     
    295294
    296295        /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function
    297         std::string getOtypeKey( FunctionDecl * function ) {
     296        std::string getOtypeKey( const FunctionDecl * function ) {
    298297                auto& params = function->type->parameters;
    299298                assert( ! params.empty() );
     
    306305        /// gets the declaration for the function acting on a type specified by otype key,
    307306        /// nullptr if none such
    308         FunctionDecl * getFunctionForOtype( DeclarationWithType * decl, const std::string& otypeKey ) {
    309                 FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl );
     307        const FunctionDecl * getFunctionForOtype( const DeclarationWithType * decl, const std::string& otypeKey ) {
     308                const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl );
    310309                if ( ! func || otypeKey != getOtypeKey( func ) ) return nullptr;
    311310                return func;
    312311        }
    313312
    314         bool Indexer::removeSpecialOverrides(
    315                         Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) {
     313        bool Indexer::removeSpecialOverrides(Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) {
    316314                // if a type contains user defined ctor/dtor/assign, then special rules trigger, which
    317315                // determinethe set of ctor/dtor/assign that can be used  by the requester. In particular,
     
    324322
    325323                // only relevant on function declarations
    326                 FunctionDecl * function = dynamic_cast< FunctionDecl * >( data.id );
     324                const FunctionDecl * function = dynamic_cast< const FunctionDecl * >( data.id );
    327325                if ( ! function ) return true;
    328326                // only need to perform this check for constructors, destructors, and assignment functions
     
    343341                        for ( const auto& entry : * mangleTable ) {
    344342                                // skip decls that aren't functions or are for the wrong type
    345                                 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     343                                const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    346344                                if ( ! decl ) continue;
    347345
     
    382380                        for ( const auto& entry : * mangleTable ) {
    383381                                // skip decls that aren't functions or are for the wrong type
    384                                 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     382                                const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    385383                                if ( ! decl ) continue;
    386384
     
    410408                        for ( const auto& entry : * mangleTable ) {
    411409                                // skip decls that aren't functions or are for the wrong type
    412                                 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     410                                const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    413411                                if ( ! decl ) continue;
    414412
     
    433431        }
    434432
    435         void Indexer::addId(
    436                         DeclarationWithType * decl, OnConflict handleConflicts, Expression * baseExpr,
    437                         BaseSyntaxNode * deleteStmt ) {
     433        void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr,
     434                        const BaseSyntaxNode * deleteStmt ) {
    438435                ++* stats().add_calls;
    439436                const std::string &name = decl->name;
     
    508505        }
    509506
    510         void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) {
     507        void Indexer::addId( const DeclarationWithType * decl, const Expression * baseExpr ) {
    511508                // default handling of conflicts is to raise an error
    512509                addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr );
    513510        }
    514511
    515         void Indexer::addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt ) {
     512        void Indexer::addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode * deleteStmt ) {
    516513                // default handling of conflicts is to raise an error
    517514                addId( decl, OnConflict::error(), nullptr, deleteStmt );
    518515        }
    519516
    520         bool addedTypeConflicts( NamedTypeDecl * existing, NamedTypeDecl * added ) {
     517        bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) {
    521518                if ( existing->base == nullptr ) {
    522519                        return false;
     
    535532        }
    536533
    537         void Indexer::addType( NamedTypeDecl * decl ) {
     534        void Indexer::addType( const NamedTypeDecl * decl ) {
    538535                ++* stats().add_calls;
    539536                const std::string & id = decl->name;
     
    554551        }
    555552
    556         bool addedDeclConflicts( AggregateDecl * existing, AggregateDecl * added ) {
     553        bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) {
    557554                if ( ! existing->body ) {
    558555                        return false;
     
    567564        }
    568565
    569         void Indexer::addStruct( StructDecl * decl ) {
     566        void Indexer::addStruct( const StructDecl * decl ) {
    570567                ++* stats().add_calls;
    571568                const std::string & id = decl->name;
     
    586583        }
    587584
    588         void Indexer::addEnum( EnumDecl * decl ) {
     585        void Indexer::addEnum( const EnumDecl * decl ) {
    589586                ++* stats().add_calls;
    590587                const std::string & id = decl->name;
     
    609606        }
    610607
    611         void Indexer::addUnion( UnionDecl * decl ) {
     608        void Indexer::addUnion( const UnionDecl * decl ) {
    612609                ++* stats().add_calls;
    613610                const std::string & id = decl->name;
     
    628625        }
    629626
    630         void Indexer::addTrait( TraitDecl * decl ) {
     627        void Indexer::addTrait( const TraitDecl * decl ) {
    631628                ++* stats().add_calls;
    632629                const std::string & id = decl->name;
     
    647644        }
    648645
    649         void Indexer::addMembers( AggregateDecl * aggr, Expression * expr,
    650                         OnConflict handleConflicts ) {
     646        void Indexer::addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts ) {
    651647                for ( Declaration * decl : aggr->members ) {
    652648                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    653649                                addId( dwt, handleConflicts, expr );
    654650                                if ( dwt->name == "" ) {
    655                                         Type * t = dwt->get_type()->stripReferences();
    656                                         if ( dynamic_cast<StructInstType *>( t ) || dynamic_cast<UnionInstType *>( t ) ) {
     651                                        const Type * t = dwt->get_type()->stripReferences();
     652                                        if ( dynamic_cast<const StructInstType *>( t ) || dynamic_cast<const UnionInstType *>( t ) ) {
    657653                                                Expression * base = expr->clone();
    658654                                                ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost?
     
    665661        }
    666662
    667         void Indexer::addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt ) {
    668                 for ( Expression * expr : withExprs ) {
     663        void Indexer::addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode * withStmt ) {
     664                for ( const Expression * expr : withExprs ) {
    669665                        if ( expr->result ) {
    670666                                AggregateDecl * aggr = expr->result->stripReferences()->getAggr();
     
    689685        }
    690686
    691         void Indexer::addFunctionType( FunctionType * ftype ) {
     687        void Indexer::addFunctionType( const FunctionType * ftype ) {
    692688                addTypes( ftype->forall );
    693689                addIds( ftype->returnVals );
     
    700696                        Expression * base = baseExpr->clone();
    701697                        ResolvExpr::referenceToRvalueConversion( base, cost );
    702                         ret = new MemberExpr( id, base );
     698                        ret = new MemberExpr( const_cast<DeclarationWithType *>(id), base );
    703699                        // xxx - this introduces hidden environments, for now remove them.
    704700                        // std::swap( base->env, ret->env );
     
    706702                        base->env = nullptr;
    707703                } else {
    708                         ret = new VariableExpr( id );
    709                 }
    710                 if ( deleteStmt ) ret = new DeletedExpr( ret, deleteStmt );
     704                        ret = new VariableExpr( const_cast<DeclarationWithType *>(id) );
     705                }
     706                if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<BaseSyntaxNode *>(deleteStmt) );
    711707                return ret;
    712708        }
  • TabularUnified src/SymTab/Indexer.h

    r8fd52e90 r6f096d2  
    4040
    4141                struct IdData {
    42                         DeclarationWithType * id = nullptr;
    43                         Expression * baseExpr = nullptr; // WithExpr
     42                        const DeclarationWithType * id = nullptr;
     43                        const Expression * baseExpr = nullptr; // WithExpr
    4444
    4545                        /// non-null if this declaration is deleted
    46                         BaseSyntaxNode * deleteStmt = nullptr;
     46                        const BaseSyntaxNode * deleteStmt = nullptr;
    4747                        /// scope of identifier
    4848                        unsigned long scope = 0;
     
    5151                        IdData() = default;
    5252                        IdData(
    53                                 DeclarationWithType * id, Expression * baseExpr, BaseSyntaxNode * deleteStmt,
     53                                const DeclarationWithType * id, const Expression * baseExpr, const BaseSyntaxNode * deleteStmt,
    5454                                unsigned long scope )
    5555                                : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ), scope( scope ) {}
    56                         IdData( const IdData& o, BaseSyntaxNode * deleteStmt )
     56                        IdData( const IdData& o, const BaseSyntaxNode * deleteStmt )
    5757                                : id( o.id ), baseExpr( o.baseExpr ), deleteStmt( deleteStmt ), scope( o.scope ) {}
    5858
     
    8282                const EnumDecl * globalLookupEnum( const std::string & id ) const;
    8383
    84                 void addId( DeclarationWithType * decl, Expression * baseExpr = nullptr );
    85                 void addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt );
     84                void addId( const DeclarationWithType * decl, const Expression * baseExpr = nullptr );
     85                void addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode * deleteStmt );
    8686
    87                 void addType( NamedTypeDecl * decl );
     87                void addType( const NamedTypeDecl * decl );
    8888                void addStruct( const std::string & id );
    89                 void addStruct( StructDecl * decl );
    90                 void addEnum( EnumDecl * decl );
     89                void addStruct( const StructDecl * decl );
     90                void addEnum( const EnumDecl * decl );
    9191                void addUnion( const std::string & id );
    92                 void addUnion( UnionDecl * decl );
    93                 void addTrait( TraitDecl * decl );
     92                void addUnion( const UnionDecl * decl );
     93                void addTrait( const TraitDecl * decl );
    9494
    9595                /// adds all of the IDs from WithStmt exprs
    96                 void addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt );
     96                void addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode * withStmt );
    9797
    9898                /// convenience function for adding a list of Ids to the indexer
     
    103103
    104104                /// convenience function for adding all of the declarations in a function type to the indexer
    105                 void addFunctionType( FunctionType * ftype );
     105                void addFunctionType( const FunctionType * ftype );
    106106
    107107          private:
     
    109109                template<typename Decl>
    110110                struct Scoped {
    111                         Decl * decl;           ///< declaration
     111                        const Decl * decl;           ///< declaration
    112112                        unsigned long scope;  ///< scope of this declaration
    113113
    114                         Scoped(Decl * d, unsigned long s) : decl(d), scope(s) {}
     114                        Scoped(const Decl * d, unsigned long s) : decl(d), scope(s) {}
    115115                };
    116116
     
    144144                /// Removes matching autogenerated constructors and destructors so that they will not be
    145145                /// selected. If returns false, passed decl should not be added.
    146                 bool removeSpecialOverrides( IdData& decl, MangleTable::Ptr& mangleTable );
     146                bool removeSpecialOverrides( IdData & decl, MangleTable::Ptr & mangleTable );
    147147
    148148                /// Options for handling identifier conflicts
     
    152152                                Delete  ///< Delete the earlier version with the delete statement
    153153                        } mode;
    154                         BaseSyntaxNode * deleteStmt;  ///< Statement that deletes this expression
     154                        const BaseSyntaxNode * deleteStmt;  ///< Statement that deletes this expression
    155155
    156156                private:
    157157                        OnConflict() : mode(Error), deleteStmt(nullptr) {}
    158                         OnConflict( BaseSyntaxNode * d ) : mode(Delete), deleteStmt(d) {}
     158                        OnConflict( const BaseSyntaxNode * d ) : mode(Delete), deleteStmt(d) {}
    159159                public:
    160160                        OnConflict( const OnConflict& ) = default;
    161161
    162162                        static OnConflict error() { return {}; }
    163                         static OnConflict deleteWith( BaseSyntaxNode * d ) { return { d }; }
     163                        static OnConflict deleteWith( const BaseSyntaxNode * d ) { return { d }; }
    164164                };
    165165
    166166                /// true if the existing identifier conflicts with the added identifier
    167167                bool addedIdConflicts(
    168                         const IdData& existing, DeclarationWithType * added, OnConflict handleConflicts,
    169                         BaseSyntaxNode * deleteStmt );
     168                        const IdData & existing, const DeclarationWithType * added, OnConflict handleConflicts,
     169                        const BaseSyntaxNode * deleteStmt );
    170170
    171171                /// common code for addId, addDeletedId, etc.
    172                 void addId(
    173                         DeclarationWithType * decl, OnConflict handleConflicts,
    174                         Expression * baseExpr = nullptr, BaseSyntaxNode * deleteStmt = nullptr );
     172                void addId(const DeclarationWithType * decl, OnConflict handleConflicts,
     173                        const Expression * baseExpr = nullptr, const BaseSyntaxNode * deleteStmt = nullptr );
    175174
    176175                /// adds all of the members of the Aggregate (addWith helper)
    177                 void addMembers( AggregateDecl * aggr, Expression * expr, OnConflict handleConflicts );
     176                void addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts );
    178177
    179178                /// returns true if there exists a declaration with C linkage and the given name with the same mangled name
    180                 bool hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const;
     179                bool hasCompatibleCDecl( const std::string & id, const std::string & mangleName ) const;
    181180                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
    182                 bool hasIncompatibleCDecl( const std::string & id, const std::string &mangleName ) const;
     181                bool hasIncompatibleCDecl( const std::string & id, const std::string & mangleName ) const;
    183182        };
    184183} // namespace SymTab
  • TabularUnified src/SymTab/Mangler.cc

    r8fd52e90 r6f096d2  
    4242                                Mangler_old( const Mangler_old & ) = delete;
    4343
    44                                 void previsit( BaseSyntaxNode * ) { visit_children = false; }
    45 
    46                                 void postvisit( ObjectDecl * declaration );
    47                                 void postvisit( FunctionDecl * declaration );
    48                                 void postvisit( TypeDecl * declaration );
    49 
    50                                 void postvisit( VoidType * voidType );
    51                                 void postvisit( BasicType * basicType );
    52                                 void postvisit( PointerType * pointerType );
    53                                 void postvisit( ArrayType * arrayType );
    54                                 void postvisit( ReferenceType * refType );
    55                                 void postvisit( FunctionType * functionType );
    56                                 void postvisit( StructInstType * aggregateUseType );
    57                                 void postvisit( UnionInstType * aggregateUseType );
    58                                 void postvisit( EnumInstType * aggregateUseType );
    59                                 void postvisit( TypeInstType * aggregateUseType );
    60                                 void postvisit( TraitInstType * inst );
    61                                 void postvisit( TupleType * tupleType );
    62                                 void postvisit( VarArgsType * varArgsType );
    63                                 void postvisit( ZeroType * zeroType );
    64                                 void postvisit( OneType * oneType );
    65                                 void postvisit( QualifiedType * qualType );
     44                                void previsit( const BaseSyntaxNode * ) { visit_children = false; }
     45
     46                                void postvisit( const ObjectDecl * declaration );
     47                                void postvisit( const FunctionDecl * declaration );
     48                                void postvisit( const TypeDecl * declaration );
     49
     50                                void postvisit( const VoidType * voidType );
     51                                void postvisit( const BasicType * basicType );
     52                                void postvisit( const PointerType * pointerType );
     53                                void postvisit( const ArrayType * arrayType );
     54                                void postvisit( const ReferenceType * refType );
     55                                void postvisit( const FunctionType * functionType );
     56                                void postvisit( const StructInstType * aggregateUseType );
     57                                void postvisit( const UnionInstType * aggregateUseType );
     58                                void postvisit( const EnumInstType * aggregateUseType );
     59                                void postvisit( const TypeInstType * aggregateUseType );
     60                                void postvisit( const TraitInstType * inst );
     61                                void postvisit( const TupleType * tupleType );
     62                                void postvisit( const VarArgsType * varArgsType );
     63                                void postvisit( const ZeroType * zeroType );
     64                                void postvisit( const OneType * oneType );
     65                                void postvisit( const QualifiedType * qualType );
    6666
    6767                                std::string get_mangleName() { return mangleName.str(); }
     
    7979
    8080                          public:
    81                                 Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
     81                                Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    8282                                        int nextVarNum, const VarMapType& varNums );
    8383
    8484                          private:
    85                                 void mangleDecl( DeclarationWithType *declaration );
    86                                 void mangleRef( ReferenceToType *refType, std::string prefix );
    87 
    88                                 void printQualifiers( Type *type );
     85                                void mangleDecl( const DeclarationWithType * declaration );
     86                                void mangleRef( const ReferenceToType * refType, std::string prefix );
     87
     88                                void printQualifiers( const Type *type );
    8989                        }; // Mangler_old
    9090                } // namespace
    9191
    92                 std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) {
     92                std::string mangle( const BaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) {
    9393                        PassVisitor<Mangler_old> mangler( mangleOverridable, typeMode, mangleGenericParams );
    9494                        maybeAccept( decl, mangler );
     
    9696                }
    9797
    98                 std::string mangleType( Type * ty ) {
     98                std::string mangleType( const Type * ty ) {
    9999                        PassVisitor<Mangler_old> mangler( false, true, true );
    100100                        maybeAccept( ty, mangler );
     
    102102                }
    103103
    104                 std::string mangleConcrete( Type * ty ) {
     104                std::string mangleConcrete( const Type * ty ) {
    105105                        PassVisitor<Mangler_old> mangler( false, false, false );
    106106                        maybeAccept( ty, mangler );
     
    110110                namespace {
    111111                        Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams )
    112                                 : nextVarNum( 0 ), isTopLevel( true ), 
    113                                 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 
     112                                : nextVarNum( 0 ), isTopLevel( true ),
     113                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    114114                                mangleGenericParams( mangleGenericParams ) {}
    115                        
    116                         Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
     115
     116                        Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    117117                                int nextVarNum, const VarMapType& varNums )
    118                                 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), 
    119                                 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 
     118                                : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ),
     119                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    120120                                mangleGenericParams( mangleGenericParams ) {}
    121121
    122                         void Mangler_old::mangleDecl( DeclarationWithType * declaration ) {
     122                        void Mangler_old::mangleDecl( const DeclarationWithType * declaration ) {
    123123                                bool wasTopLevel = isTopLevel;
    124124                                if ( isTopLevel ) {
     
    150150                        }
    151151
    152                         void Mangler_old::postvisit( ObjectDecl * declaration ) {
     152                        void Mangler_old::postvisit( const ObjectDecl * declaration ) {
    153153                                mangleDecl( declaration );
    154154                        }
    155155
    156                         void Mangler_old::postvisit( FunctionDecl * declaration ) {
     156                        void Mangler_old::postvisit( const FunctionDecl * declaration ) {
    157157                                mangleDecl( declaration );
    158158                        }
    159159
    160                         void Mangler_old::postvisit( VoidType * voidType ) {
     160                        void Mangler_old::postvisit( const VoidType * voidType ) {
    161161                                printQualifiers( voidType );
    162162                                mangleName << Encoding::void_t;
    163163                        }
    164164
    165                         void Mangler_old::postvisit( BasicType * basicType ) {
     165                        void Mangler_old::postvisit( const BasicType * basicType ) {
    166166                                printQualifiers( basicType );
    167                                 assertf( basicType->get_kind() < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->get_kind() );
    168                                 mangleName << Encoding::basicTypes[ basicType->get_kind() ];
    169                         }
    170 
    171                         void Mangler_old::postvisit( PointerType * pointerType ) {
     167                                assertf( basicType->kind < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->kind );
     168                                mangleName << Encoding::basicTypes[ basicType->kind ];
     169                        }
     170
     171                        void Mangler_old::postvisit( const PointerType * pointerType ) {
    172172                                printQualifiers( pointerType );
    173173                                // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers
     
    176176                        }
    177177
    178                         void Mangler_old::postvisit( ArrayType * arrayType ) {
     178                        void Mangler_old::postvisit( const ArrayType * arrayType ) {
    179179                                // TODO: encode dimension
    180180                                printQualifiers( arrayType );
     
    183183                        }
    184184
    185                         void Mangler_old::postvisit( ReferenceType * refType ) {
     185                        void Mangler_old::postvisit( const ReferenceType * refType ) {
    186186                                // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload.
    187187                                // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.),
     
    202202                        }
    203203
    204                         void Mangler_old::postvisit( FunctionType * functionType ) {
     204                        void Mangler_old::postvisit( const FunctionType * functionType ) {
    205205                                printQualifiers( functionType );
    206206                                mangleName << Encoding::function;
     
    219219                        }
    220220
    221                         void Mangler_old::mangleRef( ReferenceToType * refType, std::string prefix ) {
     221                        void Mangler_old::mangleRef( const ReferenceToType * refType, std::string prefix ) {
    222222                                printQualifiers( refType );
    223223
     
    225225
    226226                                if ( mangleGenericParams ) {
    227                                         std::list< Expression* >& params = refType->parameters;
     227                                        const std::list< Expression* > & params = refType->parameters;
    228228                                        if ( ! params.empty() ) {
    229229                                                mangleName << "_";
    230                                                 for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) {
    231                                                         TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
    232                                                         assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(*param));
     230                                                for ( const Expression * param : params ) {
     231                                                        const TypeExpr * paramType = dynamic_cast< const TypeExpr * >( param );
     232                                                        assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param));
    233233                                                        maybeAccept( paramType->type, *visitor );
    234234                                                }
     
    238238                        }
    239239
    240                         void Mangler_old::postvisit( StructInstType * aggregateUseType ) {
     240                        void Mangler_old::postvisit( const StructInstType * aggregateUseType ) {
    241241                                mangleRef( aggregateUseType, Encoding::struct_t );
    242242                        }
    243243
    244                         void Mangler_old::postvisit( UnionInstType * aggregateUseType ) {
     244                        void Mangler_old::postvisit( const UnionInstType * aggregateUseType ) {
    245245                                mangleRef( aggregateUseType, Encoding::union_t );
    246246                        }
    247247
    248                         void Mangler_old::postvisit( EnumInstType * aggregateUseType ) {
     248                        void Mangler_old::postvisit( const EnumInstType * aggregateUseType ) {
    249249                                mangleRef( aggregateUseType, Encoding::enum_t );
    250250                        }
    251251
    252                         void Mangler_old::postvisit( TypeInstType * typeInst ) {
     252                        void Mangler_old::postvisit( const TypeInstType * typeInst ) {
    253253                                VarMapType::iterator varNum = varNums.find( typeInst->get_name() );
    254254                                if ( varNum == varNums.end() ) {
     
    266266                        }
    267267
    268                         void Mangler_old::postvisit( TraitInstType * inst ) {
     268                        void Mangler_old::postvisit( const TraitInstType * inst ) {
    269269                                printQualifiers( inst );
    270270                                mangleName << inst->name.size() << inst->name;
    271271                        }
    272272
    273                         void Mangler_old::postvisit( TupleType * tupleType ) {
     273                        void Mangler_old::postvisit( const TupleType * tupleType ) {
    274274                                printQualifiers( tupleType );
    275275                                mangleName << Encoding::tuple << tupleType->types.size();
     
    277277                        }
    278278
    279                         void Mangler_old::postvisit( VarArgsType * varArgsType ) {
     279                        void Mangler_old::postvisit( const VarArgsType * varArgsType ) {
    280280                                printQualifiers( varArgsType );
    281281                                static const std::string vargs = "__builtin_va_list";
     
    283283                        }
    284284
    285                         void Mangler_old::postvisit( ZeroType * ) {
     285                        void Mangler_old::postvisit( const ZeroType * ) {
    286286                                mangleName << Encoding::zero;
    287287                        }
    288288
    289                         void Mangler_old::postvisit( OneType * ) {
     289                        void Mangler_old::postvisit( const OneType * ) {
    290290                                mangleName << Encoding::one;
    291291                        }
    292292
    293                         void Mangler_old::postvisit( QualifiedType * qualType ) {
     293                        void Mangler_old::postvisit( const QualifiedType * qualType ) {
    294294                                bool inqual = inQualifiedType;
    295295                                if (! inqual ) {
     
    307307                        }
    308308
    309                         void Mangler_old::postvisit( TypeDecl * decl ) {
     309                        void Mangler_old::postvisit( const TypeDecl * decl ) {
    310310                                // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be
    311311                                // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa.
     
    314314                                // aside from the assert false.
    315315                                assertf(false, "Mangler_old should not visit typedecl: %s", toCString(decl));
    316                                 assertf( decl->get_kind() < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->get_kind() );
    317                                 mangleName << Encoding::typeVariables[ decl->get_kind() ] << ( decl->name.length() ) << decl->name;
     316                                assertf( decl->kind < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind );
     317                                mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) << decl->name;
    318318                        }
    319319
     
    324324                        }
    325325
    326                         void Mangler_old::printQualifiers( Type * type ) {
     326                        void Mangler_old::printQualifiers( const Type * type ) {
    327327                                // skip if not including qualifiers
    328328                                if ( typeMode ) return;
    329                                 if ( ! type->get_forall().empty() ) {
     329                                if ( ! type->forall.empty() ) {
    330330                                        std::list< std::string > assertionNames;
    331331                                        int dcount = 0, fcount = 0, vcount = 0, acount = 0;
    332332                                        mangleName << Encoding::forall;
    333                                         for ( Type::ForallList::iterator i = type->forall.begin(); i != type->forall.end(); ++i ) {
    334                                                 switch ( (*i)->get_kind() ) {
     333                                        for ( const TypeDecl * i : type->forall ) {
     334                                                switch ( i->kind ) {
    335335                                                  case TypeDecl::Dtype:
    336336                                                        dcount++;
     
    345345                                                        assert( false );
    346346                                                } // switch
    347                                                 varNums[ (*i)->name ] = std::make_pair( nextVarNum, (int)(*i)->get_kind() );
    348                                                 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) {
    349                                                         PassVisitor<Mangler_old> sub_mangler( 
     347                                                varNums[ i->name ] = std::make_pair( nextVarNum, (int)i->kind );
     348                                                for ( const DeclarationWithType * assert : i->assertions ) {
     349                                                        PassVisitor<Mangler_old> sub_mangler(
    350350                                                                mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
    351                                                         (*assert)->accept( sub_mangler );
     351                                                        assert->accept( sub_mangler );
    352352                                                        assertionNames.push_back( sub_mangler.pass.get_mangleName() );
    353353                                                        acount++;
     
    436436
    437437                  private:
    438                         Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
     438                        Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    439439                                int nextVarNum, const VarMapType& varNums );
    440440                        friend class ast::Pass<Mangler_new>;
     
    457457        namespace {
    458458                Mangler_new::Mangler_new( Mangle::Mode mode )
    459                         : nextVarNum( 0 ), isTopLevel( true ), 
     459                        : nextVarNum( 0 ), isTopLevel( true ),
    460460                        mangleOverridable  ( ! mode.no_overrideable   ),
    461                         typeMode           (   mode.type              ), 
     461                        typeMode           (   mode.type              ),
    462462                        mangleGenericParams( ! mode.no_generic_params ) {}
    463                
    464                 Mangler_new::Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
     463
     464                Mangler_new::Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    465465                        int nextVarNum, const VarMapType& varNums )
    466                         : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), 
    467                         mangleOverridable( mangleOverridable ), typeMode( typeMode ), 
     466                        : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ),
     467                        mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    468468                        mangleGenericParams( mangleGenericParams ) {}
    469469
     
    693693                                                varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind );
    694694                                                for ( const ast::DeclWithType * assert : decl->assertions ) {
    695                                                         ast::Pass<Mangler_new> sub_mangler( 
     695                                                        ast::Pass<Mangler_new> sub_mangler(
    696696                                                                mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
    697697                                                        assert->accept( sub_mangler );
  • TabularUnified src/SymTab/Mangler.h

    r8fd52e90 r6f096d2  
    4040        namespace Mangler {
    4141                /// Mangle syntax tree object; primary interface to clients
    42                 std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );
     42                std::string mangle( const BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );
    4343
    4444                /// Mangle a type name; secondary interface
    45                 std::string mangleType( Type* ty );
     45                std::string mangleType( const Type * ty );
    4646                /// Mangle ignoring generic type parameters
    47                 std::string mangleConcrete( Type* ty );
     47                std::string mangleConcrete( const Type * ty );
    4848
    4949                namespace Encoding {
Note: See TracChangeset for help on using the changeset viewer.