Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated Matchers #68

Closed
lqi opened this issue Jul 7, 2013 · 0 comments
Closed

Duplicated Matchers #68

lqi opened this issue Jul 7, 2013 · 0 comments

Comments

@lqi
Copy link
Contributor

lqi commented Jul 7, 2013

Matchers are registered to the pool each time one matcher rule is applied, but never removed from the collection. This means, for a project with multiple files, when matcher rule is applied to the N-th file, same matchers are added to the pool N times. This results in duplicated violations.

Detail discussions can be found at https://groups.google.com/forum/#!topic/oclint-users/8GrE2rX3l0s

One solution:

diff --git a/oclint-rules/include/oclint/AbstractASTMatcherRule.h b/oclint-rules/include/oclint/AbstractASTMatcherRule.h
index 7985345..83541a5 100644
--- a/oclint-rules/include/oclint/AbstractASTMatcherRule.h
+++ b/oclint-rules/include/oclint/AbstractASTMatcherRule.h
@@ -14,7 +14,7 @@ class AbstractASTMatcherRule :
     public clang::ast_matchers::MatchFinder::MatchCallback
 {
 private:
-    clang::ast_matchers::MatchFinder _finder;
+    clang::ast_matchers::MatchFinder *_finder;

 protected:
     virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &result)
@@ -25,27 +25,34 @@ protected:
     template<typename T>
     void addMatcher(const T &nodeMatch)
     {
-        _finder.addMatcher(nodeMatch, this);
+        _finder->addMatcher(nodeMatch, this);
     }

 public:
     virtual void setUp()
     {
+        _finder = new clang::ast_matchers::MatchFinder();
         setUpMatcher();
     }

     bool VisitDecl(clang::Decl *decl)
     {
-        _finder.match(*decl, *_carrier->getASTContext());
+        _finder->match(*decl, *_carrier->getASTContext());
         return true;
     }

     bool VisitStmt(clang::Stmt *stmt)
     {
-        _finder.match(*stmt, *_carrier->getASTContext());
+        _finder->match(*stmt, *_carrier->getASTContext());
         return true;
     }

+    virtual void tearDown()
+    {
+        delete _finder;
+        _finder = NULL;
+    }
+
 public:
     virtual ~AbstractASTMatcherRule() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant