#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include <functional>
+#include <string>
namespace clang {
namespace tooling {
RangeSelector range(RangeSelector Begin, RangeSelector End);
/// Convenience version of \c range where end-points are bound nodes.
-RangeSelector range(StringRef BeginID, StringRef EndID);
+RangeSelector range(std::string BeginID, std::string 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);
+RangeSelector node(std::string 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);
+RangeSelector statement(std::string ID);
/// Given a \c MemberExpr, selects the member token. \p ID is the node's
/// binding in the match result.
-RangeSelector member(StringRef ID);
+RangeSelector member(std::string ID);
/// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr or \c
/// CxxCtorInitializer) selects the name's token. Only selects the final
/// it selects only `baz`.
///
/// \param ID is the node's binding in the match result.
-RangeSelector name(StringRef ID);
+RangeSelector name(std::string 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);
+RangeSelector callArgs(std::string ID);
// Given a \c CompoundStmt (bound to \p ID), selects the source of the
// statements (all source between the braces).
-RangeSelector statements(StringRef ID);
+RangeSelector statements(std::string ID);
// Given a \c InitListExpr (bound to \p ID), selects the range of the elements
// (all source between the braces).
-RangeSelector initListElements(StringRef ID);
+RangeSelector initListElements(std::string 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
return findPreviousTokenKind(EndLoc, SM, LangOpts, tok::TokenKind::l_paren);
}
-RangeSelector tooling::node(StringRef ID) {
+RangeSelector tooling::node(std::string ID) {
return [ID](const MatchResult &Result) -> Expected<CharSourceRange> {
Expected<DynTypedNode> Node = getNode(Result.Nodes, ID);
if (!Node)
};
}
-RangeSelector tooling::statement(StringRef ID) {
+RangeSelector tooling::statement(std::string ID) {
return [ID](const MatchResult &Result) -> Expected<CharSourceRange> {
Expected<DynTypedNode> Node = getNode(Result.Nodes, ID);
if (!Node)
};
}
-RangeSelector tooling::range(StringRef BeginID, StringRef EndID) {
- return tooling::range(node(BeginID), node(EndID));
+RangeSelector tooling::range(std::string BeginID, std::string EndID) {
+ return tooling::range(node(std::move(BeginID)), node(std::move(EndID)));
}
-RangeSelector tooling::member(StringRef ID) {
+RangeSelector tooling::member(std::string ID) {
return [ID](const MatchResult &Result) -> Expected<CharSourceRange> {
Expected<DynTypedNode> Node = getNode(Result.Nodes, ID);
if (!Node)
};
}
-RangeSelector tooling::name(StringRef ID) {
+RangeSelector tooling::name(std::string ID) {
return [ID](const MatchResult &Result) -> Expected<CharSourceRange> {
Expected<DynTypedNode> N = getNode(Result.Nodes, ID);
if (!N)
std::string ID;
public:
- RelativeSelector(StringRef ID) : ID(ID) {}
+ RelativeSelector(std::string ID) : ID(std::move(ID)) {}
Expected<CharSourceRange> operator()(const MatchResult &Result) {
Expected<DynTypedNode> N = getNode(Result.Nodes, ID);
}
} // namespace
-RangeSelector tooling::statements(StringRef ID) {
- return RelativeSelector<CompoundStmt, getStatementsRange>(ID);
+RangeSelector tooling::statements(std::string ID) {
+ return RelativeSelector<CompoundStmt, getStatementsRange>(std::move(ID));
}
namespace {
}
} // namespace
-RangeSelector tooling::callArgs(StringRef ID) {
- return RelativeSelector<CallExpr, getCallArgumentsRange>(ID);
+RangeSelector tooling::callArgs(std::string ID) {
+ return RelativeSelector<CallExpr, getCallArgumentsRange>(std::move(ID));
}
namespace {
}
} // namespace
-RangeSelector tooling::initListElements(StringRef ID) {
- return RelativeSelector<InitListExpr, getElementsRange>(ID);
+RangeSelector tooling::initListElements(std::string ID) {
+ return RelativeSelector<InitListExpr, getElementsRange>(std::move(ID));
}
RangeSelector tooling::expansion(RangeSelector S) {