Browse Source

Ensure enumerations lack conflicts when renamed

Fixes https://github.com/mono/CppSharp/issues/965.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
const-wchar_t
Dimitar Dobrev 6 years ago
parent
commit
dcd11e9433
  1. 7
      src/Generator/Passes/RenamePass.cs
  2. 16
      tests/Common/Common.Tests.cs
  3. 4
      tests/Common/Common.h

7
src/Generator/Passes/RenamePass.cs

@ -215,9 +215,14 @@ namespace CppSharp.Passes
var property = decl as Property; var property = decl as Property;
if (property != null && property.Field != null) if (property != null && property.Field != null)
return ((Class) decl.Namespace).Properties.FirstOrDefault( return ((Class) decl.Namespace).Properties.Find(
p => p != decl && p.Name == newName) != null; p => p != decl && p.Name == newName) != null;
var enumItem = decl as Enumeration.Item;
if (enumItem != null)
return ((Enumeration) enumItem.Namespace).Items.Any(
i => i != decl && i.Name == newName);
return false; return false;
} }

16
tests/Common/Common.Tests.cs

@ -51,14 +51,14 @@ public class CommonTests : GeneratorTestFixture
{ {
hasPropertyNamedAsParent.hasPropertyNamedAsParent.GetHashCode(); hasPropertyNamedAsParent.hasPropertyNamedAsParent.GetHashCode();
} }
EnumWithUnderscores e = EnumWithUnderscores.lOWER_BEFORE_CAPITAL; EnumWithUnderscores.lOWER_BEFORE_CAPITAL.GetHashCode();
e = EnumWithUnderscores.UnderscoreAtEnd; EnumWithUnderscores.UnderscoreAtEnd.GetHashCode();
e = EnumWithUnderscores.CAPITALS_More; EnumWithUnderscores.CAPITALS_More.GetHashCode();
e = EnumWithUnderscores.UsesDigits1_0; EnumWithUnderscores.UsesDigits1_0.GetHashCode();
e.GetHashCode(); ItemsDifferByCase.Case_a.GetHashCode();
ItemsDifferByCase itemsDifferByCase = ItemsDifferByCase.Case_a; ItemsDifferByCase.CaseA.GetHashCode();
itemsDifferByCase = ItemsDifferByCase.CaseA; Enum.NAME_A.GetHashCode();
itemsDifferByCase.GetHashCode(); Enum.NAME__A.GetHashCode();
new AmbiguousParamNames(0, 0).Dispose(); new AmbiguousParamNames(0, 0).Dispose();
Common.SMallFollowedByCapital(); Common.SMallFollowedByCapital();
Common.IntegerOverload(0); Common.IntegerOverload(0);

4
tests/Common/Common.h

@ -191,7 +191,9 @@ enum Enum
A = 0, B = 2, C = 5, A = 0, B = 2, C = 5,
//D = 0x80000000, //D = 0x80000000,
E = 0x1, E = 0x1,
F = -9 F = -9,
NAME_A = 10,
NAME__A = 20
}; };
typedef char TypedefChar; typedef char TypedefChar;

Loading…
Cancel
Save