Browse Source

Implement proper array printing with C array name suffix notation.

pull/1305/head
João Matos 6 years ago committed by João Matos
parent
commit
29f1cc2901
  1. 18
      src/Generator/Generators/C/CppTypePrinter.cs

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

@ -39,19 +39,29 @@ namespace CppSharp.Generators.C
public override TypePrinterResult VisitArrayType(ArrayType array, TypeQualifiers quals) public override TypePrinterResult VisitArrayType(ArrayType array, TypeQualifiers quals)
{ {
var typeName = array.Type.Visit(this); var arraySuffix = string.Empty;
switch (array.SizeType) switch (array.SizeType)
{ {
case ArrayType.ArraySize.Constant: case ArrayType.ArraySize.Constant:
return $"{typeName}[{array.Size}]"; arraySuffix = $"[{array.Size}]";
break;
case ArrayType.ArraySize.Variable: case ArrayType.ArraySize.Variable:
case ArrayType.ArraySize.Dependent: case ArrayType.ArraySize.Dependent:
case ArrayType.ArraySize.Incomplete: case ArrayType.ArraySize.Incomplete:
return $"{typeName}{(PrintVariableArrayAsPointers ? "*" : "[]")}"; arraySuffix = $"{(PrintVariableArrayAsPointers ? "*" : "[]")}";
break;
default:
throw new NotImplementedException();
} }
throw new NotSupportedException(); var result = new TypePrinterResult
{
Type = array.Type.Visit(this),
NameSuffix = new System.Text.StringBuilder(arraySuffix)
};
return result;
} }
private static string ConvertModifierToString(PointerType.TypeModifier modifier) private static string ConvertModifierToString(PointerType.TypeModifier modifier)

Loading…
Cancel
Save