Browse Source

Generated internals for template specialisations from dependent libraries.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/658/head
Dimitar Dobrev 10 years ago
parent
commit
546c32d4a7
  1. 3
      src/AST/Namespace.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 5
      src/Generator/Passes/CleanUnitPass.cs
  4. 2
      src/Generator/Passes/DelegatesPass.cs
  5. 3
      src/Generator/Passes/RenameRootNamespaces.cs
  6. 14
      src/Generator/Passes/ResolveIncompleteDeclsPass.cs
  7. 9
      src/Generator/Passes/TrimSpecializationsPass.cs
  8. 6
      tests/CSharp/AnotherUnit.h
  9. 2
      tests/CSharp/CSharp.h
  10. 5
      tests/CSharp/CSharpTemplates.h
  11. 5
      tests/NamespacesBase/NamespacesBase.h
  12. 1
      tests/NamespacesDerived/NamespacesDerived.h

3
src/AST/Namespace.cs

@ -419,7 +419,8 @@ namespace CppSharp.AST @@ -419,7 +419,8 @@ namespace CppSharp.AST
{
Func<Declaration, bool> pred = (t => t.IsGenerated);
return Enums.Exists(pred) || HasFunctions || Typedefs.Exists(pred)
|| Classes.Any() || Namespaces.Exists(n => n.HasDeclarations);
|| Classes.Any(pred) || Namespaces.Exists(n => n.HasDeclarations) ||
Templates.Any(pred);
}
}

4
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -254,7 +254,7 @@ namespace CppSharp.Generators.CSharp @@ -254,7 +254,7 @@ namespace CppSharp.Generators.CSharp
}
var templateGroups = (from template in context.Templates.OfType<ClassTemplate>()
where template.Specializations.Count > 0
where !template.IsIncomplete && template.Specializations.Count > 0
group template by context.Classes.Contains(template.TemplatedClass)
into @group
select @group).ToList();
@ -2621,7 +2621,7 @@ namespace CppSharp.Generators.CSharp @@ -2621,7 +2621,7 @@ namespace CppSharp.Generators.CSharp
var templateSpecialization = function.Namespace as ClassTemplateSpecialization;
string @namespace = templateSpecialization != null ?
(function.Namespace.OriginalName + '.') : string.Empty;
(templateSpecialization.Namespace.OriginalName + '.') : string.Empty;
CheckArgumentRange(function);
var functionName = string.Format("{0}Internal.{1}", @namespace,

5
src/Generator/Passes/CleanUnitPass.cs

@ -16,7 +16,10 @@ namespace CppSharp.Passes @@ -16,7 +16,10 @@ namespace CppSharp.Passes
public override bool VisitTranslationUnit(TranslationUnit unit)
{
if (unit.IsValid && !unit.IsSystemHeader && unit.HasDeclarations)
if (!base.VisitTranslationUnit(unit))
return false;
if (unit.IsValid && !unit.IsSystemHeader)
{
var includeDir = Path.GetFullPath(Path.GetDirectoryName(unit.FilePath));
unit.Module = DriverOptions.Modules.FirstOrDefault(

2
src/Generator/Passes/DelegatesPass.cs

@ -49,7 +49,7 @@ namespace CppSharp.Passes @@ -49,7 +49,7 @@ namespace CppSharp.Passes
var result = base.VisitLibrary(context);
foreach (var module in Driver.Options.Modules.Where(m => namespacesDelegates.ContainsKey(m)))
module.Units.Last().Declarations.Add(namespacesDelegates[module]);
module.Units.Last(u => u.HasDeclarations).Declarations.Add(namespacesDelegates[module]);
return result;
}

3
src/Generator/Passes/RenameRootNamespaces.cs

@ -11,8 +11,7 @@ namespace CppSharp.Passes @@ -11,8 +11,7 @@ namespace CppSharp.Passes
{
public override bool VisitTranslationUnit(TranslationUnit unit)
{
if (!base.VisitTranslationUnit(unit) || !unit.IsValid ||
unit.IsSystemHeader || !unit.HasDeclarations)
if (!base.VisitTranslationUnit(unit) || !unit.IsValid || unit.IsSystemHeader)
return false;
var fileName = unit.TranslationUnit.FileName;

14
src/Generator/Passes/ResolveIncompleteDeclsPass.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using CppSharp.AST;
using System.Linq;
using CppSharp.AST;
namespace CppSharp.Passes
{
@ -19,6 +20,17 @@ namespace CppSharp.Passes @@ -19,6 +20,17 @@ namespace CppSharp.Passes
if (!base.VisitClassTemplateDecl(template))
return false;
if (template.IsIncomplete)
{
var completeDeclaration = (ClassTemplate) template.CompleteDeclaration;
foreach (var specialization in template.Specializations.Where(
spec => completeDeclaration.Specializations.All(s => s.USR != spec.USR)))
{
specialization.TemplatedDecl = completeDeclaration;
completeDeclaration.Specializations.Add(specialization);
}
}
EnsureCompleteDeclaration(template.TemplatedDecl);
template.TemplatedDecl = template.TemplatedDecl.CompleteDeclaration ?? template.TemplatedDecl;

9
src/Generator/Passes/TrimSpecializationsPass.cs

@ -8,7 +8,7 @@ namespace CppSharp.Passes @@ -8,7 +8,7 @@ namespace CppSharp.Passes
{
public override bool VisitClassTemplateDecl(ClassTemplate template)
{
if (!base.VisitClassTemplateDecl(template))
if (!base.VisitClassTemplateDecl(template) || template.IsIncomplete)
return false;
template.Specializations.RemoveAll(
@ -22,12 +22,9 @@ namespace CppSharp.Passes @@ -22,12 +22,9 @@ namespace CppSharp.Passes
a => a.Type.Type != null && a.Type.Type.IsAddress()) into @group
select @group).ToList();
var lastGroup = groups.Last();
if (lastGroup.Key)
{
foreach (var specialization in lastGroup.Skip(1))
foreach (var group in groups.Where(g => g.Key))
foreach (var specialization in group.Skip(1))
template.Specializations.Remove(specialization);
}
for (int i = template.Specializations.Count - 1; i >= 0; i--)
if (template.Specializations[i] is ClassTemplatePartialSpecialization)

6
tests/CSharp/AnotherUnit.h

@ -1,3 +1,9 @@ @@ -1,3 +1,9 @@
#include "../Tests.h"
void DLL_API functionInAnotherUnit();
template <typename T>
class TemplateInAnotherUnit
{
T field;
};

2
tests/CSharp/CSharp.h

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
#include "../Tests.h"
#include <cstdint>
#include "AnotherUnit.h"
class DLL_API Foo
{
@ -23,6 +24,7 @@ public: @@ -23,6 +24,7 @@ public:
protected:
int P;
TemplateInAnotherUnit<int> templateInAnotherUnit;
};
class DLL_API Quux

5
tests/CSharp/CSharpTemplates.h

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "../Tests.h"
#include "AnotherUnit.h"
class DLL_API T1
{
@ -46,6 +47,9 @@ class HasDefaultTemplateArgument @@ -46,6 +47,9 @@ class HasDefaultTemplateArgument
T field;
};
template <typename T>
class TemplateInAnotherUnit;
class DLL_API TemplateSpecializer
{
public:
@ -61,6 +65,7 @@ private: @@ -61,6 +65,7 @@ private:
HasDefaultTemplateArgument<int> hasDefaultTemplateArgument;
DependentValueFields<T1> dependentPointerFieldsT1;
DependentValueFields<T2> dependentPointerFieldsT2;
TemplateInAnotherUnit<float> templateInAnotherUnit;
DependentValueFields<IndependentFields<int>> specializeWithSpecialization;
DependentValueFields<IndependentFields<bool>> specializeWithSameSpecialization;
NestedTemplate<int> nestedTemplate;

5
tests/NamespacesBase/NamespacesBase.h

@ -51,6 +51,11 @@ public: @@ -51,6 +51,11 @@ public:
template <typename T>
class TemplateClass
{
union
{
int i;
float f;
};
};
class DLL_API HasVirtualInCore

1
tests/NamespacesDerived/NamespacesDerived.h

@ -60,6 +60,7 @@ public: @@ -60,6 +60,7 @@ public:
Abstract* getAbstract();
private:
TemplateClass<int> t;
TemplateClass<Derived> d;
};
class DLL_API HasVirtualInDependency : public HasVirtualInCore

Loading…
Cancel
Save