Changeset ff5caaf
- Timestamp:
- Jan 11, 2019, 3:36:37 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 95b8aa7
- Parents:
- 73ac10e
- Location:
- src/SymTab
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Mangler.cc
r73ac10e rff5caaf 15 15 #include "Mangler.h" 16 16 17 #include <algorithm> // for copy, transform18 #include <cassert> // for assert, assertf19 #include <functional> // for const_mem_fun_t, mem_fun20 #include <iterator> // for ostream_iterator, back_insert_ite...21 #include <list> // for _List_iterator, list, _List_const...22 #include <string> // for string, char_traits, operator<<23 24 #include "CodeGen/OperatorTable.h" // for OperatorInfo, operatorLookup17 #include <algorithm> // for copy, transform 18 #include <cassert> // for assert, assertf 19 #include <functional> // for const_mem_fun_t, mem_fun 20 #include <iterator> // for ostream_iterator, back_insert_ite... 21 #include <list> // for _List_iterator, list, _List_const... 22 #include <string> // for string, char_traits, operator<< 23 24 #include "CodeGen/OperatorTable.h" // for OperatorInfo, operatorLookup 25 25 #include "Common/PassVisitor.h" 26 #include "Common/SemanticError.h" // for SemanticError 27 #include "Common/utility.h" // for toString 28 #include "Parser/LinkageSpec.h" // for Spec, isOverridable, AutoGen, Int... 29 #include "SynTree/Declaration.h" // for TypeDecl, DeclarationWithType 30 #include "SynTree/Expression.h" // for TypeExpr, Expression, operator<< 31 #include "SynTree/Type.h" // for Type, ReferenceToType, Type::Fora... 26 #include "Common/SemanticError.h" // for SemanticError 27 #include "Common/utility.h" // for toString 28 #include "Parser/LinkageSpec.h" // for Spec, isOverridable, AutoGen, Int... 29 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 30 #include "SynTree/Declaration.h" // for TypeDecl, DeclarationWithType 31 #include "SynTree/Expression.h" // for TypeExpr, Expression, operator<< 32 #include "SynTree/Type.h" // for Type, ReferenceToType, Type::Fora... 32 33 33 34 namespace SymTab { … … 37 38 struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler>, public WithGuards { 38 39 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams ); 40 Mangler( const ResolvExpr::TypeEnvironment& env ); 39 41 Mangler( const Mangler & ) = delete; 40 42 … … 65 67 private: 66 68 std::ostringstream mangleName; ///< Mangled name being constructed 67 typedef std::map< std::string, std::pair< int, int > > VarMapType;69 typedef std::map< std::string, std::pair< std::string, int > > VarMapType; 68 70 VarMapType varNums; ///< Map of type variables to indices 71 const ResolvExpr::TypeEnvironment* env; ///< optional environment for substitutions 69 72 int nextVarNum; ///< Next type variable index 70 73 bool isTopLevel; ///< Is the Mangler at the top level … … 75 78 bool inQualifiedType = false; ///< Add start/end delimiters around qualified type 76 79 80 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 81 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 82 const VarMapType& varNums ); 83 77 84 void mangleDecl( DeclarationWithType *declaration ); 78 85 void mangleRef( ReferenceToType *refType, std::string prefix ); … … 100 107 } 101 108 109 std::string mangleAssnKey( DeclarationWithType* decl, 110 const ResolvExpr::TypeEnvironment& env ) { 111 PassVisitor<Mangler> mangler( env ); 112 maybeAccept( decl, mangler ); 113 return mangler.pass.get_mangleName(); 114 } 115 102 116 namespace { 103 117 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams ) 104 : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ), mangleGenericParams( mangleGenericParams ) {} 118 : nextVarNum( 0 ), env(nullptr), isTopLevel( true ), 119 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 120 mangleGenericParams( mangleGenericParams ) {} 121 122 Mangler::Mangler( const ResolvExpr::TypeEnvironment& env ) 123 : nextVarNum( 0 ), env( &env ), isTopLevel( true ), mangleOverridable( false ), 124 typeMode( false ), mangleGenericParams( true ) {} 125 126 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 127 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 128 const VarMapType& varNums ) 129 : nextVarNum( nextVarNum ), varNums( varNums ), env( env ), isTopLevel( false ), 130 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 131 mangleGenericParams( mangleGenericParams ) {} 105 132 106 133 void Mangler::mangleDecl( DeclarationWithType * declaration ) { … … 329 356 assert( false ); 330 357 } // switch 331 varNums[ (*i)->name ] = std::pair< int, int >( nextVarNum++, (int)(*i)->get_kind() ); 358 std::string varName; 359 // replace type with substitution name if environment is available and bound 360 if ( env ) { 361 const EqvClass* varClass = env->lookup( (*i)->name ); 362 if ( varClass && varClass->type ) { 363 PassVisitor<Mangler> sub_mangler( 364 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, 365 env, varNums ); 366 varClass->type->accept( sub_mangler ); 367 varName = std::string{"%"} + sub_mangler.pass.get_mangleName(); 368 } 369 } 370 // otherwise just give type numeric name 371 if ( varName.empty() ) { 372 varName = std::to_string( nextVarNum++ ); 373 } 374 varNums[ (*i)->name ] = std::make_pair( varName, (int)(*i)->get_kind() ); 332 375 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) { 333 PassVisitor<Mangler> sub_mangler( mangleOverridable, typeMode, mangleGenericParams ); 334 sub_mangler.pass.nextVarNum = nextVarNum; 335 sub_mangler.pass.isTopLevel = false; 336 sub_mangler.pass.varNums = varNums; 376 PassVisitor<Mangler> sub_mangler( 377 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env, 378 varNums ); 337 379 (*assert)->accept( sub_mangler ); 338 assertionNames.push_back( sub_mangler.pass. mangleName.str() );380 assertionNames.push_back( sub_mangler.pass.get_mangleName() ); 339 381 acount++; 340 382 } // for -
src/SymTab/Mangler.h
r73ac10e rff5caaf 31 31 // * Currently name compression is not implemented. 32 32 33 namespace ResolvExpr { 34 class TypeEnvironment; 35 } 36 33 37 namespace SymTab { 34 38 namespace Mangler { … … 40 44 /// Mangle ignoring generic type parameters 41 45 std::string mangleConcrete( Type* ty ); 46 /// Mangle for assertion key 47 std::string mangleAssnKey( DeclarationWithType* decl, 48 const ResolvExpr::TypeEnvironment& env ); 42 49 43 50 namespace Encoding {
Note: See TracChangeset
for help on using the changeset viewer.