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