|
28 | 28 |
|
29 | 29 | #include "converter/lex.h" |
30 | 30 | #include "converter/mapper.h" |
31 | | -#include "converter/printer.h" |
32 | 31 | #include "converter/rules/registry.h" |
33 | 32 |
|
34 | 33 | // https://doc.rust-lang.org/reference/keywords.html |
@@ -863,40 +862,64 @@ static std::string GetParamSignature(const clang::Decl *decl) { |
863 | 862 | return args; |
864 | 863 | } |
865 | 864 |
|
866 | | -static clang::ASTNameGenerator *name_generator = nullptr; |
| 865 | +static clang::MangleContext *mangle_context = nullptr; |
867 | 866 |
|
868 | | -void SetNameGenerator(clang::ASTNameGenerator *generator) { |
869 | | - name_generator = generator; |
| 867 | +void SetMangleContext(clang::MangleContext *context) { |
| 868 | + mangle_context = context; |
870 | 869 | } |
871 | 870 |
|
872 | | -clang::ASTNameGenerator *GetNameGenerator() { return name_generator; } |
| 871 | +clang::MangleContext *GetMangleContext() { return mangle_context; } |
873 | 872 |
|
874 | 873 | static std::string GetMangledName(const clang::Decl *decl) { |
875 | | - assert(name_generator); |
876 | | - return name_generator->getName(decl); |
| 874 | + assert(mangle_context); |
| 875 | + auto *named = clang::cast<clang::NamedDecl>(decl); |
| 876 | + if (!mangle_context->shouldMangleDeclName(named)) { |
| 877 | + return named->getNameAsString(); |
| 878 | + } |
| 879 | + clang::GlobalDecl global; |
| 880 | + if (auto *ctor = clang::dyn_cast<clang::CXXConstructorDecl>(decl)) { |
| 881 | + global = clang::GlobalDecl(ctor, clang::Ctor_Complete); |
| 882 | + } else if (auto *dtor = clang::dyn_cast<clang::CXXDestructorDecl>(decl)) { |
| 883 | + global = clang::GlobalDecl(dtor, clang::Dtor_Complete); |
| 884 | + } else { |
| 885 | + global = clang::GlobalDecl(named); |
| 886 | + } |
| 887 | + std::string name; |
| 888 | + llvm::raw_string_ostream os(name); |
| 889 | + mangle_context->mangleName(global, os); |
| 890 | + return name; |
| 891 | +} |
| 892 | + |
| 893 | +static std::string |
| 894 | +GetMangledTypeName(const clang::ClassTemplateSpecializationDecl *decl) { |
| 895 | + assert(mangle_context); |
| 896 | + std::string name; |
| 897 | + llvm::raw_string_ostream os(name); |
| 898 | + mangle_context->mangleCanonicalTypeName( |
| 899 | + decl->getASTContext().getCanonicalTagType(decl), os); |
| 900 | + return name; |
877 | 901 | } |
878 | 902 |
|
879 | 903 | static std::string GetLexicalSpecializationID(const clang::Decl *decl) { |
880 | | - auto &ctx = decl->getASTContext(); |
881 | 904 | std::string id; |
882 | 905 | if (const auto *var = |
883 | 906 | clang::dyn_cast<clang::VarTemplateSpecializationDecl>(decl)) { |
884 | 907 | id += GetMangledName(var); |
885 | 908 | } |
886 | 909 | if (const auto *self = |
887 | 910 | clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl)) { |
888 | | - id += Printer::ToString(ctx, GetTypeForDecl(ctx, self)); |
| 911 | + id += GetMangledTypeName(self); |
889 | 912 | } |
890 | 913 | if (const auto *spec = |
891 | 914 | clang::dyn_cast<clang::ClassTemplateSpecializationDecl>( |
892 | 915 | decl->getLexicalDeclContext()); |
893 | 916 | spec && decl->getLexicalDeclContext() != decl->getDeclContext()) { |
894 | | - id += Printer::ToString(ctx, GetTypeForDecl(ctx, spec)); |
| 917 | + id += GetMangledTypeName(spec); |
895 | 918 | } |
896 | 919 | for (const auto *dc = decl->getDeclContext(); dc; dc = dc->getParent()) { |
897 | 920 | if (const auto *spec = |
898 | 921 | clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(dc)) { |
899 | | - id += Printer::ToString(ctx, GetTypeForDecl(ctx, spec)); |
| 922 | + id += GetMangledTypeName(spec); |
900 | 923 | } |
901 | 924 | if (const auto *fn = clang::dyn_cast<clang::FunctionDecl>(dc); |
902 | 925 | fn && fn->getTemplateSpecializationArgs()) { |
|
0 commit comments