| Eugene Zelenko | 26f34fb | 2015-11-07 00:28:50 +0000 | [diff] [blame] | 1 | //===-- GoUserExpression.h --------------------------------------*- C++ -*-===// |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef liblldb_GoUserExpression_h_ |
| 11 | #define liblldb_GoUserExpression_h_ |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| Eugene Zelenko | 26f34fb | 2015-11-07 00:28:50 +0000 | [diff] [blame] | 15 | #include <memory> |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 16 | |
| 17 | // Other libraries and framework includes |
| 18 | // Project includes |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/Expression/ExpressionVariable.h" |
| 20 | #include "lldb/Expression/UserExpression.h" |
| 21 | #include "lldb/Target/ExecutionContext.h" |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 22 | #include "lldb/lldb-forward.h" |
| 23 | #include "lldb/lldb-private.h" |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 24 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | namespace lldb_private { |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 26 | class GoParser; |
| 27 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | class GoPersistentExpressionState : public PersistentExpressionState { |
| 29 | public: |
| 30 | GoPersistentExpressionState(); |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 31 | |
| Adrian Prantl | 5435f78 | 2018-04-30 23:59:15 +0000 | [diff] [blame^] | 32 | ConstString GetNextPersistentVariableName(Target &target) override; |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 33 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override; |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 35 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | lldb::addr_t LookupSymbol(const ConstString &name) override { |
| 37 | return LLDB_INVALID_ADDRESS; |
| 38 | } |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 39 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | static bool classof(const PersistentExpressionState *pv) { |
| 41 | return pv->getKind() == PersistentExpressionState::eKindGo; |
| 42 | } |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 43 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | private: |
| 45 | uint32_t m_next_persistent_variable_id; ///< The counter used by |
| 46 | ///GetNextResultName(). |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | //---------------------------------------------------------------------- |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | /// @class GoUserExpression GoUserExpression.h |
| 51 | /// "lldb/Expression/GoUserExpression.h" |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 52 | /// @brief Encapsulates a single expression for use with Go |
| 53 | /// |
| 54 | /// LLDB uses expressions for various purposes, notably to call functions |
| 55 | /// and as a backend for the expr command. GoUserExpression encapsulates |
| 56 | /// the objects needed to parse and interpret an expression. |
| 57 | //---------------------------------------------------------------------- |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | class GoUserExpression : public UserExpression { |
| 59 | public: |
| Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 60 | GoUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, |
| 61 | llvm::StringRef prefix, lldb::LanguageType language, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | ResultType desired_type, |
| 63 | const EvaluateExpressionOptions &options); |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 64 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | bool Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| 66 | lldb_private::ExecutionPolicy execution_policy, |
| 67 | bool keep_result_in_memory, bool generate_debug_info) override; |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 68 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | bool CanInterpret() override { return true; } |
| 70 | bool FinalizeJITExecution( |
| 71 | DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| 72 | lldb::ExpressionVariableSP &result, |
| 73 | lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS, |
| 74 | lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override { |
| 75 | return true; |
| 76 | } |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 77 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | protected: |
| 79 | lldb::ExpressionResults |
| 80 | DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| 81 | const EvaluateExpressionOptions &options, |
| 82 | lldb::UserExpressionSP &shared_ptr_to_me, |
| 83 | lldb::ExpressionVariableSP &result) override; |
| Jim Ingham | ff7ac6a | 2016-04-12 17:17:35 +0000 | [diff] [blame] | 84 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | private: |
| 86 | class GoInterpreter; |
| 87 | std::unique_ptr<GoInterpreter> m_interpreter; |
| Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace lldb_private |
| 91 | |
| 92 | #endif // liblldb_GoUserExpression_h_ |