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