1cfca06d7SDimitry Andric //===-- OptionValueLanguage.cpp -------------------------------------------===//
25e95aa85SEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65e95aa85SEd Maste //
75e95aa85SEd Maste //===----------------------------------------------------------------------===//
85e95aa85SEd Maste
95e95aa85SEd Maste #include "lldb/Interpreter/OptionValueLanguage.h"
105e95aa85SEd Maste
115e95aa85SEd Maste #include "lldb/DataFormatters/FormatManager.h"
12e81d9d49SDimitry Andric #include "lldb/Target/Language.h"
13ead24645SDimitry Andric #include "lldb/Symbol/TypeSystem.h"
14f73363f1SDimitry Andric #include "lldb/Utility/Args.h"
1574a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
165e95aa85SEd Maste
175e95aa85SEd Maste using namespace lldb;
185e95aa85SEd Maste using namespace lldb_private;
195e95aa85SEd Maste
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)2014f1b3e8SDimitry Andric void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx,
2114f1b3e8SDimitry Andric Stream &strm, uint32_t dump_mask) {
225e95aa85SEd Maste if (dump_mask & eDumpOptionType)
235e95aa85SEd Maste strm.Printf("(%s)", GetTypeAsCString());
2414f1b3e8SDimitry Andric if (dump_mask & eDumpOptionValue) {
255e95aa85SEd Maste if (dump_mask & eDumpOptionType)
265e95aa85SEd Maste strm.PutCString(" = ");
2794994d37SDimitry Andric if (m_current_value != eLanguageTypeUnknown)
28e81d9d49SDimitry Andric strm.PutCString(Language::GetNameForLanguageType(m_current_value));
295e95aa85SEd Maste }
305e95aa85SEd Maste }
315e95aa85SEd Maste
ToJSON(const ExecutionContext * exe_ctx)32e3b55780SDimitry Andric llvm::json::Value OptionValueLanguage::ToJSON(const ExecutionContext *exe_ctx) {
33e3b55780SDimitry Andric return Language::GetNameForLanguageType(m_current_value);
34e3b55780SDimitry Andric }
35e3b55780SDimitry Andric
SetValueFromString(llvm::StringRef value,VarSetOperationType op)36b76161e4SDimitry Andric Status OptionValueLanguage::SetValueFromString(llvm::StringRef value,
3714f1b3e8SDimitry Andric VarSetOperationType op) {
38b76161e4SDimitry Andric Status error;
3914f1b3e8SDimitry Andric switch (op) {
405e95aa85SEd Maste case eVarSetOperationClear:
415e95aa85SEd Maste Clear();
425e95aa85SEd Maste break;
435e95aa85SEd Maste
445e95aa85SEd Maste case eVarSetOperationReplace:
4514f1b3e8SDimitry Andric case eVarSetOperationAssign: {
46ead24645SDimitry Andric LanguageSet languages_for_types = Language::GetLanguagesSupportingTypeSystems();
477fa27ce4SDimitry Andric LanguageType new_type = Language::GetLanguageTypeFromString(value.trim());
48ead24645SDimitry Andric if (new_type && languages_for_types[new_type]) {
495e95aa85SEd Maste m_value_was_set = true;
505e95aa85SEd Maste m_current_value = new_type;
5114f1b3e8SDimitry Andric } else {
52e81d9d49SDimitry Andric StreamString error_strm;
53e81d9d49SDimitry Andric error_strm.Printf("invalid language type '%s', ", value.str().c_str());
54e81d9d49SDimitry Andric error_strm.Printf("valid values are:\n");
55ead24645SDimitry Andric for (int bit : languages_for_types.bitvector.set_bits()) {
56ead24645SDimitry Andric auto language = (LanguageType)bit;
57ead24645SDimitry Andric error_strm.Printf(" %s\n",
58ead24645SDimitry Andric Language::GetNameForLanguageType(language));
59e81d9d49SDimitry Andric }
6014f1b3e8SDimitry Andric error.SetErrorString(error_strm.GetString());
61e81d9d49SDimitry Andric }
6214f1b3e8SDimitry Andric } break;
635e95aa85SEd Maste
645e95aa85SEd Maste case eVarSetOperationInsertBefore:
655e95aa85SEd Maste case eVarSetOperationInsertAfter:
665e95aa85SEd Maste case eVarSetOperationRemove:
675e95aa85SEd Maste case eVarSetOperationAppend:
685e95aa85SEd Maste case eVarSetOperationInvalid:
695e95aa85SEd Maste error = OptionValue::SetValueFromString(value, op);
705e95aa85SEd Maste break;
715e95aa85SEd Maste }
725e95aa85SEd Maste return error;
735e95aa85SEd Maste }
74