1cfca06d7SDimitry Andric //===-- OptionValueFormat.cpp ---------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/Interpreter/OptionValueFormat.h"
10f034231aSEd Maste
11f034231aSEd Maste #include "lldb/DataFormatters/FormatManager.h"
12f73363f1SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h"
1374a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
14f034231aSEd Maste
15f034231aSEd Maste using namespace lldb;
16f034231aSEd Maste using namespace lldb_private;
17f034231aSEd Maste
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)1814f1b3e8SDimitry Andric void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
1914f1b3e8SDimitry Andric uint32_t dump_mask) {
20f034231aSEd Maste if (dump_mask & eDumpOptionType)
21f034231aSEd Maste strm.Printf("(%s)", GetTypeAsCString());
2214f1b3e8SDimitry Andric if (dump_mask & eDumpOptionValue) {
23f034231aSEd Maste if (dump_mask & eDumpOptionType)
24f034231aSEd Maste strm.PutCString(" = ");
25f034231aSEd Maste strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
26f034231aSEd Maste }
27f034231aSEd Maste }
28f034231aSEd Maste
ToJSON(const ExecutionContext * exe_ctx)29e3b55780SDimitry Andric llvm::json::Value OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) {
30e3b55780SDimitry Andric return FormatManager::GetFormatAsCString(m_current_value);
31e3b55780SDimitry Andric }
32e3b55780SDimitry Andric
SetValueFromString(llvm::StringRef value,VarSetOperationType op)33b76161e4SDimitry Andric Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
3414f1b3e8SDimitry Andric VarSetOperationType op) {
35b76161e4SDimitry Andric Status error;
3614f1b3e8SDimitry Andric switch (op) {
37f034231aSEd Maste case eVarSetOperationClear:
38f034231aSEd Maste Clear();
39205afe67SEd Maste NotifyValueChanged();
40f034231aSEd Maste break;
41f034231aSEd Maste
42f034231aSEd Maste case eVarSetOperationReplace:
4314f1b3e8SDimitry Andric case eVarSetOperationAssign: {
44f034231aSEd Maste Format new_format;
45f73363f1SDimitry Andric error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);
4614f1b3e8SDimitry Andric if (error.Success()) {
47f034231aSEd Maste m_value_was_set = true;
48f034231aSEd Maste m_current_value = new_format;
49205afe67SEd Maste NotifyValueChanged();
50f034231aSEd Maste }
5114f1b3e8SDimitry Andric } break;
52f034231aSEd Maste
53f034231aSEd Maste case eVarSetOperationInsertBefore:
54f034231aSEd Maste case eVarSetOperationInsertAfter:
55f034231aSEd Maste case eVarSetOperationRemove:
56f034231aSEd Maste case eVarSetOperationAppend:
57f034231aSEd Maste case eVarSetOperationInvalid:
585e95aa85SEd Maste error = OptionValue::SetValueFromString(value, op);
59f034231aSEd Maste break;
60f034231aSEd Maste }
61f034231aSEd Maste return error;
62f034231aSEd Maste }
63