LLDB  mainline
OptionValueLanguage.cpp
Go to the documentation of this file.
1 //===-- OptionValueLanguage.cpp ---------------------------------*- C++ -*-===//
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 
10 
12 #include "lldb/Target/Language.h"
13 #include "lldb/Utility/Args.h"
14 #include "lldb/Utility/Stream.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
20  Stream &strm, uint32_t dump_mask) {
21  if (dump_mask & eDumpOptionType)
22  strm.Printf("(%s)", GetTypeAsCString());
23  if (dump_mask & eDumpOptionValue) {
24  if (dump_mask & eDumpOptionType)
25  strm.PutCString(" = ");
26  if (m_current_value != eLanguageTypeUnknown)
27  strm.PutCString(Language::GetNameForLanguageType(m_current_value));
28  }
29 }
30 
31 Status OptionValueLanguage::SetValueFromString(llvm::StringRef value,
33  Status error;
34  switch (op) {
36  Clear();
37  break;
38 
41  ConstString lang_name(value.trim());
42  std::set<lldb::LanguageType> languages_for_types;
43  std::set<lldb::LanguageType> languages_for_expressions;
44  Language::GetLanguagesSupportingTypeSystems(languages_for_types,
45  languages_for_expressions);
46 
47  LanguageType new_type =
48  Language::GetLanguageTypeFromString(lang_name.GetStringRef());
49  if (new_type && languages_for_types.count(new_type)) {
50  m_value_was_set = true;
51  m_current_value = new_type;
52  } else {
53  StreamString error_strm;
54  error_strm.Printf("invalid language type '%s', ", value.str().c_str());
55  error_strm.Printf("valid values are:\n");
56  for (lldb::LanguageType language : languages_for_types) {
57  error_strm.Printf("%s%s%s", " ",
58  Language::GetNameForLanguageType(language), "\n");
59  }
60  error.SetErrorString(error_strm.GetString());
61  }
62  } break;
63 
69  error = OptionValue::SetValueFromString(value, op);
70  break;
71  }
72  return error;
73 }
74 
75 lldb::OptionValueSP OptionValueLanguage::DeepCopy() const {
76  return OptionValueSP(new OptionValueLanguage(*this));
77 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
LanguageType
Programming language type.
VarSetOperationType
Settable state variable types.
llvm::StringRef GetString() const
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
A uniqued constant string class.
Definition: ConstString.h:38
Unknown or invalid language value.
Definition: SBAddress.h:15
static bool DumpValue(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const FormatEntity::Entry &entry, ValueObject *valobj)
An error handling class.
Definition: Status.h:44