OptionGroupPythonClassWithDict.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //===-- OptionGroupPythonClassWithDict.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. #ifndef LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
  9. #define LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
  10. #include "lldb/Interpreter/Options.h"
  11. #include "lldb/Utility/Flags.h"
  12. #include "lldb/Utility/StructuredData.h"
  13. #include "lldb/lldb-types.h"
  14. namespace lldb_private {
  15. // Use this Option group if you have a python class that implements some
  16. // Python extension point, and you pass a SBStructuredData to the class
  17. // __init__ method.
  18. // class_option specifies the class name
  19. // the key and value options are read in in pairs, and a
  20. // StructuredData::Dictionary is constructed with those pairs.
  21. class OptionGroupPythonClassWithDict : public OptionGroup {
  22. public:
  23. enum OptionKind {
  24. eScriptClass = 1 << 0,
  25. eDictKey = 1 << 1,
  26. eDictValue = 1 << 2,
  27. ePythonFunction = 1 << 3,
  28. eAllOptions = (eScriptClass | eDictKey | eDictValue | ePythonFunction)
  29. };
  30. OptionGroupPythonClassWithDict(const char *class_use, bool is_class = true,
  31. int class_option = 'C', int key_option = 'k',
  32. int value_option = 'v',
  33. uint16_t required_options = eScriptClass |
  34. ePythonFunction);
  35. ~OptionGroupPythonClassWithDict() override = default;
  36. llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
  37. return llvm::ArrayRef<OptionDefinition>(m_option_definition);
  38. }
  39. Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
  40. ExecutionContext *execution_context) override;
  41. void OptionParsingStarting(ExecutionContext *execution_context) override;
  42. Status OptionParsingFinished(ExecutionContext *execution_context) override;
  43. const StructuredData::DictionarySP GetStructuredData() {
  44. return m_dict_sp;
  45. }
  46. const std::string &GetName() {
  47. return m_name;
  48. }
  49. protected:
  50. std::string m_name;
  51. std::string m_current_key;
  52. StructuredData::DictionarySP m_dict_sp;
  53. std::string m_class_usage_text, m_key_usage_text, m_value_usage_text;
  54. bool m_is_class;
  55. OptionDefinition m_option_definition[4];
  56. Flags m_required_options;
  57. };
  58. } // namespace lldb_private
  59. #endif // LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H