Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-05-18 22:37:55 -0400
committerSergey Prigogin2011-05-18 22:37:55 -0400
commit51401d68f69e7d9d68587511d7db7ca8ebd1a125 (patch)
tree36cd90c66bc262557bb56ffd77b30a09a5bfe9b4 /codan/org.eclipse.cdt.codan.checkers
parent5af284cece004a79d644b720ee44dae1a6b4dbfb (diff)
downloadorg.eclipse.cdt-51401d68f69e7d9d68587511d7db7ca8ebd1a125.tar.gz
org.eclipse.cdt-51401d68f69e7d9d68587511d7db7ca8ebd1a125.tar.xz
org.eclipse.cdt-51401d68f69e7d9d68587511d7db7ca8ebd1a125.zip
Do not report suspicious semicolons produced by macro expansion.
Diffstat (limited to 'codan/org.eclipse.cdt.codan.checkers')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuspiciousSemicolonChecker.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuspiciousSemicolonChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuspiciousSemicolonChecker.java
index dce5cee207..e194ab1dc9 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuspiciousSemicolonChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuspiciousSemicolonChecker.java
@@ -1,12 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2010 Marc-Andre Laperle and others.
+ * Copyright (c) 2010, 2011 Marc-Andre Laperle 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:
- * Marc-Andre Laperle - Initial API and implementation
+ * Marc-Andre Laperle - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers;
@@ -38,15 +39,15 @@ public class SuspiciousSemicolonChecker extends AbstractIndexAstChecker {
if (statement instanceof IASTIfStatement) {
IASTStatement thenStmt = ((IASTIfStatement) statement).getThenClause();
IASTStatement elseStmt = ((IASTIfStatement) statement).getElseClause();
- if (elseStmt instanceof IASTNullStatement && noMacroInvolved(elseStmt) && doReportAfterElse()) {
+ if (elseStmt instanceof IASTNullStatement && doReportAfterElse() &&
+ !macroInvolved(elseStmt)) {
reportProblem(ER_ID, elseStmt);
}
- if (elseStmt != null && doNotReportIfElse() == true)
+ if (elseStmt != null && doNotReportIfElse())
return PROCESS_CONTINUE;
- if (thenStmt instanceof IASTNullStatement && noMacroInvolved(thenStmt)) {
+ if (thenStmt instanceof IASTNullStatement && !macroInvolved(thenStmt)) {
reportProblem(ER_ID, thenStmt);
}
-
}
return PROCESS_CONTINUE;
}
@@ -57,16 +58,20 @@ public class SuspiciousSemicolonChecker extends AbstractIndexAstChecker {
final IProblem pt = getProblemById(ER_ID, getFile());
return (Boolean) getPreference(pt, PARAM_ELSE);
}
+
protected boolean doReportAfterElse() {
final IProblem pt = getProblemById(ER_ID, getFile());
return (Boolean) getPreference(pt, PARAM_ALFTER_ELSE);
}
- protected boolean noMacroInvolved(IASTStatement node) {
+ protected boolean macroInvolved(IASTStatement node) {
+ if (includesMacroExpansion(node)) {
+ return true;
+ }
IASTNodeSelector nodeSelector = node.getTranslationUnit().getNodeSelector(node.getTranslationUnit().getFilePath());
IASTFileLocation fileLocation = node.getFileLocation();
IASTPreprocessorMacroExpansion macro = nodeSelector.findEnclosingMacroExpansion(fileLocation.getNodeOffset() - 1, 1);
- return macro == null;
+ return macro != null;
}
public void initPreferences(IProblemWorkingCopy problem) {

Back to the top