clang  10.0.0svn
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.
38 RangeSelector range(std::string BeginID, std::string EndID);
39 
40 /// Selects the (empty) range [B,B) when \p Selector selects the range [B,E).
42 
43 /// Selects the the point immediately following \p Selector. That is, the
44 /// (empty) range [E,E), when \p Selector selects either
45 /// * the CharRange [B,E) or
46 /// * the TokenRange [B,E'] where the token at E' spans the range [E,E').
48 
49 /// Selects a node, including trailing semicolon (for non-expression
50 /// statements). \p ID is the node's binding in the match result.
51 RangeSelector node(std::string ID);
52 
53 /// Selects a node, including trailing semicolon (always). Useful for selecting
54 /// expression statements. \p ID is the node's binding in the match result.
55 RangeSelector statement(std::string ID);
56 
57 /// Given a \c MemberExpr, selects the member token. \p ID is the node's
58 /// binding in the match result.
59 RangeSelector member(std::string ID);
60 
61 /// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr or \c
62 /// CxxCtorInitializer) selects the name's token. Only selects the final
63 /// identifier of a qualified name, but not any qualifiers or template
64 /// arguments. For example, for `::foo::bar::baz` and `::foo::bar::baz<int>`,
65 /// it selects only `baz`.
66 ///
67 /// \param ID is the node's binding in the match result.
68 RangeSelector name(std::string ID);
69 
70 // Given a \c CallExpr (bound to \p ID), selects the arguments' source text (all
71 // source between the call's parentheses).
72 RangeSelector callArgs(std::string ID);
73 
74 // Given a \c CompoundStmt (bound to \p ID), selects the source of the
75 // statements (all source between the braces).
76 RangeSelector statements(std::string ID);
77 
78 // Given a \c InitListExpr (bound to \p ID), selects the range of the elements
79 // (all source between the braces).
80 RangeSelector initListElements(std::string ID);
81 
82 /// Given an \IfStmt (bound to \p ID), selects the range of the else branch,
83 /// starting from the \c else keyword.
84 RangeSelector elseBranch(std::string ID);
85 
86 /// Selects the range from which `S` was expanded (possibly along with other
87 /// source), if `S` is an expansion, and `S` itself, otherwise. Corresponds to
88 /// `SourceManager::getExpansionRange`.
90 } // namespace transformer
91 
92 namespace tooling {
93 // DEPRECATED: These are temporary aliases supporting client migration to the
94 // `transformer` namespace.
96 
97 using transformer::after;
104 using transformer::member;
105 using transformer::name;
106 using transformer::node;
107 using transformer::range;
110 } // namespace tooling
111 } // namespace clang
112 
113 #endif // LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
Smart pointer class that efficiently represents Objective-C method names.
RangeSelector member(std::string ID)
Given a MemberExpr, selects the member token.
RangeSelector range(RangeSelector Begin, RangeSelector End)
Selects from the start of Begin and to the end of End.
RangeSelector callArgs(std::string ID)
RangeSelector before(RangeSelector Selector)
Selects the (empty) range [B,B) when Selector selects the range [B,E).
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
SourceLocation End
Represents a character-granular source range.
SourceLocation Begin
Contains all information for a given match.
MatchConsumer< CharSourceRange > RangeSelector
Definition: RangeSelector.h:27
std::function< Expected< T >(const ast_matchers::MatchFinder::MatchResult &)> MatchConsumer
A failable computation over nodes bound by AST matchers.
Definition: MatchConsumer.h:35
RangeSelector after(RangeSelector Selector)
Selects the the point immediately following Selector.
RangeSelector initListElements(std::string ID)
Dataflow Directional Tag Classes.
transformer::RangeSelector RangeSelector
Definition: RangeSelector.h:95
Defines the clang::SourceLocation class and associated facilities.
RangeSelector charRange(CharSourceRange R)
Definition: RangeSelector.h:29
RangeSelector expansion(RangeSelector S)
Selects the range from which S was expanded (possibly along with other source), if S is an expansion...
RangeSelector node(std::string ID)
Selects a node, including trailing semicolon (for non-expression statements).
RangeSelector statement(std::string ID)
Selects a node, including trailing semicolon (always).
RangeSelector statements(std::string ID)
RangeSelector elseBranch(std::string ID)
Given an (bound to ID), selects the range of the else branch, starting from the else keyword...