Browse Source

Reworked property handling to check if each property getter/setter can be generated.

Fixes a bug where we tried to generate a setter for a const field.
pull/34/merge
triton 12 years ago
parent
commit
c490d25e74
  1. 17
      src/AST/Property.cs
  2. 4
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  3. 18
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  4. 11
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

17
src/AST/Property.cs

@ -16,6 +16,23 @@ namespace CppSharp.AST
public Method SetMethod { get; set; } public Method SetMethod { get; set; }
public bool HasGetter
{
get
{
return (GetMethod != null) || (Field != null);
}
}
public bool HasSetter
{
get
{
return (SetMethod != null) ||
(Field != null && !Field.QualifiedType.Qualifiers.IsConst);
}
}
// The field that should be get and set by this property // The field that should be get and set by this property
public Field Field { get; set; } public Field Field { get; set; }

4
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -477,9 +477,7 @@ namespace CppSharp.Generators.CLI
if (prop.Ignore) continue; if (prop.Ignore) continue;
GenerateDeclarationCommon(prop); GenerateDeclarationCommon(prop);
var isGetter = prop.GetMethod != null || prop.Field != null; GenerateProperty(prop, prop.HasGetter, prop.HasSetter);
var isSetter = prop.SetMethod != null || prop.Field != null;
GenerateProperty(prop, isGetter, isSetter);
} }
PopIndent(); PopIndent();
} }

18
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -240,13 +240,23 @@ namespace CppSharp.Generators.CLI
if (property.Field != null) if (property.Field != null)
{ {
GeneratePropertyGetter(property.Field, @class, property.Name, property.Type); if (property.HasGetter)
GeneratePropertySetter(property.Field, @class, property.Name, property.Type); GeneratePropertyGetter(property.Field, @class, property.Name,
property.Type);
if (property.HasSetter)
GeneratePropertySetter(property.Field, @class, property.Name,
property.Type);
} }
else else
{ {
GeneratePropertyGetter(property.GetMethod, @class, property.Name, property.Type); if (property.HasGetter)
GeneratePropertySetter(property.SetMethod, @class, property.Name, property.Type); GeneratePropertyGetter(property.GetMethod, @class, property.Name,
property.Type);
if (property.HasSetter)
GeneratePropertySetter(property.SetMethod, @class, property.Name,
property.Type);
} }
PopBlock(); PopBlock();
} }

11
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -892,15 +892,18 @@ namespace CppSharp.Generators.CSharp
if (prop.Field != null) if (prop.Field != null)
{ {
GeneratePropertyGetter(prop.Field, @class); if (prop.HasGetter)
GeneratePropertySetter(prop.Field, @class); GeneratePropertyGetter(prop.Field, @class);
if (prop.HasSetter)
GeneratePropertySetter(prop.Field, @class);
} }
else else
{ {
if (prop.GetMethod != null) if (prop.HasGetter)
GeneratePropertyGetter(prop.GetMethod, @class); GeneratePropertyGetter(prop.GetMethod, @class);
if (prop.SetMethod != null) if (prop.HasSetter)
GeneratePropertySetter(prop.SetMethod, @class); GeneratePropertySetter(prop.SetMethod, @class);
} }

Loading…
Cancel
Save