Skip to content

Instantly share code, notes, and snippets.

@daniel-beard
Created April 20, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-beard/6b25a5cf29b7dcb31700 to your computer and use it in GitHub Desktop.
Save daniel-beard/6b25a5cf29b7dcb31700 to your computer and use it in GitHub Desktop.
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