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 @@ -31,7 +31,7 @@ namespace CppSharp.AST
public enum GenerationKind
{
/// <summary>
// Declaration is not generated.
/// Declaration is not generated.
/// </summary>
None,
/// <summary>
@ -200,7 +200,8 @@ namespace CppSharp.AST @@ -200,7 +200,8 @@ namespace CppSharp.AST
return generationKind.Value;
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;
}
@ -352,7 +353,6 @@ namespace CppSharp.AST @@ -352,7 +353,6 @@ namespace CppSharp.AST
}
public abstract T Visit<T>(IDeclVisitor<T> visitor);
}
/// <summary>

2
src/Generator/AST/Utils.cs

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

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

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

2
src/Generator/Library.cs

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

12
src/Generator/Passes/CheckIgnoredDecls.cs

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

1
tests/Basic/Basic.cs

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

12
tests/Basic/Basic.h

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

6
tests/CSharpTemp/CSharpTemp.Tests.cs

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

5
tests/CSharpTemp/CSharpTemp.cs

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

6
tests/CSharpTemp/CSharpTemp.h

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

Loading…
Cancel
Save