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

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

@ -75,61 +75,23 @@ namespace CppSharp.Generators.CSharp @@ -75,61 +75,23 @@ namespace CppSharp.Generators.CSharp
public static string GetSuffixForInternal(ClassTemplateSpecialization specialization,
CSharpTypePrinter typePrinter, bool nested = false)
{
if (!nested &&
specialization.TemplatedDecl.TemplatedClass.Fields.All(
f => !(f.Type.Desugar() is TemplateParameterType)))
if (specialization.TemplatedDecl.TemplatedClass.Fields.All(
f => !(f.Type.Desugar() is TemplateParameterType)))
return string.Empty;
if (!nested &&
specialization.Arguments.All(
if (specialization.Arguments.All(
a => a.Type.Type != null && a.Type.Type.IsAddress()))
return "_Ptr";
// we don't want internals in the names of internals :)
if (!nested)
{
typePrinter.PushContext(CSharpTypePrinterContextKind.Managed);
typePrinter.PushMarshalKind(CSharpMarshalKind.Unknown);
}
var cppTypePrinter = new CppTypePrinter(false) { PrintScopeKind = CppTypePrintScopeKind.Qualified };
CSharpTypePrinter.AppendGlobal = false;
var suffix = new StringBuilder();
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);
var suffixBuilder = new StringBuilder(specialization.USR);
for (int i = 0; i < suffixBuilder.Length; i++)
if (!char.IsLetterOrDigit(suffixBuilder[i]))
suffixBuilder[i] = '_';
const int maxCSharpIdentifierLength = 480;
if (suffixBuilder.Length > maxCSharpIdentifierLength)
return suffixBuilder.Remove(maxCSharpIdentifierLength,
suffixBuilder.Length - maxCSharpIdentifierLength).ToString();
return suffixBuilder.ToString();
}
}

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

@ -688,7 +688,7 @@ namespace CppSharp.Generators.CSharp @@ -688,7 +688,7 @@ namespace CppSharp.Generators.CSharp
ctx = ctx.Namespace;
}
if (!ctx.TranslationUnit.IsSystemHeader &&
if (!ctx.TranslationUnit.IsSystemHeader && ctx.TranslationUnit.IsValid &&
!string.IsNullOrWhiteSpace(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; @@ -8,7 +8,7 @@ using CppSharp.Generators.CSharp;
namespace CppSharp.Types.Std
{
[TypeMap("va_list", GeneratorKind = GeneratorKind.CLI)]
[TypeMap("va_list")]
public class VaList : TypeMap
{
public override string CLISignature(CLITypePrinterContext ctx)

4
tests/CSharp/CSharp.Tests.cs

@ -536,11 +536,11 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -536,11 +536,11 @@ public unsafe class CSharpTests : GeneratorTestFixture
foreach (var internalType in new[]
{
typeof(CSharp.IndependentFields.Internal),
typeof(CSharp.DependentValueFields.Internal_bool),
typeof(CSharp.DependentValueFields.Internalc__S_DependentValueFields__b),
//typeof(CSharp.DependentValueFields.Internal_float),
typeof(CSharp.DependentPointerFields.Internal),
//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();

1
tests/CSharp/CSharpTemplates.h

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

Loading…
Cancel
Save