|
| 1 | +//===-- REPL.h --------------------------------------------------*- C++ -*-===// |
| 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 | + |
| 11 | +#ifndef lldb_REPL_h |
| 12 | +#define lldb_REPL_h |
| 13 | + |
| 14 | +#include "lldb/Interpreter/OptionGroupFormat.h" |
| 15 | +#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" |
| 16 | +#include "lldb/../../source/Commands/CommandObjectExpression.h" |
| 17 | + |
| 18 | +namespace lldb_private |
| 19 | +{ |
| 20 | + |
| 21 | +class REPL : public IOHandlerDelegate |
| 22 | +{ |
| 23 | +public: |
| 24 | + //---------------------------------------------------------------------- |
| 25 | + // See TypeSystem.h for how to add subclasses to this. |
| 26 | + //---------------------------------------------------------------------- |
| 27 | + enum LLVMCastKind { |
| 28 | + eKindClang, |
| 29 | + eKindSwift, |
| 30 | + eKindGo, |
| 31 | + kNumKinds |
| 32 | + }; |
| 33 | + |
| 34 | + LLVMCastKind getKind() const { return m_kind; } |
| 35 | + |
| 36 | + REPL(LLVMCastKind kind, Target &target); |
| 37 | + |
| 38 | + virtual ~REPL(); |
| 39 | + |
| 40 | + static lldb::REPLSP |
| 41 | + Create (lldb::LanguageType language, Target *target); |
| 42 | + |
| 43 | + void |
| 44 | + SetFormatOptions (const OptionGroupFormat &options) |
| 45 | + { |
| 46 | + m_format_options = options; |
| 47 | + } |
| 48 | + |
| 49 | + void |
| 50 | + SetValueObjectDisplayOptions (const OptionGroupValueObjectDisplay &options) |
| 51 | + { |
| 52 | + m_varobj_options = options; |
| 53 | + } |
| 54 | + |
| 55 | + void |
| 56 | + SetCommandOptions (const CommandObjectExpression::CommandOptions &options) |
| 57 | + { |
| 58 | + m_command_options = options; |
| 59 | + } |
| 60 | + |
| 61 | + void |
| 62 | + SetCompilerOptions (const char *options) |
| 63 | + { |
| 64 | + if (options) |
| 65 | + m_compiler_options = options; |
| 66 | + } |
| 67 | + |
| 68 | + lldb::IOHandlerSP |
| 69 | + GetIOHandler (); |
| 70 | + |
| 71 | + Error |
| 72 | + RunLoop (); |
| 73 | + |
| 74 | + //------------------------------------------------------------------ |
| 75 | + // IOHandler::Delegate functions |
| 76 | + //------------------------------------------------------------------ |
| 77 | + void |
| 78 | + IOHandlerActivated (IOHandler &io_handler) override; |
| 79 | + |
| 80 | + bool |
| 81 | + IOHandlerInterrupt (IOHandler &io_handler) override; |
| 82 | + |
| 83 | + void |
| 84 | + IOHandlerInputInterrupted (IOHandler &io_handler, |
| 85 | + std::string &line) override; |
| 86 | + |
| 87 | + const char * |
| 88 | + IOHandlerGetFixIndentationCharacters () override; |
| 89 | + |
| 90 | + ConstString |
| 91 | + IOHandlerGetControlSequence (char ch) override; |
| 92 | + |
| 93 | + const char * |
| 94 | + IOHandlerGetCommandPrefix () override; |
| 95 | + |
| 96 | + const char * |
| 97 | + IOHandlerGetHelpPrologue () override; |
| 98 | + |
| 99 | + bool |
| 100 | + IOHandlerIsInputComplete (IOHandler &io_handler, |
| 101 | + StringList &lines) override; |
| 102 | + |
| 103 | + int |
| 104 | + IOHandlerFixIndentation (IOHandler &io_handler, |
| 105 | + const StringList &lines, |
| 106 | + int cursor_position) override; |
| 107 | + |
| 108 | + void |
| 109 | + IOHandlerInputComplete (IOHandler &io_handler, |
| 110 | + std::string &line) override; |
| 111 | + |
| 112 | + int |
| 113 | + IOHandlerComplete (IOHandler &io_handler, |
| 114 | + const char *current_line, |
| 115 | + const char *cursor, |
| 116 | + const char *last_char, |
| 117 | + int skip_first_n_matches, |
| 118 | + int max_matches, |
| 119 | + StringList &matches) override; |
| 120 | + |
| 121 | +private: |
| 122 | + std::string |
| 123 | + GetSourcePath(); |
| 124 | + |
| 125 | +protected: |
| 126 | + static int |
| 127 | + CalculateActualIndentation (const StringList &lines); |
| 128 | + |
| 129 | + //---------------------------------------------------------------------- |
| 130 | + // Subclasses should override these functions to implement a functional REPL. |
| 131 | + //---------------------------------------------------------------------- |
| 132 | + |
| 133 | + virtual Error |
| 134 | + DoInitialization () = 0; |
| 135 | + |
| 136 | + virtual ConstString |
| 137 | + GetSourceFileBasename () = 0; |
| 138 | + |
| 139 | + virtual const char * |
| 140 | + GetAutoIndentCharacters () = 0; |
| 141 | + |
| 142 | + virtual bool |
| 143 | + SourceIsComplete (const std::string &source) = 0; |
| 144 | + |
| 145 | + virtual lldb::offset_t |
| 146 | + GetDesiredIndentation (const StringList &lines, |
| 147 | + int cursor_position, |
| 148 | + int tab_size) = 0; // LLDB_INVALID_OFFSET means no change |
| 149 | + |
| 150 | + virtual lldb::LanguageType |
| 151 | + GetLanguage () = 0; |
| 152 | + |
| 153 | + virtual bool |
| 154 | + PrintOneVariable (Debugger &debugger, |
| 155 | + lldb::StreamFileSP &output_sp, |
| 156 | + lldb::ValueObjectSP &valobj_sp, |
| 157 | + ExpressionVariable *var = nullptr) = 0; |
| 158 | + |
| 159 | + virtual int |
| 160 | + CompleteCode(const std::string ¤t_code, |
| 161 | + StringList &matches) = 0; |
| 162 | + |
| 163 | + OptionGroupFormat m_format_options = OptionGroupFormat(lldb::eFormatDefault); |
| 164 | + OptionGroupValueObjectDisplay m_varobj_options; |
| 165 | + CommandObjectExpression::CommandOptions m_command_options; |
| 166 | + std::string m_compiler_options; |
| 167 | + |
| 168 | + bool m_enable_auto_indent = true; |
| 169 | + std::string m_indent_str; // Use this string for each level of indentation |
| 170 | + std::string m_current_indent_str; |
| 171 | + uint32_t m_current_indent_level = 0; |
| 172 | + |
| 173 | + std::string m_repl_source_path; |
| 174 | + bool m_dedicated_repl_mode = false; |
| 175 | + |
| 176 | + StringList m_code; // All accumulated REPL statements are saved here |
| 177 | + |
| 178 | + Target &m_target; |
| 179 | + lldb::IOHandlerSP m_io_handler_sp; |
| 180 | + LLVMCastKind m_kind; |
| 181 | +}; |
| 182 | + |
| 183 | +} |
| 184 | + |
| 185 | +#endif /* REPL_h */ |
0 commit comments