diff --git a/src/AST/Declaration.cs b/src/AST/Declaration.cs
index b402776f..79646df3 100644
--- a/src/AST/Declaration.cs
+++ b/src/AST/Declaration.cs
@@ -31,7 +31,7 @@ namespace CppSharp.AST
public enum GenerationKind
{
///
- // Declaration is not generated.
+ /// Declaration is not generated.
///
None,
///
@@ -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
}
public abstract T Visit(IDeclVisitor visitor);
-
}
///
diff --git a/src/Generator/AST/Utils.cs b/src/Generator/AST/Utils.cs
index 6c3f2446..8c83a0e9 100644
--- a/src/Generator/AST/Utils.cs
+++ b/src/Generator/AST/Utils.cs
@@ -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)
diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
index 93933007..0b52e3b9 100644
--- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
+++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
@@ -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
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
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);
diff --git a/src/Generator/Library.cs b/src/Generator/Library.cs
index bd32595e..026e8d06 100644
--- a/src/Generator/Library.cs
+++ b/src/Generator/Library.cs
@@ -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)
diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs
index df425b90..ccbfc717 100644
--- a/src/Generator/Passes/CheckIgnoredDecls.cs
+++ b/src/Generator/Passes/CheckIgnoredDecls.cs
@@ -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
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;
diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs
index 42a75b2b..269386a7 100644
--- a/tests/Basic/Basic.cs
+++ b/tests/Basic/Basic.cs
@@ -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)
diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h
index 254ee08f..6de143fd 100644
--- a/tests/Basic/Basic.h
+++ b/tests/Basic/Basic.h
@@ -6,6 +6,17 @@
#endif
#include
+class DLL_API IgnoredType
+{
+ class IgnoredNested
+ {
+ private:
+ int i;
+ };
+private:
+ int i;
+};
+
class DLL_API Foo
{
private:
@@ -25,6 +36,7 @@ public:
Foo(Private p);
int A;
float B;
+ IgnoredType ignoredType;
int fixedArray[3];
void* ptr;
static const int unsafe = 10;
diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs
index 2c6af951..a83ae64c 100644
--- a/tests/CSharpTemp/CSharpTemp.Tests.cs
+++ b/tests/CSharpTemp/CSharpTemp.Tests.cs
@@ -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()
{
diff --git a/tests/CSharpTemp/CSharpTemp.cs b/tests/CSharpTemp/CSharpTemp.cs
index 035999af..586e6502 100644
--- a/tests/CSharpTemp/CSharpTemp.cs
+++ b/tests/CSharpTemp/CSharpTemp.cs
@@ -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
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)
diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h
index 179af8aa..6d865127 100644
--- a/tests/CSharpTemp/CSharpTemp.h
+++ b/tests/CSharpTemp/CSharpTemp.h
@@ -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 {};