]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeSummary.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / TypeSummary.h
1 //===-- TypeSummary.h --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_TypeSummary_h_
11 #define lldb_TypeSummary_h_
12
13 // C Includes
14 #include <stdint.h>
15
16 // C++ Includes
17 #include <string>
18 #include <vector>
19
20 // Other libraries and framework includes
21
22 // Project includes
23 #include "lldb/lldb-public.h"
24 #include "lldb/lldb-enumerations.h"
25
26 #include "lldb/Core/ValueObject.h"
27 #include "lldb/Interpreter/ScriptInterpreterPython.h"
28 #include "lldb/Symbol/Type.h"
29
30 namespace lldb_private {
31     
32     class TypeSummaryImpl
33     {
34     public:
35         class Flags
36         {
37         public:
38             
39             Flags () :
40             m_flags (lldb::eTypeOptionCascade)
41             {}
42             
43             Flags (const Flags& other) :
44             m_flags (other.m_flags)
45             {}
46             
47             Flags (uint32_t value) :
48             m_flags (value)
49             {}
50             
51             Flags&
52             operator = (const Flags& rhs)
53             {
54                 if (&rhs != this)
55                     m_flags = rhs.m_flags;
56                 
57                 return *this;
58             }
59             
60             Flags&
61             operator = (const uint32_t& rhs)
62             {
63                 m_flags = rhs;
64                 return *this;
65             }
66             
67             Flags&
68             Clear()
69             {
70                 m_flags = 0;
71                 return *this;
72             }
73             
74             bool
75             GetCascades () const
76             {
77                 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
78             }
79             
80             Flags&
81             SetCascades (bool value = true)
82             {
83                 if (value)
84                     m_flags |= lldb::eTypeOptionCascade;
85                 else
86                     m_flags &= ~lldb::eTypeOptionCascade;
87                 return *this;
88             }
89             
90             bool
91             GetSkipPointers () const
92             {
93                 return (m_flags & lldb::eTypeOptionSkipPointers) == lldb::eTypeOptionSkipPointers;
94             }
95             
96             Flags&
97             SetSkipPointers (bool value = true)
98             {
99                 if (value)
100                     m_flags |= lldb::eTypeOptionSkipPointers;
101                 else
102                     m_flags &= ~lldb::eTypeOptionSkipPointers;
103                 return *this;
104             }
105             
106             bool
107             GetSkipReferences () const
108             {
109                 return (m_flags & lldb::eTypeOptionSkipReferences) == lldb::eTypeOptionSkipReferences;
110             }
111             
112             Flags&
113             SetSkipReferences (bool value = true)
114             {
115                 if (value)
116                     m_flags |= lldb::eTypeOptionSkipReferences;
117                 else
118                     m_flags &= ~lldb::eTypeOptionSkipReferences;
119                 return *this;
120             }
121             
122             bool
123             GetDontShowChildren () const
124             {
125                 return (m_flags & lldb::eTypeOptionHideChildren) == lldb::eTypeOptionHideChildren;
126             }
127             
128             Flags&
129             SetDontShowChildren (bool value = true)
130             {
131                 if (value)
132                     m_flags |= lldb::eTypeOptionHideChildren;
133                 else
134                     m_flags &= ~lldb::eTypeOptionHideChildren;
135                 return *this;
136             }
137             
138             bool
139             GetDontShowValue () const
140             {
141                 return (m_flags & lldb::eTypeOptionHideValue) == lldb::eTypeOptionHideValue;
142             }
143             
144             Flags&
145             SetDontShowValue (bool value = true)
146             {
147                 if (value)
148                     m_flags |= lldb::eTypeOptionHideValue;
149                 else
150                     m_flags &= ~lldb::eTypeOptionHideValue;
151                 return *this;
152             }
153             
154             bool
155             GetShowMembersOneLiner () const
156             {
157                 return (m_flags & lldb::eTypeOptionShowOneLiner) == lldb::eTypeOptionShowOneLiner;
158             }
159             
160             Flags&
161             SetShowMembersOneLiner (bool value = true)
162             {
163                 if (value)
164                     m_flags |= lldb::eTypeOptionShowOneLiner;
165                 else
166                     m_flags &= ~lldb::eTypeOptionShowOneLiner;
167                 return *this;
168             }
169             
170             bool
171             GetHideItemNames () const
172             {
173                 return (m_flags & lldb::eTypeOptionHideNames) == lldb::eTypeOptionHideNames;
174             }
175             
176             Flags&
177             SetHideItemNames (bool value = true)
178             {
179                 if (value)
180                     m_flags |= lldb::eTypeOptionHideNames;
181                 else
182                     m_flags &= ~lldb::eTypeOptionHideNames;
183                 return *this;
184             }
185             
186             uint32_t
187             GetValue ()
188             {
189                 return m_flags;
190             }
191             
192             void
193             SetValue (uint32_t value)
194             {
195                 m_flags = value;
196             }
197             
198         private:
199             uint32_t m_flags;
200         };
201         
202         typedef enum Type
203         {
204             eTypeUnknown,
205             eTypeString,
206             eTypeScript,
207             eTypeCallback
208         } Type;
209         
210         TypeSummaryImpl (const TypeSummaryImpl::Flags& flags);
211         
212         bool
213         Cascades () const
214         {
215             return m_flags.GetCascades();
216         }
217         bool
218         SkipsPointers () const
219         {
220             return m_flags.GetSkipPointers();
221         }
222         bool
223         SkipsReferences () const
224         {
225             return m_flags.GetSkipReferences();
226         }
227         
228         bool
229         DoesPrintChildren () const
230         {
231             return !m_flags.GetDontShowChildren();
232         }
233         
234         bool
235         DoesPrintValue () const
236         {
237             return !m_flags.GetDontShowValue();
238         }
239         
240         bool
241         IsOneLiner () const
242         {
243             return m_flags.GetShowMembersOneLiner();
244         }
245         
246         bool
247         HideNames () const
248         {
249             return m_flags.GetHideItemNames();
250         }
251         
252         void
253         SetCascades (bool value)
254         {
255             m_flags.SetCascades(value);
256         }
257         
258         void
259         SetSkipsPointers (bool value)
260         {
261             m_flags.SetSkipPointers(value);
262         }
263         
264         void
265         SetSkipsReferences (bool value)
266         {
267             m_flags.SetSkipReferences(value);
268         }
269         
270         void
271         SetDoesPrintChildren (bool value)
272         {
273             m_flags.SetDontShowChildren(!value);
274         }
275         
276         void
277         SetDoesPrintValue (bool value)
278         {
279             m_flags.SetDontShowValue(!value);
280         }
281         
282         void
283         SetIsOneLiner (bool value)
284         {
285             m_flags.SetShowMembersOneLiner(value);
286         }
287         
288         void
289         SetHideNames (bool value)
290         {
291             m_flags.SetHideItemNames(value);
292         }
293         
294         uint32_t
295         GetOptions ()
296         {
297             return m_flags.GetValue();
298         }
299         
300         void
301         SetOptions (uint32_t value)
302         {
303             m_flags.SetValue(value);
304         }
305         
306         virtual
307         ~TypeSummaryImpl ()
308         {
309         }
310         
311         // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for
312         // extended periods of time and we trust the ValueObject to stay around for as long as it is required
313         // for us to generate its summary
314         virtual bool
315         FormatObject (ValueObject *valobj,
316                       std::string& dest) = 0;
317         
318         virtual std::string
319         GetDescription () = 0;
320         
321         virtual bool
322         IsScripted () = 0;
323         
324         virtual Type
325         GetType () = 0;
326         
327         uint32_t&
328         GetRevision ()
329         {
330             return m_my_revision;
331         }
332         
333         typedef std::shared_ptr<TypeSummaryImpl> SharedPointer;
334         typedef bool(*SummaryCallback)(void*, ConstString, const lldb::TypeSummaryImplSP&);
335         typedef bool(*RegexSummaryCallback)(void*, lldb::RegularExpressionSP, const lldb::TypeSummaryImplSP&);
336         
337     protected:
338         uint32_t m_my_revision;
339         Flags m_flags;
340         
341     private:
342         DISALLOW_COPY_AND_ASSIGN(TypeSummaryImpl);
343     };
344     
345     // simple string-based summaries, using ${var to show data
346     struct StringSummaryFormat : public TypeSummaryImpl
347     {
348         std::string m_format;
349         
350         StringSummaryFormat(const TypeSummaryImpl::Flags& flags,
351                             const char* f);
352         
353         const char*
354         GetSummaryString () const
355         {
356             return m_format.c_str();
357         }
358         
359         void
360         SetSummaryString (const char* data)
361         {
362             if (data)
363                 m_format.assign(data);
364             else
365                 m_format.clear();
366         }
367         
368         virtual
369         ~StringSummaryFormat()
370         {
371         }
372         
373         virtual bool
374         FormatObject(ValueObject *valobj,
375                      std::string& dest);
376         
377         virtual std::string
378         GetDescription();
379         
380         virtual bool
381         IsScripted ()
382         {
383             return false;
384         }
385         
386         
387         virtual Type
388         GetType ()
389         {
390             return TypeSummaryImpl::eTypeString;
391         }
392         
393     private:
394         DISALLOW_COPY_AND_ASSIGN(StringSummaryFormat);
395     };
396     
397     // summaries implemented via a C++ function
398     struct CXXFunctionSummaryFormat : public TypeSummaryImpl
399     {
400         
401         // we should convert these to SBValue and SBStream if we ever cross
402         // the boundary towards the external world
403         typedef bool (*Callback)(ValueObject& valobj, Stream& dest);
404         
405         Callback m_impl;
406         std::string m_description;
407         
408         CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
409                                   Callback impl,
410                                   const char* description);
411         
412         Callback
413         GetBackendFunction () const
414         {
415             return m_impl;
416         }
417         
418         const char*
419         GetTextualInfo () const
420         {
421             return m_description.c_str();
422         }
423         
424         void
425         SetBackendFunction (Callback cb_func)
426         {
427             m_impl = cb_func;
428         }
429         
430         void
431         SetTextualInfo (const char* descr)
432         {
433             if (descr)
434                 m_description.assign(descr);
435             else
436                 m_description.clear();
437         }
438         
439         virtual
440         ~CXXFunctionSummaryFormat ()
441         {
442         }
443         
444         virtual bool
445         FormatObject (ValueObject *valobj,
446                       std::string& dest);
447         
448         virtual std::string
449         GetDescription ();
450         
451         virtual bool
452         IsScripted ()
453         {
454             return false;
455         }
456         
457         virtual Type
458         GetType ()
459         {
460             return TypeSummaryImpl::eTypeCallback;
461         }
462         
463         typedef std::shared_ptr<CXXFunctionSummaryFormat> SharedPointer;
464         
465     private:
466         DISALLOW_COPY_AND_ASSIGN(CXXFunctionSummaryFormat);
467     };
468     
469 #ifndef LLDB_DISABLE_PYTHON
470     
471     // Python-based summaries, running script code to show data
472     struct ScriptSummaryFormat : public TypeSummaryImpl
473     {
474         std::string m_function_name;
475         std::string m_python_script;
476         lldb::ScriptInterpreterObjectSP m_script_function_sp;
477         
478         ScriptSummaryFormat(const TypeSummaryImpl::Flags& flags,
479                             const char *function_name,
480                             const char* python_script = NULL);
481         
482         const char*
483         GetFunctionName () const
484         {
485             return m_function_name.c_str();
486         }
487         
488         const char*
489         GetPythonScript () const
490         {
491             return m_python_script.c_str();
492         }
493         
494         void
495         SetFunctionName (const char* function_name)
496         {
497             if (function_name)
498                 m_function_name.assign(function_name);
499             else
500                 m_function_name.clear();
501             m_python_script.clear();
502         }
503         
504         void
505         SetPythonScript (const char* script)
506         {
507             if (script)
508                 m_python_script.assign(script);
509             else
510                 m_python_script.clear();
511         }
512         
513         virtual
514         ~ScriptSummaryFormat ()
515         {
516         }
517         
518         virtual bool
519         FormatObject (ValueObject *valobj,
520                       std::string& dest);
521         
522         virtual std::string
523         GetDescription ();
524         
525         virtual bool
526         IsScripted ()
527         {
528             return true;
529         }
530         
531         virtual Type
532         GetType ()
533         {
534             return TypeSummaryImpl::eTypeScript;
535         }
536         
537         typedef std::shared_ptr<ScriptSummaryFormat> SharedPointer;
538         
539         
540     private:
541         DISALLOW_COPY_AND_ASSIGN(ScriptSummaryFormat);
542     };
543 #endif
544 } // namespace lldb_private
545
546 #endif  // lldb_TypeSummary_h_