15ffd83dbSDimitry Andric //===-- OptionValueFormat.cpp ---------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/Interpreter/OptionValueFormat.h"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric #include "lldb/DataFormatters/FormatManager.h"
120b57cec5SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h"
130b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric using namespace lldb;
160b57cec5SDimitry Andric using namespace lldb_private;
170b57cec5SDimitry Andric
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)180b57cec5SDimitry Andric void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
190b57cec5SDimitry Andric uint32_t dump_mask) {
200b57cec5SDimitry Andric if (dump_mask & eDumpOptionType)
210b57cec5SDimitry Andric strm.Printf("(%s)", GetTypeAsCString());
220b57cec5SDimitry Andric if (dump_mask & eDumpOptionValue) {
230b57cec5SDimitry Andric if (dump_mask & eDumpOptionType)
240b57cec5SDimitry Andric strm.PutCString(" = ");
250b57cec5SDimitry Andric strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
260b57cec5SDimitry Andric }
270b57cec5SDimitry Andric }
280b57cec5SDimitry Andric
ToJSON(const ExecutionContext * exe_ctx)29*bdd1243dSDimitry Andric llvm::json::Value OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) {
30*bdd1243dSDimitry Andric return FormatManager::GetFormatAsCString(m_current_value);
31*bdd1243dSDimitry Andric }
32*bdd1243dSDimitry Andric
SetValueFromString(llvm::StringRef value,VarSetOperationType op)330b57cec5SDimitry Andric Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
340b57cec5SDimitry Andric VarSetOperationType op) {
350b57cec5SDimitry Andric Status error;
360b57cec5SDimitry Andric switch (op) {
370b57cec5SDimitry Andric case eVarSetOperationClear:
380b57cec5SDimitry Andric Clear();
390b57cec5SDimitry Andric NotifyValueChanged();
400b57cec5SDimitry Andric break;
410b57cec5SDimitry Andric
420b57cec5SDimitry Andric case eVarSetOperationReplace:
430b57cec5SDimitry Andric case eVarSetOperationAssign: {
440b57cec5SDimitry Andric Format new_format;
450b57cec5SDimitry Andric error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);
460b57cec5SDimitry Andric if (error.Success()) {
470b57cec5SDimitry Andric m_value_was_set = true;
480b57cec5SDimitry Andric m_current_value = new_format;
490b57cec5SDimitry Andric NotifyValueChanged();
500b57cec5SDimitry Andric }
510b57cec5SDimitry Andric } break;
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric case eVarSetOperationInsertBefore:
540b57cec5SDimitry Andric case eVarSetOperationInsertAfter:
550b57cec5SDimitry Andric case eVarSetOperationRemove:
560b57cec5SDimitry Andric case eVarSetOperationAppend:
570b57cec5SDimitry Andric case eVarSetOperationInvalid:
580b57cec5SDimitry Andric error = OptionValue::SetValueFromString(value, op);
590b57cec5SDimitry Andric break;
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric return error;
620b57cec5SDimitry Andric }
63