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