Browse Source

Wrapped value typed fields with properties in order to have changes reflected to the native pointer.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/147/head
Dimitar Dobrev 12 years ago
parent
commit
e1a12027ec
  1. 4
      src/AST/Property.cs
  2. 4
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  3. 2
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  4. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  5. 2
      src/Generator/Passes/FieldToPropertyPass.cs
  6. 30
      tests/Basic/Basic.h

4
src/AST/Property.cs

@ -105,9 +105,9 @@ namespace CppSharp.AST @@ -105,9 +105,9 @@ namespace CppSharp.AST
return visitor.VisitProperty(this);
}
public bool IsBackedByValueClassField()
public bool IsInRefTypeAndBackedByValueClassField()
{
if (Field == null)
if (Field == null || ((Class) Namespace).IsRefType)
return false;
Type type;

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

@ -426,7 +426,7 @@ namespace CppSharp.Generators.CLI @@ -426,7 +426,7 @@ namespace CppSharp.Generators.CLI
foreach (var field in @class.Fields.Where(f => !f.Ignore || @class.IsValueType))
{
var property = @class.Properties.FirstOrDefault(p => p.Field == field);
if (property != null && !property.IsBackedByValueClassField())
if (property != null && !property.IsInRefTypeAndBackedByValueClassField())
{
GenerateField(@class, field);
}
@ -595,7 +595,7 @@ namespace CppSharp.Generators.CLI @@ -595,7 +595,7 @@ namespace CppSharp.Generators.CLI
PushIndent();
foreach (var prop in @class.Properties.Where(prop => !prop.Ignore))
{
if (prop.IsBackedByValueClassField())
if (prop.IsInRefTypeAndBackedByValueClassField())
{
GenerateField(@class, prop.Field);
continue;

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

@ -206,7 +206,7 @@ namespace CppSharp.Generators.CLI @@ -206,7 +206,7 @@ namespace CppSharp.Generators.CLI
}
foreach (var property in @class.Properties.Where(
p => !p.Ignore && !p.IsBackedByValueClassField()))
p => !p.Ignore && !p.IsInRefTypeAndBackedByValueClassField()))
GenerateProperty(property, realOwner);
}

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

@ -1130,7 +1130,7 @@ namespace CppSharp.Generators.CSharp @@ -1130,7 +1130,7 @@ namespace CppSharp.Generators.CSharp
{
foreach (var prop in @class.Properties.Where(p => !p.Ignore))
{
if (prop.IsBackedByValueClassField())
if (prop.IsInRefTypeAndBackedByValueClassField())
{
GenerateClassField(prop.Field, true);
continue;

2
src/Generator/Passes/FieldToPropertyPass.cs

@ -52,7 +52,7 @@ namespace CppSharp.Passes @@ -52,7 +52,7 @@ namespace CppSharp.Passes
// generated as fields later on even though they are wrapped by properties;
// that is, in turn, because it's cleaner to write
// the struct marshalling logic just for properties
if (!prop.IsBackedByValueClassField())
if (!prop.IsInRefTypeAndBackedByValueClassField())
field.Name = Generator.GeneratedIdentifier(field.Name);
@class.Properties.Add(prop);

30
tests/Basic/Basic.h

@ -17,20 +17,6 @@ public: @@ -17,20 +17,6 @@ public:
const char* GetANSI();
};
class DLL_API Foo2 : public Foo
{
struct Copy {
Foo A;
}* copy;
public:
int C;
Foo2 operator<<(signed int i);
Foo2 operator<<(signed long l);
};
struct DLL_API Bar
{
enum Item
@ -47,6 +33,21 @@ struct DLL_API Bar @@ -47,6 +33,21 @@ struct DLL_API Bar
Bar* returnPointerToValueType();
};
class DLL_API Foo2 : public Foo
{
struct Copy {
Foo A;
}* copy;
public:
int C;
Foo2 operator<<(signed int i);
Foo2 operator<<(signed long l);
Bar valueTypeField;
};
DLL_API Bar::Item operator |(Bar::Item left, Bar::Item right);
struct DLL_API Bar2 : public Bar
@ -69,6 +70,7 @@ struct DLL_API Bar2 : public Bar @@ -69,6 +70,7 @@ struct DLL_API Bar2 : public Bar
Bar* pointerToStruct;
int* pointerToPrimitive;
Foo2* pointerToClass;
Bar valueStruct;
};
enum Enum

Loading…
Cancel
Save