chore: run dfmt on all files

_sigh_ should've done this at the beginning, but better late than never.

Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
This commit is contained in:
Prajwal S N 2023-12-29 14:14:32 +05:30
parent 7f81285c1f
commit 3eb09287b2
No known key found for this signature in database
GPG Key ID: 60701A603988FAC2
6 changed files with 61 additions and 72 deletions

View File

@ -160,8 +160,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
write(rrs); write(rrs);
writeSpace = true; writeSpace = true;
stc &= ~( stc &= ~(
ASTCodegen.STC.out_ | ASTCodegen.STC.scope_ | ASTCodegen.STC.ref_ | ASTCodegen ASTCodegen.STC.out_ | ASTCodegen.STC.scope_
.STC.return_); | ASTCodegen.STC.ref_ | ASTCodegen.STC.return_);
break; break;
} }
@ -312,8 +312,7 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
write(')'); write(')');
if (target.ptrsize == 8) if (target.ptrsize == 8)
goto case Tuns64; goto case Tuns64;
else if (target.ptrsize == 4 || else if (target.ptrsize == 4 || target.ptrsize == 2)
target.ptrsize == 2)
goto case Tuns32; goto case Tuns32;
else else
assert(0); assert(0);
@ -1084,10 +1083,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
} }
} }
void writeArgs( void writeArgs(ASTCodegen.Expressions* expressions,
ASTCodegen.Expressions* expressions, ASTCodegen.Expression basis = null, ASTCodegen.Identifiers* names = null)
ASTCodegen.Expression basis = null,
ASTCodegen.Identifiers* names = null)
{ {
if (!expressions || !expressions.length) if (!expressions || !expressions.length)
return; return;
@ -1228,8 +1225,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
void visitExp(ASTCodegen.ExpStatement s) void visitExp(ASTCodegen.ExpStatement s)
{ {
if (s.exp && s.exp.op == EXP.declaration && if (s.exp && s.exp.op == EXP.declaration
(cast(ASTCodegen.DeclarationExp) s.exp).declaration) && (cast(ASTCodegen.DeclarationExp) s.exp).declaration)
{ {
(cast(ASTCodegen.DeclarationExp) s.exp).declaration.accept(this); (cast(ASTCodegen.DeclarationExp) s.exp).declaration.accept(this);
return; return;
@ -1308,7 +1305,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
{ {
if (!insideCase) if (!insideCase)
{ {
if (config.dfmt_brace_style != BraceStyle.knr || s.statement.isCompoundStatement.statements.length != 1) if (config.dfmt_brace_style != BraceStyle.knr
|| s.statement.isCompoundStatement.statements.length != 1)
write('{'); write('{');
newline(); newline();
} }
@ -1318,7 +1316,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
depth--; depth--;
if (!insideCase) if (!insideCase)
{ {
if (config.dfmt_brace_style != BraceStyle.knr || s.statement.isCompoundStatement.statements.length != 1) if (config.dfmt_brace_style != BraceStyle.knr
|| s.statement.isCompoundStatement.statements.length != 1)
{ {
write('}'); write('}');
if (!insideIfOrDo) if (!insideIfOrDo)
@ -1374,8 +1373,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
} }
if (config.dfmt_brace_style == BraceStyle.otbs) if (config.dfmt_brace_style == BraceStyle.otbs)
write(' '); write(' ');
else if (config.dfmt_brace_style != BraceStyle.knr || s._body else if (config.dfmt_brace_style != BraceStyle.knr
.isScopeStatement.statement.isCompoundStatement.statements.length > 1) || s._body.isScopeStatement.statement.isCompoundStatement.statements.length > 1)
newline(); newline();
write("while"); write("while");
if (config.dfmt_space_after_keywords) if (config.dfmt_space_after_keywords)
@ -1556,8 +1555,9 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
{ {
if (config.dfmt_brace_style == BraceStyle.otbs) if (config.dfmt_brace_style == BraceStyle.otbs)
write(' '); write(' ');
else if (config.dfmt_brace_style != BraceStyle.knr || else if (config.dfmt_brace_style != BraceStyle.knr
s.ifbody.isScopeStatement.statement.isCompoundStatement.statements.length > 1) || s.ifbody.isScopeStatement.statement.isCompoundStatement.statements.length
> 1)
newline(); newline();
write("else"); write("else");
if (!s.elsebody.isIfStatement() && config.dfmt_brace_style == BraceStyle.allman) if (!s.elsebody.isIfStatement() && config.dfmt_brace_style == BraceStyle.allman)
@ -1938,14 +1938,12 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
while (t) while (t)
{ {
write(Token.toString(t.value)); write(Token.toString(t.value));
if (t.next && if (t.next && t.value != TOK.min && t.value != TOK.comma
t.value != TOK.min && && t.next.value != TOK.comma && t.value != TOK.leftBracket
t.value != TOK.comma && t.next.value != TOK.comma && && t.next.value != TOK.leftBracket && t.next.value != TOK.rightBracket
t.value != TOK.leftBracket && t.next.value != TOK.leftBracket && && t.value != TOK.leftParenthesis && t.next.value != TOK.leftParenthesis
t.next.value != TOK.rightBracket && && t.next.value != TOK.rightParenthesis
t.value != TOK.leftParenthesis && t.next.value != TOK.leftParenthesis && && t.value != TOK.dot && t.next.value != TOK.dot)
t.next.value != TOK.rightParenthesis &&
t.value != TOK.dot && t.next.value != TOK.dot)
{ {
write(' '); write(' ');
} }
@ -1982,8 +1980,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
void writeFuncBody(ASTCodegen.FuncDeclaration f) void writeFuncBody(ASTCodegen.FuncDeclaration f)
{ {
if (config.dfmt_brace_style == BraceStyle.allman || config.dfmt_brace_style == BraceStyle if (config.dfmt_brace_style == BraceStyle.allman || config.dfmt_brace_style
.knr) == BraceStyle.knr)
newline(); newline();
else else
write(' '); write(' ');
@ -2075,8 +2073,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
if (requireDo) if (requireDo)
{ {
write("do"); write("do");
if (config.dfmt_brace_style == BraceStyle.allman || config.dfmt_brace_style == BraceStyle if (config.dfmt_brace_style == BraceStyle.allman
.knr) || config.dfmt_brace_style == BraceStyle.knr)
newline(); newline();
else else
write(' '); write(' ');
@ -2285,8 +2283,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
writeExprWithPrecedence(e, PREC.assign); writeExprWithPrecedence(e, PREC.assign);
} }
void writeFuncIdentWithPrefix(TypeFunction t, const Identifier ident, ASTCodegen void writeFuncIdentWithPrefix(TypeFunction t, const Identifier ident,
.TemplateDeclaration td) ASTCodegen.TemplateDeclaration td)
{ {
if (t.inuse) if (t.inuse)
{ {
@ -2621,8 +2619,7 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
switch (t.ty) switch (t.ty)
{ {
default: default:
return t.isTypeBasic() ? return t.isTypeBasic() ? visitBasic(cast(TypeBasic) t) : visitType(t);
visitBasic(cast(TypeBasic) t) : visitType(t);
case Terror: case Terror:
return visitError(cast(TypeError) t); return visitError(cast(TypeError) t);
@ -2692,7 +2689,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
{ {
write('@'); write('@');
bool isAnonymous = p.userAttribDecl.atts.length > 0 && !(*p.userAttribDecl.atts)[0].isCallExp(); bool isAnonymous = p.userAttribDecl.atts.length > 0
&& !(*p.userAttribDecl.atts)[0].isCallExp();
if (isAnonymous) if (isAnonymous)
write('('); write('(');
@ -2719,9 +2717,9 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
stc &= ~STC.shared_; stc &= ~STC.shared_;
writeStc(stc & ( writeStc(stc & (
STC.const_ | STC.immutable_ | STC.wild | STC.shared_ | STC.const_ | STC.immutable_ | STC.wild | STC.shared_ | STC.return_
STC.return_ | STC.returninferred | STC.scope_ | STC.scopeinferred | STC.out_ | STC.ref_ | STC | STC.returninferred | STC.scope_ | STC.scopeinferred | STC.out_
.returnScope)); | STC.ref_ | STC.returnScope));
import core.stdc.string : strncmp; import core.stdc.string : strncmp;
@ -2730,10 +2728,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
if (p.ident) if (p.ident)
write(p.ident.toString()); write(p.ident.toString());
} }
else if (p.type.ty == Tident && else if (p.type.ty == Tident && (cast(TypeIdentifier) p.type)
(cast(TypeIdentifier) p.type) .ident.toString().length > 3 && strncmp((cast(TypeIdentifier) p.type)
.ident.toString().length > 3 &&
strncmp((cast(TypeIdentifier) p.type)
.ident.toChars(), "__T", 3) == 0) .ident.toChars(), "__T", 3) == 0)
{ {
// print parameter name, instead of undetermined type parameter // print parameter name, instead of undetermined type parameter
@ -2800,12 +2796,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
with (ASTCodegen.Visibility.Kind) with (ASTCodegen.Visibility.Kind)
{ {
immutable string[7] a = [ immutable string[7] a = [
none: "none", none: "none", private_: "private", package_: "package",
private_: "private", protected_: "protected", public_: "public", export_: "export"
package_: "package",
protected_: "protected",
public_: "public",
export_: "export"
]; ];
return a[kind]; return a[kind];
} }
@ -2831,8 +2823,9 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
RootObject oarg = (*ti.tiargs)[0]; RootObject oarg = (*ti.tiargs)[0];
if (Type t = isType(oarg)) if (Type t = isType(oarg))
{ {
if ((t.equals(Type.tstring) || t.equals(Type.twstring) || t.equals(Type.tdstring) || t.mod == 0) && ( if ((t.equals(Type.tstring) || t.equals(Type.twstring)
(t.isTypeBasic() || t.ty == Tident) && (cast(TypeIdentifier) t).idents.length == 0)) || t.equals(Type.tdstring) || t.mod == 0) && ((t.isTypeBasic()
|| t.ty == Tident) && (cast(TypeIdentifier) t).idents.length == 0))
{ {
write(t.toString()); write(t.toString());
return; return;
@ -2840,8 +2833,8 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
} }
else if (ASTCodegen.Expression e = isExpression(oarg)) else if (ASTCodegen.Expression e = isExpression(oarg))
{ {
if (e.op == EXP.int64 || e.op == EXP.float64 || e.op == EXP.null_ || e.op == EXP.string_ || e.op == EXP if (e.op == EXP.int64 || e.op == EXP.float64 || e.op == EXP.null_
.this_) || e.op == EXP.string_ || e.op == EXP.this_)
{ {
write(e.toString()); write(e.toString());
return; return;
@ -3547,8 +3540,7 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
{ {
import dmd.id : Id; import dmd.id : Id;
declString = (d.ident == Id.string || d.ident == Id.wstring || d.ident == Id declString = (d.ident == Id.string || d.ident == Id.wstring || d.ident == Id.dstring);
.dstring);
write(d.ident.toString()); write(d.ident.toString());
write(" = "); write(" = ");
writeStc(d.storage_class); writeStc(d.storage_class);

View File

@ -123,8 +123,7 @@ EC getConfigFor(EC)(string path)
{ {
import std.stdio : File; import std.stdio : File;
import std.regex : regex, match; import std.regex : regex, match;
import std.path : globMatch, dirName, baseName, pathSplitter, buildPath, import std.path : globMatch, dirName, baseName, pathSplitter, buildPath, absolutePath;
absolutePath;
import std.algorithm : reverse, map, filter; import std.algorithm : reverse, map, filter;
import std.array : array; import std.array : array;
import std.file : isDir; import std.file : isDir;
@ -141,7 +140,9 @@ EC getConfigFor(EC)(string path)
EC[] sections = parseConfig!EC(buildPath(pathParts[0 .. i])); EC[] sections = parseConfig!EC(buildPath(pathParts[0 .. i]));
if (sections.length) if (sections.length)
configs ~= sections; configs ~= sections;
if (!sections.map!(a => a.root).filter!(a => a == OptionalBoolean.t).empty) if (!sections.map!(a => a.root)
.filter!(a => a == OptionalBoolean.t)
.empty)
break; break;
} }
reverse(configs); reverse(configs);

View File

@ -55,8 +55,7 @@ int main(string[] args)
import std.exception : enforce; import std.exception : enforce;
enforce!GetOptException(value == "true" || value == "false", "Invalid argument"); enforce!GetOptException(value == "true" || value == "false", "Invalid argument");
immutable OptionalBoolean optVal = value == "true" ? OptionalBoolean.t immutable OptionalBoolean optVal = value == "true" ? OptionalBoolean.t : OptionalBoolean.f;
: OptionalBoolean.f;
switch (option) switch (option)
{ {
case "align_switch_statements": case "align_switch_statements":
@ -327,12 +326,10 @@ Options:
Formatting Options: Formatting Options:
--align_switch_statements --align_switch_statements
--brace_style `, optionsToString!(typeof(Config.dfmt_brace_style)), --brace_style `, optionsToString!(typeof(Config.dfmt_brace_style)), `
`
--end_of_line `, optionsToString!(typeof(Config.end_of_line)), ` --end_of_line `, optionsToString!(typeof(Config.end_of_line)), `
--indent_size --indent_size
--indent_style, -t `, --indent_style, -t `, optionsToString!(typeof(Config.indent_style)), `
optionsToString!(typeof(Config.indent_style)), `
--keep_line_breaks --keep_line_breaks
--soft_max_line_length --soft_max_line_length
--max_line_length --max_line_length
@ -349,8 +346,7 @@ Formatting Options:
--space_before_named_arg_colon --space_before_named_arg_colon
--single_indent --single_indent
--reflow_property_chains --reflow_property_chains
`, `, optionsToString!(typeof(Config.dfmt_template_constraint_style)));
optionsToString!(typeof(Config.dfmt_template_constraint_style)));
} }
private string createFilePath(bool readFromStdin, string fileName) private string createFilePath(bool readFromStdin, string fileName)