Browse Source

Fixed the cleaning of invalid names to allow custom names for enums.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/539/head
Dimitar Dobrev 10 years ago
parent
commit
63bc07e965
  1. 9
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs
  2. 1
      tests/Basic/Basic.Tests.cs
  3. 4
      tests/Basic/Basic.cs
  4. 6
      tests/Basic/Basic.h

9
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -44,7 +44,7 @@ namespace CppSharp.Passes @@ -44,7 +44,7 @@ namespace CppSharp.Passes
}
Function function = decl as Function;
if (function == null || !function.IsOperator)
if ((function == null || !function.IsOperator) && !(decl is Enumeration))
decl.Name = CheckName(decl.Name);
StringHelpers.CleanupText(ref decl.DebugText);
@ -127,12 +127,12 @@ namespace CppSharp.Passes @@ -127,12 +127,12 @@ namespace CppSharp.Passes
return true;
}
private static void CheckEnumName(Enumeration @enum)
private void CheckEnumName(Enumeration @enum)
{
// If we still do not have a valid name, then try to guess one
// based on the enum value names.
if (!string.IsNullOrWhiteSpace(@enum.OriginalName))
if (!string.IsNullOrWhiteSpace(@enum.Name))
return;
var prefix = @enum.Items.Select(item => item.Name)
@ -140,7 +140,10 @@ namespace CppSharp.Passes @@ -140,7 +140,10 @@ namespace CppSharp.Passes
// Try a simple heuristic to make sure we end up with a valid name.
if (prefix.Length < 3)
{
@enum.Name = CheckName(@enum.Name);
return;
}
prefix = prefix.Trim().Trim('_');
@enum.Name = prefix;

1
tests/Basic/Basic.Tests.cs

@ -12,6 +12,7 @@ public class BasicTests : GeneratorTestFixture @@ -12,6 +12,7 @@ public class BasicTests : GeneratorTestFixture
{
Assert.That(new ChangedAccessOfInheritedProperty().Property, Is.EqualTo(2));
Foo.NestedAbstract a;
var renamedEmptyEnum = Foo.RenamedEmptyEnum.EmptyEnum1;
}
[Test]

4
tests/Basic/Basic.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
@ -35,6 +36,9 @@ namespace CppSharp.Tests @@ -35,6 +36,9 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("Bar");
ctx.SetClassAsValueType("Bar2");
ctx.IgnoreClassWithName("IgnoredType");
ctx.FindCompleteClass("Foo").Enums.First(
e => string.IsNullOrEmpty(e.Name)).Name = "RenamedEmptyEnum";
}
public static void Main(string[] args)

6
tests/Basic/Basic.h

@ -26,6 +26,12 @@ private: @@ -26,6 +26,12 @@ private:
Value2
};
public:
enum
{
EmptyEnum1,
EmptyEnum2
};
class NestedAbstract
{
public:

Loading…
Cancel
Save