[PATCH] D54259: [ASTMatchers] proof-of-concept: allow matching within a restricted scope.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 8 07:02:14 PST 2018


sammccall created this revision.
Herald added subscribers: cfe-commits, kadircet, zzheng, ioeric, ilya-biryukov.
Herald added a reviewer: shafik.

Tools may want to match only within e.g. the main file.
We can run the matcher only over those "top-level decls" but if it "escapes"
e.g. using the hasAncestor() matcher, then all bets are off.
In fact, any use of hasAncestor() or hasParent() will cause us to pay O(|TU|) in
performance to build the parent map, which is unacceptably bad for clangd.

The approach taken here is to restrict the parent map to only include edges
reachable from the top-level decls.
We create a "bounds" object wrapping the decls, and store the parent map cache
in it. This object must be plumbed around manually.

Not asking for review and probably won't in this form, too much plumbing.
Sadly, the better option is probably to make this a mutable attribute of
ASTContext.


Repository:
  rC Clang

https://reviews.llvm.org/D54259

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/ASTMatchers/ASTMatchFinder.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/ASTMatchers/ASTMatchersInternal.h
  include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  lib/AST/ASTContext.cpp
  lib/ASTMatchers/ASTMatchFinder.cpp
  lib/Analysis/ExprMutationAnalyzer.cpp
  lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
  lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  lib/StaticAnalyzer/Checkers/ObjCAutoreleaseWriteChecker.cpp
  lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  lib/StaticAnalyzer/Core/LoopWidening.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  lib/Tooling/RefactoringCallbacks.cpp
  unittests/AST/ASTImporterTest.cpp
  unittests/AST/DeclMatcher.h
  unittests/AST/MatchVerifier.h
  unittests/ASTMatchers/ASTMatchersInternalTest.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  unittests/ASTMatchers/ASTMatchersTest.h
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  unittests/Analysis/ExprMutationAnalyzerTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54259.173160.patch
Type: text/x-patch
Size: 121741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181108/8ef2dbd2/attachment-0001.bin>


More information about the cfe-commits mailing list