Skip to content

Commit

Permalink
refactor nested reference checking (#16693)
Browse files Browse the repository at this point in the history
  • Loading branch information
0-v-0 authored Jul 14, 2024
1 parent cfdbf56 commit f727e7f
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 36 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration
* before the semantic analysis of 'to', so that template overloading based on the
* 'this' pointer can be successful.
*/
FuncDeclaration fd = ps.isFuncDeclaration();
if (fd)
if (FuncDeclaration fd = ps.isFuncDeclaration())
{
/* Use storage_class2 instead of storage_class otherwise when we do .di generation
* we'll wind up with 'const const' rather than 'const'.
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure
*/
FuncDeclaration hasIdentityOpAssign(AggregateDeclaration ad, Scope* sc)
{
Dsymbol assign = search_function(ad, Id.assign);
if (assign)
if (Dsymbol assign = search_function(ad, Id.assign))
{
/* check identity opAssign exists
*/
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,7 @@ private final class CppMangleVisitor : Visitor
return buf.writestring("St");

auto si = getInstance(s);
Dsymbol p = getQualifier(si);
if (p)
if (Dsymbol p = getQualifier(si))
{
if (isStd(p))
{
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ extern (C++) class ClassDeclaration : AggregateDeclaration
return null;
if (cdb.ident.equals(ident))
return cdb;
auto result = cdb.searchBase(ident);
if (result)
if (auto result = cdb.searchBase(ident))
return result;
}
return null;
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 @@ -1238,8 +1238,7 @@ extern (C++) class VarDeclaration : Declaration
*/
for (auto s = cast(Dsymbol)this; s; s = s.parent)
{
auto ad = (cast(inout)s).isMember();
if (ad)
if (auto ad = (cast(inout)s).isMember())
return ad;
if (!s.parent || !s.parent.isTemplateMixin())
break;
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/dscope.d
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ extern (C++) struct Scope
if (global.params.fixAliasThis)
{
Expression exp = new ThisExp(loc);
Dsymbol aliasSym = checkAliasThis(sc.scopesym.isAggregateDeclaration(), ident, flags, &exp);
if (aliasSym)
if (Dsymbol aliasSym = checkAliasThis(sc.scopesym.isAggregateDeclaration(), ident, flags, &exp))
{
//printf("found aliassym: %s\n", aliasSym.toChars());
pscopesym = new ExpressionDsymbol(exp);
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ extern (C++) class Dsymbol : ASTNode
while (s)
{
//printf("\ts = %s '%s'\n", s.kind(), s.toPrettyChars());
Module m = s.isModule();
if (m)
if (Module m = s.isModule())
return m;
s = s.parent;
}
Expand Down Expand Up @@ -428,8 +427,7 @@ extern (C++) class Dsymbol : ASTNode
while (s)
{
//printf("\ts = %s '%s'\n", s.kind(), s.toPrettyChars());
Module m = s.isModule();
if (m)
if (Module m = s.isModule())
return m;
TemplateInstance ti = s.isTemplateInstance();
if (ti && ti.enclosing)
Expand Down
9 changes: 3 additions & 6 deletions compiler/src/dmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ extern (C++) class FuncDeclaration : Declaration
{
//printf("FuncDeclaration::overloadInsert(s = %s) this = %s\n", s.toChars(), toChars());
assert(s != this);
AliasDeclaration ad = s.isAliasDeclaration();
if (ad)
if (AliasDeclaration ad = s.isAliasDeclaration())
{
if (overnext)
return overnext.overloadInsert(ad);
Expand Down Expand Up @@ -501,8 +500,7 @@ extern (C++) class FuncDeclaration : Declaration
while (f && f.overnext)
{
//printf("f.overnext = %p %s\n", f.overnext, f.overnext.toChars());
TemplateDeclaration td = f.overnext.isTemplateDeclaration();
if (td)
if (TemplateDeclaration td = f.overnext.isTemplateDeclaration())
return td;
f = f.overnext.isFuncDeclaration();
}
Expand Down Expand Up @@ -1731,8 +1729,7 @@ extern (C++) final class FuncLiteralDeclaration : FuncDeclaration
{
if (parent)
{
TemplateInstance ti = parent.isTemplateInstance();
if (ti)
if (TemplateInstance ti = parent.isTemplateInstance())
return ti.tempdecl.toPrettyChars(QualifyTypes);
}
return Dsymbol.toPrettyChars(QualifyTypes);
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/funcsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,7 @@ Ldone:
}

// If it's a member template
ClassDeclaration cd = ti.tempdecl.isClassMember();
if (cd)
if (ClassDeclaration cd = ti.tempdecl.isClassMember())
{
.error(funcdecl.loc, "%s `%s` cannot use template to add virtual function to class `%s`", funcdecl.kind, funcdecl.toPrettyChars, cd.toChars());
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dmd/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1239,11 +1239,9 @@ public:
void scanVar(Dsymbol s)
{
//printf("scanVar(%s %s)\n", s.kind(), s.toPrettyChars());
VarDeclaration vd = s.isVarDeclaration();
if (vd)
if (VarDeclaration vd = s.isVarDeclaration())
{
TupleDeclaration td = vd.toAlias().isTupleDeclaration();
if (td)
if (TupleDeclaration td = vd.toAlias().isTupleDeclaration())
{
td.foreachVar((s)
{
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,7 @@ private size_t emitVtbl(ref DtBuilder dtb, BaseClass *b, ref FuncDeclarations bv

foreach (j; jstart .. id_vtbl_dim)
{
FuncDeclaration fd = bvtbl[j];
if (fd)
if (FuncDeclaration fd = bvtbl[j])
{
auto offset2 = b.offset;
if (fd.interfaceVirtual)
Expand Down
3 changes: 1 addition & 2 deletions druntime/benchmark/gcbench/vdparser.extra/vdc/ast/stmt.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Statement : Node
{
foreach(m; members)
{
Value v = m.interpret(sc);
if(v)
if (Value v = m.interpret(sc))
return v;
}
return null;
Expand Down
7 changes: 3 additions & 4 deletions druntime/src/core/internal/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ struct Gcx
void Invariant() const { }

debug(INVARIANT)
invariant()
invariant
{
if (initialized)
{
Expand Down Expand Up @@ -3171,8 +3171,7 @@ Lmark:
{
// first, we find the Pool this block is in, then check to see if the
// mark bit is clear.
auto pool = findPool(addr);
if (pool)
if (auto pool = findPool(addr))
{
auto offset = cast(size_t)(addr - pool.baseAddr);
auto pn = offset / PAGESIZE;
Expand Down Expand Up @@ -3924,7 +3923,7 @@ struct Pool
void Invariant() const {}

debug(INVARIANT)
invariant()
invariant
{
if (baseAddr)
{
Expand Down

0 comments on commit f727e7f

Please sign in to comment.