]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValListBase.cpp
Merging ^/head r278916 through r279022.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValListBase.cpp
1 //===-- MICmdArgValListBase.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:        MICmdArgValListBase.cpp
12 //
13 // Overview:    CMICmdArgValListBase 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 "MICmdArgValListBase.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 #include "MICmdArgValConsume.h"
32
33 //++ ------------------------------------------------------------------------------------
34 // Details: CMICmdArgValListBase constructor.
35 // Type:    Method.
36 // Args:    None.
37 // Return:  None.
38 // Throws:  None.
39 //--
40 CMICmdArgValListBase::CMICmdArgValListBase(void)
41     : m_eArgType(eArgValType_invalid)
42 {
43 }
44
45 //++ ------------------------------------------------------------------------------------
46 // Details: CMICmdArgValListBase constructor.
47 // Type:    Method.
48 // Args:    vrArgName       - (R) Argument's name to search by.
49 //          vbMandatory     - (R) True = Yes must be present, false = optional argument.
50 //          vbHandleByCmd   - (R) True = Command processes *this option, false = not handled.
51 // Return:  None.
52 // Throws:  None.
53 //--
54 CMICmdArgValListBase::CMICmdArgValListBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
55     : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
56     , m_eArgType(eArgValType_invalid)
57 {
58 }
59
60 //++ ------------------------------------------------------------------------------------
61 // Details: CMICmdArgValListBase constructor.
62 // Type:    Method.
63 // Args:    vrArgName       - (R) Argument's name to search by.
64 //          vbMandatory     - (R) True = Yes must be present, false = optional argument.
65 //          vbHandleByCmd   - (R) True = Command processes *this option, false = not handled.
66 //          veType          - (R) The type of argument to look for and create argument object of a certain type.
67 // Return:  None.
68 // Throws:  None.
69 //--
70 CMICmdArgValListBase::CMICmdArgValListBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
71                                            const ArgValType_e veType)
72     : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
73     , m_eArgType(veType)
74 {
75 }
76
77 //++ ------------------------------------------------------------------------------------
78 // Details: CMICmdArgValListBase destructor.
79 // Type:    Overridden.
80 // Args:    None.
81 // Return:  None.
82 // Throws:  None.
83 //--
84 CMICmdArgValListBase::~CMICmdArgValListBase(void)
85 {
86     // Tidy up
87     Destroy();
88 }
89
90 //++ ------------------------------------------------------------------------------------
91 // Details: Tear down resources used by *this object.
92 // Type:    Method.
93 // Args:    None.
94 // Return:  None.
95 // Throws:  None.
96 //--
97 void
98 CMICmdArgValListBase::Destroy(void)
99 {
100     // Tidy up
101     VecArgObjPtr_t::const_iterator it = m_argValue.begin();
102     while (it != m_argValue.end())
103     {
104         CMICmdArgValBase *pArgObj = *it;
105         delete pArgObj;
106
107         // Next
108         ++it;
109     }
110     m_argValue.clear();
111 }
112
113 //++ ------------------------------------------------------------------------------------
114 // Details: Create an CMICmdArgValBase derived object matching the type specified
115 //          and put the option or argument's value inside it.
116 // Type:    Method.
117 // Args:    vrTxt   - (R) Text version the option or argument.
118 //          veType  - (R) The type of argument or option object to create.
119 // Return:  CMICmdArgValBase * - Option object holding the value.
120 //                              - NULL = Functional failed.
121 // Throws:  None.
122 //--
123 CMICmdArgValBase *
124 CMICmdArgValListBase::CreationObj(const CMIUtilString &vrTxt, const ArgValType_e veType) const
125 {
126     CMICmdArgValBase *pOptionObj = nullptr;
127     switch (veType)
128     {
129         case eArgValType_File:
130             pOptionObj = new CMICmdArgValFile();
131             break;
132         case eArgValType_Consume:
133             pOptionObj = new CMICmdArgValConsume();
134             break;
135         case eArgValType_Number:
136             pOptionObj = new CMICmdArgValNumber();
137             break;
138         case eArgValType_OptionLong:
139             pOptionObj = new CMICmdArgValOptionLong();
140             break;
141         case eArgValType_OptionShort:
142             pOptionObj = new CMICmdArgValOptionShort();
143             break;
144         case eArgValType_String:
145             pOptionObj = new CMICmdArgValString();
146             break;
147         case eArgValType_StringQuoted:
148             pOptionObj = new CMICmdArgValString(true, false, false);
149             break;
150         case eArgValType_StringQuotedNumber:
151             pOptionObj = new CMICmdArgValString(true, true, false);
152             break;
153         case eArgValType_StringQuotedNumberPath:
154             pOptionObj = new CMICmdArgValString(true, true, true);
155             break;
156         case eArgValType_StringAnything:
157             pOptionObj = new CMICmdArgValString(true);
158             break;
159         case eArgValType_ThreadGrp:
160             pOptionObj = new CMICmdArgValThreadGrp();
161             break;
162         default:
163             return nullptr;
164     }
165
166     CMICmdArgContext argCntxt(vrTxt);
167     if (!pOptionObj->Validate(argCntxt))
168         return nullptr;
169
170     return pOptionObj;
171 }
172
173 //++ ------------------------------------------------------------------------------------
174 // Details: Validate the option or argument is the correct type.
175 // Type:    Method.
176 // Args:    vrTxt   - (R) Text version the option or argument.
177 //          veType  - (R) The type of value to expect.
178 // Return:  bool    - True = Yes expected type present, False = no.
179 // Throws:  None.
180 //--
181 bool
182 CMICmdArgValListBase::IsExpectedCorrectType(const CMIUtilString &vrTxt, const ArgValType_e veType) const
183 {
184     bool bValid = false;
185     switch (veType)
186     {
187         case eArgValType_File:
188             bValid = CMICmdArgValFile().IsFilePath(vrTxt);
189             break;
190         case eArgValType_Consume:
191             bValid = CMICmdArgValConsume().IsOk();
192             break;
193         case eArgValType_Number:
194             bValid = CMICmdArgValNumber().IsArgNumber(vrTxt);
195             break;
196         case eArgValType_OptionLong:
197             bValid = CMICmdArgValOptionLong().IsArgLongOption(vrTxt);
198             break;
199         case eArgValType_OptionShort:
200             bValid = CMICmdArgValOptionShort().IsArgShortOption(vrTxt);
201             break;
202         case eArgValType_String:
203             bValid = CMICmdArgValString().IsStringArg(vrTxt);
204             break;
205         case eArgValType_StringQuoted:
206             bValid = CMICmdArgValString(true, false, false).IsStringArg(vrTxt);
207             break;
208         case eArgValType_StringQuotedNumber:
209             bValid = CMICmdArgValString(true, true, false).IsStringArg(vrTxt);
210             break;
211         case eArgValType_StringQuotedNumberPath:
212             bValid = CMICmdArgValString(true, true, true).IsStringArg(vrTxt);
213             break;
214         case eArgValType_StringAnything:
215             bValid = CMICmdArgValString(true).IsStringArg(vrTxt);
216             break;
217         case eArgValType_ThreadGrp:
218             bValid = CMICmdArgValThreadGrp().IsArgThreadGrp(vrTxt);
219             break;
220         default:
221             return false;
222     }
223
224     return bValid;
225 }