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