Author: enrico Date: Tue Sep 20 13:26:30 2016 New Revision: 281993 URL: http://llvm.org/viewvc/llvm-project?rev=281993&view=rev Log: Make it so that one can register prefix matches as well as identical matches as extra cases for NSDictionary data formatting
Modified: lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.cpp lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.h Modified: lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.cpp?rev=281993&r1=281992&r2=281993&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.cpp (original) +++ lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.cpp Tue Sep 20 13:26:30 2016 @@ -34,15 +34,34 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; -std::map<ConstString, CXXFunctionSummaryFormat::Callback> & +NSDictionary_Additionals::AdditionalFormatterMatching::Prefix::Prefix( + ConstString p) + : m_prefix(p) {} + +bool NSDictionary_Additionals::AdditionalFormatterMatching::Prefix::Match( + ConstString class_name) { + return class_name.GetStringRef().startswith(m_prefix.GetStringRef()); +} + +NSDictionary_Additionals::AdditionalFormatterMatching::Full::Full(ConstString n) + : m_name(n) {} + +bool NSDictionary_Additionals::AdditionalFormatterMatching::Full::Match( + ConstString class_name) { + return (class_name == m_name); +} + +NSDictionary_Additionals::AdditionalFormatters< + CXXFunctionSummaryFormat::Callback> & NSDictionary_Additionals::GetAdditionalSummaries() { - static std::map<ConstString, CXXFunctionSummaryFormat::Callback> g_map; + static AdditionalFormatters<CXXFunctionSummaryFormat::Callback> g_map; return g_map; } -std::map<ConstString, CXXSyntheticChildren::CreateFrontEndCallback> & +NSDictionary_Additionals::AdditionalFormatters< + CXXSyntheticChildren::CreateFrontEndCallback> & NSDictionary_Additionals::GetAdditionalSynthetics() { - static std::map<ConstString, CXXSyntheticChildren::CreateFrontEndCallback> + static AdditionalFormatters<CXXSyntheticChildren::CreateFrontEndCallback> g_map; return g_map; } @@ -265,11 +284,11 @@ bool lldb_private::formatters::NSDiction }*/ else { auto &map(NSDictionary_Additionals::GetAdditionalSummaries()); - auto iter = map.find(class_name), end = map.end(); - if (iter != end) - return iter->second(valobj, stream, options); - else - return false; + for (auto &candidate : map) { + if (candidate.first && candidate.first->Match(class_name)) + return candidate.second(valobj, stream, options); + } + return false; } std::string prefix, suffix; @@ -331,9 +350,10 @@ lldb_private::formatters::NSDictionarySy return (new NSDictionary1SyntheticFrontEnd(valobj_sp)); } else { auto &map(NSDictionary_Additionals::GetAdditionalSynthetics()); - auto iter = map.find(class_name), end = map.end(); - if (iter != end) - return iter->second(synth, valobj_sp); + for (auto &candidate : map) { + if (candidate.first && candidate.first->Match((class_name))) + return candidate.second(synth, valobj_sp); + } } return nullptr; Modified: lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.h?rev=281993&r1=281992&r2=281993&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.h (original) +++ lldb/trunk/source/Plugins/Language/ObjC/NSDictionary.h Tue Sep 20 13:26:30 2016 @@ -18,6 +18,7 @@ #include "lldb/DataFormatters/TypeSynthetic.h" #include <map> +#include <memory> namespace lldb_private { namespace formatters { @@ -39,10 +40,53 @@ NSDictionarySyntheticFrontEndCreator(CXX class NSDictionary_Additionals { public: - static std::map<ConstString, CXXFunctionSummaryFormat::Callback> & + class AdditionalFormatterMatching { + public: + class Matcher { + public: + virtual ~Matcher() = default; + virtual bool Match(ConstString class_name) = 0; + + typedef std::unique_ptr<Matcher> UP; + }; + class Prefix : public Matcher { + public: + Prefix(ConstString p); + virtual ~Prefix() = default; + virtual bool Match(ConstString class_name) override; + + private: + ConstString m_prefix; + }; + class Full : public Matcher { + public: + Full(ConstString n); + virtual ~Full() = default; + virtual bool Match(ConstString class_name) override; + + private: + ConstString m_name; + }; + typedef Matcher::UP MatcherUP; + + MatcherUP GetFullMatch(ConstString n) { return llvm::make_unique<Full>(n); } + + MatcherUP GetPrefixMatch(ConstString p) { + return llvm::make_unique<Prefix>(p); + } + }; + + template <typename FormatterType> + using AdditionalFormatter = + std::pair<AdditionalFormatterMatching::MatcherUP, FormatterType>; + + template <typename FormatterType> + using AdditionalFormatters = std::vector<AdditionalFormatter<FormatterType>>; + + static AdditionalFormatters<CXXFunctionSummaryFormat::Callback> & GetAdditionalSummaries(); - static std::map<ConstString, CXXSyntheticChildren::CreateFrontEndCallback> & + static AdditionalFormatters<CXXSyntheticChildren::CreateFrontEndCallback> & GetAdditionalSynthetics(); }; } // namespace formatters _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits