Files
clang-p2996/lldb/source/DataFormatters/LanguageCategory.cpp
Enrico Granata 2233895a3b Add support for language plugins to provide data formatters
Historically, data formatters all exist in a global repository (the category map)
On top of that, some formatters can be "hardcoded" when the conditions under which they apply are not expressible as a typename (or typename regex)

This change paves the way to move formatters into per-language buckets such that the C++ plugin is responsible for ownership of the C++ formatters, and so on
The advantages of this are:
a) language formatters only get created when they might apply
b) formatters for a language are clearly owned by the matching language plugin

The current model is one of static instantiation, that is a language knows the full set of formatters it vends and that is only asked-for once, and then handed off to the FormatManager
In a future revision it might be interesting to add similar ability to the language runtimes, and monitor for certain shared library events to add even more library-specific formatters

No formatters are moved as part of this change, so practically speaking this is NFC

llvm-svn: 246515
2015-09-01 01:01:48 +00:00

134 lines
3.9 KiB
C++

//===-- 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(),
m_format_cache()
{
if (Language* language_plugin = Language::FindPlugin(lang_type))
m_category_sp = language_plugin->GetFormatters();
if (m_category_sp)
m_category_sp->Enable(true, 1);
}
bool
LanguageCategory::Get (ValueObject& valobj,
lldb::DynamicValueType dynamic,
FormattersMatchVector matches,
lldb::TypeFormatImplSP& format_sp)
{
if (!m_category_sp)
return false;
ConstString type_name = FormatManager::GetTypeForCache(valobj, dynamic);
if (type_name)
{
if (m_format_cache.GetFormat(type_name, format_sp))
return true;
}
bool result = m_category_sp->Get(valobj, matches, format_sp);
if (type_name && (!format_sp || !format_sp->NonCacheable()))
{
m_format_cache.SetFormat(type_name, format_sp);
}
return result;
}
bool
LanguageCategory::Get (ValueObject& valobj,
lldb::DynamicValueType dynamic,
FormattersMatchVector matches,
lldb::TypeSummaryImplSP& format_sp)
{
if (!m_category_sp)
return false;
ConstString type_name = FormatManager::GetTypeForCache(valobj, dynamic);
if (type_name)
{
if (m_format_cache.GetSummary(type_name, format_sp))
return true;
}
bool result = m_category_sp->Get(valobj, matches, format_sp);
if (type_name && (!format_sp || !format_sp->NonCacheable()))
{
m_format_cache.SetSummary(type_name, format_sp);
}
return result;
}
bool
LanguageCategory::Get (ValueObject& valobj,
lldb::DynamicValueType dynamic,
FormattersMatchVector matches,
lldb::SyntheticChildrenSP& format_sp)
{
if (!m_category_sp)
return false;
ConstString type_name = FormatManager::GetTypeForCache(valobj, dynamic);
if (type_name)
{
if (m_format_cache.GetSynthetic(type_name, format_sp))
return true;
}
bool result = m_category_sp->Get(valobj, matches, format_sp);
if (type_name && (!format_sp || !format_sp->NonCacheable()))
{
m_format_cache.SetSynthetic(type_name, format_sp);
}
return result;
}
bool
LanguageCategory::Get (ValueObject& valobj,
lldb::DynamicValueType dynamic,
FormattersMatchVector matches,
lldb::TypeValidatorImplSP& format_sp)
{
if (!m_category_sp)
return false;
ConstString type_name = FormatManager::GetTypeForCache(valobj, dynamic);
if (type_name)
{
if (m_format_cache.GetValidator(type_name, format_sp))
return true;
}
bool result = m_category_sp->Get(valobj, matches, format_sp);
if (type_name && (!format_sp || !format_sp->NonCacheable()))
{
m_format_cache.SetValidator(type_name, format_sp);
}
return result;
}
lldb::TypeCategoryImplSP
LanguageCategory::GetCategory () const
{
return m_category_sp;
}