Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OCLint if matcher
#include "oclint/AbstractASTMatcherRule.h"
#include "oclint/RuleSet.h"
using namespace std;
using namespace clang;
using namespace clang::ast_matchers;
using namespace oclint;
class AllIfStatementsRule : public AbstractASTMatcherRule
{
public:
virtual const string name() const override
{
return "all if statements";
}
virtual int priority() const override
{
return 3;
}
virtual void callback(const MatchFinder::MatchResult &result) override
{
const IfStmt *ifStmt = result.Nodes.getNodeAs<IfStmt>("ifStmt");
if (ifStmt) {
addViolation(ifStmt->getCond(), this, "if statement found");
}
}
virtual void setUpMatcher() override
{
addMatcher(ifStmt().bind("ifStmt"));
}
};
static RuleSet rules(new AllIfStatementsRule());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.