[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- LanguageCategory.cpp ----------------------------------------------===//
|
2015-09-02 02:22:39 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2015-09-02 02:22:39 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/DataFormatters/LanguageCategory.h"
|
|
|
|
|
|
|
|
#include "lldb/DataFormatters/FormatManager.h"
|
|
|
|
#include "lldb/DataFormatters/TypeCategory.h"
|
|
|
|
#include "lldb/DataFormatters/TypeFormat.h"
|
|
|
|
#include "lldb/DataFormatters/TypeSummary.h"
|
|
|
|
#include "lldb/DataFormatters/TypeSynthetic.h"
|
|
|
|
#include "lldb/Target/Language.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
LanguageCategory::LanguageCategory(lldb::LanguageType lang_type)
|
2015-09-17 02:28:11 +08:00
|
|
|
: m_category_sp(), m_hardcoded_formats(), m_hardcoded_summaries(),
|
2019-12-11 07:32:57 +08:00
|
|
|
m_hardcoded_synthetics(), m_format_cache(), m_enabled(false) {
|
2015-09-02 02:22:39 +08:00
|
|
|
if (Language *language_plugin = Language::FindPlugin(lang_type)) {
|
|
|
|
m_category_sp = language_plugin->GetFormatters();
|
2015-09-17 02:28:11 +08:00
|
|
|
m_hardcoded_formats = language_plugin->GetHardcodedFormats();
|
|
|
|
m_hardcoded_summaries = language_plugin->GetHardcodedSummaries();
|
|
|
|
m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics();
|
|
|
|
}
|
|
|
|
Enable();
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 05:22:03 +08:00
|
|
|
template<typename ImplSP>
|
2015-10-06 09:02:47 +08:00
|
|
|
bool LanguageCategory::Get(FormattersMatchData &match_data,
|
2019-12-11 05:22:03 +08:00
|
|
|
ImplSP &retval_sp) {
|
2015-09-02 02:22:39 +08:00
|
|
|
if (!m_category_sp)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
if (!IsEnabled())
|
2015-09-05 05:01:18 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache()) {
|
2019-12-11 05:22:03 +08:00
|
|
|
if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp))
|
|
|
|
return (bool)retval_sp;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
ValueObject &valobj(match_data.GetValueObject());
|
2019-12-11 07:20:49 +08:00
|
|
|
bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(),
|
2019-12-11 05:22:03 +08:00
|
|
|
match_data.GetMatchesVector(), retval_sp);
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache() &&
|
2019-12-11 05:22:03 +08:00
|
|
|
(!retval_sp || !retval_sp->NonCacheable())) {
|
|
|
|
m_format_cache.Set(match_data.GetTypeForCache(), retval_sp);
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-02-06 04:29:59 +08:00
|
|
|
namespace lldb_private {
|
|
|
|
|
2019-12-11 07:32:57 +08:00
|
|
|
/// Explicit instantiations for the three types.
|
2019-12-11 05:22:03 +08:00
|
|
|
/// \{
|
|
|
|
template bool
|
|
|
|
LanguageCategory::Get<lldb::TypeFormatImplSP>(FormattersMatchData &,
|
|
|
|
lldb::TypeFormatImplSP &);
|
|
|
|
template bool
|
|
|
|
LanguageCategory::Get<lldb::TypeSummaryImplSP>(FormattersMatchData &,
|
|
|
|
lldb::TypeSummaryImplSP &);
|
|
|
|
template bool
|
|
|
|
LanguageCategory::Get<lldb::SyntheticChildrenSP>(FormattersMatchData &,
|
|
|
|
lldb::SyntheticChildrenSP &);
|
|
|
|
/// \}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
auto &LanguageCategory::GetHardcodedFinder<lldb::TypeFormatImplSP>() {
|
|
|
|
return m_hardcoded_formats;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 05:22:03 +08:00
|
|
|
template <>
|
|
|
|
auto &LanguageCategory::GetHardcodedFinder<lldb::TypeSummaryImplSP>() {
|
|
|
|
return m_hardcoded_summaries;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 05:22:03 +08:00
|
|
|
template <>
|
|
|
|
auto &LanguageCategory::GetHardcodedFinder<lldb::SyntheticChildrenSP>() {
|
|
|
|
return m_hardcoded_synthetics;
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
|
|
|
|
2020-02-06 04:29:59 +08:00
|
|
|
} // namespace lldb_private
|
|
|
|
|
2019-12-11 05:22:03 +08:00
|
|
|
template <typename ImplSP>
|
2015-10-06 09:02:47 +08:00
|
|
|
bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr,
|
|
|
|
FormattersMatchData &match_data,
|
2019-12-11 05:22:03 +08:00
|
|
|
ImplSP &retval_sp) {
|
2015-09-17 02:28:11 +08:00
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
ValueObject &valobj(match_data.GetValueObject());
|
|
|
|
lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-12-11 05:22:03 +08:00
|
|
|
for (auto &candidate : GetHardcodedFinder<ImplSP>()) {
|
|
|
|
if (auto result = candidate(valobj, use_dynamic, fmt_mgr)) {
|
|
|
|
retval_sp = result;
|
2015-09-17 02:28:11 +08:00
|
|
|
break;
|
2019-12-11 05:22:03 +08:00
|
|
|
}
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
2019-12-11 05:22:03 +08:00
|
|
|
return (bool)retval_sp;
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 07:32:57 +08:00
|
|
|
/// Explicit instantiations for the three types.
|
2019-12-11 05:22:03 +08:00
|
|
|
/// \{
|
|
|
|
template bool LanguageCategory::GetHardcoded<lldb::TypeFormatImplSP>(
|
|
|
|
FormatManager &, FormattersMatchData &, lldb::TypeFormatImplSP &);
|
|
|
|
template bool LanguageCategory::GetHardcoded<lldb::TypeSummaryImplSP>(
|
|
|
|
FormatManager &, FormattersMatchData &, lldb::TypeSummaryImplSP &);
|
|
|
|
template bool LanguageCategory::GetHardcoded<lldb::SyntheticChildrenSP>(
|
|
|
|
FormatManager &, FormattersMatchData &, lldb::SyntheticChildrenSP &);
|
|
|
|
/// \}
|
2015-09-17 02:28:11 +08:00
|
|
|
|
2015-09-02 02:22:39 +08:00
|
|
|
lldb::TypeCategoryImplSP LanguageCategory::GetCategory() const {
|
|
|
|
return m_category_sp;
|
|
|
|
}
|
2015-09-05 05:01:18 +08:00
|
|
|
|
2015-12-15 10:20:48 +08:00
|
|
|
FormatCache &LanguageCategory::GetFormatCache() { return m_format_cache; }
|
|
|
|
|
2015-09-05 05:01:18 +08:00
|
|
|
void LanguageCategory::Enable() {
|
|
|
|
if (m_category_sp)
|
|
|
|
m_category_sp->Enable(true, TypeCategoryMap::Default);
|
2015-09-17 02:28:11 +08:00
|
|
|
m_enabled = true;
|
2015-09-05 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LanguageCategory::Disable() {
|
|
|
|
if (m_category_sp)
|
|
|
|
m_category_sp->Disable();
|
2015-09-17 02:28:11 +08:00
|
|
|
m_enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LanguageCategory::IsEnabled() { return m_enabled; }
|