Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Mangler.cc

    r9feb34b r0026d67  
    2424#include "CodeGen/OperatorTable.h"       // for OperatorInfo, operatorLookup
    2525#include "Common/PassVisitor.h"
    26 #include "Common/ToString.hpp"           // for toCString
    2726#include "Common/SemanticError.h"        // for SemanticError
     27#include "Common/utility.h"              // for toString
    2828#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    2929#include "SynTree/LinkageSpec.h"         // for Spec, isOverridable, AutoGen, Int...
     
    439439                  private:
    440440                        void mangleDecl( const ast::DeclWithType *declaration );
    441                         void mangleRef( const ast::BaseInstType *refType, const std::string & prefix );
     441                        void mangleRef( const ast::BaseInstType *refType, std::string prefix );
    442442
    443443                        void printQualifiers( const ast::Type *type );
     
    535535                }
    536536
     537                __attribute__((unused))
     538                inline std::vector< ast::ptr< ast::Type > > getTypes( const std::vector< ast::ptr< ast::DeclWithType > > & decls ) {
     539                        std::vector< ast::ptr< ast::Type > > ret;
     540                        std::transform( decls.begin(), decls.end(), std::back_inserter( ret ),
     541                                                        std::mem_fun( &ast::DeclWithType::get_type ) );
     542                        return ret;
     543                }
     544
    537545                void Mangler_new::postvisit( const ast::FunctionType * functionType ) {
    538546                        printQualifiers( functionType );
     
    550558                }
    551559
    552                 void Mangler_new::mangleRef(
    553                                 const ast::BaseInstType * refType, const std::string & prefix ) {
     560                void Mangler_new::mangleRef( const ast::BaseInstType * refType, std::string prefix ) {
    554561                        printQualifiers( refType );
    555562
    556563                        mangleName += prefix + std::to_string( refType->name.length() ) + refType->name;
    557564
    558                         if ( mangleGenericParams && ! refType->params.empty() ) {
    559                                 mangleName += "_";
    560                                 for ( const ast::Expr * param : refType->params ) {
    561                                         auto paramType = dynamic_cast< const ast::TypeExpr * >( param );
    562                                         assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param));
    563                                         maybeAccept( paramType->type.get(), *visitor );
     565                        if ( mangleGenericParams ) {
     566                                if ( ! refType->params.empty() ) {
     567                                        mangleName += "_";
     568                                        for ( const ast::Expr * param : refType->params ) {
     569                                                auto paramType = dynamic_cast< const ast::TypeExpr * >( param );
     570                                                assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param));
     571                                                maybeAccept( paramType->type.get(), *visitor );
     572                                        }
     573                                        mangleName += "_";
    564574                                }
    565                                 mangleName += "_";
    566575                        }
    567576                }
     
    647656                }
    648657
    649                 // For debugging:
    650658                __attribute__((unused)) void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) {
    651659                        for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) {
     
    657665                        // skip if not including qualifiers
    658666                        if ( typeMode ) return;
    659                         auto funcType = dynamic_cast<const ast::FunctionType *>( type );
    660                         if ( funcType && !funcType->forall.empty() ) {
    661                                 std::list< std::string > assertionNames;
    662                                 int dcount = 0, fcount = 0, vcount = 0, acount = 0;
    663                                 mangleName += Encoding::forall;
    664                                 for ( auto & decl : funcType->forall ) {
    665                                         switch ( decl->kind ) {
    666                                         case ast::TypeDecl::Dtype:
    667                                                 dcount++;
    668                                                 break;
    669                                         case ast::TypeDecl::Ftype:
    670                                                 fcount++;
    671                                                 break;
    672                                         case ast::TypeDecl::Ttype:
    673                                                 vcount++;
    674                                                 break;
    675                                         default:
    676                                                 assertf( false, "unimplemented kind for type variable %s", SymTab::Mangler::Encoding::typeVariables[decl->kind].c_str() );
    677                                         } // switch
    678                                         varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind );
    679                                 } // for
    680                                 for ( auto & assert : funcType->assertions ) {
    681                                         assertionNames.push_back( ast::Pass<Mangler_new>::read(
    682                                                 assert->var.get(),
    683                                                 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ) );
    684                                         acount++;
    685                                 } // for
    686                                 mangleName += std::to_string( dcount ) + "_" + std::to_string( fcount ) + "_" + std::to_string( vcount ) + "_" + std::to_string( acount ) + "_";
    687                                 for ( const auto & a : assertionNames ) mangleName += a;
    688                                 mangleName += "_";
     667                        if ( auto ptype = dynamic_cast< const ast::FunctionType * >(type) ) {
     668                                if ( ! ptype->forall.empty() ) {
     669                                        std::list< std::string > assertionNames;
     670                                        int dcount = 0, fcount = 0, vcount = 0, acount = 0;
     671                                        mangleName += Encoding::forall;
     672                                        for ( auto & decl : ptype->forall ) {
     673                                                switch ( decl->kind ) {
     674                                                  case ast::TypeDecl::Kind::Dtype:
     675                                                        dcount++;
     676                                                        break;
     677                                                  case ast::TypeDecl::Kind::Ftype:
     678                                                        fcount++;
     679                                                        break;
     680                                                  case ast::TypeDecl::Kind::Ttype:
     681                                                        vcount++;
     682                                                        break;
     683                                                  default:
     684                                                        assertf( false, "unimplemented kind for type variable %s", SymTab::Mangler::Encoding::typeVariables[decl->kind].c_str() );
     685                                                } // switch
     686                                                varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind );
     687                                        } // for
     688                                        for ( auto & assert : ptype->assertions ) {
     689                                                assertionNames.push_back( ast::Pass<Mangler_new>::read(
     690                                                        assert->var.get(),
     691                                                        mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ) );
     692                                                acount++;
     693                                        } // for
     694                                        mangleName += std::to_string( dcount ) + "_" + std::to_string( fcount ) + "_" + std::to_string( vcount ) + "_" + std::to_string( acount ) + "_";
     695                                        for(const auto & a : assertionNames) mangleName += a;
     696//                                      std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) );
     697                                        mangleName += "_";
     698                                } // if
    689699                        } // if
    690700                        if ( ! inFunctionType ) {
Note: See TracChangeset for help on using the changeset viewer.