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