1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Don't report problems inside macro expansions.

This commit is contained in:
Sergey Prigogin 2011-04-26 03:38:49 +00:00
parent 44a3a89caa
commit 04f74e7829

View file

@ -25,6 +25,8 @@ import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
@ -70,7 +72,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
@Override @Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
if (statement instanceof IASTSwitchStatement) { if (statement instanceof IASTSwitchStatement && !isProducedMyMacroExpansion(statement)) {
IASTSwitchStatement switchStmt = (IASTSwitchStatement) statement; IASTSwitchStatement switchStmt = (IASTSwitchStatement) statement;
IASTStatement body = switchStmt.getBody(); IASTStatement body = switchStmt.getBody();
if (body instanceof IASTCompoundStatement) { if (body instanceof IASTCompoundStatement) {
@ -148,6 +150,19 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
} }
return true; // TODO return true; // TODO
} }
/**
* Checks if the given statement is a result of macro expansion with a possible
* exception for the trailing semicolon.
*
* @param statement the statement to check.
* @return <code>true</code> if the statement is a result of macro expansion
*/
private boolean isProducedMyMacroExpansion(IASTStatement statement) {
IASTNodeLocation[] locations = statement.getNodeLocations();
return locations.length > 0 && locations[0] instanceof IASTMacroExpansionLocation &&
(locations.length == 1 || locations.length == 2 && locations[1].getNodeLength() == 1);
}
} }
public CaseBreakChecker() { public CaseBreakChecker() {