Browse Source

Merge pull request #465 from ddobrev/master

Fixed the naming of multiple anonymous types in a union
pull/467/head
João Matos 10 years ago
parent
commit
5d4875982e
  1. 2
      src/Generator/Options.cs
  2. 11
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs
  3. 49
      tests/Basic/Basic.h

2
src/Generator/Options.cs

@ -133,7 +133,7 @@ namespace CppSharp @@ -133,7 +133,7 @@ namespace CppSharp
public List<string> NoGenIncludeDirs;
/// <summary>
/// Wether the generated C# code should be automatically compiled.
/// Whether the generated C# code should be automatically compiled.
/// </summary>
public bool CompileCode;

11
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -74,6 +74,17 @@ namespace CppSharp.Passes @@ -74,6 +74,17 @@ namespace CppSharp.Passes
var ret = base.VisitClassDecl(@class);
this.uniqueName = currentUniqueName;
if (@class.Namespace.Classes.Any(d => d != @class && d.Name == @class.Name))
{
StringBuilder str = new StringBuilder();
str.Append(@class.Name);
do
{
str.Append('_');
} while (@class.Classes.Any(d => d != @class && d.Name == str.ToString()));
@class.Name = str.ToString();
}
return ret;
}

49
tests/Basic/Basic.h

@ -647,24 +647,24 @@ public: @@ -647,24 +647,24 @@ public:
{
};
};
struct
{
struct
{
};
};
struct
{
struct
{
};
};
struct
{
struct
{
};
};
struct
{
struct
{
};
};
struct
{
struct
{
};
};
struct
{
struct
{
};
};
union as_types
{
@ -728,3 +728,16 @@ public: @@ -728,3 +728,16 @@ public:
bool operator ==(const DifferentConstOverloads& other);
bool operator ==(int number) const;
};
class TestNamingAnonymousTypesInUnion
{
public:
union {
struct {
} argb;
struct {
} ahsv;
struct {
} acmyk;
} ct;
};

Loading…
Cancel
Save