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