Skip to content

Commit c582713

Browse files
author
Enrico Granata
committedSep 5, 2014
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
1 parent afe6794 commit c582713

16 files changed

+724
-13
lines changed
 

‎lldb/include/lldb/DataFormatters/DataVisualization.h

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class DataVisualization
7272
lldb::DynamicValueType use_dynamic);
7373
#endif
7474

75+
static lldb::TypeValidatorImplSP
76+
GetValidator (ValueObject& valobj,
77+
lldb::DynamicValueType use_dynamic);
78+
79+
static lldb::TypeValidatorImplSP
80+
GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
81+
7582
static bool
7683
AnyMatches(ConstString type_name,
7784
TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,

‎lldb/include/lldb/DataFormatters/FormatCache.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ class FormatCache
3131
bool m_format_cached : 1;
3232
bool m_summary_cached : 1;
3333
bool m_synthetic_cached : 1;
34+
bool m_validator_cached : 1;
3435

3536
lldb::TypeFormatImplSP m_format_sp;
3637
lldb::TypeSummaryImplSP m_summary_sp;
3738
lldb::SyntheticChildrenSP m_synthetic_sp;
39+
lldb::TypeValidatorImplSP m_validator_sp;
3840
public:
3941
Entry ();
4042
Entry (lldb::TypeFormatImplSP);
4143
Entry (lldb::TypeSummaryImplSP);
4244
Entry (lldb::SyntheticChildrenSP);
43-
Entry (lldb::TypeFormatImplSP,lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP);
45+
Entry (lldb::TypeValidatorImplSP);
46+
Entry (lldb::TypeFormatImplSP,lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP,lldb::TypeValidatorImplSP);
4447

4548
bool
4649
IsFormatCached ();
@@ -51,6 +54,9 @@ class FormatCache
5154
bool
5255
IsSyntheticCached ();
5356

57+
bool
58+
IsValidatorCached ();
59+
5460
lldb::TypeFormatImplSP
5561
GetFormat ();
5662

@@ -60,6 +66,9 @@ class FormatCache
6066
lldb::SyntheticChildrenSP
6167
GetSynthetic ();
6268

69+
lldb::TypeValidatorImplSP
70+
GetValidator ();
71+
6372
void
6473
SetFormat (lldb::TypeFormatImplSP);
6574

@@ -68,6 +77,9 @@ class FormatCache
6877

6978
void
7079
SetSynthetic (lldb::SyntheticChildrenSP);
80+
81+
void
82+
SetValidator (lldb::TypeValidatorImplSP);
7183
};
7284
typedef std::map<ConstString,Entry> CacheMap;
7385
CacheMap m_map;
@@ -91,6 +103,9 @@ class FormatCache
91103
bool
92104
GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp);
93105

106+
bool
107+
GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& summary_sp);
108+
94109
void
95110
SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp);
96111

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

118+
void
119+
SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& synthetic_sp);
120+
103121
void
104122
Clear ();
105123

‎lldb/include/lldb/DataFormatters/FormatManager.h

+11
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ class FormatManager : public IFormatChangeListener
148148
GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
149149
#endif
150150

151+
lldb::TypeValidatorImplSP
152+
GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
153+
151154
lldb::TypeFormatImplSP
152155
GetFormat (ValueObject& valobj,
153156
lldb::DynamicValueType use_dynamic);
@@ -162,6 +165,10 @@ class FormatManager : public IFormatChangeListener
162165
lldb::DynamicValueType use_dynamic);
163166
#endif
164167

168+
lldb::TypeValidatorImplSP
169+
GetValidator (ValueObject& valobj,
170+
lldb::DynamicValueType use_dynamic);
171+
165172
bool
166173
AnyMatches (ConstString type_name,
167174
TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
@@ -272,6 +279,7 @@ class FormatManager : public IFormatChangeListener
272279
HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
273280
HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
274281
HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
282+
HardcodedFormatterFinders<TypeValidatorImpl> m_hardcoded_validators;
275283

276284
lldb::TypeFormatImplSP
277285
GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
@@ -282,6 +290,9 @@ class FormatManager : public IFormatChangeListener
282290
lldb::SyntheticChildrenSP
283291
GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);
284292

293+
lldb::TypeValidatorImplSP
294+
GetHardcodedValidator (ValueObject&,lldb::DynamicValueType);
295+
285296
TypeCategoryMap&
286297
GetCategories ()
287298
{

‎lldb/include/lldb/DataFormatters/FormattersContainer.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "lldb/DataFormatters/TypeFormat.h"
3030
#include "lldb/DataFormatters/TypeSummary.h"
3131
#include "lldb/DataFormatters/TypeSynthetic.h"
32+
#include "lldb/DataFormatters/TypeValidator.h"
3233

3334
#include "lldb/Symbol/ClangASTContext.h"
3435
#include "lldb/Symbol/ClangASTType.h"

‎lldb/include/lldb/DataFormatters/TypeCategory.h

+35-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace lldb_private {
7171
typedef FormatterContainerPair<TypeFormatImpl> FormatContainer;
7272
typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer;
7373
typedef FormatterContainerPair<TypeFilterImpl> FilterContainer;
74+
typedef FormatterContainerPair<TypeValidatorImpl> ValidatorContainer;
7475

7576
#ifndef LLDB_DISABLE_PYTHON
7677
typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer;
@@ -94,6 +95,9 @@ namespace lldb_private {
9495
typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP;
9596
#endif // #ifndef LLDB_DISABLE_PYTHON
9697

98+
typedef ValidatorContainer::ExactMatchContainerSP ValidatorContainerSP;
99+
typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP;
100+
97101
TypeCategoryImpl (IFormatChangeListener* clist,
98102
ConstString name);
99103

@@ -147,6 +151,9 @@ namespace lldb_private {
147151
GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
148152
#endif
149153

154+
ValidatorContainer::MapValueType
155+
GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
156+
150157
lldb::TypeNameSpecifierImplSP
151158
GetTypeNameSpecifierForFormatAtIndex (size_t index);
152159

@@ -183,9 +190,26 @@ namespace lldb_private {
183190

184191
lldb::TypeNameSpecifierImplSP
185192
GetTypeNameSpecifierForSyntheticAtIndex (size_t index);
186-
187193
#endif // #ifndef LLDB_DISABLE_PYTHON
188194

195+
ValidatorContainerSP
196+
GetTypeValidatorsContainer ()
197+
{
198+
return m_validator_cont.GetExactMatch();
199+
}
200+
201+
RegexValidatorContainerSP
202+
GetRegexTypeValidatorsContainer ()
203+
{
204+
return m_validator_cont.GetRegexMatch();
205+
}
206+
207+
ValidatorContainer::MapValueType
208+
GetValidatorAtIndex (size_t index);
209+
210+
lldb::TypeNameSpecifierImplSP
211+
GetTypeNameSpecifierForValidatorAtIndex (size_t index);
212+
189213
bool
190214
IsEnabled () const
191215
{
@@ -219,6 +243,12 @@ namespace lldb_private {
219243
lldb::SyntheticChildrenSP& entry,
220244
uint32_t* reason = NULL);
221245

246+
bool
247+
Get (ValueObject& valobj,
248+
const FormattersMatchVector& candidates,
249+
lldb::TypeValidatorImplSP& entry,
250+
uint32_t* reason = NULL);
251+
222252
void
223253
Clear (FormatCategoryItems items = ALL_ITEM_TYPES);
224254

@@ -246,14 +276,12 @@ namespace lldb_private {
246276

247277
private:
248278
FormatContainer m_format_cont;
249-
250279
SummaryContainer m_summary_cont;
251-
252280
FilterContainer m_filter_cont;
253-
254281
#ifndef LLDB_DISABLE_PYTHON
255282
SynthContainer m_synth_cont;
256283
#endif // #ifndef LLDB_DISABLE_PYTHON
284+
ValidatorContainer m_validator_cont;
257285

258286
bool m_enabled;
259287

@@ -289,6 +317,9 @@ namespace lldb_private {
289317
friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>;
290318
friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>;
291319
#endif // #ifndef LLDB_DISABLE_PYTHON
320+
321+
friend class FormattersContainer<ConstString, TypeValidatorImpl>;
322+
friend class FormattersContainer<lldb::RegularExpressionSP, TypeValidatorImpl>;
292323
};
293324

294325
} // namespace lldb_private

‎lldb/include/lldb/DataFormatters/TypeCategoryMap.h

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ namespace lldb_private {
108108
lldb::DynamicValueType use_dynamic);
109109
#endif
110110

111+
lldb::TypeValidatorImplSP
112+
GetValidator (ValueObject& valobj,
113+
lldb::DynamicValueType use_dynamic);
114+
111115
private:
112116

113117
class delete_matching_categories

0 commit comments

Comments
 (0)
Please sign in to comment.