diff options
Diffstat (limited to 'include/clang/Tooling/Refactoring/Stencil.h')
-rw-r--r-- | include/clang/Tooling/Refactoring/Stencil.h | 21 |
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); |