Browse Source

Restored explicit specialisations but added exceptions for their methods.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/913/head
Dimitar Dobrev 8 years ago
parent
commit
f81800521c
  1. 55
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 7
      src/Generator/Passes/TrimSpecializationsPass.cs
  3. 8
      tests/CSharp/CSharpTemplates.cpp
  4. 25
      tests/CSharp/CSharpTemplates.h

55
src/Generator/Generators/CSharp/CSharpSources.cs

@ -799,7 +799,15 @@ namespace CppSharp.Generators.CSharp
private void GenerateFunctionSetter(Class @class, Property property) private void GenerateFunctionSetter(Class @class, Property property)
{ {
property = GetActualProperty(property, @class); var actualProperty = GetActualProperty(property, @class);
if (actualProperty == null)
{
WriteLine($@"throw new MissingMethodException(""Method {
property.Name} missing from explicit specialization {
@class.Visit(TypePrinter)}."");");
return;
}
property = actualProperty;
var param = new Parameter var param = new Parameter
{ {
Name = "value", Name = "value",
@ -1070,7 +1078,15 @@ namespace CppSharp.Generators.CSharp
private void GenerateFunctionGetter(Class @class, Property property) private void GenerateFunctionGetter(Class @class, Property property)
{ {
property = GetActualProperty(property, @class); var actualProperty = GetActualProperty(property, @class);
if (actualProperty == null)
{
WriteLine($@"throw new MissingMethodException(""Method {
property.Name} missing from explicit specialization {
@class.Visit(TypePrinter)}."");");
return;
}
property = actualProperty;
if (property.GetMethod.SynthKind == FunctionSynthKind.AbstractImplCall) if (property.GetMethod.SynthKind == FunctionSynthKind.AbstractImplCall)
GenerateVirtualPropertyCall(property.GetMethod, @class.BaseClass, property); GenerateVirtualPropertyCall(property.GetMethod, @class.BaseClass, property);
else if (property.GetMethod.IsVirtual) else if (property.GetMethod.IsVirtual)
@ -1083,11 +1099,8 @@ namespace CppSharp.Generators.CSharp
{ {
if (!(c is ClassTemplateSpecialization)) if (!(c is ClassTemplateSpecialization))
return property; return property;
if (property.GetMethod != null return c.Properties.SingleOrDefault(p => p.GetMethod != null &&
&& property.GetMethod.OperatorKind == CXXOperatorKind.Subscript) p.GetMethod.InstantiatedFrom == property.GetMethod);
return c.Properties.Single(p => p.GetMethod != null
&& p.GetMethod.InstantiatedFrom == property.GetMethod);
return c.Properties.Single(p => p.Name == property.Name);
} }
private void GenerateFieldGetter(Field field, Class @class) private void GenerateFieldGetter(Field field, Class @class)
@ -1956,9 +1969,7 @@ namespace CppSharp.Generators.CSharp
c is ClassTemplateSpecialization ? c is ClassTemplateSpecialization ?
c.Methods.First(m => m.InstantiatedFrom == dtor) : dtor), true); c.Methods.First(m => m.InstantiatedFrom == dtor) : dtor), true);
else else
this.GenerateMember(@class, c => GenerateInternalFunctionCall( this.GenerateMember(@class, c => GenerateMethodBody(c, dtor), true);
c is ClassTemplateSpecialization ?
c.Methods.First(m => m.InstantiatedFrom == dtor) : dtor), true);
if (@class.IsDependent || dtor.IsVirtual) if (@class.IsDependent || dtor.IsVirtual)
WriteCloseBraceIndent(); WriteCloseBraceIndent();
else else
@ -2265,16 +2276,14 @@ namespace CppSharp.Generators.CSharp
if (method.SynthKind == FunctionSynthKind.DefaultValueOverload || if (method.SynthKind == FunctionSynthKind.DefaultValueOverload ||
method.SynthKind == FunctionSynthKind.ComplementOperator) method.SynthKind == FunctionSynthKind.ComplementOperator)
{ {
GenerateMethodBody(method); GenerateMethodBody(@class, method);
} }
else else
{ {
var isVoid = method.OriginalReturnType.Type.Desugar().IsPrimitiveType(PrimitiveType.Void) || var isVoid = method.OriginalReturnType.Type.Desugar().IsPrimitiveType(PrimitiveType.Void) ||
method.IsConstructor; method.IsConstructor;
this.GenerateMember(@class, c => GenerateMethodBody( this.GenerateMember(@class, c => GenerateMethodBody(
c is ClassTemplateSpecialization ? c, method, method.OriginalReturnType), isVoid);
c.Methods.First(m => m.InstantiatedFrom == method) : method,
method.OriginalReturnType), isVoid);
} }
SkipImpl: SkipImpl:
@ -2289,10 +2298,24 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
private void GenerateMethodBody(Method method, private void GenerateMethodBody(Class @class, Method method,
QualifiedType returnType = default(QualifiedType)) QualifiedType returnType = default(QualifiedType))
{ {
var @class = (Class) method.Namespace; var specialization = @class as ClassTemplateSpecialization;
if (specialization != null)
{
var specializedMethod = @class.Methods.FirstOrDefault(
m => m.InstantiatedFrom == method);
if (specializedMethod != null)
method = specializedMethod;
else
{
WriteLine($@"throw new MissingMethodException(""Method {
method.Name} missing from explicit specialization {
@class.Visit(TypePrinter)}."");");
return;
}
}
if (@class.IsRefType) if (@class.IsRefType)
{ {
if (method.IsConstructor) if (method.IsConstructor)

7
src/Generator/Passes/TrimSpecializationsPass.cs

@ -95,10 +95,9 @@ namespace CppSharp.Passes
!specializations.Contains(s) && !internalSpecializations.Contains(s)); !specializations.Contains(s) && !internalSpecializations.Contains(s));
foreach (var specialization in template.Specializations.Where( foreach (var specialization in template.Specializations.Where(
s => !s.IsExplicitlyGenerated s => !s.IsExplicitlyGenerated &&
&& (s.SpecializationKind == TemplateSpecializationKind.ExplicitSpecialization (s is ClassTemplatePartialSpecialization ||
|| s is ClassTemplatePartialSpecialization internalSpecializations.Contains(s))))
|| internalSpecializations.Contains(s))))
specialization.ExplicitlyIgnore(); specialization.ExplicitlyIgnore();
Func<TemplateArgument, bool> allPointers = Func<TemplateArgument, bool> allPointers =

8
tests/CSharp/CSharpTemplates.cpp

@ -56,6 +56,14 @@ void HasDefaultTemplateArgument<bool, bool>::setStaticProperty(const bool& t)
bool HasDefaultTemplateArgument<bool, bool>::staticField; bool HasDefaultTemplateArgument<bool, bool>::staticField;
DerivesFromExplicitSpecialization::DerivesFromExplicitSpecialization()
{
}
DerivesFromExplicitSpecialization::~DerivesFromExplicitSpecialization()
{
}
HasVirtualTemplate::HasVirtualTemplate() HasVirtualTemplate::HasVirtualTemplate()
{ {
} }

25
tests/CSharp/CSharpTemplates.h

@ -275,6 +275,31 @@ DependentValueFields<D> HasDefaultTemplateArgument<T, D>::returnTemplateWithRena
template <typename T, typename D> template <typename T, typename D>
T HasDefaultTemplateArgument<T, D>::staticField; T HasDefaultTemplateArgument<T, D>::staticField;
template <typename T, typename D>
class DerivesFromTemplateWithExplicitSpecialization : public HasDefaultTemplateArgument<T, D>
{
public:
DerivesFromTemplateWithExplicitSpecialization();
~DerivesFromTemplateWithExplicitSpecialization();
};
template <typename T, typename D>
DerivesFromTemplateWithExplicitSpecialization<T, D>::DerivesFromTemplateWithExplicitSpecialization()
{
}
template <typename T, typename D>
DerivesFromTemplateWithExplicitSpecialization<T, D>::~DerivesFromTemplateWithExplicitSpecialization()
{
}
class DerivesFromExplicitSpecialization : public DerivesFromTemplateWithExplicitSpecialization<bool, bool>
{
public:
DerivesFromExplicitSpecialization();
~DerivesFromExplicitSpecialization();
};
template <typename T> template <typename T>
class TemplateWithIndexer class TemplateWithIndexer
{ {

Loading…
Cancel
Save