Browse Source

Rename templates only used through aliases

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1641/head
Dimitar Dobrev 4 years ago
parent
commit
a2aeaed92a
  1. 14
      src/Generator/Passes/StripUnusedSystemTypesPass.cs
  2. 2
      src/Generator/Passes/TrimSpecializationsPass.cs
  3. 1
      tests/NamespacesDerived/NamespacesDerived.Tests.cs
  4. 5
      tests/NamespacesDerived/NamespacesDerived.h

14
src/Generator/Passes/StripUnusedSystemTypesPass.cs

@ -59,8 +59,16 @@ namespace CppSharp.Passes
var templateType = desugared as TemplateSpecializationType; var templateType = desugared as TemplateSpecializationType;
if (templateType != null) if (templateType != null)
{ {
MarkAsUsed(templateType.Template); var template = templateType.Template;
MarkAsUsed(templateType.Template.TemplatedDecl); if (template.TemplatedDecl is TypeAlias typeAlias &&
typeAlias.Type.Desugar() is TemplateSpecializationType specializationType)
{
MarkAsUsed(template);
MarkAsUsed(template.TemplatedDecl);
template = specializationType.Template;
}
MarkAsUsed(template);
MarkAsUsed(template.TemplatedDecl);
return true; return true;
} }
@ -90,6 +98,6 @@ namespace CppSharp.Passes
} }
} }
private HashSet<Declaration> usedStdTypes = new HashSet<Declaration>(); private readonly HashSet<Declaration> usedStdTypes = new HashSet<Declaration>();
} }
} }

2
src/Generator/Passes/TrimSpecializationsPass.cs

@ -158,7 +158,7 @@ namespace CppSharp.Passes
let module = arg.Type.Type.GetModule() let module = arg.Type.Type.GetModule()
where module != null where module != null
select module).ToList().TopologicalSort(m => m.Dependencies); select module).ToList().TopologicalSort(m => m.Dependencies);
if (modules.Any()) if (modules.Count > 0)
{ {
var module = modules.Last(); var module = modules.Last();
module.ExternalClassTemplateSpecializations.Add(specialization); module.ExternalClassTemplateSpecializations.Add(specialization);

1
tests/NamespacesDerived/NamespacesDerived.Tests.cs

@ -15,6 +15,7 @@ public class NamespaceDerivedTests
using (new DerivedFromSecondaryBaseInDependency()) { } using (new DerivedFromSecondaryBaseInDependency()) { }
using (var der2 = new Derived2()) using (var der2 = new Derived2())
using (der2.LocalTypedefSpecialization) { } using (der2.LocalTypedefSpecialization) { }
Assert.That(typeof(Derived2).Assembly.GetTypes().Any(t => t.FullName.Contains("Std.Vector")), Is.True);
} }
[Test] [Test]

5
tests/NamespacesDerived/NamespacesDerived.h

@ -109,10 +109,13 @@ private:
std::basic_string<char, std::char_traits<char>, CustomAllocator<char>> customAllocatedString; std::basic_string<char, std::char_traits<char>, CustomAllocator<char>> customAllocatedString;
}; };
template<class T, class Alloc = CustomAllocator<T>>
using vector = ::std::vector<T, Alloc>;
class DLL_API StdFields class DLL_API StdFields
{ {
private: private:
std::vector<unsigned int, CustomAllocator<unsigned int>> customAllocatedVector; vector<unsigned int, CustomAllocator<unsigned int>> customAllocatedVector;
}; };
DLL_API bool operator<<(const Base& b, const char* str); DLL_API bool operator<<(const Base& b, const char* str);

Loading…
Cancel
Save