@@ -1792,6 +1792,29 @@ namespace Cpp {
17921792 QT.getAsStringInternal (type_name, Policy);
17931793 }
17941794
1795+ static void GetDeclName (const clang::Decl* D, ASTContext& Context,
1796+ std::string& name) {
1797+ // Helper to extract a fully qualified name from a Decl
1798+ PrintingPolicy Policy (Context.getPrintingPolicy ());
1799+ Policy.SuppressTagKeyword = true ;
1800+ Policy.SuppressUnwrittenScope = true ;
1801+ if (const TypeDecl* TD = dyn_cast<TypeDecl>(D)) {
1802+ // This is a class, struct, or union member.
1803+ QualType QT;
1804+ if (const TypedefDecl* Typedef = dyn_cast<const TypedefDecl>(TD)) {
1805+ // Handle the typedefs to anonymous types.
1806+ QT = Typedef->getTypeSourceInfo ()->getType ();
1807+ } else
1808+ QT = {TD->getTypeForDecl (), 0 };
1809+ get_type_as_string (QT, name, Context, Policy);
1810+ } else if (const NamedDecl* ND = dyn_cast<NamedDecl>(D)) {
1811+ // This is a namespace member.
1812+ raw_string_ostream stream (name);
1813+ ND->getNameForDiagnostic (stream, Policy, /* Qualified=*/ true );
1814+ stream.flush ();
1815+ }
1816+ }
1817+
17951818 void collect_type_info (const FunctionDecl* FD, QualType& QT,
17961819 std::ostringstream& typedefbuf,
17971820 std::ostringstream& callbuf, std::string& type_name,
@@ -2205,22 +2228,12 @@ namespace Cpp {
22052228 std::string& wrapper_name, std::string& wrapper) {
22062229 assert (FD && " generate_wrapper called without a function decl!" );
22072230 ASTContext& Context = FD->getASTContext ();
2208- PrintingPolicy Policy (Context.getPrintingPolicy ());
22092231 //
22102232 // Get the class or namespace name.
22112233 //
22122234 std::string class_name;
22132235 const clang::DeclContext* DC = get_non_transparent_decl_context (FD);
2214- if (const TypeDecl* TD = dyn_cast<TypeDecl>(DC)) {
2215- // This is a class, struct, or union member.
2216- QualType QT (TD->getTypeForDecl (), 0 );
2217- get_type_as_string (QT, class_name, Context, Policy);
2218- } else if (const NamedDecl* ND = dyn_cast<NamedDecl>(DC)) {
2219- // This is a namespace member.
2220- raw_string_ostream stream (class_name);
2221- ND->getNameForDiagnostic (stream, Policy, /* Qualified=*/ true );
2222- stream.flush ();
2223- }
2236+ GetDeclName (cast<Decl>(DC), Context, class_name);
22242237 //
22252238 // Check to make sure that we can
22262239 // instantiate and codegen this function.
@@ -2670,31 +2683,11 @@ namespace Cpp {
26702683 }
26712684
26722685 // FIXME: Sink in the code duplication from get_wrapper_code.
2673- static std::string PrepareTorWrapper (const Decl* D,
2674- const char * wrapper_prefix,
2675- std::string& class_name) {
2686+ static std::string PrepareStructorWrapper (const Decl* D,
2687+ const char * wrapper_prefix,
2688+ std::string& class_name) {
26762689 ASTContext &Context = D->getASTContext ();
2677- PrintingPolicy Policy (Context.getPrintingPolicy ());
2678- Policy.SuppressTagKeyword = true ;
2679- Policy.SuppressUnwrittenScope = true ;
2680- //
2681- // Get the class or namespace name.
2682- //
2683- if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
2684- // This is a class, struct, or union member.
2685- // Handle the typedefs to anonymous types.
2686- QualType QT;
2687- if (const TypedefDecl *Typedef = dyn_cast<const TypedefDecl>(TD))
2688- QT = Typedef->getTypeSourceInfo ()->getType ();
2689- else
2690- QT = {TD->getTypeForDecl (), 0 };
2691- get_type_as_string (QT, class_name, Context, Policy);
2692- } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
2693- // This is a namespace member.
2694- raw_string_ostream stream (class_name);
2695- ND->getNameForDiagnostic (stream, Policy, /* Qualified=*/ true );
2696- stream.flush ();
2697- }
2690+ GetDeclName (D, Context, class_name);
26982691
26992692 //
27002693 // Make the wrapper name.
@@ -2754,7 +2747,7 @@ namespace Cpp {
27542747 // Make the wrapper name.
27552748 //
27562749 std::string class_name;
2757- string wrapper_name = PrepareTorWrapper (D, " __dtor" , class_name);
2750+ string wrapper_name = PrepareStructorWrapper (D, " __dtor" , class_name);
27582751 //
27592752 // Write the wrapper code.
27602753 //
0 commit comments