Changeset cde3891 for src/SymTab
- Timestamp:
- Jan 23, 2019, 4:52:16 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a200795
- Parents:
- 9b086ca (diff), 1d832f4 (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. - Location:
- src/SymTab
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Demangle.cc
r9b086ca rcde3891 392 392 parsers.emplace_back(Encoding::enum_t, [this](Type::Qualifiers tq) { return parseEnum(tq); }); 393 393 parsers.emplace_back(Encoding::type, [this](Type::Qualifiers tq) { return parseType(tq); }); 394 parsers.emplace_back(Encoding::zero, [ this](Type::Qualifiers tq) { return new ZeroType(tq); });395 parsers.emplace_back(Encoding::one, [ this](Type::Qualifiers tq) { return new OneType(tq); });394 parsers.emplace_back(Encoding::zero, [](Type::Qualifiers tq) { return new ZeroType(tq); }); 395 parsers.emplace_back(Encoding::one, [](Type::Qualifiers tq) { return new OneType(tq); }); 396 396 } 397 397 -
src/SymTab/Mangler.cc
r9b086ca rcde3891 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 69 71 int nextVarNum; ///< Next type variable index 72 const ResolvExpr::TypeEnvironment* env; ///< optional environment for substitutions 70 73 bool isTopLevel; ///< Is the Mangler at the top level 71 74 bool mangleOverridable; ///< Specially mangle overridable built-in methods … … 75 78 bool inQualifiedType = false; ///< Add start/end delimiters around qualified type 76 79 80 public: 81 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 82 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 83 const VarMapType& varNums ); 84 85 private: 77 86 void mangleDecl( DeclarationWithType *declaration ); 78 87 void mangleRef( ReferenceToType *refType, std::string prefix ); … … 100 109 } 101 110 111 std::string mangleAssnKey( DeclarationWithType* decl, 112 const ResolvExpr::TypeEnvironment& env ) { 113 PassVisitor<Mangler> mangler( env ); 114 maybeAccept( decl, mangler ); 115 return mangler.pass.get_mangleName(); 116 } 117 102 118 namespace { 103 119 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams ) 104 : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ), mangleGenericParams( mangleGenericParams ) {} 120 : nextVarNum( 0 ), env(nullptr), isTopLevel( true ), 121 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 122 mangleGenericParams( mangleGenericParams ) {} 123 124 Mangler::Mangler( const ResolvExpr::TypeEnvironment& env ) 125 : nextVarNum( 0 ), env( &env ), isTopLevel( true ), mangleOverridable( false ), 126 typeMode( false ), mangleGenericParams( true ) {} 127 128 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 129 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 130 const VarMapType& varNums ) 131 : varNums( varNums ), nextVarNum( nextVarNum ), env( env ), isTopLevel( false ), 132 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 133 mangleGenericParams( mangleGenericParams ) {} 105 134 106 135 void Mangler::mangleDecl( DeclarationWithType * declaration ) { … … 329 358 assert( false ); 330 359 } // switch 331 varNums[ (*i)->name ] = std::pair< int, int >( nextVarNum++, (int)(*i)->get_kind() ); 360 std::string varName; 361 // replace type with substitution name if environment is available and bound 362 if ( env ) { 363 const ResolvExpr::EqvClass* varClass = env->lookup( (*i)->name ); 364 if ( varClass && varClass->type ) { 365 PassVisitor<Mangler> sub_mangler( 366 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, 367 env, varNums ); 368 varClass->type->accept( sub_mangler ); 369 varName = std::string{"%"} + sub_mangler.pass.get_mangleName(); 370 } 371 } 372 // otherwise just give type numeric name 373 if ( varName.empty() ) { 374 varName = std::to_string( nextVarNum++ ); 375 } 376 varNums[ (*i)->name ] = std::make_pair( varName, (int)(*i)->get_kind() ); 332 377 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; 378 PassVisitor<Mangler> sub_mangler( 379 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env, 380 varNums ); 337 381 (*assert)->accept( sub_mangler ); 338 assertionNames.push_back( sub_mangler.pass. mangleName.str() );382 assertionNames.push_back( sub_mangler.pass.get_mangleName() ); 339 383 acount++; 340 384 } // for -
src/SymTab/Mangler.h
r9b086ca rcde3891 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 { -
src/SymTab/Validate.cc
r9b086ca rcde3891 398 398 assert( aggr ); // TODO: need to handle forward declarations 399 399 for ( Declaration * member : aggr->members ) { 400 if ( StructInstType * inst = dynamic_cast< StructInstType * >( child ) ) { 401 if ( StructDecl * aggr = dynamic_cast< StructDecl * >( member ) ) { 402 if ( aggr->name == inst->name ) { 403 // TODO: is this case, and other non-TypeInstType cases, necessary? 404 return new StructInstType( qualType->get_qualifiers(), aggr ); 405 } 406 } 407 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( child ) ) { 408 if ( UnionDecl * aggr = dynamic_cast< UnionDecl * > ( member ) ) { 409 if ( aggr->name == inst->name ) { 410 return new UnionInstType( qualType->get_qualifiers(), aggr ); 411 } 412 } 413 } else if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( child ) ) { 414 if ( EnumDecl * aggr = dynamic_cast< EnumDecl * > ( member ) ) { 415 if ( aggr->name == inst->name ) { 416 return new EnumInstType( qualType->get_qualifiers(), aggr ); 417 } 418 } 419 } else if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) { 400 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) { 420 401 // name on the right is a typedef 421 402 if ( NamedTypeDecl * aggr = dynamic_cast< NamedTypeDecl * > ( member ) ) { … … 424 405 Type * ret = aggr->base->clone(); 425 406 ret->get_qualifiers() = qualType->get_qualifiers(); 407 TypeSubstitution sub = parent->genericSubstitution(); 408 sub.apply(ret); 426 409 return ret; 427 410 }
Note:
See TracChangeset
for help on using the changeset viewer.