forked from OSchip/llvm-project
Fix parsing of complicated C++ names
Summary: CPlusPlusLanguage::MethodName was not correctly parsing templated functions whose demangled name included the return type -- the space before the function name was included in the "context" and the context itself was not terminated correctly due to a misuse of the substr function (second argument is length, not the end position). Fix that and add a regression test. Reviewers: clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D23608 llvm-svn: 279038
This commit is contained in:
parent
6ee4f905dc
commit
9361c439e8
|
@ -220,6 +220,8 @@ CPlusPlusLanguage::MethodName::Parse()
|
|||
context_start = full.rfind(' ', template_start);
|
||||
if (context_start == llvm::StringRef::npos)
|
||||
context_start = 0;
|
||||
else
|
||||
++context_start;
|
||||
|
||||
context_end = full.rfind(':', template_start);
|
||||
if (context_end == llvm::StringRef::npos || context_end < context_start)
|
||||
|
@ -240,7 +242,7 @@ CPlusPlusLanguage::MethodName::Parse()
|
|||
else
|
||||
{
|
||||
if (context_start < context_end)
|
||||
m_context = full.substr(context_start, context_end - 1);
|
||||
m_context = full.substr(context_start, context_end - 1 - context_start);
|
||||
const size_t basename_begin = context_end + 1;
|
||||
m_basename = full.substr(basename_begin, basename_end - basename_begin);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ add_subdirectory(Editline)
|
|||
add_subdirectory(Expression)
|
||||
add_subdirectory(Host)
|
||||
add_subdirectory(Interpreter)
|
||||
add_subdirectory(Language)
|
||||
add_subdirectory(Process)
|
||||
add_subdirectory(ScriptInterpreter)
|
||||
add_subdirectory(Symbol)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
add_subdirectory(CPlusPlus)
|
|
@ -0,0 +1,3 @@
|
|||
add_lldb_unittest(LanguageCPlusPlusTests
|
||||
CPlusPlusLanguageTest.cpp
|
||||
)
|
|
@ -0,0 +1,41 @@
|
|||
//===-- CPlusPlusLanguageTest.cpp -------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
||||
|
||||
using namespace lldb_private;
|
||||
|
||||
TEST(CPlusPlusLanguage, MethodName)
|
||||
{
|
||||
struct TestCase {
|
||||
std::string input;
|
||||
std::string context, basename, arguments, qualifiers, scope_qualified_name;
|
||||
};
|
||||
|
||||
TestCase test_cases[] = {{"foo::bar(baz)", "foo", "bar", "(baz)", "", "foo::bar"},
|
||||
{"std::basic_ostream<char, std::char_traits<char> >& "
|
||||
"std::operator<<<std::char_traits<char> >"
|
||||
"(std::basic_ostream<char, std::char_traits<char> >&, char const*)",
|
||||
"std", "operator<<<std::char_traits<char> >",
|
||||
"(std::basic_ostream<char, std::char_traits<char> >&, char const*)", "",
|
||||
"std::operator<<<std::char_traits<char> >"}};
|
||||
|
||||
for (const auto &test: test_cases)
|
||||
{
|
||||
CPlusPlusLanguage::MethodName method(ConstString(test.input));
|
||||
EXPECT_TRUE(method.IsValid());
|
||||
EXPECT_EQ(test.context, method.GetContext());
|
||||
EXPECT_EQ(test.basename, method.GetBasename());
|
||||
EXPECT_EQ(test.arguments, method.GetArguments());
|
||||
EXPECT_EQ(test.qualifiers, method.GetQualifiers());
|
||||
EXPECT_EQ(test.scope_qualified_name, method.GetScopeQualifiedName());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue