]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnMIValueResult.cpp
MFV r348537: 8601 memory leak in get_special_prop()
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnMIValueResult.cpp
1 //===-- MICmnMIValueResult.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 "MICmnMIValueResult.h"
12 #include "MICmnResources.h"
13
14 // Instantiations:
15 const CMIUtilString CMICmnMIValueResult::ms_constStrEqual("=");
16
17 //++
18 //------------------------------------------------------------------------------------
19 // Details: CMICmnMIValueResult constructor.
20 // Type:    Method.
21 // Args:    None.
22 // Return:  None.
23 // Throws:  None.
24 //--
25 CMICmnMIValueResult::CMICmnMIValueResult() : m_bEmptyConstruction(true) {}
26
27 //++
28 //------------------------------------------------------------------------------------
29 // Details: CMICmnMIValueResult constructor.
30 // Type:    Method.
31 // Args:    vrVariable  - (R) MI value's name.
32 //          vrValue     - (R) The MI value.
33 // Return:  None.
34 // Throws:  None.
35 //--
36 CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
37                                          const CMICmnMIValue &vrValue)
38     : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
39       m_bEmptyConstruction(false), m_bUseSpacing(false) {
40   BuildResult();
41 }
42
43 //++
44 //------------------------------------------------------------------------------------
45 // Details: CMICmnMIValueResult constructor.
46 // Type:    Method.
47 // Args:    vrVariable      - (R) MI value's name.
48 //          vrValue         - (R) The MI value.
49 //          vbUseSpacing    - (R) True = put space separators into the string,
50 //          false = no spaces used.
51 // Return:  None.
52 // Throws:  None.
53 //--
54 CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
55                                          const CMICmnMIValue &vrValue,
56                                          const bool vbUseSpacing)
57     : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
58       m_bEmptyConstruction(false), m_bUseSpacing(vbUseSpacing) {
59   BuildResult();
60 }
61
62 //++
63 //------------------------------------------------------------------------------------
64 // Details: CMICmnMIValueResult destructor.
65 // Type:    Overrideable.
66 // Args:    None.
67 // Return:  None.
68 // Throws:  None.
69 //--
70 CMICmnMIValueResult::~CMICmnMIValueResult() {}
71
72 //++
73 //------------------------------------------------------------------------------------
74 // Details: Build the MI value result string.
75 // Type:    Method.
76 // Args:    None.
77 // Return:  None.
78 // Throws:  None.
79 //--
80 void CMICmnMIValueResult::BuildResult() {
81   const char *pFormat = m_bUseSpacing ? "%s %s %s" : "%s%s%s";
82   m_strValue = CMIUtilString::Format(pFormat, m_strPartVariable.c_str(),
83                                      ms_constStrEqual.c_str(),
84                                      m_partMIValue.GetString().c_str());
85 }
86
87 //++
88 //------------------------------------------------------------------------------------
89 // Details: Build the MI value result string.
90 // Type:    Method.
91 // Args:    vrVariable  - (R) MI value's name.
92 //          vrValue     - (R) The MI value.
93 // Return:  None.
94 // Throws:  None.
95 //--
96 void CMICmnMIValueResult::BuildResult(const CMIUtilString &vVariable,
97                                       const CMICmnMIValue &vValue) {
98   const char *pFormat = m_bUseSpacing ? "%s, %s %s %s" : "%s,%s%s%s";
99   m_strValue = CMIUtilString::Format(
100       pFormat, m_strValue.c_str(), vVariable.c_str(), ms_constStrEqual.c_str(),
101       vValue.GetString().c_str());
102 }
103
104 //++
105 //------------------------------------------------------------------------------------
106 // Details: Append another MI value object to *this MI value result.
107 // Type:    Method.
108 // Args:    vrVariable  - (R) MI value's name.
109 //          vrValue     - (R) The MI value.
110 // Return:  MIstatus::success - Functional succeeded.
111 //          MIstatus::failure - Functional failed.
112 // Throws:  None.
113 //--
114 void CMICmnMIValueResult::Add(const CMIUtilString &vrVariable,
115                               const CMICmnMIValue &vrValue) {
116   if (!m_bEmptyConstruction)
117     BuildResult(vrVariable, vrValue);
118   else {
119     m_bEmptyConstruction = false;
120     m_strPartVariable = vrVariable;
121     m_partMIValue = vrValue;
122     BuildResult();
123   }
124 }