diff --git a/analysis/asm_style.d b/analysis/asm_style.d new file mode 100644 index 0000000..5e23553 --- /dev/null +++ b/analysis/asm_style.d @@ -0,0 +1,55 @@ +// Copyright Brian Schott (Hackerpilot) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +module analysis.asm_style; + +import std.stdio; +import std.d.ast; +import std.d.lexer; +import analysis.base; +import analysis.helpers; + +/** + * Checks for confusing asm expressions. + * See_also: $(LINK https://issues.dlang.org/show_bug.cgi?id=9738) + */ +class AsmStyleCheck : BaseAnalyzer +{ + alias visit = BaseAnalyzer.visit; + + this(string fileName) + { + super(fileName); + } + + override void visit(const AsmBrExp brExp) + { + if (brExp.asmBrExp !is null) + { + addErrorMessage(brExp.line, brExp.column, + "This is confusing because it looks like an array index. Rewrite a[1] as [a + 1] to clarify."); + } + brExp.accept(this); + } +} + +unittest +{ + import analysis.config; + StaticAnalysisConfig sac; + sac.asm_style_check = true; + assertAnalyzerWarnings(q{ + void testAsm() + { + asm + { + mov a, someArray[1]; // [warn]: This is confusing because it looks like an array index. Rewrite a[1] as [a + 1] to clarify. + } + } + }c, sac); + + stderr.writeln("Unittest for AsmStyleCheck passed."); +} + diff --git a/analysis/builtin_property_names.d b/analysis/builtin_property_names.d index f547894..cb10918 100644 --- a/analysis/builtin_property_names.d +++ b/analysis/builtin_property_names.d @@ -90,13 +90,13 @@ unittest { import analysis.config; StaticAnalysisConfig sac; - sac.builtin_property_name_check = true; + sac.builtin_property_names_check = true; assertAnalyzerWarnings(q{ class SomeClass { - void init(); // - int init; - auto init = 10; + void init(); // [warn]: Avoid naming members 'init'. This can confuse code that depends on the '.init' property of a type. + int init; // [warn]: Avoid naming members 'init'. This can confuse code that depends on the '.init' property of a type. + auto init = 10; // [warn]: Avoid naming members 'init'. This can confuse code that depends on the '.init' property of a type. } }c, sac); diff --git a/analysis/config.d b/analysis/config.d index 54e48e7..4bb5fca 100644 --- a/analysis/config.d +++ b/analysis/config.d @@ -62,4 +62,7 @@ struct StaticAnalysisConfig @INI("Checks for methods or properties whose names conflict with built-in properties") bool builtin_property_names_check; + + @INI("Checks for confusing code in inline asm statements") + bool asm_style_check; } diff --git a/analysis/helpers.d b/analysis/helpers.d index 4abe1c4..87587c4 100644 --- a/analysis/helpers.d +++ b/analysis/helpers.d @@ -49,7 +49,7 @@ S after(S)(S value, S separator) * and make sure they match the warnings in the comments. Warnings are * marked like so: // [warn]: Failed to do somethings. */ -void assertAnalyzerWarnings(string code, StaticAnalysisConfig config, string file=__FILE__, size_t line=__LINE__) +void assertAnalyzerWarnings(string code, const StaticAnalysisConfig config, string file=__FILE__, size_t line=__LINE__) { import analysis.run; diff --git a/analysis/length_subtraction.d b/analysis/length_subtraction.d index 1efd77a..634493b 100644 --- a/analysis/length_subtraction.d +++ b/analysis/length_subtraction.d @@ -60,7 +60,7 @@ unittest { import analysis.config; StaticAnalysisConfig sac; - sac.if_else_same_check = true; + sac.length_subtraction_check = true; assertAnalyzerWarnings(q{ void testSizeT() { diff --git a/analysis/objectconst.d b/analysis/objectconst.d index 45fc29d..f0c7070 100644 --- a/analysis/objectconst.d +++ b/analysis/objectconst.d @@ -104,22 +104,22 @@ unittest // Will warn, because none are const class Dog { - bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const. + bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. { return true; } - int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const. + int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. { return 1; } - hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const. + hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. { return 0; } - string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const. + string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. { return "Dog"; } diff --git a/analysis/run.d b/analysis/run.d index d562154..b8f8fdd 100644 --- a/analysis/run.d +++ b/analysis/run.d @@ -27,6 +27,7 @@ import analysis.duplicate_attribute; import analysis.opequals_without_tohash; import analysis.length_subtraction; import analysis.builtin_property_names; +import analysis.asm_style; void messageFunction(string fileName, size_t line, size_t column, string message, bool isError) @@ -58,7 +59,7 @@ void analyze(File output, string[] fileNames, StaticAnalysisConfig config, bool } // For a string -string[] analyze(string fileName, ubyte[] code, StaticAnalysisConfig analysisConfig, bool staticAnalyze = true) +string[] analyze(string fileName, ubyte[] code, const StaticAnalysisConfig analysisConfig, bool staticAnalyze = true) { import std.parallelism; @@ -98,6 +99,7 @@ string[] analyze(string fileName, ubyte[] code, StaticAnalysisConfig analysisCon if (analysisConfig.opequals_tohash_check) checks ~= new OpEqualsWithoutToHashCheck(fileName); if (analysisConfig.length_subtraction_check) checks ~= new LengthSubtractionCheck(fileName); if (analysisConfig.builtin_property_names_check) checks ~= new BuiltinPropertyNameCheck(fileName); + if (analysisConfig.asm_style_check) checks ~= new AsmStyleCheck(fileName); foreach (check; checks) { diff --git a/analysis/unused.d b/analysis/unused.d index e109a93..36c80fa 100644 --- a/analysis/unused.d +++ b/analysis/unused.d @@ -287,6 +287,14 @@ class UnusedVariableCheck : BaseAnalyzer blockStatementIntroducesScope = cs; } + override void visit(const AsmPrimaryExp primary) + { + if (primary.token != tok!"") + variableUsed(primary.token.text); + if (primary.identifierChain !is null) + variableUsed(primary.identifierChain.identifiers[0].text); + } + void variableDeclared(string name, size_t line, size_t column, bool isParameter, bool isRef) { @@ -313,7 +321,7 @@ class UnusedVariableCheck : BaseAnalyzer { foreach (uu; tree[$ - 1]) { - if (!uu.isRef) + if (!uu.isRef && tree.length > 1) addErrorMessage(uu.line, uu.column, (uu.isParameter ? "Parameter " : "Variable ") ~ uu.name ~ " is never used."); diff --git a/astprinter.d b/astprinter.d index 25e9b5b..fb222e6 100644 --- a/astprinter.d +++ b/astprinter.d @@ -42,16 +42,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const AliasInitializer aliasInitializer) - { - mixin (tagAndAccept!"aliasInitializer"); - } - - override void visit(const AliasThisDeclaration aliasThisDeclaration) - { - mixin (tagAndAccept!"aliasThisDeclaration"); - } - override void visit(const AlignAttribute alignAttribute) { output.writeln(""); @@ -87,29 +77,28 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const ArgumentList argumentList) + override void visit(const AsmInstruction asmInstruction) { - mixin (tagAndAccept!"argumentList"); - } - - override void visit(const Arguments arguments) - { - mixin (tagAndAccept!"arguments"); - } - - override void visit(const ArrayInitializer arrayInitializer) - { - mixin (tagAndAccept!"arrayInitializer"); - } - - override void visit(const ArrayLiteral arrayLiteral) - { - mixin (tagAndAccept!"arrayLiteral"); - } - - override void visit(const ArrayMemberInitialization arrayMemberInitialization) - { - mixin (tagAndAccept!"arrayMemberInitialization"); + output.writeln(""); + if (asmInstruction.hasAlign) + { + output.writeln(""); + visit(asmInstruction.identifierOrIntegerOrOpcode); + output.writeln(""); + } + if (asmInstruction.asmInstruction !is null) + { + output.writeln(""); } override void visit(const AssertExpression assertExpression) @@ -138,11 +127,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const AssocArrayLiteral assocArrayLiteral) - { - mixin (tagAndAccept!"assocArrayLiteral"); - } - override void visit(const AtAttribute atAttribute) { output.writeln(""); @@ -163,12 +147,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const AttributeDeclaration attributeDeclaration) - { - assert (attributeDeclaration !is null); - mixin (tagAndAccept!"attributeDeclaration"); - } - override void visit(const AutoDeclaration autoDec) { output.writeln(""); @@ -183,20 +161,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const BlockStatement blockStatement) - { - output.writeln(""); - blockStatement.accept(this); - output.writeln(""); - } - - override void visit(const BodyStatement bodyStatement) - { - output.writeln(""); - bodyStatement.accept(this); - output.writeln(""); - } - override void visit(const BreakStatement breakStatement) { if (breakStatement.label.type == tok!"") @@ -205,16 +169,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const BaseClass baseClass) - { - mixin (tagAndAccept!"baseClass"); - } - - override void visit(const BaseClassList baseClassList) - { - mixin (tagAndAccept!"baseClassList"); - } - override void visit(const CaseRangeStatement caseRangeStatement) { output.writeln(""); @@ -235,26 +189,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const CaseStatement caseStatement) - { - mixin (tagAndAccept!"caseStatement"); - } - - override void visit(const CastExpression castExpression) - { - mixin (tagAndAccept!"castExpression"); - } - - override void visit(const CastQualifier castQualifier) - { - mixin (tagAndAccept!"castQualifier"); - } - - override void visit(const Catches catches) - { - mixin (tagAndAccept!"catches"); - } - override void visit(const Catch catch_) { output.writeln(""); @@ -271,16 +205,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const CmpExpression cmpExpression) - { - mixin (tagAndAccept!"cmpExpression"); - } - - override void visit(const CompileCondition compileCondition) - { - mixin (tagAndAccept!"compileCondition"); - } - override void visit(const ConditionalDeclaration conditionalDeclaration) { output.writeln(""); @@ -314,18 +238,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const Constraint constraint) - { - output.writeln(""); - constraint.accept(this); - output.writeln(""); - } - - override void visit(const Constructor constructor) - { - mixin (tagAndAccept!"constructor"); - } - override void visit(const ContinueStatement continueStatement) { if (continueStatement.label.type == tok!"") @@ -353,21 +265,6 @@ class XMLPrinter : ASTVisitor debugSpecification.identifierOrInteger.text, "\"/>"); } - override void visit(const Declaration declaration) - { - mixin (tagAndAccept!"declaration"); - } - - override void visit(const DeclarationsAndStatements declarationsAndStatements) - { - mixin (tagAndAccept!"declarationsAndStatements"); - } - - override void visit(const DeclarationOrStatement declarationOrStatement) - { - mixin (tagAndAccept!"declarationOrStatement"); - } - override void visit(const Declarator declarator) { output.writeln(""); @@ -377,21 +274,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const DefaultStatement defaultStatement) - { - mixin (tagAndAccept!"defaultStatement"); - } - - override void visit(const DeleteExpression deleteExpression) - { - mixin (tagAndAccept!"deleteExpression"); - } - - override void visit(const DeleteStatement deleteStatement) - { - mixin (tagAndAccept!"deleteStatement"); - } - override void visit(const Deprecated deprecated_) { if (deprecated_.assignExpression !is null) @@ -404,21 +286,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const Destructor destructor) - { - mixin (tagAndAccept!"destructor"); - } - - override void visit(const DoStatement doStatement) - { - mixin (tagAndAccept!"doStatement"); - } - - override void visit(const EnumBody enumBody) - { - mixin (tagAndAccept!"enumBody"); - } - override void visit(const EnumDeclaration enumDec) { output.writeln(""); @@ -449,27 +316,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const Expression expression) - { - output.writeln(""); - expression.accept(this); - output.writeln(""); - } - - override void visit(const ExpressionStatement expressionStatement) - { - output.writeln(""); - expressionStatement.accept(this); - output.writeln(""); - } - - override void visit(const FinalSwitchStatement finalSwitchStatement) - { - output.writeln(""); - finalSwitchStatement.accept(this); - output.writeln(""); - } - override void visit(const Finally finally_) { output.writeln(""); @@ -538,31 +384,6 @@ class XMLPrinter : ASTVisitor } - override void visit(const ForeachTypeList foreachTypeList) - { - mixin (tagAndAccept!"foreachTypeList"); - } - - override void visit(const FunctionAttribute functionAttribute) - { - mixin (tagAndAccept!"functionAttribute"); - } - - override void visit(const FunctionBody functionBody) - { - mixin (tagAndAccept!"functionBody"); - } - - override void visit(const FunctionCallExpression functionCallExpression) - { - mixin (tagAndAccept!"functionCallExpression"); - } - - override void visit(const FunctionCallStatement functionCallStatement) - { - mixin (tagAndAccept!"functionCallStatement"); - } - override void visit(const FunctionDeclaration functionDec) { output.writeln(""); @@ -603,26 +424,6 @@ class XMLPrinter : ASTVisitor } } - override void visit(const IdentifierChain identifierChain) - { - mixin (tagAndAccept!"identifierChain"); - } - - override void visit(const IdentifierList identifierList) - { - mixin (tagAndAccept!"identifierList"); - } - - override void visit(const IdentifierOrTemplateChain identifierOrTemplateChain) - { - mixin (tagAndAccept!"identifierOrTemplateChain"); - } - - override void visit(const IdentifierOrTemplateInstance identifierOrTemplateInstance) - { - mixin (tagAndAccept!"identifierOrTemplateInstance"); - } - override void visit(const IdentityExpression identityExpression) { if (identityExpression.negated) @@ -676,26 +477,6 @@ class XMLPrinter : ASTVisitor "\" rename=\"", importBind.left.text, "\"/>"); } - override void visit(const ImportBindings importBindings) - { - mixin (tagAndAccept!"importBindings"); - } - - override void visit(const ImportDeclaration importDeclaration) - { - mixin (tagAndAccept!"importDeclaration"); - } - - override void visit(const ImportExpression importExpression) - { - mixin (tagAndAccept!"importExpression"); - } - - override void visit(const IndexExpression indexExpression) - { - mixin (tagAndAccept!"indexExpression"); - } - override void visit(const InExpression inExpression) { if (inExpression.negated) @@ -711,11 +492,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const InStatement inStatement) - { - mixin (tagAndAccept!"inStatement"); - } - override void visit(const Initialize initialize) { if (initialize.statementNoCaseNoDefault is null) @@ -788,11 +564,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const KeyValuePairs keyValuePairs) - { - mixin (tagAndAccept!"keyValuePairs"); - } - override void visit (const LabeledStatement labeledStatement) { output.writeln(""); } - override void visit(const LastCatch lastCatch) - { - mixin (tagAndAccept!"lastCatch"); - } - override void visit(const LinkageAttribute linkageAttribute) { if (linkageAttribute.hasPlusPlus) @@ -836,26 +602,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const MixinDeclaration mixinDeclaration) - { - mixin (tagAndAccept!"mixinDeclaration"); - } - - override void visit(const MixinExpression mixinExpression) - { - mixin (tagAndAccept!"mixinExpression"); - } - - override void visit(const MixinTemplateDeclaration mixinTemplateDeclaration) - { - mixin (tagAndAccept!"mixinTemplateDeclaration"); - } - - override void visit(const MixinTemplateName mixinTemplateName) - { - mixin (tagAndAccept!"mixinTemplateName"); - } - override void visit(const Module module_) { output.writeln(""); @@ -864,11 +610,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const ModuleDeclaration moduleDeclaration) - { - mixin (tagAndAccept!"moduleDeclaration"); - } - override void visit(const MulExpression mulExpression) { output.writeln(""); @@ -884,41 +625,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const NewAnonClassExpression newAnonClassExpression) - { - mixin (tagAndAccept!"newAnonClassExpression"); - } - - override void visit(const NewExpression newExpression) - { - mixin (tagAndAccept!"newExpression"); - } - - override void visit(const StatementNoCaseNoDefault statementNoCaseNoDefault) - { - mixin (tagAndAccept!"statementNoCaseNoDefault"); - } - - override void visit(const NonVoidInitializer nonVoidInitializer) - { - mixin (tagAndAccept!"nonVoidInitializer"); - } - - override void visit(const OrExpression orExpression) - { - mixin (tagAndAccept!"orExpression"); - } - - override void visit(const OrOrExpression orOrExpression) - { - mixin (tagAndAccept!"orOrExpression"); - } - - override void visit(const OutStatement outStatement) - { - mixin (tagAndAccept!"outStatement"); - } - override void visit(const Parameter param) { output.writeln(""); @@ -934,16 +640,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const Parameters parameters) - { - mixin (tagAndAccept!"parameters"); - } - - override void visit(const Postblit postblit) - { - mixin (tagAndAccept!"postblit"); - } - override void visit(const PostIncDecExpression postIncDecExpression) { output.writeln(""); } - override void visit(const PragmaDeclaration pragmaDeclaration) - { - mixin (tagAndAccept!"pragmaDeclaration"); - } - - override void visit(const PragmaExpression pragmaExpression) - { - mixin (tagAndAccept!"pragmaExpression"); - } - override void visit(const PreIncDecExpression preIncDecExpression) { output.writeln(""); } - override void visit(const PrimaryExpression primaryExpression) - { - mixin (tagAndAccept!"primaryExpression"); - } - - // TODO: Register - override void visit(const RelExpression relExpression) { output.writeln(""); } - override void visit(const Statement statement) - { - mixin (tagAndAccept!"statement"); - } - - override void visit(const StaticAssertDeclaration staticAssertDeclaration) - { - mixin (tagAndAccept!"staticAssertDeclaration"); - } - - override void visit(const StaticAssertStatement staticAssertStatement) - { - mixin (tagAndAccept!"staticAssertStatement"); - } - - override void visit(const StaticConstructor staticConstructor) - { - mixin (tagAndAccept!"staticConstructor"); - } - - override void visit(const StaticDestructor staticDestructor) - { - mixin (tagAndAccept!"staticDestructor"); - } - - override void visit(const StaticIfCondition staticIfCondition) - { - mixin (tagAndAccept!"staticIfCondition"); - } - - override void visit(const StorageClass storageClass) - { - mixin (tagAndAccept!"storageClass"); - } - - override void visit(const StructBody structBody) - { - mixin (tagAndAccept!"structBody"); - } - override void visit(const StructDeclaration structDec) { output.writeln(""); @@ -1123,36 +747,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const StructInitializer structInitializer) - { - mixin (tagAndAccept!"structInitializer"); - } - - override void visit(const StructMemberInitializer structMemberInitializer) - { - mixin (tagAndAccept!"structMemberInitializer"); - } - - override void visit(const StructMemberInitializers structMemberInitializers) - { - mixin (tagAndAccept!"structMemberInitializers"); - } - - override void visit(const SwitchStatement switchStatement) - { - mixin (tagAndAccept!"switchStatement"); - } - - override void visit(const Symbol symbol) - { - mixin (tagAndAccept!"symbol"); - } - - override void visit(const SynchronizedStatement synchronizedStatement) - { - mixin (tagAndAccept!"synchronizedStatement"); - } - override void visit(const TemplateAliasParameter templateAliasParameter) { output.writeln(""); @@ -1188,26 +782,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const TemplateArgument templateArgument) - { - mixin (tagAndAccept!"templateArgument"); - } - - override void visit(const TemplateArgumentList templateArgumentList) - { - mixin (tagAndAccept!"templateArgumentList"); - } - - override void visit(const TemplateArguments templateArguments) - { - mixin (tagAndAccept!"templateArguments"); - } - - override void visit (const EponymousTemplateDeclaration eponymousTemplateDeclaration) - { - mixin (tagAndAccept!"eponymousTemplateDeclaration"); - } - override void visit(const TemplateDeclaration templateDeclaration) { if (templateDeclaration.eponymousTemplateDeclaration !is null) @@ -1231,71 +805,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const TemplateInstance templateInstance) - { - mixin (tagAndAccept!"templateInstance"); - } - - override void visit(const TemplateMixinExpression templateMixinExpression) - { - mixin (tagAndAccept!"templateMixinExpression"); - } - - override void visit(const TemplateParameter templateParameter) - { - mixin (tagAndAccept!"templateParameter"); - } - - override void visit(const TemplateParameterList templateParameterList) - { - mixin (tagAndAccept!"templateParameterList"); - } - - override void visit(const TemplateParameters templateParameters) - { - mixin (tagAndAccept!"templateParameters"); - } - - override void visit(const TemplateSingleArgument templateSingleArgument) - { - mixin (tagAndAccept!"templateSingleArgument"); - } - - override void visit(const TemplateThisParameter templateThisParameter) - { - mixin (tagAndAccept!"templateThisParameter"); - } - - override void visit(const TemplateTupleParameter templateTupleParameter) - { - mixin (tagAndAccept!"templateTupleParameter"); - } - - override void visit(const TemplateTypeParameter templateTypeParameter) - { - mixin (tagAndAccept!"templateTypeParameter"); - } - - override void visit(const TemplateValueParameter templateValueParameter) - { - mixin (tagAndAccept!"templateValueParameter"); - } - - override void visit(const TemplateValueParameterDefault templateValueParameterDefault) - { - mixin (tagAndAccept!"templateValueParameterDefault"); - } - - override void visit(const TernaryExpression ternaryExpression) - { - mixin (tagAndAccept!"ternaryExpression"); - } - - override void visit(const ThrowStatement throwStatement) - { - mixin (tagAndAccept!"throwStatement"); - } - override void visit(const Token token) { string tagName; @@ -1325,16 +834,6 @@ class XMLPrinter : ASTVisitor output.writeln("<", tagName, ">", xmlEscape(token.text), ""); } - override void visit(const TraitsExpression traitsExpression) - { - mixin (tagAndAccept!"traitsExpression"); - } - - override void visit(const TryStatement tryStatement) - { - mixin (tagAndAccept!"tryStatement"); - } - override void visit(const Type type) { auto app = appender!string(); @@ -1357,11 +856,6 @@ class XMLPrinter : ASTVisitor } } - override void visit(const TypeSpecialization typeSpecialization) - { - mixin (tagAndAccept!"typeSpecialization"); - } - override void visit(const TypeSuffix typeSuffix) { if (typeSuffix.star) @@ -1407,16 +901,6 @@ class XMLPrinter : ASTVisitor } } - override void visit(const TypeidExpression typeidExpression) - { - mixin (tagAndAccept!"typeidExpression"); - } - - override void visit(const TypeofExpression typeofExpression) - { - mixin (tagAndAccept!"typeofExpression"); - } - override void visit(const UnaryExpression unaryExpression) { output.writeln(""); @@ -1467,31 +951,6 @@ class XMLPrinter : ASTVisitor output.writeln(""); } - override void visit(const Vector vector) - { - mixin (tagAndAccept!"vector"); - } - - override void visit(const VersionCondition versionCondition) - { - mixin (tagAndAccept!"versionCondition"); - } - - override void visit(const VersionSpecification versionSpecification) - { - mixin (tagAndAccept!"versionSpecification"); - } - - override void visit(const WhileStatement whileStatement) - { - mixin (tagAndAccept!"whileStatement"); - } - - override void visit(const WithStatement withStatement) - { - mixin (tagAndAccept!"withStatement"); - } - override void visit(const XorExpression xorExpression) { output.writeln(""); @@ -1507,6 +966,125 @@ class XMLPrinter : ASTVisitor output.writeln(""); } + override void visit(const AliasInitializer aliasInitializer) { mixin (tagAndAccept!"aliasInitializer"); } + override void visit(const AliasThisDeclaration aliasThisDeclaration) { mixin (tagAndAccept!"aliasThisDeclaration"); } + override void visit(const ArgumentList argumentList) { mixin (tagAndAccept!"argumentList"); } + override void visit(const Arguments arguments) { mixin (tagAndAccept!"arguments"); } + override void visit(const ArrayInitializer arrayInitializer) { mixin (tagAndAccept!"arrayInitializer"); } + override void visit(const ArrayLiteral arrayLiteral) { mixin (tagAndAccept!"arrayLiteral"); } + override void visit(const ArrayMemberInitialization arrayMemberInitialization) { mixin (tagAndAccept!"arrayMemberInitialization"); } + override void visit(const AsmAddExp asmAddExp) { mixin (tagAndAccept!"asmAddExp"); } + override void visit(const AsmAndExp asmAndExp) { mixin (tagAndAccept!"asmAndExp"); } + override void visit(const AsmBrExp asmBrExp) { mixin (tagAndAccept!"asmBrExp"); } + override void visit(const AsmEqualExp asmEqualExp) { mixin (tagAndAccept!"asmEqualExp"); } + override void visit(const AsmExp asmExp) { mixin (tagAndAccept!"asmExp"); } + override void visit(const AsmLogAndExp asmLogAndExp) { mixin (tagAndAccept!"asmLogAndExp"); } + override void visit(const AsmLogOrExp asmLogOrExp) { mixin (tagAndAccept!"asmLogOrExp"); } + override void visit(const AsmMulExp asmMulExp) { mixin (tagAndAccept!"asmMulExp"); } + override void visit(const AsmOrExp asmOrExp) { mixin (tagAndAccept!"asmOrExp"); } + override void visit(const AsmPrimaryExp asmPrimaryExp) { mixin (tagAndAccept!"asmPrimaryExp"); } + override void visit(const AsmRelExp asmRelExp) { mixin (tagAndAccept!"asmRelExp"); } + override void visit(const AsmShiftExp asmShiftExp) { mixin (tagAndAccept!"asmShiftExp"); } + override void visit(const AsmStatement asmStatement) { mixin (tagAndAccept!"asmStatement"); } + override void visit(const AsmTypePrefix asmTypePrefix) { mixin (tagAndAccept!"asmTypePrefix"); } + override void visit(const AsmUnaExp asmUnaExp) { mixin (tagAndAccept!"asmUnaExp"); } + override void visit(const AsmXorExp asmXorExp) { mixin (tagAndAccept!"asmXorExp"); } + override void visit(const AssocArrayLiteral assocArrayLiteral) { mixin (tagAndAccept!"assocArrayLiteral"); } + override void visit(const AttributeDeclaration attributeDeclaration) { mixin (tagAndAccept!"attributeDeclaration"); } + override void visit(const BaseClass baseClass) { mixin (tagAndAccept!"baseClass"); } + override void visit(const BaseClassList baseClassList) { mixin (tagAndAccept!"baseClassList"); } + override void visit(const BlockStatement blockStatement) { mixin (tagAndAccept!"blockStatement"); } + override void visit(const BodyStatement bodyStatement) { mixin (tagAndAccept!"bodyStatement"); } + override void visit(const CaseStatement caseStatement) { mixin (tagAndAccept!"caseStatement"); } + override void visit(const CastExpression castExpression) { mixin (tagAndAccept!"castExpression"); } + override void visit(const CastQualifier castQualifier) { mixin (tagAndAccept!"castQualifier"); } + override void visit(const Catches catches) { mixin (tagAndAccept!"catches"); } + override void visit(const CmpExpression cmpExpression) { mixin (tagAndAccept!"cmpExpression"); } + override void visit(const CompileCondition compileCondition) { mixin (tagAndAccept!"compileCondition"); } + override void visit(const Constraint constraint) { mixin (tagAndAccept!"constraint"); } + override void visit(const Constructor constructor) { mixin (tagAndAccept!"constructor"); } + override void visit(const Declaration declaration) { mixin (tagAndAccept!"declaration"); } + override void visit(const DeclarationOrStatement declarationOrStatement) { mixin (tagAndAccept!"declarationOrStatement"); } + override void visit(const DeclarationsAndStatements declarationsAndStatements) { mixin (tagAndAccept!"declarationsAndStatements"); } + override void visit(const DefaultStatement defaultStatement) { mixin (tagAndAccept!"defaultStatement"); } + override void visit(const DeleteExpression deleteExpression) { mixin (tagAndAccept!"deleteExpression"); } + override void visit(const DeleteStatement deleteStatement) { mixin (tagAndAccept!"deleteStatement"); } + override void visit(const Destructor destructor) { mixin (tagAndAccept!"destructor"); } + override void visit(const DoStatement doStatement) { mixin (tagAndAccept!"doStatement"); } + override void visit(const EnumBody enumBody) { mixin (tagAndAccept!"enumBody"); } + override void visit(const EponymousTemplateDeclaration eponymousTemplateDeclaration) { mixin (tagAndAccept!"eponymousTemplateDeclaration"); } + override void visit(const Expression expression) { mixin (tagAndAccept!"expression"); } + override void visit(const ExpressionStatement expressionStatement) { mixin (tagAndAccept!"expressionStatement"); } + override void visit(const FinalSwitchStatement finalSwitchStatement) { mixin (tagAndAccept!"finalSwitchStatement"); } + override void visit(const ForeachTypeList foreachTypeList) { mixin (tagAndAccept!"foreachTypeList"); } + override void visit(const FunctionAttribute functionAttribute) { mixin (tagAndAccept!"functionAttribute"); } + override void visit(const FunctionBody functionBody) { mixin (tagAndAccept!"functionBody"); } + override void visit(const FunctionCallExpression functionCallExpression) { mixin (tagAndAccept!"functionCallExpression"); } + override void visit(const FunctionCallStatement functionCallStatement) { mixin (tagAndAccept!"functionCallStatement"); } + override void visit(const IdentifierChain identifierChain) { mixin (tagAndAccept!"identifierChain"); } + override void visit(const IdentifierList identifierList) { mixin (tagAndAccept!"identifierList"); } + override void visit(const IdentifierOrTemplateChain identifierOrTemplateChain) { mixin (tagAndAccept!"identifierOrTemplateChain"); } + override void visit(const IdentifierOrTemplateInstance identifierOrTemplateInstance) { mixin (tagAndAccept!"identifierOrTemplateInstance"); } + override void visit(const ImportBindings importBindings) { mixin (tagAndAccept!"importBindings"); } + override void visit(const ImportDeclaration importDeclaration) { mixin (tagAndAccept!"importDeclaration"); } + override void visit(const ImportExpression importExpression) { mixin (tagAndAccept!"importExpression"); } + override void visit(const IndexExpression indexExpression) { mixin (tagAndAccept!"indexExpression"); } + override void visit(const InStatement inStatement) { mixin (tagAndAccept!"inStatement"); } + override void visit(const KeyValuePairs keyValuePairs) { mixin (tagAndAccept!"keyValuePairs"); } + override void visit(const MixinExpression mixinExpression) { mixin (tagAndAccept!"mixinExpression"); } + override void visit(const MixinTemplateDeclaration mixinTemplateDeclaration) { mixin (tagAndAccept!"mixinTemplateDeclaration"); } + override void visit(const MixinTemplateName mixinTemplateName) { mixin (tagAndAccept!"mixinTemplateName"); } override void visit(const ModuleDeclaration moduleDeclaration) { mixin (tagAndAccept!"moduleDeclaration"); } override void visit(const LastCatch lastCatch) { mixin (tagAndAccept!"lastCatch"); } + override void visit(const NewExpression newExpression) { mixin (tagAndAccept!"newExpression"); } + override void visit(const NonVoidInitializer nonVoidInitializer) { mixin (tagAndAccept!"nonVoidInitializer"); } + override void visit(const Operands operands) { mixin (tagAndAccept!"operands"); } + override void visit(const OrExpression orExpression) { mixin (tagAndAccept!"orExpression"); } + override void visit(const OrOrExpression orOrExpression) { mixin (tagAndAccept!"orOrExpression"); } + override void visit(const OutStatement outStatement) { mixin (tagAndAccept!"outStatement"); } override void visit(const MixinDeclaration mixinDeclaration) { mixin (tagAndAccept!"mixinDeclaration"); } + override void visit(const Parameters parameters) { mixin (tagAndAccept!"parameters"); } + override void visit(const Postblit postblit) { mixin (tagAndAccept!"postblit"); } override void visit(const NewAnonClassExpression newAnonClassExpression) { mixin (tagAndAccept!"newAnonClassExpression"); } + override void visit(const PragmaDeclaration pragmaDeclaration) { mixin (tagAndAccept!"pragmaDeclaration"); } + override void visit(const PragmaExpression pragmaExpression) { mixin (tagAndAccept!"pragmaExpression"); } + override void visit(const PrimaryExpression primaryExpression) { mixin (tagAndAccept!"primaryExpression"); } + override void visit(const ScopeGuardStatement scopeGuardStatement) { mixin (tagAndAccept!"scopeGuardStatement"); } + override void visit(const SharedStaticConstructor sharedStaticConstructor) { mixin (tagAndAccept!"sharedStaticConstructor"); } + override void visit(const SharedStaticDestructor sharedStaticDestructor) { mixin (tagAndAccept!"sharedStaticDestructor"); } + override void visit(const StatementNoCaseNoDefault statementNoCaseNoDefault) { mixin (tagAndAccept!"statementNoCaseNoDefault"); } + override void visit(const StaticAssertDeclaration staticAssertDeclaration) { mixin (tagAndAccept!"staticAssertDeclaration"); } + override void visit(const StaticAssertStatement staticAssertStatement) { mixin (tagAndAccept!"staticAssertStatement"); } + override void visit(const StaticConstructor staticConstructor) { mixin (tagAndAccept!"staticConstructor"); } + override void visit(const StaticDestructor staticDestructor) { mixin (tagAndAccept!"staticDestructor"); } + override void visit(const StaticIfCondition staticIfCondition) { mixin (tagAndAccept!"staticIfCondition"); } + override void visit(const StorageClass storageClass) { mixin (tagAndAccept!"storageClass"); } + override void visit(const StructBody structBody) { mixin (tagAndAccept!"structBody"); } + override void visit(const StructInitializer structInitializer) { mixin (tagAndAccept!"structInitializer"); } + override void visit(const StructMemberInitializers structMemberInitializers) { mixin (tagAndAccept!"structMemberInitializers"); } + override void visit(const StructMemberInitializer structMemberInitializer) { mixin (tagAndAccept!"structMemberInitializer"); } + override void visit(const SwitchStatement switchStatement) { mixin (tagAndAccept!"switchStatement"); } + override void visit(const Symbol symbol) { mixin (tagAndAccept!"symbol"); } + override void visit(const SynchronizedStatement synchronizedStatement) { mixin (tagAndAccept!"synchronizedStatement"); } override void visit(const Statement statement) { mixin (tagAndAccept!"statement"); } + override void visit(const TemplateArgumentList templateArgumentList) { mixin (tagAndAccept!"templateArgumentList"); } + override void visit(const TemplateArguments templateArguments) { mixin (tagAndAccept!"templateArguments"); } + override void visit(const TemplateArgument templateArgument) { mixin (tagAndAccept!"templateArgument"); } + override void visit(const TemplateMixinExpression templateMixinExpression) { mixin (tagAndAccept!"templateMixinExpression"); } + override void visit(const TemplateParameterList templateParameterList) { mixin (tagAndAccept!"templateParameterList"); } + override void visit(const TemplateParameters templateParameters) { mixin (tagAndAccept!"templateParameters"); } + override void visit(const TemplateParameter templateParameter) { mixin (tagAndAccept!"templateParameter"); } + override void visit(const TemplateSingleArgument templateSingleArgument) { mixin (tagAndAccept!"templateSingleArgument"); } + override void visit(const TemplateThisParameter templateThisParameter) { mixin (tagAndAccept!"templateThisParameter"); } + override void visit(const TemplateTupleParameter templateTupleParameter) { mixin (tagAndAccept!"templateTupleParameter"); } + override void visit(const TemplateTypeParameter templateTypeParameter) { mixin (tagAndAccept!"templateTypeParameter"); } + override void visit(const TemplateValueParameterDefault templateValueParameterDefault) { mixin (tagAndAccept!"templateValueParameterDefault"); } + override void visit(const TemplateValueParameter templateValueParameter) { mixin (tagAndAccept!"templateValueParameter"); } + override void visit(const TernaryExpression ternaryExpression) { mixin (tagAndAccept!"ternaryExpression"); } + override void visit(const ThrowStatement throwStatement) { mixin (tagAndAccept!"throwStatement"); } + override void visit(const TryStatement tryStatement) { mixin (tagAndAccept!"tryStatement"); } override void visit(const TemplateInstance templateInstance) { mixin (tagAndAccept!"templateInstance"); } + override void visit(const TypeofExpression typeofExpression) { mixin (tagAndAccept!"typeofExpression"); } override void visit(const TypeSpecialization typeSpecialization) { mixin (tagAndAccept!"typeSpecialization"); } override void visit(const TraitsExpression traitsExpression) { mixin (tagAndAccept!"traitsExpression"); } + override void visit(const Vector vector) { mixin (tagAndAccept!"vector"); } + override void visit(const VersionCondition versionCondition) { mixin (tagAndAccept!"versionCondition"); } + override void visit(const VersionSpecification versionSpecification) { mixin (tagAndAccept!"versionSpecification"); } + override void visit(const WhileStatement whileStatement) { mixin (tagAndAccept!"whileStatement"); } + override void visit(const WithStatement withStatement) { mixin (tagAndAccept!"withStatement"); } override void visit(const TypeidExpression typeidExpression) { mixin (tagAndAccept!"typeidExpression"); } + alias visit = ASTVisitor.visit; private static string xmlEscape(string s) diff --git a/libdparse b/libdparse index acb6b43..cef8259 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit acb6b43655b1144fbcaf08ec0442a81143cdb569 +Subproject commit cef8259a0d9f153bea6ca8c86812e714206ceaed diff --git a/makefile b/makefile index b65d322..3c33e0b 100644 --- a/makefile +++ b/makefile @@ -17,9 +17,13 @@ SRC = main.d\ inifiled/source/*.d INCLUDE_PATHS = -Ilibdparse/src VERSIONS = +DEBUG_VERSIONS = -version=std_parser_verbose all: dmdbuild +debug: + ${DMD} -ofdsc ${VERSIONS} ${DEBUG_VERSIONS} ${INCLUDE_PATHS} ${SRC} + dmdbuild: ${DMD} -O -release -inline -ofdscanner ${VERSIONS} ${INCLUDE_PATHS} ${SRC} diff --git a/test.sh b/test.sh index 8de8d51..7325f67 100755 --- a/test.sh +++ b/test.sh @@ -3,13 +3,7 @@ rm -f test rm -f test.o dmd\ - main.d\ - stats.d\ - imports.d\ - highlighter.d\ - ctags.d\ - astprinter.d\ - outliner.d\ + *.d\ libdparse/src/std/*.d\ libdparse/src/std/d/*.d\ inifiled/source/*.d\