Skip to content

Commit 717c4f1

Browse files
committed
[upstreaming] Split out Args.[h/cpp] modifications
1 parent 535d747 commit 717c4f1

File tree

5 files changed

+114
-92
lines changed

5 files changed

+114
-92
lines changed

lldb/include/lldb/Utility/Args.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ class Args {
247247
/// If the argument was originally quoted, put in the quote char here.
248248
void Unshift(llvm::StringRef arg_str, char quote_char = '\0');
249249

250-
bool GetOptionValueAsString(const char *option, std::string &value);
251-
252-
int GetOptionValuesAsStrings(const char *option,
253-
std::vector<std::string> &values);
254-
255250
// Clear the arguments.
256251
//
257252
// For re-setting or blanking out the list of arguments.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//===-- OptionParsing.h -----------------------------------------*- 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+
#ifndef LLDB_UTILITY_OPTION_PARSING_H
10+
#define LLDB_UTILITY_OPTION_PARSING_H
11+
12+
#include "lldb/Utility/Args.h"
13+
14+
namespace lldb_private {
15+
namespace OptionParsing {
16+
inline bool GetOptionValueAsString(Args &args, const char *option,
17+
std::string &value) {
18+
for (size_t ai = 0, ae = args.GetArgumentCount(); ai != ae; ++ai) {
19+
const char *arg = args.GetArgumentAtIndex(ai);
20+
const char *option_loc = strstr(arg, option);
21+
22+
const bool is_long_option = (option[0] == '-' && option[1] == '-');
23+
24+
if (option_loc == arg) {
25+
const char *after_option = option_loc + strlen(option);
26+
27+
switch (*after_option) {
28+
default:
29+
if (is_long_option) {
30+
continue;
31+
} else {
32+
value = after_option;
33+
return true;
34+
}
35+
break;
36+
case '=':
37+
value = after_option + 1;
38+
return true;
39+
case '\0': {
40+
const char *next_value = args.GetArgumentAtIndex(ai + 1);
41+
if (next_value) {
42+
value = next_value;
43+
return true;
44+
} else {
45+
return false;
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
return false;
53+
}
54+
55+
inline int GetOptionValuesAsStrings(Args &args, const char *option,
56+
std::vector<std::string> &values) {
57+
int ret = 0;
58+
59+
for (size_t ai = 0, ae = args.GetArgumentCount(); ai != ae; ++ai) {
60+
const char *arg = args.GetArgumentAtIndex(ai);
61+
const char *option_loc = strstr(arg, option);
62+
63+
const bool is_long_option = (option[0] == '-' && option[1] == '-');
64+
65+
if (option_loc == arg) {
66+
const char *after_option = option_loc + strlen(option);
67+
68+
switch (*after_option) {
69+
default:
70+
if (is_long_option) {
71+
continue;
72+
} else {
73+
values.push_back(after_option);
74+
++ret;
75+
}
76+
break;
77+
case '=':
78+
values.push_back(after_option + 1);
79+
++ret;
80+
break;
81+
case '\0': {
82+
const char *next_value = args.GetArgumentAtIndex(ai + 1);
83+
if (next_value) {
84+
values.push_back(next_value);
85+
++ret;
86+
++ai;
87+
break;
88+
} else {
89+
return ret;
90+
}
91+
}
92+
}
93+
}
94+
}
95+
96+
return ret;
97+
}
98+
99+
} // namespace OptionParsing
100+
} // namespace lldb_private
101+
102+
#endif // LLDB_UTILITY_OPTION_PARSING_H

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "lldb/Core/StreamFile.h"
2020
#include "lldb/Core/Value.h"
2121
#include "lldb/Utility/ArchSpec.h"
22+
#include "lldb/Utility/OptionParsing.h"
2223
#include "lldb/Utility/RegularExpression.h"
2324
#include "lldb/Utility/Scalar.h"
2425
#include "lldb/Utility/StreamString.h"
@@ -3043,7 +3044,8 @@ bool SymbolFileDWARF::GetCompileOption(const char *option, std::string &value,
30433044
if (strstr(flags, option)) {
30443045
Args compiler_args(flags);
30453046

3046-
return compiler_args.GetOptionValueAsString(option, value);
3047+
return OptionParsing::GetOptionValueAsString(compiler_args,
3048+
option, value);
30473049
}
30483050
}
30493051
}
@@ -3062,7 +3064,8 @@ bool SymbolFileDWARF::GetCompileOption(const char *option, std::string &value,
30623064
if (strstr(flags, option)) {
30633065
Args compiler_args(flags);
30643066

3065-
return compiler_args.GetOptionValueAsString(option, value);
3067+
return OptionParsing::GetOptionValueAsString(compiler_args,
3068+
option, value);
30663069
}
30673070
}
30683071
}
@@ -3093,7 +3096,8 @@ int SymbolFileDWARF::GetCompileOptions(const char *option,
30933096
if (strstr(flags, option)) {
30943097
Args compiler_args(flags);
30953098

3096-
return compiler_args.GetOptionValuesAsStrings(option, values);
3099+
return OptionParsing::GetOptionValuesAsStrings(compiler_args,
3100+
option, values);
30973101
}
30983102
}
30993103
}
@@ -3114,7 +3118,8 @@ int SymbolFileDWARF::GetCompileOptions(const char *option,
31143118
if (strstr(flags, option)) {
31153119
Args compiler_args(flags);
31163120

3117-
return compiler_args.GetOptionValuesAsStrings(option, values);
3121+
return OptionParsing::GetOptionValuesAsStrings(compiler_args,
3122+
option, values);
31183123
}
31193124
}
31203125
}

lldb/source/Target/SwiftLanguageRuntime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "lldb/Target/ThreadPlanRunToAddress.h"
7373
#include "lldb/Target/ThreadPlanStepInRange.h"
7474
#include "lldb/Target/ThreadPlanStepOverRange.h"
75+
#include "lldb/Utility/OptionParsing.h"
7576
#include "lldb/Utility/Status.h"
7677

7778
#include "lldb/Utility/CleanUp.h"
@@ -3401,7 +3402,8 @@ Status SwiftLanguageRuntime::SwiftExceptionPrecondition::ConfigurePrecondition(
34013402
Args &args) {
34023403
Status error;
34033404
std::vector<std::string> object_typenames;
3404-
args.GetOptionValuesAsStrings("exception-typename", object_typenames);
3405+
OptionParsing::GetOptionValuesAsStrings(args, "exception-typename",
3406+
object_typenames);
34053407
for (auto type_name : object_typenames)
34063408
AddTypeName(type_name.c_str());
34073409
return error;

lldb/source/Utility/Args.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -480,88 +480,6 @@ uint32_t Args::StringToGenericRegister(llvm::StringRef s) {
480480
return result;
481481
}
482482

483-
bool Args::GetOptionValueAsString(const char *option, std::string &value) {
484-
for (size_t ai = 0, ae = GetArgumentCount(); ai != ae; ++ai) {
485-
const char *arg = GetArgumentAtIndex(ai);
486-
const char *option_loc = strstr(arg, option);
487-
488-
const bool is_long_option = (option[0] == '-' && option[1] == '-');
489-
490-
if (option_loc == arg) {
491-
const char *after_option = option_loc + strlen(option);
492-
493-
switch (*after_option) {
494-
default:
495-
if (is_long_option) {
496-
continue;
497-
} else {
498-
value = after_option;
499-
return true;
500-
}
501-
break;
502-
case '=':
503-
value = after_option + 1;
504-
return true;
505-
case '\0': {
506-
const char *next_value = GetArgumentAtIndex(ai + 1);
507-
if (next_value) {
508-
value = next_value;
509-
return true;
510-
} else {
511-
return false;
512-
}
513-
}
514-
}
515-
}
516-
}
517-
518-
return false;
519-
}
520-
521-
int Args::GetOptionValuesAsStrings(const char *option,
522-
std::vector<std::string> &value) {
523-
int ret = 0;
524-
525-
for (size_t ai = 0, ae = GetArgumentCount(); ai != ae; ++ai) {
526-
const char *arg = GetArgumentAtIndex(ai);
527-
const char *option_loc = strstr(arg, option);
528-
529-
const bool is_long_option = (option[0] == '-' && option[1] == '-');
530-
531-
if (option_loc == arg) {
532-
const char *after_option = option_loc + strlen(option);
533-
534-
switch (*after_option) {
535-
default:
536-
if (is_long_option) {
537-
continue;
538-
} else {
539-
value.push_back(after_option);
540-
++ret;
541-
}
542-
break;
543-
case '=':
544-
value.push_back(after_option + 1);
545-
++ret;
546-
break;
547-
case '\0': {
548-
const char *next_value = GetArgumentAtIndex(ai + 1);
549-
if (next_value) {
550-
value.push_back(next_value);
551-
++ret;
552-
++ai;
553-
break;
554-
} else {
555-
return ret;
556-
}
557-
}
558-
}
559-
}
560-
}
561-
562-
return ret;
563-
}
564-
565483
void Args::EncodeEscapeSequences(const char *src, std::string &dst) {
566484
dst.clear();
567485
if (src) {

0 commit comments

Comments
 (0)