]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmnMIValueList.cpp
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmnMIValueList.cpp
1 //===-- MICmnMIValueList.cpp ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // In-house headers:
10 #include "MICmnMIValueList.h"
11 #include "MICmnResources.h"
12
13 //++
14 // Details: CMICmnMIValueList constructor.
15 // Type:    Method.
16 // Args:    vbValueTypeList - (R) True = yes value type list, false = result
17 // type list.
18 // Return:  None.
19 // Throws:  None.
20 //--
21 CMICmnMIValueList::CMICmnMIValueList(const bool vbValueTypeList) {
22   m_strValue = "[]";
23 }
24
25 //++
26 // Details: CMICmnMIValueList constructor.
27 //          Construct a results only list.
28 //          return MIstatus::failure.
29 // Type:    Method.
30 // Args:    vResult - (R) MI result object.
31 // Return:  None.
32 // Throws:  None.
33 //--
34 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValueResult &vResult) {
35   m_strValue = vResult.GetString();
36   BuildList();
37   m_bJustConstructed = false;
38 }
39
40 //++
41 // Details: CMICmnMIValueList constructor.
42 //          Construct a value only list.
43 // Type:    Method.
44 // Args:    vValue  - (R) MI value object.
45 // Return:  None.
46 // Throws:  None.
47 //--
48 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValue &vValue) {
49   m_strValue = vValue.GetString();
50   BuildList();
51   m_bJustConstructed = false;
52 }
53
54 //++
55 // Details: CMICmnMIValueList destructor.
56 // Type:    Overrideable.
57 // Args:    None.
58 // Return:  None.
59 // Throws:  None.
60 //--
61 CMICmnMIValueList::~CMICmnMIValueList() {}
62
63 //++
64 // Details: Build the result value's mandatory data part, one tuple
65 // Type:    Method.
66 // Args:    None.
67 // Return:  None.
68 // Throws:  None.
69 //--
70 void CMICmnMIValueList::BuildList() {
71   const char *pFormat = "[%s]";
72   m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
73 }
74
75 //++
76 // Details: Add another MI result object to  the value list's of list is
77 // results.
78 //          Only result objects can be added to a list of result otherwise this
79 //          function
80 //          will return MIstatus::failure.
81 // Type:    Method.
82 // Args:    vResult - (R) The MI result object.
83 // Return:  None.
84 // Throws:  None.
85 //--
86 void CMICmnMIValueList::Add(const CMICmnMIValueResult &vResult) {
87   BuildList(vResult);
88 }
89
90 //++
91 // Details: Add another MI value object to  the value list's of list is values.
92 //          Only values objects can be added to a list of values otherwise this
93 //          function
94 //          will return MIstatus::failure.
95 // Type:    Method.
96 // Args:    vValue  - (R) The MI value object.
97 // Return:  None.
98 // Throws:  None.
99 //--
100 void CMICmnMIValueList::Add(const CMICmnMIValue &vValue) { BuildList(vValue); }
101
102 //++
103 // Details: Add another MI result object to  the value list's of list is
104 // results.
105 //          Only result objects can be added to a list of result otherwise this
106 //          function
107 //          will return MIstatus::failure.
108 // Type:    Method.
109 // Args:    vResult - (R) The MI result object.
110 // Return:  None.
111 // Throws:  None.
112 //--
113 void CMICmnMIValueList::BuildList(const CMICmnMIValueResult &vResult) {
114   // Clear out the default "<Invalid>" text
115   if (m_bJustConstructed) {
116     m_bJustConstructed = false;
117     m_strValue = vResult.GetString();
118     BuildList();
119     return;
120   }
121
122   const CMIUtilString data(ExtractContentNoBrackets());
123   const char *pFormat = "[%s,%s]";
124   m_strValue =
125       CMIUtilString::Format(pFormat, data.c_str(), vResult.GetString().c_str());
126 }
127
128 //++
129 // Details: Add another MI value object to  the value list's of list is values.
130 //          Only values objects can be added to a list of values otherwise this
131 //          function
132 //          will return MIstatus::failure.
133 // Type:    Method.
134 // Args:    vValue  - (R) The MI value object.
135 // Return:  None.
136 // Throws:  None.
137 //--
138 void CMICmnMIValueList::BuildList(const CMICmnMIValue &vValue) {
139   // Clear out the default "<Invalid>" text
140   if (m_bJustConstructed) {
141     m_bJustConstructed = false;
142     m_strValue = vValue.GetString();
143     BuildList();
144     return;
145   }
146
147   // Remove already present '[' and ']' from the start and end
148   m_strValue = m_strValue.Trim();
149   size_t len = m_strValue.size();
150   if ((len > 1) && (m_strValue[0] == '[') && (m_strValue[len - 1] == ']'))
151     m_strValue = m_strValue.substr(1, len - 2);
152   const char *pFormat = "[%s,%s]";
153   m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(),
154                                      vValue.GetString().c_str());
155 }
156
157 //++
158 // Details: Retrieve the contents of *this value object but without the outer
159 // most
160 //          brackets.
161 // Type:    Method.
162 // Args:    None.
163 // Return:  CMIUtilString - Data within the object.
164 // Throws:  None.
165 //--
166 CMIUtilString CMICmnMIValueList::ExtractContentNoBrackets() const {
167   CMIUtilString data(m_strValue);
168
169   if (data[0] == '[') {
170     data = data.substr(1, data.length() - 1);
171   }
172   if (data[data.size() - 1] == ']') {
173     data = data.substr(0, data.length() - 1);
174   }
175
176   return data;
177 }