Browse Source

Fixed the FindOperator method for classes.

Added AST test case and fixed line endings (LF).
pull/237/head
Elias Holzer 11 years ago
parent
commit
487189ebad
  1. 5
      src/AST/Class.cs
  2. 2
      src/AST/Namespace.cs
  3. 9
      src/Generator.Tests/AST/TestAST.cs
  4. 16
      tests/Native/AST.h

5
src/AST/Class.cs

@ -199,6 +199,11 @@ namespace CppSharp.AST @@ -199,6 +199,11 @@ namespace CppSharp.AST
}
}
public override IEnumerable<Function> FindOperator(CXXOperatorKind kind)
{
return Methods.Where(m => m.OperatorKind == kind);
}
public override IEnumerable<Function> GetOverloads(Function function)
{
if (function.IsOperator)

2
src/AST/Namespace.cs

@ -320,7 +320,7 @@ namespace CppSharp.AST @@ -320,7 +320,7 @@ namespace CppSharp.AST
return Enums.Find(e => e.ItemsByName.ContainsKey(name));
}
public IEnumerable<Function> FindOperator(CXXOperatorKind kind)
public virtual IEnumerable<Function> FindOperator(CXXOperatorKind kind)
{
return Functions.Where(fn => fn.OperatorKind == kind);
}

9
src/Generator.Tests/AST/TestAST.cs

@ -57,5 +57,14 @@ namespace CppSharp.Generator.Tests.AST @@ -57,5 +57,14 @@ namespace CppSharp.Generator.Tests.AST
}
Assert.IsTrue(func.Parameters[2].HasDefaultValue, "Parameter.HasDefaultValue");
}
[Test]
public void TestASTHelperMethods()
{
var @class = AstContext.FindClass("Math::Complex").FirstOrDefault();
Assert.IsNotNull(@class, "Couldn't find Math::Complex class.");
var plusOperator = @class.FindOperator(CXXOperatorKind.Plus).FirstOrDefault();
Assert.IsNotNull(plusOperator, "Couldn't find operator+ in Math::Complex class.");
}
}
}

16
tests/Native/AST.h

@ -1,2 +1,18 @@ @@ -1,2 +1,18 @@
// Tests assignment of AST.Parameter properties
void TestParameterProperties(bool a, const short& b, int* c = nullptr) {};
// Tests various AST helper methods (like FindClass, FindOperator etc.)
namespace Math
{
struct Complex {
Complex(double r, double i) : re(r), im(i) {}
Complex operator+(Complex &other);
private:
double re, im;
};
// Operator overloaded using a member function
Complex Complex::operator+(Complex &other) {
return Complex(re + other.re, im + other.im);
}
}
Loading…
Cancel
Save