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   static const char *g_expression_prefix;
27 
28   static ClangExpressionSourceCode *CreateWrapped(const char *prefix,
29                                              const char *body) {
30     return new ClangExpressionSourceCode("$__lldb_expr", prefix, body, true);
31   }
32 
33   uint32_t GetNumBodyLines();
34 
35   /// Generates the source code that will evaluate the expression.
36   ///
37   /// \param text output parameter containing the source code string.
38   /// \param wrapping_language If the expression is supossed to be wrapped,
39   ///        then this is the language that should be used for that.
40   /// \param static_method True iff the expression is valuated inside a static
41   ///        Objective-C method.
42   /// \param exe_ctx The execution context in which the expression will be
43   ///        evaluated.
44   /// \param add_locals True iff local variables should be injected into the
45   ///        expression source code.
46   /// \param modules A list of (C++) modules that the expression should import.
47   ///
48   /// \return true iff the source code was successfully generated.
49   bool GetText(std::string &text, lldb::LanguageType wrapping_language,
50                bool static_method,
51                ExecutionContext &exe_ctx,
52                bool add_locals,
53                llvm::ArrayRef<std::string> modules) const;
54 
55   // Given a string returned by GetText, find the beginning and end of the body
56   // passed to CreateWrapped. Return true if the bounds could be found.  This
57   // will also work on text with FixItHints applied.
58   static bool GetOriginalBodyBounds(std::string transformed_text,
59                                     lldb::LanguageType wrapping_language,
60                                     size_t &start_loc, size_t &end_loc);
61 
62 protected:
63   ClangExpressionSourceCode(const char *name, const char *prefix, const char *body,
64                        bool wrap) :
65       ExpressionSourceCode(name, prefix, body, wrap) {}
66 };
67 
68 } // namespace lldb_private
69 
70 #endif
71