text: //===--- RangeSelector.h - Source-selection library ---------*- C++ -*-===//
  //
  // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  // See https://llvm.org/LICENSE.txt for license information.
  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  //
  //===----------------------------------------------------------------------===//
  ///
  ///  \file
  ///  Defines a combinator library supporting the definition of _selectors_,
  ///  which select source ranges based on (bound) AST nodes.
  ///
  //===----------------------------------------------------------------------===//
  
  #ifndef LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
  #define LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
  
  #include "clang/ASTMatchers/ASTMatchFinder.h"
  #include "clang/Basic/SourceLocation.h"
  #include "llvm/ADT/StringRef.h"
  #include "llvm/Support/Error.h"
  #include <functional>
  
  namespace clang {
  namespace tooling {
  using RangeSelector = std::function<Expected<CharSourceRange>(
      const ast_matchers::MatchFinder::MatchResult &)>;
  
  inline RangeSelector charRange(CharSourceRange R) {
    return [R](const ast_matchers::MatchFinder::MatchResult &)
               -> Expected<CharSourceRange> { return R; };
  }
  
  /// Selects from the start of \p Begin and to the end of \p End.
  RangeSelector range(RangeSelector Begin, RangeSelector End);
  
  /// Convenience version of \c range where end-points are bound nodes.
  RangeSelector range(StringRef BeginID, StringRef EndID);
  
  /// Selects a node, including trailing semicolon (for non-expression
  /// statements). \p ID is the node's binding in the match result.
  RangeSelector node(StringRef ID);
  
  /// Selects a node, including trailing semicolon (always). Useful for selecting
  /// expression statements. \p ID is the node's binding in the match result.
  RangeSelector statement(StringRef ID);
  
  /// Given a \c MemberExpr, selects the member token. \p ID is the node's
  /// binding in the match result.
  RangeSelector member(StringRef ID);
  
  /// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr or \c
  /// CxxCtorInitializer) selects the name's token.  Only selects the final
  /// identifier of a qualified name, but not any qualifiers or template
  /// arguments.  For example, for `::foo::bar::baz` and `::foo::bar::baz<int>`,
  /// it selects only `baz`.
  ///
  /// \param ID is the node's binding in the match result.
  RangeSelector name(StringRef ID);
  
  // Given a \c CallExpr (bound to \p ID), selects the arguments' source text (all
  // source between the call's parentheses).
  RangeSelector callArgs(StringRef ID);
  
  // Given a \c CompoundStmt (bound to \p ID), selects the source of the
  // statements (all source between the braces).
  RangeSelector statements(StringRef ID);
  
  // Given a \c InitListExpr (bound to \p ID), selects the range of the elements
  // (all source between the braces).
  RangeSelector initListElements(StringRef ID);
  
  /// Selects the range from which `S` was expanded (possibly along with other
  /// source), if `S` is an expansion, and `S` itself, otherwise.  Corresponds to
  /// `SourceManager::getExpansionRange`.
  RangeSelector expansion(RangeSelector S);
  } // namespace tooling
  } // namespace clang
  
  #endif // LLVM_CLANG_TOOLING_REFACTOR_RANGE_SELECTOR_H_
  