LLDB  mainline
OptionValueLanguage.cpp
Go to the documentation of this file.
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 
10 
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 
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));
29  }
30 }
31 
32 Status OptionValueLanguage::SetValueFromString(llvm::StringRef value,
34  Status error;
35  switch (op) {
37  Clear();
38  break;
39 
42  ConstString lang_name(value.trim());
43  LanguageSet languages_for_types = Language::GetLanguagesSupportingTypeSystems();
44  LanguageType new_type =
45  Language::GetLanguageTypeFromString(lang_name.GetStringRef());
46  if (new_type && languages_for_types[new_type]) {
47  m_value_was_set = true;
48  m_current_value = new_type;
49  } else {
50  StreamString error_strm;
51  error_strm.Printf("invalid language type '%s', ", value.str().c_str());
52  error_strm.Printf("valid values are:\n");
53  for (int bit : languages_for_types.bitvector.set_bits()) {
54  auto language = (LanguageType)bit;
55  error_strm.Printf(" %s\n",
56  Language::GetNameForLanguageType(language));
57  }
58  error.SetErrorString(error_strm.GetString());
59  }
60  } break;
61 
67  error = OptionValue::SetValueFromString(value, op);
68  break;
69  }
70  return error;
71 }
lldb_private::eVarSetOperationInsertBefore
@ eVarSetOperationInsertBefore
Definition: lldb-private-enumerations.h:85
lldb_private::eVarSetOperationReplace
@ eVarSetOperationReplace
Definition: lldb-private-enumerations.h:84
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
FormatManager.h
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::Stream
Definition: Stream.h:28
Language.h
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::VarSetOperationType
VarSetOperationType
Settable state variable types.
Definition: lldb-private-enumerations.h:83
lldb_private::LanguageSet::bitvector
llvm::SmallBitVector bitvector
Definition: TypeSystem.h:41
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
Args.h
OptionValueLanguage.h
lldb_private::eVarSetOperationAppend
@ eVarSetOperationAppend
Definition: lldb-private-enumerations.h:88
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
bit
#define bit
Definition: EmulateInstructionARM64.cpp:73
TypeSystem.h
lldb_private::Status
Definition: Status.h:44
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
uint32_t
lldb_private::eVarSetOperationRemove
@ eVarSetOperationRemove
Definition: lldb-private-enumerations.h:87
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::LanguageSet
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:40
lldb_private::eVarSetOperationInvalid
@ eVarSetOperationInvalid
Definition: lldb-private-enumerations.h:91
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb
Definition: SBAddress.h:15
lldb_private::eVarSetOperationClear
@ eVarSetOperationClear
Definition: lldb-private-enumerations.h:89
DumpValue
static bool DumpValue(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const FormatEntity::Entry &entry, ValueObject *valobj)
Definition: FormatEntity.cpp:673
lldb_private::eVarSetOperationInsertAfter
@ eVarSetOperationInsertAfter
Definition: lldb-private-enumerations.h:86
lldb_private::eVarSetOperationAssign
@ eVarSetOperationAssign
Definition: lldb-private-enumerations.h:90