1 //===-- OptionValueFormat.cpp -----------------------------------*- C++ -*-===//
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 Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
30 VarSetOperationType op) {
33 case eVarSetOperationClear:
38 case eVarSetOperationReplace:
39 case eVarSetOperationAssign: {
41 error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);
42 if (error.Success()) {
43 m_value_was_set = true;
44 m_current_value = new_format;
49 case eVarSetOperationInsertBefore:
50 case eVarSetOperationInsertAfter:
51 case eVarSetOperationRemove:
52 case eVarSetOperationAppend:
53 case eVarSetOperationInvalid:
54 error = OptionValue::SetValueFromString(value, op);
60 lldb::OptionValueSP OptionValueFormat::DeepCopy() const {
61 return OptionValueSP(new OptionValueFormat(*this));