summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYitzhak Mandelbaum <yitzhakm@google.com>2019-10-07 16:20:22 +0000
committerYitzhak Mandelbaum <yitzhakm@google.com>2019-10-07 16:20:22 +0000
commitcb574e1588c197f809f0877f647f414a5baaf13f (patch)
treebf0e898449477bd807bd79b337d2606e30041560 /include
parentd779f019c1215809fd65103f77f20026202bf35e (diff)
downloadclang-cb574e1588c197f809f0877f647f414a5baaf13f.tar.gz
[libTooling] Add `toString` method to the Stencil class
Summary: `toString` generates a string representation of the stencil. Patch by Harshal T. Lehri. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68574 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373916 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/clang/Tooling/Refactoring/Stencil.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/clang/Tooling/Refactoring/Stencil.h b/include/clang/Tooling/Refactoring/Stencil.h
index 96fd978e94..b80320d409 100644
--- a/include/clang/Tooling/Refactoring/Stencil.h
+++ b/include/clang/Tooling/Refactoring/Stencil.h
@@ -50,6 +50,11 @@ public:
virtual bool isEqual(const StencilPartInterface &other) const = 0;
+ /// Constructs a string representation of the StencilPart. StencilParts
+ /// generated by the `selection` and `run` functions do not have a unique
+ /// string representation.
+ virtual std::string toString() const = 0;
+
const void *typeId() const { return TypeId; }
protected:
@@ -86,6 +91,12 @@ public:
return Impl->isEqual(*Other.Impl);
}
+ std::string toString() const {
+ if (Impl == nullptr)
+ return "";
+ return Impl->toString();
+ }
+
private:
std::shared_ptr<StencilPartInterface> Impl;
};
@@ -120,6 +131,16 @@ public:
return eval(Result);
}
+ /// Constructs a string representation of the Stencil. The string is not
+ /// guaranteed to be unique.
+ std::string toString() const {
+ std::vector<std::string> PartStrings;
+ PartStrings.reserve(Parts.size());
+ for (const auto &Part : Parts)
+ PartStrings.push_back(Part.toString());
+ return llvm::join(PartStrings, ", ");
+ }
+
private:
friend bool operator==(const Stencil &A, const Stencil &B);
static StencilPart wrap(llvm::StringRef Text);