-
-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathTypeHelper.cs
68 lines (64 loc) · 2.54 KB
/
TypeHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using CppSharp.AST;
using Type = CppSharp.AST.Type;
namespace FFmpeg.AutoGen.CppSharpUnsafeGenerator.Processing;
internal static class TypeHelper
{
public static string GetTypeName(Type type)
{
return type switch
{
PointerType x => $"{GetTypeName(x.QualifiedPointee.Type)}*",
BuiltinType x => GetTypeName(x.Type),
TypedefType x => GetTypeName(x),
TagType x => x.Declaration.Name,
ArrayType x => $"{GetTypeName(x.Type)}[]",
AttributedType => GetTypeName(PrimitiveType.Void),
_ => throw new NotSupportedException()
};
}
private static string GetTypeName(TypedefType type)
{
return type.Declaration.Type switch
{
BuiltinType x => GetTypeName(x),
PointerType x => GetTypeName(x),
_ => type.Declaration.Name
};
}
private static string GetTypeName(PrimitiveType type)
{
return type switch
{
PrimitiveType.Void => "void",
PrimitiveType.Bool => "bool",
PrimitiveType.Char => "byte",
PrimitiveType.SChar => "sbyte",
PrimitiveType.UChar => "byte",
PrimitiveType.Short => "short",
PrimitiveType.UShort => "ushort",
PrimitiveType.Int => "int",
PrimitiveType.UInt => "uint",
PrimitiveType.Long => "long",
PrimitiveType.ULong => "ulong",
PrimitiveType.LongLong => "long",
PrimitiveType.ULongLong => "ulong",
PrimitiveType.Float => "float",
PrimitiveType.Double => "double",
PrimitiveType.Decimal => "decimal",
PrimitiveType.IntPtr => "IntPtr",
PrimitiveType.UIntPtr => "UIntPtr",
PrimitiveType.Null => throw new NotSupportedException(),
PrimitiveType.WideChar => throw new NotSupportedException(),
PrimitiveType.Char16 => throw new NotSupportedException(),
PrimitiveType.Char32 => throw new NotSupportedException(),
PrimitiveType.Int128 => throw new NotSupportedException(),
PrimitiveType.UInt128 => throw new NotSupportedException(),
PrimitiveType.Half => throw new NotSupportedException(),
PrimitiveType.LongDouble => "LongDouble",
PrimitiveType.Float128 => throw new NotSupportedException(),
PrimitiveType.String => throw new NotSupportedException(),
_ => throw new ArgumentOutOfRangeException(nameof(type))
};
}
}