Changes in / [9a19608:de8dfac2]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Mangler.cc

    r9a19608 rde8dfac2  
    3232#include "SynTree/Type.h"                // for Type, ReferenceToType, Type::Fora...
    3333
    34 #include "AST/Pass.hpp"
    35 
    3634namespace SymTab {
    3735        namespace Mangler {
    3836                namespace {
    3937                        /// Mangles names to a unique C identifier
    40                         struct Mangler_old : public WithShortCircuiting, public WithVisitorRef<Mangler_old>, public WithGuards {
    41                                 Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
    42                                 Mangler_old( const Mangler_old & ) = delete;
     38                        struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler>, public WithGuards {
     39                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
     40                                Mangler( const Mangler & ) = delete;
    4341
    4442                                void previsit( BaseSyntaxNode * ) { visit_children = false; }
     
    7977
    8078                          public:
    81                                 Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
     79                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    8280                                        int nextVarNum, const VarMapType& varNums );
    8381
     
    8785
    8886                                void printQualifiers( Type *type );
    89                         }; // Mangler_old
     87                        }; // Mangler
    9088                } // namespace
    9189
    9290                std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) {
    93                         PassVisitor<Mangler_old> mangler( mangleOverridable, typeMode, mangleGenericParams );
     91                        PassVisitor<Mangler> mangler( mangleOverridable, typeMode, mangleGenericParams );
    9492                        maybeAccept( decl, mangler );
    9593                        return mangler.pass.get_mangleName();
     
    9795
    9896                std::string mangleType( Type * ty ) {
    99                         PassVisitor<Mangler_old> mangler( false, true, true );
     97                        PassVisitor<Mangler> mangler( false, true, true );
    10098                        maybeAccept( ty, mangler );
    10199                        return mangler.pass.get_mangleName();
     
    103101
    104102                std::string mangleConcrete( Type * ty ) {
    105                         PassVisitor<Mangler_old> mangler( false, false, false );
     103                        PassVisitor<Mangler> mangler( false, false, false );
    106104                        maybeAccept( ty, mangler );
    107105                        return mangler.pass.get_mangleName();
     
    109107
    110108                namespace {
    111                         Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams )
     109                        Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams )
    112110                                : nextVarNum( 0 ), isTopLevel( true ),
    113111                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    114112                                mangleGenericParams( mangleGenericParams ) {}
    115113                       
    116                         Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
     114                        Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    117115                                int nextVarNum, const VarMapType& varNums )
    118116                                : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ),
     
    120118                                mangleGenericParams( mangleGenericParams ) {}
    121119
    122                         void Mangler_old::mangleDecl( DeclarationWithType * declaration ) {
     120                        void Mangler::mangleDecl( DeclarationWithType * declaration ) {
    123121                                bool wasTopLevel = isTopLevel;
    124122                                if ( isTopLevel ) {
     
    150148                        }
    151149
    152                         void Mangler_old::postvisit( ObjectDecl * declaration ) {
     150                        void Mangler::postvisit( ObjectDecl * declaration ) {
    153151                                mangleDecl( declaration );
    154152                        }
    155153
    156                         void Mangler_old::postvisit( FunctionDecl * declaration ) {
     154                        void Mangler::postvisit( FunctionDecl * declaration ) {
    157155                                mangleDecl( declaration );
    158156                        }
    159157
    160                         void Mangler_old::postvisit( VoidType * voidType ) {
     158                        void Mangler::postvisit( VoidType * voidType ) {
    161159                                printQualifiers( voidType );
    162160                                mangleName << Encoding::void_t;
    163161                        }
    164162
    165                         void Mangler_old::postvisit( BasicType * basicType ) {
     163                        void Mangler::postvisit( BasicType * basicType ) {
    166164                                printQualifiers( basicType );
    167165                                assertf( basicType->get_kind() < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->get_kind() );
     
    169167                        }
    170168
    171                         void Mangler_old::postvisit( PointerType * pointerType ) {
     169                        void Mangler::postvisit( PointerType * pointerType ) {
    172170                                printQualifiers( pointerType );
    173171                                // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers
     
    176174                        }
    177175
    178                         void Mangler_old::postvisit( ArrayType * arrayType ) {
     176                        void Mangler::postvisit( ArrayType * arrayType ) {
    179177                                // TODO: encode dimension
    180178                                printQualifiers( arrayType );
     
    183181                        }
    184182
    185                         void Mangler_old::postvisit( ReferenceType * refType ) {
     183                        void Mangler::postvisit( ReferenceType * refType ) {
    186184                                // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload.
    187185                                // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.),
     
    202200                        }
    203201
    204                         void Mangler_old::postvisit( FunctionType * functionType ) {
     202                        void Mangler::postvisit( FunctionType * functionType ) {
    205203                                printQualifiers( functionType );
    206204                                mangleName << Encoding::function;
     
    219217                        }
    220218
    221                         void Mangler_old::mangleRef( ReferenceToType * refType, std::string prefix ) {
     219                        void Mangler::mangleRef( ReferenceToType * refType, std::string prefix ) {
    222220                                printQualifiers( refType );
    223221
     
    238236                        }
    239237
    240                         void Mangler_old::postvisit( StructInstType * aggregateUseType ) {
     238                        void Mangler::postvisit( StructInstType * aggregateUseType ) {
    241239                                mangleRef( aggregateUseType, Encoding::struct_t );
    242240                        }
    243241
    244                         void Mangler_old::postvisit( UnionInstType * aggregateUseType ) {
     242                        void Mangler::postvisit( UnionInstType * aggregateUseType ) {
    245243                                mangleRef( aggregateUseType, Encoding::union_t );
    246244                        }
    247245
    248                         void Mangler_old::postvisit( EnumInstType * aggregateUseType ) {
     246                        void Mangler::postvisit( EnumInstType * aggregateUseType ) {
    249247                                mangleRef( aggregateUseType, Encoding::enum_t );
    250248                        }
    251249
    252                         void Mangler_old::postvisit( TypeInstType * typeInst ) {
     250                        void Mangler::postvisit( TypeInstType * typeInst ) {
    253251                                VarMapType::iterator varNum = varNums.find( typeInst->get_name() );
    254252                                if ( varNum == varNums.end() ) {
     
    266264                        }
    267265
    268                         void Mangler_old::postvisit( TraitInstType * inst ) {
     266                        void Mangler::postvisit( TraitInstType * inst ) {
    269267                                printQualifiers( inst );
    270268                                mangleName << inst->name.size() << inst->name;
    271269                        }
    272270
    273                         void Mangler_old::postvisit( TupleType * tupleType ) {
     271                        void Mangler::postvisit( TupleType * tupleType ) {
    274272                                printQualifiers( tupleType );
    275273                                mangleName << Encoding::tuple << tupleType->types.size();
     
    277275                        }
    278276
    279                         void Mangler_old::postvisit( VarArgsType * varArgsType ) {
     277                        void Mangler::postvisit( VarArgsType * varArgsType ) {
    280278                                printQualifiers( varArgsType );
    281279                                static const std::string vargs = "__builtin_va_list";
     
    283281                        }
    284282
    285                         void Mangler_old::postvisit( ZeroType * ) {
     283                        void Mangler::postvisit( ZeroType * ) {
    286284                                mangleName << Encoding::zero;
    287285                        }
    288286
    289                         void Mangler_old::postvisit( OneType * ) {
     287                        void Mangler::postvisit( OneType * ) {
    290288                                mangleName << Encoding::one;
    291289                        }
    292290
    293                         void Mangler_old::postvisit( QualifiedType * qualType ) {
     291                        void Mangler::postvisit( QualifiedType * qualType ) {
    294292                                bool inqual = inQualifiedType;
    295293                                if (! inqual ) {
     
    307305                        }
    308306
    309                         void Mangler_old::postvisit( TypeDecl * decl ) {
     307                        void Mangler::postvisit( TypeDecl * decl ) {
    310308                                // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be
    311309                                // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa.
     
    313311                                // and the case has not yet come up in practice. Alternatively, if not then this code can be removed
    314312                                // aside from the assert false.
    315                                 assertf(false, "Mangler_old should not visit typedecl: %s", toCString(decl));
     313                                assertf(false, "Mangler should not visit typedecl: %s", toCString(decl));
    316314                                assertf( decl->get_kind() < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->get_kind() );
    317315                                mangleName << Encoding::typeVariables[ decl->get_kind() ] << ( decl->name.length() ) << decl->name;
     
    324322                        }
    325323
    326                         void Mangler_old::printQualifiers( Type * type ) {
     324                        void Mangler::printQualifiers( Type * type ) {
    327325                                // skip if not including qualifiers
    328326                                if ( typeMode ) return;
     
    347345                                                varNums[ (*i)->name ] = std::make_pair( nextVarNum, (int)(*i)->get_kind() );
    348346                                                for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) {
    349                                                         PassVisitor<Mangler_old> sub_mangler(
     347                                                        PassVisitor<Mangler> sub_mangler(
    350348                                                                mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
    351349                                                        (*assert)->accept( sub_mangler );
     
    393391
    394392namespace Mangle {
    395         namespace {
    396                 /// Mangles names to a unique C identifier
    397                 struct Mangler_new : public ast::WithShortCircuiting, public ast::WithVisitorRef<Mangler_new>, public ast::WithGuards {
    398                         Mangler_new( Mangle::Mode mode );
    399                         Mangler_new( const Mangler_new & ) = delete;
    400 
    401                         void previsit( ast::Node * ) { visit_children = false; }
    402 
    403                         void postvisit( ast::ObjectDecl * declaration );
    404                         void postvisit( ast::FunctionDecl * declaration );
    405                         void postvisit( ast::TypeDecl * declaration );
    406 
    407                         void postvisit( ast::VoidType * voidType );
    408                         void postvisit( ast::BasicType * basicType );
    409                         void postvisit( ast::PointerType * pointerType );
    410                         void postvisit( ast::ArrayType * arrayType );
    411                         void postvisit( ast::ReferenceType * refType );
    412                         void postvisit( ast::FunctionType * functionType );
    413                         void postvisit( ast::StructInstType * aggregateUseType );
    414                         void postvisit( ast::UnionInstType * aggregateUseType );
    415                         void postvisit( ast::EnumInstType * aggregateUseType );
    416                         void postvisit( ast::TypeInstType * aggregateUseType );
    417                         void postvisit( ast::TraitInstType * inst );
    418                         void postvisit( ast::TupleType * tupleType );
    419                         void postvisit( ast::VarArgsType * varArgsType );
    420                         void postvisit( ast::ZeroType * zeroType );
    421                         void postvisit( ast::OneType * oneType );
    422                         void postvisit( ast::QualifiedType * qualType );
    423 
    424                         std::string get_mangleName() { return mangleName.str(); }
    425                   private:
    426                         std::ostringstream mangleName;  ///< Mangled name being constructed
    427                         typedef std::map< std::string, std::pair< int, int > > VarMapType;
    428                         VarMapType varNums;             ///< Map of type variables to indices
    429                         int nextVarNum;                 ///< Next type variable index
    430                         bool isTopLevel;                ///< Is the Mangler at the top level
    431                         bool mangleOverridable;         ///< Specially mangle overridable built-in methods
    432                         bool typeMode;                  ///< Produce a unique mangled name for a type
    433                         bool mangleGenericParams;       ///< Include generic parameters in name mangling if true
    434                         bool inFunctionType = false;    ///< Include type qualifiers if false.
    435                         bool inQualifiedType = false;   ///< Add start/end delimiters around qualified type
    436 
    437                   private:
    438                         Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
    439                                 int nextVarNum, const VarMapType& varNums );
    440                         friend class ast::Pass<Mangler_new>;
    441 
    442                   private:
    443                         void mangleDecl( ast::DeclWithType *declaration );
    444                         void mangleRef( ast::ReferenceToType *refType, std::string prefix );
    445 
    446                         void printQualifiers( ast::Type *type );
    447                 }; // Mangler_new
    448         } // namespace
    449 
    450 
    451393        std::string mangle( const ast::Node * decl, Mangle::Mode mode ) {
    452                 ast::Pass<Mangler_new> mangler( mode );
    453                 maybeAccept( decl, mangler );
    454                 return mangler.pass.get_mangleName();
     394                #warning unimplemented
     395                assert( decl && mode.val && false );
     396                return "";
    455397        }
    456 
    457         namespace {
    458                 Mangler_new::Mangler_new( Mangle::Mode mode )
    459                         : nextVarNum( 0 ), isTopLevel( true ),
    460                         mangleOverridable  ( ! mode.no_overrideable   ),
    461                         typeMode           (   mode.type              ),
    462                         mangleGenericParams( ! mode.no_generic_params ) {}
    463                
    464                 Mangler_new::Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
    465                         int nextVarNum, const VarMapType& varNums )
    466                         : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ),
    467                         mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    468                         mangleGenericParams( mangleGenericParams ) {}
    469 
    470                 void Mangler_new::mangleDecl( ast::DeclWithType * decl ) {
    471                         bool wasTopLevel = isTopLevel;
    472                         if ( isTopLevel ) {
    473                                 varNums.clear();
    474                                 nextVarNum = 0;
    475                                 isTopLevel = false;
    476                         } // if
    477                         mangleName << Encoding::manglePrefix;
    478                         CodeGen::OperatorInfo opInfo;
    479                         if ( operatorLookup( decl->name, opInfo ) ) {
    480                                 mangleName << opInfo.outputName.size() << opInfo.outputName;
    481                         } else {
    482                                 mangleName << decl->name.size() << decl->name;
    483                         } // if
    484                         maybeAccept( decl->get_type(), *visitor );
    485                         if ( mangleOverridable && decl->linkage.is_overrideable ) {
    486                                 // want to be able to override autogenerated and intrinsic routines,
    487                                 // so they need a different name mangling
    488                                 if ( decl->linkage == ast::Linkage::AutoGen ) {
    489                                         mangleName << Encoding::autogen;
    490                                 } else if ( decl->linkage == ast::Linkage::Intrinsic ) {
    491                                         mangleName << Encoding::intrinsic;
    492                                 } else {
    493                                         // if we add another kind of overridable function, this has to change
    494                                         assert( false && "unknown overrideable linkage" );
    495                                 } // if
    496                         }
    497                         isTopLevel = wasTopLevel;
    498                 }
    499 
    500                 void Mangler_new::postvisit( ast::ObjectDecl * decl ) {
    501                         mangleDecl( decl );
    502                 }
    503 
    504                 void Mangler_new::postvisit( ast::FunctionDecl * decl ) {
    505                         mangleDecl( decl );
    506                 }
    507 
    508                 void Mangler_new::postvisit( ast::VoidType * voidType ) {
    509                         printQualifiers( voidType );
    510                         mangleName << Encoding::void_t;
    511                 }
    512 
    513                 void Mangler_new::postvisit( ast::BasicType * basicType ) {
    514                         printQualifiers( basicType );
    515                         assertf( basicType->kind < ast::BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->kind );
    516                         mangleName << Encoding::basicTypes[ basicType->kind ];
    517                 }
    518 
    519                 void Mangler_new::postvisit( ast::PointerType * pointerType ) {
    520                         printQualifiers( pointerType );
    521                         // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers
    522                         if ( ! pointerType->base.as<ast::FunctionType>() ) mangleName << Encoding::pointer;
    523                         maybe_accept( pointerType->base.get(), *visitor );
    524                 }
    525 
    526                 void Mangler_new::postvisit( ast::ArrayType * arrayType ) {
    527                         // TODO: encode dimension
    528                         printQualifiers( arrayType );
    529                         mangleName << Encoding::array << "0";
    530                         maybeAccept( arrayType->base.get(), *visitor );
    531                 }
    532 
    533                 void Mangler_new::postvisit( ast::ReferenceType * refType ) {
    534                         // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload.
    535                         // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.),
    536                         // by pretending every reference type is a function parameter.
    537                         GuardValue( inFunctionType );
    538                         inFunctionType = true;
    539                         printQualifiers( refType );
    540                         maybeAccept( refType->base.get(), *visitor );
    541                 }
    542 
    543                 namespace {
    544                         inline std::vector< ast::ptr< ast::Type > > getTypes( const std::vector< ast::ptr< ast::DeclWithType > > & decls ) {
    545                                 std::vector< ast::ptr< ast::Type > > ret;
    546                                 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ),
    547                                                                 std::mem_fun( &ast::DeclWithType::get_type ) );
    548                                 return ret;
    549                         }
    550                 }
    551 
    552                 void Mangler_new::postvisit( ast::FunctionType * functionType ) {
    553                         printQualifiers( functionType );
    554                         mangleName << Encoding::function;
    555                         // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters,
    556                         // since qualifiers on outermost parameter type do not differentiate function types, e.g.,
    557                         // void (*)(const int) and void (*)(int) are the same type, but void (*)(const int *) and void (*)(int *) are different
    558                         GuardValue( inFunctionType );
    559                         inFunctionType = true;
    560                         std::vector< ast::ptr< ast::Type > > returnTypes = getTypes( functionType->returns );
    561                         if (returnTypes.empty()) mangleName << Encoding::void_t;
    562                         else acceptAll( returnTypes, *visitor );
    563                         mangleName << "_";
    564                         std::vector< ast::ptr< ast::Type > > paramTypes = getTypes( functionType->params );
    565                         acceptAll( paramTypes, *visitor );
    566                         mangleName << "_";
    567                 }
    568 
    569                 void Mangler_new::mangleRef( ast::ReferenceToType * refType, std::string prefix ) {
    570                         printQualifiers( refType );
    571 
    572                         mangleName << prefix << refType->name.length() << refType->name;
    573 
    574                         if ( mangleGenericParams ) {
    575                                 std::vector< ast::ptr< ast::Expr > >& params = refType->params;
    576                                 if ( ! params.empty() ) {
    577                                         mangleName << "_";
    578                                         for ( std::vector< ast::ptr< ast::Expr > >::const_iterator param = params.begin(); param != params.end(); ++param ) {
    579                                                 const ast::TypeExpr *paramType = param->as< ast::TypeExpr >();
    580                                                 assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(*param));
    581                                                 maybeAccept( paramType->type.get(), *visitor );
    582                                         }
    583                                         mangleName << "_";
    584                                 }
    585                         }
    586                 }
    587 
    588                 void Mangler_new::postvisit( ast::StructInstType * aggregateUseType ) {
    589                         mangleRef( aggregateUseType, Encoding::struct_t );
    590                 }
    591 
    592                 void Mangler_new::postvisit( ast::UnionInstType * aggregateUseType ) {
    593                         mangleRef( aggregateUseType, Encoding::union_t );
    594                 }
    595 
    596                 void Mangler_new::postvisit( ast::EnumInstType * aggregateUseType ) {
    597                         mangleRef( aggregateUseType, Encoding::enum_t );
    598                 }
    599 
    600                 void Mangler_new::postvisit( ast::TypeInstType * typeInst ) {
    601                         VarMapType::iterator varNum = varNums.find( typeInst->name );
    602                         if ( varNum == varNums.end() ) {
    603                                 mangleRef( typeInst, Encoding::type );
    604                         } else {
    605                                 printQualifiers( typeInst );
    606                                 // Note: Can't use name here, since type variable names do not actually disambiguate a function, e.g.
    607                                 //   forall(dtype T) void f(T);
    608                                 //   forall(dtype S) void f(S);
    609                                 // are equivalent and should mangle the same way. This is accomplished by numbering the type variables when they
    610                                 // are first found and prefixing with the appropriate encoding for the type class.
    611                                 assertf( varNum->second.second < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", varNum->second.second );
    612                                 mangleName << Encoding::typeVariables[varNum->second.second] << varNum->second.first;
    613                         } // if
    614                 }
    615 
    616                 void Mangler_new::postvisit( ast::TraitInstType * inst ) {
    617                         printQualifiers( inst );
    618                         mangleName << inst->name.size() << inst->name;
    619                 }
    620 
    621                 void Mangler_new::postvisit( ast::TupleType * tupleType ) {
    622                         printQualifiers( tupleType );
    623                         mangleName << Encoding::tuple << tupleType->types.size();
    624                         acceptAll( tupleType->types, *visitor );
    625                 }
    626 
    627                 void Mangler_new::postvisit( ast::VarArgsType * varArgsType ) {
    628                         printQualifiers( varArgsType );
    629                         static const std::string vargs = "__builtin_va_list";
    630                         mangleName << Encoding::type << vargs.size() << vargs;
    631                 }
    632 
    633                 void Mangler_new::postvisit( ast::ZeroType * ) {
    634                         mangleName << Encoding::zero;
    635                 }
    636 
    637                 void Mangler_new::postvisit( ast::OneType * ) {
    638                         mangleName << Encoding::one;
    639                 }
    640 
    641                 void Mangler_new::postvisit( ast::QualifiedType * qualType ) {
    642                         bool inqual = inQualifiedType;
    643                         if (! inqual ) {
    644                                 // N marks the start of a qualified type
    645                                 inQualifiedType = true;
    646                                 mangleName << Encoding::qualifiedTypeStart;
    647                         }
    648                         maybeAccept( qualType->parent.get(), *visitor );
    649                         maybeAccept( qualType->child.get(), *visitor );
    650                         if ( ! inqual ) {
    651                                 // E marks the end of a qualified type
    652                                 inQualifiedType = false;
    653                                 mangleName << Encoding::qualifiedTypeEnd;
    654                         }
    655                 }
    656 
    657                 void Mangler_new::postvisit( ast::TypeDecl * decl ) {
    658                         // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be
    659                         // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa.
    660                         // Note: The current scheme may already work correctly for this case, I have not thought about this deeply
    661                         // and the case has not yet come up in practice. Alternatively, if not then this code can be removed
    662                         // aside from the assert false.
    663                         assertf(false, "Mangler_new should not visit typedecl: %s", toCString(decl));
    664                         assertf( decl->kind < ast::TypeVar::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind );
    665                         mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) << decl->name;
    666                 }
    667 
    668                 __attribute__((unused)) void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) {
    669                         for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) {
    670                                 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl;
    671                         } // for
    672                 }
    673 
    674                 void Mangler_new::printQualifiers( ast::Type * type ) {
    675                         // skip if not including qualifiers
    676                         if ( typeMode ) return;
    677                         if ( ast::ParameterizedType * ptype = dynamic_cast< ast::ParameterizedType * >(type) ) {
    678                                 if ( ! ptype->forall.empty() ) {
    679                                         std::list< std::string > assertionNames;
    680                                         int dcount = 0, fcount = 0, vcount = 0, acount = 0;
    681                                         mangleName << Encoding::forall;
    682                                         for ( ast::ParameterizedType::ForallList::iterator i = ptype->forall.begin(); i != ptype->forall.end(); ++i ) {
    683                                                 switch ( (*i)->kind ) {
    684                                                         case ast::TypeVar::Kind::Dtype:
    685                                                         dcount++;
    686                                                         break;
    687                                                         case ast::TypeVar::Kind::Ftype:
    688                                                         fcount++;
    689                                                         break;
    690                                                         case ast::TypeVar::Kind::Ttype:
    691                                                         vcount++;
    692                                                         break;
    693                                                         default:
    694                                                         assert( false );
    695                                                 } // switch
    696                                                 varNums[ (*i)->name ] = std::make_pair( nextVarNum, (int)(*i)->kind );
    697                                                 for ( std::vector< ast::ptr< ast::DeclWithType > >::const_iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) {
    698                                                         ast::Pass<Mangler_new> sub_mangler(
    699                                                                 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
    700                                                         (*assert)->accept( sub_mangler );
    701                                                         assertionNames.push_back( sub_mangler.pass.get_mangleName() );
    702                                                         acount++;
    703                                                 } // for
    704                                         } // for
    705                                         mangleName << dcount << "_" << fcount << "_" << vcount << "_" << acount << "_";
    706                                         std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) );
    707                                         mangleName << "_";
    708                                 } // if
    709                         } // if
    710                         if ( ! inFunctionType ) {
    711                                 // these qualifiers do not distinguish the outermost type of a function parameter
    712                                 if ( type->is_const() ) {
    713                                         mangleName << Encoding::qualifiers.at(Type::Const);
    714                                 } // if
    715                                 if ( type->is_volatile() ) {
    716                                         mangleName << Encoding::qualifiers.at(Type::Volatile);
    717                                 } // if
    718                                 // Removed due to restrict not affecting function compatibility in GCC
    719                                 // if ( type->get_isRestrict() ) {
    720                                 //      mangleName << "E";
    721                                 // } // if
    722                                 if ( type->is_atomic() ) {
    723                                         mangleName << Encoding::qualifiers.at(Type::Atomic);
    724                                 } // if
    725                         }
    726                         if ( type->is_mutex() ) {
    727                                 mangleName << Encoding::qualifiers.at(Type::Mutex);
    728                         } // if
    729                         if ( type->is_lvalue() ) {
    730                                 // mangle based on whether the type is lvalue, so that the resolver can differentiate lvalues and rvalues
    731                                 mangleName << Encoding::qualifiers.at(Type::Lvalue);
    732                         }
    733 
    734                         if ( inFunctionType ) {
    735                                 // turn off inFunctionType so that types can be differentiated for nested qualifiers
    736                                 GuardValue( inFunctionType );
    737                                 inFunctionType = false;
    738                         }
    739                 }
    740         }       // namespace
    741398} // namespace Mangle
    742399
Note: See TracChangeset for help on using the changeset viewer.