diff options
author | Enrico Granata <egranata@apple.com> | 2014-09-05 20:45:07 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2014-09-05 20:45:07 +0000 |
commit | c582713ce6d050f00246114abdce9e220047518a (patch) | |
tree | 9ca75d0c8d4e9c34d735b1d4ac688e2780490603 /lldb/source/DataFormatters/FormatCache.cpp | |
parent | afe6794bc2ee35880e970e7e9fcde6c2ad72b51b (diff) | |
download | llvm-c582713ce6d050f00246114abdce9e220047518a.zip llvm-c582713ce6d050f00246114abdce9e220047518a.tar.gz llvm-c582713ce6d050f00246114abdce9e220047518a.tar.bz2 |
Introduce the notion of a "type validator" formatter
Type Validators have the purpose of looking at a ValueObject, and making sure that there is nothing semantically wrong about the object's contents
For instance, if you have a class that represents a speed, the validator might trigger if the speed value is greater than the speed of light
This first patch hooks up the moving parts in the formatters subsystem, but does not link ValueObjects to TypeValidators, nor lets the SB API be exposed to validators
It also lacks the notion of Python validators
llvm-svn: 217277
Diffstat (limited to 'lldb/source/DataFormatters/FormatCache.cpp')
-rw-r--r-- | lldb/source/DataFormatters/FormatCache.cpp | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/lldb/source/DataFormatters/FormatCache.cpp b/lldb/source/DataFormatters/FormatCache.cpp index 3721f182..aaa4bc1 100644 --- a/lldb/source/DataFormatters/FormatCache.cpp +++ b/lldb/source/DataFormatters/FormatCache.cpp @@ -25,16 +25,20 @@ FormatCache::Entry::Entry () : m_format_cached(false), m_summary_cached(false), m_synthetic_cached(false), +m_validator_cached(false), m_format_sp(), m_summary_sp(), -m_synthetic_sp() +m_synthetic_sp(), +m_validator_sp() {} FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) : m_summary_cached(false), m_synthetic_cached(false), +m_validator_cached(false), m_summary_sp(), -m_synthetic_sp() +m_synthetic_sp(), +m_validator_sp() { SetFormat (format_sp); } @@ -42,8 +46,10 @@ m_synthetic_sp() FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : m_format_cached(false), m_synthetic_cached(false), +m_validator_cached(false), m_format_sp(), -m_synthetic_sp() +m_synthetic_sp(), +m_validator_sp() { SetSummary (summary_sp); } @@ -51,17 +57,31 @@ m_synthetic_sp() FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : m_format_cached(false), m_summary_cached(false), +m_validator_cached(false), m_format_sp(), -m_summary_sp() +m_summary_sp(), +m_validator_sp() { SetSynthetic (synthetic_sp); } -FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp) +FormatCache::Entry::Entry (lldb::TypeValidatorImplSP validator_sp) : +m_format_cached(false), +m_summary_cached(false), +m_synthetic_cached(false), +m_format_sp(), +m_summary_sp(), +m_synthetic_sp() +{ + SetValidator (validator_sp); +} + +FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp, lldb::TypeValidatorImplSP validator_sp) { SetFormat (format_sp); SetSummary (summary_sp); SetSynthetic (synthetic_sp); + SetValidator (validator_sp); } bool @@ -82,6 +102,12 @@ FormatCache::Entry::IsSyntheticCached () return m_synthetic_cached; } +bool +FormatCache::Entry::IsValidatorCached () +{ + return m_validator_cached; +} + lldb::TypeFormatImplSP FormatCache::Entry::GetFormat () { @@ -100,6 +126,12 @@ FormatCache::Entry::GetSynthetic () return m_synthetic_sp; } +lldb::TypeValidatorImplSP +FormatCache::Entry::GetValidator () +{ + return m_validator_sp; +} + void FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp) { @@ -121,6 +153,13 @@ FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp) m_synthetic_sp = synthetic_sp; } +void +FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp) +{ + m_validator_cached = true; + m_validator_sp = validator_sp; +} + FormatCache::FormatCache () : m_map(), m_mutex (Mutex::eMutexTypeRecursive) @@ -201,6 +240,26 @@ FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& sy return false; } +bool +FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp) +{ + Mutex::Locker lock(m_mutex); + auto entry = GetEntry(type); + if (entry.IsValidatorCached()) + { +#ifdef LLDB_CONFIGURATION_DEBUG + m_cache_hits++; +#endif + validator_sp = entry.GetValidator(); + return true; + } +#ifdef LLDB_CONFIGURATION_DEBUG + m_cache_misses++; +#endif + validator_sp.reset(); + return false; +} + void FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) { @@ -223,6 +282,13 @@ FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& sy } void +FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp) +{ + Mutex::Locker lock(m_mutex); + GetEntry(type).SetValidator(validator_sp); +} + +void FormatCache::Clear () { Mutex::Locker lock(m_mutex); |