[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / source / Interpreter / OptionValueLanguage.cpp
blobeb8eef0c600b2293c2e48454daad43ed94dbf7c8
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionValueLanguage.h"
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"
17 using namespace lldb;
18 using namespace lldb_private;
20 void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx,
21 Stream &strm, uint32_t dump_mask) {
22 if (dump_mask & eDumpOptionType)
23 strm.Printf("(%s)", GetTypeAsCString());
24 if (dump_mask & eDumpOptionValue) {
25 if (dump_mask & eDumpOptionType)
26 strm.PutCString(" = ");
27 if (m_current_value != eLanguageTypeUnknown)
28 strm.PutCString(Language::GetNameForLanguageType(m_current_value));
32 llvm::json::Value OptionValueLanguage::ToJSON(const ExecutionContext *exe_ctx) {
33 return Language::GetNameForLanguageType(m_current_value);
36 Status OptionValueLanguage::SetValueFromString(llvm::StringRef value,
37 VarSetOperationType op) {
38 Status error;
39 switch (op) {
40 case eVarSetOperationClear:
41 Clear();
42 break;
44 case eVarSetOperationReplace:
45 case eVarSetOperationAssign: {
46 LanguageSet languages_for_types = Language::GetLanguagesSupportingTypeSystems();
47 LanguageType new_type = Language::GetLanguageTypeFromString(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("invalid language type '%s', ", value.str().c_str());
54 error_strm.Printf("valid values are:\n");
55 for (int bit : languages_for_types.bitvector.set_bits()) {
56 auto language = (LanguageType)bit;
57 error_strm.Printf(" %s\n",
58 Language::GetNameForLanguageType(language));
60 error = Status(error_strm.GetString().str());
62 } break;
64 case eVarSetOperationInsertBefore:
65 case eVarSetOperationInsertAfter:
66 case eVarSetOperationRemove:
67 case eVarSetOperationAppend:
68 case eVarSetOperationInvalid:
69 error = OptionValue::SetValueFromString(value, op);
70 break;
72 return error;