[PATCH] D100423: [AST] Add a print method to Introspection LocationCall
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 15 14:18:54 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG542e7806e610: [AST] Add a print method to Introspection LocationCall (authored by njames93).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100423/new/
https://reviews.llvm.org/D100423
Files:
clang/include/clang/Tooling/NodeIntrospection.h
clang/lib/Tooling/NodeIntrospection.cpp
clang/unittests/Introspection/IntrospectionTest.cpp
Index: clang/unittests/Introspection/IntrospectionTest.cpp
===================================================================
--- clang/unittests/Introspection/IntrospectionTest.cpp
+++ clang/unittests/Introspection/IntrospectionTest.cpp
@@ -36,9 +36,9 @@
}),
std::inserter(Result, Result.end()),
[](const auto &Accessor) {
- return std::make_pair(
- LocationCallFormatterCpp::format(Accessor.second.get()),
- Accessor.first);
+ return std::make_pair(LocationCallFormatterCpp::format(
+ *Accessor.second.get()),
+ Accessor.first);
});
return Result;
}
Index: clang/lib/Tooling/NodeIntrospection.cpp
===================================================================
--- clang/lib/Tooling/NodeIntrospection.cpp
+++ clang/lib/Tooling/NodeIntrospection.cpp
@@ -13,25 +13,40 @@
#include "clang/Tooling/NodeIntrospection.h"
#include "clang/AST/AST.h"
+#include "llvm/Support/raw_ostream.h"
namespace clang {
namespace tooling {
-std::string LocationCallFormatterCpp::format(LocationCall *Call) {
- SmallVector<LocationCall *> vec;
- while (Call) {
- vec.push_back(Call);
- Call = Call->on();
+void LocationCallFormatterCpp::print(const LocationCall &Call,
+ llvm::raw_ostream &OS) {
+ if (const LocationCall *On = Call.on()) {
+ print(*On, OS);
+ if (On->returnsPointer())
+ OS << "->";
+ else
+ OS << '.';
}
- std::string result;
- for (auto *VecCall : llvm::reverse(llvm::makeArrayRef(vec).drop_front())) {
- result +=
- (VecCall->name() + "()" + (VecCall->returnsPointer() ? "->" : "."))
- .str();
+
+ OS << Call.name();
+ if (Call.args().empty()) {
+ OS << "()";
+ return;
+ }
+ OS << '(' << Call.args().front();
+ for (const std::string &Arg : Call.args().drop_front()) {
+ OS << ", " << Arg;
}
- result += (vec.back()->name() + "()").str();
- return result;
+ OS << ')';
+}
+
+std::string LocationCallFormatterCpp::format(const LocationCall &Call) {
+ std::string Result;
+ llvm::raw_string_ostream OS(Result);
+ print(Call, OS);
+ OS.flush();
+ return Result;
}
namespace internal {
Index: clang/include/clang/Tooling/NodeIntrospection.h
===================================================================
--- clang/include/clang/Tooling/NodeIntrospection.h
+++ clang/include/clang/Tooling/NodeIntrospection.h
@@ -58,7 +58,8 @@
class LocationCallFormatterCpp {
public:
- static std::string format(LocationCall *Call);
+ static void print(const LocationCall &Call, llvm::raw_ostream &OS);
+ static std::string format(const LocationCall &Call);
};
namespace internal {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100423.337898.patch
Type: text/x-patch
Size: 2887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210415/c7f8fcc9/attachment.bin>
More information about the cfe-commits
mailing list