Make most AST classes final and most methods for processing them const

This commit is contained in:
Hackerpilot 2014-03-03 22:24:58 -08:00
parent b2b7fc3e17
commit b60df8e5c4
14 changed files with 810 additions and 807 deletions

View File

@ -22,7 +22,7 @@ protected:
template visitTemplate(T)
{
override void visit(T structDec)
override void visit(const T structDec)
{
inAggregate = true;
structDec.accept(this);

View File

@ -21,7 +21,7 @@ class DeleteCheck : BaseAnalyzer
super(fileName);
}
override void visit(DeleteExpression d)
override void visit(const DeleteExpression d)
{
addErrorMessage(d.line, d.column, "Avoid using the delete keyword");
d.accept(this);

View File

@ -27,7 +27,7 @@ class EnumArrayLiteralCheck : BaseAnalyzer
mixin visitTemplate!UnionDeclaration;
mixin visitTemplate!StructDeclaration;
override void visit(Declaration dec)
override void visit(const Declaration dec)
{
if (inAggregate) foreach (attr; dec.attributes)
{
@ -41,7 +41,7 @@ class EnumArrayLiteralCheck : BaseAnalyzer
looking = false;
}
override void visit(AutoDeclaration autoDec)
override void visit(const AutoDeclaration autoDec)
{
if (looking)
{

View File

@ -21,7 +21,7 @@ class FloatOperatorCheck : BaseAnalyzer
super(fileName);
}
override void visit(RelExpression r)
override void visit(const RelExpression r)
{
if (r.operator == tok!"<>"
|| r.operator == tok!"!<>"

View File

@ -22,7 +22,7 @@ class NumberStyleCheck : BaseAnalyzer
super(fileName);
}
override void visit(Token t)
override void visit(const Token t)
{
import std.algorithm;
if (isNumberLiteral(t.type) && !t.text.startsWith("0x")

View File

@ -27,7 +27,7 @@ class ObjectConstCheck : BaseAnalyzer
mixin visitTemplate!UnionDeclaration;
mixin visitTemplate!StructDeclaration;
override void visit(Declaration d)
override void visit(const Declaration d)
{
if (inAggregate && d.functionDeclaration !is null
&& isInteresting(d.functionDeclaration.name.text)
@ -41,14 +41,14 @@ class ObjectConstCheck : BaseAnalyzer
d.accept(this);
}
private static bool hasConst(Attribute[] attributes)
private static bool hasConst(const Attribute[] attributes)
{
import std.algorithm;
return attributes.any!(a => a.attribute == tok!"const"
|| (a.storageClass !is null && a.storageClass.token == tok!"const"));
}
private static bool hasConst(MemberFunctionAttribute[] attributes)
private static bool hasConst(const MemberFunctionAttribute[] attributes)
{
import std.algorithm;
return attributes.any!(a => a.tokenType == tok!"const");

View File

@ -13,8 +13,11 @@ import analysis.base;
* Checks for Pokémon exception handling, i.e. "gotta' catch 'em all".
*
* ---
* catch (Exception e)
* ...
* try {
* choose(pikachu);
* } catch (Exception e) {
* ...
* }
* ---
*/
class PokemonExceptionCheck : BaseAnalyzer
@ -26,7 +29,7 @@ class PokemonExceptionCheck : BaseAnalyzer
super(fileName);
}
override void visit(Catch c)
override void visit(const Catch c)
{
if (c.type.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length != 1)
{

View File

@ -31,7 +31,7 @@ class BackwardsRangeCheck : BaseAnalyzer
super(fileName);
}
override void visit(ForeachStatement foreachStatement)
override void visit(const ForeachStatement foreachStatement)
{
if (foreachStatement.low !is null && foreachStatement.high !is null)
{
@ -54,7 +54,7 @@ class BackwardsRangeCheck : BaseAnalyzer
foreachStatement.accept(this);
}
override void visit(UnaryExpression unary)
override void visit(const UnaryExpression unary)
{
if (state != State.ignore && unary.primaryExpression is null)
return;
@ -62,7 +62,7 @@ class BackwardsRangeCheck : BaseAnalyzer
unary.accept(this);
}
override void visit(PrimaryExpression primary)
override void visit(const PrimaryExpression primary)
{
import std.conv;
import std.string;
@ -82,7 +82,7 @@ class BackwardsRangeCheck : BaseAnalyzer
}
}
override void visit(SliceExpression sliceExpression)
override void visit(const SliceExpression sliceExpression)
{
if (sliceExpression.lower !is null && sliceExpression.upper !is null)
{

View File

@ -25,7 +25,7 @@ class StyleChecker : BaseAnalyzer
super(fileName);
}
override void visit(ModuleDeclaration dec)
override void visit(const ModuleDeclaration dec)
{
foreach (part; dec.moduleName.identifiers)
{
@ -35,36 +35,36 @@ class StyleChecker : BaseAnalyzer
}
}
override void visit(Declarator dec)
override void visit(const Declarator dec)
{
checkLowercaseName("Variable", dec.name);
}
override void visit(FunctionDeclaration dec)
override void visit(const FunctionDeclaration dec)
{
checkLowercaseName("Function", dec.name);
}
void checkLowercaseName(string type, ref Token name)
void checkLowercaseName(string type, ref const Token name)
{
if (name.text.matchFirst(varFunNameRegex).length == 0)
addErrorMessage(name.line, name.column, type ~ " name "
~ name.text ~ " does not match style guidelines");
}
override void visit(ClassDeclaration dec)
override void visit(const ClassDeclaration dec)
{
checkAggregateName("Class", dec.name);
dec.accept(this);
}
override void visit(InterfaceDeclaration dec)
override void visit(const InterfaceDeclaration dec)
{
checkAggregateName("Interface", dec.name);
dec.accept(this);
}
override void visit(EnumDeclaration dec)
override void visit(const EnumDeclaration dec)
{
if (dec.name.text is null || dec.name.text.length == 0)
return;
@ -72,7 +72,7 @@ class StyleChecker : BaseAnalyzer
dec.accept(this);
}
override void visit(StructDeclaration dec)
override void visit(const StructDeclaration dec)
{
checkAggregateName("Struct", dec.name);
dec.accept(this);

File diff suppressed because it is too large Load Diff

20
ctags.d
View File

@ -27,7 +27,7 @@ void printCtags(File output, string[] fileNames)
auto bytes = uninitializedArray!(ubyte[])(to!size_t(f.size));
f.rawRead(bytes);
auto tokens = byToken(bytes, config, cache);
Module m = parseModule(tokens.array, fileName, &doNothing);
Module m = parseModule(tokens.array, fileName, null, &doNothing);
auto printer = new CTagsPrinter;
printer.fileName = fileName;
printer.visit(m);
@ -42,7 +42,7 @@ void printCtags(File output, string[] fileNames)
class CTagsPrinter : ASTVisitor
{
override void visit(ClassDeclaration dec)
override void visit(const ClassDeclaration dec)
{
tagLines ~= "%s\t%s\t%d;\"\tc%s\n".format(dec.name.text, fileName, dec.name.line, context);
auto c = context;
@ -51,7 +51,7 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(StructDeclaration dec)
override void visit(const StructDeclaration dec)
{
tagLines ~= "%s\t%s\t%d;\"\ts%s\n".format(dec.name.text, fileName, dec.name.line, context);
auto c = context;
@ -60,7 +60,7 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(InterfaceDeclaration dec)
override void visit(const InterfaceDeclaration dec)
{
tagLines ~= "%s\t%s\t%d;\"\ti%s\n".format(dec.name.text, fileName, dec.name.line, context);
auto c = context;
@ -69,7 +69,7 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(TemplateDeclaration dec)
override void visit(const TemplateDeclaration dec)
{
tagLines ~= "%s\t%s\t%d;\"\tT%s\n".format(dec.name.text, fileName, dec.name.line, context);
auto c = context;
@ -78,7 +78,7 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(FunctionDeclaration dec)
override void visit(const FunctionDeclaration dec)
{
tagLines ~= "%s\t%s\t%d;\"\tf\tarity:%d%s\n".format(dec.name.text, fileName,
dec.name.line, dec.parameters.parameters.length, context);
@ -88,7 +88,7 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(EnumDeclaration dec)
override void visit(const EnumDeclaration dec)
{
if (dec.name == tok!"")
{
@ -103,7 +103,7 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(UnionDeclaration dec)
override void visit(const UnionDeclaration dec)
{
if (dec.name == tok!"")
{
@ -118,13 +118,13 @@ class CTagsPrinter : ASTVisitor
context = c;
}
override void visit(EnumMember mem)
override void visit(const EnumMember mem)
{
tagLines ~= "%s\t%s\t%d;\"\te%s\n".format(mem.name.text, fileName,
mem.name.line, context);
}
override void visit(VariableDeclaration dec)
override void visit(const VariableDeclaration dec)
{
foreach (d; dec.declarators)
{

View File

@ -10,7 +10,7 @@ import std.stdio;
class ImportPrinter : ASTVisitor
{
override void visit(SingleImport singleImport)
override void visit(const SingleImport singleImport)
{
ignore = false;
singleImport.accept(this);
@ -18,7 +18,7 @@ class ImportPrinter : ASTVisitor
ignore = true;
}
override void visit(IdentifierChain identifierChain)
override void visit(const IdentifierChain identifierChain)
{
if (ignore) return;
bool first = true;

View File

@ -18,7 +18,7 @@ class Outliner : ASTVisitor
this.output = output;
}
override void visit(ClassDeclaration classDec)
override void visit(const ClassDeclaration classDec)
{
printIndentation();
output.writeln("class ", classDec.name.text, " : ", classDec.name.line);
@ -28,7 +28,7 @@ class Outliner : ASTVisitor
finish();
}
override void visit(EnumDeclaration enumDec)
override void visit(const EnumDeclaration enumDec)
{
printIndentation();
output.writeln("enum ", enumDec.name.text, " : ", enumDec.name.line);
@ -38,14 +38,14 @@ class Outliner : ASTVisitor
finish();
}
override void visit(EnumMember enumMem)
override void visit(const EnumMember enumMem)
{
printIndentation();
output.writeln(enumMem.name.text, " : ", enumMem.name.line);
finish();
}
override void visit(FunctionDeclaration functionDec)
override void visit(const FunctionDeclaration functionDec)
{
printIndentation();
if (functionDec.hasAuto)
@ -65,7 +65,7 @@ class Outliner : ASTVisitor
finish();
}
override void visit(InterfaceDeclaration interfaceDec)
override void visit(const InterfaceDeclaration interfaceDec)
{
printIndentation();
output.writeln("interface ", interfaceDec.name.text, " : ",
@ -76,7 +76,7 @@ class Outliner : ASTVisitor
finish();
}
override void visit(StructDeclaration structDec)
override void visit(const StructDeclaration structDec)
{
printIndentation();
output.writeln("struct ", structDec.name.text, " : ",
@ -87,7 +87,7 @@ class Outliner : ASTVisitor
finish();
}
override void visit(TemplateDeclaration templateDeclaration)
override void visit(const TemplateDeclaration templateDeclaration)
{
printIndentation();
output.writeln("template ", templateDeclaration.name.text, " : ",
@ -98,14 +98,14 @@ class Outliner : ASTVisitor
finish();
}
override void visit(StaticConstructor s) {}
override void visit(StaticDestructor s) {}
override void visit(SharedStaticConstructor s) {}
override void visit(SharedStaticDestructor s) {}
override void visit(Constructor c) {}
override void visit(Unittest u) {}
override void visit(const StaticConstructor s) {}
override void visit(const StaticDestructor s) {}
override void visit(const SharedStaticConstructor s) {}
override void visit(const SharedStaticDestructor s) {}
override void visit(const Constructor c) {}
override void visit(const Unittest u) {}
override void visit(UnionDeclaration unionDeclaration)
override void visit(const UnionDeclaration unionDeclaration)
{
printIndentation();
output.writeln("union ", unionDeclaration.name.text, " : ",
@ -116,9 +116,9 @@ class Outliner : ASTVisitor
finish();
}
override void visit(VariableDeclaration variableDeclaration)
override void visit(const VariableDeclaration variableDeclaration)
{
foreach (Declarator d; variableDeclaration.declarators)
foreach (const Declarator d; variableDeclaration.declarators)
{
printIndentation();
auto app = appender!(char[])();

File diff suppressed because it is too large Load Diff