llvm-project/clang
Sam McCall 814e7974c6 [AST] Allow limiting the scope of common AST traversals (getParents, RAV).
Summary:
The goal is to allow analyses such as clang-tidy checks to run on a
subset of the AST, e.g. "only on main-file decls" for interactive tools.

Today, these become "problematically global" by running RecursiveASTVisitors
rooted at the TUDecl, or by navigating up via ASTContext::getParent().

The scope is restricted using a set of top-level-decls that RecursiveASTVisitors
should be rooted at. This also applies to the visitor that populates the
parent map, and so the top-level-decls are considered to have no parents.

This patch makes the traversal scope a mutable property of ASTContext.
The more obvious way to do this is to pass the top-level decls to
relevant functions directly, but this has some problems:
 - it's error-prone: accidentally mixing restricted and unrestricted
   scopes is a performance trap. Interleaving multiple analyses is
   common (many clang-tidy checks run matchers or RAVs from matcher callbacks)
 - it doesn't map well to the actual use cases, where we really do want
   *all* traversals to be restricted.
 - it involves a lot of plumbing in parts of the code that don't care
   about traversals.
This approach was tried out in D54259 and D54261, I wanted to like it
but it feels pretty awful in practice.

Caveats: to get scope-limiting behavior of RecursiveASTVisitors, callers
have to call the new TraverseAST(Ctx) function instead of TraverseDecl(TU).
I think this is an improvement to the API regardless.

Reviewers: klimek, ioeric

Subscribers: mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D54309

llvm-svn: 346847
2018-11-14 10:33:30 +00:00
..
INPUTS
bindings [python] Support PathLike filenames and directories 2018-11-10 11:41:36 +00:00
cmake [CMake] Include clang-apply-replacements in Fuchsia toolchain 2018-11-14 04:06:47 +00:00
docs UserManual: Tweak the /Zc:dllexportInlines- docs some 2018-11-13 09:05:12 +00:00
examples Fix buildbots - update clang-interpreter to use Legacy ORC classes introduced in rL344572. 2018-10-16 09:21:58 +00:00
include [AST] Allow limiting the scope of common AST traversals (getParents, RAV). 2018-11-14 10:33:30 +00:00
lib [AST] Allow limiting the scope of common AST traversals (getParents, RAV). 2018-11-14 10:33:30 +00:00
runtime [CMake] Make bootstrap and compiler-rt depend on cxx-headers. 2018-06-28 18:35:25 +00:00
test [OpenCL] Fix invalid address space generation for clk_event_t 2018-11-14 09:40:05 +00:00
tools [OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension 2018-11-08 11:25:41 +00:00
unittests [AST] Allow limiting the scope of common AST traversals (getParents, RAV). 2018-11-14 10:33:30 +00:00
utils [analyzer] Drastically simplify the tblgen files used for checkers 2018-11-12 17:49:51 +00:00
www Implement P1094R2 (nested inline namespaces) 2018-11-12 17:19:48 +00:00
.arcconfig
.clang-format
.clang-tidy
.gitignore [NFC] Add tags file to .gitignore 2018-08-22 23:23:17 +00:00
CMakeLists.txt CMake: Deprecate using llvm-config to detect llvm installation 2018-11-13 03:42:46 +00:00
CODE_OWNERS.TXT
INSTALL.txt
LICENSE.TXT Update copyright year to 2018. 2018-06-18 12:22:17 +00:00
ModuleInfo.txt
NOTES.txt
README.txt

README.txt

//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//

Welcome to Clang.  This is a compiler front-end for the C family of languages
(C, C++, Objective-C, and Objective-C++) which is built as part of the LLVM
compiler infrastructure project.

Unlike many other compiler frontends, Clang is useful for a number of things
beyond just compiling code: we intend for Clang to be host to a number of
different source-level tools.  One example of this is the Clang Static Analyzer.

If you're interested in more (including how to build Clang) it is best to read
the relevant web sites.  Here are some pointers:

Information on Clang:             http://clang.llvm.org/
Building and using Clang:         http://clang.llvm.org/get_started.html
Clang Static Analyzer:            http://clang-analyzer.llvm.org/
Information on the LLVM project:  http://llvm.org/

If you have questions or comments about Clang, a great place to discuss them is
on the Clang development mailing list:
  http://lists.llvm.org/mailman/listinfo/cfe-dev

If you find a bug in Clang, please file it in the LLVM bug tracker:
  http://llvm.org/bugs/