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
diff --git a/lldb/source/DataFormatters/FormatCache.cpp b/lldb/source/DataFormatters/FormatCache.cpp
index 3721f18..aaa4bc1 100644
--- a/lldb/source/DataFormatters/FormatCache.cpp
+++ b/lldb/source/DataFormatters/FormatCache.cpp
@@ -25,16 +25,20 @@
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 @@
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 @@
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 @@
return m_synthetic_cached;
}
+bool
+FormatCache::Entry::IsValidatorCached ()
+{
+ return m_validator_cached;
+}
+
lldb::TypeFormatImplSP
FormatCache::Entry::GetFormat ()
{
@@ -100,6 +126,12 @@
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 @@
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 @@
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 @@
}
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);