Skip to content

Commit

Permalink
[dtemplate.d] use early return (#16601)
Browse files Browse the repository at this point in the history
instead of goto labels
  • Loading branch information
thewilsonator authored Jun 20, 2024
1 parent 3658e62 commit 71c81dd
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions compiler/src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ private bool match(RootObject o1, RootObject o2)
o1, o1.toChars(), o1.dyncast(), o2, o2.toChars(), o2.dyncast());
}

bool yes()
{
static if (log)
printf("\t. match\n");
return true;
}
bool no()
{
static if (log)
printf("\t. nomatch\n");
return false;
}
/* A proper implementation of the various equals() overrides
* should make it possible to just do o1.equals(o2), but
* we'll do that another day.
Expand All @@ -299,23 +311,23 @@ private bool match(RootObject o1, RootObject o2)
{
auto t2 = isType(o2);
if (!t2)
goto Lnomatch;
return no();

static if (log)
{
printf("\tt1 = %s\n", t1.toChars());
printf("\tt2 = %s\n", t2.toChars());
}
if (!t1.equals(t2))
goto Lnomatch;
return no();

goto Lmatch;
return yes();
}
if (auto e1 = getExpression(o1))
{
auto e2 = getExpression(o2);
if (!e2)
goto Lnomatch;
return no();

static if (log)
{
Expand All @@ -328,53 +340,45 @@ private bool match(RootObject o1, RootObject o2)
// as well as expression equality to ensure templates are properly
// matched.
if (!(e1.type && e2.type && e1.type.equals(e2.type)) || !e1.equals(e2))
goto Lnomatch;
return no();

goto Lmatch;
return yes();
}
if (auto s1 = isDsymbol(o1))
{
auto s2 = isDsymbol(o2);
if (!s2)
goto Lnomatch;
return no();

static if (log)
{
printf("\ts1 = %s \n", s1.kind(), s1.toChars());
printf("\ts2 = %s \n", s2.kind(), s2.toChars());
}
if (!s1.equals(s2))
goto Lnomatch;
return no();
if (s1.parent != s2.parent && !s1.isFuncDeclaration() && !s2.isFuncDeclaration())
goto Lnomatch;
return no();

goto Lmatch;
return yes();
}
if (auto u1 = isTuple(o1))
{
auto u2 = isTuple(o2);
if (!u2)
goto Lnomatch;
return no();

static if (log)
{
printf("\tu1 = %s\n", u1.toChars());
printf("\tu2 = %s\n", u2.toChars());
}
if (!arrayObjectMatch(u1.objects, u2.objects))
goto Lnomatch;
return no();

goto Lmatch;
return yes();
}
Lmatch:
static if (log)
printf("\t. match\n");
return true;

Lnomatch:
static if (log)
printf("\t. nomatch\n");
return false;
return yes();
}

/************************************
Expand Down

0 comments on commit 71c81dd

Please sign in to comment.