Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
39648 views
//===-- ClangExpressionSourceCode.h -----------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONSOURCECODE_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONSOURCECODE_H1011#include "lldb/Expression/Expression.h"12#include "lldb/Expression/ExpressionSourceCode.h"13#include "lldb/lldb-enumerations.h"14#include "llvm/ADT/ArrayRef.h"15#include "llvm/ADT/StringRef.h"1617#include <string>1819namespace lldb_private {2021class ExecutionContext;2223class ClangExpressionSourceCode : public ExpressionSourceCode {24public:25/// The file name we use for the wrapper code that we inject before26/// the user expression.27static const llvm::StringRef g_prefix_file_name;28static const char *g_expression_prefix;29static const char *g_expression_suffix;3031/// The possible ways an expression can be wrapped.32enum class WrapKind {33/// Wrapped in a non-static member function of a C++ class.34CppMemberFunction,35/// Wrapped in an instance Objective-C method.36ObjCInstanceMethod,37/// Wrapped in a static Objective-C method.38ObjCStaticMethod,39/// Wrapped in a non-member function.40/// Note that this is also used for static member functions of a C++ class.41Function42};4344static ClangExpressionSourceCode *CreateWrapped(llvm::StringRef filename,45llvm::StringRef prefix,46llvm::StringRef body,47WrapKind wrap_kind) {48return new ClangExpressionSourceCode(filename, "$__lldb_expr", prefix, body,49Wrap, wrap_kind);50}5152/// Generates the source code that will evaluate the expression.53///54/// \param text output parameter containing the source code string.55/// \param exe_ctx The execution context in which the expression will be56/// evaluated.57/// \param add_locals True iff local variables should be injected into the58/// expression source code.59/// \param force_add_all_locals True iff all local variables should be60/// injected even if they are not used in the expression.61/// \param modules A list of (C++) modules that the expression should import.62///63/// \return true iff the source code was successfully generated.64bool GetText(std::string &text, ExecutionContext &exe_ctx, bool add_locals,65bool force_add_all_locals,66llvm::ArrayRef<std::string> modules) const;6768// Given a string returned by GetText, find the beginning and end of the body69// passed to CreateWrapped. Return true if the bounds could be found. This70// will also work on text with FixItHints applied.71bool GetOriginalBodyBounds(std::string transformed_text,72size_t &start_loc, size_t &end_loc);7374protected:75ClangExpressionSourceCode(llvm::StringRef filename, llvm::StringRef name,76llvm::StringRef prefix, llvm::StringRef body,77Wrapping wrap, WrapKind wrap_kind);7879private:80/// Writes "using" declarations for local variables into the specified stream.81///82/// Behaviour is undefined if 'frame == nullptr'.83///84/// \param[out] stream Stream that this function generates "using"85/// declarations into.86///87/// \param[in] expr Expression source that we're evaluating.88///89/// \param[in] frame StackFrame which carries information about the local90/// variables that we're generating "using" declarations for.91void AddLocalVariableDecls(StreamString &stream, const std::string &expr,92StackFrame *frame) const;9394/// String marking the start of the user expression.95std::string m_start_marker;96/// String marking the end of the user expression.97std::string m_end_marker;98/// How the expression has been wrapped.99const WrapKind m_wrap_kind;100};101102} // namespace lldb_private103104#endif105106107