]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnMIValueList.cpp
Update lldb to upstream trunk r242221.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnMIValueList.cpp
1 //===-- Platform.cpp --------------------------------------------*- 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 // In-house headers:
11 #include "MICmnMIValueList.h"
12 #include "MICmnResources.h"
13
14 //++ ------------------------------------------------------------------------------------
15 // Details: CMICmnMIValueList constructor.
16 // Type:    Method.
17 // Args:    vbValueTypeList - (R) True = yes value type list, false = result type list.
18 // Return:  None.
19 // Throws:  None.
20 //--
21 CMICmnMIValueList::CMICmnMIValueList(const bool vbValueTypeList)
22 {
23     m_strValue = "[]";
24 }
25
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmnMIValueList constructor.
28 //          Construct a results only list.
29 //          return MIstatus::failure.
30 // Type:    Method.
31 // Args:    vResult - (R) MI result object.
32 // Return:  None.
33 // Throws:  None.
34 //--
35 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValueResult &vResult)
36 {
37     m_strValue = vResult.GetString();
38     BuildList();
39     m_bJustConstructed = false;
40 }
41
42 //++ ------------------------------------------------------------------------------------
43 // Details: CMICmnMIValueList constructor.
44 //          Construct a value only list.
45 // Type:    Method.
46 // Args:    vValue  - (R) MI value object.
47 // Return:  None.
48 // Throws:  None.
49 //--
50 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValue &vValue)
51 {
52     m_strValue = vValue.GetString();
53     BuildList();
54     m_bJustConstructed = false;
55 }
56
57 //++ ------------------------------------------------------------------------------------
58 // Details: CMICmnMIValueList destructor.
59 // Type:    Overrideable.
60 // Args:    None.
61 // Return:  None.
62 // Throws:  None.
63 //--
64 CMICmnMIValueList::~CMICmnMIValueList(void)
65 {
66 }
67
68 //++ ------------------------------------------------------------------------------------
69 // Details: Build the result value's mandatory data part, one tuple
70 // Type:    Method.
71 // Args:    None.
72 // Return:  MIstatus::success - Functional succeeded.
73 //          MIstatus::failure - Functional failed.
74 // Throws:  None.
75 //--
76 bool
77 CMICmnMIValueList::BuildList(void)
78 {
79     const char *pFormat = "[%s]";
80     m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
81
82     return MIstatus::success;
83 }
84
85 //++ ------------------------------------------------------------------------------------
86 // Details: Add another MI result object to  the value list's of list is results.
87 //          Only result objects can be added to a list of result otherwise this function
88 //          will return MIstatus::failure.
89 // Type:    Method.
90 // Args:    vResult - (R) The MI result object.
91 // Return:  MIstatus::success - Functional succeeded.
92 //          MIstatus::failure - Functional failed.
93 // Throws:  None.
94 //--
95 bool
96 CMICmnMIValueList::Add(const CMICmnMIValueResult &vResult)
97 {
98     return BuildList(vResult);
99 }
100
101 //++ ------------------------------------------------------------------------------------
102 // Details: Add another MI value object to  the value list's of list is values.
103 //          Only values objects can be added to a list of values otherwise this function
104 //          will return MIstatus::failure.
105 // Type:    Method.
106 // Args:    vValue  - (R) The MI value object.
107 // Return:  MIstatus::success - Functional succeeded.
108 //          MIstatus::failure - Functional failed.
109 // Throws:  None.
110 //--
111 bool
112 CMICmnMIValueList::Add(const CMICmnMIValue &vValue)
113 {
114     return BuildList(vValue);
115 }
116
117 //++ ------------------------------------------------------------------------------------
118 // Details: Add another MI result object to  the value list's of list is results.
119 //          Only result objects can be added to a list of result otherwise this function
120 //          will return MIstatus::failure.
121 // Type:    Method.
122 // Args:    vResult - (R) The MI result object.
123 // Return:  MIstatus::success - Functional succeeded.
124 //          MIstatus::failure - Functional failed.
125 // Throws:  None.
126 //--
127 bool
128 CMICmnMIValueList::BuildList(const CMICmnMIValueResult &vResult)
129 {
130     // Clear out the default "<Invalid>" text
131     if (m_bJustConstructed)
132     {
133         m_bJustConstructed = false;
134         m_strValue = vResult.GetString();
135         return BuildList();
136     }
137
138     const CMIUtilString data(ExtractContentNoBrackets());
139     const char *pFormat = "[%s,%s]";
140     m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vResult.GetString().c_str());
141
142     return MIstatus::success;
143 }
144
145 //++ ------------------------------------------------------------------------------------
146 // Details: Add another MI value object to  the value list's of list is values.
147 //          Only values objects can be added to a list of values otherwise this function
148 //          will return MIstatus::failure.
149 // Type:    Method.
150 // Args:    vValue  - (R) The MI value object.
151 // Return:  MIstatus::success - Functional succeeded.
152 //          MIstatus::failure - Functional failed.
153 // Throws:  None.
154 //--
155 bool
156 CMICmnMIValueList::BuildList(const CMICmnMIValue &vValue)
157 {
158     // Clear out the default "<Invalid>" text
159     if (m_bJustConstructed)
160     {
161         m_bJustConstructed = false;
162         m_strValue = vValue.GetString();
163         return BuildList();
164     }
165
166     // Remove already present '[' and ']' from the start and end
167     m_strValue = m_strValue.Trim();
168     size_t len = m_strValue.size();
169     if ( (len > 1) && (m_strValue[0] == '[') && (m_strValue[len - 1] == ']') )
170         m_strValue = m_strValue.substr(1, len - 2);
171     const char *pFormat = "[%s,%s]";
172     m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(), vValue.GetString().c_str());
173
174     return MIstatus::success;
175 }
176
177 //++ ------------------------------------------------------------------------------------
178 // Details: Retrieve the contents of *this value object but without the outer most
179 //          brackets.
180 // Type:    Method.
181 // Args:    None.
182 // Return:  CMIUtilString - Data within the object.
183 // Throws:  None.
184 //--
185 CMIUtilString
186 CMICmnMIValueList::ExtractContentNoBrackets(void) const
187 {
188     CMIUtilString data(m_strValue);
189
190     if (data[0] == '[')
191     {
192         data = data.substr(1, data.length() - 1);
193     }
194     if (data[data.size() - 1] == ']')
195     {
196         data = data.substr(0, data.length() - 1);
197     }
198
199     return data;
200 }