clang  14.0.0git
RangeSelector.h
Go to the documentation of this file.
1 //===--- RangeSelector.h - Source-selection library ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Defines a combinator library supporting the definition of _selectors_,
11 /// which select source ranges based on (bound) AST nodes.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
16 #define LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
17 
21 #include "llvm/Support/Error.h"
22 #include <functional>
23 #include <string>
24 
25 namespace clang {
26 namespace transformer {
28 
30  return [R](const ast_matchers::MatchFinder::MatchResult &)
31  -> Expected<CharSourceRange> { return R; };
32 }
33 
34 /// Selects from the start of \p Begin and to the end of \p End.
36 
37 /// Convenience version of \c range where end-points are bound nodes.
39 
40 /// DEPRECATED. Use `enclose`.
42  return enclose(std::move(Begin), std::move(End));
43 }
44 
45 /// DEPRECATED. Use `encloseNodes`.
46 inline RangeSelector range(std::string BeginID, std::string EndID) {
47  return encloseNodes(std::move(BeginID), std::move(EndID));
48 }
49 
50 /// Selects the (empty) range [B,B) when \p Selector selects the range [B,E).
52 
53 /// Selects the point immediately following \p Selector. That is, the
54 /// (empty) range [E,E), when \p Selector selects either
55 /// * the CharRange [B,E) or
56 /// * the TokenRange [B,E'] where the token at E' spans the range [E',E).
58 
59 /// Selects the range between `R1` and `R2.
61  return enclose(after(std::move(R1)), before(std::move(R2)));
62 }
63 
64 /// Selects a node, including trailing semicolon, if any (for declarations and
65 /// non-expression statements). \p ID is the node's binding in the match result.
67 
68 /// Selects a node, including trailing semicolon (always). Useful for selecting
69 /// expression statements. \p ID is the node's binding in the match result.
71 
72 /// Given a \c MemberExpr, selects the member token. \p ID is the node's
73 /// binding in the match result.
75 
76 /// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr, \c
77 /// CxxCtorInitializer, and \c TypeLoc) selects the name's token. Only selects
78 /// the final identifier of a qualified name, but not any qualifiers or template
79 /// arguments. For example, for `::foo::bar::baz` and `::foo::bar::baz<int>`,
80 /// it selects only `baz`.
81 ///
82 /// \param ID is the node's binding in the match result.
84 
85 // Given a \c CallExpr (bound to \p ID), selects the arguments' source text (all
86 // source between the call's parentheses).
88 
89 // Given a \c CompoundStmt (bound to \p ID), selects the source of the
90 // statements (all source between the braces).
92 
93 // Given a \c InitListExpr (bound to \p ID), selects the range of the elements
94 // (all source between the braces).
96 
97 /// Given an \IfStmt (bound to \p ID), selects the range of the else branch,
98 /// starting from the \c else keyword.
100 
101 /// Selects the range from which `S` was expanded (possibly along with other
102 /// source), if `S` is an expansion, and `S` itself, otherwise. Corresponds to
103 /// `SourceManager::getExpansionRange`.
105 } // namespace transformer
106 } // namespace clang
107 
108 #endif // LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
MatchConsumer.h
clang::transformer::initListElements
RangeSelector initListElements(std::string ID)
Definition: RangeSelector.cpp:312
clang::transformer::charRange
RangeSelector charRange(CharSourceRange R)
Definition: RangeSelector.h:29
llvm::Expected
Definition: LLVM.h:41
ASTMatchFinder.h
clang::transformer::elseBranch
RangeSelector elseBranch(std::string ID)
Given an \IfStmt (bound to ID), selects the range of the else branch, starting from the else keyword.
Definition: RangeSelector.cpp:325
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::transformer::RangeSelector
MatchConsumer< CharSourceRange > RangeSelector
Definition: RangeSelector.h:27
clang::transformer::statement
RangeSelector statement(std::string ID)
Selects a node, including trailing semicolon (always).
Definition: RangeSelector.cpp:154
SourceLocation.h
clang::transformer::expansion
RangeSelector expansion(RangeSelector S)
Selects the range from which S was expanded (possibly along with other source), if S is an expansion,...
Definition: RangeSelector.cpp:329
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:255
clang::transformer::between
RangeSelector between(RangeSelector R1, RangeSelector R2)
Selects the range between R1 and `R2.
Definition: RangeSelector.h:60
clang::transformer::MatchConsumer
std::function< Expected< T >(const ast_matchers::MatchFinder::MatchResult &)> MatchConsumer
A failable computation over nodes bound by AST matchers.
Definition: MatchConsumer.h:35
clang::transformer::after
RangeSelector after(RangeSelector Selector)
Selects the point immediately following Selector.
Definition: RangeSelector.cpp:115
clang::transformer::member
RangeSelector member(std::string ID)
Given a MemberExpr, selects the member token.
Definition: RangeSelector.cpp:188
clang::ast_matchers::MatchFinder::MatchResult
Contains all information for a given match.
Definition: ASTMatchFinder.h:74
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang
Definition: CalledOnceCheck.h:17
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:748
clang::transformer::range
RangeSelector range(RangeSelector Begin, RangeSelector End)
DEPRECATED. Use enclose.
Definition: RangeSelector.h:41
clang::transformer::callArgs
RangeSelector callArgs(std::string ID)
Definition: RangeSelector.cpp:298
clang::transformer::enclose
RangeSelector enclose(RangeSelector Begin, RangeSelector End)
Selects from the start of Begin and to the end of End.
Definition: RangeSelector.cpp:164
clang::transformer::encloseNodes
RangeSelector encloseNodes(std::string BeginID, std::string EndID)
Convenience version of range where end-points are bound nodes.
Definition: RangeSelector.cpp:183
clang::transformer::statements
RangeSelector statements(std::string ID)
Definition: RangeSelector.cpp:283
clang::transformer::node
RangeSelector node(std::string ID)
Selects a node, including trailing semicolon, if any (for declarations and non-expression statements)...
Definition: RangeSelector.cpp:141
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
Definition: RangeSelector.cpp:200
clang::transformer::before
RangeSelector before(RangeSelector Selector)
Selects the (empty) range [B,B) when Selector selects the range [B,E).
Definition: RangeSelector.cpp:106