Browse Source

Fixed the internals of templates specialising arrays by simplifying the names.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/696/head
Dimitar Dobrev 9 years ago
parent
commit
aabe7409d1
  1. 3
      src/Generator/Driver.cs
  2. 60
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 2
      src/Generator/Types/Std/Stdlib.cs
  5. 4
      tests/CSharp/CSharp.Tests.cs
  6. 1
      tests/CSharp/CSharpTemplates.h

3
src/Generator/Driver.cs

@ -404,11 +404,12 @@ namespace CppSharp
foreach (var template in output.Templates) foreach (var template in output.Templates)
{ {
var fileRelativePath = string.Format("{0}.{1}", fileBase, template.FileExtension); var fileRelativePath = string.Format("{0}.{1}", fileBase, template.FileExtension);
Diagnostics.Message("Generated '{0}'", fileRelativePath);
var file = Path.Combine(outputPath, fileRelativePath); var file = Path.Combine(outputPath, fileRelativePath);
File.WriteAllText(file, template.Generate()); File.WriteAllText(file, template.Generate());
output.TranslationUnit.Module.CodeFiles.Add(file); output.TranslationUnit.Module.CodeFiles.Add(file);
Diagnostics.Message("Generated '{0}'", fileRelativePath);
} }
} }
} }

60
src/Generator/Generators/CSharp/CSharpSources.cs

@ -75,61 +75,23 @@ namespace CppSharp.Generators.CSharp
public static string GetSuffixForInternal(ClassTemplateSpecialization specialization, public static string GetSuffixForInternal(ClassTemplateSpecialization specialization,
CSharpTypePrinter typePrinter, bool nested = false) CSharpTypePrinter typePrinter, bool nested = false)
{ {
if (!nested && if (specialization.TemplatedDecl.TemplatedClass.Fields.All(
specialization.TemplatedDecl.TemplatedClass.Fields.All(
f => !(f.Type.Desugar() is TemplateParameterType))) f => !(f.Type.Desugar() is TemplateParameterType)))
return string.Empty; return string.Empty;
if (!nested && if (specialization.Arguments.All(
specialization.Arguments.All(
a => a.Type.Type != null && a.Type.Type.IsAddress())) a => a.Type.Type != null && a.Type.Type.IsAddress()))
return "_Ptr"; return "_Ptr";
// we don't want internals in the names of internals :) var suffixBuilder = new StringBuilder(specialization.USR);
if (!nested) for (int i = 0; i < suffixBuilder.Length; i++)
{ if (!char.IsLetterOrDigit(suffixBuilder[i]))
typePrinter.PushContext(CSharpTypePrinterContextKind.Managed); suffixBuilder[i] = '_';
typePrinter.PushMarshalKind(CSharpMarshalKind.Unknown); const int maxCSharpIdentifierLength = 480;
} if (suffixBuilder.Length > maxCSharpIdentifierLength)
var cppTypePrinter = new CppTypePrinter(false) { PrintScopeKind = CppTypePrintScopeKind.Qualified }; return suffixBuilder.Remove(maxCSharpIdentifierLength,
CSharpTypePrinter.AppendGlobal = false; suffixBuilder.Length - maxCSharpIdentifierLength).ToString();
var suffix = new StringBuilder(); return suffixBuilder.ToString();
foreach (var argType in from argType in specialization.Arguments
where argType.Type.Type != null
select argType.Type.Type)
{
suffix.Append('_');
ClassTemplateSpecialization nestedSpecialization;
if (argType.TryGetDeclaration(out nestedSpecialization))
{
suffix.Append(typePrinter.GetNestedQualifiedName(nestedSpecialization));
suffix.Append(GetSuffixForInternal(nestedSpecialization, typePrinter, true));
CSharpTypePrinter.AppendGlobal = false;
continue;
}
Class @class;
if (argType.TryGetClass(out @class))
{
nestedSpecialization = @class.Namespace as ClassTemplateSpecialization;
if (nestedSpecialization != null)
{
suffix.Append(typePrinter.GetNestedQualifiedName(nestedSpecialization));
suffix.Append(GetSuffixForInternal(nestedSpecialization, typePrinter, true));
CSharpTypePrinter.AppendGlobal = false;
suffix.Append('_');
suffix.Append(@class.Name);
continue;
}
}
suffix.Append(argType.Visit(cppTypePrinter));
}
if (!nested)
{
typePrinter.PopContext();
typePrinter.PopMarshalKind();
}
CSharpTypePrinter.AppendGlobal = true;
return FormatTypesStringForIdentifier(suffix);
} }
} }

2
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -688,7 +688,7 @@ namespace CppSharp.Generators.CSharp
ctx = ctx.Namespace; ctx = ctx.Namespace;
} }
if (!ctx.TranslationUnit.IsSystemHeader && if (!ctx.TranslationUnit.IsSystemHeader && ctx.TranslationUnit.IsValid &&
!string.IsNullOrWhiteSpace(ctx.TranslationUnit.Module.OutputNamespace)) !string.IsNullOrWhiteSpace(ctx.TranslationUnit.Module.OutputNamespace))
names.Add(ctx.TranslationUnit.Module.OutputNamespace); names.Add(ctx.TranslationUnit.Module.OutputNamespace);

2
src/Generator/Types/Std/Stdlib.cs

@ -8,7 +8,7 @@ using CppSharp.Generators.CSharp;
namespace CppSharp.Types.Std namespace CppSharp.Types.Std
{ {
[TypeMap("va_list", GeneratorKind = GeneratorKind.CLI)] [TypeMap("va_list")]
public class VaList : TypeMap public class VaList : TypeMap
{ {
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(CLITypePrinterContext ctx)

4
tests/CSharp/CSharp.Tests.cs

@ -536,11 +536,11 @@ public unsafe class CSharpTests : GeneratorTestFixture
foreach (var internalType in new[] foreach (var internalType in new[]
{ {
typeof(CSharp.IndependentFields.Internal), typeof(CSharp.IndependentFields.Internal),
typeof(CSharp.DependentValueFields.Internal_bool), typeof(CSharp.DependentValueFields.Internalc__S_DependentValueFields__b),
//typeof(CSharp.DependentValueFields.Internal_float), //typeof(CSharp.DependentValueFields.Internal_float),
typeof(CSharp.DependentPointerFields.Internal), typeof(CSharp.DependentPointerFields.Internal),
//typeof(CSharp.DependentValueFields.Internal_Ptr), //typeof(CSharp.DependentValueFields.Internal_Ptr),
typeof(CSharp.HasDefaultTemplateArgument.Internal_int_IndependentFields_int) typeof(CSharp.HasDefaultTemplateArgument.Internalc__S_HasDefaultTemplateArgument__I___S_IndependentFields__I)
}) })
{ {
var independentFields = internalType.GetFields(); var independentFields = internalType.GetFields();

1
tests/CSharp/CSharpTemplates.h

@ -71,6 +71,7 @@ private:
NestedTemplate<int> nestedTemplate; NestedTemplate<int> nestedTemplate;
DependentValueFields<DependentValueFields<int*>> nestedDependentPointer1; DependentValueFields<DependentValueFields<int*>> nestedDependentPointer1;
DependentValueFields<DependentValueFields<char*>> nestedDependentPointer2; DependentValueFields<DependentValueFields<char*>> nestedDependentPointer2;
DependentValueFields<char[3]> dependentFieldArray;
void completeSpecializationInParameter(DependentValueFields<float> p1, void completeSpecializationInParameter(DependentValueFields<float> p1,
DependentValueFields<int*> p2, DependentValueFields<int*> p2,
DependentValueFields<float*> p3); DependentValueFields<float*> p3);

Loading…
Cancel
Save