Browse Source

Replaced the vague checks for explicit interface impls with a specific property.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/68/head
Dimitar Dobrev 12 years ago
parent
commit
f07ddf79fc
  1. 2
      src/AST/Method.cs
  2. 2
      src/AST/Property.cs
  3. 24
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  4. 4
      src/Generator/Passes/MultipleInheritancePass.cs
  5. 1
      tests/CSharpTemp/CSharpTemp.Tests.cs

2
src/AST/Method.cs

@ -126,6 +126,8 @@ namespace CppSharp.AST
public MethodConversionKind Conversion { get; set; } public MethodConversionKind Conversion { get; set; }
public Class ExplicitInterfaceImpl { get; set; }
public override QualifiedType GetFunctionType() public override QualifiedType GetFunctionType()
{ {
var qualifiedType = base.GetFunctionType(); var qualifiedType = base.GetFunctionType();

2
src/AST/Property.cs

@ -62,6 +62,8 @@ namespace CppSharp.AST
// The field that should be get and set by this property // The field that should be get and set by this property
public Field Field { get; set; } public Field Field { get; set; }
public Class ExplicitInterfaceImpl { get; set; }
private readonly List<Parameter> parameters = new List<Parameter>(); private readonly List<Parameter> parameters = new List<Parameter>();
/// <summary> /// <summary>

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

@ -1000,13 +1000,13 @@ namespace CppSharp.Generators.CSharp
var type = prop.Type; var type = prop.Type;
if (prop.Parameters.Count > 0 && prop.Type.IsPointerToPrimitiveType()) if (prop.Parameters.Count > 0 && prop.Type.IsPointerToPrimitiveType())
type = ((PointerType) prop.Type).Pointee; type = ((PointerType) prop.Type).Pointee;
// explicit impl
if (prop.Name.Contains('.')) if (prop.ExplicitInterfaceImpl == null)
WriteLine("{0} {1}", type, GetPropertyName(prop));
else
WriteLine("{0} {1} {2}", WriteLine("{0} {1} {2}",
prop.Access == AccessSpecifier.Public ? "public" : "protected", prop.Access == AccessSpecifier.Public ? "public" : "protected",
type, GetPropertyName(prop)); type, GetPropertyName(prop));
else
WriteLine("{0} {1}.{2}", type, prop.ExplicitInterfaceImpl.Name, GetPropertyName(prop));
WriteStartBraceIndent(); WriteStartBraceIndent();
if (prop.Field != null) if (prop.Field != null)
@ -1033,12 +1033,8 @@ namespace CppSharp.Generators.CSharp
private string GetPropertyName(Property prop) private string GetPropertyName(Property prop)
{ {
// check for explicit interface implementations return prop.Parameters.Count == 0 ? SafeIdentifier(prop.Name)
var indexOfDot = prop.Name.IndexOf('.'); : string.Format("this[{0}]", this.FormatMethodParameters(prop.Parameters));
string name = prop.Name.Substring(prop.Name.IndexOf('.') + 1);
return prop.Name.Substring(0, indexOfDot + 1) +
(prop.Parameters.Count == 0 ? SafeIdentifier(name)
: string.Format("this[{0}]", FormatMethodParameters(prop.Parameters)));
} }
private void GenerateVariable(Class @class, Type type, Variable variable) private void GenerateVariable(Class @class, Type type, Variable variable)
@ -1602,8 +1598,7 @@ namespace CppSharp.Generators.CSharp
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
GenerateDeclarationCommon(method); GenerateDeclarationCommon(method);
// check if this is an explicit interface implementation if (method.ExplicitInterfaceImpl == null)
if (!method.Name.Contains('.'))
{ {
switch (GetValidMethodAccess(method, @class)) switch (GetValidMethodAccess(method, @class))
{ {
@ -1637,8 +1632,11 @@ namespace CppSharp.Generators.CSharp
if (method.IsConstructor || method.IsDestructor) if (method.IsConstructor || method.IsDestructor)
Write("{0}(", functionName); Write("{0}(", functionName);
else else if (method.ExplicitInterfaceImpl == null)
Write("{0} {1}(", method.OriginalReturnType, functionName); Write("{0} {1}(", method.OriginalReturnType, functionName);
else
Write("{0} {1}.{2}(", method.OriginalReturnType,
method.ExplicitInterfaceImpl.Name, functionName);
Write(FormatMethodParameters(method.Parameters)); Write(FormatMethodParameters(method.Parameters));

4
src/Generator/Passes/MultipleInheritancePass.cs

@ -85,7 +85,7 @@ namespace CppSharp.Passes
}; };
var rootBaseMethod = @class.GetRootBaseMethod(method, true); var rootBaseMethod = @class.GetRootBaseMethod(method, true);
if (rootBaseMethod != null && !rootBaseMethod.Ignore) if (rootBaseMethod != null && !rootBaseMethod.Ignore)
impl.Name = @interface.Name + "." + impl.Name; impl.ExplicitInterfaceImpl = @interface;
@class.Methods.Add(impl); @class.Methods.Add(impl);
} }
foreach (var @base in @interface.Bases) foreach (var @base in @interface.Bases)
@ -99,7 +99,7 @@ namespace CppSharp.Passes
var impl = new Property(property) { Namespace = @class }; var impl = new Property(property) { Namespace = @class };
var rootBaseProperty = @class.GetRootBaseProperty(property, true); var rootBaseProperty = @class.GetRootBaseProperty(property, true);
if (rootBaseProperty != null && !rootBaseProperty.Ignore) if (rootBaseProperty != null && !rootBaseProperty.Ignore)
impl.Name = @interface.Name + "." + impl.Name; impl.ExplicitInterfaceImpl = @interface;
@class.Properties.Add(impl); @class.Properties.Add(impl);
} }
foreach (var @base in @interface.Bases) foreach (var @base in @interface.Bases)

1
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -41,5 +41,6 @@ public class CSharpTempTests
Assert.That(baz[0], Is.EqualTo(50)); Assert.That(baz[0], Is.EqualTo(50));
bar[0] = new Foo { A = 1000 }; bar[0] = new Foo { A = 1000 };
Assert.That(bar[0].A, Is.EqualTo(1000)); Assert.That(bar[0].A, Is.EqualTo(1000));
Assert.That(baz.farAwayFunc(), Is.EqualTo(20));
} }
} }
Loading…
Cancel
Save