Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Mangler.cc

    r1da22500 rf465f0e  
    3535                namespace {
    3636                        /// Mangles names to a unique C identifier
    37                         struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler> {
     37                        struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler>, public WithGuards {
    3838                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
    3939                                Mangler( const Mangler & ) = delete;
     
    5555                                void postvisit( EnumInstType * aggregateUseType );
    5656                                void postvisit( TypeInstType * aggregateUseType );
     57                                void postvisit( TraitInstType * inst );
    5758                                void postvisit( TupleType * tupleType );
    5859                                void postvisit( VarArgsType * varArgsType );
     
    7071                                bool typeMode;                  ///< Produce a unique mangled name for a type
    7172                                bool mangleGenericParams;       ///< Include generic parameters in name mangling if true
     73                                bool inFunctionType = false;    ///< Include type qualifiers if false.
    7274
    7375                                void mangleDecl( DeclarationWithType *declaration );
     
    189191
    190192                        void Mangler::postvisit( ReferenceType * refType ) {
     193                                // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload.
     194                                // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.),
     195                                // by pretending every reference type is a function parameter.
     196                                GuardValue( inFunctionType );
     197                                inFunctionType = true;
    191198                                printQualifiers( refType );
    192                                 mangleName << "R";
    193199                                maybeAccept( refType->base, *visitor );
    194200                        }
     
    206212                                printQualifiers( functionType );
    207213                                mangleName << "F";
     214                                // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters,
     215                                // since qualifiers on outermost parameter type do not differentiate function types, e.g.,
     216                                // void (*)(const int) and void (*)(int) are the same type, but void (*)(const int *) and void (*)(int *) are different
     217                                GuardValue( inFunctionType );
     218                                inFunctionType = true;
    208219                                std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() );
    209220                                acceptAll( returnTypes, *visitor );
     
    270281                        }
    271282
     283                        void Mangler::postvisit( TraitInstType * inst ) {
     284                                printQualifiers( inst );
     285                                mangleName << "_Y" << inst->name << "_";
     286                        }
     287
    272288                        void Mangler::postvisit( TupleType * tupleType ) {
    273289                                printQualifiers( tupleType );
     
    304320                                // skip if not including qualifiers
    305321                                if ( typeMode ) return;
    306 
    307322                                if ( ! type->get_forall().empty() ) {
    308323                                        std::list< std::string > assertionNames;
     
    337352                                        mangleName << "_";
    338353                                } // if
    339                                 if ( type->get_const() ) {
    340                                         mangleName << "C";
    341                                 } // if
    342                                 if ( type->get_volatile() ) {
    343                                         mangleName << "V";
    344                                 } // if
     354                                if ( ! inFunctionType ) {
     355                                        // these qualifiers do not distinguish the outermost type of a function parameter
     356                                        if ( type->get_const() ) {
     357                                                mangleName << "C";
     358                                        } // if
     359                                        if ( type->get_volatile() ) {
     360                                                mangleName << "V";
     361                                        } // if
     362                                        // Removed due to restrict not affecting function compatibility in GCC
     363                                        // if ( type->get_isRestrict() ) {
     364                                        //      mangleName << "E";
     365                                        // } // if
     366                                        if ( type->get_atomic() ) {
     367                                                mangleName << "A";
     368                                        } // if
     369                                }
    345370                                if ( type->get_mutex() ) {
    346371                                        mangleName << "M";
    347372                                } // if
    348                                 // Removed due to restrict not affecting function compatibility in GCC
    349                 //              if ( type->get_isRestrict() ) {
    350                 //                      mangleName << "E";
    351                 //              } // if
    352373                                if ( type->get_lvalue() ) {
    353374                                        // mangle based on whether the type is lvalue, so that the resolver can differentiate lvalues and rvalues
    354375                                        mangleName << "L";
    355376                                }
    356                                 if ( type->get_atomic() ) {
    357                                         mangleName << "A";
    358                                 } // if
     377
     378                                if ( inFunctionType ) {
     379                                        // turn off inFunctionType so that types can be differentiated for nested qualifiers
     380                                        GuardValue( inFunctionType );
     381                                        inFunctionType = false;
     382                                }
    359383                        }
    360384                }       // namespace
Note: See TracChangeset for help on using the changeset viewer.