Author: teemperor Date: Wed Sep 25 02:56:23 2019 New Revision: 372836 URL: http://llvm.org/viewvc/llvm-project?rev=372836&view=rev Log: [lldb][NFC] Refactor and document *DumpToStreamOptions
Those two classes were mostly copy-pasted. Modified: lldb/trunk/include/lldb/DataFormatters/StringPrinter.h Modified: lldb/trunk/include/lldb/DataFormatters/StringPrinter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/StringPrinter.h?rev=372836&r1=372835&r2=372836&view=diff ============================================================================== --- lldb/trunk/include/lldb/DataFormatters/StringPrinter.h (original) +++ lldb/trunk/include/lldb/DataFormatters/StringPrinter.h Wed Sep 25 02:56:23 2019 @@ -24,19 +24,9 @@ public: enum class GetPrintableElementType { ASCII, UTF8 }; - class ReadStringAndDumpToStreamOptions { + class DumpToStreamOptions { public: - ReadStringAndDumpToStreamOptions() = default; - - ReadStringAndDumpToStreamOptions(ValueObject &valobj); - - void SetLocation(uint64_t l) { m_location = l; } - - uint64_t GetLocation() const { return m_location; } - - void SetProcessSP(lldb::ProcessSP p) { m_process_sp = p; } - - lldb::ProcessSP GetProcessSP() const { return m_process_sp; } + DumpToStreamOptions() = default; void SetStream(Stream *s) { m_stream = s; } @@ -80,90 +70,75 @@ public: void SetLanguage(lldb::LanguageType l) { m_language_type = l; } - lldb::LanguageType GetLanguage() const - { - return m_language_type; - } + lldb::LanguageType GetLanguage() const { return m_language_type; } private: - uint64_t m_location = 0; - lldb::ProcessSP m_process_sp; + /// The used output stream. Stream *m_stream = nullptr; + /// String that should be printed before the heading quote character. std::string m_prefix_token; + /// String that should be printed after the trailing quote character. std::string m_suffix_token; + /// The quote character that should surround the string. char m_quote = '"'; + /// The length of the memory region that should be dumped in bytes. uint32_t m_source_size = 0; bool m_needs_zero_termination = true; + /// True iff non-printable characters should be escaped when dumping + /// them to the stream. bool m_escape_non_printables = true; + /// True iff the max-string-summary-length setting of the target should + /// be ignored. bool m_ignore_max_length = false; + /// True iff a zero bytes ('\0') should terminate the memory region that + /// is being dumped. bool m_zero_is_terminator = true; + /// The language that the generated string literal is supposed to be valid + /// for. This changes for example what and how certain characters are + /// escaped. + /// For example, printing the a string containing only a quote (") char + /// with eLanguageTypeC would escape the quote character. lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown; }; - class ReadBufferAndDumpToStreamOptions { + class ReadStringAndDumpToStreamOptions : public DumpToStreamOptions { public: - ReadBufferAndDumpToStreamOptions() = default; - - ReadBufferAndDumpToStreamOptions(ValueObject &valobj); - - ReadBufferAndDumpToStreamOptions( - const ReadStringAndDumpToStreamOptions &options); - - void SetData(DataExtractor d) { m_data = d; } - - lldb_private::DataExtractor GetData() const { return m_data; } - - void SetStream(Stream *s) { m_stream = s; } - - Stream *GetStream() const { return m_stream; } - - void SetPrefixToken(const std::string &p) { m_prefix_token = p; } - - void SetPrefixToken(std::nullptr_t) { m_prefix_token.clear(); } - - const char *GetPrefixToken() const { return m_prefix_token.c_str(); } + ReadStringAndDumpToStreamOptions() = default; - void SetSuffixToken(const std::string &p) { m_suffix_token = p; } + ReadStringAndDumpToStreamOptions(ValueObject &valobj); - void SetSuffixToken(std::nullptr_t) { m_suffix_token.clear(); } + void SetLocation(uint64_t l) { m_location = l; } - const char *GetSuffixToken() const { return m_suffix_token.c_str(); } + uint64_t GetLocation() const { return m_location; } - void SetQuote(char q) { m_quote = q; } + void SetProcessSP(lldb::ProcessSP p) { m_process_sp = p; } - char GetQuote() const { return m_quote; } + lldb::ProcessSP GetProcessSP() const { return m_process_sp; } - void SetSourceSize(uint32_t s) { m_source_size = s; } + private: + uint64_t m_location = 0; + lldb::ProcessSP m_process_sp; + }; - uint32_t GetSourceSize() const { return m_source_size; } + class ReadBufferAndDumpToStreamOptions : public DumpToStreamOptions { + public: + ReadBufferAndDumpToStreamOptions() = default; - void SetEscapeNonPrintables(bool e) { m_escape_non_printables = e; } + ReadBufferAndDumpToStreamOptions(ValueObject &valobj); - bool GetEscapeNonPrintables() const { return m_escape_non_printables; } + ReadBufferAndDumpToStreamOptions( + const ReadStringAndDumpToStreamOptions &options); - void SetBinaryZeroIsTerminator(bool e) { m_zero_is_terminator = e; } + void SetData(DataExtractor d) { m_data = d; } - bool GetBinaryZeroIsTerminator() const { return m_zero_is_terminator; } + lldb_private::DataExtractor GetData() const { return m_data; } void SetIsTruncated(bool t) { m_is_truncated = t; } bool GetIsTruncated() const { return m_is_truncated; } - - void SetLanguage(lldb::LanguageType l) { m_language_type = l; } - - lldb::LanguageType GetLanguage() const { return m_language_type; } - private: DataExtractor m_data; - Stream *m_stream = nullptr; - std::string m_prefix_token; - std::string m_suffix_token; - char m_quote = '"'; - uint32_t m_source_size = 0; - bool m_escape_non_printables = true; - bool m_zero_is_terminator = true; bool m_is_truncated = false; - lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown; }; // I can't use a std::unique_ptr for this because the Deleter is a template _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits