From 8340fbb9c7bc9ea5f3b636ec3c449ff87d88fd9d Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Fri, 19 Jun 2020 19:16:27 +0200 Subject: [PATCH] [lldb] Reactivate Objective-C++ plugin Summary: Since commit 7b3ef05a37fef2f805d31f498d30198ddeeb1a0c the Objective-C++ plugin is dead code. That commit added Objective-C++ to the list of languages for which `Language::LanguageIsCPlusPlus` returns true. As the C++ language plugin also uses that method to figure out if it is responsible for a given language, the C++ plugin since then also became the plugin that we found when looking for a language plugin for Objective-C++. The only real fallout from that is that the source highlighting for Objective-C++ files never worked as we always found the C++ plugin which refuses to highlight files with Objective-C++ extensions. This patch just adds a special exception for Objective-C++ to the list of languages that are governed by the C++ plugin. Also adds a test that makes sure that we find the right plugin for all C language types and that the highlighting for `.mm` (Objective-C++) and `.m` (Objective-C) files works. I didn't revert 7b3ef05a37fef2f805d31f498d30198ddeeb1a0c as it does make sense to return true for Objective-C++ from `Language::LanguageIsCPlusPlus` (e.g., we currently check if we care about ODR violations by doing `if (Language::LanguageIsCPlusPlus(...))` and this should also work for Objective-C++). Fixes rdar://64420183 Reviewers: aprantl Reviewed By: aprantl Subscribers: mgorny, abidh, JDevlieghere Differential Revision: https://reviews.llvm.org/D82109 --- .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 4 +- .../Language/CLanguages/CLanguagesTest.cpp | 46 ++++++++++++++++++++++ lldb/unittests/Language/CLanguages/CMakeLists.txt | 8 ++++ lldb/unittests/Language/CMakeLists.txt | 1 + .../Language/Highlighting/HighlighterTest.cpp | 2 + 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lldb/unittests/Language/CLanguages/CLanguagesTest.cpp create mode 100644 lldb/unittests/Language/CLanguages/CMakeLists.txt diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 9d7d490..08e43ae 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -70,7 +70,9 @@ uint32_t CPlusPlusLanguage::GetPluginVersion() { return 1; } // Static Functions Language *CPlusPlusLanguage::CreateInstance(lldb::LanguageType language) { - if (Language::LanguageIsCPlusPlus(language)) + // Use plugin for C++ but not for Objective-C++ (which has its own plugin). + if (Language::LanguageIsCPlusPlus(language) && + language != eLanguageTypeObjC_plus_plus) return new CPlusPlusLanguage(); return nullptr; } diff --git a/lldb/unittests/Language/CLanguages/CLanguagesTest.cpp b/lldb/unittests/Language/CLanguages/CLanguagesTest.cpp new file mode 100644 index 0000000..c68bd56 --- /dev/null +++ b/lldb/unittests/Language/CLanguages/CLanguagesTest.cpp @@ -0,0 +1,46 @@ +//===-- CLanguagesTest.cpp ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" +#include "Plugins/Language/ObjC/ObjCLanguage.h" +#include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h" +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/lldb-enumerations.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +/// Returns the name of the LLDB plugin for the given language or a null +/// ConstString if there is no fitting plugin. +static ConstString GetPluginName(lldb::LanguageType language) { + Language *language_plugin = Language::FindPlugin(language); + if (language_plugin) + return language_plugin->GetPluginName(); + return ConstString(); +} + +TEST(CLanguages, LookupCLanguagesByLanguageType) { + SubsystemRAII langs; + + // There is no plugin to find for C. + EXPECT_EQ(Language::FindPlugin(lldb::eLanguageTypeC), nullptr); + EXPECT_EQ(Language::FindPlugin(lldb::eLanguageTypeC89), nullptr); + EXPECT_EQ(Language::FindPlugin(lldb::eLanguageTypeC99), nullptr); + EXPECT_EQ(Language::FindPlugin(lldb::eLanguageTypeC11), nullptr); + + EXPECT_EQ(GetPluginName(lldb::eLanguageTypeC_plus_plus), "cplusplus"); + EXPECT_EQ(GetPluginName(lldb::eLanguageTypeC_plus_plus_03), "cplusplus"); + EXPECT_EQ(GetPluginName(lldb::eLanguageTypeC_plus_plus_11), "cplusplus"); + EXPECT_EQ(GetPluginName(lldb::eLanguageTypeC_plus_plus_14), "cplusplus"); + + EXPECT_EQ(GetPluginName(lldb::eLanguageTypeObjC), "objc"); + + EXPECT_EQ(GetPluginName(lldb::eLanguageTypeObjC_plus_plus), "objcplusplus"); +} diff --git a/lldb/unittests/Language/CLanguages/CMakeLists.txt b/lldb/unittests/Language/CLanguages/CMakeLists.txt new file mode 100644 index 0000000..1361404 --- /dev/null +++ b/lldb/unittests/Language/CLanguages/CMakeLists.txt @@ -0,0 +1,8 @@ +add_lldb_unittest(LanguageCLanguagesTests + CLanguagesTest.cpp + + LINK_LIBS + lldbPluginCPlusPlusLanguage + lldbPluginObjCLanguage + lldbPluginObjCPlusPlusLanguage +) diff --git a/lldb/unittests/Language/CMakeLists.txt b/lldb/unittests/Language/CMakeLists.txt index 3a6e5de..3cca831 100644 --- a/lldb/unittests/Language/CMakeLists.txt +++ b/lldb/unittests/Language/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(CPlusPlus) +add_subdirectory(CLanguages) add_subdirectory(Highlighting) diff --git a/lldb/unittests/Language/Highlighting/HighlighterTest.cpp b/lldb/unittests/Language/Highlighting/HighlighterTest.cpp index 447dcce..7a2d716 100644 --- a/lldb/unittests/Language/Highlighting/HighlighterTest.cpp +++ b/lldb/unittests/Language/Highlighting/HighlighterTest.cpp @@ -58,6 +58,8 @@ TEST_F(HighlighterTest, HighlighterSelectionPath) { EXPECT_EQ(getName("a/dir.CC"), "clang"); EXPECT_EQ(getName("/a/dir.hpp"), "clang"); EXPECT_EQ(getName("header.h"), "clang"); + EXPECT_EQ(getName("foo.m"), "clang"); + EXPECT_EQ(getName("foo.mm"), "clang"); EXPECT_EQ(getName(""), "none"); EXPECT_EQ(getName("/dev/null"), "none"); -- 2.7.4