Skip to content

Commit

Permalink
[refactor] simplify nested reference checking (#16664)
Browse files Browse the repository at this point in the history
  • Loading branch information
0-v-0 authored Jul 5, 2024
1 parent 0f1c5d9 commit 265a77b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 27 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dmd/backend/aarray.d
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ nothrow:
{
while (e)
{
auto result = dg(cast(Key*)(e + 1), cast(Value*)(cast(void*)(e + 1) + aligned_keysize));
if (result)
if (auto result = dg(cast(Key*)(e + 1), cast(Value*)(cast(void*)(e + 1) + aligned_keysize)))
return result;
e = e.next;
}
Expand Down
14 changes: 5 additions & 9 deletions compiler/src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -2140,8 +2140,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
{
if (hasAliasThis)
{
auto result = tryAliasThisCast();
if (result)
if (auto result = tryAliasThisCast())
return result;
}

Expand Down Expand Up @@ -2235,8 +2234,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
*/
if (hasAliasThis)
{
auto result = tryAliasThisCast();
if (result)
if (auto result = tryAliasThisCast())
return result;
}
error(e.loc, "cannot cast expression `%s` of type `%s` to `%s`", e.toChars(), e.type.toChars(), t.toChars());
Expand Down Expand Up @@ -2557,7 +2555,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
// See if need to truncate or extend the literal
if (auto tsa = tb.isTypeSArray())
{
size_t dim2 = cast(size_t)tsa.dim.toInteger();
const dim2 = cast(size_t)tsa.dim.toInteger();
//printf("dim from = %d, to = %d\n", cast(int)se.len, cast(int)dim2);

// Changing dimensions
Expand Down Expand Up @@ -2637,8 +2635,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
tb.ty == Tpointer && tb.nextOf().ty == Tfunction)
{
auto ve = e.e1.isVarExp();
auto f = ve.var.isFuncDeclaration();
if (f)
if (auto f = ve.var.isFuncDeclaration())
{
assert(f.isImportedSymbol());
f = f.overloadExactMatch(tb.nextOf());
Expand Down Expand Up @@ -2946,8 +2943,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
{
if (e.func)
{
auto f = e.func.overloadExactMatch(tb.nextOf());
if (f)
if (auto f = e.func.overloadExactMatch(tb.nextOf()))
{
int offset;
if (f.tintro && f.tintro.nextOf().isBaseOf(f.type.nextOf(), &offset) && offset)
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ extern (C++) abstract class Declaration : Dsymbol
// is an overload in the overload set that isn't
if (isAliasedDeclaration)
{
FuncDeclaration fd = isFuncDeclaration();
if (fd)
if (FuncDeclaration fd = isFuncDeclaration())
{
for (FuncDeclaration ovl = fd; ovl; ovl = cast(FuncDeclaration)ovl.overnext)
if (!(ovl.storage_class & STC.disable))
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dmd/enumsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)
*/
ed.members.foreachDsymbol( (s)
{
EnumMember em = s.isEnumMember();
if (em)
if (EnumMember em = s.isEnumMember())
em._scope = sce;
});

Expand Down Expand Up @@ -386,8 +385,7 @@ Expression getDefaultValue(EnumDeclaration ed, const ref Loc loc)

foreach (const i; 0 .. ed.members.length)
{
EnumMember em = (*ed.members)[i].isEnumMember();
if (em)
if (EnumMember em = (*ed.members)[i].isEnumMember())
{
if (em.semanticRun < PASS.semanticdone)
{
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dmd/escape.d
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,7 @@ void escapeByValue(Expression e, ref scope EscapeByResults er, bool retRefTransi

void visitSymOff(SymOffExp e)
{
VarDeclaration v = e.var.isVarDeclaration();
if (v)
if (VarDeclaration v = e.var.isVarDeclaration())
er.byRef(v, retRefTransition);
}

Expand Down Expand Up @@ -1966,8 +1965,7 @@ void escapeByRef(Expression e, ref scope EscapeByResults er, bool retRefTransiti

void visitVar(VarExp e)
{
auto v = e.var.isVarDeclaration();
if (v)
if (auto v = e.var.isVarDeclaration())
{
if (v.storage_class & STC.ref_ && v.storage_class & (STC.foreach_ | STC.temp) && v._init)
{
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,15 @@ private extern(C++) final class Semantic3Visitor : Visitor
Statement fpreinv = null;
if (funcdecl.addPreInvariant())
{
Expression e = addInvariant(funcdecl.isThis(), funcdecl.vthis);
if (e)
if (Expression e = addInvariant(funcdecl.isThis(), funcdecl.vthis))
fpreinv = new ExpStatement(Loc.initial, e);
}

// Postcondition invariant
Statement fpostinv = null;
if (funcdecl.addPostInvariant())
{
Expression e = addInvariant(funcdecl.isThis(), funcdecl.vthis);
if (e)
if (Expression e = addInvariant(funcdecl.isThis(), funcdecl.vthis))
fpostinv = new ExpStatement(Loc.initial, e);
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7257,8 +7257,7 @@ Type stripDefaultArgs(Type t)
{
foreach (i, p; *parameters)
{
Parameter ps = stripParameter(p);
if (ps)
if (Parameter ps = stripParameter(p))
{
// Replace params with a copy we can modify
Parameters* nparams = new Parameters(parameters.length);
Expand Down

0 comments on commit 265a77b

Please sign in to comment.