Browse Source

Revert "Revert "Included ignored fields in the wrappers for better marshalling.""

This reverts commit 27d3f21a75.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/1140/head
Dimitar Dobrev 11 years ago
parent
commit
062f8e26e0
  1. 6
      src/AST/Declaration.cs
  2. 2
      src/Generator/AST/Utils.cs
  3. 9
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  4. 2
      src/Generator/Library.cs
  5. 12
      src/Generator/Passes/CheckIgnoredDecls.cs
  6. 1
      tests/Basic/Basic.cs
  7. 12
      tests/Basic/Basic.h
  8. 6
      tests/CSharpTemp/CSharpTemp.Tests.cs
  9. 5
      tests/CSharpTemp/CSharpTemp.cs
  10. 6
      tests/CSharpTemp/CSharpTemp.h

6
src/AST/Declaration.cs

@ -31,7 +31,7 @@ namespace CppSharp.AST
public enum GenerationKind public enum GenerationKind
{ {
/// <summary> /// <summary>
// Declaration is not generated. /// Declaration is not generated.
/// </summary> /// </summary>
None, None,
/// <summary> /// <summary>
@ -200,7 +200,8 @@ namespace CppSharp.AST
return generationKind.Value; return generationKind.Value;
if (Namespace != null) if (Namespace != null)
return Namespace.GenerationKind; // fields in nested classes have to always be generated
return !Namespace.IsGenerated && this is Field ? GenerationKind.Internal : Namespace.GenerationKind;
return GenerationKind.Generate; return GenerationKind.Generate;
} }
@ -352,7 +353,6 @@ namespace CppSharp.AST
} }
public abstract T Visit<T>(IDeclVisitor<T> visitor); public abstract T Visit<T>(IDeclVisitor<T> visitor);
} }
/// <summary> /// <summary>

2
src/Generator/AST/Utils.cs

@ -65,7 +65,7 @@ namespace CppSharp.AST
public static bool CheckIgnoreField(Field field, bool useInternals = false) public static bool CheckIgnoreField(Field field, bool useInternals = false)
{ {
if (field.Access == AccessSpecifier.Private) if (field.Access == AccessSpecifier.Private && !useInternals)
return true; return true;
if (field.Class.IsValueType && field.IsDeclared) if (field.Class.IsValueType && field.IsDeclared)

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

@ -353,7 +353,7 @@ namespace CppSharp.Generators.CSharp
public void GenerateClass(Class @class) public void GenerateClass(Class @class)
{ {
if (!@class.IsGenerated || @class.IsIncomplete) if (@class.IsIncomplete)
return; return;
PushBlock(CSharpBlockKind.Class); PushBlock(CSharpBlockKind.Class);
@ -370,7 +370,7 @@ namespace CppSharp.Generators.CSharp
GenerateClassInternals(@class); GenerateClassInternals(@class);
GenerateDeclContext(@class); GenerateDeclContext(@class);
if (@class.IsDependent) if (@class.IsDependent || !@class.IsGenerated)
goto exit; goto exit;
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
@ -720,14 +720,15 @@ namespace CppSharp.Generators.CSharp
if (!string.IsNullOrWhiteSpace(fieldTypePrinted.NameSuffix)) if (!string.IsNullOrWhiteSpace(fieldTypePrinted.NameSuffix))
safeIdentifier += fieldTypePrinted.NameSuffix; safeIdentifier += fieldTypePrinted.NameSuffix;
var access = @class != null && !@class.IsGenerated ? "internal" : "public";
if (field.Expression != null) if (field.Expression != null)
{ {
var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter); var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter);
Write("public {0} {1} = {2};", fieldTypePrinted.Type, safeIdentifier, fieldValuePrinted); Write("{0} {1} {2} = {3};", access, fieldTypePrinted.Type, safeIdentifier, fieldValuePrinted);
} }
else else
{ {
Write("public {0} {1};", fieldTypePrinted.Type, safeIdentifier); Write("{0} {1} {2};", access, fieldTypePrinted.Type, safeIdentifier);
} }
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);

2
src/Generator/Library.cs

@ -184,7 +184,7 @@ namespace CppSharp
public static void IgnoreClassWithName(this ASTContext context, string name) public static void IgnoreClassWithName(this ASTContext context, string name)
{ {
foreach (var @class in context.FindClass(name)) foreach (var @class in context.FindClass(name))
@class.ExplicitlyIgnore(); @class.GenerationKind = GenerationKind.Internal;
} }
public static void SetClassAsOpaque(this ASTContext context, string name) public static void SetClassAsOpaque(this ASTContext context, string name)

12
src/Generator/Passes/CheckIgnoredDecls.cs

@ -40,13 +40,13 @@ namespace CppSharp.Passes
{ {
Log.Debug("Decl '{0}' was ignored due to invalid access", Log.Debug("Decl '{0}' was ignored due to invalid access",
decl.Name); decl.Name);
decl.ExplicitlyIgnore(); decl.GenerationKind = decl is Field ? GenerationKind.Internal : GenerationKind.None;
return true; return true;
} }
if (decl.IsDependent) if (decl.IsDependent)
{ {
decl.ExplicitlyIgnore(); decl.GenerationKind = decl is Field ? GenerationKind.Internal : GenerationKind.None;
Log.Debug("Decl '{0}' was ignored due to dependent context", Log.Debug("Decl '{0}' was ignored due to dependent context",
decl.Name); decl.Name);
return true; return true;
@ -62,11 +62,13 @@ namespace CppSharp.Passes
var type = field.Type; var type = field.Type;
string msg; Declaration decl;
if (!HasInvalidType(type, out msg)) type.TryGetDeclaration(out decl);
string msg = "internal";
if (decl == null || (decl.GenerationKind != GenerationKind.Internal && !HasInvalidType(type, out msg)))
return false; return false;
field.ExplicitlyIgnore(); field.GenerationKind = GenerationKind.Internal;
var @class = (Class)field.Namespace; var @class = (Class)field.Namespace;

1
tests/Basic/Basic.cs

@ -34,6 +34,7 @@ namespace CppSharp.Tests
driver.AddTranslationUnitPass(new CheckMacroPass()); driver.AddTranslationUnitPass(new CheckMacroPass());
ctx.SetClassAsValueType("Bar"); ctx.SetClassAsValueType("Bar");
ctx.SetClassAsValueType("Bar2"); ctx.SetClassAsValueType("Bar2");
ctx.IgnoreClassWithName("IgnoredType");
} }
public static void Main(string[] args) public static void Main(string[] args)

12
tests/Basic/Basic.h

@ -6,6 +6,17 @@
#endif #endif
#include <string> #include <string>
class DLL_API IgnoredType
{
class IgnoredNested
{
private:
int i;
};
private:
int i;
};
class DLL_API Foo class DLL_API Foo
{ {
private: private:
@ -25,6 +36,7 @@ public:
Foo(Private p); Foo(Private p);
int A; int A;
float B; float B;
IgnoredType ignoredType;
int fixedArray[3]; int fixedArray[3];
void* ptr; void* ptr;
static const int unsafe = 10; static const int unsafe = 10;

6
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -247,6 +247,12 @@ public class CSharpTempTests : GeneratorTestFixture
Assert.That(res, Is.EqualTo(50)); Assert.That(res, Is.EqualTo(50));
} }
[Test]
public void TestInnerClasses()
{
QMap.Iterator test_iter;
}
[Test] [Test]
public void TestNativeToManagedMapWithForeignObjects() public void TestNativeToManagedMapWithForeignObjects()
{ {

5
tests/CSharpTemp/CSharpTemp.cs

@ -59,8 +59,7 @@ namespace CppSharp.Tests
public override string CSharpSignature(CSharpTypePrinterContext ctx) public override string CSharpSignature(CSharpTypePrinterContext ctx)
{ {
if (ctx.CSharpKind == CSharpTypePrinterContextKind.Native) if (ctx.CSharpKind == CSharpTypePrinterContextKind.Native)
// pointless, put just so that the generated code compiles return Type.IsAddress() ? "QList.Internal*" : "QList.Internal";
return "global::System.IntPtr";
return string.Format("System.Collections.Generic.{0}<{1}>", return string.Format("System.Collections.Generic.{0}<{1}>",
ctx.CSharpKind == CSharpTypePrinterContextKind.DefaultExpression ? "List" : "IList", ctx.CSharpKind == CSharpTypePrinterContextKind.DefaultExpression ? "List" : "IList",
@ -70,7 +69,7 @@ namespace CppSharp.Tests
public override void CSharpMarshalToNative(MarshalContext ctx) public override void CSharpMarshalToNative(MarshalContext ctx)
{ {
// pointless, put just so that the generated code compiles // pointless, put just so that the generated code compiles
ctx.Return.Write("new global::System.IntPtr()"); ctx.Return.Write("new QList.Internal()");
} }
public override void CSharpMarshalToManaged(MarshalContext ctx) public override void CSharpMarshalToManaged(MarshalContext ctx)

6
tests/CSharpTemp/CSharpTemp.h

@ -80,7 +80,11 @@ class DLL_API ForceCreationOfInterface : public Foo, public Bar
class DLL_API Baz : public Foo, public Bar class DLL_API Baz : public Foo, public Bar
{ {
public: public:
class NestedBase1 {}; class NestedBase1 {
int f1;
double f2;
void* f3;
};
class NestedBase2 {}; class NestedBase2 {};
class NestedDerived : public NestedBase1, public NestedBase2 {}; class NestedDerived : public NestedBase1, public NestedBase2 {};

Loading…
Cancel
Save