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 15 using namespace lldb; 16 using namespace lldb_private; 17 18 void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 19 uint32_t dump_mask) { 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)); 26 } 27 } 28 29 Status OptionValueFormat::SetValueFromString(llvm::StringRef value, 30 VarSetOperationType op) { 31 Status error; 32 switch (op) { 33 case eVarSetOperationClear: 34 Clear(); 35 NotifyValueChanged(); 36 break; 37 38 case eVarSetOperationReplace: 39 case eVarSetOperationAssign: { 40 Format new_format; 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; 45 NotifyValueChanged(); 46 } 47 } break; 48 49 case eVarSetOperationInsertBefore: 50 case eVarSetOperationInsertAfter: 51 case eVarSetOperationRemove: 52 case eVarSetOperationAppend: 53 case eVarSetOperationInvalid: 54 error = OptionValue::SetValueFromString(value, op); 55 break; 56 } 57 return error; 58 } 59