diff options
author | Andrew Gvozdev | 2011-04-29 03:00:09 +0000 |
---|---|---|
committer | Andrew Gvozdev | 2011-04-29 03:00:09 +0000 |
commit | f1daf6235aa95f02713dcbd32831f171e5b0af8c (patch) | |
tree | 91e02f16ad414135a3cb20262320cb3e06ad88e1 | |
parent | 1c43fad405160d436c65a79bb6545f2d6e4b60b0 (diff) | |
download | org.eclipse.cdt-f1daf6235aa95f02713dcbd32831f171e5b0af8c.tar.gz org.eclipse.cdt-f1daf6235aa95f02713dcbd32831f171e5b0af8c.tar.xz org.eclipse.cdt-f1daf6235aa95f02713dcbd32831f171e5b0af8c.zip |
bug 343429: [checker] Checker to pinpoint unused static functions in a file
5 files changed, 861 insertions, 310 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties b/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties index f94ed6f9e75..cd01cc4b343 100644 --- a/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties +++ b/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties @@ -111,3 +111,15 @@ checker.name.AbstractClassCreation = Abstract class cannot be instantiated problem.name.AbstractClassCreation = Abstract class cannot be instantiated problem.messagePattern.AbstractClassCreation = The type ''{0}'' must implement the inherited pure virtual method ''{1}'' problem.description.AbstractClassCreation = All inherited pure virtual methods must be implemented to allow instantiation of the class + +checker.name.UnusedSymbolInFileScopeChecker = Unused symbols and declarations in file scope +problem.description.UnusedVariableDeclarationProblem = Finds unused global variable declarations in file scope +problem.messagePattern.UnusedVariableDeclarationProblem = Unused declaration of variable ''{0}'' +problem.name.UnusedVariableDeclarationProblem = Unused variable declaration in file scope +problem.description.UnusedFunctionDeclarationProblem = Finds unused function declarations +problem.messagePattern.UnusedFunctionDeclarationProblem = Unused declaration of function ''{0}'' +problem.name.UnusedFunctionDeclarationProblem = Unused function declaration +problem.description.UnusedStaticFunctionProblem = Finds static functions which cannot be possible used not being referenced inside the file +problem.messagePattern.UnusedStaticFunctionProblem = Unused static function ''{0}'' +problem.name.UnusedStaticFunctionProblem = Unused static function + diff --git a/codan/org.eclipse.cdt.codan.checkers/plugin.xml b/codan/org.eclipse.cdt.codan.checkers/plugin.xml index 0d09d0c6563..f1afe2bd9e6 100644 --- a/codan/org.eclipse.cdt.codan.checkers/plugin.xml +++ b/codan/org.eclipse.cdt.codan.checkers/plugin.xml @@ -9,345 +9,380 @@ class="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionChecker" id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionChecker" name="%checker.name.AssignmentInCondition"> - <problem - defaultSeverity="Warning" - description="%problem.description.AssignmentInCondition" - id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem" - messagePattern="%problem.messagePattern.AssignmentInCondition" - name="%problem.name.AssignmentInCondition"> - </problem> + <problem + defaultSeverity="Warning" + description="%problem.description.AssignmentInCondition" + id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem" + messagePattern="%problem.messagePattern.AssignmentInCondition" + name="%problem.name.AssignmentInCondition"> + </problem> </checker> - <checker + <checker class="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker" id="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker" name="%checker.name.StatementHasNoEffect"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultSeverity="Warning" - description="%problem.description.StatementHasNoEffect" - id="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem" - messagePattern="%problem.messagePattern.StatementHasNoEffect" - name="%problem.name.StatementHasNoEffect"/> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultSeverity="Warning" + description="%problem.description.StatementHasNoEffect" + id="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem" + messagePattern="%problem.messagePattern.StatementHasNoEffect" + name="%problem.name.StatementHasNoEffect"/> </checker> <checker class="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor" id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDescructor" name="%checker.name.NonVirtualDescructor"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultSeverity="Warning" - description="%problem.description.NonVirtualDescructor" - id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem" - messagePattern="%problem.messagePattern.NonVirtualDescructor" - name="%problem.name.NonVirtualDescructor"> - </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultSeverity="Warning" + description="%problem.description.NonVirtualDescructor" + id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem" + messagePattern="%problem.messagePattern.NonVirtualDescructor" + name="%problem.name.NonVirtualDescructor"> + </problem> </checker> <checker class="org.eclipse.cdt.codan.internal.checkers.CatchByReference" id="org.eclipse.cdt.codan.internal.checkers.CatchByReference" name="%checker.name.CatchByReference"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultSeverity="Warning" - description="%problem.description.CatchByReference" - id="org.eclipse.cdt.codan.internal.checkers.CatchByReference" - name="%problem.name.CatchByReference" - messagePattern="%problem.messagePattern.CatchByReference"> - </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultSeverity="Warning" + description="%problem.description.CatchByReference" + id="org.eclipse.cdt.codan.internal.checkers.CatchByReference" + name="%problem.name.CatchByReference" + messagePattern="%problem.messagePattern.CatchByReference"> + </problem> </checker> <checker class="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker" id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker" name="%checker.name.SuggestedParenthesis"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultSeverity="Warning" - description="%problem.description.SuggestedParenthesis" - id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem" - messagePattern="%problem.messagePattern.SuggestedParenthesis" - name="%problem.name.SuggestedParenthesis"> - </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultSeverity="Warning" + description="%problem.description.SuggestedParenthesis" + id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem" + messagePattern="%problem.messagePattern.SuggestedParenthesis" + name="%problem.name.SuggestedParenthesis"> + </problem> </checker> - <checker + <checker class="org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker" id="org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker" name="%checker.name.NamingConventionFunction"> - <problem - category="org.eclipse.cdt.codan.core.categories.CodeStyle" - defaultEnabled="false" - defaultSeverity="Info" - description="%problem.description.NamingConventionFunction" - id="org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker" - messagePattern="%problem.messagePattern.NamingConventionFunction" + <problem + category="org.eclipse.cdt.codan.core.categories.CodeStyle" + defaultEnabled="false" + defaultSeverity="Info" + description="%problem.description.NamingConventionFunction" + id="org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker" + messagePattern="%problem.messagePattern.NamingConventionFunction" + multiple="true" + name="%problem.name.NamingConventionFunction"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.ReturnChecker" + id="org.eclipse.cdt.codan.internal.checkers.ReturnChecker" + name="%checker.name.ReturnChecker"> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.NoReturnValue" + id="org.eclipse.cdt.codan.checkers.noreturn" + messagePattern="%problem.messagePattern.NoReturnValue" + name="%problem.name.NoReturnValue"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.UnusedReturnValue" + id="org.eclipse.cdt.codan.checkers.errreturnvalue" + messagePattern="%problem.messagePattern.UnusedReturnValue" + name="%problem.name.UnusedReturnValue"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Warning" + description="%problem.description.NoReturn" + id="org.eclipse.cdt.codan.checkers.errnoreturn" + messagePattern="%problem.messagePattern.NoReturn" + name="%problem.name.NoReturn"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker" + id="org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker" + name="%binding.checker.name"> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.G" + id="org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.G" + name="%problem.name.G"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.0" + id="org.eclipse.cdt.codan.internal.checkers.OverloadProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.0" + name="%problem.name.0"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.1" + id="org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.1" + name="%problem.name.1"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.2" + id="org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.2" + name="%problem.name.2"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.3" + id="org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.3" + name="%problem.name.3"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.4" + id="org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.4" + name="%problem.name.4"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.5" + id="org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.5" + name="%problem.name.5"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.6" + id="org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.6" + name="%problem.name.6"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.7" + id="org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.7" + name="%problem.name.7"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.8" + id="org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.8" + name="%problem.name.8"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.9" + id="org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.9" + name="%problem.name.9"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.10" + id="org.eclipse.cdt.codan.internal.checkers.InvalidArguments" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.10" + name="%problem.name.10"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.11" + id="org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.11" + name="%problem.name.11"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.12" + id="org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem" + markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" + messagePattern="%problem.messagePattern.12" + name="%problem.name.12"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfChecker" + id="org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfChecker" + name="%checker.name.AssignmentToItself"> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.AssignmentToItself" + id="org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem" + messagePattern="%problem.messagePattern.AssignmentToItself" + name="%problem.name.AssignmentToItself"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.ReturnStyleChecker" + id="org.eclipse.cdt.codan.internal.checkers.ReturnStyle" + name="%checker.name.ReturnStyle"> + <problem + category="org.eclipse.cdt.codan.core.categories.CodeStyle" + defaultEnabled="false" + defaultSeverity="Warning" + description="%problem.description.ReturnStyle" + id="org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem" + messagePattern="%problem.messagePattern.ReturnStyle" + name="%problem.name.ReturnStyle"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonChecker" + id="org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolon" + name="%checker.name.SuspiciousSemicolon"> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Warning" + description="%problem.description.SuspiciousSemicolon" + id="org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem" + messagePattern="%problem.messagePattern.SuspiciousSemicolon" + name="%problem.name.SuspiciousSemicolon"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.CaseBreakChecker" + id="org.eclipse.cdt.codan.internal.checkers.CaseBreak" + name="%checker.name.CaseBreak"> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Warning" + description="%problem.description.CaseBreak" + id="org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem" + messagePattern="%problem.messagePattern.CaseBreak" + name="%checker.name.CaseBreak"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.fs.ScanfFormatStringSecurityChecker" + id="org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityChecker" + name="%checker.name.FormatString"> + <problem + category="org.eclipse.cdt.codan.core.categories.Security" + defaultEnabled="false" + defaultSeverity="Warning" + description="%problem.description.FormatString" + id="org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem" + messagePattern="%problem.messagePattern.FormatString" + name="%problem.name.FormatString"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.AbstractClassInstantiationChecker" + id="org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation" + name="%checker.name.AbstractClassCreation"> + <problem + category="org.eclipse.cdt.codan.core.categories.CompilerErrors" + defaultEnabled="true" + defaultSeverity="Error" + description="%problem.description.AbstractClassCreation" + id="org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation" + messagePattern="%problem.messagePattern.AbstractClassCreation" + name="%problem.name.AbstractClassCreation"> + </problem> + </checker> + <checker + class="org.eclipse.cdt.codan.internal.checkers.UnusedSymbolInFileScopeChecker" + id="org.eclipse.cdt.codan.internal.checkers.UnusedSymbolInFileScopeChecker" + name="%checker.name.UnusedSymbolInFileScopeChecker"> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Warning" + description="%problem.description.UnusedVariableDeclarationProblem" + id="org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem" + messagePattern="%problem.messagePattern.UnusedVariableDeclarationProblem" + multiple="true" + name="%problem.name.UnusedVariableDeclarationProblem"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Warning" + description="%problem.description.UnusedFunctionDeclarationProblem" + id="org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem" + messagePattern="%problem.messagePattern.UnusedFunctionDeclarationProblem" + multiple="true" + name="%problem.name.UnusedFunctionDeclarationProblem"> + </problem> + <problem + category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" + defaultEnabled="true" + defaultSeverity="Warning" + description="%problem.description.UnusedStaticFunctionProblem" + id="org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem" + messagePattern="%problem.messagePattern.UnusedStaticFunctionProblem" multiple="true" - name="%problem.name.NamingConventionFunction"> - </problem> + name="%problem.name.UnusedStaticFunctionProblem"> + </problem> </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.ReturnChecker" - id="org.eclipse.cdt.codan.internal.checkers.ReturnChecker" - name="%checker.name.ReturnChecker"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.NoReturnValue" - id="org.eclipse.cdt.codan.checkers.noreturn" - messagePattern="%problem.messagePattern.NoReturnValue" - name="%problem.name.NoReturnValue"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.UnusedReturnValue" - id="org.eclipse.cdt.codan.checkers.errreturnvalue" - messagePattern="%problem.messagePattern.UnusedReturnValue" - name="%problem.name.UnusedReturnValue"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultEnabled="true" - defaultSeverity="Warning" - description="%problem.description.NoReturn" - id="org.eclipse.cdt.codan.checkers.errnoreturn" - messagePattern="%problem.messagePattern.NoReturn" - name="%problem.name.NoReturn"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker" - id="org.eclipse.cdt.codan.internal.checkers.ProblemBindingChecker" - name="%binding.checker.name"> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.G" - id="org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.G" - name="%problem.name.G"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.0" - id="org.eclipse.cdt.codan.internal.checkers.OverloadProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.0" - name="%problem.name.0"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.1" - id="org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.1" - name="%problem.name.1"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.2" - id="org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.2" - name="%problem.name.2"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.3" - id="org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.3" - name="%problem.name.3"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.4" - id="org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.4" - name="%problem.name.4"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.5" - id="org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.5" - name="%problem.name.5"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.6" - id="org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.6" - name="%problem.name.6"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.7" - id="org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.7" - name="%problem.name.7"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.8" - id="org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.8" - name="%problem.name.8"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.9" - id="org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.9" - name="%problem.name.9"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.10" - id="org.eclipse.cdt.codan.internal.checkers.InvalidArguments" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.10" - name="%problem.name.10"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.11" - id="org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.11" - name="%problem.name.11"> - </problem> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.12" - id="org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem" - markerType="org.eclipse.cdt.codan.core.codanSemanticProblem" - messagePattern="%problem.messagePattern.12" - name="%problem.name.12"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfChecker" - id="org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfChecker" - name="%checker.name.AssignmentToItself"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.AssignmentToItself" - id="org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem" - messagePattern="%problem.messagePattern.AssignmentToItself" - name="%problem.name.AssignmentToItself"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.ReturnStyleChecker" - id="org.eclipse.cdt.codan.internal.checkers.ReturnStyle" - name="%checker.name.ReturnStyle"> - <problem - category="org.eclipse.cdt.codan.core.categories.CodeStyle" - defaultEnabled="false" - defaultSeverity="Warning" - description="%problem.description.ReturnStyle" - id="org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem" - messagePattern="%problem.messagePattern.ReturnStyle" - name="%problem.name.ReturnStyle"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonChecker" - id="org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolon" - name="%checker.name.SuspiciousSemicolon"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultEnabled="true" - defaultSeverity="Warning" - description="%problem.description.SuspiciousSemicolon" - id="org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem" - messagePattern="%problem.messagePattern.SuspiciousSemicolon" - name="%problem.name.SuspiciousSemicolon"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.CaseBreakChecker" - id="org.eclipse.cdt.codan.internal.checkers.CaseBreak" - name="%checker.name.CaseBreak"> - <problem - category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems" - defaultEnabled="true" - defaultSeverity="Warning" - description="%problem.description.CaseBreak" - id="org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem" - messagePattern="%problem.messagePattern.CaseBreak" - name="%checker.name.CaseBreak"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.fs.ScanfFormatStringSecurityChecker" - id="org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityChecker" - name="%checker.name.FormatString"> - <problem - category="org.eclipse.cdt.codan.core.categories.Security" - defaultEnabled="false" - defaultSeverity="Warning" - description="%problem.description.FormatString" - id="org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem" - messagePattern="%problem.messagePattern.FormatString" - name="%problem.name.FormatString"> - </problem> - </checker> - <checker - class="org.eclipse.cdt.codan.internal.checkers.AbstractClassInstantiationChecker" - id="org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation" - name="%checker.name.AbstractClassCreation"> - <problem - category="org.eclipse.cdt.codan.core.categories.CompilerErrors" - defaultEnabled="true" - defaultSeverity="Error" - description="%problem.description.AbstractClassCreation" - id="org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation" - messagePattern="%problem.messagePattern.AbstractClassCreation" - name="%problem.name.AbstractClassCreation"> - </problem> - </checker> </extension> </plugin> diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java new file mode 100644 index 00000000000..841b8d45b06 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (c) 2011 Andrew Gvozdev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Gvozdev - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.codan.checkers.CodanCheckersActivator; +import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IProblemType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; + +/** + * Checker looking for unused function or variable declarations. + */ +public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { + public static final String ER_UNUSED_VARIABLE_DECLARATION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem"; //$NON-NLS-1$ + public static final String ER_UNUSED_FUNCTION_DECLARATION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem"; //$NON-NLS-1$ + public static final String ER_UNUSED_STATIC_FUNCTION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem"; //$NON-NLS-1$ + + private Map<IBinding, IASTDeclarator> externFunctionDeclarations = new HashMap<IBinding, IASTDeclarator>(); + private Map<IBinding, IASTDeclarator> staticFunctionDeclarations = new HashMap<IBinding, IASTDeclarator>(); + private Map<IBinding, IASTDeclarator> staticFunctionDefinitions = new HashMap<IBinding, IASTDeclarator>(); + private Map<IBinding, IASTDeclarator> externVariableDeclarations = new HashMap<IBinding, IASTDeclarator>(); + private Map<IBinding, IASTDeclarator> staticVariableDeclarations = new HashMap<IBinding, IASTDeclarator>(); + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckerWithPreferences#initParameters + * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) + */ + @Override + public void initPreferences(IProblemWorkingCopy problem) { + super.initPreferences(problem); + } + + private void clearCandidates() { + externFunctionDeclarations.clear(); + staticFunctionDeclarations.clear(); + staticFunctionDefinitions.clear(); + externVariableDeclarations.clear(); + staticVariableDeclarations.clear(); + } + + private boolean isAnyCandidate() { + return externFunctionDeclarations.size() > 0 || + staticFunctionDeclarations.size() > 0 || + staticFunctionDefinitions.size() > 0 || + externVariableDeclarations.size() > 0 || + staticVariableDeclarations.size() > 0; + } + + public void processAst(IASTTranslationUnit ast) { + if (ast.isHeaderUnit()) + return; + + clearCandidates(); + collectCandidates(ast); + + if (isAnyCandidate()) { + filterOutUsedElements(ast); + reportProblems(); + } + } + + private void collectCandidates(IASTTranslationUnit ast) { + try { + ast.accept(new ASTVisitor() { + { + shouldVisitDeclarations = true; + } + + @Override + public int visit(IASTDeclaration element) { + if (element instanceof IASTSimpleDeclaration) { + // declarations + IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) element; + + IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); + for (IASTDeclarator decl : declarators) { + IASTName astName = decl.getName(); + if (astName != null) { + IBinding binding = astName.resolveBinding(); + int storageClass = simpleDeclaration.getDeclSpecifier().getStorageClass(); + + if (binding instanceof IFunction) { + if (storageClass == IASTDeclSpecifier.sc_extern || storageClass == IASTDeclSpecifier.sc_unspecified) { + externFunctionDeclarations.put(binding, decl); + } else if (storageClass == IASTDeclSpecifier.sc_static) { + staticFunctionDeclarations.put(binding, decl); + } + } else if (binding instanceof IVariable) { + if (storageClass == IASTDeclSpecifier.sc_extern) { + externVariableDeclarations.put(binding, decl); + } else if (storageClass == IASTDeclSpecifier.sc_static) { + IType type = ((IVariable) binding).getType(); + // account for class constructor and avoid possible false positive + if (!(type instanceof ICPPClassType) && !(type instanceof IProblemType)) { + staticVariableDeclarations.put(binding, decl); + } + } + } + } + } + return PROCESS_SKIP; + } else if (element instanceof IASTFunctionDefinition) { + // definitions + IASTFunctionDefinition definition = (IASTFunctionDefinition) element; + + IASTName astName = definition.getDeclarator().getName(); + if (astName != null) { + IBinding binding = astName.resolveBinding(); + + if (definition.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_static) { + if (!(astName instanceof ICPPASTQualifiedName)) { + staticFunctionDefinitions.put(binding, definition.getDeclarator()); + } + } + + // externFunctionDeclarators filter out + externFunctionDeclarations.remove(binding); + // staticFunctionDeclarators filter out + staticFunctionDeclarations.remove(binding); + } + } + return PROCESS_SKIP; + } + + }); + } catch (Exception e) { + CodanCheckersActivator.log(e); + } + } + + private void filterOutUsedElements(IASTTranslationUnit ast) { + try { + ast.accept(new ASTVisitor() { + { + shouldVisitNames = true; + } + + @Override + public int visit(IASTName name) { + IBinding binding = name.resolveBinding(); + if (binding instanceof ICPPMethod) + return PROCESS_CONTINUE; + + IASTNode parentNode = name.getParent(); + + if (!(parentNode instanceof IASTFunctionDefinition || parentNode instanceof IASTFunctionDeclarator)) { + externFunctionDeclarations.remove(binding); + staticFunctionDefinitions.remove(binding); + } + + if (!(parentNode instanceof IASTDeclarator)) { + externVariableDeclarations.remove(binding); + staticVariableDeclarations.remove(binding); + } + + if (!isAnyCandidate()) + return PROCESS_ABORT; + + return PROCESS_CONTINUE; + } + + }); + } catch (Exception e) { + CodanCheckersActivator.log(e); + } + } + + private IASTName getAstName(IASTDeclarator decl) { + IASTName astName = null; + do { + astName = decl.getName(); + if (astName != null && astName.getSimpleID().length > 0) + return astName; + + // resolve parenthesis if need to + decl = decl.getNestedDeclarator(); + } while (decl != null); + + return astName; + } + + private void reportProblems() { + List<IASTDeclarator> funcDeclarators = new ArrayList<IASTDeclarator>(); + funcDeclarators.addAll(externFunctionDeclarations.values()); + funcDeclarators.addAll(staticFunctionDeclarations.values()); + for (IASTDeclarator symbol : funcDeclarators) { + IASTName astName = getAstName(symbol); + if (astName != null) { + String symbolName = new String(astName.getSimpleID()); + reportProblem(ER_UNUSED_FUNCTION_DECLARATION_ID, astName, symbolName); + } + } + + List<IASTDeclarator> varDeclarators = new ArrayList<IASTDeclarator>(); + varDeclarators.addAll(externVariableDeclarations.values()); + varDeclarators.addAll(staticVariableDeclarations.values()); + for (IASTDeclarator symbol : varDeclarators) { + IASTName astName = getAstName(symbol); + if (astName != null) { + String symbolName = new String(astName.getSimpleID()); + reportProblem(ER_UNUSED_VARIABLE_DECLARATION_ID, astName, symbolName); + } + } + + List<IASTDeclarator> staticFuncDeclarators = new ArrayList<IASTDeclarator>(); + staticFuncDeclarators.addAll(staticFunctionDefinitions.values()); + for (IASTDeclarator symbol : staticFuncDeclarators) { + IASTName astName = getAstName(symbol); + if (astName != null) { + String symbolName = new String(astName.getSimpleID()); + reportProblem(ER_UNUSED_STATIC_FUNCTION_ID, astName, symbolName); + } + } + + clearCandidates(); // release memory + } + + @Override + public boolean runInEditor() { + return true; + } +} diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java new file mode 100644 index 00000000000..c737a95dda6 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java @@ -0,0 +1,247 @@ +/******************************************************************************* + * Copyright (c) 2011 Andrew Gvozdev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Gvozdev - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.internal.checkers; + +import java.io.IOException; + +import org.eclipse.cdt.codan.core.test.CheckerTestCase; +import org.eclipse.cdt.codan.internal.checkers.UnusedSymbolInFileScopeChecker; + +/** + * Test for {@see UnusedSymbolInFileScopeChecker} class + * + */ +public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase { + @Override + public void setUp() throws Exception { + super.setUp(); + enableProblems( + UnusedSymbolInFileScopeChecker.ER_UNUSED_VARIABLE_DECLARATION_ID, + UnusedSymbolInFileScopeChecker.ER_UNUSED_FUNCTION_DECLARATION_ID, + UnusedSymbolInFileScopeChecker.ER_UNUSED_STATIC_FUNCTION_ID); + } + + //////////////////////////////////////////////////////////////////////////// + // extern function declarations + //////////////////////////////////////////////////////////////////////////// + + // int test_fun(); + // extern int test_efun(); + public void testExternFunction_Declaration_Unused() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + checkErrorLine(2); + } + + // int test_fun(); + // void fun() { + // test_fun(); + // } + public void testExternFunction_Declaration_Used() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + // void test_fun(); + // void test_fun() {} + public void testExternFunction_Declaration_FollowedByDefinition() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + //////////////////////////////////////////////////////////////////////////// + // extern function definitions + //////////////////////////////////////////////////////////////////////////// + + // void test_fun(void) {} + public void testExternFunction_Definition() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + //////////////////////////////////////////////////////////////////////////// + // Static function declarations + //////////////////////////////////////////////////////////////////////////// + + // static void test_fun(void); + public void testStaticFunction_Declaration_Unused() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // static void test_fun(void); + // static void test_fun(void) {} + public void testStaticFunction_Declaration_FollowedByDefinition() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(2); + } + + // static void test_fun(void); + // void fun() { + // test_fun(); + // } + public void testStaticFunction_Declaration_Used() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + //////////////////////////////////////////////////////////////////////////// + // Static function definitions + //////////////////////////////////////////////////////////////////////////// + + // static void test_fun(void) {} + public void testStaticFunction_Definition_Unused() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // static void test_fun(void); + // static void test_fun(void) {} + public void testStaticFunction_Definition_Unused_WithDeclaration() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(2); + } + + // static void test_fun(void) {} + // void fun() { + // test_fun(); + // } + public void testStaticFunction_Definition_Used() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + // void fun() { + // test_fun(); + // } + // static int test_fun(void) {} + public void testStaticFunction_Definition_UsedBeforeDefinition() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + // static int test_fun(void) {} + // static int test_fun(int) {} + // void fun() { + // test_fun(0); + // } + public void testStaticFunction_Definition_Signature() throws IOException { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(1); + } + + // static int test_fun(void) {} + // void fun() { + // int test_fun=0; + // } + public void testStaticFunction_Definition_SynonymLocalScope() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // static int test_fun(void) {} + // void fun(int test_fun) { + // } + public void testStaticFunction_Definition_SynonymArgs() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // static int (test_fun) (); + public void testStaticFunction_Definition_InParentheses() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + //////////////////////////////////////////////////////////////////////////// + // Extern variables declaration + //////////////////////////////////////////////////////////////////////////// + + // extern int test_var; + public void testExternVariable_Declaration_Unused() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // extern int test_var; + // void fun() { + // test_var=0; + // } + public void testExternVariable_Declaration_Used() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + // extern int i, + // test_var; + public void testExternVariable_Declaration_Combined() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + checkErrorLine(2); + } + + //////////////////////////////////////////////////////////////////////////// + // Extern variables definition + //////////////////////////////////////////////////////////////////////////// + + // int test_var; + // int test_var2=0; + public void testExternVariable_Definition() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + //////////////////////////////////////////////////////////////////////////// + // Static variables + //////////////////////////////////////////////////////////////////////////// + + // static int test_var; + public void testStaticVariable_Unused() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // static int (*test_var)(float, char, char); + public void testStaticVariable_Unused_FunctionPointer() throws IOException { + loadCodeAndRun(getAboveComment()); + checkErrorLine(1); + } + + // static int test_var; + // int i=test_var; + public void testStaticVariable_Used_GlobalScope() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + // static int test_var; + // void fun() { + // int i=test_var; + // } + public void testStaticVariable_Used_LocalScope() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + + // class Class; + // static Class test_var; // constructor is called here + public void testStaticVariable_Used_Constructor() throws IOException { + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); + } + + // static X test_var; // avoid possible false positive, binding checker would complain anyway + public void testExternVariable_Declaration_IgnoreUnresolved() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + +} diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java index 0bf302e7d43..ed5ae7a2c5d 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.ReturnStyleCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.StatementHasNoEffectCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.SuggestedParenthesisCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.SuspiciousSemicolonCheckerTest; +import org.eclipse.cdt.codan.core.internal.checkers.UnusedSymbolInFileScopeCheckerTest; import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CreateLocalVariableQuickFixTest; import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.SuggestedParenthesisQuickFixTest; @@ -61,6 +62,7 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTestSuite(StatementHasNoEffectCheckerTest.class); suite.addTestSuite(SuggestedParenthesisCheckerTest.class); suite.addTestSuite(SuspiciousSemicolonCheckerTest.class); + suite.addTestSuite(UnusedSymbolInFileScopeCheckerTest.class); // framework suite.addTest(CodanFastTestSuite.suite()); // quick fixes |