Skip to content

Commit

Permalink
Fix long/unsigned long C++ primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed May 12, 2024
1 parent 28a294d commit 0fd2f5e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/CppAst/CppModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ private CppType GetCppTypeInternal(CXCursor cursor, CXType type, CXCursor parent
return CppPrimitiveType.UnsignedInt;

case CXTypeKind.CXType_ULong:
return type.SizeOf == 8 ? CppPrimitiveType.UnsignedLongLong : CppPrimitiveType.UnsignedInt;
return CppPrimitiveType.UnsignedLong;

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

case CXTypeKind.CXType_Long:
return CppPrimitiveType.Int;
return CppPrimitiveType.Long;

case CXTypeKind.CXType_LongLong:
return CppPrimitiveType.LongLong;
Expand Down
10 changes: 10 additions & 0 deletions src/CppAst/CppPrimitiveKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public enum CppPrimitiveKind
/// </summary>
Int,

/// <summary>
/// C++ `long`
/// </summary>
Long,

/// <summary>
/// C++ `long long` (64bits)
/// </summary>
Expand All @@ -59,6 +64,11 @@ public enum CppPrimitiveKind
/// </summary>
UnsignedInt,

/// <summary>
/// C++ `unsigned long`
/// </summary>
UnsignedLong,

/// <summary>
/// C++ `unsigned long long` (64 bits)
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions src/CppAst/CppPrimitiveType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public sealed class CppPrimitiveType : CppType
/// </summary>
public static readonly CppPrimitiveType Int = new CppPrimitiveType(CppPrimitiveKind.Int);

/// <summary>
/// Singleton instance of the `long` type.
/// </summary>
public static readonly CppPrimitiveType Long = new CppPrimitiveType(CppPrimitiveKind.Long);

/// <summary>
/// Singleton instance of the `long long` type.
/// </summary>
Expand All @@ -61,6 +66,11 @@ public sealed class CppPrimitiveType : CppType
/// </summary>
public static readonly CppPrimitiveType UnsignedInt = new CppPrimitiveType(CppPrimitiveKind.UnsignedInt);

/// <summary>
/// Singleton instance of the `unsigned long` type.
/// </summary>
public static readonly CppPrimitiveType UnsignedLong = new CppPrimitiveType(CppPrimitiveKind.UnsignedLong);

/// <summary>
/// Singleton instance of the `unsigned long long` type.
/// </summary>
Expand Down Expand Up @@ -120,6 +130,10 @@ private void UpdateSize(out int sizeOf)
case CppPrimitiveKind.Int:
sizeOf = 4;
break;
case CppPrimitiveKind.Long:
case CppPrimitiveKind.UnsignedLong:
sizeOf = 4; // This is incorrect
break;
case CppPrimitiveKind.LongLong:
sizeOf = 8;
break;
Expand Down

0 comments on commit 0fd2f5e

Please sign in to comment.