Skip to content

Commit bdb1418

Browse files
committed
implement DIP1008 - Exceptions and @nogc
1 parent afebe0c commit bdb1418

File tree

15 files changed

+79
-8
lines changed

15 files changed

+79
-8
lines changed

src/ddmd/backend/rtlsym.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ void rtlsym_init()
6060

6161
//printf("rtlsym_init(%s)\n", regm_str(FREGSAVED));
6262

63-
#if MARS
6463
type *t = type_fake(TYnfunc);
6564
t->Tmangle = mTYman_c;
6665
t->Tcount++;
6766

67+
#if MARS
6868
// Variadic function
6969
type *tv = type_fake(TYnfunc);
7070
tv->Tmangle = mTYman_c;

src/ddmd/backend/rtlsym.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum
5858
RTLSYM_DSWITCHERR,
5959
RTLSYM_DHIDDENFUNC,
6060
RTLSYM_NEWCLASS,
61+
RTLSYM_NEWTHROW,
6162
RTLSYM_NEWARRAYT,
6263
RTLSYM_NEWARRAYIT,
6364
RTLSYM_NEWITEMT,

src/ddmd/backend/rtlsym.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ SYMBOL_MARS(SWITCH_DSTRING,FLfunc,FREGSAVED,"_d_switch_dstring", 0, t) \
8383
SYMBOL_MARS(DSWITCHERR, FLfunc,FREGSAVED,"_d_switch_error", SFLexit, t) \
8484
SYMBOL_MARS(DHIDDENFUNC, FLfunc,FREGSAVED,"_d_hidden_func", 0, t) \
8585
SYMBOL_MARS(NEWCLASS, FLfunc,FREGSAVED,"_d_newclass", 0, t) \
86+
SYMBOL_MARS(NEWTHROW, FLfunc,FREGSAVED,"_d_newThrowable", 0, t) \
8687
SYMBOL_MARS(NEWARRAYT, FLfunc,FREGSAVED,"_d_newarrayT", 0, t) \
8788
SYMBOL_MARS(NEWARRAYIT, FLfunc,FREGSAVED,"_d_newarrayiT", 0, t) \
8889
SYMBOL_MARS(NEWITEMT, FLfunc,FREGSAVED,"_d_newitemT", 0, t) \

src/ddmd/declaration.d

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,10 @@ extern (C++) class VarDeclaration : Declaration
10191019
uint sequenceNumber; // order the variables are declared
10201020
__gshared uint nextSequenceNumber; // the counter for sequenceNumber
10211021
FuncDeclarations nestedrefs; // referenced by these lexically nested functions
1022-
bool isargptr; // if parameter that _argptr points to
10231022
structalign_t alignment;
1023+
bool isargptr; // if parameter that _argptr points to
10241024
bool ctorinit; // it has been initialized in a ctor
1025+
bool iscatchvar; // this is the exception object variable in catch() clause
10251026

10261027
// Both these mean the var is not rebindable once assigned,
10271028
// and the destructor gets run when it goes out of scope
@@ -2170,6 +2171,9 @@ extern (C++) class VarDeclaration : Declaration
21702171
return null;
21712172
}
21722173

2174+
if (iscatchvar)
2175+
return null; // destructor is built by `void semantic(Catch c, Scope* sc)`, not here
2176+
21732177
Expression e = null;
21742178
// Destructors for structs and arrays of structs
21752179
Type tv = type.baseElemOf();

src/ddmd/declaration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ class VarDeclaration : public Declaration
238238
unsigned offset;
239239
unsigned sequenceNumber; // order the variables are declared
240240
FuncDeclarations nestedrefs; // referenced by these lexically nested functions
241-
bool isargptr; // if parameter that _argptr points to
242241
structalign_t alignment;
242+
bool isargptr; // if parameter that _argptr points to
243243
bool ctorinit; // it has been initialized in a ctor
244+
bool iscatchvar; // this is the exception object variable in catch() clause
244245
bool onstack; // it is a class that was allocated on the stack
245246
bool mynew; // it is a class new'd with custom operator new
246247
int canassign; // it can be assigned to

src/ddmd/escape.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ bool checkThrowEscape(Scope* sc, Expression e, bool gag)
430430

431431
Dsymbol p = v.toParent2();
432432

433-
if (v.isScope())
433+
if (v.isScope() && !v.iscatchvar) // special case: allow catch var to be rethrown
434+
// despite being `scope`
434435
{
435436
if (sc._module && sc._module.isRoot())
436437
{

src/ddmd/expression.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5947,10 +5947,12 @@ extern (C++) final class NewExp : Expression
59475947
Expressions* newargs; // Array of Expression's to call new operator
59485948
Type newtype;
59495949
Expressions* arguments; // Array of Expression's
5950+
59505951
Expression argprefix; // expression to be evaluated just before arguments[]
59515952
CtorDeclaration member; // constructor function
59525953
NewDeclaration allocator; // allocator function
5953-
int onstack; // allocate on stack
5954+
bool onstack; // allocate on stack
5955+
bool thrownew; // this NewExp is the expression of a ThrowStatement
59545956

59555957
extern (D) this(Loc loc, Expression thisexp, Expressions* newargs, Type newtype, Expressions* arguments)
59565958
{

src/ddmd/expression.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/* Compiler implementation of the D programming language
3-
* Copyright (c) 1999-2016 by Digital Mars
3+
* Copyright (c) 1999-2017 by Digital Mars
44
* All Rights Reserved
55
* written by Walter Bright
66
* http://www.digitalmars.com
@@ -527,7 +527,8 @@ class NewExp : public Expression
527527

528528
CtorDeclaration *member; // constructor function
529529
NewDeclaration *allocator; // allocator function
530-
int onstack; // allocate on stack
530+
bool onstack; // allocate on stack
531+
bool thrownew; // this NewExp is the expression of a ThrowStatement
531532

532533
Expression *syntaxCopy();
533534
Expression *semantic(Scope *sc);

src/ddmd/globals.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct Param
126126
bool check10378; // check for issues transitioning to 10738
127127
bool bug10378; // use pre- https://issues.dlang.org/show_bug.cgi?id=10378 search strategy
128128
bool vsafe; // use enhanced @safe checking
129+
bool ehnogc; // use @nogc exception handling
129130
/** The --transition=safe switch should only be used to show code with
130131
* silent semantics changes related to @safe improvements. It should not be
131132
* used to hide a feature that will have to go through deprecate-then-error

src/ddmd/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct Param
115115
bool check10378; // check for issues transitioning to 10738
116116
bool bug10378; // use pre-bugzilla 10378 search strategy
117117
bool vsafe; // use enhanced @safe checking
118+
bool ehnogc; // use @nogc exception handling
118119
bool showGaggedErrors; // print gagged errors anyway
119120

120121
CPU cpu; // CPU instruction set to target

0 commit comments

Comments
 (0)