@@ -1792,6 +1792,29 @@ namespace Cpp {
1792
1792
QT.getAsStringInternal (type_name, Policy);
1793
1793
}
1794
1794
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
+
1795
1818
void collect_type_info (const FunctionDecl* FD, QualType& QT,
1796
1819
std::ostringstream& typedefbuf,
1797
1820
std::ostringstream& callbuf, std::string& type_name,
@@ -2205,22 +2228,12 @@ namespace Cpp {
2205
2228
std::string& wrapper_name, std::string& wrapper) {
2206
2229
assert (FD && " generate_wrapper called without a function decl!" );
2207
2230
ASTContext& Context = FD->getASTContext ();
2208
- PrintingPolicy Policy (Context.getPrintingPolicy ());
2209
2231
//
2210
2232
// Get the class or namespace name.
2211
2233
//
2212
2234
std::string class_name;
2213
2235
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);
2224
2237
//
2225
2238
// Check to make sure that we can
2226
2239
// instantiate and codegen this function.
@@ -2670,31 +2683,11 @@ namespace Cpp {
2670
2683
}
2671
2684
2672
2685
// 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) {
2676
2689
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);
2698
2691
2699
2692
//
2700
2693
// Make the wrapper name.
@@ -2754,7 +2747,7 @@ namespace Cpp {
2754
2747
// Make the wrapper name.
2755
2748
//
2756
2749
std::string class_name;
2757
- string wrapper_name = PrepareTorWrapper (D, " __dtor" , class_name);
2750
+ string wrapper_name = PrepareStructorWrapper (D, " __dtor" , class_name);
2758
2751
//
2759
2752
// Write the wrapper code.
2760
2753
//
0 commit comments