| 1 | //===-- OptionValueLanguage.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/OptionValueLanguage.h" |
| 10 | |
| 11 | #include "lldb/DataFormatters/FormatManager.h" |
| 12 | #include "lldb/Target/Language.h" |
| 13 | #include "lldb/Symbol/TypeSystem.h" |
| 14 | #include "lldb/Utility/Args.h" |
| 15 | #include "lldb/Utility/Stream.h" |
| 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
| 20 | void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx, |
| 21 | Stream &strm, uint32_t dump_mask) { |
| 22 | if (dump_mask & eDumpOptionType) |
| 23 | strm.Printf(format: "(%s)", GetTypeAsCString()); |
| 24 | if (dump_mask & eDumpOptionValue) { |
| 25 | if (dump_mask & eDumpOptionType) |
| 26 | strm.PutCString(cstr: " = "); |
| 27 | if (m_current_value != eLanguageTypeUnknown) |
| 28 | strm.PutCString(cstr: Language::GetNameForLanguageType(language: m_current_value)); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | llvm::json::Value |
| 33 | OptionValueLanguage::ToJSON(const ExecutionContext *exe_ctx) const { |
| 34 | return Language::GetNameForLanguageType(language: m_current_value); |
| 35 | } |
| 36 | |
| 37 | Status OptionValueLanguage::SetValueFromString(llvm::StringRef value, |
| 38 | VarSetOperationType op) { |
| 39 | Status error; |
| 40 | switch (op) { |
| 41 | case eVarSetOperationClear: |
| 42 | Clear(); |
| 43 | break; |
| 44 | |
| 45 | case eVarSetOperationReplace: |
| 46 | case eVarSetOperationAssign: { |
| 47 | LanguageSet languages_for_types = Language::GetLanguagesSupportingTypeSystems(); |
| 48 | LanguageType new_type = Language::GetLanguageTypeFromString(string: value.trim()); |
| 49 | if (new_type && languages_for_types[new_type]) { |
| 50 | m_value_was_set = true; |
| 51 | m_current_value = new_type; |
| 52 | } else { |
| 53 | StreamString error_strm; |
| 54 | error_strm.Printf(format: "invalid language type '%s', ", value.str().c_str()); |
| 55 | error_strm.Printf(format: "valid values are:\n"); |
| 56 | for (int bit : languages_for_types.bitvector.set_bits()) { |
| 57 | auto language = (LanguageType)bit; |
| 58 | error_strm.Printf(format: " %s\n", |
| 59 | Language::GetNameForLanguageType(language)); |
| 60 | } |
| 61 | error = Status(error_strm.GetString().str()); |
| 62 | } |
| 63 | } break; |
| 64 | |
| 65 | case eVarSetOperationInsertBefore: |
| 66 | case eVarSetOperationInsertAfter: |
| 67 | case eVarSetOperationRemove: |
| 68 | case eVarSetOperationAppend: |
| 69 | case eVarSetOperationInvalid: |
| 70 | error = OptionValue::SetValueFromString(value, op); |
| 71 | break; |
| 72 | } |
| 73 | return error; |
| 74 | } |
| 75 |
