1 //===-- ExpressionSourceCode.h ----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_ExpressionSourceCode_h 11 #define liblldb_ExpressionSourceCode_h 12 13 #include "lldb/lldb-enumerations.h" 14 15 #include <string> 16 17 namespace lldb_private { 18 19 class ExecutionContext; 20 21 class ExpressionSourceCode { 22 public: 23 static const char *g_expression_prefix; 24 CreateWrapped(const char * prefix,const char * body)25 static ExpressionSourceCode *CreateWrapped(const char *prefix, 26 const char *body) { 27 return new ExpressionSourceCode("$__lldb_expr", prefix, body, true); 28 } 29 CreateUnwrapped(const char * name,const char * body)30 static ExpressionSourceCode *CreateUnwrapped(const char *name, 31 const char *body) { 32 return new ExpressionSourceCode(name, "", body, false); 33 } 34 NeedsWrapping()35 bool NeedsWrapping() const { return m_wrap; } 36 GetName()37 const char *GetName() const { return m_name.c_str(); } 38 39 bool GetText(std::string &text, lldb::LanguageType wrapping_language, 40 bool static_method, ExecutionContext &exe_ctx) const; 41 42 // Given a string returned by GetText, find the beginning and end of the body 43 // passed to CreateWrapped. Return true if the bounds could be found. This 44 // will also work on text with FixItHints applied. 45 static bool GetOriginalBodyBounds(std::string transformed_text, 46 lldb::LanguageType wrapping_language, 47 size_t &start_loc, size_t &end_loc); 48 49 private: ExpressionSourceCode(const char * name,const char * prefix,const char * body,bool wrap)50 ExpressionSourceCode(const char *name, const char *prefix, const char *body, 51 bool wrap) 52 : m_name(name), m_prefix(prefix), m_body(body), m_wrap(wrap) {} 53 54 std::string m_name; 55 std::string m_prefix; 56 std::string m_body; 57 bool m_wrap; 58 }; 59 60 } // namespace lldb_private 61 62 #endif 63