Changeset 67130fe for src/SymTab
- Timestamp:
- Jun 4, 2019, 6:39:23 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c6a1e8a
- Parents:
- 7564e10 (diff), 1346914 (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:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Mangler.cc
r7564e10 r67130fe 32 32 #include "SynTree/Type.h" // for Type, ReferenceToType, Type::Fora... 33 33 34 #include "AST/Pass.hpp" 35 34 36 namespace SymTab { 35 37 namespace Mangler { 36 38 namespace { 37 39 /// Mangles names to a unique C identifier 38 struct Mangler : public WithShortCircuiting, public WithVisitorRef<Mangler>, public WithGuards {39 Mangler ( bool mangleOverridable, bool typeMode, bool mangleGenericParams );40 Mangler ( const Mangler& ) = delete;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; 41 43 42 44 void previsit( BaseSyntaxNode * ) { visit_children = false; } … … 77 79 78 80 public: 79 Mangler ( bool mangleOverridable, bool typeMode, bool mangleGenericParams,81 Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 80 82 int nextVarNum, const VarMapType& varNums ); 81 83 … … 85 87 86 88 void printQualifiers( Type *type ); 87 }; // Mangler 89 }; // Mangler_old 88 90 } // namespace 89 91 90 92 std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) { 91 PassVisitor<Mangler > mangler( mangleOverridable, typeMode, mangleGenericParams );93 PassVisitor<Mangler_old> mangler( mangleOverridable, typeMode, mangleGenericParams ); 92 94 maybeAccept( decl, mangler ); 93 95 return mangler.pass.get_mangleName(); … … 95 97 96 98 std::string mangleType( Type * ty ) { 97 PassVisitor<Mangler > mangler( false, true, true );99 PassVisitor<Mangler_old> mangler( false, true, true ); 98 100 maybeAccept( ty, mangler ); 99 101 return mangler.pass.get_mangleName(); … … 101 103 102 104 std::string mangleConcrete( Type * ty ) { 103 PassVisitor<Mangler > mangler( false, false, false );105 PassVisitor<Mangler_old> mangler( false, false, false ); 104 106 maybeAccept( ty, mangler ); 105 107 return mangler.pass.get_mangleName(); … … 107 109 108 110 namespace { 109 Mangler ::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams )111 Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams ) 110 112 : nextVarNum( 0 ), isTopLevel( true ), 111 113 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 112 114 mangleGenericParams( mangleGenericParams ) {} 113 115 114 Mangler ::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,116 Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 115 117 int nextVarNum, const VarMapType& varNums ) 116 118 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), … … 118 120 mangleGenericParams( mangleGenericParams ) {} 119 121 120 void Mangler ::mangleDecl( DeclarationWithType * declaration ) {122 void Mangler_old::mangleDecl( DeclarationWithType * declaration ) { 121 123 bool wasTopLevel = isTopLevel; 122 124 if ( isTopLevel ) { … … 148 150 } 149 151 150 void Mangler ::postvisit( ObjectDecl * declaration ) {152 void Mangler_old::postvisit( ObjectDecl * declaration ) { 151 153 mangleDecl( declaration ); 152 154 } 153 155 154 void Mangler ::postvisit( FunctionDecl * declaration ) {156 void Mangler_old::postvisit( FunctionDecl * declaration ) { 155 157 mangleDecl( declaration ); 156 158 } 157 159 158 void Mangler ::postvisit( VoidType * voidType ) {160 void Mangler_old::postvisit( VoidType * voidType ) { 159 161 printQualifiers( voidType ); 160 162 mangleName << Encoding::void_t; 161 163 } 162 164 163 void Mangler ::postvisit( BasicType * basicType ) {165 void Mangler_old::postvisit( BasicType * basicType ) { 164 166 printQualifiers( basicType ); 165 167 assertf( basicType->get_kind() < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->get_kind() ); … … 167 169 } 168 170 169 void Mangler ::postvisit( PointerType * pointerType ) {171 void Mangler_old::postvisit( PointerType * pointerType ) { 170 172 printQualifiers( pointerType ); 171 173 // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers … … 174 176 } 175 177 176 void Mangler ::postvisit( ArrayType * arrayType ) {178 void Mangler_old::postvisit( ArrayType * arrayType ) { 177 179 // TODO: encode dimension 178 180 printQualifiers( arrayType ); … … 181 183 } 182 184 183 void Mangler ::postvisit( ReferenceType * refType ) {185 void Mangler_old::postvisit( ReferenceType * refType ) { 184 186 // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload. 185 187 // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.), … … 200 202 } 201 203 202 void Mangler ::postvisit( FunctionType * functionType ) {204 void Mangler_old::postvisit( FunctionType * functionType ) { 203 205 printQualifiers( functionType ); 204 206 mangleName << Encoding::function; … … 217 219 } 218 220 219 void Mangler ::mangleRef( ReferenceToType * refType, std::string prefix ) {221 void Mangler_old::mangleRef( ReferenceToType * refType, std::string prefix ) { 220 222 printQualifiers( refType ); 221 223 … … 236 238 } 237 239 238 void Mangler ::postvisit( StructInstType * aggregateUseType ) {240 void Mangler_old::postvisit( StructInstType * aggregateUseType ) { 239 241 mangleRef( aggregateUseType, Encoding::struct_t ); 240 242 } 241 243 242 void Mangler ::postvisit( UnionInstType * aggregateUseType ) {244 void Mangler_old::postvisit( UnionInstType * aggregateUseType ) { 243 245 mangleRef( aggregateUseType, Encoding::union_t ); 244 246 } 245 247 246 void Mangler ::postvisit( EnumInstType * aggregateUseType ) {248 void Mangler_old::postvisit( EnumInstType * aggregateUseType ) { 247 249 mangleRef( aggregateUseType, Encoding::enum_t ); 248 250 } 249 251 250 void Mangler ::postvisit( TypeInstType * typeInst ) {252 void Mangler_old::postvisit( TypeInstType * typeInst ) { 251 253 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 252 254 if ( varNum == varNums.end() ) { … … 264 266 } 265 267 266 void Mangler ::postvisit( TraitInstType * inst ) {268 void Mangler_old::postvisit( TraitInstType * inst ) { 267 269 printQualifiers( inst ); 268 270 mangleName << inst->name.size() << inst->name; 269 271 } 270 272 271 void Mangler ::postvisit( TupleType * tupleType ) {273 void Mangler_old::postvisit( TupleType * tupleType ) { 272 274 printQualifiers( tupleType ); 273 275 mangleName << Encoding::tuple << tupleType->types.size(); … … 275 277 } 276 278 277 void Mangler ::postvisit( VarArgsType * varArgsType ) {279 void Mangler_old::postvisit( VarArgsType * varArgsType ) { 278 280 printQualifiers( varArgsType ); 279 281 static const std::string vargs = "__builtin_va_list"; … … 281 283 } 282 284 283 void Mangler ::postvisit( ZeroType * ) {285 void Mangler_old::postvisit( ZeroType * ) { 284 286 mangleName << Encoding::zero; 285 287 } 286 288 287 void Mangler ::postvisit( OneType * ) {289 void Mangler_old::postvisit( OneType * ) { 288 290 mangleName << Encoding::one; 289 291 } 290 292 291 void Mangler ::postvisit( QualifiedType * qualType ) {293 void Mangler_old::postvisit( QualifiedType * qualType ) { 292 294 bool inqual = inQualifiedType; 293 295 if (! inqual ) { … … 305 307 } 306 308 307 void Mangler ::postvisit( TypeDecl * decl ) {309 void Mangler_old::postvisit( TypeDecl * decl ) { 308 310 // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be 309 311 // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa. … … 311 313 // and the case has not yet come up in practice. Alternatively, if not then this code can be removed 312 314 // aside from the assert false. 313 assertf(false, "Mangler should not visit typedecl: %s", toCString(decl));315 assertf(false, "Mangler_old should not visit typedecl: %s", toCString(decl)); 314 316 assertf( decl->get_kind() < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->get_kind() ); 315 317 mangleName << Encoding::typeVariables[ decl->get_kind() ] << ( decl->name.length() ) << decl->name; … … 322 324 } 323 325 324 void Mangler ::printQualifiers( Type * type ) {326 void Mangler_old::printQualifiers( Type * type ) { 325 327 // skip if not including qualifiers 326 328 if ( typeMode ) return; … … 345 347 varNums[ (*i)->name ] = std::make_pair( nextVarNum, (int)(*i)->get_kind() ); 346 348 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) { 347 PassVisitor<Mangler > sub_mangler(349 PassVisitor<Mangler_old> sub_mangler( 348 350 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ); 349 351 (*assert)->accept( sub_mangler ); … … 390 392 } // namespace SymTab 391 393 394 namespace 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( const ast::Node * ) { visit_children = false; } 402 403 void postvisit( const ast::ObjectDecl * declaration ); 404 void postvisit( const ast::FunctionDecl * declaration ); 405 void postvisit( const ast::TypeDecl * declaration ); 406 407 void postvisit( const ast::VoidType * voidType ); 408 void postvisit( const ast::BasicType * basicType ); 409 void postvisit( const ast::PointerType * pointerType ); 410 void postvisit( const ast::ArrayType * arrayType ); 411 void postvisit( const ast::ReferenceType * refType ); 412 void postvisit( const ast::FunctionType * functionType ); 413 void postvisit( const ast::StructInstType * aggregateUseType ); 414 void postvisit( const ast::UnionInstType * aggregateUseType ); 415 void postvisit( const ast::EnumInstType * aggregateUseType ); 416 void postvisit( const ast::TypeInstType * aggregateUseType ); 417 void postvisit( const ast::TraitInstType * inst ); 418 void postvisit( const ast::TupleType * tupleType ); 419 void postvisit( const ast::VarArgsType * varArgsType ); 420 void postvisit( const ast::ZeroType * zeroType ); 421 void postvisit( const ast::OneType * oneType ); 422 void postvisit( const 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( const ast::DeclWithType *declaration ); 444 void mangleRef( const ast::ReferenceToType *refType, std::string prefix ); 445 446 void printQualifiers( const ast::Type *type ); 447 }; // Mangler_new 448 } // namespace 449 450 451 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(); 455 } 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( const 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( const ast::ObjectDecl * decl ) { 501 mangleDecl( decl ); 502 } 503 504 void Mangler_new::postvisit( const ast::FunctionDecl * decl ) { 505 mangleDecl( decl ); 506 } 507 508 void Mangler_new::postvisit( const ast::VoidType * voidType ) { 509 printQualifiers( voidType ); 510 mangleName << Encoding::void_t; 511 } 512 513 void Mangler_new::postvisit( const 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( const 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( const 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( const 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 inline std::vector< ast::ptr< ast::Type > > getTypes( const std::vector< ast::ptr< ast::DeclWithType > > & decls ) { 544 std::vector< ast::ptr< ast::Type > > ret; 545 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ), 546 std::mem_fun( &ast::DeclWithType::get_type ) ); 547 return ret; 548 } 549 550 void Mangler_new::postvisit( const ast::FunctionType * functionType ) { 551 printQualifiers( functionType ); 552 mangleName << Encoding::function; 553 // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters, 554 // since qualifiers on outermost parameter type do not differentiate function types, e.g., 555 // void (*)(const int) and void (*)(int) are the same type, but void (*)(const int *) and void (*)(int *) are different 556 GuardValue( inFunctionType ); 557 inFunctionType = true; 558 std::vector< ast::ptr< ast::Type > > returnTypes = getTypes( functionType->returns ); 559 if (returnTypes.empty()) mangleName << Encoding::void_t; 560 else accept_each( returnTypes, *visitor ); 561 mangleName << "_"; 562 std::vector< ast::ptr< ast::Type > > paramTypes = getTypes( functionType->params ); 563 accept_each( paramTypes, *visitor ); 564 mangleName << "_"; 565 } 566 567 void Mangler_new::mangleRef( const ast::ReferenceToType * refType, std::string prefix ) { 568 printQualifiers( refType ); 569 570 mangleName << prefix << refType->name.length() << refType->name; 571 572 if ( mangleGenericParams ) { 573 if ( ! refType->params.empty() ) { 574 mangleName << "_"; 575 for ( const ast::Expr * param : refType->params ) { 576 auto paramType = dynamic_cast< const ast::TypeExpr * >( param ); 577 assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param)); 578 maybeAccept( paramType->type.get(), *visitor ); 579 } 580 mangleName << "_"; 581 } 582 } 583 } 584 585 void Mangler_new::postvisit( const ast::StructInstType * aggregateUseType ) { 586 mangleRef( aggregateUseType, Encoding::struct_t ); 587 } 588 589 void Mangler_new::postvisit( const ast::UnionInstType * aggregateUseType ) { 590 mangleRef( aggregateUseType, Encoding::union_t ); 591 } 592 593 void Mangler_new::postvisit( const ast::EnumInstType * aggregateUseType ) { 594 mangleRef( aggregateUseType, Encoding::enum_t ); 595 } 596 597 void Mangler_new::postvisit( const ast::TypeInstType * typeInst ) { 598 VarMapType::iterator varNum = varNums.find( typeInst->name ); 599 if ( varNum == varNums.end() ) { 600 mangleRef( typeInst, Encoding::type ); 601 } else { 602 printQualifiers( typeInst ); 603 // Note: Can't use name here, since type variable names do not actually disambiguate a function, e.g. 604 // forall(dtype T) void f(T); 605 // forall(dtype S) void f(S); 606 // are equivalent and should mangle the same way. This is accomplished by numbering the type variables when they 607 // are first found and prefixing with the appropriate encoding for the type class. 608 assertf( varNum->second.second < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", varNum->second.second ); 609 mangleName << Encoding::typeVariables[varNum->second.second] << varNum->second.first; 610 } // if 611 } 612 613 void Mangler_new::postvisit( const ast::TraitInstType * inst ) { 614 printQualifiers( inst ); 615 mangleName << inst->name.size() << inst->name; 616 } 617 618 void Mangler_new::postvisit( const ast::TupleType * tupleType ) { 619 printQualifiers( tupleType ); 620 mangleName << Encoding::tuple << tupleType->types.size(); 621 accept_each( tupleType->types, *visitor ); 622 } 623 624 void Mangler_new::postvisit( const ast::VarArgsType * varArgsType ) { 625 printQualifiers( varArgsType ); 626 static const std::string vargs = "__builtin_va_list"; 627 mangleName << Encoding::type << vargs.size() << vargs; 628 } 629 630 void Mangler_new::postvisit( const ast::ZeroType * ) { 631 mangleName << Encoding::zero; 632 } 633 634 void Mangler_new::postvisit( const ast::OneType * ) { 635 mangleName << Encoding::one; 636 } 637 638 void Mangler_new::postvisit( const ast::QualifiedType * qualType ) { 639 bool inqual = inQualifiedType; 640 if (! inqual ) { 641 // N marks the start of a qualified type 642 inQualifiedType = true; 643 mangleName << Encoding::qualifiedTypeStart; 644 } 645 maybeAccept( qualType->parent.get(), *visitor ); 646 maybeAccept( qualType->child.get(), *visitor ); 647 if ( ! inqual ) { 648 // E marks the end of a qualified type 649 inQualifiedType = false; 650 mangleName << Encoding::qualifiedTypeEnd; 651 } 652 } 653 654 void Mangler_new::postvisit( const ast::TypeDecl * decl ) { 655 // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be 656 // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa. 657 // Note: The current scheme may already work correctly for this case, I have not thought about this deeply 658 // and the case has not yet come up in practice. Alternatively, if not then this code can be removed 659 // aside from the assert false. 660 assertf(false, "Mangler_new should not visit typedecl: %s", toCString(decl)); 661 assertf( decl->kind < ast::TypeVar::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind ); 662 mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) << decl->name; 663 } 664 665 __attribute__((unused)) void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) { 666 for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) { 667 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl; 668 } // for 669 } 670 671 void Mangler_new::printQualifiers( const ast::Type * type ) { 672 // skip if not including qualifiers 673 if ( typeMode ) return; 674 if ( auto ptype = dynamic_cast< const ast::ParameterizedType * >(type) ) { 675 if ( ! ptype->forall.empty() ) { 676 std::list< std::string > assertionNames; 677 int dcount = 0, fcount = 0, vcount = 0, acount = 0; 678 mangleName << Encoding::forall; 679 for ( const ast::TypeDecl * decl : ptype->forall ) { 680 switch ( decl->kind ) { 681 case ast::TypeVar::Kind::Dtype: 682 dcount++; 683 break; 684 case ast::TypeVar::Kind::Ftype: 685 fcount++; 686 break; 687 case ast::TypeVar::Kind::Ttype: 688 vcount++; 689 break; 690 default: 691 assert( false ); 692 } // switch 693 varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind ); 694 for ( const ast::DeclWithType * assert : decl->assertions ) { 695 ast::Pass<Mangler_new> sub_mangler( 696 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ); 697 assert->accept( sub_mangler ); 698 assertionNames.push_back( sub_mangler.pass.get_mangleName() ); 699 acount++; 700 } // for 701 } // for 702 mangleName << dcount << "_" << fcount << "_" << vcount << "_" << acount << "_"; 703 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 704 mangleName << "_"; 705 } // if 706 } // if 707 if ( ! inFunctionType ) { 708 // these qualifiers do not distinguish the outermost type of a function parameter 709 if ( type->is_const() ) { 710 mangleName << Encoding::qualifiers.at(Type::Const); 711 } // if 712 if ( type->is_volatile() ) { 713 mangleName << Encoding::qualifiers.at(Type::Volatile); 714 } // if 715 // Removed due to restrict not affecting function compatibility in GCC 716 // if ( type->get_isRestrict() ) { 717 // mangleName << "E"; 718 // } // if 719 if ( type->is_atomic() ) { 720 mangleName << Encoding::qualifiers.at(Type::Atomic); 721 } // if 722 } 723 if ( type->is_mutex() ) { 724 mangleName << Encoding::qualifiers.at(Type::Mutex); 725 } // if 726 if ( type->is_lvalue() ) { 727 // mangle based on whether the type is lvalue, so that the resolver can differentiate lvalues and rvalues 728 mangleName << Encoding::qualifiers.at(Type::Lvalue); 729 } 730 731 if ( inFunctionType ) { 732 // turn off inFunctionType so that types can be differentiated for nested qualifiers 733 GuardValue( inFunctionType ); 734 inFunctionType = false; 735 } 736 } 737 } // namespace 738 } // namespace Mangle 739 392 740 // Local Variables: // 393 741 // tab-width: 4 // -
src/SymTab/Mangler.h
r7564e10 r67130fe 21 21 #include <utility> // for pair 22 22 23 #include "AST/Bitfield.hpp" 24 #include "AST/Fwd.hpp" 23 25 #include "SynTree/SynTree.h" // for Types 24 26 #include "SynTree/Visitor.h" // for Visitor, maybeAccept … … 75 77 } // SymTab 76 78 79 namespace Mangle { 80 /// Bitflags for mangle modes 81 enum { 82 NoOverrideable = 1 << 0, 83 Type = 1 << 1, 84 NoGenericParams = 1 << 2 85 }; 86 87 /// Bitflag type for mangler modes 88 struct mangle_flags { 89 union { 90 unsigned int val; 91 struct { 92 bool no_overrideable : 1; 93 bool type : 1; 94 bool no_generic_params : 1; 95 }; 96 }; 97 98 constexpr mangle_flags( unsigned int val ) : val(val) {} 99 }; 100 101 using Mode = bitfield<mangle_flags>; 102 103 /// Mangle declaration name 104 std::string mangle( const ast::Node * decl, Mode mode = {} ); 105 106 namespace Encoding { 107 using namespace SymTab::Mangler::Encoding; 108 }; 109 } 110 77 111 extern "C" { 78 112 char * cforall_demangle(const char *, int);
Note:
See TracChangeset
for help on using the changeset viewer.