LLDB  mainline
ClangUtilityFunction.h
Go to the documentation of this file.
1 //===-- ClangUtilityFunction.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 LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include "ClangExpressionHelper.h"
17 
19 #include "lldb/lldb-forward.h"
20 #include "lldb/lldb-private.h"
21 
22 namespace lldb_private {
23 
24 /// \class ClangUtilityFunction ClangUtilityFunction.h
25 /// "lldb/Expression/ClangUtilityFunction.h" Encapsulates a single expression
26 /// for use with Clang
27 ///
28 /// LLDB uses expressions for various purposes, notably to call functions
29 /// and as a backend for the expr command. ClangUtilityFunction encapsulates
30 /// a self-contained function meant to be used from other code. Utility
31 /// functions can perform error-checking for ClangUserExpressions, or can
32 /// simply provide a way to push a function into the target for the debugger
33 /// to call later on.
35  // LLVM RTTI support
36  static char ID;
37 
38 public:
39  bool isA(const void *ClassID) const override {
40  return ClassID == &ID || UtilityFunction::isA(ClassID);
41  }
42  static bool classof(const Expression *obj) { return obj->isA(&ID); }
43 
44  /// Constructor
45  ///
46  /// \param[in] text
47  /// The text of the function. Must be a full translation unit.
48  ///
49  /// \param[in] name
50  /// The name of the function, as used in the text.
51  ///
52  /// \param[in] enable_debugging
53  /// Enable debugging of this function.
55  std::string name, bool enable_debugging);
56 
57  ~ClangUtilityFunction() override;
58 
60  return &m_type_system_helper;
61  }
62 
64 
66 
67  void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) {
68  m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
69  }
70 
71  bool Install(DiagnosticManager &diagnostic_manager,
72  ExecutionContext &exe_ctx) override;
73 
74 private:
76  public:
77  ClangUtilityFunctionHelper() = default;
78 
79  ~ClangUtilityFunctionHelper() override = default;
80 
81  /// Return the object that the parser should use when resolving external
82  /// values. May be NULL if everything should be self-contained.
84  return m_expr_decl_map_up.get();
85  }
86 
87  void ResetDeclMap() { m_expr_decl_map_up.reset(); }
88 
89  void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory);
90 
91  /// Return the object that the parser should allow to access ASTs. May be
92  /// nullptr if the ASTs do not need to be transformed.
93  ///
94  /// \param[in] passthrough
95  /// The ASTConsumer that the returned transformer should send
96  /// the ASTs to after transformation.
97  clang::ASTConsumer *
98  ASTTransformer(clang::ASTConsumer *passthrough) override {
99  return nullptr;
100  }
101 
102  private:
103  std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up;
104  };
105 
106  /// The map to use when parsing and materializing the expression.
108 };
109 
110 } // namespace lldb_private
111 
112 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper
Definition: ClangUtilityFunction.h:75
lldb_private::ClangUtilityFunction::ClangUtilityFunction
ClangUtilityFunction(ExecutionContextScope &exe_scope, std::string text, std::string name, bool enable_debugging)
Constructor.
Definition: ClangUtilityFunction.cpp:37
lldb_private::ClangUtilityFunction::GetTypeSystemHelper
ExpressionTypeSystemHelper * GetTypeSystemHelper() override
Definition: ClangUtilityFunction.h:59
lldb_private::ClangUtilityFunction::isA
bool isA(const void *ClassID) const override
Definition: ClangUtilityFunction.h:39
lldb_private::ExpressionTypeSystemHelper
Definition: ExpressionTypeSystemHelper.h:26
lldb_private::Expression::isA
virtual bool isA(const void *ClassID) const =0
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper::ClangUtilityFunctionHelper
ClangUtilityFunctionHelper()=default
lldb_private::ClangUtilityFunction::ResetDeclMap
void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory)
Definition: ClangUtilityFunction.h:67
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::ClangUtilityFunction::~ClangUtilityFunction
~ClangUtilityFunction() override
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper::DeclMap
ClangExpressionDeclMap * DeclMap() override
Return the object that the parser should use when resolving external values.
Definition: ClangUtilityFunction.h:83
lldb_private::ClangUtilityFunction::m_type_system_helper
ClangUtilityFunctionHelper m_type_system_helper
The map to use when parsing and materializing the expression.
Definition: ClangUtilityFunction.h:107
lldb_private::ClangUtilityFunction
Definition: ClangUtilityFunction.h:34
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper::ResetDeclMap
void ResetDeclMap()
Definition: ClangUtilityFunction.h:87
UtilityFunction.h
lldb-private.h
lldb_private::ClangUtilityFunction::Install
bool Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) override
Install the utility function into a process.
Definition: ClangUtilityFunction.cpp:80
lldb_private::ClangUtilityFunction::DeclMap
ClangExpressionDeclMap * DeclMap()
Definition: ClangUtilityFunction.h:63
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
lldb_private::ClangUtilityFunction::ResetDeclMap
void ResetDeclMap()
Definition: ClangUtilityFunction.h:65
lldb_private::UtilityFunction::isA
bool isA(const void *ClassID) const override
Definition: UtilityFunction.h:35
lldb_private::ClangExpressionHelper
Definition: ClangExpressionHelper.h:30
lldb-forward.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ClangUtilityFunction::classof
static bool classof(const Expression *obj)
Definition: ClangUtilityFunction.h:42
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper::~ClangUtilityFunctionHelper
~ClangUtilityFunctionHelper() override=default
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper::m_expr_decl_map_up
std::unique_ptr< ClangExpressionDeclMap > m_expr_decl_map_up
Definition: ClangUtilityFunction.h:103
lldb_private::ClangUtilityFunction::ClangUtilityFunctionHelper::ASTTransformer
clang::ASTConsumer * ASTTransformer(clang::ASTConsumer *passthrough) override
Return the object that the parser should allow to access ASTs.
Definition: ClangUtilityFunction.h:98
lldb_private::ClangUtilityFunction::ID
static char ID
Definition: ClangUtilityFunction.h:36
lldb_private::Expression
Definition: Expression.h:33
ClangExpressionHelper.h
lldb_private::UtilityFunction
Definition: UtilityFunction.h:30
lldb_private::ClangExpressionDeclMap
Definition: ClangExpressionDeclMap.h:56