From 4e112eca7750a4f530c986be55c178c43c16d3ea Mon Sep 17 00:00:00 2001 From: Elliott Baron Date: Sat, 26 Jun 2010 22:27:34 -0400 Subject: Update codan plugins to CDT 7.0. * org.eclipse.cdt.codan.checkers.ui: Updated. * org.eclipse.cdt.codan.checkers: Updated. * org.eclipse.cdt.codan.core: Updated. * org.eclipse.cdt.codan.ui: Updated. * org.eclipse.cdt.codan.core.cxx: Added. * org.eclipse.cdt.codan.extension/META-INF/MANIFEST.MF: Import org.eclipse.cdt.codan.core.cxx.model. * org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/checkers/AbstractPropSimChecker.java: Superclass moved. --- org.eclipse.cdt.codan.checkers/.project | 6 + .../.settings/CVS/Entries | 2 +- org.eclipse.cdt.codan.checkers/.settings/CVS/Tag | 1 + .../.settings/org.eclipse.jdt.core.prefs | 65 ++++++- org.eclipse.cdt.codan.checkers/CVS/Entries | 10 +- org.eclipse.cdt.codan.checkers/CVS/Tag | 1 + .../META-INF/CVS/Entries | 2 +- org.eclipse.cdt.codan.checkers/META-INF/CVS/Tag | 1 + .../META-INF/MANIFEST.MF | 12 +- .../OSGI-INF/CVS/Entries | 1 + .../OSGI-INF/CVS/Repository | 1 + org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Root | 1 + org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Tag | 1 + .../OSGI-INF/l10n/CVS/Entries | 1 + .../OSGI-INF/l10n/CVS/Repository | 1 + .../OSGI-INF/l10n/CVS/Root | 1 + .../OSGI-INF/l10n/CVS/Tag | 1 + .../OSGI-INF/l10n/bundle.properties | 47 +++++ org.eclipse.cdt.codan.checkers/about.html | 24 +++ org.eclipse.cdt.codan.checkers/build.properties | 14 +- org.eclipse.cdt.codan.checkers/plugin.xml | 113 +++++++++--- org.eclipse.cdt.codan.checkers/src/CVS/Tag | 1 + org.eclipse.cdt.codan.checkers/src/org/CVS/Tag | 1 + .../src/org/eclipse/CVS/Tag | 1 + .../src/org/eclipse/cdt/CVS/Tag | 1 + .../src/org/eclipse/cdt/codan/CVS/Entries | 2 + .../src/org/eclipse/cdt/codan/CVS/Tag | 1 + .../org/eclipse/cdt/codan/checkers/Activator.java | 74 -------- .../src/org/eclipse/cdt/codan/checkers/CVS/Entries | 2 +- .../src/org/eclipse/cdt/codan/checkers/CVS/Tag | 1 + .../cdt/codan/checkers/CodanCheckersActivator.java | 84 +++++++++ .../sample/AssignmentInConditionChecker.java | 59 ------ .../eclipse/cdt/codan/checkers/sample/CVS/Entries | 5 - .../cdt/codan/checkers/sample/CVS/Repository | 1 - .../org/eclipse/cdt/codan/checkers/sample/CVS/Root | 1 - .../eclipse/cdt/codan/checkers/sample/CVS/Template | 0 .../codan/checkers/sample/CatchUsesReference.java | 82 --------- .../checkers/sample/NonVirtualDestructor.java | 181 ------------------ .../sample/StatementHasNoEffectChecker.java | 110 ----------- .../sample/SuggestedParenthesisChecker.java | 143 --------------- .../src/org/eclipse/cdt/codan/internal/CVS/Entries | 1 + .../org/eclipse/cdt/codan/internal/CVS/Repository | 1 + .../src/org/eclipse/cdt/codan/internal/CVS/Root | 1 + .../src/org/eclipse/cdt/codan/internal/CVS/Tag | 1 + .../org/eclipse/cdt/codan/internal/CVS/Template | 0 .../checkers/AssignmentInConditionChecker.java | 59 ++++++ .../cdt/codan/internal/checkers/CVS/Entries | 10 + .../cdt/codan/internal/checkers/CVS/Repository | 1 + .../eclipse/cdt/codan/internal/checkers/CVS/Root | 1 + .../eclipse/cdt/codan/internal/checkers/CVS/Tag | 1 + .../cdt/codan/internal/checkers/CVS/Template | 0 .../codan/internal/checkers/CatchByReference.java | 158 ++++++++++++++++ .../codan/internal/checkers/CheckersMessages.java | 34 ++++ .../checkers/NamingConventionFunctionChecker.java | 82 +++++++++ .../internal/checkers/NonVirtualDestructor.java | 176 ++++++++++++++++++ .../cdt/codan/internal/checkers/ReturnChecker.java | 202 +++++++++++++++++++++ .../checkers/StatementHasNoEffectChecker.java | 196 ++++++++++++++++++++ .../checkers/SuggestedParenthesisChecker.java | 141 ++++++++++++++ .../codan/internal/checkers/messages.properties | 17 ++ 59 files changed, 1442 insertions(+), 696 deletions(-) create mode 100644 org.eclipse.cdt.codan.checkers/.settings/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/META-INF/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Entries create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Repository create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Root create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Entries create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Repository create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Root create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties create mode 100644 org.eclipse.cdt.codan.checkers/about.html create mode 100644 org.eclipse.cdt.codan.checkers/src/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Tag delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CodanCheckersActivator.java delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Repository delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Root delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Template delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/NonVirtualDestructor.java delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Entries create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Repository create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Root create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Entries create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Repository create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Root create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Tag create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuggestedParenthesisChecker.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/messages.properties (limited to 'org.eclipse.cdt.codan.checkers') diff --git a/org.eclipse.cdt.codan.checkers/.project b/org.eclipse.cdt.codan.checkers/.project index 6b76138..c99d7bb 100644 --- a/org.eclipse.cdt.codan.checkers/.project +++ b/org.eclipse.cdt.codan.checkers/.project @@ -20,9 +20,15 @@ + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature diff --git a/org.eclipse.cdt.codan.checkers/.settings/CVS/Entries b/org.eclipse.cdt.codan.checkers/.settings/CVS/Entries index c7206e9..d9b5490 100644 --- a/org.eclipse.cdt.codan.checkers/.settings/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/.settings/CVS/Entries @@ -1 +1 @@ -/org.eclipse.jdt.core.prefs/1.2/Tue Jun 2 21:11:37 2009// +/org.eclipse.jdt.core.prefs/1.3/Wed Mar 24 03:31:58 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/.settings/CVS/Tag b/org.eclipse.cdt.codan.checkers/.settings/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/.settings/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs index bd2d10b..58392e2 100644 --- a/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Tue Jun 02 17:10:46 EDT 2009 +#Wed Mar 17 23:31:06 EDT 2010 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 @@ -7,6 +7,69 @@ org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=error +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning +org.eclipse.jdt.core.compiler.problem.nullReference=error +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error +org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.source=1.5 diff --git a/org.eclipse.cdt.codan.checkers/CVS/Entries b/org.eclipse.cdt.codan.checkers/CVS/Entries index f0bd9f5..5d283e5 100644 --- a/org.eclipse.cdt.codan.checkers/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/CVS/Entries @@ -1,7 +1,9 @@ -/.classpath/1.3/Wed Dec 16 21:48:51 2009// -/.project/1.1/Thu Apr 9 12:48:43 2009// +/.classpath/1.3/Wed Dec 16 21:48:51 2009//TCDT_7_0_0 +/.project/1.2/Wed Mar 24 03:31:58 2010//TCDT_7_0_0 D/.settings//// D/META-INF//// -/build.properties/1.1/Thu Apr 9 12:48:44 2009// -/plugin.xml/1.7/Wed Dec 16 21:48:51 2009// +D/OSGI-INF//// +/about.html/1.1/Mon Jun 14 18:35:55 2010//TCDT_7_0_0 +/build.properties/1.6/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 +/plugin.xml/1.23/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 D/src//// diff --git a/org.eclipse.cdt.codan.checkers/CVS/Tag b/org.eclipse.cdt.codan.checkers/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/META-INF/CVS/Entries b/org.eclipse.cdt.codan.checkers/META-INF/CVS/Entries index 011c155..2943796 100644 --- a/org.eclipse.cdt.codan.checkers/META-INF/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/META-INF/CVS/Entries @@ -1 +1 @@ -/MANIFEST.MF/1.4/Sat Apr 18 02:11:45 2009// +/MANIFEST.MF/1.9/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/META-INF/CVS/Tag b/org.eclipse.cdt.codan.checkers/META-INF/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/META-INF/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF b/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF index 50e70f6..6d6406e 100644 --- a/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF +++ b/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF @@ -1,12 +1,16 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Checkers +Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.cdt.codan.checkers;singleton:=true -Bundle-Version: 1.0.0 -Bundle-Activator: org.eclipse.cdt.codan.checkers.Activator +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.cdt.codan.checkers.CodanCheckersActivator Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources;bundle-version="3.5.0", + org.eclipse.cdt.codan.core;bundle-version="1.0.0", org.eclipse.cdt.core;bundle-version="5.1.0", - org.eclipse.cdt.codan.core;bundle-version="1.0.0" + org.eclipse.cdt.codan.core.cxx;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Vendor: %Bundle-Vendor +Export-Package: org.eclipse.cdt.codan.checkers, + org.eclipse.cdt.codan.internal.checkers;x-friends:="org.eclipse.cdt.codan.checkers.ui" diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Entries b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Entries new file mode 100644 index 0000000..2928641 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Entries @@ -0,0 +1 @@ +D/l10n//// diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Repository b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Repository new file mode 100644 index 0000000..0ba340a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/OSGI-INF diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Root b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Tag b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Entries b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Entries new file mode 100644 index 0000000..6feb6a6 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Entries @@ -0,0 +1 @@ +/bundle.properties/1.2/Thu Jun 3 17:01:33 2010//TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Repository b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Repository new file mode 100644 index 0000000..32fbdd6 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Root b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Tag b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..3f942ae --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,47 @@ +############################################################################### +# Copyright (c) 2010 Alena Laskavaia 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: +# Alena Laskavaia - initial API and implementation +############################################################################### +#Properties file for org.eclipse.cdt.codan.checkers +Bundle-Vendor = Eclipse CDT +Bundle-Name = Codan Checkers +checker.name.AssignmentInCondition = Assignment in condition +problem.description.AssignmentInCondition = Finds statements like 'if (a=b)' +problem.messagePattern.AssignmentInCondition = Possible assignment in condition ''{0}'' +problem.name.AssignmentInCondition = Assignment in condition +checker.name.StatementHasNoEffect = StatementHasNoEffectChecker +problem.description.StatementHasNoEffect = Finds statements like 'a;' or '-a;' or 'a-b;' which do no seems to have any side effect therefore suspicious +problem.messagePattern.StatementHasNoEffect = Statement has no effect ''{0}'' +problem.name.StatementHasNoEffect = Statement has no effect +checker.name.NonVirtualDescructor = NonVirtualDescructorChecker +problem.description.NonVirtualDescructor = If destructor is not declared virtual - destructor of derived class would not be called. +problem.messagePattern.NonVirtualDescructor = Class ''{0}'' has virtual method ''{1}'' but non-virtual destructor ''{2}'' +problem.name.NonVirtualDescructor = Class has a virtual method and non-virtual destructor +checker.name.CatchByReference = CatchByReferenceChecker +problem.description.CatchByReference = Catching by reference is recommended by C++ experts, "Throw by value, catch by reference". For one thing, this avoids copying and potentially slicing the exception. +problem.messagePattern.CatchByReference = Catching by reference is recommended ''{0}'' +problem.name.CatchByReference = Catching by reference is recommended +checker.name.SuggestedParenthesis = SuggestedParenthesisChecker +problem.description.SuggestedParenthesis = This checker finds problems related to either lack of understanding precedence of operators or misspelling of operators in expression. For example (!a<10) or (a && b & c) +problem.messagePattern.SuggestedParenthesis = Suggested parenthesis around expression ''{0}'' +problem.name.SuggestedParenthesis = Suggested parenthesis around expression +checker.name.NamingConventionFunction = NamingConventionFunctionChecker +problem.description.NamingConventionFunction = Finds and reports functions name of which does not match pattern parameter +problem.messagePattern.NamingConventionFunction = Bad function name "{0}" (pattern /{1}/) +problem.name.NamingConventionFunction = Name convention for function +checker.name.ReturnChecker = Return inconsistencies +problem.description.NoReturnValue = Return statment has no return value, if somebody would use return value from this function it would be random +problem.messagePattern.NoReturnValue = Return without value, in function returning non-void +problem.name.NoReturnValue = No return value +problem.description.UnusedReturnValue = Return statement has a value, but function is declared to return void. Did you mean to declare function with return value? +problem.messagePattern.UnusedReturnValue = Return has value, in function returning void +problem.name.UnusedReturnValue = Unused return value +problem.description.NoReturn = No return statement in a function which is declared to return value +problem.messagePattern.NoReturn = No return, in function returning non-void +problem.name.NoReturn = No return \ No newline at end of file diff --git a/org.eclipse.cdt.codan.checkers/about.html b/org.eclipse.cdt.codan.checkers/about.html new file mode 100644 index 0000000..d7c5118 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/about.html @@ -0,0 +1,24 @@ + + +About + + +

About This Content

+ +

June 22, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/org.eclipse.cdt.codan.checkers/build.properties b/org.eclipse.cdt.codan.checkers/build.properties index e9863e2..df3189f 100644 --- a/org.eclipse.cdt.codan.checkers/build.properties +++ b/org.eclipse.cdt.codan.checkers/build.properties @@ -1,5 +1,17 @@ +############################################################################### +# Copyright (c) 2009, 2010 Alena Laskavaia 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: +# Alena Laskavaia - initial API and implementation +############################################################################### source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - plugin.xml + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + about.html diff --git a/org.eclipse.cdt.codan.checkers/plugin.xml b/org.eclipse.cdt.codan.checkers/plugin.xml index 63b999e..d206032 100644 --- a/org.eclipse.cdt.codan.checkers/plugin.xml +++ b/org.eclipse.cdt.codan.checkers/plugin.xml @@ -3,65 +3,124 @@ + id="org.eclipse.cdt.codan.core.internal.checkers"> + class="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionChecker" + id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionChecker" + name="%checker.name.AssignmentInCondition"> + description="%problem.description.AssignmentInCondition" + id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem" + messagePattern="%problem.messagePattern.AssignmentInCondition" + name="%problem.name.AssignmentInCondition"> + class="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker" + id="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker" + name="%checker.name.StatementHasNoEffect"> - + description="%problem.description.StatementHasNoEffect" + id="org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem" + messagePattern="%problem.messagePattern.StatementHasNoEffect" + name="%problem.name.StatementHasNoEffect"/> + class="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor" + id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDescructor" + name="%checker.name.NonVirtualDescructor"> + description="%problem.description.NonVirtualDescructor" + id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem" + messagePattern="%problem.messagePattern.NonVirtualDescructor" + name="%problem.name.NonVirtualDescructor"> + class="org.eclipse.cdt.codan.internal.checkers.CatchByReference" + id="org.eclipse.cdt.codan.internal.checkers.CatchByReference" + name="%checker.name.CatchByReference"> + description="%problem.description.CatchByReference" + id="org.eclipse.cdt.codan.internal.checkers.CatchByReference" + name="%problem.name.CatchByReference" + messagePattern="%problem.messagePattern.CatchByReference"> + class="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker" + id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker" + name="%checker.name.SuggestedParenthesis"> + description="%problem.description.SuggestedParenthesis" + id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem" + messagePattern="%problem.messagePattern.SuggestedParenthesis" + name="%problem.name.SuggestedParenthesis"> + + + + + + + + + + + + + + + + diff --git a/org.eclipse.cdt.codan.checkers/src/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Entries b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Entries index 513604d..83a5699 100644 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Entries @@ -1 +1,3 @@ D/checkers//// +D/examples//// +D/internal//// diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java deleted file mode 100644 index 2915e7d..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.eclipse.cdt.codan.checkers; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends Plugin { - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers"; - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext - * ) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext - * ) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - - /** - * @param e - */ - public static void log(Throwable e) { - getDefault().getLog().log(getStatus(e)); - } - - public static void log(String message) { - getDefault().getLog().log(new Status(Status.ERROR, PLUGIN_ID, message)); - } - - /** - * @param e - * @return - */ - public static IStatus getStatus(Throwable e) { - return new Status(Status.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); - } -} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Entries b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Entries index 0f9ebcd..2c318af 100644 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Entries @@ -1,2 +1,2 @@ -/Activator.java/1.3/Sat May 9 01:36:37 2009// +/CodanCheckersActivator.java/1.3/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 D/sample//// diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CodanCheckersActivator.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CodanCheckersActivator.java new file mode 100644 index 0000000..c2e21c3 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CodanCheckersActivator.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2010 Alena Laskavaia 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.checkers; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class CodanCheckersActivator extends Plugin { + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers"; //$NON-NLS-1$ + // The shared instance + private static CodanCheckersActivator plugin; + + /** + * The constructor + */ + public CodanCheckersActivator() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static CodanCheckersActivator getDefault() { + return plugin; + } + + /** + * @param e + */ + public static void log(Throwable e) { + getDefault().getLog().log(getStatus(e)); + } + + public static void log(String message) { + getDefault().getLog().log(new Status(Status.ERROR, PLUGIN_ID, message)); + } + + /** + * @param e + * @return + */ + public static IStatus getStatus(Throwable e) { + return new Status(Status.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java deleted file mode 100644 index 5ce5661..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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: - * Alena Laskavaia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.codan.checkers.sample; - -import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; -import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTForStatement; -import org.eclipse.cdt.core.dom.ast.IASTIfStatement; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; - -public class AssignmentInConditionChecker extends AbstractIndexAstChecker { - private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionProblem"; - - public void processAst(IASTTranslationUnit ast) { - // traverse the ast using the visitor pattern. - ast.accept(new CheckCodeVisitor()); - } - - class CheckCodeVisitor extends ASTVisitor { - CheckCodeVisitor() { - shouldVisitExpressions = true; - } - - public int visit(IASTExpression expression) { - if (isAssignmentExpression(expression) - && isUsedAsCondition(expression)) { - reportProblem(ER_ID, expression, "Possible assignment in condition"); - } - return PROCESS_CONTINUE; - } - - private boolean isAssignmentExpression(IASTExpression e) { - if (e instanceof IASTBinaryExpression) { - IASTBinaryExpression binExpr = (IASTBinaryExpression) e; - return binExpr.getOperator() == IASTBinaryExpression.op_assign; - } - return false; - } - - private boolean isUsedAsCondition(IASTExpression expression) { - ASTNodeProperty prop = expression.getPropertyInParent(); - if (prop == IASTForStatement.CONDITION - || prop == IASTIfStatement.CONDITION) - return true; - return false; - } - } -} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries deleted file mode 100644 index 705d9ab..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries +++ /dev/null @@ -1,5 +0,0 @@ -/AssignmentInConditionChecker.java/1.4/Fri Jul 31 20:39:13 2009// -/CatchUsesReference.java/1.2/Sat Nov 21 02:25:12 2009// -/NonVirtualDestructor.java/1.4/Fri Jul 31 20:39:13 2009// -/StatementHasNoEffectChecker.java/1.5/Fri Jul 31 20:39:13 2009// -/SuggestedParenthesisChecker.java/1.2/Sat Nov 21 03:03:08 2009// diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Repository b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Repository deleted file mode 100644 index 28a5431..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Repository +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Root b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Root deleted file mode 100644 index 04efa23..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Root +++ /dev/null @@ -1 +0,0 @@ -:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Template deleted file mode 100644 index e69de29..0000000 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java deleted file mode 100644 index b3556cc..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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: - * Alena Laskavaia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.codan.checkers.sample; - -import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; -import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTStatement; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; - -/** - * @author Alena - * - */ -public class CatchUsesReference extends AbstractIndexAstChecker { - private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.CatchUsesReference"; - - public void processAst(IASTTranslationUnit ast) { - // traverse the ast using the visitor pattern. - ast.accept(new OnCatch()); - } - - class OnCatch extends ASTVisitor { - OnCatch() { - shouldVisitStatements = true; - } - public int visit(IASTStatement stmt) { - if (stmt instanceof ICPPASTTryBlockStatement) { - ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt; - ICPPASTCatchHandler[] catchHandlers = tblock.getCatchHandlers(); - for (int i = 0; i < catchHandlers.length; i++) { - ICPPASTCatchHandler catchHandler = catchHandlers[i]; - if (usesReference(catchHandler)) { - reportProblem(ER_ID, catchHandler.getDeclaration(), "Catch clause uses reference in declaration of exception"); - } - } - - return PROCESS_SKIP; - } - return PROCESS_CONTINUE; - } - /** - * @param catchHandler - * @return - */ - private boolean usesReference(ICPPASTCatchHandler catchHandler) { - IASTDeclaration declaration = catchHandler.getDeclaration(); - if (declaration instanceof IASTSimpleDeclaration) { - IASTDeclarator[] declarators = ((IASTSimpleDeclaration) declaration).getDeclarators(); - for (int i = 0; i < declarators.length; i++) { - IASTDeclarator d = declarators[i]; - IASTPointerOperator[] pointerOperators = d.getPointerOperators(); - for (int j = 0; j < pointerOperators.length; j++) { - IASTPointerOperator po = pointerOperators[j]; - if (po instanceof ICPPASTReferenceOperator) { - return true; - } - - } - } - } - return false; - } - } - - -} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/NonVirtualDestructor.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/NonVirtualDestructor.java deleted file mode 100644 index 45f7e72..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/NonVirtualDestructor.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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: - * Alena Laskavaia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.codan.checkers.sample; - -import java.text.MessageFormat; - -import org.eclipse.cdt.codan.checkers.Activator; -import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; - -/** - * Checker to find that class has virtual method and non virtual destructor - * - * @author Alena - * - */ -public class NonVirtualDestructor extends AbstractIndexAstChecker { - private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.NonVirtualDestructorProblem"; - - public void processAst(IASTTranslationUnit ast) { - // traverse the ast using the visitor pattern. - ast.accept(new OnEachClass()); - } - - class OnEachClass extends ASTVisitor { - private IASTName className; - private IBinding virMethodName; - private IBinding destName; - - OnEachClass() { - // shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; - } - - public int visit(IASTDeclSpecifier decl) { - if (isClassDecl(decl)) { - try { - boolean err = hasErrorCondition(decl); - if (err) { - String mess; - String clazz = className.toString(); - String method = virMethodName.getName(); - IASTNode ast = decl; - if (destName != null) { - if (destName instanceof ICPPInternalBinding) { - ICPPInternalBinding bin = (ICPPInternalBinding) destName; - ast = bin.getDeclarations()[0]; - } - mess = MessageFormat - .format( - "Class ''{0}'' has virtual method ''{1}'' but non-virtual destructor ''{2}''", - clazz, method, destName.getName()); - reportProblem(ER_ID, ast, mess); - } - } - } catch (DOMException e) { - // ignore, no error - } catch (Exception e) { - Activator.log(e); - } - return PROCESS_SKIP; - } - return PROCESS_CONTINUE; - } - - /** - * @param decl - * @throws DOMException - */ - private boolean hasErrorCondition(IASTDeclSpecifier decl) - throws DOMException { - ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl; - className = spec.getName(); - IBinding binding = className.getBinding(); - if (binding == null) { - binding = className.resolveBinding(); - } - if (binding instanceof ICPPClassType) { - ICPPClassType type = (ICPPClassType) binding; - virMethodName = null; - destName = null; - // check for the following conditions: - // class has own virtual method and own non-virtual destructor - // class has own virtual method and base non-virtual destructor - // class has base virtual method and own non-virtual destructor - ICPPMethod[] declaredMethods = type.getDeclaredMethods(); - boolean hasOwnVirtualMethod = false; - boolean hasOwnNonVirDestructor = false; - boolean hasDestructor = false; - boolean hasVirtualMethod = false; - for (int i = 0; i < declaredMethods.length; i++) { - ICPPMethod icppMethod = declaredMethods[i]; - if (icppMethod.isVirtual() && !icppMethod.isDestructor()) { - hasOwnVirtualMethod = true; - virMethodName = icppMethod; - } - if (icppMethod.isDestructor()) { - hasDestructor = true; - if (!icppMethod.isVirtual()) { - hasOwnNonVirDestructor = true; - destName = icppMethod; - } - } - } - boolean hasVirDestructor = false; - // class has own virtual method and own non-virtual destructor - if (hasOwnVirtualMethod && hasOwnNonVirDestructor) { - return true; - } - // class does not have virtual methods but has virtual - // destructor - // - not an error - if (hasOwnVirtualMethod == false && hasDestructor == true - && hasOwnNonVirDestructor == false) { - return false; - } - ICPPMethod[] allDeclaredMethods = type.getAllDeclaredMethods(); - for (int i = 0; i < allDeclaredMethods.length; i++) { - ICPPMethod icppMethod = allDeclaredMethods[i]; - if (icppMethod.isVirtual() && !icppMethod.isDestructor()) { - hasVirtualMethod = true; - if (virMethodName == null) - virMethodName = icppMethod; - } - if (icppMethod.isDestructor()) { - hasDestructor = true; - if (icppMethod.isVirtual()) { - hasVirDestructor = true; - } else { - if (destName == null) - destName = icppMethod; - } - } - } - if (hasOwnVirtualMethod) { - // class has own virtual method and base non-virtual - // destructor - if (hasDestructor == true && hasVirDestructor == false) { - return true; - } - } else if (hasVirtualMethod) { - // class has base virtual method and own non-virtual - // destructor - if (hasOwnNonVirDestructor == true) { - return true; - } - } - } - return false; - } - - /** - * @param decl - * @return - */ - private boolean isClassDecl(IASTDeclSpecifier decl) { - if (decl instanceof ICPPASTCompositeTypeSpecifier) { - return true; - } - return false; - } - } -} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java deleted file mode 100644 index c08f58a..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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: - * Alena Laskavaia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.codan.checkers.sample; - -import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; -import org.eclipse.cdt.core.dom.ast.IASTIdExpression; -import org.eclipse.cdt.core.dom.ast.IASTStatement; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; -import org.eclipse.cdt.core.dom.ast.IBasicType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; - -/** - * Checker that detects statements without effect such as - * - * a+b; - * - * or - * - * +b; - * - * - */ -public class StatementHasNoEffectChecker extends AbstractIndexAstChecker { - private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.StatementHasNoEffectProblem"; - - public void processAst(IASTTranslationUnit ast) { - // traverse the ast using the visitor pattern. - ast.accept(new CheckStmpVisitor()); - } - - class CheckStmpVisitor extends ASTVisitor { - CheckStmpVisitor() { - shouldVisitStatements = true; - } - - public int visit(IASTStatement stmt) { - if (stmt instanceof IASTExpressionStatement) { - if (hasNoEffect(((IASTExpressionStatement) stmt) - .getExpression())) { - reportProblem(ER_ID, stmt, "Statement has no effect"); - } - return PROCESS_SKIP; - } - return PROCESS_CONTINUE; - } - - /** - * We consider has not effect binary statements without assignment and - * unary statement which is not dec and inc. If operator is overloaded - * we not going to bother. - * - * @param e - * @return - */ - private boolean hasNoEffect(IASTExpression e) { - if (e instanceof IASTBinaryExpression) { - IASTBinaryExpression binExpr = (IASTBinaryExpression) e; - if (binExpr.getOperator() == IASTBinaryExpression.op_assign) - return false; - if (binExpr instanceof CPPASTBinaryExpression) { - // unfortunately ICPPASTBinaryExpression does not have - // getOverload public method - CPPASTBinaryExpression cppBin = (CPPASTBinaryExpression) binExpr; - ICPPFunction overload = cppBin.getOverload(); - if (overload != null) - return false; - IType expressionType = binExpr.getOperand1() - .getExpressionType(); - if (!(expressionType instanceof IBasicType)) { - return false; // must be overloaded but parser could not - // find it - } - } - return true; - } - if (e instanceof IASTUnaryExpression) { - IASTUnaryExpression unaryExpr = (IASTUnaryExpression) e; - int operator = unaryExpr.getOperator(); - switch (operator) { - case IASTUnaryExpression.op_postFixDecr: - case IASTUnaryExpression.op_prefixDecr: - case IASTUnaryExpression.op_postFixIncr: - case IASTUnaryExpression.op_prefixIncr: - return false; - } - return true; - } - if (e instanceof IASTIdExpression) { - // simply a; - return true; - } - return false; - } - } -} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java deleted file mode 100644 index 27712b4..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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: - * Alena Laskavaia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.codan.checkers.sample; - -import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; -import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTForStatement; -import org.eclipse.cdt.core.dom.ast.IASTIfStatement; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; - -/** - * This checker finds a problems that cause by lack of understanding operator - * precedence in C. In any case it is better to surround expressions in - * parenthesis to improve readability. Example: ! x>0 && x<10 (this would be - * (!x)>0 && x<10 in C) We only look for &&, || and ! operators (and binary | & - * ^ ~) - * - * @author Alena - * - */ -public class SuggestedParenthesisChecker extends AbstractIndexAstChecker { - private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.SuggestedParenthesisProblem"; - - public void processAst(IASTTranslationUnit ast) { - // traverse the ast using the visitor pattern. - ast.accept(new ExpressionVisitor()); - } - - class ExpressionVisitor extends ASTVisitor { - private SuspiciousExpressionVisitor svis; - - ExpressionVisitor() { - shouldVisitExpressions = true; - svis = new SuspiciousExpressionVisitor(); - } - - public int visit(IASTExpression expression) { - int precedence = getPrecedence(expression); - if (precedence == 2) { // unary not - if (isUsedAsOperand(expression)) { - reportProblem(ER_ID, expression, - "Suggested parenthesis around expression"); - return PROCESS_SKIP; - } - } - if (precedence >= 0) { - synchronized (svis) { // since we use only one instance of this - // visitor sync just in case - svis.init(expression); - expression.accept(svis); - if (svis.suspicious == true) { - reportProblem(ER_ID, svis.other, - "Suggested parenthesis around expression"); - return PROCESS_SKIP; - } - } - } - return PROCESS_CONTINUE; - } - - private boolean isUsedAsOperand(IASTExpression expression) { - ASTNodeProperty prop = expression.getPropertyInParent(); - if (prop == IASTBinaryExpression.OPERAND_ONE - || prop == IASTBinaryExpression.OPERAND_TWO - || prop == IASTUnaryExpression.OPERAND) - return true; - return false; - } - } - - private int getPrecedence(IASTExpression e) { - if (e instanceof IASTBinaryExpression) { - IASTBinaryExpression binExpr = (IASTBinaryExpression) e; - int operator = binExpr.getOperator(); - if (operator == IASTBinaryExpression.op_binaryAnd) - return 8; - if (operator == IASTBinaryExpression.op_binaryXor) - return 9; - if (operator == IASTBinaryExpression.op_binaryOr) - return 10; - if (operator == IASTBinaryExpression.op_logicalAnd) - return 11; - if (operator == IASTBinaryExpression.op_logicalOr) - return 12; - } - if (e instanceof IASTUnaryExpression) { - IASTUnaryExpression binExpr = (IASTUnaryExpression) e; - int operator = binExpr.getOperator(); - if (operator == IASTUnaryExpression.op_not) - return 2; - if (operator == IASTUnaryExpression.op_tilde) - return 2; - } - return -1; - } - - class SuspiciousExpressionVisitor extends ASTVisitor { - IASTExpression parent; - IASTExpression other; - boolean suspicious = false; - - void init(IASTExpression e) { - parent = e; - suspicious = false; - } - - SuspiciousExpressionVisitor() { - shouldVisitExpressions = true; - } - - public int visit(IASTExpression expression) { - if (expression == parent) - return PROCESS_CONTINUE; - if (expression instanceof IASTUnaryExpression) { - IASTUnaryExpression uExpr = (IASTUnaryExpression) expression; - int operator = uExpr.getOperator(); - if (operator == IASTUnaryExpression.op_bracketedPrimary) { - return PROCESS_SKIP; - } - } - if (getPrecedence(expression) < 0) // not considered operator - return PROCESS_CONTINUE; - if (getPrecedence(expression) == getPrecedence(parent)) { - return PROCESS_SKIP; - } - suspicious = true; - other = expression; - return PROCESS_ABORT; - } - } -} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Entries b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Entries new file mode 100644 index 0000000..513604d --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Entries @@ -0,0 +1 @@ +D/checkers//// diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Repository b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Repository new file mode 100644 index 0000000..5afb44a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Root b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Tag new file mode 100644 index 0000000..3cd1ca4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Tag @@ -0,0 +1 @@ +TCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java new file mode 100644 index 0000000..6a17ef8 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; + +public class AssignmentInConditionChecker extends AbstractIndexAstChecker { + private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem"; //$NON-NLS-1$ + + public void processAst(IASTTranslationUnit ast) { + // traverse the ast using the visitor pattern. + ast.accept(new CheckCodeVisitor()); + } + + class CheckCodeVisitor extends ASTVisitor { + CheckCodeVisitor() { + shouldVisitExpressions = true; + } + + public int visit(IASTExpression expression) { + if (isAssignmentExpression(expression) + && isUsedAsCondition(expression)) { + reportProblem(ER_ID, expression, expression.getRawSignature()); + } + return PROCESS_CONTINUE; + } + + private boolean isAssignmentExpression(IASTExpression e) { + if (e instanceof IASTBinaryExpression) { + IASTBinaryExpression binExpr = (IASTBinaryExpression) e; + return binExpr.getOperator() == IASTBinaryExpression.op_assign; + } + return false; + } + + private boolean isUsedAsCondition(IASTExpression expression) { + ASTNodeProperty prop = expression.getPropertyInParent(); + if (prop == IASTForStatement.CONDITION + || prop == IASTIfStatement.CONDITION) + return true; + return false; + } + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Entries b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Entries new file mode 100644 index 0000000..2c93e0c --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Entries @@ -0,0 +1,10 @@ +/AssignmentInConditionChecker.java/1.4/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 +/CatchByReference.java/1.6/Thu Jun 3 17:01:33 2010//TCDT_7_0_0 +/CheckersMessages.java/1.6/Thu May 27 01:21:57 2010//TCDT_7_0_0 +/NamingConventionFunctionChecker.java/1.9/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 +/NonVirtualDestructor.java/1.4/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 +/ReturnChecker.java/1.12/Fri Jun 4 03:03:37 2010//TCDT_7_0_0 +/StatementHasNoEffectChecker.java/1.16/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 +/SuggestedParenthesisChecker.java/1.8/Sun Jun 27 01:30:37 2010//TCDT_7_0_0 +/messages.properties/1.7/Thu Jun 3 17:01:33 2010//TCDT_7_0_0 +D/sample//// diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Repository b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Repository new file mode 100644 index 0000000..7543811 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Root b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Tag b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Tag new file mode 100644 index 0000000..49a449a --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Tag @@ -0,0 +1 @@ +NCDT_7_0_0 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java new file mode 100644 index 0000000..6f0afc8 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import org.eclipse.cdt.codan.checkers.CodanCheckersActivator; +import org.eclipse.cdt.codan.core.cxx.CxxAstUtils; +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.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTPointer; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IPointerType; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; + +/** + * Catching by reference is recommended by C++ experts, for example Herb + * Sutter/Andrei Alexandresscu "C++ Coding Standards", Rule 73 + * "Throw by value, catch by reference". + * For one thing, this avoids copying and potentially slicing the exception. + * + */ +public class CatchByReference extends AbstractIndexAstChecker { + public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.CatchByReference"; //$NON-NLS-1$ + public static final String PARAM_EXCEPT_ARG_LIST = "exceptions"; //$NON-NLS-1$ + public static final String PARAM_UNKNOWN_TYPE = "unknown"; //$NON-NLS-1$ + + public void processAst(IASTTranslationUnit ast) { + // traverse the ast using the visitor pattern. + ast.accept(new OnCatch()); + } + + class OnCatch extends ASTVisitor { + OnCatch() { + shouldVisitStatements = true; + } + + public int visit(IASTStatement stmt) { + if (stmt instanceof ICPPASTTryBlockStatement) { + try { + ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt; + ICPPASTCatchHandler[] catchHandlers = tblock + .getCatchHandlers(); + for (int i = 0; i < catchHandlers.length; i++) { + ICPPASTCatchHandler catchHandler = catchHandlers[i]; + IASTDeclaration decl = catchHandler.getDeclaration(); + if (decl instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl; + IASTDeclSpecifier spec = sdecl.getDeclSpecifier(); + if (!usesReference(catchHandler)) { + if (spec instanceof IASTNamedTypeSpecifier) { + IASTName tname = ((IASTNamedTypeSpecifier) spec) + .getName(); + IType typeName = (IType) tname + .resolveBinding(); + typeName = CxxAstUtils.getInstance() + .unwindTypedef(typeName); + if (typeName instanceof IBasicType + || typeName instanceof IPointerType + || typeName == null) + continue; + if (typeName instanceof IProblemBinding && !shouldReportForUnknownType()) + continue; + String arg = spec.getRawSignature(); + if (!isFilteredArg(arg)) { + reportProblem(ER_ID, decl, arg); + } + } + } + } + } + } catch (Exception e) { + CodanCheckersActivator.log(e); + } + return PROCESS_SKIP; + } + return PROCESS_CONTINUE; + } + + /** + * If it uses reference or ponter + * + * @param catchHandler + * @return + */ + private boolean usesReference(ICPPASTCatchHandler catchHandler) { + IASTDeclaration declaration = catchHandler.getDeclaration(); + if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclarator[] declarators = ((IASTSimpleDeclaration) declaration) + .getDeclarators(); + for (int i = 0; i < declarators.length; i++) { + IASTDeclarator d = declarators[i]; + IASTPointerOperator[] pointerOperators = d + .getPointerOperators(); + for (int j = 0; j < pointerOperators.length; j++) { + IASTPointerOperator po = pointerOperators[j]; + if (po instanceof ICPPASTReferenceOperator) { + return true; + } + if (po instanceof IASTPointer) { + return true; + } + } + } + } + return false; + } + } + + @Override + public void initPreferences(IProblemWorkingCopy problem) { + super.initPreferences(problem); + addPreference(problem, PARAM_UNKNOWN_TYPE, + CheckersMessages.CatchByReference_ReportForUnknownType, Boolean.FALSE); + addListPreference(problem, PARAM_EXCEPT_ARG_LIST, + CheckersMessages.GenericParameter_ParameterExceptions, + CheckersMessages.GenericParameter_ParameterExceptionsItem); + } + + public boolean isFilteredArg(String arg) { + Object[] arr = (Object[]) getPreference( + getProblemById(ER_ID, getFile()), PARAM_EXCEPT_ARG_LIST); + for (int i = 0; i < arr.length; i++) { + String str = (String) arr[i]; + if (arg.equals(str)) + return true; + } + return false; + } + + /** + * @return + */ + public boolean shouldReportForUnknownType() { + return (Boolean) getPreference(getProblemById(ER_ID, getFile()), + PARAM_UNKNOWN_TYPE); + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java new file mode 100644 index 0000000..089934f --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2009,2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages + */ +public class CheckersMessages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.codan.internal.checkers.messages"; //$NON-NLS-1$ + public static String CatchByReference_ReportForUnknownType; + public static String NamingConventionFunctionChecker_LabelNamePattern; + public static String ReturnChecker_Param0; + public static String GenericParameter_ParameterExceptions; + public static String GenericParameter_ParameterExceptionsItem; + public static String StatementHasNoEffectChecker_ParameterMacro; + public static String SuggestedParenthesisChecker_SuggestParanthesesAroundNot; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, CheckersMessages.class); + } + + private CheckersMessages() { + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java new file mode 100644 index 0000000..4758ed1 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import java.util.regex.Pattern; + +import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; +import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences; +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; + +/** + * This is style checker for function name code style. Pattern parameter is + * regular expression defining the style. + * + */ +public class NamingConventionFunctionChecker extends AbstractIndexAstChecker + implements ICheckerWithPreferences { + private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker"; //$NON-NLS-1$ + public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$ + + public void processAst(IASTTranslationUnit ast) { + final IProblem pt = getProblemById(ER_ID, getFile()); + try { + ast.accept(new ASTVisitor() { + { + shouldVisitDeclarations = true; + } + + public int visit(IASTDeclaration element) { + if (element instanceof IASTFunctionDefinition) { + String parameter = (String) getPreference(pt,PARAM_KEY); + Pattern pattern = Pattern.compile(parameter); + IASTName astName = ((IASTFunctionDefinition) element) + .getDeclarator().getName(); + String name = astName.toString(); + if (!pattern.matcher(name).find()) { + reportProblem(ER_ID, astName, name, parameter); + } + } + return PROCESS_SKIP; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckerWithPreferences#initParameters + * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) + */ + public void initPreferences(IProblemWorkingCopy problem) { + super.initPreferences(problem); + addPreference( + problem, + PARAM_KEY, + CheckersMessages.NamingConventionFunctionChecker_LabelNamePattern, + "^[a-z]"); //$NON-NLS-1$ + } + + @Override + public boolean runInEditor() { + return true; + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java new file mode 100644 index 0000000..c4bdbad --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import org.eclipse.cdt.codan.checkers.CodanCheckersActivator; +import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; + +/** + * Checker to find that class has virtual method and non virtual destructor + * + * @author Alena + * + */ +public class NonVirtualDestructor extends AbstractIndexAstChecker { + private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$ + + public void processAst(IASTTranslationUnit ast) { + // traverse the ast using the visitor pattern. + ast.accept(new OnEachClass()); + } + + class OnEachClass extends ASTVisitor { + private IASTName className; + private IBinding virMethodName; + private IBinding destructorName; + + OnEachClass() { + // shouldVisitDeclarations = true; + shouldVisitDeclSpecifiers = true; + } + + public int visit(IASTDeclSpecifier decl) { + if (isClassDecl(decl)) { + try { + boolean err = hasErrorCondition(decl); + if (err) { + String clazz = className.toString(); + String method = virMethodName.getName(); + IASTNode ast = decl; + if (destructorName != null) { + if (destructorName instanceof ICPPInternalBinding) { + ICPPInternalBinding bin = (ICPPInternalBinding) destructorName; + IASTNode[] decls = bin.getDeclarations(); + if (decls!=null && decls.length>0) + ast = decls[0]; + } + reportProblem(ER_ID, ast, clazz, method, destructorName.getName()); + } + } + } catch (DOMException e) { + // ignore, no error + } catch (Exception e) { + CodanCheckersActivator.log(e); + } + return PROCESS_SKIP; + } + return PROCESS_CONTINUE; + } + + /** + * @param decl + * @throws DOMException + */ + private boolean hasErrorCondition(IASTDeclSpecifier decl) + throws DOMException { + ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl; + className = spec.getName(); + IBinding binding = className.getBinding(); + if (binding == null) { + binding = className.resolveBinding(); + } + if (binding instanceof ICPPClassType) { + ICPPClassType type = (ICPPClassType) binding; + virMethodName = null; + destructorName = null; + // check for the following conditions: + // class has own virtual method and own non-virtual destructor + // class has own virtual method and base non-virtual destructor + // class has base virtual method and own non-virtual destructor + ICPPMethod[] declaredMethods = type.getDeclaredMethods(); + boolean hasOwnVirtualMethod = false; + boolean hasOwnNonVirDestructor = false; + boolean hasDestructor = false; + boolean hasVirtualMethod = false; + for (int i = 0; i < declaredMethods.length; i++) { + ICPPMethod icppMethod = declaredMethods[i]; + if (icppMethod.isVirtual() && !icppMethod.isDestructor()) { + hasOwnVirtualMethod = true; + virMethodName = icppMethod; + } + if (icppMethod.isDestructor()) { + hasDestructor = true; + if (!icppMethod.isVirtual()) { + hasOwnNonVirDestructor = true; + destructorName = icppMethod; + } + } + } + boolean hasVirDestructor = false; + // class has own virtual method and own non-virtual destructor + if (hasOwnVirtualMethod && hasOwnNonVirDestructor) { + return true; + } + // class does not have virtual methods but has virtual + // destructor + // - not an error + if (hasOwnVirtualMethod == false && hasDestructor == true + && hasOwnNonVirDestructor == false) { + return false; + } + ICPPMethod[] allDeclaredMethods = type.getAllDeclaredMethods(); + for (int i = 0; i < allDeclaredMethods.length; i++) { + ICPPMethod icppMethod = allDeclaredMethods[i]; + if (icppMethod.isVirtual() && !icppMethod.isDestructor()) { + hasVirtualMethod = true; + if (virMethodName == null) + virMethodName = icppMethod; + } + if (icppMethod.isDestructor()) { + hasDestructor = true; + if (icppMethod.isVirtual()) { + hasVirDestructor = true; + } else { + if (destructorName == null) + destructorName = icppMethod; + } + } + } + if (hasOwnVirtualMethod) { + // class has own virtual method and base non-virtual + // destructor + if (hasDestructor == true && hasVirDestructor == false) { + return true; + } + } else if (hasVirtualMethod) { + // class has base virtual method and own non-virtual + // destructor + if (hasOwnNonVirDestructor == true) { + return true; + } + } + } + return false; + } + + /** + * @param decl + * @return + */ + private boolean isClassDecl(IASTDeclSpecifier decl) { + if (decl instanceof ICPPASTCompositeTypeSpecifier) { + return true; + } + return false; + } + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java new file mode 100644 index 0000000..e88c86d --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2009,2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import java.util.Iterator; + +import org.eclipse.cdt.codan.core.cxx.model.AbstractAstFunctionChecker; +import org.eclipse.cdt.codan.core.cxx.model.CxxModelsCache; +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.codan.core.model.cfg.ICfgData; +import org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph; +import org.eclipse.cdt.codan.core.model.cfg.IExitNode; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; + +/** + * The checker suppose to find issue related to mismatched return value/function + * declaration
+ *
  • Function declared as returning non-void returns void + *
  • Function declared as returning void has non-void return + *
  • Function declared as returning non-void has no return (requires control + * flow graph) + */ +public class ReturnChecker extends AbstractAstFunctionChecker { + private static final String PARAM_IMPLICIT = "implicit"; //$NON-NLS-1$ + public final String RET_NO_VALUE_ID = "org.eclipse.cdt.codan.checkers.noreturn"; //$NON-NLS-1$ + public final String RET_ERR_VALUE_ID = "org.eclipse.cdt.codan.checkers.errreturnvalue"; //$NON-NLS-1$ + public final String RET_NORET_ID = "org.eclipse.cdt.codan.checkers.errnoreturn"; //$NON-NLS-1$ + + class ReturnStmpVisitor extends ASTVisitor { + private IASTFunctionDefinition func; + boolean hasret; + + ReturnStmpVisitor(IASTFunctionDefinition func) { + shouldVisitStatements = true; + shouldVisitDeclarations = true; + this.func = func; + this.hasret = false; + } + public int visit(IASTDeclaration element) { + if (element!=func) + return PROCESS_SKIP; // skip inner functions + return PROCESS_CONTINUE; + } + public int visit(IASTStatement stmt) { + if (stmt instanceof IASTReturnStatement) { + hasret = true; + IASTReturnStatement ret = (IASTReturnStatement) stmt; + if (!isVoid(func)) { + if (checkImplicitReturn(RET_NO_VALUE_ID) + || isExplicitReturn(func)) { + if (ret.getReturnValue() == null) + reportProblem(RET_NO_VALUE_ID, ret); + } + } else { + if (ret.getReturnValue() != null) { + IType type = ret.getReturnValue().getExpressionType(); + if (isVoid(type)) + return PROCESS_SKIP; + reportProblem(RET_ERR_VALUE_ID, ret.getReturnValue()); + } + } + + return PROCESS_SKIP; + } + return PROCESS_CONTINUE; + } + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.cxx.model.AbstractAstFunctionChecker# + * processFunction(org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition) + */ + @Override + protected void processFunction(IASTFunctionDefinition func) { + ReturnStmpVisitor visitor = new ReturnStmpVisitor(func); + func.accept(visitor); + if (!visitor.hasret) { + // no return at all + if (!isVoid(func) + && (checkImplicitReturn(RET_NORET_ID) || isExplicitReturn(func))) { + if (endsWithNoExitNode(func)) + reportProblem(RET_NORET_ID, func.getDeclSpecifier()); + } + } + } + + /** + * @param if - problem id + * @return true if need to check inside functions with implicit return + */ + protected boolean checkImplicitReturn(String id) { + final IProblem pt = getProblemById(id, getFile()); + return (Boolean) getPreference(pt,PARAM_IMPLICIT); + } + + /** + * @param func + * @return + */ + protected boolean endsWithNoExitNode(IASTFunctionDefinition func) { + IControlFlowGraph graph = CxxModelsCache.getInstance() + .getControlFlowGraph(func); + Iterator exitNodeIterator = graph.getExitNodeIterator(); + boolean noexitop = false; + for (; exitNodeIterator.hasNext();) { + IExitNode node = exitNodeIterator.next(); + if (((ICfgData) node).getData() == null) { + // if it real exit node such as return, exit or throw data + // will be an ast node, it is null it is fake node added by the + // graph builder + noexitop = true; + break; + } + } + return noexitop; + } + + /** + * @param func + * @return + */ + protected boolean isExplicitReturn(IASTFunctionDefinition func) { + return getDeclSpecType(func) != ICASTSimpleDeclSpecifier.t_unspecified; + } + + /** + * @param func + * @return + */ + public boolean isVoid(IASTFunctionDefinition func) { + int type = getDeclSpecType(func); + if (type == IASTSimpleDeclSpecifier.t_void) { + IASTFunctionDeclarator declarator = func.getDeclarator(); + if (declarator.getPointerOperators().length == 0) + return true; + } + return false; + } + /** + * check if type if void + * (uses deprecated API for compatibility with 6.0) + * @param type + * @throws DOMException + */ + @SuppressWarnings("deprecation") + public boolean isVoid(IType type) { + if (type instanceof IBasicType) { + try { + if (((IBasicType) type).getType()==IBasicType.t_void) + return true; + } catch (DOMException e) { + return false; + } + } + return false; + } + /** + * @param func + * @return + */ + protected int getDeclSpecType(IASTFunctionDefinition func) { + IASTDeclSpecifier declSpecifier = func.getDeclSpecifier(); + int type = -1; + if (declSpecifier instanceof IASTSimpleDeclSpecifier) { + type = ((IASTSimpleDeclSpecifier) declSpecifier).getType(); + } + return type; + } + + /* checker must implement @link ICheckerWithPreferences */ + public void initPreferences(IProblemWorkingCopy problem) { + super.initPreferences(problem); + if (problem.getId().equals(RET_NO_VALUE_ID) + || problem.getId().equals(RET_NORET_ID)) { + addPreference(problem, PARAM_IMPLICIT, + CheckersMessages.ReturnChecker_Param0, Boolean.FALSE); + } + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java new file mode 100644 index 0000000..331e86b --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/StatementHasNoEffectChecker.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import org.eclipse.cdt.codan.core.cxx.CxxAstUtils; +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.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; + +/** + * Checker that detects statements without effect such as + * + * a+b; + * or + * +b; + * + * + */ +public class StatementHasNoEffectChecker extends AbstractIndexAstChecker { + public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem"; //$NON-NLS-1$ + public static final String PARAM_MACRO_ID = "macro"; //$NON-NLS-1$ + public static final String PARAM_EXCEPT_ARG_LIST = "exceptions"; //$NON-NLS-1$ + + public void processAst(IASTTranslationUnit ast) { + ast.accept(new CheckStmpVisitor()); + } + + class CheckStmpVisitor extends ASTVisitor { + CheckStmpVisitor() { + shouldVisitStatements = true; + } + + public int visit(IASTStatement stmt) { + if (stmt instanceof IASTExpressionStatement) { + IASTExpression expression = ((IASTExpressionStatement) stmt) + .getExpression(); + if (hasNoEffect(expression)) { + boolean inMacro = CxxAstUtils.getInstance().isInMacro( + expression); + boolean shouldReportInMacro = shouldReportInMacro(); + if (inMacro && !shouldReportInMacro) + return PROCESS_SKIP; + String arg = expression.getRawSignature(); + if (!isFilteredArg(arg)) + reportProblem(ER_ID, stmt, arg); + } + return PROCESS_SKIP; + } + return PROCESS_CONTINUE; + } + + /** + * We consider has not effect binary statements without assignment and + * unary statement which is not dec and inc. If operator is overloaded + * we not going to bother. + * + * @param e + * @return + */ + private boolean hasNoEffect(IASTExpression e) { + if (e instanceof IASTBinaryExpression) { + IASTBinaryExpression binExpr = (IASTBinaryExpression) e; + if (isPossibleAssignment(binExpr)) + return false; + switch (binExpr.getOperator()) { + case IASTBinaryExpression.op_logicalOr: + case IASTBinaryExpression.op_logicalAnd: + return hasNoEffect(binExpr.getOperand1()) + && hasNoEffect(binExpr.getOperand2()); + } + return true; + } + if (e instanceof IASTUnaryExpression) { + IASTUnaryExpression unaryExpr = (IASTUnaryExpression) e; + int operator = unaryExpr.getOperator(); + switch (operator) { + case IASTUnaryExpression.op_postFixDecr: + case IASTUnaryExpression.op_prefixDecr: + case IASTUnaryExpression.op_postFixIncr: + case IASTUnaryExpression.op_prefixIncr: + case IASTUnaryExpression.op_throw: + return false; + case IASTUnaryExpression.op_bracketedPrimary: + return hasNoEffect(unaryExpr.getOperand()); + } + return true; + } + // simply a; + if (e instanceof IASTIdExpression) { + // check if it is part of GNU comp stmt expression i.e. ({foo();a;}) + IASTNode parent = e.getParent(); + if (parent instanceof IASTExpressionStatement) { + IASTNode parent2 = parent.getParent(); + if (parent2 instanceof IASTCompoundStatement) { + IASTNode parent3 = parent2.getParent(); + if (parent3 instanceof IGNUASTCompoundStatementExpression) { + return false; + } + } + } + return true; + } + return false; + } + } + + public void initPreferences(IProblemWorkingCopy problem) { + super.initPreferences(problem); + addPreference(problem, PARAM_MACRO_ID, + CheckersMessages.StatementHasNoEffectChecker_ParameterMacro, + Boolean.TRUE); + addListPreference( + problem, + PARAM_EXCEPT_ARG_LIST, + CheckersMessages.GenericParameter_ParameterExceptions, + CheckersMessages.GenericParameter_ParameterExceptionsItem); + } + + /**s + * @param paramExceptArgList + * @param arg + * @return + */ + public boolean isFilteredArg(String arg) { + Object[] arr = (Object[]) getPreference( + getProblemById(ER_ID, getFile()), PARAM_EXCEPT_ARG_LIST); + for (int i = 0; i < arr.length; i++) { + String str = (String) arr[i]; + if (arg.equals(str)) + return true; + } + return false; + } + + /** + * @return + */ + public boolean shouldReportInMacro() { + return (Boolean) getPreference(getProblemById(ER_ID, getFile()), + PARAM_MACRO_ID); + } + + @SuppressWarnings("restriction") + public boolean isPossibleAssignment(IASTBinaryExpression expr) { + switch (expr.getOperator()) { + case IASTBinaryExpression.op_assign: + case IASTBinaryExpression.op_binaryAndAssign: + case IASTBinaryExpression.op_binaryOrAssign: + case IASTBinaryExpression.op_binaryXorAssign: + case IASTBinaryExpression.op_divideAssign: + case IASTBinaryExpression.op_minusAssign: + case IASTBinaryExpression.op_moduloAssign: + case IASTBinaryExpression.op_multiplyAssign: + case IASTBinaryExpression.op_plusAssign: + case IASTBinaryExpression.op_shiftLeftAssign: + case IASTBinaryExpression.op_shiftRightAssign: + return true; + } + if (expr instanceof CPPASTBinaryExpression) { + // unfortunately ICPPASTBinaryExpression does not have + // getOverload public method + CPPASTBinaryExpression cppBin = (CPPASTBinaryExpression) expr; + ICPPFunction overload = cppBin.getOverload(); + if (overload != null) + return true; + IType expressionType = cppBin.getOperand1().getExpressionType(); + if (!(expressionType instanceof IBasicType)) { + return true; // must be overloaded but parser could not + // find it + } + } + return false; + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuggestedParenthesisChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuggestedParenthesisChecker.java new file mode 100644 index 0000000..659703d --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuggestedParenthesisChecker.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Alena Laskavaia + * 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: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers; + +import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; +import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; + +/** + * This checker finds a problems which are caused by lack of understanding + * operator + * precedence in C. In any case it is better to surround expressions in + * parenthesis to improve readability. Example: ! x>0 && x<10 (this would be + * (!x)>0 && x<10 in C) We only look for &&, || and ! operators (and binary | & + * ^ ~) + * + * @author Alena + * + */ +public class SuggestedParenthesisChecker extends AbstractIndexAstChecker { + public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem"; //$NON-NLS-1$ + public static final String PARAM_NOT = "paramNot"; //$NON-NLS-1$ + + + + public void processAst(IASTTranslationUnit ast) { + // traverse the ast using the visitor pattern. + ast.accept(new ExpressionVisitor()); + } + + class ExpressionVisitor extends ASTVisitor { + ExpressionVisitor() { + shouldVisitExpressions = true; + } + + public int visit(IASTExpression expression) { + int precedence = getPrecedence(expression); + IASTNode parent = expression.getParent(); + if (parent instanceof IASTExpression) { + IASTExpression parentExpr = (IASTExpression) parent; + if (isInParentesis(expression)) + return PROCESS_CONTINUE; + if (precedence == 2) { // unary not + if (isParamNot() && isUsedAsOperand(expression)) { + reportProblem(ER_ID, expression, expression.getRawSignature()); + return PROCESS_SKIP; + } + } else if (precedence >= 0) { + int pp = getPrecedence(parentExpr); + if (pp == -1 || pp == precedence) + return PROCESS_CONTINUE; + reportProblem(ER_ID, expression, expression.getRawSignature()); + } + } + return PROCESS_CONTINUE; + } + + private boolean isUsedAsOperand(IASTExpression expression) { + ASTNodeProperty prop = expression.getPropertyInParent(); + if (prop == IASTBinaryExpression.OPERAND_ONE + // || prop == IASTBinaryExpression.OPERAND_TWO + || prop == IASTUnaryExpression.OPERAND) + return true; + return false; + } + } + + private int getPrecedence(IASTExpression e) { + if (e instanceof IASTBinaryExpression) { + IASTBinaryExpression binExpr = (IASTBinaryExpression) e; + int operator = binExpr.getOperator(); + if (operator == IASTBinaryExpression.op_binaryAnd) + return 8; + if (operator == IASTBinaryExpression.op_binaryXor) + return 9; + if (operator == IASTBinaryExpression.op_binaryOr) + return 10; + if (operator == IASTBinaryExpression.op_logicalAnd) + return 11; + if (operator == IASTBinaryExpression.op_logicalOr) + return 12; + } + if (e instanceof IASTUnaryExpression) { + IASTUnaryExpression binExpr = (IASTUnaryExpression) e; + int operator = binExpr.getOperator(); + if (operator == IASTUnaryExpression.op_not) + return 2; + if (operator == IASTUnaryExpression.op_tilde) + return 2; + } + return -1; + } + + /** + * @param parent + * @return + */ + private boolean isInParentesis(IASTExpression node) { + IASTNode parent = node.getParent(); + if (parent instanceof IASTUnaryExpression) { + IASTUnaryExpression br = (IASTUnaryExpression) parent; + if (br.getOperator() == IASTUnaryExpression.op_bracketedPrimary) { + return true; + } + } + return false; + } + + public boolean isParamNot() { + return (Boolean) getPreference(getProblemById(ER_ID, getFile()), + PARAM_NOT); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences + * #initPreferences(org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) + */ + @Override + public void initPreferences(IProblemWorkingCopy problem) { + super.initPreferences(problem); + addPreference(problem, PARAM_NOT, + CheckersMessages.SuggestedParenthesisChecker_SuggestParanthesesAroundNot, Boolean.FALSE); + } +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/messages.properties b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/messages.properties new file mode 100644 index 0000000..94c7757 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/messages.properties @@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2010 Alena Laskavaia 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: +# Alena Laskavaia - initial API and implementation +############################################################################### +CatchByReference_ReportForUnknownType=Report a problem if type cannot be resolved +NamingConventionFunctionChecker_LabelNamePattern=Name Pattern +ReturnChecker_Param0=Also check functions with implicit return value +GenericParameter_ParameterExceptions=Exceptions (value of the problem argument) +GenericParameter_ParameterExceptionsItem=Value of the argument +StatementHasNoEffectChecker_ParameterMacro=Report problem in statements that comes from macro expansion +SuggestedParenthesisChecker_SuggestParanthesesAroundNot=Suggest parentesis around not operator -- cgit