Skip to content

Commit 8634de5

Browse files
committed
[lldb] add review changes
1 parent a0f2bcd commit 8634de5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ static bool IsTrivialBasename(const llvm::StringRef &basename) {
208208
return idx == basename.size();
209209
}
210210

211+
/// A context is trivial if an only if it matches this pattern.
212+
/// "^\s*([A-Za-z_:]*)\s*$".
213+
static bool IsTrivialContext(llvm::StringRef context) {
214+
// remove trailing or leading whitespace.
215+
context = context.trim();
216+
217+
const auto iter = context.find_if_not([](char current) {
218+
return std::isalnum(static_cast<unsigned char>(current)) ||
219+
current == '_' || current == ':';
220+
});
221+
return iter == llvm::StringRef::npos;
222+
}
223+
211224
/// Writes out the function name in 'full_name' to 'out_stream'
212225
/// but replaces each argument type with the variable name
213226
/// and the corresponding pretty-printed value
@@ -481,12 +494,7 @@ bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() {
481494
m_basename = full.substr(basename_begin, basename_end - basename_begin);
482495
}
483496

484-
// if the context has a white space it may have a return type.
485-
// e.g. `int foo::bar::func()` or `Type<int > foo::bar::func(int)`
486-
const bool no_whitespace =
487-
m_context.find_first_of(" \t\n\v\f\r") == llvm::StringRef::npos;
488-
489-
if (no_whitespace && IsTrivialBasename(m_basename)) {
497+
if (IsTrivialBasename(m_basename) && IsTrivialContext(m_context)) {
490498
return true;
491499
}
492500
// The C++ basename doesn't match our regular expressions so this can't

lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ TEST(CPlusPlusLanguage, MethodNameParsing) {
3030
{"foo::~bar(baz)", "", "foo", "~bar", "(baz)", "", "foo::~bar"},
3131
{"a::b::c::d(e,f)", "", "a::b::c", "d", "(e,f)", "", "a::b::c::d"},
3232
{"void f(int)", "void", "", "f", "(int)", "", "f"},
33-
{"int main()", "int", "", "main", "()", "", "main"},
33+
{"std::vector<int>foo::bar()", "std::vector<int>", "foo", "bar", "()", "",
34+
"foo::bar"},
3435
{"int foo::bar::func01(int a, double b)", "int", "foo::bar", "func01",
3536
"(int a, double b)", "", "foo::bar::func01"},
3637

0 commit comments

Comments
 (0)