1 //===-- ClangExpressionSourceCode.h -----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ClangExpressionSourceCode_h
10 #define liblldb_ClangExpressionSourceCode_h
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"
20 namespace lldb_private {
22 class ExecutionContext;
24 class ClangExpressionSourceCode : public ExpressionSourceCode {
26 static const char *g_expression_prefix;
28 static ClangExpressionSourceCode *CreateWrapped(const char *prefix,
30 return new ClangExpressionSourceCode("$__lldb_expr", prefix, body, true);
33 uint32_t GetNumBodyLines();
35 /// Generates the source code that will evaluate the expression.
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
44 /// \param add_locals True iff local variables should be injected into the
45 /// expression source code.
46 /// \param force_add_all_locals True iff all local variables should be
47 /// injected even if they are not used in the expression.
48 /// \param modules A list of (C++) modules that the expression should import.
50 /// \return true iff the source code was successfully generated.
51 bool GetText(std::string &text, lldb::LanguageType wrapping_language,
52 bool static_method, ExecutionContext &exe_ctx, bool add_locals,
53 bool force_add_all_locals,
54 llvm::ArrayRef<std::string> modules) const;
56 // Given a string returned by GetText, find the beginning and end of the body
57 // passed to CreateWrapped. Return true if the bounds could be found. This
58 // will also work on text with FixItHints applied.
59 static bool GetOriginalBodyBounds(std::string transformed_text,
60 lldb::LanguageType wrapping_language,
61 size_t &start_loc, size_t &end_loc);
64 ClangExpressionSourceCode(const char *name, const char *prefix, const char *body,
66 ExpressionSourceCode(name, prefix, body, wrap) {}
69 } // namespace lldb_private