]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValOptionShort.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValOptionShort.cpp
1 //===-- MICmdArgValOptionShort.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 "MICmdArgValOptionShort.h"
11 #include "MICmdArgContext.h"
12
13 //++
14 // Details: CMICmdArgValOptionShort constructor.
15 // Type:    Method.
16 // Args:    None.
17 // Return:  None.
18 // Throws:  None.
19 //--
20 CMICmdArgValOptionShort::CMICmdArgValOptionShort() {}
21
22 //++
23 // Details: CMICmdArgValOptionShort constructor.
24 // Type:    Method.
25 // Args:    vrArgName       - (R) Argument's name to search by.
26 //          vbMandatory     - (R) True = Yes must be present, false = optional
27 //          argument.
28 //          vbHandleByCmd   - (R) True = Command processes *this option, false =
29 //          not handled.
30 // Return:  None.
31 // Throws:  None.
32 //--
33 CMICmdArgValOptionShort::CMICmdArgValOptionShort(const CMIUtilString &vrArgName,
34                                                  const bool vbMandatory,
35                                                  const bool vbHandleByCmd)
36     : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd) {}
37
38 //++
39 // Details: CMICmdArgValOptionLong constructor.
40 // Type:    Method.
41 // Args:    vrArgName           - (R) Argument's name to search by.
42 //          vbMandatory         - (R) True = Yes must be present, false =
43 //          optional argument.
44 //          vbHandleByCmd       - (R) True = Command processes *this option,
45 //          false = not handled.
46 //          veType              - (R) The type of argument to look for and
47 //          create argument object of a certain type.
48 //          vnExpectingNOptions - (R) The number of options expected to read
49 //          following *this argument.
50 // Return:  None.
51 // Throws:  None.
52 //--
53 CMICmdArgValOptionShort::CMICmdArgValOptionShort(
54     const CMIUtilString &vrArgName, const bool vbMandatory,
55     const bool vbHandleByCmd, const ArgValType_e veType,
56     const MIuint vnExpectingNOptions)
57     : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd, veType,
58                              vnExpectingNOptions) {}
59
60 //++
61 // Details: CMICmdArgValOptionShort destructor.
62 // Type:    Overridden.
63 // Args:    None.
64 // Return:  None.
65 // Throws:  None.
66 //--
67 CMICmdArgValOptionShort::~CMICmdArgValOptionShort() {}
68
69 //++
70 // Details: Examine the string and determine if it is a valid short type option
71 // argument.
72 // Type:    Method.
73 // Args:    vrTxt   - (R) Some text.
74 // Return:  bool    - True = yes valid arg, false = no.
75 // Throws:  None.
76 //--
77 bool CMICmdArgValOptionShort::IsArgShortOption(
78     const CMIUtilString &vrTxt) const {
79   // Look for --someLongOption
80   MIint nPos = vrTxt.find("--");
81   if (nPos == 0)
82     return false;
83
84   // Look for -f short option
85   nPos = vrTxt.find('-');
86   if (nPos != 0)
87     return false;
88
89   if (vrTxt.length() > 2)
90     return false;
91
92   return true;
93 }
94
95 //++
96 // Details: Examine the string and determine if it is a valid short type option
97 // argument.
98 //          Long type argument looks like -f some short option.
99 // Type:    Overridden.
100 // Args:    vrTxt   - (R) Some text.
101 // Return:  bool    - True = yes valid arg, false = no.
102 // Throws:  None.
103 //--
104 bool CMICmdArgValOptionShort::IsArgOptionCorrect(
105     const CMIUtilString &vrTxt) const {
106   return IsArgShortOption(vrTxt);
107 }
108
109 //++
110 // Details: Does the argument name of the argument being parsed ATM match the
111 // name of
112 //          *this argument object.
113 // Type:    Overridden.
114 // Args:    vrTxt   - (R) Some text.
115 // Return:  bool    - True = yes arg name matched, false = no.
116 // Throws:  None.
117 //--
118 bool CMICmdArgValOptionShort::ArgNameMatch(const CMIUtilString &vrTxt) const {
119   const CMIUtilString strArg = vrTxt.substr(1);
120   return (strArg == GetName());
121 }