2016-11-26 13:23:44 +08:00
|
|
|
//===-- OptionValueLanguage.cpp ---------------------------------*- C++ -*-===//
|
2015-02-21 03:46:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-21 03:46:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionValueLanguage.h"
|
|
|
|
|
|
|
|
#include "lldb/DataFormatters/FormatManager.h"
|
2015-09-02 09:06:46 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2015-02-21 03:46:30 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx,
|
|
|
|
Stream &strm, uint32_t dump_mask) {
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.Printf("(%s)", GetTypeAsCString());
|
|
|
|
if (dump_mask & eDumpOptionValue) {
|
2015-02-21 03:46:30 +08:00
|
|
|
if (dump_mask & eDumpOptionType)
|
2016-09-07 04:57:50 +08:00
|
|
|
strm.PutCString(" = ");
|
2018-10-26 08:00:17 +08:00
|
|
|
if (m_current_value != eLanguageTypeUnknown)
|
|
|
|
strm.PutCString(Language::GetNameForLanguageType(m_current_value));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-02-21 03:46:30 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValueLanguage::SetValueFromString(llvm::StringRef value,
|
|
|
|
VarSetOperationType op) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
switch (op) {
|
|
|
|
case eVarSetOperationClear:
|
|
|
|
Clear();
|
|
|
|
break;
|
2015-10-09 07:07:53 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
case eVarSetOperationReplace:
|
|
|
|
case eVarSetOperationAssign: {
|
|
|
|
ConstString lang_name(value.trim());
|
|
|
|
std::set<lldb::LanguageType> languages_for_types;
|
|
|
|
std::set<lldb::LanguageType> languages_for_expressions;
|
|
|
|
Language::GetLanguagesSupportingTypeSystems(languages_for_types,
|
|
|
|
languages_for_expressions);
|
2015-02-21 03:46:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
LanguageType new_type =
|
2016-09-17 10:00:02 +08:00
|
|
|
Language::GetLanguageTypeFromString(lang_name.GetStringRef());
|
2016-09-07 04:57:50 +08:00
|
|
|
if (new_type && languages_for_types.count(new_type)) {
|
|
|
|
m_value_was_set = true;
|
|
|
|
m_current_value = new_type;
|
|
|
|
} else {
|
|
|
|
StreamString error_strm;
|
|
|
|
error_strm.Printf("invalid language type '%s', ", value.str().c_str());
|
|
|
|
error_strm.Printf("valid values are:\n");
|
|
|
|
for (lldb::LanguageType language : languages_for_types) {
|
|
|
|
error_strm.Printf("%s%s%s", " ",
|
|
|
|
Language::GetNameForLanguageType(language), "\n");
|
|
|
|
}
|
2016-11-17 05:15:24 +08:00
|
|
|
error.SetErrorString(error_strm.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} break;
|
2015-02-21 03:46:30 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
case eVarSetOperationRemove:
|
|
|
|
case eVarSetOperationAppend:
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
error = OptionValue::SetValueFromString(value, op);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
2015-02-21 03:46:30 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::OptionValueSP OptionValueLanguage::DeepCopy() const {
|
|
|
|
return OptionValueSP(new OptionValueLanguage(*this));
|
|
|
|
}
|