Code cleanup

This commit is contained in:
Hackerpilot 2015-01-26 01:34:28 -08:00
parent 4de59912db
commit 0e89df07f8
6 changed files with 46 additions and 18 deletions

View File

@ -19,6 +19,9 @@ class LocalImportCheck : BaseAnalyzer
{ {
alias visit = BaseAnalyzer.visit; alias visit = BaseAnalyzer.visit;
/**
* Construct with the given file name.
*/
this(string fileName) this(string fileName)
{ {
super(fileName); super(fileName);

View File

@ -17,8 +17,12 @@ import analysis.helpers;
*/ */
class NumberStyleCheck : BaseAnalyzer class NumberStyleCheck : BaseAnalyzer
{ {
public:
alias visit = BaseAnalyzer.visit; alias visit = BaseAnalyzer.visit;
/**
* Constructs the style checker with the given file name.
*/
this(string fileName) this(string fileName)
{ {
super(fileName); super(fileName);
@ -26,7 +30,6 @@ class NumberStyleCheck : BaseAnalyzer
override void visit(const Token t) override void visit(const Token t)
{ {
import std.algorithm;
if (isNumberLiteral(t.type) && !t.text.startsWith("0x") if (isNumberLiteral(t.type) && !t.text.startsWith("0x")
&& ((t.text.startsWith("0b") && !t.text.matchFirst(badBinaryRegex).empty) && ((t.text.startsWith("0b") && !t.text.matchFirst(badBinaryRegex).empty)
|| !t.text.matchFirst(badDecimalRegex).empty)) || !t.text.matchFirst(badDecimalRegex).empty))
@ -35,14 +38,14 @@ class NumberStyleCheck : BaseAnalyzer
"Use underscores to improve number constant readability."); "Use underscores to improve number constant readability.");
} }
} }
private:
auto badBinaryRegex = ctRegex!(`^0b[01]{9,}`); auto badBinaryRegex = ctRegex!(`^0b[01]{9,}`);
auto badDecimalRegex = ctRegex!(`^\d{5,}`); auto badDecimalRegex = ctRegex!(`^\d{5,}`);
} }
unittest unittest
{ {
import analysis.config; import analysis.config : StaticAnalysisConfig;
StaticAnalysisConfig sac; StaticAnalysisConfig sac;
sac.number_style_check = true; sac.number_style_check = true;
assertAnalyzerWarnings(q{ assertAnalyzerWarnings(q{

View File

@ -43,16 +43,19 @@ class UndocumentedDeclarationCheck : BaseAnalyzer
} }
} }
bool shouldPop = false; immutable bool shouldPop = dec.attributeDeclaration is null;
bool prevOverride = getOverride(); immutable bool prevOverride = getOverride();
bool ovr = false; bool ovr = false;
bool pushed = false;
foreach (attribute; dec.attributes) foreach (attribute; dec.attributes)
{ {
shouldPop = dec.attributeDeclaration !is null;
if (isProtection(attribute.attribute.type)) if (isProtection(attribute.attribute.type))
{ {
if (shouldPop) if (shouldPop)
{
pushed = true;
push(attribute.attribute.type); push(attribute.attribute.type);
}
else else
set(attribute.attribute.type); set(attribute.attribute.type);
} }
@ -62,7 +65,7 @@ class UndocumentedDeclarationCheck : BaseAnalyzer
if (ovr) if (ovr)
setOverride(true); setOverride(true);
dec.accept(this); dec.accept(this);
if (shouldPop) if (shouldPop && pushed)
pop(); pop();
if (ovr) if (ovr)
setOverride(prevOverride); setOverride(prevOverride);

View File

@ -10,13 +10,9 @@ import std.stdio;
import std.string; import std.string;
import std.array; import std.array;
template tagAndAccept(string tagName) /**
{ * AST visitor that outputs an XML representation of the AST to its file.
immutable tagAndAccept = `output.writeln("<` ~ tagName ~ `>");` */
~ tagName ~ `.accept(this);`
~ `output.writeln("</` ~ tagName ~ `>");`;
}
class XMLPrinter : ASTVisitor class XMLPrinter : ASTVisitor
{ {
override void visit(const AddExpression addExpression) override void visit(const AddExpression addExpression)
@ -1094,6 +1090,17 @@ class XMLPrinter : ASTVisitor
output.writeln("<ddoc>", xmlEscape(comment), "</ddoc>"); output.writeln("<ddoc>", xmlEscape(comment), "</ddoc>");
} }
/**
* File that output is written to.
*/
File output; File output;
} }
private:
template tagAndAccept(string tagName)
{
immutable tagAndAccept = `output.writeln("<` ~ tagName ~ `>");`
~ tagName ~ `.accept(this);`
~ `output.writeln("</` ~ tagName ~ `>");`;
}

View File

@ -14,8 +14,12 @@ import std.stdio;
import std.array; import std.array;
import std.conv; import std.conv;
void doNothing(string, size_t, size_t, string, bool) {} /**
* Prints CTAGS information to the given file.
* Params:
* outpt = the file that CTAGS info is written to
* fileNames = tags will be generated from these files
*/
void printCtags(File output, string[] fileNames) void printCtags(File output, string[] fileNames)
{ {
string[] tags; string[] tags;
@ -41,6 +45,10 @@ void printCtags(File output, string[] fileNames)
tags.sort().copy(output.lockingTextWriter); tags.sort().copy(output.lockingTextWriter);
} }
private:
void doNothing(string, size_t, size_t, string, bool) {}
class CTagsPrinter : ASTVisitor class CTagsPrinter : ASTVisitor
{ {
override void visit(const ClassDeclaration dec) override void visit(const ClassDeclaration dec)

View File

@ -9,6 +9,9 @@ import std.d.ast;
import std.stdio; import std.stdio;
import std.container; import std.container;
/**
* AST visitor that collects modules imported to an R-B tree.
*/
class ImportPrinter : ASTVisitor class ImportPrinter : ASTVisitor
{ {
this() this()
@ -38,9 +41,10 @@ class ImportPrinter : ASTVisitor
imports.insert(s); imports.insert(s);
} }
RedBlackTree!string imports;
alias visit = ASTVisitor.visit; alias visit = ASTVisitor.visit;
private:
RedBlackTree!string imports;
bool ignore = true; bool ignore = true;
} }