clang 22.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_TRANSFORMER_RANGESELECTOR_H
16#define LLVM_CLANG_TOOLING_TRANSFORMER_RANGESELECTOR_H
17
21#include "llvm/Support/Error.h"
22#include <functional>
23#include <string>
24
25namespace clang {
26namespace transformer {
28
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.
38RangeSelector encloseNodes(std::string BeginID, std::string EndID);
39
40/// Selects the merge of the two ranges, i.e. from min(First.begin,
41/// Second.begin) to max(First.end, Second.end).
43
44/// DEPRECATED. Use `enclose`.
46 return enclose(std::move(Begin), std::move(End));
47}
48
49/// DEPRECATED. Use `encloseNodes`.
50inline RangeSelector range(std::string BeginID, std::string EndID) {
51 return encloseNodes(std::move(BeginID), std::move(EndID));
52}
53
54/// Selects the (empty) range [B,B) when \p Selector selects the range [B,E).
56
57/// Selects the point immediately following \p Selector. That is, the
58/// (empty) range [E,E), when \p Selector selects either
59/// * the CharRange [B,E) or
60/// * the TokenRange [B,E'] where the token at E' spans the range [E',E).
62
63/// Selects the range between `R1` and `R2.
65 return enclose(after(std::move(R1)), before(std::move(R2)));
66}
67
68/// Selects a node, including trailing semicolon, if any (for declarations and
69/// non-expression statements). \p ID is the node's binding in the match result.
70RangeSelector node(std::string ID);
71
72/// Selects a node, including trailing semicolon (always). Useful for selecting
73/// expression statements. \p ID is the node's binding in the match result.
74RangeSelector statement(std::string ID);
75
76/// Given a \c MemberExpr, selects the member token. \p ID is the node's
77/// binding in the match result.
78RangeSelector member(std::string ID);
79
80/// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr, \c
81/// CxxCtorInitializer, and \c TypeLoc) selects the name's token. Only selects
82/// the final identifier of a qualified name, but not any qualifiers or template
83/// arguments. For example, for `::foo::bar::baz` and `::foo::bar::baz<int>`,
84/// it selects only `baz`.
85///
86/// \param ID is the node's binding in the match result.
87RangeSelector name(std::string ID);
88
89// Given a \c CallExpr (bound to \p ID), selects the arguments' source text (all
90// source between the call's parentheses).
91RangeSelector callArgs(std::string ID);
92
93// Given a \c CXXConstructExpr (bound to \p ID), selects the
94// arguments' source text. Depending on the syntactic form of the construct,
95// this is the range between parentheses or braces.
96RangeSelector constructExprArgs(std::string ID);
97
98// Given a \c CompoundStmt (bound to \p ID), selects the source of the
99// statements (all source between the braces).
100RangeSelector statements(std::string ID);
101
102// Given a \c InitListExpr (bound to \p ID), selects the range of the elements
103// (all source between the braces).
104RangeSelector initListElements(std::string ID);
105
106/// Given an \IfStmt (bound to \p ID), selects the range of the else branch,
107/// starting from the \c else keyword.
108RangeSelector elseBranch(std::string ID);
109
110/// Selects the range from which `S` was expanded (possibly along with other
111/// source), if `S` is an expansion, and `S` itself, otherwise. Corresponds to
112/// `SourceManager::getExpansionRange`.
114} // namespace transformer
115} // namespace clang
116
117#endif // LLVM_CLANG_TOOLING_TRANSFORMER_RANGESELECTOR_H
Defines the clang::SourceLocation class and associated facilities.
Represents a character-granular source range.
Smart pointer class that efficiently represents Objective-C method names.
RangeSelector initListElements(std::string ID)
RangeSelector enclose(RangeSelector Begin, RangeSelector End)
Selects from the start of Begin and to the end of End.
RangeSelector merge(RangeSelector First, RangeSelector Second)
Selects the merge of the two ranges, i.e.
RangeSelector member(std::string ID)
Given a MemberExpr, selects the member token. ID is the node's binding in the match result.
RangeSelector between(RangeSelector R1, RangeSelector R2)
Selects the range between R1 and `R2.
RangeSelector elseBranch(std::string ID)
Given an \IfStmt (bound to ID), selects the range of the else branch, starting from the else keyword.
RangeSelector node(std::string ID)
Selects a node, including trailing semicolon, if any (for declarations and non-expression statements)...
RangeSelector encloseNodes(std::string BeginID, std::string EndID)
Convenience version of range where end-points are bound nodes.
RangeSelector after(RangeSelector Selector)
Selects the point immediately following Selector.
RangeSelector constructExprArgs(std::string ID)
MatchConsumer< CharSourceRange > RangeSelector
RangeSelector callArgs(std::string ID)
RangeSelector before(RangeSelector Selector)
Selects the (empty) range [B,B) when Selector selects the range [B,E).
RangeSelector range(RangeSelector Begin, RangeSelector End)
DEPRECATED. Use enclose.
RangeSelector statement(std::string ID)
Selects a node, including trailing semicolon (always). Useful for selecting expression statements....
RangeSelector charRange(CharSourceRange R)
std::function< Expected< T >(const ast_matchers::MatchFinder::MatchResult &)> MatchConsumer
A failable computation over nodes bound by AST matchers.
RangeSelector expansion(RangeSelector S)
Selects the range from which S was expanded (possibly along with other source), if S is an expansion,...
RangeSelector statements(std::string ID)
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
The JSON file list parser is used to communicate input to InstallAPI.
Contains all information for a given match.