Ignore:
Timestamp:
Jul 19, 2019, 2:16:01 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4eb43fa
Parents:
1f1c102 (diff), 8ac3b0e (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 new-ast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Mangler.cc

    r1f1c102 rf53acdf8  
    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 );
Note: See TracChangeset for help on using the changeset viewer.