From ed188ee9be4358c43090d30e5738679f8435f334 Mon Sep 17 00:00:00 2001 From: Matthew Brennan Jones Date: Thu, 29 May 2014 17:19:25 -0700 Subject: [PATCH] Small cleanup of style and junk comments. --- analysis/base.d | 1 + analysis/duplicate_attribute.d | 2 +- analysis/enumarrayliteral.d | 1 + analysis/helpers.d | 17 ++++++++--------- analysis/ifelsesame.d | 13 +++---------- analysis/numbers.d | 1 + analysis/objectconst.d | 2 +- analysis/package.d | 1 + analysis/pokemon.d | 9 +++++---- analysis/range.d | 4 ++-- analysis/run.d | 2 +- analysis/unused.d | 1 + astprinter.d | 1 + ctags.d | 1 + formatter.d | 5 +++-- highlighter.d | 5 +++-- stats.d | 3 ++- std/allocator.d | 1 + std/d/entities.d | 1 + std/d/lexer.d | 23 ++++++++++++----------- std/d/parser.d | 27 ++++++++++++++------------- std/lexer.d | 7 ++++--- 22 files changed, 68 insertions(+), 60 deletions(-) diff --git a/analysis/base.d b/analysis/base.d index f84363a..bdb9223 100644 --- a/analysis/base.d +++ b/analysis/base.d @@ -59,3 +59,4 @@ protected: MessageSet _messages; } + diff --git a/analysis/duplicate_attribute.d b/analysis/duplicate_attribute.d index 556d319..c36041e 100644 --- a/analysis/duplicate_attribute.d +++ b/analysis/duplicate_attribute.d @@ -14,7 +14,7 @@ import analysis.helpers; /** - * Checks for duplicate attributes such as @property, @safe, + * Checks for duplicate attributes such as @property, @safe, * @trusted, @system, pure, and nothrow */ class DuplicateAttributeCheck : BaseAnalyzer diff --git a/analysis/enumarrayliteral.d b/analysis/enumarrayliteral.d index 6c065ac..8120d19 100644 --- a/analysis/enumarrayliteral.d +++ b/analysis/enumarrayliteral.d @@ -59,3 +59,4 @@ class EnumArrayLiteralCheck : BaseAnalyzer autoDec.accept(this); } } + diff --git a/analysis/helpers.d b/analysis/helpers.d index 6c22aea..54ead36 100644 --- a/analysis/helpers.d +++ b/analysis/helpers.d @@ -44,7 +44,7 @@ S after(S)(S value, S separator) } /** - * This assert function will analyze the passed in code, get the warnings, + * This assert function will analyze the passed in code, get the warnings, * and make sure they match the warnings in the comments. Warnings are * marked like so: // [warn]: Failed to do somethings. */ @@ -100,8 +100,8 @@ void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, s if (lineNo !in warnings) { string errors = "Expected warning:\n%s\nFrom source code at (%s:?):\n%s".format( - messages[lineNo], - lineNo, + messages[lineNo], + lineNo, codeLines[lineNo - line] ); throw new core.exception.AssertError(errors, file, lineNo); @@ -110,9 +110,9 @@ void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, s else if (warnings[lineNo] != messages[lineNo]) { string errors = "Expected warning:\n%s\nBut was:\n%s\nFrom source code at (%s:?):\n%s".format( - messages[lineNo], - warnings[lineNo], - lineNo, + messages[lineNo], + warnings[lineNo], + lineNo, codeLines[lineNo - line] ); throw new core.exception.AssertError(errors, file, lineNo); @@ -127,8 +127,8 @@ void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, s if (lineNo !in messages) { unexpectedWarnings ~= "%s\nFrom source code at (%s:?):\n%s".format( - warning, - lineNo, + warning, + lineNo, codeLines[lineNo - line] ); } @@ -140,4 +140,3 @@ void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, s } } - diff --git a/analysis/ifelsesame.d b/analysis/ifelsesame.d index 7a02d13..078d946 100644 --- a/analysis/ifelsesame.d +++ b/analysis/ifelsesame.d @@ -52,24 +52,17 @@ unittest void testSizeT() { string person = "unknown"; - if(person == "unknown")// [warn]: "Else" branch is identical to "Then" branch. - { + if (person == "unknown") // [warn]: "Else" branch is identical to "Then" branch. person = "bobrick"; // same - } else - { person = "bobrick"; // same - } - if(person == "unknown") // ok - { + if (person == "unknown") // ok person = "ricky"; // not same - } else - { person = "bobby"; // not same - } } }c, analysis.run.AnalyzerCheck.if_else_same_check); stderr.writeln("Unittest for IfElseSameCheck passed."); } + diff --git a/analysis/numbers.d b/analysis/numbers.d index e9935a7..6791f92 100644 --- a/analysis/numbers.d +++ b/analysis/numbers.d @@ -58,3 +58,4 @@ unittest stderr.writeln("Unittest for NumberStyleCheck passed."); } + diff --git a/analysis/objectconst.d b/analysis/objectconst.d index f8fc5d8..ea4cb25 100644 --- a/analysis/objectconst.d +++ b/analysis/objectconst.d @@ -116,7 +116,7 @@ unittest return 0; } - string toString()// [warn]: opCmp, toHash, opEquals, and toString should be declared const + string toString() // [warn]: opCmp, toHash, opEquals, and toString should be declared const { return "Dog"; } diff --git a/analysis/package.d b/analysis/package.d index 225b82e..8be9d25 100644 --- a/analysis/package.d +++ b/analysis/package.d @@ -4,3 +4,4 @@ public import analysis.style; public import analysis.enumarrayliteral; public import analysis.pokemon; public import analysis.base; + diff --git a/analysis/pokemon.d b/analysis/pokemon.d index f699234..9a8bf17 100644 --- a/analysis/pokemon.d +++ b/analysis/pokemon.d @@ -73,19 +73,19 @@ unittest { // ... } - catch(AssertError err) //ok + catch (AssertError err) //ok { } - catch(Exception err) // ok + catch (Exception err) // ok { } - catch(Error err) // [warn]: Catching Error or Throwable is almost always a bad idea + catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea { } - catch(Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea + catch (Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea { } @@ -97,3 +97,4 @@ unittest stderr.writeln("Unittest for PokemonExceptionCheck passed."); } + diff --git a/analysis/range.d b/analysis/range.d index 965a334..75327e6 100644 --- a/analysis/range.d +++ b/analysis/range.d @@ -139,8 +139,8 @@ unittest data = data[1 .. 3]; // ok data = data[3 .. 1]; // [warn]: 3 is larger than 1. This slice is likely incorrect. - foreach(n; 1 .. 3) { } // ok - foreach(n; 3 .. 1) { } // [warn]: 3 is larger than 1. Did you mean to use 'foreach_reverse( ... ; 1 .. 3)'? + foreach (n; 1 .. 3) { } // ok + foreach (n; 3 .. 1) { } // [warn]: 3 is larger than 1. Did you mean to use 'foreach_reverse( ... ; 1 .. 3)'? } }c, analysis.run.AnalyzerCheck.backwards_range_check); diff --git a/analysis/run.d b/analysis/run.d index 15f6079..331e64b 100644 --- a/analysis/run.d +++ b/analysis/run.d @@ -114,7 +114,7 @@ string[] analyze(string fileName, ubyte[] code, AnalyzerCheck analyzers, bool st } MessageSet set = new MessageSet; - foreach(check; checks) + foreach (check; checks) foreach (message; check.messages) set.insert(message); diff --git a/analysis/unused.d b/analysis/unused.d index 928fda0..32eb8db 100644 --- a/analysis/unused.d +++ b/analysis/unused.d @@ -335,3 +335,4 @@ class UnusedVariableCheck : BaseAnalyzer bool blockStatementIntroducesScope = true; } + diff --git a/astprinter.d b/astprinter.d index c805469..7a4bce8 100644 --- a/astprinter.d +++ b/astprinter.d @@ -1519,3 +1519,4 @@ class XMLPrinter : ASTVisitor File output; } + diff --git a/ctags.d b/ctags.d index 9b53fa2..ae7d506 100644 --- a/ctags.d +++ b/ctags.d @@ -168,3 +168,4 @@ class CTagsPrinter : ASTVisitor int suppressDepth; string context; } + diff --git a/formatter.d b/formatter.d index b2008d2..11ecb38 100644 --- a/formatter.d +++ b/formatter.d @@ -343,7 +343,7 @@ class Formatter(Sink) void format(const IdentifierChain identifierChain) { bool first = true; - foreach(ident; identifierChain.identifiers) + foreach (ident; identifierChain.identifiers) { if (!first) sink.put("."); @@ -358,7 +358,7 @@ class Formatter(Sink) void format(const IdentifierOrTemplateChain identifierOrTemplateChain) { bool first = true; - foreach(ident; identifierOrTemplateChain.identifiersOrTemplateInstances) + foreach (ident; identifierOrTemplateChain.identifiersOrTemplateInstances) { if (!first) sink.put("."); @@ -832,3 +832,4 @@ private: IndentStyle style; Sink sink; } + diff --git a/highlighter.d b/highlighter.d index cf48e27..7f9dfe2 100644 --- a/highlighter.d +++ b/highlighter.d @@ -53,7 +53,7 @@ html { background-color: #fdf6e3; color: #002b36; } writeSpan("cons", t.text.replace("<", "<")); else { - version(Windows) + version (Windows) { // Stupid Windows automatically does a LF → CRLF, so // CRLF → CRCRLF, which is obviously wrong. @@ -70,8 +70,9 @@ html { background-color: #fdf6e3; color: #002b36; } void writeSpan(string cssClass, string value) { - version(Windows) + version (Windows) stdout.write(``, value.replace("&", "&").replace("<", "<").replace("\r", ""), ``); else stdout.write(``, value.replace("&", "&").replace("<", "<"), ``); } + diff --git a/stats.d b/stats.d index e09d5e5..cbc8e3b 100644 --- a/stats.d +++ b/stats.d @@ -11,7 +11,7 @@ import std.d.lexer; pure nothrow bool isLineOfCode(IdType t) { - switch(t) + switch (t) { case tok!";": case tok!"while": @@ -52,3 +52,4 @@ ulong printLineCount(Tokens)(File output, string fileName, ref Tokens tokens) output.writefln("%s:\t%d", fileName, count); return count; } + diff --git a/std/allocator.d b/std/allocator.d index e4aae8e..499262e 100644 --- a/std/allocator.d +++ b/std/allocator.d @@ -4614,3 +4614,4 @@ version(none) struct TemplateAllocator } static shared TemplateAllocator it; } + diff --git a/std/d/entities.d b/std/d/entities.d index 65aa8ce..f9df641 100644 --- a/std/d/entities.d +++ b/std/d/entities.d @@ -2147,3 +2147,4 @@ immutable HtmlEntity[] characterEntities = [ HtmlEntity("zwj", "\u200D"), HtmlEntity("zwnj", "\u200C") ]; + diff --git a/std/d/lexer.d b/std/d/lexer.d index a4c0e75..1bc382c 100644 --- a/std/d/lexer.d +++ b/std/d/lexer.d @@ -1199,9 +1199,9 @@ public struct DLexer Token lexTokenString() pure { mixin (tokenStart); - assert(range.front == 'q'); + assert (range.front == 'q'); range.popFront(); - assert(range.front == '{'); + assert (range.front == '{'); range.popFront(); auto app = appender!string(); app.put("q{"); @@ -1679,7 +1679,7 @@ public: free(cast(void*) prev.bytes.ptr); free(cast(void*) prev); } - foreach(nodePointer; buckets) + foreach (nodePointer; buckets) { Node* currentNode = nodePointer; while (currentNode !is null) @@ -1956,15 +1956,16 @@ unittest // valid enum hex = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F']; auto source = ""; - foreach(h1; hex) - foreach(h2; hex) + foreach (h1; hex) + foreach (h2; hex) source ~= "'\\x" ~ h1 ~ h2 ~ "'"; - assert(toks(source).filter!(t => t.type != tok!"characterLiteral").empty); + assert (toks(source).filter!(t => t.type != tok!"characterLiteral").empty); // invalid - assert(toks(`'\x'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); - assert(toks(`'\x_'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); - assert(toks(`'\xA'`).messages[0] == DLexer.Message(1,5,"Error: 2 hex digits expected.",true)); - assert(toks(`'\xAY'`).messages[0] == DLexer.Message(1,5,"Error: 2 hex digits expected.",true)); - assert(toks(`'\xXX'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); + assert (toks(`'\x'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); + assert (toks(`'\x_'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); + assert (toks(`'\xA'`).messages[0] == DLexer.Message(1,5,"Error: 2 hex digits expected.",true)); + assert (toks(`'\xAY'`).messages[0] == DLexer.Message(1,5,"Error: 2 hex digits expected.",true)); + assert (toks(`'\xXX'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); } + diff --git a/std/d/parser.d b/std/d/parser.d index 3db48d0..ad47494 100644 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -1259,7 +1259,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c; assert (classZero.structBody is null); auto classOne = p.parseClassDeclaration(); - assert (classOne.name.text == "ClassOne"); // FIXME classOne.name.text is "ClassZero" on my machine TM + assert (classOne.name.text == "ClassOne"); assert (classOne.structBody.declarations.length == 0); assert (classOne.baseClassList is null); assert (classOne.constraint is null); @@ -1412,7 +1412,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c; trueDeclarations ~= dec; node.trueDeclarations = ownArray(trueDeclarations); - if(currentIs(tok!"else")) + if (currentIs(tok!"else")) advance(); else return node; @@ -1491,7 +1491,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c; if (node.parameters is null) return null; MemberFunctionAttribute[] memberFunctionAttributes; - while(moreTokens() && currentIsMemberFunctionAttribute()) + while (moreTokens() && currentIsMemberFunctionAttribute()) memberFunctionAttributes ~= parseMemberFunctionAttribute(); node.memberFunctionAttributes = ownArray(memberFunctionAttributes); @@ -1995,7 +1995,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c; else { MemberFunctionAttribute[] memberFunctionAttributes; - while(moreTokens() && currentIsMemberFunctionAttribute()) + while (moreTokens() && currentIsMemberFunctionAttribute()) memberFunctionAttributes ~= parseMemberFunctionAttribute(); node.memberFunctionAttributes = ownArray(memberFunctionAttributes); node.functionBody = parseFunctionBody(); @@ -2544,7 +2544,7 @@ body {} // six if (isAuto) goto functionName; - while(moreTokens() && currentIsMemberFunctionAttribute()) + while (moreTokens() && currentIsMemberFunctionAttribute()) memberFunctionAttributes ~= parseMemberFunctionAttribute(); node.returnType = type is null ? parseType() : type; @@ -2571,7 +2571,7 @@ body {} // six node.parameters = parseParameters(); if (node.parameters is null) return null; - while(moreTokens() && currentIsMemberFunctionAttribute()) + while (moreTokens() && currentIsMemberFunctionAttribute()) memberFunctionAttributes ~= parseMemberFunctionAttribute(); if (isTemplate && currentIs(tok!"if")) @@ -3434,7 +3434,7 @@ invariant() foo(); { advance(); node.hasPlusPlus = true; - version(DIP61) if (currentIs(tok!",")) + version (DIP61) if (currentIs(tok!",")) { advance(); node.identifierChain = parseIdentifierChain(); @@ -5226,7 +5226,7 @@ q{(int a, ...) node.templateAliasParameter = parseTemplateAliasParameter(); break; case tok!"identifier": - if(peekIs(tok!"...")) + if (peekIs(tok!"...")) node.templateTupleParameter = parseTemplateTupleParameter(); else if (peekIsOneOf(tok!":", tok!"=", tok!",", tok!")")) node.templateTypeParameter = parseTemplateTypeParameter(); @@ -5536,7 +5536,7 @@ q{(int a, ...) { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!Type; - switch(current.type) + switch (current.type) { case tok!"const": case tok!"immutable": @@ -5753,7 +5753,7 @@ q{(int a, ...) { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!TypeSuffix; - switch(current.type) + switch (current.type) { case tok!"*": node.star = true; @@ -6100,7 +6100,7 @@ q{doStuff(5)}c; node.comment = comment; Declarator[] declarators; - while(true) + while (true) { auto declarator = parseDeclarator(); if (declarator is null) return null; @@ -6344,7 +6344,7 @@ protected: mixin(traceEnterAndExit!(__FUNCTION__)); auto i = index; scope(exit) index = i; - assert(currentIs(L)); + assert (currentIs(L)); advance(); while (moreTokens()) switch (current.type) { @@ -6685,7 +6685,7 @@ protected: void skip(alias O, alias C)() { - assert(currentIs(O), current().text); + assert (currentIs(O), current().text); advance(); int depth = 1; while (moreTokens()) @@ -7018,3 +7018,4 @@ protected: int _traceDepth; string comment; } + diff --git a/std/lexer.d b/std/lexer.d index a9f05a6..544c73d 100644 --- a/std/lexer.d +++ b/std/lexer.d @@ -173,9 +173,9 @@ unittest enum tok(string token) = TokenId!(IdType, ["foo"], ["bar"], ["doo"], token); alias str = tokenStringRepresentation!(IdType, ["foo"], ["bar"], ["doo"]); - static assert(str(tok!"foo") == "foo"); - static assert(str(tok!"bar") == "bar"); - static assert(str(tok!"doo") == "doo"); + static assert (str(tok!"foo") == "foo"); + static assert (str(tok!"bar") == "bar"); + static assert (str(tok!"doo") == "doo"); } /** @@ -772,3 +772,4 @@ struct LexerRange */ size_t line; } +