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

1
tests/Basic/Basic.Tests.cs

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

4
tests/Basic/Basic.cs

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

6
tests/Basic/Basic.h

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

Loading…
Cancel
Save