Browse Source

Move some helper functions out of the template and into an helpers class.

pull/12/merge
triton 12 years ago
parent
commit
cb85d8ead3
  1. 48
      src/Generator/AST/Utils.cs
  2. 48
      src/Generator/Generators/Template.cs
  3. 4
      src/Generator/Passes/CheckAmbiguousOverloads.cs

48
src/Generator/AST/Utils.cs

@ -1,9 +1,53 @@ @@ -1,9 +1,53 @@
using System.Collections.Generic;

namespace CppSharp.AST
{
public static class Utils
{
public static bool CheckIgnoreFunction(Class @class, Function function)
{
if (function.Ignore) return true;
if (function is Method)
return CheckIgnoreMethod(@class, function as Method);
return false;
}
public static bool CheckIgnoreMethod(Class @class, Method method)
{
if (method.Ignore) return true;
var isEmptyCtor = method.IsConstructor && method.Parameters.Count == 0;
if (@class.IsValueType && isEmptyCtor)
return true;
if (method.IsCopyConstructor || method.IsMoveConstructor)
return true;
if (method.IsDestructor)
return true;
if (method.OperatorKind == CXXOperatorKind.Equal)
return true;
if (method.Kind == CXXMethodKind.Conversion)
return true;
if (method.Access != AccessSpecifier.Public)
return true;
return false;
}
public static bool CheckIgnoreField(Class @class, Field field)
{
if (field.Ignore) return true;
if (field.Access != AccessSpecifier.Public)
return true;
return false;
}
}
}

48
src/Generator/Generators/Template.cs

@ -22,52 +22,4 @@ @@ -22,52 +22,4 @@
Transform = driver.Transform;
TranslationUnit = unit;
}
public static bool CheckIgnoreFunction(Class @class, Function function)
{
if (function.Ignore) return true;
if (function is Method)
return CheckIgnoreMethod(@class, function as Method);
return false;
}
public static bool CheckIgnoreMethod(Class @class, Method method)
{
if (method.Ignore) return true;
var isEmptyCtor = method.IsConstructor && method.Parameters.Count == 0;
if (@class.IsValueType && isEmptyCtor)
return true;
if (method.IsCopyConstructor || method.IsMoveConstructor)
return true;
if (method.IsDestructor)
return true;
if (method.OperatorKind == CXXOperatorKind.Equal)
return true;
if (method.Kind == CXXMethodKind.Conversion)
return true;
if (method.Access != AccessSpecifier.Public)
return true;
return false;
}
public static bool CheckIgnoreField(Class @class, Field field)
{
if (field.Ignore) return true;
if (field.Access != AccessSpecifier.Public)
return true;
return false;
}
}
}

4
src/Generator/Passes/CheckAmbiguousOverloads.cs

@ -30,10 +30,10 @@ namespace CppSharp.Passes @@ -30,10 +30,10 @@ namespace CppSharp.Passes
if (overload1.Function == overload2.Function)
return false;
if (TextTemplate.CheckIgnoreFunction(@class, overload1.Function))
if (AST.Utils.CheckIgnoreFunction(@class, overload1.Function))
return false;
if (TextTemplate.CheckIgnoreFunction(@class, overload2.Function))
if (AST.Utils.CheckIgnoreFunction(@class, overload2.Function))
return false;
// TODO: Default parameters?

Loading…
Cancel
Save