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 OptionValueLanguage::ToJSON(const ExecutionContext *exe_ctx) { |
33 | return Language::GetNameForLanguageType(language: m_current_value); |
34 | } |
35 | |
36 | Status OptionValueLanguage::SetValueFromString(llvm::StringRef value, |
37 | VarSetOperationType op) { |
38 | Status error; |
39 | switch (op) { |
40 | case eVarSetOperationClear: |
41 | Clear(); |
42 | break; |
43 | |
44 | case eVarSetOperationReplace: |
45 | case eVarSetOperationAssign: { |
46 | LanguageSet languages_for_types = Language::GetLanguagesSupportingTypeSystems(); |
47 | LanguageType new_type = Language::GetLanguageTypeFromString(string: value.trim()); |
48 | if (new_type && languages_for_types[new_type]) { |
49 | m_value_was_set = true; |
50 | m_current_value = new_type; |
51 | } else { |
52 | StreamString error_strm; |
53 | error_strm.Printf(format: "invalid language type '%s', ", value.str().c_str()); |
54 | error_strm.Printf(format: "valid values are:\n"); |
55 | for (int bit : languages_for_types.bitvector.set_bits()) { |
56 | auto language = (LanguageType)bit; |
57 | error_strm.Printf(format: " %s\n", |
58 | Language::GetNameForLanguageType(language)); |
59 | } |
60 | error.SetErrorString(error_strm.GetString()); |
61 | } |
62 | } break; |
63 | |
64 | case eVarSetOperationInsertBefore: |
65 | case eVarSetOperationInsertAfter: |
66 | case eVarSetOperationRemove: |
67 | case eVarSetOperationAppend: |
68 | case eVarSetOperationInvalid: |
69 | error = OptionValue::SetValueFromString(value, op); |
70 | break; |
71 | } |
72 | return error; |
73 | } |
74 |