1 //===-- OptionValueFormat.cpp ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionValueFormat.h"
11 #include "lldb/DataFormatters/FormatManager.h"
12 #include "lldb/Interpreter/OptionArgParser.h"
13 #include "lldb/Utility/Stream.h"
16 using namespace lldb_private
;
18 void OptionValueFormat::DumpValue(const ExecutionContext
*exe_ctx
, Stream
&strm
,
20 if (dump_mask
& eDumpOptionType
)
21 strm
.Printf("(%s)", GetTypeAsCString());
22 if (dump_mask
& eDumpOptionValue
) {
23 if (dump_mask
& eDumpOptionType
)
24 strm
.PutCString(" = ");
25 strm
.PutCString(FormatManager::GetFormatAsCString(m_current_value
));
29 llvm::json::Value
OptionValueFormat::ToJSON(const ExecutionContext
*exe_ctx
) {
30 return FormatManager::GetFormatAsCString(m_current_value
);
33 Status
OptionValueFormat::SetValueFromString(llvm::StringRef value
,
34 VarSetOperationType op
) {
37 case eVarSetOperationClear
:
42 case eVarSetOperationReplace
:
43 case eVarSetOperationAssign
: {
45 error
= OptionArgParser::ToFormat(value
.str().c_str(), new_format
, nullptr);
46 if (error
.Success()) {
47 m_value_was_set
= true;
48 m_current_value
= new_format
;
53 case eVarSetOperationInsertBefore
:
54 case eVarSetOperationInsertAfter
:
55 case eVarSetOperationRemove
:
56 case eVarSetOperationAppend
:
57 case eVarSetOperationInvalid
:
58 error
= OptionValue::SetValueFromString(value
, op
);