Files
clang-p2996/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
Sean Callanan 579e70c9b0 Add a DiagnosticManager replace error streams in the expression parser.
We want to do a better job presenting errors that occur when evaluating
expressions. Key to this effort is getting away from a model where all
errors are spat out onto a stream where the client has to take or leave
all of them.

To this end, this patch adds a new class, DiagnosticManager, which
contains errors produced by the compiler or by LLDB as an expression
is created. The DiagnosticManager can dump itself to a log as well as
to a string. Clients will (in the future) be able to filter out the
errors they're interested in by ID or present subsets of these errors
to the user.

This patch is not intended to change the *users* of errors - only to
thread DiagnosticManagers to all the places where streams are used. I
also attempt to standardize our use of errors a bit, removing trailing
newlines and making clients omit 'error:', 'warning:' etc. and instead
pass the Severity flag.

The patch is testsuite-neutral, with modifications to one part of the
MI tests because it relied on "error: error:" being erroneously
printed. This patch fixes the MI variable handling and the testcase.

<rdar://problem/22864976>

llvm-svn: 263859
2016-03-19 00:03:59 +00:00

138 lines
4.3 KiB
C++

//===-- ClangUtilityFunction.h ----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ClangUtilityFunction_h_
#define liblldb_ClangUtilityFunction_h_
// C Includes
// C++ Includes
#include <string>
#include <map>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "ClangExpressionHelper.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-private.h"
#include "lldb/Core/ClangForward.h"
#include "lldb/Expression/UtilityFunction.h"
namespace lldb_private
{
//----------------------------------------------------------------------
/// @class ClangUtilityFunction ClangUtilityFunction.h "lldb/Expression/ClangUtilityFunction.h"
/// @brief Encapsulates a single expression for use with Clang
///
/// LLDB uses expressions for various purposes, notably to call functions
/// and as a backend for the expr command. ClangUtilityFunction encapsulates
/// a self-contained function meant to be used from other code. Utility
/// functions can perform error-checking for ClangUserExpressions, or can
/// simply provide a way to push a function into the target for the debugger to
/// call later on.
//----------------------------------------------------------------------
class ClangUtilityFunction : public UtilityFunction
{
public:
class ClangUtilityFunctionHelper : public ClangExpressionHelper
{
public:
ClangUtilityFunctionHelper ()
{
}
~ClangUtilityFunctionHelper() override {}
//------------------------------------------------------------------
/// Return the object that the parser should use when resolving external
/// values. May be NULL if everything should be self-contained.
//------------------------------------------------------------------
ClangExpressionDeclMap *
DeclMap() override
{
return m_expr_decl_map_up.get();
}
void
ResetDeclMap()
{
m_expr_decl_map_up.reset();
}
void
ResetDeclMap (ExecutionContext & exe_ctx, bool keep_result_in_memory);
//------------------------------------------------------------------
/// Return the object that the parser should allow to access ASTs.
/// May be NULL if the ASTs do not need to be transformed.
///
/// @param[in] passthrough
/// The ASTConsumer that the returned transformer should send
/// the ASTs to after transformation.
//------------------------------------------------------------------
clang::ASTConsumer *
ASTTransformer(clang::ASTConsumer *passthrough) override
{
return nullptr;
}
private:
std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up;
};
//------------------------------------------------------------------
/// Constructor
///
/// @param[in] text
/// The text of the function. Must be a full translation unit.
///
/// @param[in] name
/// The name of the function, as used in the text.
//------------------------------------------------------------------
ClangUtilityFunction (ExecutionContextScope &exe_scope,
const char *text,
const char *name);
~ClangUtilityFunction() override;
ExpressionTypeSystemHelper *
GetTypeSystemHelper () override
{
return &m_type_system_helper;
}
ClangExpressionDeclMap *
DeclMap()
{
return m_type_system_helper.DeclMap();
}
void
ResetDeclMap ()
{
m_type_system_helper.ResetDeclMap();
}
void
ResetDeclMap (ExecutionContext & exe_ctx, bool keep_result_in_memory)
{
m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
}
bool
Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) override;
private:
ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when parsing and materializing the expression.
};
} // namespace lldb_private
#endif // liblldb_ClangUtilityFunction_h_