From 71213dfbf853b2912d451e7a056b7bf253345ebe Mon Sep 17 00:00:00 2001 From: 0-v-0 Date: Wed, 22 Jan 2025 05:03:42 +0800 Subject: [PATCH] Remove redundant else (#20751) --- compiler/src/dmd/compiler.d | 3 +-- compiler/src/dmd/ctfeexpr.d | 8 +++----- compiler/src/dmd/dtemplate.d | 23 +++++++++-------------- compiler/src/dmd/func.d | 3 +-- compiler/src/dmd/iasmdmd.d | 11 +++++------ compiler/src/dmd/mangle/cpp.d | 25 ++++++++++++------------- compiler/src/dmd/mtype.d | 12 +++++------- compiler/src/dmd/objc.d | 11 +++++------ compiler/src/dmd/objc_glue.d | 9 ++++----- compiler/src/dmd/target.d | 32 +++++++++++++++----------------- 10 files changed, 60 insertions(+), 77 deletions(-) diff --git a/compiler/src/dmd/compiler.d b/compiler/src/dmd/compiler.d index 1398669781..a9031f6bc7 100644 --- a/compiler/src/dmd/compiler.d +++ b/compiler/src/dmd/compiler.d @@ -194,8 +194,7 @@ private struct ModuleComponentRange return packages[index]; if (index == packages.length) return name; - else - return Identifier.idPool("package"); + return Identifier.idPool("package"); } void popFront() @safe { index++; } } diff --git a/compiler/src/dmd/ctfeexpr.d b/compiler/src/dmd/ctfeexpr.d index a6cfe6e9ea..6d2a954cb7 100644 --- a/compiler/src/dmd/ctfeexpr.d +++ b/compiler/src/dmd/ctfeexpr.d @@ -1529,11 +1529,9 @@ Expression ctfeCast(UnionExp* pue, const ref Loc loc, Type type, Type to, Expres : tclass.implicitConvTo(to.mutableOf()); if (match) return paint(); - else - { - emplaceExp!(NullExp)(pue, loc, to); - return pue.exp(); - } + + emplaceExp!(NullExp)(pue, loc, to); + return pue.exp(); } // Allow TypeInfo type painting diff --git a/compiler/src/dmd/dtemplate.d b/compiler/src/dmd/dtemplate.d index 7f7437cdb1..dd9f3dac6b 100644 --- a/compiler/src/dmd/dtemplate.d +++ b/compiler/src/dmd/dtemplate.d @@ -217,17 +217,12 @@ Dsymbol getDsymbol(RootObject oarg) return te.td; if (auto te = ea.isScopeExp()) return te.sds; - else - return null; - } - else - { - // Try to convert Type to symbol - if (auto ta = isType(oarg)) - return ta.toDsymbol(null); - else - return isDsymbol(oarg); // if already a symbol + return null; } + // Try to convert Type to symbol + if (auto ta = isType(oarg)) + return ta.toDsymbol(null); + return isDsymbol(oarg); // if already a symbol } @@ -5752,8 +5747,8 @@ MATCH matchArg(TemplateParameter tp, Loc instLoc, Scope* sc, Objects* tiargs, si if (auto ttp = tp.isTemplateTupleParameter()) return matchArgTuple(ttp); - else - return matchArgParameter(); + + return matchArgParameter(); } MATCH matchArg(TemplateParameter tp, Scope* sc, RootObject oarg, size_t i, TemplateParameters* parameters, ref Objects dedtypes, Declaration* psparam) @@ -6221,8 +6216,8 @@ void printTemplateStats(bool listInstances, ErrorSink eSink) auto diff = b.ts.uniqueInstantiations - a.ts.uniqueInstantiations; if (diff) return diff; - else - return b.ts.numInstantiations - a.ts.numInstantiations; + + return b.ts.numInstantiations - a.ts.numInstantiations; } } diff --git a/compiler/src/dmd/func.d b/compiler/src/dmd/func.d index 993bce85ee..70f4c8303a 100644 --- a/compiler/src/dmd/func.d +++ b/compiler/src/dmd/func.d @@ -581,8 +581,7 @@ extern (C++) class FuncDeclaration : Declaration { if (isMain()) return "D main"; - else - return Dsymbol.toPrettyChars(QualifyTypes); + return Dsymbol.toPrettyChars(QualifyTypes); } /** for diagnostics, e.g. 'int foo(int x, int y) pure' */ diff --git a/compiler/src/dmd/iasmdmd.d b/compiler/src/dmd/iasmdmd.d index 526e5e2726..3d5c2590f8 100644 --- a/compiler/src/dmd/iasmdmd.d +++ b/compiler/src/dmd/iasmdmd.d @@ -2181,8 +2181,7 @@ void asm_merge_opnds(ref OPND o1, ref OPND o2) { if (o1.segreg) return illegalAddressError("o1.segment && o2.segreg"); - else - o1.segreg = o2.segreg; + o1.segreg = o2.segreg; } // combine the OPND's symbol field @@ -2266,8 +2265,8 @@ void asm_merge_opnds(ref OPND o1, ref OPND o2) { if (o1.pregDisp2) return illegalAddressError("o1.pregDisp2 && o2.pregDisp2"); - else - o1.pregDisp2 = o2.pregDisp2; + + o1.pregDisp2 = o2.pregDisp2; } if (o1.bRIP && (o1.pregDisp1 || o2.bRIP || o1.base)) @@ -2290,8 +2289,8 @@ void asm_merge_opnds(ref OPND o1, ref OPND o2) { if (o1.uchMultiplier) return illegalAddressError("o1.uchMultiplier && o2.uchMultiplier"); - else - o1.uchMultiplier = o2.uchMultiplier; + + o1.uchMultiplier = o2.uchMultiplier; } if (o2.ptype && !o1.ptype) o1.ptype = o2.ptype; diff --git a/compiler/src/dmd/mangle/cpp.d b/compiler/src/dmd/mangle/cpp.d index 67c9b53f1b..81b74f0fdb 100644 --- a/compiler/src/dmd/mangle/cpp.d +++ b/compiler/src/dmd/mangle/cpp.d @@ -435,10 +435,10 @@ private final class CppMangleVisitor : Visitor // 4. null pointer: std::nullptr_t (since C++11) if (t.ty == Tvoid || t.ty == Tbool) return true; - else if (t.ty == Tnull && global.params.cplusplus >= CppStdRevision.cpp11) + if (t.ty == Tnull && global.params.cplusplus >= CppStdRevision.cpp11) return true; - else - return t.isTypeBasic() && (t.isIntegral() || t.isReal()); + + return t.isTypeBasic() && (t.isIntegral() || t.isReal()); } /****************************** @@ -1939,21 +1939,21 @@ extern(C++): //printf("enum id = '%s'\n", id.toChars()); if (id == Id.__c_long) return writeBasicType(t, 0, 'l'); - else if (id == Id.__c_ulong) + if (id == Id.__c_ulong) return writeBasicType(t, 0, 'm'); - else if (id == Id.__c_char) + if (id == Id.__c_char) return writeBasicType(t, 0, 'c'); - else if (id == Id.__c_wchar_t) + if (id == Id.__c_wchar_t) return writeBasicType(t, 0, 'w'); - else if (id == Id.__c_longlong) + if (id == Id.__c_longlong) return writeBasicType(t, 0, 'x'); - else if (id == Id.__c_ulonglong) + if (id == Id.__c_ulonglong) return writeBasicType(t, 0, 'y'); - else if (id == Id.__c_complex_float) + if (id == Id.__c_complex_float) return Type.tcomplex32.accept(this); - else if (id == Id.__c_complex_double) + if (id == Id.__c_complex_double) return Type.tcomplex64.accept(this); - else if (id == Id.__c_complex_real) + if (id == Id.__c_complex_real) return Type.tcomplex80.accept(this); doSymbol(t); @@ -2362,8 +2362,7 @@ private bool isNamespaceEqual (CPPNamespaceDeclaration a, Nspace b, size_t idx = // We need to see if there's more ident enclosing if (auto pb = b.toParent().isNspace()) return isNamespaceEqual(a.cppnamespace, pb); - else - return a.cppnamespace is null; + return a.cppnamespace is null; } /// Returns: diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index f91687b7f3..b270943403 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -1295,17 +1295,15 @@ extern (C++) abstract class Type : ASTNode { if (t.isWildConst()) return MODFlags.wild; - else - return MODFlags.wildconst; + return MODFlags.wildconst; } - else if (isWild()) + if (isWild()) return MODFlags.wild; - else if (isConst()) + if (isConst()) return MODFlags.const_; - else if (isMutable()) + if (isMutable()) return MODFlags.mutable; - else - assert(0); + assert(0); } return 0; } diff --git a/compiler/src/dmd/objc.d b/compiler/src/dmd/objc.d index c5ee77ae79..b671986758 100644 --- a/compiler/src/dmd/objc.d +++ b/compiler/src/dmd/objc.d @@ -714,8 +714,8 @@ extern(C++) private final class Supported : Objc { if (cd.classKind == ClassKind.objc && fd.isStatic && !cd.objc.isMeta) return cd.objc.metaclass; - else - return cd; + + return cd; } override void addToClassMethodList(FuncDeclaration fd, ClassDeclaration cd) const @@ -805,11 +805,10 @@ extern(C++) private final class Supported : Objc { if (classDeclaration.baseClass) return getRuntimeMetaclass(classDeclaration.baseClass); - else - return classDeclaration; + + return classDeclaration; } - else - return classDeclaration.objc.metaclass; + return classDeclaration.objc.metaclass; } override void addSymbols(AttribDeclaration attribDeclaration, diff --git a/compiler/src/dmd/objc_glue.d b/compiler/src/dmd/objc_glue.d index 6d7697e34d..90312104b5 100644 --- a/compiler/src/dmd/objc_glue.d +++ b/compiler/src/dmd/objc_glue.d @@ -604,8 +604,8 @@ static: { if (hasHiddenArgument) return setMsgSendSymbol!("_objc_msgSendSuper_stret")(TYhfunc); - else - return setMsgSendSymbol!("_objc_msgSendSuper")(TYnfunc); + + return setMsgSendSymbol!("_objc_msgSendSuper")(TYnfunc); } Symbol* getImageInfo() @@ -1209,12 +1209,11 @@ private: if (var.toParent() is classDeclaration) return Symbols.getIVarOffset(classDeclaration, var, false); - else if (classDeclaration.baseClass) + if (classDeclaration.baseClass) return ObjcClassDeclaration(classDeclaration.baseClass, false) .getIVarOffset(var); - else - assert(false, "Trying to get the base class of a root class"); + assert(false, "Trying to get the base class of a root class"); } /** diff --git a/compiler/src/dmd/target.d b/compiler/src/dmd/target.d index 9f17df654c..8e90414d3e 100644 --- a/compiler/src/dmd/target.d +++ b/compiler/src/dmd/target.d @@ -525,12 +525,11 @@ extern (C++) struct Target { if (os == Target.OS.OSX) return Target.ObjectFormat.macho; - else if (os & Target.OS.Posix) + if (os & Target.OS.Posix) return Target.ObjectFormat.elf; - else if (os == Target.OS.Windows) + if (os == Target.OS.Windows) return Target.ObjectFormat.coff; - else - assert(0, "unkown object format"); + assert(0, "unkown object format"); } /** @@ -1057,8 +1056,8 @@ extern (C++) struct Target TypeTuple tt = toArgTypes_sysv_x64(tn); if (!tt) return false; // void - else - return !tt.arguments.length; + + return !tt.arguments.length; } Lagain: @@ -1144,8 +1143,8 @@ extern (C++) struct Target { if (tns.ty == TY.Tcomplex32) return false; // in EDX:EAX, not ST1:ST0 - else - return true; + + return true; } else if (os == Target.OS.Windows && isX86 && @@ -1257,10 +1256,9 @@ extern (C++) struct Target case objectFormat.stringof: if (os == Target.OS.Windows) return stringExp("coff"); - else if (os == Target.OS.OSX) + if (os == Target.OS.OSX) return stringExp("macho"); - else - return stringExp("elf"); + return stringExp("elf"); case floatAbi.stringof: return stringExp("hard"); case cppRuntimeLibrary.stringof: @@ -1555,8 +1553,8 @@ struct TargetCPP return toCppMangleItanium(s); if (target.os == Target.OS.Windows) return toCppMangleMSVC(s); - else - assert(0, "fix this"); + + assert(0, "fix this"); } /** @@ -1575,8 +1573,8 @@ struct TargetCPP return cppTypeInfoMangleItanium(cd); if (target.os == Target.OS.Windows) return cppTypeInfoMangleMSVC(cd); - else - assert(0, "fix this"); + + assert(0, "fix this"); } /** @@ -1645,8 +1643,8 @@ struct TargetCPP // MSVC adds padding between base and derived fields if required. if (target.os == Target.OS.Windows) return (baseClass.structsize + baseClass.alignsize - 1) & ~(baseClass.alignsize - 1); - else - return baseClass.structsize; + + return baseClass.structsize; } }