Permalink
Browse files

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

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jun 7, 2017
1 parent d487088 commit 91bcc7c8a2a2f8b7bff06c18e5d647586d378a91
@@ -71,7 +71,7 @@ public override bool VisitDeclaration(Declaration decl)
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",
@@ -61,25 +61,8 @@ public override bool VisitClassDecl(Class @class)
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;
}
@@ -94,7 +94,8 @@ private void RemoveUnusedStdTypes(DeclarationContext context)
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);
}
}
@@ -1350,3 +1350,7 @@ DLL_API int useDuplicateDeclaredStruct(DuplicateDeclaredStruct* s)
{
return s->i;
}
void useStdStringJustAsParameter(std::string s)
{
}
@@ -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)
return key;
}
extern const ComplexArrayElement ArrayOfVariableSize[];
extern const ComplexArrayElement ArrayOfVariableSize[];
void useStdStringJustAsParameter(std::string s);

0 comments on commit 91bcc7c

Please sign in to comment.