]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/lldb-mi/MICmnMIValueTuple.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / tools / lldb-mi / MICmnMIValueTuple.cpp
1 //===-- MICmnMIValueTuple.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 //------------------------------------------------------------------------------------
15 // Details: CMICmnMIValueTuple constructor.
16 // Type:    Method.
17 // Args:    None.
18 // Return:  None.
19 // Throws:  None.
20 //--
21 CMICmnMIValueTuple::CMICmnMIValueTuple() : m_bSpaceAfterComma(false) {
22   m_strValue = "{}";
23 }
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   m_strValue = vResult.GetString();
36   BuildTuple();
37   m_bJustConstructed = false;
38 }
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,
46 //          false = no spaces used.
47 // Return:  None.
48 // Throws:  None.
49 //--
50 CMICmnMIValueTuple::CMICmnMIValueTuple(const CMICmnMIValueResult &vResult,
51                                        const bool vbUseSpacing)
52     : m_bSpaceAfterComma(vbUseSpacing) {
53   m_strValue = vResult.GetString();
54   BuildTuple();
55   m_bJustConstructed = false;
56 }
57
58 //++
59 //------------------------------------------------------------------------------------
60 // Details: CMICmnMIValueTuple destructor.
61 // Type:    Overrideable.
62 // Args:    None.
63 // Return:  None.
64 // Throws:  None.
65 //--
66 CMICmnMIValueTuple::~CMICmnMIValueTuple() {}
67
68 //++
69 //------------------------------------------------------------------------------------
70 // Details: Build the result value's mandatory data part, one tuple
71 // Type:    Method.
72 // Args:    None.
73 // Return:  None.
74 // Throws:  None.
75 //--
76 void CMICmnMIValueTuple::BuildTuple() {
77   const char *pFormat = "{%s}";
78   m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
79 }
80
81 //++
82 //------------------------------------------------------------------------------------
83 // Details: Add another MI result object to the value's list of tuples.
84 // Type:    Method.
85 // Args:    vResult - (R) The MI result object.
86 // Return:  None.
87 // Throws:  None.
88 //--
89 void CMICmnMIValueTuple::BuildTuple(const CMICmnMIValueResult &vResult) {
90   // Clear out the default "<Invalid>" text
91   if (m_bJustConstructed) {
92     m_bJustConstructed = false;
93     m_strValue = vResult.GetString();
94     BuildTuple();
95     return;
96   }
97
98   if (m_strValue[0] == '{') {
99     m_strValue = m_strValue.substr(1, m_strValue.size() - 1);
100   }
101   if (m_strValue[m_strValue.size() - 1] == '}') {
102     m_strValue = m_strValue.substr(0, m_strValue.size() - 1);
103   }
104
105   const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
106   m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(),
107                                      vResult.GetString().c_str());
108 }
109
110 //++
111 //------------------------------------------------------------------------------------
112 // Details: Add string value to the value's list of tuples.
113 // Type:    Method.
114 // Args:    vValue  - (R) The string object.
115 // Return:  None.
116 // Throws:  None.
117 //--
118 void CMICmnMIValueTuple::BuildTuple(const CMIUtilString &vValue) {
119   // Clear out the default "<Invalid>" text
120   if (m_bJustConstructed) {
121     m_bJustConstructed = false;
122     m_strValue = vValue;
123     BuildTuple();
124     return;
125   }
126
127   const CMIUtilString data(ExtractContentNoBrackets());
128   const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
129   m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vValue.c_str());
130 }
131
132 //++
133 //------------------------------------------------------------------------------------
134 // Details: Add another MI value object to  the value list's of list is values.
135 //          Only values objects can be added to a list of values otherwise this
136 //          function
137 //          will return MIstatus::failure.
138 // Type:    Method.
139 // Args:    vValue  - (R) The MI value object.
140 // Return:  None.
141 // Throws:  None.
142 //--
143 void CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult) {
144   BuildTuple(vResult);
145 }
146
147 //++
148 //------------------------------------------------------------------------------------
149 // Details: Add another MI value object to  the value list's of list is values.
150 //          Only values objects can be added to a list of values otherwise this
151 //          function
152 //          will return MIstatus::failure.
153 // Type:    Method.
154 // Args:    vValue          - (R) The MI value object.
155 //          vbUseSpacing    - (R) True = put space separators into the string,
156 //          false = no spaces used.
157 // Return:  None.
158 // Throws:  None.
159 //--
160 void CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult,
161                              const bool vbUseSpacing) {
162   m_bSpaceAfterComma = vbUseSpacing;
163   BuildTuple(vResult);
164 }
165
166 //++
167 //------------------------------------------------------------------------------------
168 // Details: Add another MI value object to  the value list's of list is values.
169 //          Only values objects can be added to a list of values otherwise this
170 //          function
171 //          will return MIstatus::failure.
172 // Type:    Method.
173 // Args:    vValue          - (R) The MI value object.
174 //          vbUseSpacing    - (R) True = put space separators into the string,
175 //          false = no spaces used.
176 // Return:  None.
177 // Throws:  None.
178 //--
179 void CMICmnMIValueTuple::Add(const CMICmnMIValueConst &vValue,
180                              const bool vbUseSpacing) {
181   m_bSpaceAfterComma = vbUseSpacing;
182   BuildTuple(vValue.GetString());
183 }
184
185 //++
186 //------------------------------------------------------------------------------------
187 // Details: Retrieve the contents of *this value object but without the outer
188 // most
189 //          brackets.
190 // Type:    Method.
191 // Args:    None.
192 // Return:  CMIUtilString - Data within the object.
193 // Throws:  None.
194 //--
195 CMIUtilString CMICmnMIValueTuple::ExtractContentNoBrackets() const {
196   CMIUtilString data(m_strValue);
197
198   if (data[0] == '{') {
199     data = data.substr(1, data.length() - 1);
200   }
201   if (data[data.size() - 1] == '}') {
202     data = data.substr(0, data.length() - 1);
203   }
204
205   return data;
206 }