From 4ddb7c229b88da10fde2ba47888af654cdcf47b3 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 26 Jan 2015 00:13:53 -0800 Subject: [PATCH 1/5] Update libdparse. --- libdparse | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdparse b/libdparse index bcf115f..5f32686 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit bcf115f811bb5b2a99d09eb3b8df139102d2d982 +Subproject commit 5f32686dad3abfe79d45a7fa4a1299c39ea0d077 From 4de59912dbf5329f35ce040d8d2bc7cd70955070 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 26 Jan 2015 01:34:20 -0800 Subject: [PATCH 2/5] Update libdparse. --- libdparse | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdparse b/libdparse index 5f32686..364e0f1 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit 5f32686dad3abfe79d45a7fa4a1299c39ea0d077 +Subproject commit 364e0f14fa5941531d449a03d556b44fb12832d6 From 0e89df07f84dd2ce2a5cf52ff12cfbb3f65b6c93 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 26 Jan 2015 01:34:28 -0800 Subject: [PATCH 3/5] Code cleanup --- src/analysis/local_imports.d | 3 +++ src/analysis/numbers.d | 9 ++++++--- src/analysis/undocumented.d | 11 +++++++---- src/astprinter.d | 21 ++++++++++++++------- src/ctags.d | 12 ++++++++++-- src/imports.d | 8 ++++++-- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/analysis/local_imports.d b/src/analysis/local_imports.d index 71ecb50..002eda9 100644 --- a/src/analysis/local_imports.d +++ b/src/analysis/local_imports.d @@ -19,6 +19,9 @@ class LocalImportCheck : BaseAnalyzer { alias visit = BaseAnalyzer.visit; + /** + * Construct with the given file name. + */ this(string fileName) { super(fileName); diff --git a/src/analysis/numbers.d b/src/analysis/numbers.d index 384cd2f..2227589 100644 --- a/src/analysis/numbers.d +++ b/src/analysis/numbers.d @@ -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{ diff --git a/src/analysis/undocumented.d b/src/analysis/undocumented.d index c7c1019..165f807 100644 --- a/src/analysis/undocumented.d +++ b/src/analysis/undocumented.d @@ -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); diff --git a/src/astprinter.d b/src/astprinter.d index 019c2de..5d0bed0 100644 --- a/src/astprinter.d +++ b/src/astprinter.d @@ -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("");`; -} - +/** + * 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("", xmlEscape(comment), ""); } + /** + * File that output is written to. + */ File output; } +private: + +template tagAndAccept(string tagName) +{ + immutable tagAndAccept = `output.writeln("<` ~ tagName ~ `>");` + ~ tagName ~ `.accept(this);` + ~ `output.writeln("");`; +} diff --git a/src/ctags.d b/src/ctags.d index 8a896e4..5ea435b 100644 --- a/src/ctags.d +++ b/src/ctags.d @@ -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) diff --git a/src/imports.d b/src/imports.d index 6670dba..5009a68 100644 --- a/src/imports.d +++ b/src/imports.d @@ -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; } From 13a5a3e693868363679f2337d6b929066d498746 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 26 Jan 2015 13:13:12 -0800 Subject: [PATCH 4/5] Minor fixes --- src/analysis/numbers.d | 1 + src/analysis/unmodified.d | 12 ++++++++---- src/astprinter.d | 1 - src/imports.d | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/analysis/numbers.d b/src/analysis/numbers.d index 2227589..bc67da3 100644 --- a/src/analysis/numbers.d +++ b/src/analysis/numbers.d @@ -30,6 +30,7 @@ public: override void visit(const Token t) { + import std.algorithm : startsWith; if (isNumberLiteral(t.type) && !t.text.startsWith("0x") && ((t.text.startsWith("0b") && !t.text.matchFirst(badBinaryRegex).empty) || !t.text.matchFirst(badDecimalRegex).empty)) diff --git a/src/analysis/unmodified.d b/src/analysis/unmodified.d index b272f53..419b3c3 100644 --- a/src/analysis/unmodified.d +++ b/src/analysis/unmodified.d @@ -108,17 +108,21 @@ class UnmodifiedFinder:BaseAnalyzer 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) { -// import std.stdio : stderr; -// stderr.writeln(ioti.identifier.text, " ", ioti.identifier.line); if (ioti.identifier != tok!"" && interest > 0) - { variableMightBeModified(ioti.identifier.text); - } ioti.accept(this); } + mixin PartsMightModify!AsmPrimaryExp; mixin PartsMightModify!IndexExpression; mixin PartsMightModify!SliceExpression; mixin PartsMightModify!FunctionCallExpression; diff --git a/src/astprinter.d b/src/astprinter.d index 5d0bed0..89411c3 100644 --- a/src/astprinter.d +++ b/src/astprinter.d @@ -91,7 +91,6 @@ class XMLPrinter : ASTVisitor visit(asmInstruction.identifierOrIntegerOrOpcode); if (asmInstruction.operands !is null) { - stderr.writeln("operands is not null"); visit(asmInstruction.operands); } output.writeln(""); diff --git a/src/imports.d b/src/imports.d index 5009a68..2cdfa96 100644 --- a/src/imports.d +++ b/src/imports.d @@ -43,8 +43,9 @@ class ImportPrinter : ASTVisitor alias visit = ASTVisitor.visit; -private: - + /// Collected imports RedBlackTree!string imports; + +private: bool ignore = true; } From c5277b1e31f0c7f432952ced5fa2470ac1bf95b5 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 26 Jan 2015 16:39:58 -0800 Subject: [PATCH 5/5] Update libdparse --- libdparse | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdparse b/libdparse index 364e0f1..b64fb8c 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit 364e0f14fa5941531d449a03d556b44fb12832d6 +Subproject commit b64fb8c91efa17a895567403969d4fc87adaa42a