]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnMIValueList.cpp
Merge ^/head r275118 through r275209.
[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 CMICmnMIValueList::BuildList( void )
89 {
90         const MIchar * pFormat = "[%s]";
91         m_strValue = CMIUtilString::Format( pFormat, m_strValue.c_str() );
92         
93         return MIstatus::success;
94 }
95
96 //++ ------------------------------------------------------------------------------------
97 // Details:     Add another MI result object to  the value list's of list is results. 
98 //                      Only result obejcts can be added to a list of result otherwise this function 
99 //                      will return MIstatus::failure.
100 // Type:        Method.
101 // Args:        vResult - (R) The MI result object.
102 // Return:      MIstatus::success - Functional succeeded.
103 //                      MIstatus::failure - Functional failed.
104 // Throws:      None.
105 //--
106 bool CMICmnMIValueList::Add( const CMICmnMIValueResult & vResult )
107 {
108         return BuildList( vResult );
109 }
110
111 //++ ------------------------------------------------------------------------------------
112 // Details:     Add another MI value object to  the value list's of list is values.
113 //                      Only values objects can be added to a list of values otherwise this function 
114 //                      will return MIstatus::failure.
115 // Type:        Method.
116 // Args:        vValue  - (R) The MI value object.
117 // Return:      MIstatus::success - Functional succeeded.
118 //                      MIstatus::failure - Functional failed.
119 // Throws:      None.
120 //--
121 bool CMICmnMIValueList::Add( const CMICmnMIValue & vValue )
122 {
123         return BuildList( vValue );
124 }
125
126 //++ ------------------------------------------------------------------------------------
127 // Details:     Add another MI result object to  the value list's of list is results. 
128 //                      Only result obejcts can be added to a list of result otherwise this function 
129 //                      will return MIstatus::failure.
130 // Type:        Method.
131 // Args:        vResult - (R) The MI result object.
132 // Return:      MIstatus::success - Functional succeeded.
133 //                      MIstatus::failure - Functional failed.
134 // Throws:      None.
135 //--
136 bool CMICmnMIValueList::BuildList( const CMICmnMIValueResult & vResult )
137 {
138         // Clear out the default "<Invalid>" text
139         if( m_bJustConstructed )
140         {
141                 m_bJustConstructed = false;
142                 m_strValue = vResult.GetString();
143                 return BuildList();
144         }
145
146         const CMIUtilString data( ExtractContentNoBrackets() );
147         const MIchar * pFormat = "[%s,%s]";
148         m_strValue = CMIUtilString::Format( pFormat, data.c_str(), vResult.GetString().c_str() );
149
150         return MIstatus::success;
151 }
152
153 //++ ------------------------------------------------------------------------------------
154 // Details:     Add another MI value object to  the value list's of list is values.
155 //                      Only values objects can be added to a list of values otherwise this function 
156 //                      will return MIstatus::failure.
157 // Type:        Method.
158 // Args:        vValue  - (R) The MI value object.
159 // Return:      MIstatus::success - Functional succeeded.
160 //                      MIstatus::failure - Functional failed.
161 // Throws:      None.
162 //--
163 bool CMICmnMIValueList::BuildList( const CMICmnMIValue & vValue )
164 {
165         // Clear out the default "<Invalid>" text
166         if( m_bJustConstructed )
167         {
168                 m_bJustConstructed = false;
169                 m_strValue = vValue.GetString();
170                 return BuildList();
171         }
172
173         const MIchar * pFormat = "[%s,%s]";
174         m_strValue = m_strValue.FindAndReplace( "[", "" );
175         m_strValue = m_strValue.FindAndReplace( "]", "" );      
176         m_strValue = CMIUtilString::Format( pFormat, m_strValue.c_str(), vValue.GetString().c_str() );
177
178         return MIstatus::success;
179 }
180
181 //++ ------------------------------------------------------------------------------------
182 // Details:     Retrieve the contents of *this value object but without the outer most 
183 //                      brackets.
184 // Type:        Method.
185 // Args:        None.
186 // Return:      CMIUtilString - Data within the object.
187 // Throws:      None.
188 //--
189 CMIUtilString CMICmnMIValueList::ExtractContentNoBrackets( void ) const
190 {
191         CMIUtilString data( m_strValue );
192
193         if( data[ 0 ] == '[' )
194         {
195                 data = data.substr( 1, data.length() - 1 );
196         }
197         if( data[ data.size() - 1 ] == ']' )
198         {
199                 data = data.substr( 0, data.length() - 1 );
200         }
201                 
202         return data;
203 }