Debian Codegraph @

gcc/d/dmd/root/dcompat.h

raw
1
2 /* Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved
3 * written by Walter Bright
4 * https://www.digitalmars.com
5 * Distributed under the Boost Software License, Version 1.0.
6 * https://www.boost.org/LICENSE_1_0.txt
7 * https://github.com/dlang/dmd/blob/master/src/dmd/root/dcompat.h
8 */
9
10 #pragma once
11
12 #include "dsystem.h"
13
14 /// Represents a D [ ] array
15 template<typename T>
16 struct DArray
17 {
18 size_t length;
19 T *ptr;
20
21 DArray() : length(0), ptr(nullptr) { }
22
23 DArray(size_t length_in, T *ptr_in)
24 : length(length_in), ptr(ptr_in) { }
25 };
26
27 struct DString : public DArray<const char>
28 {
29 DString() : DArray<const char>() { }
30
31 DString(const char *ptr)
32 : DArray<const char>(ptr ? strlen(ptr) : 0, ptr) { }
33
34 DString(size_t length, const char *ptr)
35 : DArray<const char>(length, ptr) { }
36 };
37
38 /// Corresponding C++ type that maps to D size_t
39 #if __APPLE__ && (__i386__ || __ppc__)
40 // size_t is 'unsigned long', which makes it mangle differently than D's 'uint'
41 typedef unsigned d_size_t;
42 #elif MARS && DMD_VERSION >= 2079 && DMD_VERSION <= 2081 && \
43 __APPLE__ && __SIZEOF_SIZE_T__ == 8
44 // DMD versions between 2.079 and 2.081 mapped D ulong to uint64_t on OS X.
45 typedef uint64_t d_size_t;
46 #elif defined(__OpenBSD__) && !defined(__LP64__)
47 // size_t is 'unsigned long', which makes it mangle differently than D's 'uint'
48 typedef unsigned d_size_t;
49 #else
50 typedef size_t d_size_t;
51 #endif
52
53 /// Corresponding C++ type that maps to D bool
54 #if __APPLE__ && __ppc__
55 // bool is defined as an 'int', which does not match same size as D
56 typedef uint8_t d_bool;
57 #else
58 typedef bool d_bool;
59 #endif