Browse Source

Fix CppTypePrinter to check for typemaps for tag types and keep track of them.

pull/1316/merge
João Matos 6 years ago committed by João Matos
parent
commit
a6fc9fa8e4
  1. 16
      src/Generator/Generators/C/CppTypePrinter.cs
  2. 2
      src/Generator/Generators/TypePrinter.cs
  3. 1
      src/Generator/Types/TypeMapDatabase.cs

16
src/Generator/Generators/C/CppTypePrinter.cs

@ -35,10 +35,21 @@ namespace CppSharp.Generators.C @@ -35,10 +35,21 @@ namespace CppSharp.Generators.C
public TypeMapDatabase TypeMapDatabase => Context.TypeMaps;
public DriverOptions Options => Context.Options;
public bool ResolveTypeMaps { get; set; } = true;
public bool ResolveTypedefs { get; set; }
public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
public override TypePrinterResult VisitTagType(TagType tag,
TypeQualifiers quals)
{
TypeMap typeMap;
if (ResolveTypeMaps && TypeMapDatabase.FindTypeMap(tag, out typeMap) &&
!typeMap.IsIgnored)
{
var typePrinterContext = new TypePrinterContext { Type = tag };
var type = typeMap.CppSignatureType(typePrinterContext).ToString();
return new TypePrinterResult(type) { TypeMap = typeMap };
}
var qual = GetStringQuals(quals);
return $"{qual}{tag.Declaration.Visit(this)}";
}
@ -88,6 +99,9 @@ namespace CppSharp.Generators.C @@ -88,6 +99,9 @@ namespace CppSharp.Generators.C
TypeQualifiers quals)
{
var pointeeType = pointer.Pointee.Visit(this, pointer.QualifiedPointee.Qualifiers);
if (pointeeType.TypeMap != null)
return pointeeType;
var mod = PrintTypeModifiers ? ConvertModifierToString(pointer.Modifier) : string.Empty;
pointeeType.NamePrefix.Append(mod);

2
src/Generator/Generators/TypePrinter.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using CppSharp.AST;
using CppSharp.Types;
using System;
using System.Collections.Generic;
using System.Text;
@ -11,6 +12,7 @@ namespace CppSharp.Generators @@ -11,6 +12,7 @@ namespace CppSharp.Generators
public string Name { get; set; } = string.Empty;
public StringBuilder NamePrefix { get; set; } = new StringBuilder();
public StringBuilder NameSuffix { get; set; } = new StringBuilder();
public TypeMap TypeMap { get; set; }
public TypePrinterResult(string type = "", string nameSuffix = "")
{

1
src/Generator/Types/TypeMapDatabase.cs

@ -91,6 +91,7 @@ namespace CppSharp.Types @@ -91,6 +91,7 @@ namespace CppSharp.Types
var typePrinter = new CppTypePrinter(Context)
{
ResolveTypeMaps = false,
PrintTypeQualifiers = printExtra,
PrintTypeModifiers = printExtra,
PrintLogicalNames = true

Loading…
Cancel
Save