2015-09-02 02:22:39 +08:00
|
|
|
//===-- LanguageCategory.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/DataFormatters/LanguageCategory.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#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/DataFormatters/TypeValidator.h"
|
|
|
|
#include "lldb/Target/Language.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
LanguageCategory::LanguageCategory (lldb::LanguageType lang_type) :
|
|
|
|
m_category_sp(),
|
2015-09-17 02:28:11 +08:00
|
|
|
m_hardcoded_formats(),
|
|
|
|
m_hardcoded_summaries(),
|
|
|
|
m_hardcoded_synthetics(),
|
|
|
|
m_hardcoded_validators(),
|
|
|
|
m_format_cache(),
|
|
|
|
m_enabled(false)
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
|
|
|
if (Language* language_plugin = Language::FindPlugin(lang_type))
|
2015-09-17 02:28:11 +08:00
|
|
|
{
|
2015-09-02 02:22:39 +08:00
|
|
|
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();
|
|
|
|
m_hardcoded_validators = language_plugin->GetHardcodedValidators();
|
|
|
|
}
|
|
|
|
Enable();
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::Get (FormattersMatchData& match_data,
|
2015-09-02 02:22:39 +08:00
|
|
|
lldb::TypeFormatImplSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!m_category_sp)
|
|
|
|
return false;
|
2015-09-05 05:01:18 +08:00
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
if (!IsEnabled())
|
2015-09-05 05:01:18 +08:00
|
|
|
return false;
|
2015-09-02 02:22:39 +08:00
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache())
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
if (m_format_cache.GetFormat(match_data.GetTypeForCache(), format_sp))
|
2015-09-15 06:18:32 +08:00
|
|
|
return format_sp.get() != nullptr;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
|
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
|
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp);
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::Get (FormattersMatchData& match_data,
|
2015-09-02 02:22:39 +08:00
|
|
|
lldb::TypeSummaryImplSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!m_category_sp)
|
|
|
|
return false;
|
2015-09-05 05:01:18 +08:00
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
if (!IsEnabled())
|
2015-09-05 05:01:18 +08:00
|
|
|
return false;
|
2015-09-02 02:22:39 +08:00
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache())
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
if (m_format_cache.GetSummary(match_data.GetTypeForCache(), format_sp))
|
2015-09-15 06:18:32 +08:00
|
|
|
return format_sp.get() != nullptr;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
|
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
|
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp);
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::Get (FormattersMatchData& match_data,
|
2015-09-02 02:22:39 +08:00
|
|
|
lldb::SyntheticChildrenSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!m_category_sp)
|
|
|
|
return false;
|
2015-09-05 05:01:18 +08:00
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
if (!IsEnabled())
|
2015-09-05 05:01:18 +08:00
|
|
|
return false;
|
2015-09-02 02:22:39 +08:00
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache())
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), format_sp))
|
2015-09-15 06:18:32 +08:00
|
|
|
return format_sp.get() != nullptr;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
|
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
|
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp);
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::Get (FormattersMatchData& match_data,
|
2015-09-02 02:22:39 +08:00
|
|
|
lldb::TypeValidatorImplSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!m_category_sp)
|
|
|
|
return false;
|
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
if (!IsEnabled())
|
2015-09-05 05:01:18 +08:00
|
|
|
return false;
|
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache())
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
if (m_format_cache.GetValidator(match_data.GetTypeForCache(), format_sp))
|
2015-09-15 06:18:32 +08:00
|
|
|
return format_sp.get() != nullptr;
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
|
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
|
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-02 02:22:39 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp);
|
2015-09-02 02:22:39 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
|
|
|
|
FormattersMatchData& match_data,
|
2015-09-17 02:28:11 +08:00
|
|
|
lldb::TypeFormatImplSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
|
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
for (auto& candidate : m_hardcoded_formats)
|
|
|
|
{
|
|
|
|
if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
|
|
|
|
break;
|
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-17 02:28:11 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp);
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
|
|
|
return format_sp.get() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
|
|
|
|
FormattersMatchData& match_data,
|
2015-09-17 02:28:11 +08:00
|
|
|
lldb::TypeSummaryImplSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
|
|
|
|
|
2015-09-17 02:28:11 +08:00
|
|
|
for (auto& candidate : m_hardcoded_summaries)
|
|
|
|
{
|
|
|
|
if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
|
|
|
|
break;
|
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-17 02:28:11 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp);
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
|
|
|
return format_sp.get() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
|
|
|
|
FormattersMatchData& match_data,
|
2015-09-17 02:28:11 +08:00
|
|
|
lldb::SyntheticChildrenSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
|
2015-09-17 02:28:11 +08:00
|
|
|
|
|
|
|
for (auto& candidate : m_hardcoded_synthetics)
|
|
|
|
{
|
|
|
|
if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
|
|
|
|
break;
|
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-17 02:28:11 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp);
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
|
|
|
return format_sp.get() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-10-06 09:02:47 +08:00
|
|
|
LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
|
|
|
|
FormattersMatchData& match_data,
|
2015-09-17 02:28:11 +08:00
|
|
|
lldb::TypeValidatorImplSP& format_sp)
|
|
|
|
{
|
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
|
|
|
|
2015-10-06 09:02:47 +08:00
|
|
|
ValueObject& valobj(match_data.GetValueObject());
|
|
|
|
lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
|
2015-09-17 02:28:11 +08:00
|
|
|
|
|
|
|
for (auto& candidate : m_hardcoded_validators)
|
|
|
|
{
|
|
|
|
if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
|
|
|
|
break;
|
|
|
|
}
|
2015-10-06 09:02:47 +08:00
|
|
|
if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
|
2015-09-17 02:28:11 +08:00
|
|
|
{
|
2015-10-06 09:02:47 +08:00
|
|
|
m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp);
|
2015-09-17 02:28:11 +08:00
|
|
|
}
|
|
|
|
return format_sp.get() != nullptr;
|
|
|
|
}
|
|
|
|
|
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;
|
2015-09-05 05:01:18 +08:00
|
|
|
}
|