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 @@ -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 @@ -526,7 +526,7 @@ namespace CppSharp.Generators.CLI
var staticMethods = new List<Method>();
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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)

12
src/Generator/Generators/CLI/CLISources.cs

@ -210,7 +210,7 @@ namespace CppSharp.Generators.CLI @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

12
tests/CLI/CLI.cpp

@ -13,4 +13,16 @@ std::string Date::testStdString(std::string s) @@ -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;
}

9
tests/CLI/CLI.h

@ -48,4 +48,11 @@ std::ostream& operator<<(std::ostream& os, const Date& dt) @@ -48,4 +48,11 @@ std::ostream& operator<<(std::ostream& os, const Date& dt)
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