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