]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValListOfN.cpp
MFV r347136:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValListOfN.cpp
1 //===-- MICmdArgValListOfN.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 "MICmdArgValListOfN.h"
12 #include "MICmdArgContext.h"
13 #include "MICmdArgValFile.h"
14 #include "MICmdArgValNumber.h"
15 #include "MICmdArgValOptionLong.h"
16 #include "MICmdArgValOptionShort.h"
17 #include "MICmdArgValString.h"
18 #include "MICmdArgValThreadGrp.h"
19
20 //++
21 //------------------------------------------------------------------------------------
22 // Details: CMICmdArgValListOfN constructor.
23 // Type:    Method.
24 // Args:    None.
25 // Return:  None.
26 // Throws:  None.
27 //--
28 CMICmdArgValListOfN::CMICmdArgValListOfN() {}
29
30 //++
31 //------------------------------------------------------------------------------------
32 // Details: CMICmdArgValListOfN constructor.
33 // Type:    Method.
34 // Args:    vrArgName       - (R) Argument's name to search by.
35 //          vbMandatory     - (R) True = Yes must be present, false = optional
36 //          argument.
37 //          vbHandleByCmd   - (R) True = Command processes *this option, false =
38 //          not handled.
39 //          veType          - (R) The type of argument to look for and create
40 //          argument object of a certain type.
41 // Return:  None.
42 // Throws:  None.
43 //--
44 CMICmdArgValListOfN::CMICmdArgValListOfN(const CMIUtilString &vrArgName,
45                                          const bool vbMandatory,
46                                          const bool vbHandleByCmd,
47                                          const ArgValType_e veType)
48     : CMICmdArgValListBase(vrArgName, vbMandatory, vbHandleByCmd, veType) {}
49
50 //++
51 //------------------------------------------------------------------------------------
52 // Details: CMICmdArgValListOfN destructor.
53 // Type:    Overridden.
54 // Args:    None.
55 // Return:  None.
56 // Throws:  None.
57 //--
58 CMICmdArgValListOfN::~CMICmdArgValListOfN() {}
59
60 //++
61 //------------------------------------------------------------------------------------
62 // Details: Parse the command's argument options string and try to extract the
63 // list of
64 //          arguments based on the argument object type to look for.
65 // Type:    Overridden.
66 // Args:    vwArgContext    - (RW) The command's argument options string.
67 // Return:  MIstatus::success - Functional succeeded.
68 //          MIstatus::failure - Functional failed.
69 // Throws:  None.
70 //--
71 bool CMICmdArgValListOfN::Validate(CMICmdArgContext &vwArgContext) {
72   if (m_eArgType >= eArgValType_count) {
73     m_eArgType = eArgValType_invalid;
74     return MIstatus::failure;
75   }
76
77   if (vwArgContext.IsEmpty())
78     return m_bMandatory ? MIstatus::failure : MIstatus::success;
79
80   const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
81   if (IsListOfN(rArg) && CreateList(rArg)) {
82     m_bFound = true;
83     m_bValid = true;
84     vwArgContext.RemoveArg(rArg);
85     return MIstatus::success;
86   } else
87     return MIstatus::failure;
88 }
89
90 //++
91 //------------------------------------------------------------------------------------
92 // Details: Create list of argument objects each holding a value extract from
93 // the command
94 //          options line.
95 // Type:    Method.
96 // Args:    vrTxt   - (R) Some options text.
97 // Return:  bool -  True = yes valid arg, false = no.
98 // Throws:  None.
99 //--
100 bool CMICmdArgValListOfN::CreateList(const CMIUtilString &vrTxt) {
101   CMIUtilString::VecString_t vecOptions;
102   if ((m_eArgType == eArgValType_StringQuoted) ||
103       (m_eArgType == eArgValType_StringQuotedNumber) ||
104       (m_eArgType == eArgValType_StringQuotedNumberPath) ||
105       (m_eArgType == eArgValType_StringAnything)) {
106     if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
107       return MIstatus::failure;
108   } else if (vrTxt.Split(" ", vecOptions) == 0)
109     return MIstatus::failure;
110
111   CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
112   while (it != vecOptions.end()) {
113     const CMIUtilString &rOption = *it;
114     CMICmdArgValBase *pOption = CreationObj(rOption, m_eArgType);
115     if (pOption != nullptr)
116       m_argValue.push_back(pOption);
117     else
118       return MIstatus::failure;
119
120     // Next
121     ++it;
122   }
123
124   return MIstatus::success;
125 }
126
127 //++
128 //------------------------------------------------------------------------------------
129 // Details: Examine the string and determine if it is a valid string type
130 // argument.
131 // Type:    Method.
132 // Args:    vrTxt   - (R) Some text.
133 // Return:  bool -  True = yes valid arg, false = no.
134 // Throws:  None.
135 //--
136 bool CMICmdArgValListOfN::IsListOfN(const CMIUtilString &vrTxt) const {
137   CMIUtilString::VecString_t vecOptions;
138   if ((m_eArgType == eArgValType_StringQuoted) ||
139       (m_eArgType == eArgValType_StringQuotedNumber) ||
140       (m_eArgType == eArgValType_StringQuotedNumberPath) ||
141       (m_eArgType == eArgValType_StringAnything)) {
142     if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
143       return false;
144   } else if (vrTxt.Split(" ", vecOptions) == 0)
145     return false;
146
147   CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
148   while (it != vecOptions.end()) {
149     const CMIUtilString &rOption = *it;
150     if (!IsExpectedCorrectType(rOption, m_eArgType))
151       break;
152
153     // Next
154     ++it;
155   }
156
157   return true;
158 }
159
160 //++
161 //------------------------------------------------------------------------------------
162 // Details: Retrieve the list of CMICmdArgValBase derived option objects found
163 // following
164 //          *this long option argument. For example "list-thread-groups [
165 //          --recurse 1 ]"
166 //          where 1 is the list of expected option to follow.
167 // Type:    Method.
168 // Args:    None.
169 // Return:  CMICmdArgValListBase::VecArgObjPtr_t & -    List of options.
170 // Throws:  None.
171 //--
172 const CMICmdArgValListBase::VecArgObjPtr_t &
173 CMICmdArgValListOfN::GetExpectedOptions() const {
174   return m_argValue;
175 }