Browse Source

Fixed the generated C# when std::string is only used as a parameter.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/859/head
Dimitar Dobrev 8 years ago
parent
commit
91bcc7c8a2
  1. 2
      src/Generator/Passes/CheckIgnoredDecls.cs
  2. 21
      src/Generator/Passes/IgnoreSystemDeclarationsPass.cs
  3. 3
      src/Generator/Passes/StripUnusedSystemTypesPass.cs
  4. 4
      tests/CSharp/CSharp.cpp
  5. 5
      tests/CSharp/CSharp.h

2
src/Generator/Passes/CheckIgnoredDecls.cs

@ -71,7 +71,7 @@ namespace CppSharp.Passes @@ -71,7 +71,7 @@ namespace CppSharp.Passes
return true;
}
if (decl.IsDependent)
if (decl.IsDependent && !decl.IsExplicitlyGenerated)
{
decl.GenerationKind = decl is Field ? GenerationKind.Internal : GenerationKind.None;
Diagnostics.Debug("Decl '{0}' was ignored due to dependent context",

21
src/Generator/Passes/IgnoreSystemDeclarationsPass.cs

@ -61,25 +61,8 @@ namespace CppSharp.Passes @@ -61,25 +61,8 @@ namespace CppSharp.Passes
m.Parameters[0].Type.Desugar().IsPointerToPrimitiveType(PrimitiveType.Char) &&
!m.Parameters[1].Type.Desugar().IsPrimitiveType());
ctor.GenerationKind = GenerationKind.Generate;
foreach (var parameter in ctor.Parameters)
parameter.DefaultArgument = null;
}
foreach (var ctor in @class.Methods.Where(m =>
{
if (!m.IsConstructor || m.Parameters.Count != 2)
return false;
for (int i = 0; i < m.Parameters.Count; i++)
{
var type = m.Parameters[i].Type.Desugar();
var templateParameter = (type.GetFinalPointee() ?? type) as TemplateParameterType;
if (templateParameter == null ||
@class.TemplateParameters.All(t => t.Name != templateParameter.Parameter.Name))
return false;
}
return true;
}))
{
ctor.GenerationKind = GenerationKind.Generate;
ctor.InstantiatedFrom.GenerationKind = GenerationKind.Generate;
ctor.InstantiatedFrom.Namespace.GenerationKind = GenerationKind.Generate;
foreach (var parameter in ctor.Parameters)
parameter.DefaultArgument = null;
}

3
src/Generator/Passes/StripUnusedSystemTypesPass.cs

@ -94,7 +94,8 @@ namespace CppSharp.Passes @@ -94,7 +94,8 @@ namespace CppSharp.Passes
var nestedContext = declaration as Namespace;
if (nestedContext != null)
RemoveUnusedStdTypes(nestedContext);
else if (!this.usedStdTypes.Contains(declaration))
else if (!this.usedStdTypes.Contains(declaration) &&
!declaration.IsExplicitlyGenerated)
context.Declarations.RemoveAt(i);
}
}

4
tests/CSharp/CSharp.cpp

@ -1350,3 +1350,7 @@ DLL_API int useDuplicateDeclaredStruct(DuplicateDeclaredStruct* s) @@ -1350,3 +1350,7 @@ DLL_API int useDuplicateDeclaredStruct(DuplicateDeclaredStruct* s)
{
return s->i;
}
void useStdStringJustAsParameter(std::string s)
{
}

5
tests/CSharp/CSharp.h

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
#include <cstdint>
#include <vector>
#include <limits>
#include <string>
#include "AnotherUnit.h"
class DLL_API Foo
@ -1205,4 +1206,6 @@ int TestIndexedProperties::operator[](const int& key) @@ -1205,4 +1206,6 @@ int TestIndexedProperties::operator[](const int& key)
return key;
}
extern const ComplexArrayElement ArrayOfVariableSize[];
extern const ComplexArrayElement ArrayOfVariableSize[];
void useStdStringJustAsParameter(std::string s);

Loading…
Cancel
Save