1351290Sdim//===-- ClangExpressionSourceCode.h -----------------------------*- C++ -*-===// 2351290Sdim// 3351290Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4351290Sdim// See https://llvm.org/LICENSE.txt for license information. 5351290Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6351290Sdim// 7351290Sdim//===----------------------------------------------------------------------===// 8351290Sdim 9351290Sdim#ifndef liblldb_ClangExpressionSourceCode_h 10351290Sdim#define liblldb_ClangExpressionSourceCode_h 11351290Sdim 12351290Sdim#include "lldb/Expression/Expression.h" 13351290Sdim#include "lldb/Expression/ExpressionSourceCode.h" 14351290Sdim#include "lldb/lldb-enumerations.h" 15351290Sdim#include "llvm/ADT/ArrayRef.h" 16351290Sdim#include "llvm/ADT/StringRef.h" 17351290Sdim 18351290Sdim#include <string> 19351290Sdim 20351290Sdimnamespace lldb_private { 21351290Sdim 22351290Sdimclass ExecutionContext; 23351290Sdim 24351290Sdimclass ClangExpressionSourceCode : public ExpressionSourceCode { 25351290Sdimpublic: 26360784Sdim /// The file name we use for the wrapper code that we inject before 27360784Sdim /// the user expression. 28360784Sdim static const llvm::StringRef g_prefix_file_name; 29351290Sdim static const char *g_expression_prefix; 30351290Sdim 31360784Sdim static ClangExpressionSourceCode *CreateWrapped(llvm::StringRef filename, 32360784Sdim llvm::StringRef prefix, 33360784Sdim llvm::StringRef body) { 34360784Sdim return new ClangExpressionSourceCode(filename, "$__lldb_expr", prefix, body, 35360784Sdim Wrap); 36351290Sdim } 37351290Sdim 38351290Sdim /// Generates the source code that will evaluate the expression. 39351290Sdim /// 40351290Sdim /// \param text output parameter containing the source code string. 41351290Sdim /// \param wrapping_language If the expression is supossed to be wrapped, 42351290Sdim /// then this is the language that should be used for that. 43351290Sdim /// \param static_method True iff the expression is valuated inside a static 44351290Sdim /// Objective-C method. 45351290Sdim /// \param exe_ctx The execution context in which the expression will be 46351290Sdim /// evaluated. 47351290Sdim /// \param add_locals True iff local variables should be injected into the 48351290Sdim /// expression source code. 49351290Sdim /// \param force_add_all_locals True iff all local variables should be 50351290Sdim /// injected even if they are not used in the expression. 51351290Sdim /// \param modules A list of (C++) modules that the expression should import. 52351290Sdim /// 53351290Sdim /// \return true iff the source code was successfully generated. 54351290Sdim bool GetText(std::string &text, lldb::LanguageType wrapping_language, 55351290Sdim bool static_method, ExecutionContext &exe_ctx, bool add_locals, 56351290Sdim bool force_add_all_locals, 57351290Sdim llvm::ArrayRef<std::string> modules) const; 58351290Sdim 59351290Sdim // Given a string returned by GetText, find the beginning and end of the body 60351290Sdim // passed to CreateWrapped. Return true if the bounds could be found. This 61351290Sdim // will also work on text with FixItHints applied. 62360784Sdim bool GetOriginalBodyBounds(std::string transformed_text, 63360784Sdim lldb::LanguageType wrapping_language, 64360784Sdim size_t &start_loc, size_t &end_loc); 65351290Sdim 66351290Sdimprotected: 67360784Sdim ClangExpressionSourceCode(llvm::StringRef filename, llvm::StringRef name, 68360784Sdim llvm::StringRef prefix, llvm::StringRef body, 69360784Sdim Wrapping wrap); 70360784Sdim 71360784Sdimprivate: 72360784Sdim /// String marking the start of the user expression. 73360784Sdim std::string m_start_marker; 74360784Sdim /// String marking the end of the user expression. 75360784Sdim std::string m_end_marker; 76351290Sdim}; 77351290Sdim 78351290Sdim} // namespace lldb_private 79351290Sdim 80351290Sdim#endif 81