Skip to content

Commit 47d34a4

Browse files
authored
Merge pull request #10260 from WalterBright/checkEnclosedInTry
add checkEnclosedInTry() merged-on-behalf-of: Walter Bright <[email protected]>
2 parents a47acfe + a2fa2f3 commit 47d34a4

File tree

1 file changed

+25
-37
lines changed

1 file changed

+25
-37
lines changed

src/dmd/s2ir.d

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,7 @@ private extern (C++) class S2irVisitor : Visitor
433433
block_setLoc(b, s.loc);
434434

435435
// Check that bdest is in an enclosing try block
436-
for (block *bt = b.Btry; bt != bdest.Btry; bt = bt.Btry)
437-
{
438-
if (!bt)
439-
{
440-
//printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry);
441-
s.error("cannot `goto` into `try` block");
442-
break;
443-
}
444-
}
436+
bdest.checkEnclosedInTry(b, s);
445437

446438
block_next(blx,BCgoto,null);
447439
}
@@ -466,16 +458,7 @@ private extern (C++) class S2irVisitor : Visitor
466458
if (b.Btry != label.lblock.Btry)
467459
{
468460
// Check that lblock is in an enclosing try block
469-
for (block *bt = b.Btry; bt != label.lblock.Btry; bt = bt.Btry)
470-
{
471-
if (!bt)
472-
{
473-
//printf("b.Btry = %p, label.lblock.Btry = %p\n", b.Btry, label.lblock.Btry);
474-
s.error("cannot `goto` into `try` block");
475-
break;
476-
}
477-
478-
}
461+
label.lblock.checkEnclosedInTry(b, s);
479462
}
480463
}
481464
block_next(blx, BCgoto, label.lblock);
@@ -632,15 +615,7 @@ private extern (C++) class S2irVisitor : Visitor
632615
if (b.Btry != bdest.Btry)
633616
{
634617
// Check that bdest is in an enclosing try block
635-
for (block *bt = b.Btry; bt != bdest.Btry; bt = bt.Btry)
636-
{
637-
if (!bt)
638-
{
639-
//printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry);
640-
s.error("cannot `goto` into `try` block");
641-
break;
642-
}
643-
}
618+
bdest.checkEnclosedInTry(b, s);
644619

645620
//setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1);
646621
}
@@ -663,15 +638,7 @@ private extern (C++) class S2irVisitor : Visitor
663638
if (b.Btry != bdest.Btry)
664639
{
665640
// Check that bdest is in an enclosing try block
666-
for (block *bt = b.Btry; bt != bdest.Btry; bt = bt.Btry)
667-
{
668-
if (!bt)
669-
{
670-
//printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry);
671-
s.error("cannot `goto` into `try` block");
672-
break;
673-
}
674-
}
641+
bdest.checkEnclosedInTry(b, s);
675642

676643
//setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1);
677644
}
@@ -1828,3 +1795,24 @@ void insertFinallyBlockGotos(block *startblock)
18281795
printf("-------------------------\n");
18291796
}
18301797
}
1798+
1799+
/***************************************************
1800+
* Issue error if bd is not enclosed in a try block.
1801+
* Params:
1802+
* bd = block to check
1803+
* bcurrent = current block (starting point)
1804+
* s = statement to use for error messages
1805+
*/
1806+
private void checkEnclosedInTry(const block* bd, const block* bcurrent, Statement s)
1807+
{
1808+
for (const(block)* bt = bcurrent.Btry; bt != bd.Btry; bt = bt.Btry)
1809+
{
1810+
if (!bt)
1811+
{
1812+
//printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry);
1813+
s.error("cannot `goto` into `try` block");
1814+
break;
1815+
}
1816+
}
1817+
}
1818+

0 commit comments

Comments
 (0)