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:
Pavel Labath 2016-08-18 08:21:38 +00:00
parent 6ee4f905dc
commit 9361c439e8
5 changed files with 49 additions and 1 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -0,0 +1 @@
add_subdirectory(CPlusPlus)

View File

@ -0,0 +1,3 @@
add_lldb_unittest(LanguageCPlusPlusTests
CPlusPlusLanguageTest.cpp
)

View File

@ -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());
}
}