1 //===-- ClangExpressionSourceCode.h -----------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef liblldb_ClangExpressionSourceCode_h 10 #define liblldb_ClangExpressionSourceCode_h 11 12 #include "lldb/Expression/Expression.h" 13 #include "lldb/Expression/ExpressionSourceCode.h" 14 #include "lldb/lldb-enumerations.h" 15 #include "llvm/ADT/ArrayRef.h" 16 #include "llvm/ADT/StringRef.h" 17 18 #include <string> 19 20 namespace lldb_private { 21 22 class ExecutionContext; 23 24 class ClangExpressionSourceCode : public ExpressionSourceCode { 25 public: 26 /// The file name we use for the wrapper code that we inject before 27 /// the user expression. 28 static const llvm::StringRef g_prefix_file_name; 29 static const char *g_expression_prefix; 30 31 static ClangExpressionSourceCode *CreateWrapped(llvm::StringRef filename, 32 llvm::StringRef prefix, 33 llvm::StringRef body) { 34 return new ClangExpressionSourceCode(filename, "$__lldb_expr", prefix, body, 35 Wrap); 36 } 37 38 /// Generates the source code that will evaluate the expression. 39 /// 40 /// \param text output parameter containing the source code string. 41 /// \param wrapping_language If the expression is supossed to be wrapped, 42 /// then this is the language that should be used for that. 43 /// \param static_method True iff the expression is valuated inside a static 44 /// Objective-C method. 45 /// \param exe_ctx The execution context in which the expression will be 46 /// evaluated. 47 /// \param add_locals True iff local variables should be injected into the 48 /// expression source code. 49 /// \param force_add_all_locals True iff all local variables should be 50 /// injected even if they are not used in the expression. 51 /// \param modules A list of (C++) modules that the expression should import. 52 /// 53 /// \return true iff the source code was successfully generated. 54 bool GetText(std::string &text, lldb::LanguageType wrapping_language, 55 bool static_method, ExecutionContext &exe_ctx, bool add_locals, 56 bool force_add_all_locals, 57 llvm::ArrayRef<std::string> modules) const; 58 59 // Given a string returned by GetText, find the beginning and end of the body 60 // passed to CreateWrapped. Return true if the bounds could be found. This 61 // will also work on text with FixItHints applied. 62 bool GetOriginalBodyBounds(std::string transformed_text, 63 lldb::LanguageType wrapping_language, 64 size_t &start_loc, size_t &end_loc); 65 66 protected: 67 ClangExpressionSourceCode(llvm::StringRef filename, llvm::StringRef name, 68 llvm::StringRef prefix, llvm::StringRef body, 69 Wrapping wrap); 70 71 private: 72 /// String marking the start of the user expression. 73 std::string m_start_marker; 74 /// String marking the end of the user expression. 75 std::string m_end_marker; 76 }; 77 78 } // namespace lldb_private 79 80 #endif 81