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