From e4fa47e2af7ccf2030ba560ac51728a1d13bd06c Mon Sep 17 00:00:00 2001 From: 0-v-0 Date: Sun, 21 Jul 2024 10:43:40 +0800 Subject: [PATCH] refactor variable declarations --- compiler/src/dmd/importc.d | 2 +- compiler/src/dmd/root/longdouble.d | 8 +++----- compiler/src/dmd/templatesem.d | 5 ++--- compiler/src/dmd/tocvdebug.d | 4 ++-- druntime/benchmark/gcbench/vdparser.extra/vdc/ast/node.d | 4 ++-- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/src/dmd/importc.d b/compiler/src/dmd/importc.d index ece56c8d1b..527151d219 100644 --- a/compiler/src/dmd/importc.d +++ b/compiler/src/dmd/importc.d @@ -121,7 +121,6 @@ Expression fieldLookup(Expression e, Scope* sc, Identifier id, bool arrow) if (e.isErrorExp()) return e; - Dsymbol s; auto t = e.type; if (t.isTypePointer()) { @@ -131,6 +130,7 @@ Expression fieldLookup(Expression e, Scope* sc, Identifier id, bool arrow) error(e.loc, "since `%s` is a pointer, use `%s->%s` instead of `%s.%s`", pe, pe, id.toChars(), pe, id.toChars()); e = new PtrExp(e.loc, e); } + Dsymbol s; if (auto ts = t.isTypeStruct()) s = ts.sym.search(e.loc, id, 0); if (!s) diff --git a/compiler/src/dmd/root/longdouble.d b/compiler/src/dmd/root/longdouble.d index 64ea0460e9..d7e5043096 100644 --- a/compiler/src/dmd/root/longdouble.d +++ b/compiler/src/dmd/root/longdouble.d @@ -267,13 +267,11 @@ ulong ld_readull(const longdouble_soft* pthis) // so we roll our own conversion (it also allows the usual C wrap-around // instead of the "invalid value" created by the FPU) int expo = pthis.exponent - 0x3fff; - ulong u; if(expo < 0 || expo > 127) return 0; - if(expo < 64) - u = pthis.mantissa >> (63 - expo); - else - u = pthis.mantissa << (expo - 63); + ulong u = expo < 64 ? + pthis.mantissa << (63 - expo) : + pthis.mantissa >> (expo - 63); if(pthis.sign) u = ~u + 1; return u; diff --git a/compiler/src/dmd/templatesem.d b/compiler/src/dmd/templatesem.d index d26e35d814..fc638fad30 100644 --- a/compiler/src/dmd/templatesem.d +++ b/compiler/src/dmd/templatesem.d @@ -154,7 +154,7 @@ void templateDeclarationSemantic(Scope* sc, TemplateDeclaration tempdecl) /* Calculate TemplateParameter.dependent */ - TemplateParameters tparams = TemplateParameters(1); + auto tparams = TemplateParameters(1); for (size_t i = 0; i < tempdecl.parameters.length; i++) { TemplateParameter tp = (*tempdecl.parameters)[i]; @@ -336,8 +336,7 @@ MATCH matchWithInstance(Scope* sc, TemplateDeclaration td, TemplateInstance ti, ti.parent = td.parent; // Similar to doHeaderInstantiation - FuncDeclaration fd = td.onemember ? td.onemember.isFuncDeclaration() : null; - if (fd) + if (FuncDeclaration fd = td.onemember ? td.onemember.isFuncDeclaration() : null) { TypeFunction tf = fd.type.isTypeFunction().syntaxCopy(); diff --git a/compiler/src/dmd/tocvdebug.d b/compiler/src/dmd/tocvdebug.d index da0be48702..c63b6e0d94 100644 --- a/compiler/src/dmd/tocvdebug.d +++ b/compiler/src/dmd/tocvdebug.d @@ -146,12 +146,12 @@ enum CV8_NAMELENMAX = 0xffff; // length record is 16-bit only uint cv4_Denum(EnumDeclaration e) { //dbg_printf("cv4_Denum(%s)\n", e.toChars()); - const uint property = (!e.members || !e.memtype || !e.memtype.isintegral()) + const uint property = !e.members || !e.memtype || !e.memtype.isintegral() ? 0x80 // enum is forward referenced or non-integer : 0; // Compute the number of fields, and the length of the fieldlist record - CvFieldList mc = CvFieldList(0, 0); + auto mc = CvFieldList(0, 0); if (!property) { for (size_t i = 0; i < e.members.length; i++) diff --git a/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/node.d b/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/node.d index 9a46f9b54d..c81add85bb 100644 --- a/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/node.d +++ b/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/node.d @@ -346,7 +346,7 @@ class Node void expandNonScopeSimple(Scope sc, size_t i, size_t j) { - Node[1] narray; + Node[1] narray = void; for(size_t m = i; m < j; ) { Node n = members[m]; @@ -522,7 +522,7 @@ class Node //////////////////////////////////////////////////////////// version(COUNT) {} else // invariant does not work with destructor - invariant() + invariant { if(!__ctfe) foreach(m; members)