1 //===-- CommandObjectExpression.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_COMMANDS_COMMANDOBJECTEXPRESSION_H
10 #define LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H
11 
12 #include "lldb/Core/IOHandler.h"
13 #include "lldb/Interpreter/CommandObject.h"
14 #include "lldb/Interpreter/OptionGroupBoolean.h"
15 #include "lldb/Interpreter/OptionGroupFormat.h"
16 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
17 #include "lldb/Target/Target.h"
18 #include "lldb/lldb-private-enumerations.h"
19 
20 namespace lldb_private {
21 
22 class CommandObjectExpression : public CommandObjectRaw,
23                                 public IOHandlerDelegate {
24 public:
25   class CommandOptions : public OptionGroup {
26   public:
27     CommandOptions();
28 
29     ~CommandOptions() override;
30 
31     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
32 
33     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
34                           ExecutionContext *execution_context) override;
35 
36     void OptionParsingStarting(ExecutionContext *execution_context) override;
37 
38     bool top_level;
39     bool unwind_on_error;
40     bool ignore_breakpoints;
41     bool allow_jit;
42     bool show_types;
43     bool show_summary;
44     bool debug;
45     uint32_t timeout;
46     bool try_all_threads;
47     lldb::LanguageType language;
48     LanguageRuntimeDescriptionDisplayVerbosity m_verbosity;
49     LazyBool auto_apply_fixits;
50   };
51 
52   CommandObjectExpression(CommandInterpreter &interpreter);
53 
54   ~CommandObjectExpression() override;
55 
56   Options *GetOptions() override;
57 
58   void HandleCompletion(CompletionRequest &request) override;
59 
60 protected:
61   // IOHandler::Delegate functions
62   void IOHandlerInputComplete(IOHandler &io_handler,
63                               std::string &line) override;
64 
65   bool IOHandlerIsInputComplete(IOHandler &io_handler,
66                                 StringList &lines) override;
67 
68   bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
69 
70   /// Return the appropriate expression options used for evaluating the
71   /// expression in the given target.
72   EvaluateExpressionOptions GetEvalOptions(const Target &target);
73 
74   /// Evaluates the given expression.
75   /// \param output_stream The stream to which the evaluation result will be
76   ///                      printed.
77   /// \param error_stream Contains error messages that should be displayed to
78   ///                     the user in case the evaluation fails.
79   /// \param result A CommandReturnObject which status will be set to the
80   ///               appropriate value depending on evaluation success and
81   ///               whether the expression produced any result.
82   /// \return Returns true iff the expression was successfully evaluated,
83   ///         executed and the result could be printed to the output stream.
84   bool EvaluateExpression(llvm::StringRef expr, Stream &output_stream,
85                           Stream &error_stream, CommandReturnObject &result);
86 
87   void GetMultilineExpression();
88 
89   OptionGroupOptions m_option_group;
90   OptionGroupFormat m_format_options;
91   OptionGroupValueObjectDisplay m_varobj_options;
92   OptionGroupBoolean m_repl_option;
93   CommandOptions m_command_options;
94   uint32_t m_expr_line_count;
95   std::string m_expr_lines;       // Multi-line expression support
96   std::string m_fixed_expression; // Holds the current expression's fixed text.
97 };
98 
99 } // namespace lldb_private
100 
101 #endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H
102