Skip to content

Commit e82cc29

Browse files
committed
Add OptionValueFormatEntityList
1 parent 409ca49 commit e82cc29

File tree

8 files changed

+331
-3
lines changed

8 files changed

+331
-3
lines changed

lldb/include/lldb/Interpreter/OptionValue.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class OptionValue {
5151
eTypeString,
5252
eTypeUInt64,
5353
eTypeUUID,
54-
eTypeFormatEntity
54+
eTypeFormatEntity,
55+
eTypeFormatEntityList,
5556
};
5657

5758
enum {
@@ -72,7 +73,7 @@ class OptionValue {
7273
virtual ~OptionValue() = default;
7374

7475
OptionValue(const OptionValue &other);
75-
76+
7677
OptionValue& operator=(const OptionValue &other);
7778

7879
// Subclasses should override these functions
@@ -249,6 +250,9 @@ class OptionValue {
249250
OptionValueFormatEntity *GetAsFormatEntity();
250251
const OptionValueFormatEntity *GetAsFormatEntity() const;
251252

253+
OptionValueFormatEntityList *GetAsFormatEntityList();
254+
const OptionValueFormatEntityList *GetAsFormatEntityList() const;
255+
252256
bool AppendFileSpecValue(FileSpec file_spec);
253257

254258
bool OptionWasSet() const { return m_value_was_set; }
@@ -286,6 +290,8 @@ class OptionValue {
286290
return GetFileSpecValue();
287291
if constexpr (std::is_same_v<T, FileSpecList>)
288292
return GetFileSpecListValue();
293+
if constexpr (std::is_same_v<T, std::vector<FormatEntity::Entry>>)
294+
return GetFormatEntityList();
289295
if constexpr (std::is_same_v<T, lldb::LanguageType>)
290296
return GetLanguageValue();
291297
if constexpr (std::is_same_v<T, llvm::StringRef>)
@@ -387,8 +393,9 @@ class OptionValue {
387393
bool SetUUIDValue(const UUID &uuid);
388394

389395
const FormatEntity::Entry *GetFormatEntity() const;
396+
std::vector<FormatEntity::Entry> GetFormatEntityList() const;
390397
const RegularExpression *GetRegexValue() const;
391-
398+
392399
mutable std::mutex m_mutex;
393400
};
394401

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//===-- OptionValueFormatEntityList.h --------------------------------*-
2+
// C++-*-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLDB_INTERPRETER_OPTIONVALUEFORMATENTITYLIST_H
11+
#define LLDB_INTERPRETER_OPTIONVALUEFORMATENTITYLIST_H
12+
13+
#include "lldb/Core/FormatEntity.h"
14+
#include "lldb/Interpreter/OptionValue.h"
15+
16+
namespace lldb_private {
17+
18+
class OptionValueFormatEntityList
19+
: public Cloneable<OptionValueFormatEntityList, OptionValue> {
20+
public:
21+
OptionValueFormatEntityList();
22+
23+
OptionValueFormatEntityList(const OptionValueFormatEntityList &other)
24+
: Cloneable(other), m_current_entries(other.m_current_entries),
25+
m_current_formats(other.m_current_formats) {}
26+
27+
~OptionValueFormatEntityList() override = default;
28+
29+
// Virtual subclass pure virtual overrides
30+
31+
OptionValue::Type GetType() const override { return eTypeFormatEntityList; }
32+
33+
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
34+
uint32_t dump_mask) override;
35+
36+
Status
37+
SetValueFromString(llvm::StringRef value,
38+
VarSetOperationType op = eVarSetOperationAssign) override;
39+
40+
void Clear() override;
41+
42+
std::vector<FormatEntity::Entry> GetCurrentValue() const {
43+
std::lock_guard<std::recursive_mutex> lock(m_mutex);
44+
return m_current_entries;
45+
}
46+
47+
protected:
48+
llvm::Error Append(llvm::StringRef str);
49+
llvm::Error Insert(size_t idx, llvm::StringRef str);
50+
llvm::Error Replace(size_t idx, llvm::StringRef str);
51+
llvm::Error Remove(size_t idx);
52+
53+
lldb::OptionValueSP Clone() const override;
54+
55+
std::vector<FormatEntity::Entry> m_current_entries;
56+
std::vector<std::string> m_current_formats;
57+
mutable std::recursive_mutex m_mutex;
58+
};
59+
60+
} // namespace lldb_private
61+
62+
#endif // LLDB_INTERPRETER_OPTIONVALUEFORMATENTITYLIST_H

lldb/include/lldb/Interpreter/OptionValues.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "lldb/Interpreter/OptionValueFileSpecList.h"
2323
#include "lldb/Interpreter/OptionValueFormat.h"
2424
#include "lldb/Interpreter/OptionValueFormatEntity.h"
25+
#include "lldb/Interpreter/OptionValueFormatEntityList.h"
2526
#include "lldb/Interpreter/OptionValueLanguage.h"
2627
#include "lldb/Interpreter/OptionValuePathMappings.h"
2728
#include "lldb/Interpreter/OptionValueProperties.h"

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class OptionValueFileSpec;
150150
class OptionValueFileSpecList;
151151
class OptionValueFormat;
152152
class OptionValueFormatEntity;
153+
class OptionValueFormatEntityList;
153154
class OptionValueLanguage;
154155
class OptionValuePathMappings;
155156
class OptionValueProperties;

lldb/source/Interpreter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
4141
OptionValueFileSpecList.cpp
4242
OptionValueFormat.cpp
4343
OptionValueFormatEntity.cpp
44+
OptionValueFormatEntityList.cpp
4445
OptionValueLanguage.cpp
4546
OptionValuePathMappings.cpp
4647
OptionValueProperties.cpp

lldb/source/Interpreter/OptionValue.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ const OptionValueFormatEntity *OptionValue::GetAsFormatEntity() const {
184184
return nullptr;
185185
}
186186

187+
OptionValueFormatEntityList *OptionValue::GetAsFormatEntityList() {
188+
if (GetType() == OptionValue::eTypeFormatEntityList)
189+
return static_cast<OptionValueFormatEntityList *>(this);
190+
return nullptr;
191+
}
192+
193+
const OptionValueFormatEntityList *OptionValue::GetAsFormatEntityList() const {
194+
if (GetType() == OptionValue::eTypeFormatEntityList)
195+
return static_cast<const OptionValueFormatEntityList *>(this);
196+
return nullptr;
197+
}
198+
187199
OptionValuePathMappings *OptionValue::GetAsPathMappings() {
188200
if (GetType() == OptionValue::eTypePathMap)
189201
return static_cast<OptionValuePathMappings *>(this);
@@ -380,6 +392,13 @@ bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) {
380392
return false;
381393
}
382394

395+
std::vector<FormatEntity::Entry> OptionValue::GetFormatEntityList() const {
396+
std::lock_guard<std::mutex> lock(m_mutex);
397+
if (const OptionValueFormatEntityList *option_value = GetAsFormatEntityList())
398+
return option_value->GetCurrentValue();
399+
return {};
400+
}
401+
383402
const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
384403
std::lock_guard<std::mutex> lock(m_mutex);
385404
if (const OptionValueFormatEntity *option_value = GetAsFormatEntity())
@@ -502,6 +521,8 @@ const char *OptionValue::GetBuiltinTypeAsCString(Type t) {
502521
return "format";
503522
case eTypeFormatEntity:
504523
return "format-string";
524+
case eTypeFormatEntityList:
525+
return "format-string-list";
505526
case eTypeLanguage:
506527
return "language";
507528
case eTypePathMap:
@@ -546,6 +567,9 @@ lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask(
546567
case 1u << eTypeFormatEntity:
547568
value_sp = std::make_shared<OptionValueFormatEntity>(nullptr);
548569
break;
570+
case 1u << eTypeFormatEntityList:
571+
value_sp = std::make_shared<OptionValueFormatEntityList>();
572+
break;
549573
case 1u << eTypeLanguage:
550574
value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown);
551575
break;

0 commit comments

Comments
 (0)