From 0a61baa4b660e4cb66e292cf589fee1214572401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Peter=20Rouven=20M=C3=BCller?= Date: Sat, 22 Apr 2017 23:07:56 +0200 Subject: [PATCH] Completely ignore incomplete classes in C++/CLI (#823) Signed-off-by: realvictorprm --- src/Generator/Generators/CLI/CLIHeaders.cs | 27 +++++++++++++++++----- src/Generator/Generators/CLI/CLISources.cs | 12 ++++++---- tests/CLI/CLI.cpp | 12 ++++++++++ tests/CLI/CLI.h | 9 +++++++- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/Generator/Generators/CLI/CLIHeaders.cs b/src/Generator/Generators/CLI/CLIHeaders.cs index 2b13fb48..01a5f85b 100644 --- a/src/Generator/Generators/CLI/CLIHeaders.cs +++ b/src/Generator/Generators/CLI/CLIHeaders.cs @@ -394,7 +394,7 @@ namespace CppSharp.Generators.CLI foreach (var ctor in @class.Constructors) { - if (ASTUtils.CheckIgnoreMethod(ctor, Options)) + if (ASTUtils.CheckIgnoreMethod(ctor, Options) || FunctionIgnored(ctor)) continue; // C++/CLI does not allow special member funtions for value types. @@ -526,7 +526,7 @@ namespace CppSharp.Generators.CLI var staticMethods = new List(); foreach (var method in methods) { - if (ASTUtils.CheckIgnoreMethod(method, Options)) + if (ASTUtils.CheckIgnoreMethod(method, Options) || FunctionIgnored(method)) continue; if (method.IsConstructor) @@ -622,7 +622,8 @@ namespace CppSharp.Generators.CLI } PushIndent(); - foreach (var prop in @class.Properties.Where(prop => !ASTUtils.CheckIgnoreProperty(prop))) + foreach (var prop in @class.Properties.Where( + prop => !ASTUtils.CheckIgnoreProperty(prop) && !TypeIgnored(prop.Type))) { if (prop.IsInRefTypeAndBackedByValueClassField()) { @@ -657,7 +658,7 @@ namespace CppSharp.Generators.CLI public void GenerateProperty(Property property) { - if (!(property.HasGetter || property.HasSetter)) + if (!(property.HasGetter || property.HasSetter) || TypeIgnored(property.Type)) return; PushBlock(BlockKind.Property, property); @@ -718,7 +719,7 @@ namespace CppSharp.Generators.CLI public void GenerateMethod(Method method) { - if (ASTUtils.CheckIgnoreMethod(method, Options)) return; + if (ASTUtils.CheckIgnoreMethod(method, Options) || FunctionIgnored(method)) return; PushBlock(BlockKind.Method, method); GenerateDeclarationCommon(method); @@ -789,7 +790,7 @@ namespace CppSharp.Generators.CLI public void GenerateFunction(Function function) { - if (!function.IsGenerated) + if (!function.IsGenerated || FunctionIgnored(function)) return; PushBlock(BlockKind.Function, function); @@ -806,6 +807,20 @@ namespace CppSharp.Generators.CLI PopBlock(); } + public static bool FunctionIgnored(Function function) + { + return TypeIgnored(function.ReturnType.Type) || + function.Parameters.Any(param => TypeIgnored(param.Type)); + } + + public static bool TypeIgnored(CppSharp.AST.Type type) + { + var desugared = type.Desugar(); + var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar(); + Class @class; + return finalType.TryGetClass(out @class) && @class.IsIncomplete; + } + public void GenerateEnum(Enumeration @enum) { if (!@enum.IsGenerated || @enum.IsIncomplete) diff --git a/src/Generator/Generators/CLI/CLISources.cs b/src/Generator/Generators/CLI/CLISources.cs index 463b3db6..08b86705 100644 --- a/src/Generator/Generators/CLI/CLISources.cs +++ b/src/Generator/Generators/CLI/CLISources.cs @@ -210,7 +210,7 @@ namespace CppSharp.Generators.CLI foreach (var method in @class.Methods.Where(m => @class == realOwner || !m.IsOperator)) { - if (ASTUtils.CheckIgnoreMethod(method, Options)) + if (ASTUtils.CheckIgnoreMethod(method, Options) || CLIHeaders.FunctionIgnored(method)) continue; // C++/CLI does not allow special member funtions for value types. @@ -237,7 +237,8 @@ namespace CppSharp.Generators.CLI } foreach (var property in @class.Properties.Where( - p => !ASTUtils.CheckIgnoreProperty(p) && !p.IsInRefTypeAndBackedByValueClassField())) + p => !ASTUtils.CheckIgnoreProperty(p) && !p.IsInRefTypeAndBackedByValueClassField() && + !CLIHeaders.TypeIgnored(p.Type))) GenerateProperty(property, realOwner); } @@ -686,7 +687,8 @@ namespace CppSharp.Generators.CLI } int paramIndex = 0; - foreach (var property in @class.Properties.Where( p => !ASTUtils.CheckIgnoreProperty(p))) + foreach (var property in @class.Properties.Where( + p => !ASTUtils.CheckIgnoreProperty(p) && !CLIHeaders.TypeIgnored(p.Type))) { if (property.Field == null) continue; @@ -742,6 +744,8 @@ namespace CppSharp.Generators.CLI public void GenerateMethod(Method method, Class @class) { + if (CLIHeaders.FunctionIgnored(method)) + return; PushBlock(BlockKind.Method, method); if (method.IsConstructor || method.IsDestructor || @@ -894,7 +898,7 @@ namespace CppSharp.Generators.CLI public void GenerateFunction(Function function, DeclarationContext @namespace) { - if (!function.IsGenerated) + if (!function.IsGenerated || CLIHeaders.FunctionIgnored(function)) return; GenerateDeclarationCommon(function); diff --git a/tests/CLI/CLI.cpp b/tests/CLI/CLI.cpp index 448d3de8..d528c7c8 100644 --- a/tests/CLI/CLI.cpp +++ b/tests/CLI/CLI.cpp @@ -13,4 +13,16 @@ std::string Date::testStdString(std::string s) void testFreeFunction() { +} + +struct IncompleteStruct {}; + +IncompleteStruct* createIncompleteStruct() +{ + return new IncompleteStruct(); +} + +DLL_API void useIncompleteStruct(IncompleteStruct * a) +{ + return; } \ No newline at end of file diff --git a/tests/CLI/CLI.h b/tests/CLI/CLI.h index ac317433..1077f4df 100644 --- a/tests/CLI/CLI.h +++ b/tests/CLI/CLI.h @@ -48,4 +48,11 @@ std::ostream& operator<<(std::ostream& os, const Date& dt) return os; } -DLL_API void testFreeFunction(); \ No newline at end of file +DLL_API void testFreeFunction(); + +struct CompleteIncompleteStruct; + +typedef struct IncompleteStruct IncompleteStruct; + +DLL_API IncompleteStruct* createIncompleteStruct(); +DLL_API void useIncompleteStruct(IncompleteStruct* a); \ No newline at end of file