Small cleanup of style and junk comments.

This commit is contained in:
Matthew Brennan Jones 2014-05-29 17:19:25 -07:00
parent 34b312b45e
commit ed188ee9be
22 changed files with 68 additions and 60 deletions

View File

@ -59,3 +59,4 @@ protected:
MessageSet _messages; MessageSet _messages;
} }

View File

@ -59,3 +59,4 @@ class EnumArrayLiteralCheck : BaseAnalyzer
autoDec.accept(this); autoDec.accept(this);
} }
} }

View File

@ -140,4 +140,3 @@ void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, s
} }
} }

View File

@ -52,24 +52,17 @@ unittest
void testSizeT() void testSizeT()
{ {
string person = "unknown"; 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 person = "bobrick"; // same
}
else else
{
person = "bobrick"; // same person = "bobrick"; // same
}
if(person == "unknown") // ok if (person == "unknown") // ok
{
person = "ricky"; // not same person = "ricky"; // not same
}
else else
{
person = "bobby"; // not same person = "bobby"; // not same
} }
}
}c, analysis.run.AnalyzerCheck.if_else_same_check); }c, analysis.run.AnalyzerCheck.if_else_same_check);
stderr.writeln("Unittest for IfElseSameCheck passed."); stderr.writeln("Unittest for IfElseSameCheck passed.");
} }

View File

@ -58,3 +58,4 @@ unittest
stderr.writeln("Unittest for NumberStyleCheck passed."); stderr.writeln("Unittest for NumberStyleCheck passed.");
} }

View File

@ -116,7 +116,7 @@ unittest
return 0; 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"; return "Dog";
} }

View File

@ -4,3 +4,4 @@ public import analysis.style;
public import analysis.enumarrayliteral; public import analysis.enumarrayliteral;
public import analysis.pokemon; public import analysis.pokemon;
public import analysis.base; public import analysis.base;

View File

@ -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."); stderr.writeln("Unittest for PokemonExceptionCheck passed.");
} }

View File

@ -139,8 +139,8 @@ unittest
data = data[1 .. 3]; // ok data = data[1 .. 3]; // ok
data = data[3 .. 1]; // [warn]: 3 is larger than 1. This slice is likely incorrect. data = data[3 .. 1]; // [warn]: 3 is larger than 1. This slice is likely incorrect.
foreach(n; 1 .. 3) { } // ok 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; 3 .. 1) { } // [warn]: 3 is larger than 1. Did you mean to use 'foreach_reverse( ... ; 1 .. 3)'?
} }
}c, analysis.run.AnalyzerCheck.backwards_range_check); }c, analysis.run.AnalyzerCheck.backwards_range_check);

View File

@ -114,7 +114,7 @@ string[] analyze(string fileName, ubyte[] code, AnalyzerCheck analyzers, bool st
} }
MessageSet set = new MessageSet; MessageSet set = new MessageSet;
foreach(check; checks) foreach (check; checks)
foreach (message; check.messages) foreach (message; check.messages)
set.insert(message); set.insert(message);

View File

@ -335,3 +335,4 @@ class UnusedVariableCheck : BaseAnalyzer
bool blockStatementIntroducesScope = true; bool blockStatementIntroducesScope = true;
} }

View File

@ -1519,3 +1519,4 @@ class XMLPrinter : ASTVisitor
File output; File output;
} }

View File

@ -168,3 +168,4 @@ class CTagsPrinter : ASTVisitor
int suppressDepth; int suppressDepth;
string context; string context;
} }

View File

@ -343,7 +343,7 @@ class Formatter(Sink)
void format(const IdentifierChain identifierChain) void format(const IdentifierChain identifierChain)
{ {
bool first = true; bool first = true;
foreach(ident; identifierChain.identifiers) foreach (ident; identifierChain.identifiers)
{ {
if (!first) if (!first)
sink.put("."); sink.put(".");
@ -358,7 +358,7 @@ class Formatter(Sink)
void format(const IdentifierOrTemplateChain identifierOrTemplateChain) void format(const IdentifierOrTemplateChain identifierOrTemplateChain)
{ {
bool first = true; bool first = true;
foreach(ident; identifierOrTemplateChain.identifiersOrTemplateInstances) foreach (ident; identifierOrTemplateChain.identifiersOrTemplateInstances)
{ {
if (!first) if (!first)
sink.put("."); sink.put(".");
@ -832,3 +832,4 @@ private:
IndentStyle style; IndentStyle style;
Sink sink; Sink sink;
} }

View File

@ -53,7 +53,7 @@ html { background-color: #fdf6e3; color: #002b36; }
writeSpan("cons", t.text.replace("<", "&lt;")); writeSpan("cons", t.text.replace("<", "&lt;"));
else else
{ {
version(Windows) version (Windows)
{ {
// Stupid Windows automatically does a LF → CRLF, so // Stupid Windows automatically does a LF → CRLF, so
// CRLF → CRCRLF, which is obviously wrong. // CRLF → CRCRLF, which is obviously wrong.
@ -70,8 +70,9 @@ html { background-color: #fdf6e3; color: #002b36; }
void writeSpan(string cssClass, string value) void writeSpan(string cssClass, string value)
{ {
version(Windows) version (Windows)
stdout.write(`<span class="`, cssClass, `">`, value.replace("&", "&amp;").replace("<", "&lt;").replace("\r", ""), `</span>`); stdout.write(`<span class="`, cssClass, `">`, value.replace("&", "&amp;").replace("<", "&lt;").replace("\r", ""), `</span>`);
else else
stdout.write(`<span class="`, cssClass, `">`, value.replace("&", "&amp;").replace("<", "&lt;"), `</span>`); stdout.write(`<span class="`, cssClass, `">`, value.replace("&", "&amp;").replace("<", "&lt;"), `</span>`);
} }

View File

@ -11,7 +11,7 @@ import std.d.lexer;
pure nothrow bool isLineOfCode(IdType t) pure nothrow bool isLineOfCode(IdType t)
{ {
switch(t) switch (t)
{ {
case tok!";": case tok!";":
case tok!"while": case tok!"while":
@ -52,3 +52,4 @@ ulong printLineCount(Tokens)(File output, string fileName, ref Tokens tokens)
output.writefln("%s:\t%d", fileName, count); output.writefln("%s:\t%d", fileName, count);
return count; return count;
} }

View File

@ -4614,3 +4614,4 @@ version(none) struct TemplateAllocator
} }
static shared TemplateAllocator it; static shared TemplateAllocator it;
} }

View File

@ -2147,3 +2147,4 @@ immutable HtmlEntity[] characterEntities = [
HtmlEntity("zwj", "\u200D"), HtmlEntity("zwj", "\u200D"),
HtmlEntity("zwnj", "\u200C") HtmlEntity("zwnj", "\u200C")
]; ];

View File

@ -1199,9 +1199,9 @@ public struct DLexer
Token lexTokenString() pure Token lexTokenString() pure
{ {
mixin (tokenStart); mixin (tokenStart);
assert(range.front == 'q'); assert (range.front == 'q');
range.popFront(); range.popFront();
assert(range.front == '{'); assert (range.front == '{');
range.popFront(); range.popFront();
auto app = appender!string(); auto app = appender!string();
app.put("q{"); app.put("q{");
@ -1679,7 +1679,7 @@ public:
free(cast(void*) prev.bytes.ptr); free(cast(void*) prev.bytes.ptr);
free(cast(void*) prev); free(cast(void*) prev);
} }
foreach(nodePointer; buckets) foreach (nodePointer; buckets)
{ {
Node* currentNode = nodePointer; Node* currentNode = nodePointer;
while (currentNode !is null) while (currentNode !is null)
@ -1956,15 +1956,16 @@ unittest
// valid // 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']; 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 = ""; auto source = "";
foreach(h1; hex) foreach (h1; hex)
foreach(h2; hex) foreach (h2; hex)
source ~= "'\\x" ~ h1 ~ h2 ~ "'"; 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 // 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(`'\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(`'\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(`'\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(`'\xXX'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true));
} }

View File

@ -1259,7 +1259,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c;
assert (classZero.structBody is null); assert (classZero.structBody is null);
auto classOne = p.parseClassDeclaration(); 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.structBody.declarations.length == 0);
assert (classOne.baseClassList is null); assert (classOne.baseClassList is null);
assert (classOne.constraint is null); assert (classOne.constraint is null);
@ -1412,7 +1412,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c;
trueDeclarations ~= dec; trueDeclarations ~= dec;
node.trueDeclarations = ownArray(trueDeclarations); node.trueDeclarations = ownArray(trueDeclarations);
if(currentIs(tok!"else")) if (currentIs(tok!"else"))
advance(); advance();
else else
return node; return node;
@ -1491,7 +1491,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c;
if (node.parameters is null) return null; if (node.parameters is null) return null;
MemberFunctionAttribute[] memberFunctionAttributes; MemberFunctionAttribute[] memberFunctionAttributes;
while(moreTokens() && currentIsMemberFunctionAttribute()) while (moreTokens() && currentIsMemberFunctionAttribute())
memberFunctionAttributes ~= parseMemberFunctionAttribute(); memberFunctionAttributes ~= parseMemberFunctionAttribute();
node.memberFunctionAttributes = ownArray(memberFunctionAttributes); node.memberFunctionAttributes = ownArray(memberFunctionAttributes);
@ -1995,7 +1995,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c;
else else
{ {
MemberFunctionAttribute[] memberFunctionAttributes; MemberFunctionAttribute[] memberFunctionAttributes;
while(moreTokens() && currentIsMemberFunctionAttribute()) while (moreTokens() && currentIsMemberFunctionAttribute())
memberFunctionAttributes ~= parseMemberFunctionAttribute(); memberFunctionAttributes ~= parseMemberFunctionAttribute();
node.memberFunctionAttributes = ownArray(memberFunctionAttributes); node.memberFunctionAttributes = ownArray(memberFunctionAttributes);
node.functionBody = parseFunctionBody(); node.functionBody = parseFunctionBody();
@ -2544,7 +2544,7 @@ body {} // six
if (isAuto) if (isAuto)
goto functionName; goto functionName;
while(moreTokens() && currentIsMemberFunctionAttribute()) while (moreTokens() && currentIsMemberFunctionAttribute())
memberFunctionAttributes ~= parseMemberFunctionAttribute(); memberFunctionAttributes ~= parseMemberFunctionAttribute();
node.returnType = type is null ? parseType() : type; node.returnType = type is null ? parseType() : type;
@ -2571,7 +2571,7 @@ body {} // six
node.parameters = parseParameters(); node.parameters = parseParameters();
if (node.parameters is null) return null; if (node.parameters is null) return null;
while(moreTokens() && currentIsMemberFunctionAttribute()) while (moreTokens() && currentIsMemberFunctionAttribute())
memberFunctionAttributes ~= parseMemberFunctionAttribute(); memberFunctionAttributes ~= parseMemberFunctionAttribute();
if (isTemplate && currentIs(tok!"if")) if (isTemplate && currentIs(tok!"if"))
@ -3434,7 +3434,7 @@ invariant() foo();
{ {
advance(); advance();
node.hasPlusPlus = true; node.hasPlusPlus = true;
version(DIP61) if (currentIs(tok!",")) version (DIP61) if (currentIs(tok!","))
{ {
advance(); advance();
node.identifierChain = parseIdentifierChain(); node.identifierChain = parseIdentifierChain();
@ -5226,7 +5226,7 @@ q{(int a, ...)
node.templateAliasParameter = parseTemplateAliasParameter(); node.templateAliasParameter = parseTemplateAliasParameter();
break; break;
case tok!"identifier": case tok!"identifier":
if(peekIs(tok!"...")) if (peekIs(tok!"..."))
node.templateTupleParameter = parseTemplateTupleParameter(); node.templateTupleParameter = parseTemplateTupleParameter();
else if (peekIsOneOf(tok!":", tok!"=", tok!",", tok!")")) else if (peekIsOneOf(tok!":", tok!"=", tok!",", tok!")"))
node.templateTypeParameter = parseTemplateTypeParameter(); node.templateTypeParameter = parseTemplateTypeParameter();
@ -5536,7 +5536,7 @@ q{(int a, ...)
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = allocate!Type; auto node = allocate!Type;
switch(current.type) switch (current.type)
{ {
case tok!"const": case tok!"const":
case tok!"immutable": case tok!"immutable":
@ -5753,7 +5753,7 @@ q{(int a, ...)
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = allocate!TypeSuffix; auto node = allocate!TypeSuffix;
switch(current.type) switch (current.type)
{ {
case tok!"*": case tok!"*":
node.star = true; node.star = true;
@ -6100,7 +6100,7 @@ q{doStuff(5)}c;
node.comment = comment; node.comment = comment;
Declarator[] declarators; Declarator[] declarators;
while(true) while (true)
{ {
auto declarator = parseDeclarator(); auto declarator = parseDeclarator();
if (declarator is null) return null; if (declarator is null) return null;
@ -6344,7 +6344,7 @@ protected:
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto i = index; auto i = index;
scope(exit) index = i; scope(exit) index = i;
assert(currentIs(L)); assert (currentIs(L));
advance(); advance();
while (moreTokens()) switch (current.type) while (moreTokens()) switch (current.type)
{ {
@ -6685,7 +6685,7 @@ protected:
void skip(alias O, alias C)() void skip(alias O, alias C)()
{ {
assert(currentIs(O), current().text); assert (currentIs(O), current().text);
advance(); advance();
int depth = 1; int depth = 1;
while (moreTokens()) while (moreTokens())
@ -7018,3 +7018,4 @@ protected:
int _traceDepth; int _traceDepth;
string comment; string comment;
} }

View File

@ -173,9 +173,9 @@ unittest
enum tok(string token) = TokenId!(IdType, ["foo"], ["bar"], ["doo"], token); enum tok(string token) = TokenId!(IdType, ["foo"], ["bar"], ["doo"], token);
alias str = tokenStringRepresentation!(IdType, ["foo"], ["bar"], ["doo"]); alias str = tokenStringRepresentation!(IdType, ["foo"], ["bar"], ["doo"]);
static assert(str(tok!"foo") == "foo"); static assert (str(tok!"foo") == "foo");
static assert(str(tok!"bar") == "bar"); static assert (str(tok!"bar") == "bar");
static assert(str(tok!"doo") == "doo"); static assert (str(tok!"doo") == "doo");
} }
/** /**
@ -772,3 +772,4 @@ struct LexerRange
*/ */
size_t line; size_t line;
} }