Skip to content

Commit

Permalink
Fix #288: Missing __u/int128 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Nov 13, 2023
1 parent d96406b commit a7212f8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Add support for FreeBSD
* Drop support for Windows 32 bit
* [Issue 287](https://github.com/jacob-carlborg/dstep/issues/287): Add support for adding public imports
* [Issue 288](https://github.com/jacob-carlborg/dstep/issues/288): Missing `__u/int128` support

### Bugs Fixed

Expand Down
18 changes: 15 additions & 3 deletions dstep/translator/Type.d
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ package string reduceAlias(Type type)
tuple("u8", CXTypeKind.uChar): "ubyte",
tuple("u16", CXTypeKind.uShort): "ushort",
tuple("u32", CXTypeKind.uInt): "uint",
tuple("u64", CXTypeKind.uLongLong): "ulong"
tuple("u64", CXTypeKind.uLongLong): "ulong",
tuple("__int128_t", CXTypeKind.int128): "Cent",

// There's no unsigned 128 bit integer in D. Use signed instead.
tuple("__uint128_t", CXTypeKind.uInt128): "Cent"
];

auto canonical = type.canonical;
Expand Down Expand Up @@ -580,7 +584,11 @@ string translateType (Context context, CXTypeKind kind, bool rewriteIdToObjcObje
return "c_ulong";

case uLongLong: return "ulong";
case uInt128: return "<unimplemented>";
case uInt128:
context.includeHandler.addImport("core.int128");
// There's no unsigned 128 bit integer in D. Use signed instead.
return "Cent";

case charS: return "char";
case sChar: return "byte";
case wChar: return "wchar";
Expand All @@ -592,7 +600,11 @@ string translateType (Context context, CXTypeKind kind, bool rewriteIdToObjcObje
return "c_long";

case longLong: return "long";
case int128: return "<unimplemented>";

case int128:
context.includeHandler.addImport("core.int128");
return "Cent";

case float_: return "float";
case double_: return "double";
case longDouble: return "real";
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/issues/issue288_int128.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright: Copyright (c) 2023 Jacob Carlborg. All rights reserved.
* Authors: Jacob Carlborg
* Version: Initial created: November 10, 2023
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
*/

import Common;
import dstep.translator.Options;

unittest
{
assertTranslates(
q"C
__int128 a();
unsigned __int128 b();
__int128_t c();
__uint128_t d();
typedef __uint128_t tb_uint128_t;
C",

q"D
import core.int128;
extern (C):
Cent a ();
Cent b ();
Cent c ();
Cent d ();
alias tb_uint128_t = Cent;
D", Options(reduceAliases: true));
}

0 comments on commit a7212f8

Please sign in to comment.