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
30OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) const {
31 return FormatManager::GetFormatAsCString(format: m_current_value);
32}
33
34Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
35 VarSetOperationType op) {
36 Status error;
37 switch (op) {
38 case eVarSetOperationClear:
39 Clear();
40 NotifyValueChanged();
41 break;
42
43 case eVarSetOperationReplace:
44 case eVarSetOperationAssign: {
45 Format new_format;
46 error = OptionArgParser::ToFormat(s: value.str().c_str(), format&: new_format, byte_size_ptr: nullptr);
47 if (error.Success()) {
48 m_value_was_set = true;
49 m_current_value = new_format;
50 NotifyValueChanged();
51 }
52 } break;
53
54 case eVarSetOperationInsertBefore:
55 case eVarSetOperationInsertAfter:
56 case eVarSetOperationRemove:
57 case eVarSetOperationAppend:
58 case eVarSetOperationInvalid:
59 error = OptionValue::SetValueFromString(value, op);
60 break;
61 }
62 return error;
63}
64

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

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