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;
/**
* Construct with the given file name.
*/
this(string fileName)
{
super(fileName);

View File

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

View File

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

View File

@ -10,13 +10,9 @@ import std.stdio;
import std.string;
import std.array;
template tagAndAccept(string tagName)
{
immutable tagAndAccept = `output.writeln("<` ~ tagName ~ `>");`
~ tagName ~ `.accept(this);`
~ `output.writeln("</` ~ tagName ~ `>");`;
}
/**
* AST visitor that outputs an XML representation of the AST to its file.
*/
class XMLPrinter : ASTVisitor
{
override void visit(const AddExpression addExpression)
@ -1094,6 +1090,17 @@ class XMLPrinter : ASTVisitor
output.writeln("<ddoc>", xmlEscape(comment), "</ddoc>");
}
/**
* File that output is written to.
*/
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.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)
{
string[] tags;
@ -41,6 +45,10 @@ void printCtags(File output, string[] fileNames)
tags.sort().copy(output.lockingTextWriter);
}
private:
void doNothing(string, size_t, size_t, string, bool) {}
class CTagsPrinter : ASTVisitor
{
override void visit(const ClassDeclaration dec)

View File

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