Skip to content

Commit 0fd2f5e

Browse files
committed
Fix long/unsigned long C++ primitive
1 parent 28a294d commit 0fd2f5e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/CppAst/CppModelBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ private CppType GetCppTypeInternal(CXCursor cursor, CXType type, CXCursor parent
18161816
return CppPrimitiveType.UnsignedInt;
18171817

18181818
case CXTypeKind.CXType_ULong:
1819-
return type.SizeOf == 8 ? CppPrimitiveType.UnsignedLongLong : CppPrimitiveType.UnsignedInt;
1819+
return CppPrimitiveType.UnsignedLong;
18201820

18211821
case CXTypeKind.CXType_ULongLong:
18221822
return CppPrimitiveType.UnsignedLongLong;
@@ -1837,7 +1837,7 @@ private CppType GetCppTypeInternal(CXCursor cursor, CXType type, CXCursor parent
18371837
return CppPrimitiveType.Int;
18381838

18391839
case CXTypeKind.CXType_Long:
1840-
return CppPrimitiveType.Int;
1840+
return CppPrimitiveType.Long;
18411841

18421842
case CXTypeKind.CXType_LongLong:
18431843
return CppPrimitiveType.LongLong;

src/CppAst/CppPrimitiveKind.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public enum CppPrimitiveKind
3939
/// </summary>
4040
Int,
4141

42+
/// <summary>
43+
/// C++ `long`
44+
/// </summary>
45+
Long,
46+
4247
/// <summary>
4348
/// C++ `long long` (64bits)
4449
/// </summary>
@@ -59,6 +64,11 @@ public enum CppPrimitiveKind
5964
/// </summary>
6065
UnsignedInt,
6166

67+
/// <summary>
68+
/// C++ `unsigned long`
69+
/// </summary>
70+
UnsignedLong,
71+
6272
/// <summary>
6373
/// C++ `unsigned long long` (64 bits)
6474
/// </summary>

src/CppAst/CppPrimitiveType.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public sealed class CppPrimitiveType : CppType
4141
/// </summary>
4242
public static readonly CppPrimitiveType Int = new CppPrimitiveType(CppPrimitiveKind.Int);
4343

44+
/// <summary>
45+
/// Singleton instance of the `long` type.
46+
/// </summary>
47+
public static readonly CppPrimitiveType Long = new CppPrimitiveType(CppPrimitiveKind.Long);
48+
4449
/// <summary>
4550
/// Singleton instance of the `long long` type.
4651
/// </summary>
@@ -61,6 +66,11 @@ public sealed class CppPrimitiveType : CppType
6166
/// </summary>
6267
public static readonly CppPrimitiveType UnsignedInt = new CppPrimitiveType(CppPrimitiveKind.UnsignedInt);
6368

69+
/// <summary>
70+
/// Singleton instance of the `unsigned long` type.
71+
/// </summary>
72+
public static readonly CppPrimitiveType UnsignedLong = new CppPrimitiveType(CppPrimitiveKind.UnsignedLong);
73+
6474
/// <summary>
6575
/// Singleton instance of the `unsigned long long` type.
6676
/// </summary>
@@ -120,6 +130,10 @@ private void UpdateSize(out int sizeOf)
120130
case CppPrimitiveKind.Int:
121131
sizeOf = 4;
122132
break;
133+
case CppPrimitiveKind.Long:
134+
case CppPrimitiveKind.UnsignedLong:
135+
sizeOf = 4; // This is incorrect
136+
break;
123137
case CppPrimitiveKind.LongLong:
124138
sizeOf = 8;
125139
break;

0 commit comments

Comments
 (0)