1*80814287SRaphael Isemann //===-- OptionValueFormat.cpp ---------------------------------------------===//
267cc0636SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
667cc0636SGreg Clayton //
767cc0636SGreg Clayton //===----------------------------------------------------------------------===//
867cc0636SGreg Clayton
967cc0636SGreg Clayton #include "lldb/Interpreter/OptionValueFormat.h"
1067cc0636SGreg Clayton
115548cb50SEnrico Granata #include "lldb/DataFormatters/FormatManager.h"
1247cbf4a0SPavel Labath #include "lldb/Interpreter/OptionArgParser.h"
13bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
1467cc0636SGreg Clayton
1567cc0636SGreg Clayton using namespace lldb;
1667cc0636SGreg Clayton using namespace lldb_private;
1767cc0636SGreg Clayton
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)18b9c1b51eSKate Stone void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
19b9c1b51eSKate Stone uint32_t dump_mask) {
2067cc0636SGreg Clayton if (dump_mask & eDumpOptionType)
2167cc0636SGreg Clayton strm.Printf("(%s)", GetTypeAsCString());
22b9c1b51eSKate Stone if (dump_mask & eDumpOptionValue) {
2367cc0636SGreg Clayton if (dump_mask & eDumpOptionType)
2467cc0636SGreg Clayton strm.PutCString(" = ");
2567cc0636SGreg Clayton strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
2667cc0636SGreg Clayton }
2767cc0636SGreg Clayton }
2867cc0636SGreg Clayton
SetValueFromString(llvm::StringRef value,VarSetOperationType op)2997206d57SZachary Turner Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
30b9c1b51eSKate Stone VarSetOperationType op) {
3197206d57SZachary Turner Status error;
32b9c1b51eSKate Stone switch (op) {
3367cc0636SGreg Clayton case eVarSetOperationClear:
3467cc0636SGreg Clayton Clear();
35332e8b1cSGreg Clayton NotifyValueChanged();
3667cc0636SGreg Clayton break;
3767cc0636SGreg Clayton
3867cc0636SGreg Clayton case eVarSetOperationReplace:
39b9c1b51eSKate Stone case eVarSetOperationAssign: {
4067cc0636SGreg Clayton Format new_format;
4147cbf4a0SPavel Labath error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);
42b9c1b51eSKate Stone if (error.Success()) {
4367cc0636SGreg Clayton m_value_was_set = true;
4467cc0636SGreg Clayton m_current_value = new_format;
45332e8b1cSGreg Clayton NotifyValueChanged();
4667cc0636SGreg Clayton }
47b9c1b51eSKate Stone } break;
4867cc0636SGreg Clayton
4967cc0636SGreg Clayton case eVarSetOperationInsertBefore:
5067cc0636SGreg Clayton case eVarSetOperationInsertAfter:
5167cc0636SGreg Clayton case eVarSetOperationRemove:
5267cc0636SGreg Clayton case eVarSetOperationAppend:
5367cc0636SGreg Clayton case eVarSetOperationInvalid:
54c95f7e2aSPavel Labath error = OptionValue::SetValueFromString(value, op);
5567cc0636SGreg Clayton break;
5667cc0636SGreg Clayton }
5767cc0636SGreg Clayton return error;
5867cc0636SGreg Clayton }
59