]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnMIValueTuple.cpp
Update LLDB snapshot to upstream r241361
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnMIValueTuple.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 "MICmnMIValueTuple.h"
12
13 //++ ------------------------------------------------------------------------------------
14 // Details: CMICmnMIValueTuple constructor.
15 // Type:    Method.
16 // Args:    None.
17 // Return:  None.
18 // Throws:  None.
19 //--
20 CMICmnMIValueTuple::CMICmnMIValueTuple(void)
21     : m_bSpaceAfterComma(false)
22 {
23     m_strValue = "{}";
24 }
25
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmnMIValueTuple constructor.
28 // Type:    Method.
29 // Args:    vResult - (R) MI result object.
30 // Return:  None.
31 // Throws:  None.
32 //--
33 CMICmnMIValueTuple::CMICmnMIValueTuple(const CMICmnMIValueResult &vResult)
34     : m_bSpaceAfterComma(false)
35 {
36     m_strValue = vResult.GetString();
37     BuildTuple();
38     m_bJustConstructed = false;
39 }
40
41 //++ ------------------------------------------------------------------------------------
42 // Details: CMICmnMIValueTuple constructor.
43 // Type:    Method.
44 // Args:    vResult         - (R) MI result object.
45 //          vbUseSpacing    - (R) True = put space separators into the string, false = no spaces used.
46 // Return:  None.
47 // Throws:  None.
48 //--
49 CMICmnMIValueTuple::CMICmnMIValueTuple(const CMICmnMIValueResult &vResult, const bool vbUseSpacing)
50     : m_bSpaceAfterComma(vbUseSpacing)
51 {
52     m_strValue = vResult.GetString();
53     BuildTuple();
54     m_bJustConstructed = false;
55 }
56
57 //++ ------------------------------------------------------------------------------------
58 // Details: CMICmnMIValueTuple destructor.
59 // Type:    Overrideable.
60 // Args:    None.
61 // Return:  None.
62 // Throws:  None.
63 //--
64 CMICmnMIValueTuple::~CMICmnMIValueTuple(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 CMICmnMIValueTuple::BuildTuple(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's list of tuples.
87 // Type:    Method.
88 // Args:    vResult - (R) The MI result object.
89 // Return:  MIstatus::success - Functional succeeded.
90 //          MIstatus::failure - Functional failed.
91 // Throws:  None.
92 //--
93 bool
94 CMICmnMIValueTuple::BuildTuple(const CMICmnMIValueResult &vResult)
95 {
96     // Clear out the default "<Invalid>" text
97     if (m_bJustConstructed)
98     {
99         m_bJustConstructed = false;
100         m_strValue = vResult.GetString();
101         return BuildTuple();
102     }
103
104     if (m_strValue[0] == '{')
105     {
106         m_strValue = m_strValue.substr(1, m_strValue.size() - 1);
107     }
108     if (m_strValue[m_strValue.size() - 1] == '}')
109     {
110         m_strValue = m_strValue.substr(0, m_strValue.size() - 1);
111     }
112
113     const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
114     m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(), vResult.GetString().c_str());
115
116     return MIstatus::success;
117 }
118
119 //++ ------------------------------------------------------------------------------------
120 // Details: Add string value to the value's list of tuples.
121 // Type:    Method.
122 // Args:    vValue  - (R) The string object.
123 // Return:  MIstatus::success - Functional succeeded.
124 //          MIstatus::failure - Functional failed.
125 // Throws:  None.
126 //--
127 bool
128 CMICmnMIValueTuple::BuildTuple(const CMIUtilString &vValue)
129 {
130     // Clear out the default "<Invalid>" text
131     if (m_bJustConstructed)
132     {
133         m_bJustConstructed = false;
134         m_strValue = vValue;
135         return BuildTuple();
136     }
137
138     const CMIUtilString data(ExtractContentNoBrackets());
139     const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
140     m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vValue.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 CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult)
157 {
158     return BuildTuple(vResult);
159 }
160
161 //++ ------------------------------------------------------------------------------------
162 // Details: Add another MI value object to  the value list's of list is values.
163 //          Only values objects can be added to a list of values otherwise this function
164 //          will return MIstatus::failure.
165 // Type:    Method.
166 // Args:    vValue          - (R) The MI value object.
167 //          vbUseSpacing    - (R) True = put space separators into the string, false = no spaces used.
168 // Return:  MIstatus::success - Functional succeeded.
169 //          MIstatus::failure - Functional failed.
170 // Throws:  None.
171 //--
172 bool
173 CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult, const bool vbUseSpacing)
174 {
175     m_bSpaceAfterComma = vbUseSpacing;
176     return BuildTuple(vResult);
177 }
178
179 //++ ------------------------------------------------------------------------------------
180 // Details: Add another MI value object to  the value list's of list is values.
181 //          Only values objects can be added to a list of values otherwise this function
182 //          will return MIstatus::failure.
183 // Type:    Method.
184 // Args:    vValue          - (R) The MI value object.
185 //          vbUseSpacing    - (R) True = put space separators into the string, false = no spaces used.
186 // Return:  MIstatus::success - Functional succeeded.
187 //          MIstatus::failure - Functional failed.
188 // Throws:  None.
189 //--
190 bool
191 CMICmnMIValueTuple::Add(const CMICmnMIValueConst &vValue, const bool vbUseSpacing)
192 {
193     m_bSpaceAfterComma = vbUseSpacing;
194     return BuildTuple(vValue.GetString());
195 }
196
197 //++ ------------------------------------------------------------------------------------
198 // Details: Retrieve the contents of *this value object but without the outer most
199 //          brackets.
200 // Type:    Method.
201 // Args:    None.
202 // Return:  CMIUtilString - Data within the object.
203 // Throws:  None.
204 //--
205 CMIUtilString
206 CMICmnMIValueTuple::ExtractContentNoBrackets(void) const
207 {
208     CMIUtilString data(m_strValue);
209
210     if (data[0] == '{')
211     {
212         data = data.substr(1, data.length() - 1);
213     }
214     if (data[data.size() - 1] == '}')
215     {
216         data = data.substr(0, data.length() - 1);
217     }
218
219     return data;
220 }