Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit bd645f6

Browse files
authored
Merge pull request #2303 from Geod24/std-cpp
Refactor core.stdcpp to use extern(C++, string) and CppRuntime_* versions merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents 467d5df + 9a0dd5f commit bd645f6

File tree

2 files changed

+161
-167
lines changed

2 files changed

+161
-167
lines changed

src/core/stdcpp/exception.d

Lines changed: 64 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,95 +11,90 @@
1111

1212
module core.stdcpp.exception;
1313

14-
version (CRuntime_DigitalMars)
14+
extern (C++, "std"):
15+
16+
version (CppRuntime_DigitalMars)
1517
{
1618
import core.stdcpp.typeinfo;
1719

18-
extern (C++, std)
19-
{
20-
alias void function() unexpected_handler;
21-
unexpected_handler set_unexpected(unexpected_handler f) nothrow;
22-
void unexpected();
20+
alias void function() unexpected_handler;
21+
unexpected_handler set_unexpected(unexpected_handler f) nothrow;
22+
void unexpected();
2323

24-
alias void function() terminate_handler;
25-
terminate_handler set_terminate(terminate_handler f) nothrow;
26-
void terminate();
24+
alias void function() terminate_handler;
25+
terminate_handler set_terminate(terminate_handler f) nothrow;
26+
void terminate();
2727

28-
bool uncaught_exception();
28+
bool uncaught_exception();
2929

30-
class exception
31-
{
32-
this() nothrow { }
33-
this(const exception) nothrow { }
34-
//exception operator=(const exception) nothrow { return this; }
35-
//virtual ~this() nothrow;
36-
void dtor() { }
37-
const(char)* what() const nothrow;
38-
}
30+
class exception
31+
{
32+
this() nothrow { }
33+
this(const exception) nothrow { }
34+
//exception operator=(const exception) nothrow { return this; }
35+
//virtual ~this() nothrow;
36+
void dtor() { }
37+
const(char)* what() const nothrow;
38+
}
3939

40-
class bad_exception : exception
41-
{
42-
this() nothrow { }
43-
this(const bad_exception) nothrow { }
44-
//bad_exception operator=(const bad_exception) nothrow { return this; }
45-
//virtual ~this() nothrow;
46-
override const(char)* what() const nothrow;
47-
}
40+
class bad_exception : exception
41+
{
42+
this() nothrow { }
43+
this(const bad_exception) nothrow { }
44+
//bad_exception operator=(const bad_exception) nothrow { return this; }
45+
//virtual ~this() nothrow;
46+
override const(char)* what() const nothrow;
4847
}
4948
}
50-
else version (CRuntime_Glibc)
49+
else version (CppRuntime_Gcc)
5150
{
52-
extern (C++, std)
53-
{
54-
alias void function() unexpected_handler;
55-
unexpected_handler set_unexpected(unexpected_handler f) nothrow;
56-
void unexpected();
51+
alias void function() unexpected_handler;
52+
unexpected_handler set_unexpected(unexpected_handler f) nothrow;
53+
void unexpected();
5754

58-
alias void function() terminate_handler;
59-
terminate_handler set_terminate(terminate_handler f) nothrow;
60-
void terminate();
55+
alias void function() terminate_handler;
56+
terminate_handler set_terminate(terminate_handler f) nothrow;
57+
void terminate();
6158

62-
pure bool uncaught_exception();
59+
pure bool uncaught_exception();
6360

64-
class exception
65-
{
66-
this();
67-
//virtual ~this();
68-
void dtor1();
69-
void dtor2();
70-
const(char)* what() const;
71-
}
61+
class exception
62+
{
63+
this();
64+
//virtual ~this();
65+
void dtor1();
66+
void dtor2();
67+
const(char)* what() const;
68+
}
7269

73-
class bad_exception : exception
74-
{
75-
this();
76-
//virtual ~this();
77-
override const(char)* what() const;
78-
}
70+
class bad_exception : exception
71+
{
72+
this();
73+
//virtual ~this();
74+
override const(char)* what() const;
7975
}
8076
}
81-
else version (CRuntime_Microsoft)
77+
else version (CppRuntime_Microsoft)
8278
{
83-
extern (C++, std)
79+
class exception
8480
{
85-
class exception
86-
{
87-
this();
88-
this(const exception);
89-
//exception operator=(const exception) { return this; }
81+
this();
82+
this(const exception);
83+
//exception operator=(const exception) { return this; }
9084
//virtual ~this();
91-
void dtor() { }
92-
const(char)* what() const;
85+
void dtor() { }
86+
const(char)* what() const;
9387

94-
private:
95-
const(char)* mywhat;
96-
bool dofree;
97-
}
88+
private:
89+
const(char)* mywhat;
90+
bool dofree;
91+
}
9892

99-
class bad_exception : exception
100-
{
101-
this(const(char)* msg = "bad exception");
102-
//virtual ~this();
103-
}
93+
class bad_exception : exception
94+
{
95+
this(const(char)* msg = "bad exception");
96+
//virtual ~this();
10497
}
10598
}
99+
else
100+
static assert(0, "Missing std::exception binding for this platform");

src/core/stdcpp/typeinfo.d

Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,55 @@
1111

1212
module core.stdcpp.typeinfo;
1313

14-
version (CRuntime_DigitalMars)
14+
version (CppRuntime_DigitalMars)
1515
{
1616
import core.stdcpp.exception;
1717

18-
extern (C++, std)
18+
extern (C++, "std"):
19+
20+
class type_info
1921
{
20-
class type_info
21-
{
22-
void* pdata;
23-
24-
public:
25-
//virtual ~this();
26-
void dtor() { } // reserve slot in vtbl[]
27-
28-
//bool operator==(const type_info rhs) const;
29-
//bool operator!=(const type_info rhs) const;
30-
final bool before(const type_info rhs) const;
31-
final const(char)* name() const;
32-
protected:
33-
//type_info();
34-
private:
35-
//this(const type_info rhs);
36-
//type_info operator=(const type_info rhs);
37-
}
22+
void* pdata;
23+
24+
public:
25+
//virtual ~this();
26+
void dtor() { } // reserve slot in vtbl[]
27+
28+
//bool operator==(const type_info rhs) const;
29+
//bool operator!=(const type_info rhs) const;
30+
final bool before(const type_info rhs) const;
31+
final const(char)* name() const;
32+
protected:
33+
//type_info();
34+
private:
35+
//this(const type_info rhs);
36+
//type_info operator=(const type_info rhs);
37+
}
3838

39-
class bad_cast : core.stdcpp.exception.std.exception
40-
{
41-
this() nothrow { }
42-
this(const bad_cast) nothrow { }
43-
//bad_cast operator=(const bad_cast) nothrow { return this; }
44-
//virtual ~this() nothrow;
45-
override const(char)* what() const nothrow;
46-
}
39+
class bad_cast : exception
40+
{
41+
this() nothrow { }
42+
this(const bad_cast) nothrow { }
43+
//bad_cast operator=(const bad_cast) nothrow { return this; }
44+
//virtual ~this() nothrow;
45+
override const(char)* what() const nothrow;
46+
}
4747

48-
class bad_typeid : core.stdcpp.exception.std.exception
49-
{
50-
this() nothrow { }
51-
this(const bad_typeid) nothrow { }
52-
//bad_typeid operator=(const bad_typeid) nothrow { return this; }
53-
//virtual ~this() nothrow;
54-
override const (char)* what() const nothrow;
55-
}
48+
class bad_typeid : exception
49+
{
50+
this() nothrow { }
51+
this(const bad_typeid) nothrow { }
52+
//bad_typeid operator=(const bad_typeid) nothrow { return this; }
53+
//virtual ~this() nothrow;
54+
override const (char)* what() const nothrow;
5655
}
5756
}
58-
else version (CRuntime_Microsoft)
57+
else version (CppRuntime_Microsoft)
5958
{
6059
import core.stdcpp.exception;
6160

61+
extern (C++, "std"):
62+
6263
struct __type_info_node
6364
{
6465
void* _MemPtr;
@@ -67,82 +68,80 @@ else version (CRuntime_Microsoft)
6768

6869
extern __gshared __type_info_node __type_info_root_node;
6970

70-
extern (C++, std)
71+
class type_info
7172
{
72-
class type_info
73-
{
74-
//virtual ~this();
75-
void dtor() { } // reserve slot in vtbl[]
76-
//bool operator==(const type_info rhs) const;
77-
//bool operator!=(const type_info rhs) const;
78-
final bool before(const type_info rhs) const;
79-
final const(char)* name(__type_info_node* p = &__type_info_root_node) const;
80-
81-
private:
82-
void* pdata;
83-
char[1] _name;
84-
//type_info operator=(const type_info rhs);
85-
}
73+
//virtual ~this();
74+
void dtor() { } // reserve slot in vtbl[]
75+
//bool operator==(const type_info rhs) const;
76+
//bool operator!=(const type_info rhs) const;
77+
final bool before(const type_info rhs) const;
78+
final const(char)* name(__type_info_node* p = &__type_info_root_node) const;
79+
80+
private:
81+
void* pdata;
82+
char[1] _name;
83+
//type_info operator=(const type_info rhs);
84+
}
8685

87-
class bad_cast : core.stdcpp.exception.std.exception
88-
{
89-
this(const(char)* msg = "bad cast");
90-
//virtual ~this();
91-
}
86+
class bad_cast : exception
87+
{
88+
this(const(char)* msg = "bad cast");
89+
//virtual ~this();
90+
}
9291

93-
class bad_typeid : core.stdcpp.exception.std.exception
94-
{
95-
this(const(char)* msg = "bad typeid");
96-
//virtual ~this();
97-
}
92+
class bad_typeid : exception
93+
{
94+
this(const(char)* msg = "bad typeid");
95+
//virtual ~this();
9896
}
9997
}
100-
else version (CRuntime_Glibc)
98+
else version (CppRuntime_Gcc)
10199
{
102100
import core.stdcpp.exception;
103101

104-
extern (C++, __cxxabiv1)
102+
extern (C++, "__cxxabiv1")
105103
{
106104
class __class_type_info;
107105
}
108106

109-
extern (C++, std)
107+
extern (C++, "std"):
108+
109+
class type_info
110110
{
111-
class type_info
112-
{
113-
void dtor1(); // consume destructor slot in vtbl[]
114-
void dtor2(); // consume destructor slot in vtbl[]
115-
final const(char)* name()() const nothrow {
116-
return _name[0] == '*' ? _name + 1 : _name;
117-
}
118-
final bool before()(const type_info _arg) const {
119-
import core.stdc.string : strcmp;
120-
return (_name[0] == '*' && _arg._name[0] == '*')
121-
? _name < _arg._name
122-
: strcmp(_name, _arg._name) < 0;
123-
}
124-
//bool operator==(const type_info) const;
125-
bool __is_pointer_p() const;
126-
bool __is_function_p() const;
127-
bool __do_catch(const type_info, void**, uint) const;
128-
bool __do_upcast(const __cxxabiv1.__class_type_info, void**) const;
129-
130-
const(char)* _name;
131-
this(const(char)*);
111+
void dtor1(); // consume destructor slot in vtbl[]
112+
void dtor2(); // consume destructor slot in vtbl[]
113+
final const(char)* name()() const nothrow {
114+
return _name[0] == '*' ? _name + 1 : _name;
132115
}
133-
134-
class bad_cast : core.stdcpp.exception.std.exception
135-
{
136-
this();
137-
//~this();
138-
override const(char)* what() const;
116+
final bool before()(const type_info _arg) const {
117+
import core.stdc.string : strcmp;
118+
return (_name[0] == '*' && _arg._name[0] == '*')
119+
? _name < _arg._name
120+
: strcmp(_name, _arg._name) < 0;
139121
}
122+
//bool operator==(const type_info) const;
123+
bool __is_pointer_p() const;
124+
bool __is_function_p() const;
125+
bool __do_catch(const type_info, void**, uint) const;
126+
bool __do_upcast(const __class_type_info, void**) const;
127+
128+
const(char)* _name;
129+
this(const(char)*);
130+
}
140131

141-
class bad_typeid : core.stdcpp.exception.std.exception
142-
{
143-
this();
144-
//~this();
145-
override const(char)* what() const;
146-
}
132+
class bad_cast : exception
133+
{
134+
this();
135+
//~this();
136+
override const(char)* what() const;
137+
}
138+
139+
class bad_typeid : exception
140+
{
141+
this();
142+
//~this();
143+
override const(char)* what() const;
147144
}
148145
}
146+
else
147+
static assert(0, "Missing std::type_info binding for this platform");

0 commit comments

Comments
 (0)