Browse Source

Completely ignore incomplete classes in C++/CLI (#823)

Signed-off-by: realvictorprm <mueller.vpr@gmail.com>
pull/824/head
Victor Peter Rouven Müller 8 years ago committed by Dimitar Dobrev
parent
commit
0a61baa4b6
  1. 27
      src/Generator/Generators/CLI/CLIHeaders.cs
  2. 12
      src/Generator/Generators/CLI/CLISources.cs
  3. 12
      tests/CLI/CLI.cpp
  4. 9
      tests/CLI/CLI.h

27
src/Generator/Generators/CLI/CLIHeaders.cs

@ -394,7 +394,7 @@ namespace CppSharp.Generators.CLI
foreach (var ctor in @class.Constructors) foreach (var ctor in @class.Constructors)
{ {
if (ASTUtils.CheckIgnoreMethod(ctor, Options)) if (ASTUtils.CheckIgnoreMethod(ctor, Options) || FunctionIgnored(ctor))
continue; continue;
// C++/CLI does not allow special member funtions for value types. // C++/CLI does not allow special member funtions for value types.
@ -526,7 +526,7 @@ namespace CppSharp.Generators.CLI
var staticMethods = new List<Method>(); var staticMethods = new List<Method>();
foreach (var method in methods) foreach (var method in methods)
{ {
if (ASTUtils.CheckIgnoreMethod(method, Options)) if (ASTUtils.CheckIgnoreMethod(method, Options) || FunctionIgnored(method))
continue; continue;
if (method.IsConstructor) if (method.IsConstructor)
@ -622,7 +622,8 @@ namespace CppSharp.Generators.CLI
} }
PushIndent(); 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()) if (prop.IsInRefTypeAndBackedByValueClassField())
{ {
@ -657,7 +658,7 @@ namespace CppSharp.Generators.CLI
public void GenerateProperty(Property property) public void GenerateProperty(Property property)
{ {
if (!(property.HasGetter || property.HasSetter)) if (!(property.HasGetter || property.HasSetter) || TypeIgnored(property.Type))
return; return;
PushBlock(BlockKind.Property, property); PushBlock(BlockKind.Property, property);
@ -718,7 +719,7 @@ namespace CppSharp.Generators.CLI
public void GenerateMethod(Method method) public void GenerateMethod(Method method)
{ {
if (ASTUtils.CheckIgnoreMethod(method, Options)) return; if (ASTUtils.CheckIgnoreMethod(method, Options) || FunctionIgnored(method)) return;
PushBlock(BlockKind.Method, method); PushBlock(BlockKind.Method, method);
GenerateDeclarationCommon(method); GenerateDeclarationCommon(method);
@ -789,7 +790,7 @@ namespace CppSharp.Generators.CLI
public void GenerateFunction(Function function) public void GenerateFunction(Function function)
{ {
if (!function.IsGenerated) if (!function.IsGenerated || FunctionIgnored(function))
return; return;
PushBlock(BlockKind.Function, function); PushBlock(BlockKind.Function, function);
@ -806,6 +807,20 @@ namespace CppSharp.Generators.CLI
PopBlock(); 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) public void GenerateEnum(Enumeration @enum)
{ {
if (!@enum.IsGenerated || @enum.IsIncomplete) if (!@enum.IsGenerated || @enum.IsIncomplete)

12
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)) 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; continue;
// C++/CLI does not allow special member funtions for value types. // 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( 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); GenerateProperty(property, realOwner);
} }
@ -686,7 +687,8 @@ namespace CppSharp.Generators.CLI
} }
int paramIndex = 0; 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) if (property.Field == null)
continue; continue;
@ -742,6 +744,8 @@ namespace CppSharp.Generators.CLI
public void GenerateMethod(Method method, Class @class) public void GenerateMethod(Method method, Class @class)
{ {
if (CLIHeaders.FunctionIgnored(method))
return;
PushBlock(BlockKind.Method, method); PushBlock(BlockKind.Method, method);
if (method.IsConstructor || method.IsDestructor || if (method.IsConstructor || method.IsDestructor ||
@ -894,7 +898,7 @@ namespace CppSharp.Generators.CLI
public void GenerateFunction(Function function, DeclarationContext @namespace) public void GenerateFunction(Function function, DeclarationContext @namespace)
{ {
if (!function.IsGenerated) if (!function.IsGenerated || CLIHeaders.FunctionIgnored(function))
return; return;
GenerateDeclarationCommon(function); GenerateDeclarationCommon(function);

12
tests/CLI/CLI.cpp

@ -13,4 +13,16 @@ std::string Date::testStdString(std::string s)
void testFreeFunction() void testFreeFunction()
{ {
}
struct IncompleteStruct {};
IncompleteStruct* createIncompleteStruct()
{
return new IncompleteStruct();
}
DLL_API void useIncompleteStruct(IncompleteStruct * a)
{
return;
} }

9
tests/CLI/CLI.h

@ -48,4 +48,11 @@ std::ostream& operator<<(std::ostream& os, const Date& dt)
return os; return os;
} }
DLL_API void testFreeFunction(); DLL_API void testFreeFunction();
struct CompleteIncompleteStruct;
typedef struct IncompleteStruct IncompleteStruct;
DLL_API IncompleteStruct* createIncompleteStruct();
DLL_API void useIncompleteStruct(IncompleteStruct* a);
Loading…
Cancel
Save