1//===-- OptionValueFormat.cpp ---------------------------------------------===//
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#include "lldb/Interpreter/OptionValueFormat.h"
10
11#include "lldb/DataFormatters/FormatManager.h"
12#include "lldb/Interpreter/OptionArgParser.h"
13#include "lldb/Utility/Stream.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
18void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
19 uint32_t dump_mask) {
20 if (dump_mask & eDumpOptionType)
21 strm.Printf(format: "(%s)", GetTypeAsCString());
22 if (dump_mask & eDumpOptionValue) {
23 if (dump_mask & eDumpOptionType)
24 strm.PutCString(cstr: " = ");
25 strm.PutCString(cstr: FormatManager::GetFormatAsCString(format: m_current_value));
26 }
27}
28
29llvm::json::Value OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) {
30 return FormatManager::GetFormatAsCString(format: m_current_value);
31}
32
33Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
34 VarSetOperationType op) {
35 Status error;
36 switch (op) {
37 case eVarSetOperationClear:
38 Clear();
39 NotifyValueChanged();
40 break;
41
42 case eVarSetOperationReplace:
43 case eVarSetOperationAssign: {
44 Format new_format;
45 error = OptionArgParser::ToFormat(s: value.str().c_str(), format&: new_format, byte_size_ptr: nullptr);
46 if (error.Success()) {
47 m_value_was_set = true;
48 m_current_value = new_format;
49 NotifyValueChanged();
50 }
51 } break;
52
53 case eVarSetOperationInsertBefore:
54 case eVarSetOperationInsertAfter:
55 case eVarSetOperationRemove:
56 case eVarSetOperationAppend:
57 case eVarSetOperationInvalid:
58 error = OptionValue::SetValueFromString(value, op);
59 break;
60 }
61 return error;
62}
63

source code of lldb/source/Interpreter/OptionValueFormat.cpp