1e8d8bef9SDimitry Andric //===-- CommandObjectRegexCommand.h -----------------------------*- C++ -*-===// 2e8d8bef9SDimitry Andric // 3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e8d8bef9SDimitry Andric // 7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 8e8d8bef9SDimitry Andric 9e8d8bef9SDimitry Andric #ifndef LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 10e8d8bef9SDimitry Andric #define LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 11e8d8bef9SDimitry Andric 12e8d8bef9SDimitry Andric #include <list> 13e8d8bef9SDimitry Andric 14e8d8bef9SDimitry Andric #include "lldb/Interpreter/CommandObject.h" 15e8d8bef9SDimitry Andric #include "lldb/Utility/CompletionRequest.h" 16e8d8bef9SDimitry Andric #include "lldb/Utility/RegularExpression.h" 17e8d8bef9SDimitry Andric 18e8d8bef9SDimitry Andric namespace lldb_private { 19e8d8bef9SDimitry Andric 20e8d8bef9SDimitry Andric // CommandObjectRegexCommand 21e8d8bef9SDimitry Andric 22e8d8bef9SDimitry Andric class CommandObjectRegexCommand : public CommandObjectRaw { 23e8d8bef9SDimitry Andric public: 24e8d8bef9SDimitry Andric CommandObjectRegexCommand(CommandInterpreter &interpreter, 25e8d8bef9SDimitry Andric llvm::StringRef name, llvm::StringRef help, 2606c3fb27SDimitry Andric llvm::StringRef syntax, 27e8d8bef9SDimitry Andric uint32_t completion_type_mask, bool is_removable); 28e8d8bef9SDimitry Andric 29e8d8bef9SDimitry Andric ~CommandObjectRegexCommand() override; 30e8d8bef9SDimitry Andric IsRemovable()31e8d8bef9SDimitry Andric bool IsRemovable() const override { return m_is_removable; } 32e8d8bef9SDimitry Andric 33e8d8bef9SDimitry Andric bool AddRegexCommand(llvm::StringRef re_cstr, llvm::StringRef command_cstr); 34e8d8bef9SDimitry Andric HasRegexEntries()35e8d8bef9SDimitry Andric bool HasRegexEntries() const { return !m_entries.empty(); } 36e8d8bef9SDimitry Andric 37e8d8bef9SDimitry Andric void HandleCompletion(CompletionRequest &request) override; 38e8d8bef9SDimitry Andric 39e8d8bef9SDimitry Andric protected: 40*5f757f3fSDimitry Andric void DoExecute(llvm::StringRef command, CommandReturnObject &result) override; 41e8d8bef9SDimitry Andric 4281ad6265SDimitry Andric /// Substitute variables of the format %\d+ in the input string. 4381ad6265SDimitry Andric static llvm::Expected<std::string> SubstituteVariables( 4481ad6265SDimitry Andric llvm::StringRef input, 4581ad6265SDimitry Andric const llvm::SmallVectorImpl<llvm::StringRef> &replacements); 4681ad6265SDimitry Andric 47e8d8bef9SDimitry Andric struct Entry { 48e8d8bef9SDimitry Andric RegularExpression regex; 49e8d8bef9SDimitry Andric std::string command; 50e8d8bef9SDimitry Andric }; 51e8d8bef9SDimitry Andric 52e8d8bef9SDimitry Andric typedef std::list<Entry> EntryCollection; 53e8d8bef9SDimitry Andric const uint32_t m_completion_type_mask; 54e8d8bef9SDimitry Andric EntryCollection m_entries; 55e8d8bef9SDimitry Andric bool m_is_removable; 56e8d8bef9SDimitry Andric 57e8d8bef9SDimitry Andric private: 58e8d8bef9SDimitry Andric CommandObjectRegexCommand(const CommandObjectRegexCommand &) = delete; 59e8d8bef9SDimitry Andric const CommandObjectRegexCommand & 60e8d8bef9SDimitry Andric operator=(const CommandObjectRegexCommand &) = delete; 61e8d8bef9SDimitry Andric }; 62e8d8bef9SDimitry Andric 63e8d8bef9SDimitry Andric } // namespace lldb_private 64e8d8bef9SDimitry Andric 65e8d8bef9SDimitry Andric #endif // LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 66