diff --git a/compiler/src/dmd/backend/arm/disasmarm.d b/compiler/src/dmd/backend/arm/disasmarm.d index d874d7a554..4a7735bb0e 100644 --- a/compiler/src/dmd/backend/arm/disasmarm.d +++ b/compiler/src/dmd/backend/arm/disasmarm.d @@ -274,8 +274,10 @@ void disassemble(uint c) @trusted uint ins = *(cast(uint*)&code[c]); p0[0]='\0'; - if (bObjectcode) { - for (i=siz; i; --i) { + if (bObjectcode) + { + for (i=siz; i; --i) + { snprintf( buf.ptr, buf.length, "%02X", code[c+i-1] ); printf("%s ", buf.ptr); //strcat( p0.ptr, buf.ptr ); diff --git a/compiler/src/dmd/backend/machobj.d b/compiler/src/dmd/backend/machobj.d index 7df4dc82c3..f8a79c34bd 100644 --- a/compiler/src/dmd/backend/machobj.d +++ b/compiler/src/dmd/backend/machobj.d @@ -53,7 +53,7 @@ alias nlist = dmd.backend.mach.nlist; // avoid conflict with dmd.backend.dlist * put before nothrow because qsort was not marked nothrow until version 2.086 */ -extern (C) { +extern (C) @trusted private int mach_rel_fp(scope const(void*) e1, scope const(void*) e2) { Relocation* r1 = cast(Relocation*)e1; @@ -61,7 +61,6 @@ private int mach_rel_fp(scope const(void*) e1, scope const(void*) e2) return cast(int)(r1.offset - r2.offset); } -} @trusted void mach_relsort(OutBuffer* buf) diff --git a/compiler/src/dmd/backend/mscoffobj.d b/compiler/src/dmd/backend/mscoffobj.d index d7c58ef0db..de75054143 100644 --- a/compiler/src/dmd/backend/mscoffobj.d +++ b/compiler/src/dmd/backend/mscoffobj.d @@ -2133,7 +2133,7 @@ void MsCoffObj_addrel(segidx_t seg, targ_size_t offset, Symbol* targsym, * Sort the relocation entry buffer. */ -extern (C) { +extern (C) @trusted private int mscoff_rel_fp(scope const(void*) e1, scope const(void*) e2) { Relocation* r1 = cast(Relocation*)e1; @@ -2141,7 +2141,6 @@ private int mscoff_rel_fp(scope const(void*) e1, scope const(void*) e2) return cast(int)(r1.offset - r2.offset); } -} /******************************* * Refer to address that is in the data segment. diff --git a/compiler/src/dmd/backend/x86/disasm86.d b/compiler/src/dmd/backend/x86/disasm86.d index 09eaaa0d08..bd5d78092f 100644 --- a/compiler/src/dmd/backend/x86/disasm86.d +++ b/compiler/src/dmd/backend/x86/disasm86.d @@ -651,7 +651,8 @@ char* getEAimpl(ubyte rex, uint c, int do_xmm, uint vlen) return displacementFixup(c + 2, 2, rmstr[rm]); case 3: - switch (opcode) { + switch (opcode) + { case 0x8c: case 0x8e: p = wordreg[rm]; @@ -1886,8 +1887,10 @@ void disassemble(uint c) p0[0]='\0'; if (opcode == 0 && c + 1 >= code.length) return; - if (bObjectcode) { - for (i=0; i isInRange!UAX31_Start(c), diff --git a/compiler/src/dmd/dinterpret.d b/compiler/src/dmd/dinterpret.d index 5dbab0918c..3a08c10daf 100644 --- a/compiler/src/dmd/dinterpret.d +++ b/compiler/src/dmd/dinterpret.d @@ -1989,13 +1989,15 @@ public: Declaration decl = ve.var; // We cannot take the address of an imported symbol at compile time - if (decl.isImportedSymbol()) { + if (decl.isImportedSymbol()) + { error(e.loc, "cannot take address of imported symbol `%s` at compile time", decl.toChars()); result = CTFEExp.cantexp; return; } - if (decl.isDataseg()) { + if (decl.isDataseg()) + { // Normally this is already done by optimize() // Do it here in case optimize(WANTvalue) wasn't run before CTFE emplaceExp!(SymOffExp)(pue, e.loc, e.e1.isVarExp().var, 0); diff --git a/compiler/src/dmd/doc.d b/compiler/src/dmd/doc.d index 0e77cdfc98..261fa387e0 100644 --- a/compiler/src/dmd/doc.d +++ b/compiler/src/dmd/doc.d @@ -2061,9 +2061,9 @@ string toLowercase(string s) pure @safe // TODO: maybe unicode lowercase, somehow if (c >= 'A' && c <= 'Z') { - if (!lower.length) { + if (!lower.length) lower.reserve(s.length); - } + lower ~= s[lower.length..i]; c += 'a' - 'A'; lower ~= c; diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 2e1ebee5ee..54c8e42192 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -5343,7 +5343,8 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc) { s = tident.toDsymbol(sc); // don't error for `var1.static_symbol` - if (s && s.needThis()) { + if (s && s.needThis()) + { error(ds.loc, "cannot alias %s member `%s` of variable `%s`", s.kind(), s.toChars(), mt.ident.toChars()); errorSupplemental(ds.loc, "Use `typeof(%s)` instead to preserve behaviour", diff --git a/compiler/src/dmd/dtoh.d b/compiler/src/dmd/dtoh.d index efd0a2f53e..a586f87490 100644 --- a/compiler/src/dmd/dtoh.d +++ b/compiler/src/dmd/dtoh.d @@ -976,7 +976,8 @@ public: { EnumKind kind = getEnumKind(type); - if (vd.visibility.kind == AST.Visibility.Kind.none || vd.visibility.kind == AST.Visibility.Kind.private_) { + if (vd.visibility.kind == AST.Visibility.Kind.none || vd.visibility.kind == AST.Visibility.Kind.private_) + { ignored("enum `%s` because it is `%s`.", vd.toPrettyChars(), AST.visibilityToChars(vd.visibility.kind)); return; } diff --git a/compiler/src/dmd/e2ir.d b/compiler/src/dmd/e2ir.d index a68123b2d3..f4a37c1549 100644 --- a/compiler/src/dmd/e2ir.d +++ b/compiler/src/dmd/e2ir.d @@ -6908,7 +6908,8 @@ elem* buildRangeError(ref IRState irs, Loc loc) * Returns: * elem generated */ -elem* buildArraySliceError(ref IRState irs, Loc loc, elem* lower, elem* upper, elem* length) { +elem* buildArraySliceError(ref IRState irs, Loc loc, elem* lower, elem* upper, elem* length) +{ final switch (irs.params.checkAction) { case CHECKACTION.C: @@ -6935,7 +6936,8 @@ elem* buildArraySliceError(ref IRState irs, Loc loc, elem* lower, elem* upper, e * Returns: * elem generated */ -elem* buildArrayIndexError(ref IRState irs, Loc loc, elem* index, elem* length) { +elem* buildArrayIndexError(ref IRState irs, Loc loc, elem* index, elem* length) +{ final switch (irs.params.checkAction) { case CHECKACTION.C: @@ -6951,7 +6953,8 @@ elem* buildArrayIndexError(ref IRState irs, Loc loc, elem* index, elem* length) } /// Returns: elem representing a C-string (char*) to the filename -elem* locToFileElem(const ref IRState irs, Loc loc) { +elem* locToFileElem(const ref IRState irs, Loc loc) +{ elem* efile; if (auto fname = loc.filename) diff --git a/compiler/src/dmd/file_manager.d b/compiler/src/dmd/file_manager.d index 7f39ec91f0..f2116e585d 100644 --- a/compiler/src/dmd/file_manager.d +++ b/compiler/src/dmd/file_manager.d @@ -101,8 +101,10 @@ private struct PathCache */ bool exists = true; auto st = PathStack(filespec); - while (st.up) { - if (auto cached = pathStatus.lookup(st.cur)) { + while (st.up) + { + if (auto cached = pathStatus.lookup(st.cur)) + { exists = cached.value; break; } @@ -112,7 +114,8 @@ private struct PathCache * Once a directory is found to not exist, all the directories * to the right of it do not exist */ - while (st.down) { + while (st.down) + { if (!exists) pathStatus.insert(st.cur, false); else @@ -218,17 +221,19 @@ nothrow: const(char)[] n = FileName.combine(p, sdi); - if (!pathCache.pathExists(n)) { + if (!pathCache.pathExists(n)) + { FileName.free(n.ptr); continue; // no need to check for anything else. } - if (FileName.exists(n) == 1) { + if (FileName.exists(n) == 1) return n; - } + FileName.free(n.ptr); n = FileName.combine(p, sd); - if (FileName.exists(n) == 1) { + if (FileName.exists(n) == 1) + { whichPathFoundThis = pathIndex; return n; } @@ -241,14 +246,16 @@ nothrow: if (pathCache.isExistingPath(n)) { const n2i = FileName.combine(n, package_di); - if (FileName.exists(n2i) == 1) { + if (FileName.exists(n2i) == 1) + { whichPathFoundThis = pathIndex; return n2i; } FileName.free(n2i.ptr); const n2 = FileName.combine(n, package_d); - if (FileName.exists(n2) == 1) { + if (FileName.exists(n2) == 1) + { whichPathFoundThis = pathIndex; return n2; } @@ -272,14 +279,16 @@ nothrow: const p = entry.path.toDString(); const(char)[] n = FileName.combine(p, si); - if (FileName.exists(n) == 1) { + if (FileName.exists(n) == 1) + { whichPathFoundThis = pathIndex; return n; } FileName.free(n.ptr); n = FileName.combine(p, sc); - if (FileName.exists(n) == 1) { + if (FileName.exists(n) == 1) + { whichPathFoundThis = pathIndex; return n; } diff --git a/compiler/src/dmd/json.d b/compiler/src/dmd/json.d index 05924f7b8b..490032066e 100644 --- a/compiler/src/dmd/json.d +++ b/compiler/src/dmd/json.d @@ -41,10 +41,13 @@ import dmd.root.string; import dmd.target; import dmd.visitor; -version(Windows) { +version(Windows) +{ extern (C) char* _getcwd(char* buffer, size_t maxlen); alias getcwd = _getcwd; -} else { +} +else +{ import core.sys.posix.unistd : getcwd; } diff --git a/compiler/src/dmd/lambdacomp.d b/compiler/src/dmd/lambdacomp.d index 90c794e240..96a17805d2 100644 --- a/compiler/src/dmd/lambdacomp.d +++ b/compiler/src/dmd/lambdacomp.d @@ -445,7 +445,8 @@ public: visitType(p.type); } - override void visit(StructLiteralExp e) { + override void visit(StructLiteralExp e) + { static if (LOG) printf("StructLiteralExp: %s\n", e.toChars); diff --git a/compiler/src/dmd/lexer.d b/compiler/src/dmd/lexer.d index 61b4f414c1..b327637312 100644 --- a/compiler/src/dmd/lexer.d +++ b/compiler/src/dmd/lexer.d @@ -3441,9 +3441,8 @@ class Lexer int linestart = 0; if (ct == '/') { - if (q < qend && *q == ' ') { + if (q < qend && *q == ' ') ++q; - } } else if (q < qend) { diff --git a/compiler/src/dmd/link.d b/compiler/src/dmd/link.d index 2b7b946101..ac785eee6d 100644 --- a/compiler/src/dmd/link.d +++ b/compiler/src/dmd/link.d @@ -1064,18 +1064,21 @@ public int runPreprocessor(Loc loc, const(char)[] cpp, const(char)[] filename, c if (!vsopt.VSInstallDir) vsopt.initialize(); - if (auto vcincludedir = vsopt.getVCIncludeDir()) { + if (auto vcincludedir = vsopt.getVCIncludeDir()) includePaths.push(vcincludedir); - } else { + else return STATUS_FAILED; - } - if (auto sdkincludedir = vsopt.getSDKIncludePath()) { + + if (auto sdkincludedir = vsopt.getSDKIncludePath()) + { includePaths.push(FileName.combine(sdkincludedir, "ucrt")); includePaths.push(FileName.combine(sdkincludedir, "shared")); includePaths.push(FileName.combine(sdkincludedir, "um")); includePaths.push(FileName.combine(sdkincludedir, "winrt")); includePaths.push(FileName.combine(sdkincludedir, "cppwinrt")); - } else { + } + else + { includePaths = Strings.init; return STATUS_FAILED; } @@ -1193,13 +1196,15 @@ public int runPreprocessor(Loc loc, const(char)[] cpp, const(char)[] filename, c // pipe so we can read the output of the preprocssor int[2] pipefd; // [0] is read, [1] is write - if (pipe(&pipefd[0]) == -1) { + if (pipe(&pipefd[0]) == -1) + { perror("pipe"); // failed to create pipe return STATUS_FAILED; } pid_t childpid = fork(); - if (childpid == -1) { + if (childpid == -1) + { perror("fork failed"); // fork failed return STATUS_FAILED; } @@ -1223,11 +1228,11 @@ public int runPreprocessor(Loc loc, const(char)[] cpp, const(char)[] filename, c OutBuffer buffer; ubyte[1024] tmp = void; ptrdiff_t nread; - while ((nread = read(pipefd[0], tmp.ptr, tmp.length)) > 0) { + while ((nread = read(pipefd[0], tmp.ptr, tmp.length)) > 0) buffer.write(tmp[0 .. nread]); - } - if (nread == -1) { + if (nread == -1) + { perror("read"); return STATUS_FAILED; } diff --git a/compiler/src/dmd/mars.d b/compiler/src/dmd/mars.d index 0d4ac15bf9..e4133ffe54 100644 --- a/compiler/src/dmd/mars.d +++ b/compiler/src/dmd/mars.d @@ -334,9 +334,8 @@ const(char)[] parse_conf_arg(Strings* args) const(char)[] arg = p.toDString; if (arg.length && arg[0] == '-') { - if(arg.length >= 6 && arg[1 .. 6] == "conf="){ + if(arg.length >= 6 && arg[1 .. 6] == "conf=") conf = arg[6 .. $]; - } else if (arg[1 .. $] == "run") break; } diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index 0e876ac654..5846613c9c 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -3863,7 +3863,8 @@ extern (C++) struct ParameterList foreach (_, p1; cast() this) { auto p2 = other[idx++]; - if (!p2 || p1 != p2) { + if (!p2 || p1 != p2) + { diff = true; break; } diff --git a/compiler/src/dmd/root/response.d b/compiler/src/dmd/root/response.d index 4a3044000d..257b1ea361 100644 --- a/compiler/src/dmd/root/response.d +++ b/compiler/src/dmd/root/response.d @@ -341,8 +341,8 @@ unittest * The null-terminator is inside the bounds of the array. * If cp could not be resolved, null is returned. */ -private char[] lookupInEnvironment(scope const(char)* cp) nothrow { - +private char[] lookupInEnvironment(scope const(char)* cp) nothrow +{ import core.stdc.stdlib: getenv; import core.stdc.string: strlen; import dmd.root.rmem: mem; diff --git a/compiler/src/dmd/root/string.d b/compiler/src/dmd/root/string.d index 847af0eab6..be606c41f7 100644 --- a/compiler/src/dmd/root/string.d +++ b/compiler/src/dmd/root/string.d @@ -377,9 +377,9 @@ auto splitLines(const char[] text) public const(char)[] front() { advance(); - if (index > eolIndex || index >= text.length) { + if (index > eolIndex || index >= text.length) return ""; - } + return text[index .. eolIndex]; } diff --git a/compiler/src/dmd/root/strtold.d b/compiler/src/dmd/root/strtold.d index 80091ea4a0..f74edab01d 100644 --- a/compiler/src/dmd/root/strtold.d +++ b/compiler/src/dmd/root/strtold.d @@ -356,7 +356,8 @@ longdouble_soft strtold_dm(const(char) *p, char **endp) pow >>= 1; u++; } - static if(0) { + static if(0) + { for (int i = 0; i < 5; i++) printf("%04x ",ldval.value[i]); printf("\n"); @@ -419,8 +420,8 @@ void main() /************************* Bigint ************************************/ -static if (0) { - +static if (0) +{ /* This program computes powers of 10 exactly. * Used to generate postab[]. */ diff --git a/compiler/src/dmd/sarif.d b/compiler/src/dmd/sarif.d index c6ea7d68e4..2af7c65312 100644 --- a/compiler/src/dmd/sarif.d +++ b/compiler/src/dmd/sarif.d @@ -63,7 +63,8 @@ string intToString(int value) nothrow { } /// Represents a SARIF result containing a rule ID, message, and location. -struct SarifResult { +struct SarifResult +{ string ruleId; /// Rule identifier. string message; /// Error or warning message. string uri; /// URI of the affected file. @@ -74,7 +75,8 @@ struct SarifResult { /// /// Returns: /// - A JSON string representing the SARIF result, including the rule ID, message, and location. - string toJson() nothrow { + string toJson() nothrow + { OutBuffer buffer; buffer.writestring(`{"ruleId": "`); buffer.writestring(ruleId); @@ -115,7 +117,8 @@ void addSarifDiagnostic(const SourceLoc loc, const(char)* format, va_list ap, Er } /// Represents a SARIF report containing tool information, invocation, and results. -struct SarifReport { +struct SarifReport +{ ToolInformation tool; /// Information about the analysis tool. Invocation invocation; /// Execution information. SarifResult[] results; /// List of SARIF results (errors, warnings, etc.). @@ -124,16 +127,19 @@ struct SarifReport { /// /// Returns: /// - A JSON string representing the SARIF report, including the tool information, invocation, and results. - string toJson() nothrow { + string toJson() nothrow + { OutBuffer buffer; buffer.writestring(`{"tool": `); buffer.writestring(tool.toJson()); buffer.writestring(`, "invocation": `); buffer.writestring(invocation.toJson()); buffer.writestring(`, "results": [`); - if (results.length > 0) { + if (results.length > 0) + { buffer.writestring(results[0].toJson()); - foreach (result; results[1 .. $]) { + foreach (result; results[1 .. $]) + { buffer.writestring(`, `); buffer.writestring(result.toJson()); } @@ -144,14 +150,16 @@ struct SarifReport { } /// Represents invocation information for the analysis process. -struct Invocation { +struct Invocation +{ bool executionSuccessful; /// Whether the execution was successful. /// Converts the invocation information to a JSON string. /// /// Returns: /// - A JSON representation of the invocation status. - string toJson() nothrow { + string toJson() nothrow + { OutBuffer buffer; buffer.writestring(`{"executionSuccessful": `); buffer.writestring(executionSuccessful ? "true" : "false"); @@ -170,7 +178,8 @@ Params: Returns: A formatted error message string. */ -string formatErrorMessage(const(char)* format, va_list ap) nothrow { +string formatErrorMessage(const(char)* format, va_list ap) nothrow +{ char[2048] buffer; import core.stdc.stdio : vsnprintf; vsnprintf(buffer.ptr, buffer.length, format, ap); @@ -188,7 +197,8 @@ Returns: */ string errorKindToString(ErrorKind kind) nothrow { - final switch (kind) { + final switch (kind) + { case ErrorKind.error: return "error"; // Serious problem case ErrorKind.warning: return "warning"; // Problem found case ErrorKind.deprecation: return "note"; // Minor problem, opportunity for improvement @@ -220,15 +230,15 @@ void generateSarifReport(bool executionSuccessful) nothrow // Extract and clean the version string string toolVersion = global.versionString(); // Remove 'v' prefix if it exists - if (toolVersion.length > 0 && toolVersion[0] == 'v') { + if (toolVersion.length > 0 && toolVersion[0] == 'v') toolVersion = toolVersion[1 .. $]; - } + // Find the first non-numeric character after the version number size_t length = toolVersion.length; const(char)* nonNumeric = strchr(toolVersion.ptr, '-'); - if (nonNumeric) { + if (nonNumeric) length = cast(size_t)(nonNumeric - toolVersion.ptr); - } + string cleanedVersion = toolVersion[0 .. length]; // Build SARIF report @@ -276,7 +286,8 @@ void generateSarifReport(bool executionSuccessful) nothrow ob.writestringln(`"results": [`); ob.level += 1; - foreach (idx, diag; diagnostics) { + foreach (idx, diag; diagnostics) + { ob.writestringln("{"); ob.level += 1; @@ -332,11 +343,10 @@ void generateSarifReport(bool executionSuccessful) nothrow // Closing brace for each diagnostic item ob.level -= 1; - if (idx < diagnostics.length - 1) { + if (idx < diagnostics.length - 1) ob.writestringln("},"); - } else { + else ob.writestringln("}"); - } } // Close the run and SARIF JSON diff --git a/compiler/src/dmd/sideeffect.d b/compiler/src/dmd/sideeffect.d index 9c69092ec5..659b0f4e0a 100644 --- a/compiler/src/dmd/sideeffect.d +++ b/compiler/src/dmd/sideeffect.d @@ -351,7 +351,8 @@ bool discardValue(Expression e) bool seenSideEffect = false; foreach(expr; [tmp.e1, tmp.e2]) { - if (hasSideEffect(expr)) { + if (hasSideEffect(expr)) + { errorSupplemental(expr.loc, "note that `%s` may have a side effect", expr.toErrMsg()); seenSideEffect |= true; } diff --git a/compiler/src/dmd/tokens.d b/compiler/src/dmd/tokens.d index e82a582bee..aad88d6bca 100644 --- a/compiler/src/dmd/tokens.d +++ b/compiler/src/dmd/tokens.d @@ -436,8 +436,10 @@ enum FirstCKeyword = TOK.inline; // Assert that all token enum members have consecutive values and // that none of them overlap static assert(() { - foreach (idx, enumName; __traits(allMembers, TOK)) { - static if (idx != __traits(getMember, TOK, enumName)) { + foreach (idx, enumName; __traits(allMembers, TOK)) + { + static if (idx != __traits(getMember, TOK, enumName)) + { pragma(msg, "Error: Expected TOK.", enumName, " to be ", idx, " but is ", __traits(getMember, TOK, enumName)); static assert(0); } @@ -925,13 +927,18 @@ nothrow: return 0; } - extern(D) void appendInterpolatedPart(const ref OutBuffer buf) { + extern(D) void appendInterpolatedPart(const ref OutBuffer buf) + { appendInterpolatedPart(cast(const(char)*)buf[].ptr, buf.length); } - extern(D) void appendInterpolatedPart(const(char)[] str) { + + extern(D) void appendInterpolatedPart(const(char)[] str) + { appendInterpolatedPart(str.ptr, str.length); } - extern(D) void appendInterpolatedPart(const(char)* ptr, size_t length) { + + extern(D) void appendInterpolatedPart(const(char)* ptr, size_t length) + { assert(value == TOK.interpolated); if (interpolatedSet is null) interpolatedSet = new InterpolatedSet;