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