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

2
src/AST/Property.cs

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

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

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

4
src/Generator/Passes/MultipleInheritancePass.cs

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

1
tests/CSharpTemp/CSharpTemp.Tests.cs

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