]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmdArgValPrintValues.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmdArgValPrintValues.cpp
1 //===-- MICmdArgValPrintValues.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 "MICmdArgValPrintValues.h"
11 #include "MICmdArgContext.h"
12
13 //++
14 // Details: CMICmdArgValPrintValues constructor.
15 // Type:    Method.
16 // Args:    None.
17 // Return:  None.
18 // Throws:  None.
19 //--
20 CMICmdArgValPrintValues::CMICmdArgValPrintValues() : m_nPrintValues(0) {}
21
22 //++
23 // Details: CMICmdArgValPrintValues constructor.
24 // Type:    Method.
25 // Args:    vrArgName       - (R) Argument's name to search by.
26 //          vbMandatory     - (R) True = Yes must be present, false = optional
27 //          argument.
28 //          vbHandleByCmd   - (R) True = Command processes *this option, false =
29 //          not handled.
30 // Return:  None.
31 // Throws:  None.
32 //--
33 CMICmdArgValPrintValues::CMICmdArgValPrintValues(const CMIUtilString &vrArgName,
34                                                  const bool vbMandatory,
35                                                  const bool vbHandleByCmd)
36     : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd),
37       m_nPrintValues(0) {}
38
39 //++
40 // Details: CMICmdArgValPrintValues destructor.
41 // Type:    Overridden.
42 // Args:    None.
43 // Return:  None.
44 // Throws:  None.
45 //--
46 CMICmdArgValPrintValues::~CMICmdArgValPrintValues() {}
47
48 //++
49 // Details: Parse the command's argument options string and try to extract the
50 // value *this
51 //          argument is looking for.
52 // Type:    Overridden.
53 // Args:    vwArgContext    - (RW) The command's argument options string.
54 // Return:  MIstatus::success - Functional succeeded.
55 //          MIstatus::failure - Functional failed.
56 // Throws:  None.
57 //--
58 bool CMICmdArgValPrintValues::Validate(CMICmdArgContext &vwArgContext) {
59   if (vwArgContext.IsEmpty())
60     return m_bMandatory ? MIstatus::failure : MIstatus::success;
61
62   const CMIUtilString strArg(vwArgContext.GetArgs()[0]);
63   if (IsArgPrintValues(strArg) && ExtractPrintValues(strArg)) {
64     m_bFound = true;
65     m_bValid = true;
66     m_argValue = GetPrintValues();
67     vwArgContext.RemoveArg(strArg);
68     return MIstatus::success;
69   }
70
71   return MIstatus::failure;
72 }
73
74 //++
75 // Details: Examine the string and determine if it is a valid string type
76 // argument.
77 // Type:    Method.
78 // Args:    vrTxt   - (R) Some text.
79 // Return:  bool    - True = yes valid arg, false = no.
80 // Throws:  None.
81 //--
82 bool CMICmdArgValPrintValues::IsArgPrintValues(
83     const CMIUtilString &vrTxt) const {
84   return (CMIUtilString::Compare(vrTxt, "0") ||
85           CMIUtilString::Compare(vrTxt, "--no-values") ||
86           CMIUtilString::Compare(vrTxt, "1") ||
87           CMIUtilString::Compare(vrTxt, "--all-values") ||
88           CMIUtilString::Compare(vrTxt, "2") ||
89           CMIUtilString::Compare(vrTxt, "--simple-values"));
90 }
91
92 //++
93 // Details: Extract the print-values from the print-values argument.
94 // Type:    Method.
95 // Args:    vrTxt   - (R) Some text.
96 // Return:  MIstatus::success - Functional succeeded.
97 //          MIstatus::failure - Functional failed.
98 // Throws:  None.
99 //--
100 bool CMICmdArgValPrintValues::ExtractPrintValues(const CMIUtilString &vrTxt) {
101   if (CMIUtilString::Compare(vrTxt, "0") ||
102       CMIUtilString::Compare(vrTxt, "--no-values"))
103     m_nPrintValues = 0;
104   else if (CMIUtilString::Compare(vrTxt, "1") ||
105            CMIUtilString::Compare(vrTxt, "--all-values"))
106     m_nPrintValues = 1;
107   else if (CMIUtilString::Compare(vrTxt, "2") ||
108            CMIUtilString::Compare(vrTxt, "--simple-values"))
109     m_nPrintValues = 2;
110   else
111     return MIstatus::failure;
112
113   return MIstatus::success;
114 }
115
116 //++
117 // Details: Retrieve the print-values found in the argument.
118 // Type:    Method.
119 // Args:    None.
120 // Return:  MIuint - The print-values.
121 // Throws:  None.
122 //--
123 MIuint CMICmdArgValPrintValues::GetPrintValues() const {
124   return m_nPrintValues;
125 }