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