commit
699acff662
|
@ -1 +1 @@
|
||||||
Subproject commit bcf115f811bb5b2a99d09eb3b8df139102d2d982
|
Subproject commit b64fb8c91efa17a895567403969d4fc87adaa42a
|
|
@ -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);
|
||||||
|
|
|
@ -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,7 @@ class NumberStyleCheck : BaseAnalyzer
|
||||||
|
|
||||||
override void visit(const Token t)
|
override void visit(const Token t)
|
||||||
{
|
{
|
||||||
import std.algorithm;
|
import std.algorithm : startsWith;
|
||||||
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 +39,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{
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -108,17 +108,21 @@ class UnmodifiedFinder:BaseAnalyzer
|
||||||
dec.accept(this);
|
dec.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void visit(const IdentifierChain ic)
|
||||||
|
{
|
||||||
|
if (ic.identifiers.length && interest > 0)
|
||||||
|
variableMightBeModified(ic.identifiers[0].text);
|
||||||
|
ic.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
override void visit(const IdentifierOrTemplateInstance ioti)
|
override void visit(const IdentifierOrTemplateInstance ioti)
|
||||||
{
|
{
|
||||||
// import std.stdio : stderr;
|
|
||||||
// stderr.writeln(ioti.identifier.text, " ", ioti.identifier.line);
|
|
||||||
if (ioti.identifier != tok!"" && interest > 0)
|
if (ioti.identifier != tok!"" && interest > 0)
|
||||||
{
|
|
||||||
variableMightBeModified(ioti.identifier.text);
|
variableMightBeModified(ioti.identifier.text);
|
||||||
}
|
|
||||||
ioti.accept(this);
|
ioti.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mixin PartsMightModify!AsmPrimaryExp;
|
||||||
mixin PartsMightModify!IndexExpression;
|
mixin PartsMightModify!IndexExpression;
|
||||||
mixin PartsMightModify!SliceExpression;
|
mixin PartsMightModify!SliceExpression;
|
||||||
mixin PartsMightModify!FunctionCallExpression;
|
mixin PartsMightModify!FunctionCallExpression;
|
||||||
|
|
|
@ -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)
|
||||||
|
@ -95,7 +91,6 @@ class XMLPrinter : ASTVisitor
|
||||||
visit(asmInstruction.identifierOrIntegerOrOpcode);
|
visit(asmInstruction.identifierOrIntegerOrOpcode);
|
||||||
if (asmInstruction.operands !is null)
|
if (asmInstruction.operands !is null)
|
||||||
{
|
{
|
||||||
stderr.writeln("operands is not null");
|
|
||||||
visit(asmInstruction.operands);
|
visit(asmInstruction.operands);
|
||||||
}
|
}
|
||||||
output.writeln("</asmInstruction>");
|
output.writeln("</asmInstruction>");
|
||||||
|
@ -1094,6 +1089,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 ~ `>");`;
|
||||||
|
}
|
||||||
|
|
12
src/ctags.d
12
src/ctags.d
|
@ -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)
|
||||||
|
|
|
@ -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,11 @@ class ImportPrinter : ASTVisitor
|
||||||
imports.insert(s);
|
imports.insert(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
RedBlackTree!string imports;
|
|
||||||
|
|
||||||
alias visit = ASTVisitor.visit;
|
alias visit = ASTVisitor.visit;
|
||||||
|
|
||||||
|
/// Collected imports
|
||||||
|
RedBlackTree!string imports;
|
||||||
|
|
||||||
|
private:
|
||||||
bool ignore = true;
|
bool ignore = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue