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