ClangExpressionSourceCode.h revision 355940
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
20namespace lldb_private {
21
22class ExecutionContext;
23
24class ClangExpressionSourceCode : public ExpressionSourceCode {
25public:
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 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.
49  ///
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;
55
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);
62
63protected:
64  ClangExpressionSourceCode(const char *name, const char *prefix, const char *body,
65                       bool wrap) :
66      ExpressionSourceCode(name, prefix, body, wrap) {}
67};
68
69} // namespace lldb_private
70
71#endif
72