FormatClasses.h revision 263363
1//===-- FormatClasses.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_FormatClasses_h_
11#define lldb_FormatClasses_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/ClangASTType.h"
29#include "lldb/Symbol/Type.h"
30
31#include "lldb/DataFormatters/TypeFormat.h"
32#include "lldb/DataFormatters/TypeSummary.h"
33#include "lldb/DataFormatters/TypeSynthetic.h"
34
35namespace lldb_private {
36
37class TypeNameSpecifierImpl
38{
39public:
40    TypeNameSpecifierImpl() :
41    m_is_regex(false),
42    m_type()
43    {
44    }
45
46    TypeNameSpecifierImpl (const char* name, bool is_regex) :
47    m_is_regex(is_regex),
48    m_type()
49    {
50        if (name)
51            m_type.m_type_name.assign(name);
52    }
53
54    // if constructing with a given type, is_regex cannot be true since we are
55    // giving an exact type to match
56    TypeNameSpecifierImpl (lldb::TypeSP type) :
57    m_is_regex(false),
58    m_type()
59    {
60        if (type)
61        {
62            m_type.m_type_name.assign(type->GetName().GetCString());
63            m_type.m_type_pair.SetType(type);
64        }
65    }
66
67    TypeNameSpecifierImpl (ClangASTType type) :
68    m_is_regex(false),
69    m_type()
70    {
71        if (type.IsValid())
72        {
73            m_type.m_type_name.assign(type.GetConstTypeName().GetCString());
74            m_type.m_type_pair.SetType(type);
75        }
76    }
77
78    const char*
79    GetName()
80    {
81        if (m_type.m_type_name.size())
82            return m_type.m_type_name.c_str();
83        return NULL;
84    }
85
86    lldb::TypeSP
87    GetTypeSP ()
88    {
89        if (m_type.m_type_pair.IsValid())
90            return m_type.m_type_pair.GetTypeSP();
91        return lldb::TypeSP();
92    }
93
94    ClangASTType
95    GetClangASTType ()
96    {
97        if (m_type.m_type_pair.IsValid())
98            return m_type.m_type_pair.GetClangASTType();
99        return ClangASTType();
100    }
101
102    bool
103    IsRegex()
104    {
105        return m_is_regex;
106    }
107
108private:
109    bool m_is_regex;
110    // this works better than TypeAndOrName because the latter only wraps a TypeSP
111    // whereas TypePair can also be backed by a ClangASTType
112    struct TypeOrName
113    {
114        std::string m_type_name;
115        TypePair m_type_pair;
116    };
117    TypeOrName m_type;
118
119
120private:
121    DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl);
122};
123
124} // namespace lldb_private
125
126#endif	// lldb_FormatClasses_h_
127