Skip to content

Commit

Permalink
Introduce the notion of a "type validator" formatter
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Enrico Granata committed Sep 5, 2014
1 parent afe6794 commit c582713
Show file tree
Hide file tree
Showing 16 changed files with 724 additions and 13 deletions.
7 changes: 7 additions & 0 deletions lldb/include/lldb/DataFormatters/DataVisualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class DataVisualization
lldb::DynamicValueType use_dynamic);
#endif

static lldb::TypeValidatorImplSP
GetValidator (ValueObject& valobj,
lldb::DynamicValueType use_dynamic);

static lldb::TypeValidatorImplSP
GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);

static bool
AnyMatches(ConstString type_name,
TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
Expand Down
20 changes: 19 additions & 1 deletion lldb/include/lldb/DataFormatters/FormatCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ class FormatCache
bool m_format_cached : 1;
bool m_summary_cached : 1;
bool m_synthetic_cached : 1;
bool m_validator_cached : 1;

lldb::TypeFormatImplSP m_format_sp;
lldb::TypeSummaryImplSP m_summary_sp;
lldb::SyntheticChildrenSP m_synthetic_sp;
lldb::TypeValidatorImplSP m_validator_sp;
public:
Entry ();
Entry (lldb::TypeFormatImplSP);
Entry (lldb::TypeSummaryImplSP);
Entry (lldb::SyntheticChildrenSP);
Entry (lldb::TypeFormatImplSP,lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP);
Entry (lldb::TypeValidatorImplSP);
Entry (lldb::TypeFormatImplSP,lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP,lldb::TypeValidatorImplSP);

bool
IsFormatCached ();
Expand All @@ -51,6 +54,9 @@ class FormatCache
bool
IsSyntheticCached ();

bool
IsValidatorCached ();

lldb::TypeFormatImplSP
GetFormat ();

Expand All @@ -60,6 +66,9 @@ class FormatCache
lldb::SyntheticChildrenSP
GetSynthetic ();

lldb::TypeValidatorImplSP
GetValidator ();

void
SetFormat (lldb::TypeFormatImplSP);

Expand All @@ -68,6 +77,9 @@ class FormatCache

void
SetSynthetic (lldb::SyntheticChildrenSP);

void
SetValidator (lldb::TypeValidatorImplSP);
};
typedef std::map<ConstString,Entry> CacheMap;
CacheMap m_map;
Expand All @@ -91,6 +103,9 @@ class FormatCache
bool
GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp);

bool
GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& summary_sp);

void
SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp);

Expand All @@ -100,6 +115,9 @@ class FormatCache
void
SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp);

void
SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& synthetic_sp);

void
Clear ();

Expand Down
11 changes: 11 additions & 0 deletions lldb/include/lldb/DataFormatters/FormatManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class FormatManager : public IFormatChangeListener
GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
#endif

lldb::TypeValidatorImplSP
GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);

lldb::TypeFormatImplSP
GetFormat (ValueObject& valobj,
lldb::DynamicValueType use_dynamic);
Expand All @@ -162,6 +165,10 @@ class FormatManager : public IFormatChangeListener
lldb::DynamicValueType use_dynamic);
#endif

lldb::TypeValidatorImplSP
GetValidator (ValueObject& valobj,
lldb::DynamicValueType use_dynamic);

bool
AnyMatches (ConstString type_name,
TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
Expand Down Expand Up @@ -272,6 +279,7 @@ class FormatManager : public IFormatChangeListener
HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
HardcodedFormatterFinders<TypeValidatorImpl> m_hardcoded_validators;

lldb::TypeFormatImplSP
GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
Expand All @@ -282,6 +290,9 @@ class FormatManager : public IFormatChangeListener
lldb::SyntheticChildrenSP
GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);

lldb::TypeValidatorImplSP
GetHardcodedValidator (ValueObject&,lldb::DynamicValueType);

TypeCategoryMap&
GetCategories ()
{
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/DataFormatters/FormattersContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "lldb/DataFormatters/TypeFormat.h"
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
#include "lldb/DataFormatters/TypeValidator.h"

#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTType.h"
Expand Down
39 changes: 35 additions & 4 deletions lldb/include/lldb/DataFormatters/TypeCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace lldb_private {
typedef FormatterContainerPair<TypeFormatImpl> FormatContainer;
typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer;
typedef FormatterContainerPair<TypeFilterImpl> FilterContainer;
typedef FormatterContainerPair<TypeValidatorImpl> ValidatorContainer;

#ifndef LLDB_DISABLE_PYTHON
typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer;
Expand All @@ -94,6 +95,9 @@ namespace lldb_private {
typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP;
#endif // #ifndef LLDB_DISABLE_PYTHON

typedef ValidatorContainer::ExactMatchContainerSP ValidatorContainerSP;
typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP;

TypeCategoryImpl (IFormatChangeListener* clist,
ConstString name);

Expand Down Expand Up @@ -147,6 +151,9 @@ namespace lldb_private {
GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
#endif

ValidatorContainer::MapValueType
GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);

lldb::TypeNameSpecifierImplSP
GetTypeNameSpecifierForFormatAtIndex (size_t index);

Expand Down Expand Up @@ -183,9 +190,26 @@ namespace lldb_private {

lldb::TypeNameSpecifierImplSP
GetTypeNameSpecifierForSyntheticAtIndex (size_t index);

#endif // #ifndef LLDB_DISABLE_PYTHON

ValidatorContainerSP
GetTypeValidatorsContainer ()
{
return m_validator_cont.GetExactMatch();
}

RegexValidatorContainerSP
GetRegexTypeValidatorsContainer ()
{
return m_validator_cont.GetRegexMatch();
}

ValidatorContainer::MapValueType
GetValidatorAtIndex (size_t index);

lldb::TypeNameSpecifierImplSP
GetTypeNameSpecifierForValidatorAtIndex (size_t index);

bool
IsEnabled () const
{
Expand Down Expand Up @@ -219,6 +243,12 @@ namespace lldb_private {
lldb::SyntheticChildrenSP& entry,
uint32_t* reason = NULL);

bool
Get (ValueObject& valobj,
const FormattersMatchVector& candidates,
lldb::TypeValidatorImplSP& entry,
uint32_t* reason = NULL);

void
Clear (FormatCategoryItems items = ALL_ITEM_TYPES);

Expand Down Expand Up @@ -246,14 +276,12 @@ namespace lldb_private {

private:
FormatContainer m_format_cont;

SummaryContainer m_summary_cont;

FilterContainer m_filter_cont;

#ifndef LLDB_DISABLE_PYTHON
SynthContainer m_synth_cont;
#endif // #ifndef LLDB_DISABLE_PYTHON
ValidatorContainer m_validator_cont;

bool m_enabled;

Expand Down Expand Up @@ -289,6 +317,9 @@ namespace lldb_private {
friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>;
friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>;
#endif // #ifndef LLDB_DISABLE_PYTHON

friend class FormattersContainer<ConstString, TypeValidatorImpl>;
friend class FormattersContainer<lldb::RegularExpressionSP, TypeValidatorImpl>;
};

} // namespace lldb_private
Expand Down
4 changes: 4 additions & 0 deletions lldb/include/lldb/DataFormatters/TypeCategoryMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ namespace lldb_private {
lldb::DynamicValueType use_dynamic);
#endif

lldb::TypeValidatorImplSP
GetValidator (ValueObject& valobj,
lldb::DynamicValueType use_dynamic);

private:

class delete_matching_categories
Expand Down
Loading

0 comments on commit c582713

Please sign in to comment.