180814287SRaphael Isemann //===-- OptionValue.cpp ---------------------------------------------------===//
267cc0636SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
667cc0636SGreg Clayton //
767cc0636SGreg Clayton //===----------------------------------------------------------------------===//
867cc0636SGreg Clayton
967cc0636SGreg Clayton #include "lldb/Interpreter/OptionValue.h"
1067cc0636SGreg Clayton #include "lldb/Interpreter/OptionValues.h"
11573ab909SZachary Turner #include "lldb/Utility/StringList.h"
1267cc0636SGreg Clayton
13827c0122SJonas Devlieghere #include <memory>
14827c0122SJonas Devlieghere
1567cc0636SGreg Clayton using namespace lldb;
1667cc0636SGreg Clayton using namespace lldb_private;
1767cc0636SGreg Clayton
1805097246SAdrian Prantl // Get this value as a uint64_t value if it is encoded as a boolean, uint64_t
1905097246SAdrian Prantl // or int64_t. Other types will cause "fail_value" to be returned
GetUInt64Value(uint64_t fail_value,bool * success_ptr)20b9c1b51eSKate Stone uint64_t OptionValue::GetUInt64Value(uint64_t fail_value, bool *success_ptr) {
2167cc0636SGreg Clayton if (success_ptr)
2267cc0636SGreg Clayton *success_ptr = true;
23b9c1b51eSKate Stone switch (GetType()) {
24b9c1b51eSKate Stone case OptionValue::eTypeBoolean:
25b9c1b51eSKate Stone return static_cast<OptionValueBoolean *>(this)->GetCurrentValue();
26b9c1b51eSKate Stone case OptionValue::eTypeSInt64:
27b9c1b51eSKate Stone return static_cast<OptionValueSInt64 *>(this)->GetCurrentValue();
28b9c1b51eSKate Stone case OptionValue::eTypeUInt64:
29b9c1b51eSKate Stone return static_cast<OptionValueUInt64 *>(this)->GetCurrentValue();
3067cc0636SGreg Clayton default:
3167cc0636SGreg Clayton break;
3267cc0636SGreg Clayton }
3367cc0636SGreg Clayton if (success_ptr)
3467cc0636SGreg Clayton *success_ptr = false;
3567cc0636SGreg Clayton return fail_value;
3667cc0636SGreg Clayton }
3767cc0636SGreg Clayton
SetSubValue(const ExecutionContext * exe_ctx,VarSetOperationType op,llvm::StringRef name,llvm::StringRef value)3897206d57SZachary Turner Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx,
3931d97a5cSZachary Turner VarSetOperationType op, llvm::StringRef name,
4031d97a5cSZachary Turner llvm::StringRef value) {
4197206d57SZachary Turner Status error;
4289533764SJonas Devlieghere error.SetErrorString("SetSubValue is not supported");
4367cc0636SGreg Clayton return error;
4467cc0636SGreg Clayton }
4567cc0636SGreg Clayton
GetAsBoolean()46b9c1b51eSKate Stone OptionValueBoolean *OptionValue::GetAsBoolean() {
4767cc0636SGreg Clayton if (GetType() == OptionValue::eTypeBoolean)
4867cc0636SGreg Clayton return static_cast<OptionValueBoolean *>(this);
49d78c9576SEd Maste return nullptr;
5067cc0636SGreg Clayton }
5167cc0636SGreg Clayton
GetAsBoolean() const52b9c1b51eSKate Stone const OptionValueBoolean *OptionValue::GetAsBoolean() const {
5367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeBoolean)
5467cc0636SGreg Clayton return static_cast<const OptionValueBoolean *>(this);
55d78c9576SEd Maste return nullptr;
5667cc0636SGreg Clayton }
5767cc0636SGreg Clayton
GetAsChar() const58b9c1b51eSKate Stone const OptionValueChar *OptionValue::GetAsChar() const {
593e7442b6SZachary Turner if (GetType() == OptionValue::eTypeChar)
603e7442b6SZachary Turner return static_cast<const OptionValueChar *>(this);
613e7442b6SZachary Turner return nullptr;
623e7442b6SZachary Turner }
633e7442b6SZachary Turner
GetAsChar()64b9c1b51eSKate Stone OptionValueChar *OptionValue::GetAsChar() {
653e7442b6SZachary Turner if (GetType() == OptionValue::eTypeChar)
663e7442b6SZachary Turner return static_cast<OptionValueChar *>(this);
673e7442b6SZachary Turner return nullptr;
683e7442b6SZachary Turner }
6967cc0636SGreg Clayton
GetAsFileSpec()70b9c1b51eSKate Stone OptionValueFileSpec *OptionValue::GetAsFileSpec() {
7167cc0636SGreg Clayton if (GetType() == OptionValue::eTypeFileSpec)
7267cc0636SGreg Clayton return static_cast<OptionValueFileSpec *>(this);
73d78c9576SEd Maste return nullptr;
7467cc0636SGreg Clayton }
7567cc0636SGreg Clayton
GetAsFileSpec() const76b9c1b51eSKate Stone const OptionValueFileSpec *OptionValue::GetAsFileSpec() const {
7767cc0636SGreg Clayton if (GetType() == OptionValue::eTypeFileSpec)
7867cc0636SGreg Clayton return static_cast<const OptionValueFileSpec *>(this);
79d78c9576SEd Maste return nullptr;
8067cc0636SGreg Clayton }
8167cc0636SGreg Clayton
GetAsFileSpecList()82b9c1b51eSKate Stone OptionValueFileSpecList *OptionValue::GetAsFileSpecList() {
8367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeFileSpecList)
8467cc0636SGreg Clayton return static_cast<OptionValueFileSpecList *>(this);
85d78c9576SEd Maste return nullptr;
8667cc0636SGreg Clayton }
8767cc0636SGreg Clayton
GetAsFileSpecList() const88b9c1b51eSKate Stone const OptionValueFileSpecList *OptionValue::GetAsFileSpecList() const {
8967cc0636SGreg Clayton if (GetType() == OptionValue::eTypeFileSpecList)
9067cc0636SGreg Clayton return static_cast<const OptionValueFileSpecList *>(this);
91d78c9576SEd Maste return nullptr;
9267cc0636SGreg Clayton }
9367cc0636SGreg Clayton
GetAsArch()94b9c1b51eSKate Stone OptionValueArch *OptionValue::GetAsArch() {
9567cc0636SGreg Clayton if (GetType() == OptionValue::eTypeArch)
9667cc0636SGreg Clayton return static_cast<OptionValueArch *>(this);
97d78c9576SEd Maste return nullptr;
9867cc0636SGreg Clayton }
9967cc0636SGreg Clayton
GetAsArch() const100b9c1b51eSKate Stone const OptionValueArch *OptionValue::GetAsArch() const {
10167cc0636SGreg Clayton if (GetType() == OptionValue::eTypeArch)
10267cc0636SGreg Clayton return static_cast<const OptionValueArch *>(this);
103d78c9576SEd Maste return nullptr;
10467cc0636SGreg Clayton }
10567cc0636SGreg Clayton
GetAsArray()106b9c1b51eSKate Stone OptionValueArray *OptionValue::GetAsArray() {
10767cc0636SGreg Clayton if (GetType() == OptionValue::eTypeArray)
10867cc0636SGreg Clayton return static_cast<OptionValueArray *>(this);
109d78c9576SEd Maste return nullptr;
11067cc0636SGreg Clayton }
11167cc0636SGreg Clayton
GetAsArray() const112b9c1b51eSKate Stone const OptionValueArray *OptionValue::GetAsArray() const {
11367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeArray)
11467cc0636SGreg Clayton return static_cast<const OptionValueArray *>(this);
115d78c9576SEd Maste return nullptr;
11667cc0636SGreg Clayton }
11767cc0636SGreg Clayton
GetAsArgs()118b9c1b51eSKate Stone OptionValueArgs *OptionValue::GetAsArgs() {
11967cc0636SGreg Clayton if (GetType() == OptionValue::eTypeArgs)
12067cc0636SGreg Clayton return static_cast<OptionValueArgs *>(this);
121d78c9576SEd Maste return nullptr;
12267cc0636SGreg Clayton }
12367cc0636SGreg Clayton
GetAsArgs() const124b9c1b51eSKate Stone const OptionValueArgs *OptionValue::GetAsArgs() const {
12567cc0636SGreg Clayton if (GetType() == OptionValue::eTypeArgs)
12667cc0636SGreg Clayton return static_cast<const OptionValueArgs *>(this);
127d78c9576SEd Maste return nullptr;
12867cc0636SGreg Clayton }
12967cc0636SGreg Clayton
GetAsDictionary()130b9c1b51eSKate Stone OptionValueDictionary *OptionValue::GetAsDictionary() {
13167cc0636SGreg Clayton if (GetType() == OptionValue::eTypeDictionary)
13267cc0636SGreg Clayton return static_cast<OptionValueDictionary *>(this);
133d78c9576SEd Maste return nullptr;
13467cc0636SGreg Clayton }
13567cc0636SGreg Clayton
GetAsDictionary() const136b9c1b51eSKate Stone const OptionValueDictionary *OptionValue::GetAsDictionary() const {
13767cc0636SGreg Clayton if (GetType() == OptionValue::eTypeDictionary)
13867cc0636SGreg Clayton return static_cast<const OptionValueDictionary *>(this);
139d78c9576SEd Maste return nullptr;
14067cc0636SGreg Clayton }
14167cc0636SGreg Clayton
GetAsEnumeration()142b9c1b51eSKate Stone OptionValueEnumeration *OptionValue::GetAsEnumeration() {
14367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeEnum)
14467cc0636SGreg Clayton return static_cast<OptionValueEnumeration *>(this);
145d78c9576SEd Maste return nullptr;
14667cc0636SGreg Clayton }
14767cc0636SGreg Clayton
GetAsEnumeration() const148b9c1b51eSKate Stone const OptionValueEnumeration *OptionValue::GetAsEnumeration() const {
14967cc0636SGreg Clayton if (GetType() == OptionValue::eTypeEnum)
15067cc0636SGreg Clayton return static_cast<const OptionValueEnumeration *>(this);
151d78c9576SEd Maste return nullptr;
15267cc0636SGreg Clayton }
15367cc0636SGreg Clayton
GetAsFormat()154b9c1b51eSKate Stone OptionValueFormat *OptionValue::GetAsFormat() {
15567cc0636SGreg Clayton if (GetType() == OptionValue::eTypeFormat)
15667cc0636SGreg Clayton return static_cast<OptionValueFormat *>(this);
157d78c9576SEd Maste return nullptr;
15867cc0636SGreg Clayton }
15967cc0636SGreg Clayton
GetAsFormat() const160b9c1b51eSKate Stone const OptionValueFormat *OptionValue::GetAsFormat() const {
16167cc0636SGreg Clayton if (GetType() == OptionValue::eTypeFormat)
16267cc0636SGreg Clayton return static_cast<const OptionValueFormat *>(this);
163d78c9576SEd Maste return nullptr;
16467cc0636SGreg Clayton }
16567cc0636SGreg Clayton
GetAsLanguage()166b9c1b51eSKate Stone OptionValueLanguage *OptionValue::GetAsLanguage() {
1678fdf7859SEnrico Granata if (GetType() == OptionValue::eTypeLanguage)
1688fdf7859SEnrico Granata return static_cast<OptionValueLanguage *>(this);
169248a1305SKonrad Kleine return nullptr;
1708fdf7859SEnrico Granata }
1718fdf7859SEnrico Granata
GetAsLanguage() const172b9c1b51eSKate Stone const OptionValueLanguage *OptionValue::GetAsLanguage() const {
1738fdf7859SEnrico Granata if (GetType() == OptionValue::eTypeLanguage)
1748fdf7859SEnrico Granata return static_cast<const OptionValueLanguage *>(this);
175248a1305SKonrad Kleine return nullptr;
1768fdf7859SEnrico Granata }
1778fdf7859SEnrico Granata
GetAsFormatEntity()178b9c1b51eSKate Stone OptionValueFormatEntity *OptionValue::GetAsFormatEntity() {
179554f68d3SGreg Clayton if (GetType() == OptionValue::eTypeFormatEntity)
180554f68d3SGreg Clayton return static_cast<OptionValueFormatEntity *>(this);
181554f68d3SGreg Clayton return nullptr;
182554f68d3SGreg Clayton }
183554f68d3SGreg Clayton
GetAsFormatEntity() const184b9c1b51eSKate Stone const OptionValueFormatEntity *OptionValue::GetAsFormatEntity() const {
185554f68d3SGreg Clayton if (GetType() == OptionValue::eTypeFormatEntity)
186554f68d3SGreg Clayton return static_cast<const OptionValueFormatEntity *>(this);
187554f68d3SGreg Clayton return nullptr;
188554f68d3SGreg Clayton }
189554f68d3SGreg Clayton
GetAsPathMappings()190b9c1b51eSKate Stone OptionValuePathMappings *OptionValue::GetAsPathMappings() {
19167cc0636SGreg Clayton if (GetType() == OptionValue::eTypePathMap)
19267cc0636SGreg Clayton return static_cast<OptionValuePathMappings *>(this);
193d78c9576SEd Maste return nullptr;
19467cc0636SGreg Clayton }
19567cc0636SGreg Clayton
GetAsPathMappings() const196b9c1b51eSKate Stone const OptionValuePathMappings *OptionValue::GetAsPathMappings() const {
19767cc0636SGreg Clayton if (GetType() == OptionValue::eTypePathMap)
19867cc0636SGreg Clayton return static_cast<const OptionValuePathMappings *>(this);
199d78c9576SEd Maste return nullptr;
20067cc0636SGreg Clayton }
20167cc0636SGreg Clayton
GetAsProperties()202b9c1b51eSKate Stone OptionValueProperties *OptionValue::GetAsProperties() {
20367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeProperties)
20467cc0636SGreg Clayton return static_cast<OptionValueProperties *>(this);
205d78c9576SEd Maste return nullptr;
20667cc0636SGreg Clayton }
20767cc0636SGreg Clayton
GetAsProperties() const208b9c1b51eSKate Stone const OptionValueProperties *OptionValue::GetAsProperties() const {
20967cc0636SGreg Clayton if (GetType() == OptionValue::eTypeProperties)
21067cc0636SGreg Clayton return static_cast<const OptionValueProperties *>(this);
211d78c9576SEd Maste return nullptr;
21267cc0636SGreg Clayton }
21367cc0636SGreg Clayton
GetAsRegex()214b9c1b51eSKate Stone OptionValueRegex *OptionValue::GetAsRegex() {
21567cc0636SGreg Clayton if (GetType() == OptionValue::eTypeRegex)
21667cc0636SGreg Clayton return static_cast<OptionValueRegex *>(this);
217d78c9576SEd Maste return nullptr;
21867cc0636SGreg Clayton }
21967cc0636SGreg Clayton
GetAsRegex() const220b9c1b51eSKate Stone const OptionValueRegex *OptionValue::GetAsRegex() const {
22167cc0636SGreg Clayton if (GetType() == OptionValue::eTypeRegex)
22267cc0636SGreg Clayton return static_cast<const OptionValueRegex *>(this);
223d78c9576SEd Maste return nullptr;
22467cc0636SGreg Clayton }
22567cc0636SGreg Clayton
GetAsSInt64()226b9c1b51eSKate Stone OptionValueSInt64 *OptionValue::GetAsSInt64() {
22767cc0636SGreg Clayton if (GetType() == OptionValue::eTypeSInt64)
22867cc0636SGreg Clayton return static_cast<OptionValueSInt64 *>(this);
229d78c9576SEd Maste return nullptr;
23067cc0636SGreg Clayton }
23167cc0636SGreg Clayton
GetAsSInt64() const232b9c1b51eSKate Stone const OptionValueSInt64 *OptionValue::GetAsSInt64() const {
23367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeSInt64)
23467cc0636SGreg Clayton return static_cast<const OptionValueSInt64 *>(this);
235d78c9576SEd Maste return nullptr;
23667cc0636SGreg Clayton }
23767cc0636SGreg Clayton
GetAsString()238b9c1b51eSKate Stone OptionValueString *OptionValue::GetAsString() {
23967cc0636SGreg Clayton if (GetType() == OptionValue::eTypeString)
24067cc0636SGreg Clayton return static_cast<OptionValueString *>(this);
241d78c9576SEd Maste return nullptr;
24267cc0636SGreg Clayton }
24367cc0636SGreg Clayton
GetAsString() const244b9c1b51eSKate Stone const OptionValueString *OptionValue::GetAsString() const {
24567cc0636SGreg Clayton if (GetType() == OptionValue::eTypeString)
24667cc0636SGreg Clayton return static_cast<const OptionValueString *>(this);
247d78c9576SEd Maste return nullptr;
24867cc0636SGreg Clayton }
24967cc0636SGreg Clayton
GetAsUInt64()250b9c1b51eSKate Stone OptionValueUInt64 *OptionValue::GetAsUInt64() {
25167cc0636SGreg Clayton if (GetType() == OptionValue::eTypeUInt64)
25267cc0636SGreg Clayton return static_cast<OptionValueUInt64 *>(this);
253d78c9576SEd Maste return nullptr;
25467cc0636SGreg Clayton }
25567cc0636SGreg Clayton
GetAsUInt64() const256b9c1b51eSKate Stone const OptionValueUInt64 *OptionValue::GetAsUInt64() const {
25767cc0636SGreg Clayton if (GetType() == OptionValue::eTypeUInt64)
25867cc0636SGreg Clayton return static_cast<const OptionValueUInt64 *>(this);
259d78c9576SEd Maste return nullptr;
26067cc0636SGreg Clayton }
26167cc0636SGreg Clayton
GetAsUUID()262b9c1b51eSKate Stone OptionValueUUID *OptionValue::GetAsUUID() {
26367cc0636SGreg Clayton if (GetType() == OptionValue::eTypeUUID)
26467cc0636SGreg Clayton return static_cast<OptionValueUUID *>(this);
265d78c9576SEd Maste return nullptr;
26667cc0636SGreg Clayton }
26767cc0636SGreg Clayton
GetAsUUID() const268b9c1b51eSKate Stone const OptionValueUUID *OptionValue::GetAsUUID() const {
26967cc0636SGreg Clayton if (GetType() == OptionValue::eTypeUUID)
27067cc0636SGreg Clayton return static_cast<const OptionValueUUID *>(this);
271d78c9576SEd Maste return nullptr;
27267cc0636SGreg Clayton }
27367cc0636SGreg Clayton
GetBooleanValue(bool fail_value) const274b9c1b51eSKate Stone bool OptionValue::GetBooleanValue(bool fail_value) const {
27567cc0636SGreg Clayton const OptionValueBoolean *option_value = GetAsBoolean();
27667cc0636SGreg Clayton if (option_value)
27767cc0636SGreg Clayton return option_value->GetCurrentValue();
27867cc0636SGreg Clayton return fail_value;
27967cc0636SGreg Clayton }
28067cc0636SGreg Clayton
SetBooleanValue(bool new_value)281b9c1b51eSKate Stone bool OptionValue::SetBooleanValue(bool new_value) {
28267cc0636SGreg Clayton OptionValueBoolean *option_value = GetAsBoolean();
283b9c1b51eSKate Stone if (option_value) {
28467cc0636SGreg Clayton option_value->SetCurrentValue(new_value);
28567cc0636SGreg Clayton return true;
28667cc0636SGreg Clayton }
28767cc0636SGreg Clayton return false;
28867cc0636SGreg Clayton }
28967cc0636SGreg Clayton
GetCharValue(char fail_value) const290b9c1b51eSKate Stone char OptionValue::GetCharValue(char fail_value) const {
2913e7442b6SZachary Turner const OptionValueChar *option_value = GetAsChar();
2923e7442b6SZachary Turner if (option_value)
2933e7442b6SZachary Turner return option_value->GetCurrentValue();
2943e7442b6SZachary Turner return fail_value;
2953e7442b6SZachary Turner }
2963e7442b6SZachary Turner
SetCharValue(char new_value)297b9c1b51eSKate Stone char OptionValue::SetCharValue(char new_value) {
2983e7442b6SZachary Turner OptionValueChar *option_value = GetAsChar();
299b9c1b51eSKate Stone if (option_value) {
3003e7442b6SZachary Turner option_value->SetCurrentValue(new_value);
3013e7442b6SZachary Turner return true;
3023e7442b6SZachary Turner }
3033e7442b6SZachary Turner return false;
3043e7442b6SZachary Turner }
3053e7442b6SZachary Turner
GetEnumerationValue(int64_t fail_value) const306b9c1b51eSKate Stone int64_t OptionValue::GetEnumerationValue(int64_t fail_value) const {
30767cc0636SGreg Clayton const OptionValueEnumeration *option_value = GetAsEnumeration();
30867cc0636SGreg Clayton if (option_value)
3091f746071SGreg Clayton return option_value->GetCurrentValue();
31067cc0636SGreg Clayton return fail_value;
31167cc0636SGreg Clayton }
31267cc0636SGreg Clayton
SetEnumerationValue(int64_t value)313b9c1b51eSKate Stone bool OptionValue::SetEnumerationValue(int64_t value) {
31467cc0636SGreg Clayton OptionValueEnumeration *option_value = GetAsEnumeration();
315b9c1b51eSKate Stone if (option_value) {
31667cc0636SGreg Clayton option_value->SetCurrentValue(value);
31767cc0636SGreg Clayton return true;
31867cc0636SGreg Clayton }
31967cc0636SGreg Clayton return false;
32067cc0636SGreg Clayton }
32167cc0636SGreg Clayton
GetFileSpecValue() const322b9c1b51eSKate Stone FileSpec OptionValue::GetFileSpecValue() const {
32367cc0636SGreg Clayton const OptionValueFileSpec *option_value = GetAsFileSpec();
32467cc0636SGreg Clayton if (option_value)
32567cc0636SGreg Clayton return option_value->GetCurrentValue();
32667cc0636SGreg Clayton return FileSpec();
32767cc0636SGreg Clayton }
32867cc0636SGreg Clayton
SetFileSpecValue(const FileSpec & file_spec)329b9c1b51eSKate Stone bool OptionValue::SetFileSpecValue(const FileSpec &file_spec) {
33067cc0636SGreg Clayton OptionValueFileSpec *option_value = GetAsFileSpec();
331b9c1b51eSKate Stone if (option_value) {
3326920b52bSGreg Clayton option_value->SetCurrentValue(file_spec, false);
33367cc0636SGreg Clayton return true;
33467cc0636SGreg Clayton }
33567cc0636SGreg Clayton return false;
33667cc0636SGreg Clayton }
33767cc0636SGreg Clayton
GetFileSpecListValue() const338b9c1b51eSKate Stone FileSpecList OptionValue::GetFileSpecListValue() const {
33967cc0636SGreg Clayton const OptionValueFileSpecList *option_value = GetAsFileSpecList();
34067cc0636SGreg Clayton if (option_value)
34167cc0636SGreg Clayton return option_value->GetCurrentValue();
34267cc0636SGreg Clayton return FileSpecList();
34367cc0636SGreg Clayton }
34467cc0636SGreg Clayton
GetFormatValue(lldb::Format fail_value) const345b9c1b51eSKate Stone lldb::Format OptionValue::GetFormatValue(lldb::Format fail_value) const {
34667cc0636SGreg Clayton const OptionValueFormat *option_value = GetAsFormat();
34767cc0636SGreg Clayton if (option_value)
34867cc0636SGreg Clayton return option_value->GetCurrentValue();
34967cc0636SGreg Clayton return fail_value;
35067cc0636SGreg Clayton }
35167cc0636SGreg Clayton
SetFormatValue(lldb::Format new_value)352b9c1b51eSKate Stone bool OptionValue::SetFormatValue(lldb::Format new_value) {
35367cc0636SGreg Clayton OptionValueFormat *option_value = GetAsFormat();
354b9c1b51eSKate Stone if (option_value) {
35567cc0636SGreg Clayton option_value->SetCurrentValue(new_value);
35667cc0636SGreg Clayton return true;
35767cc0636SGreg Clayton }
35867cc0636SGreg Clayton return false;
35967cc0636SGreg Clayton }
36067cc0636SGreg Clayton
3618fdf7859SEnrico Granata lldb::LanguageType
GetLanguageValue(lldb::LanguageType fail_value) const362b9c1b51eSKate Stone OptionValue::GetLanguageValue(lldb::LanguageType fail_value) const {
3638fdf7859SEnrico Granata const OptionValueLanguage *option_value = GetAsLanguage();
3648fdf7859SEnrico Granata if (option_value)
3658fdf7859SEnrico Granata return option_value->GetCurrentValue();
3668fdf7859SEnrico Granata return fail_value;
3678fdf7859SEnrico Granata }
3688fdf7859SEnrico Granata
SetLanguageValue(lldb::LanguageType new_language)369b9c1b51eSKate Stone bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) {
3708fdf7859SEnrico Granata OptionValueLanguage *option_value = GetAsLanguage();
371b9c1b51eSKate Stone if (option_value) {
3728fdf7859SEnrico Granata option_value->SetCurrentValue(new_language);
3738fdf7859SEnrico Granata return true;
3748fdf7859SEnrico Granata }
3758fdf7859SEnrico Granata return false;
3768fdf7859SEnrico Granata }
3778fdf7859SEnrico Granata
GetFormatEntity() const378b9c1b51eSKate Stone const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
379554f68d3SGreg Clayton const OptionValueFormatEntity *option_value = GetAsFormatEntity();
380554f68d3SGreg Clayton if (option_value)
381554f68d3SGreg Clayton return &option_value->GetCurrentValue();
382554f68d3SGreg Clayton return nullptr;
383554f68d3SGreg Clayton }
384554f68d3SGreg Clayton
GetRegexValue() const385b9c1b51eSKate Stone const RegularExpression *OptionValue::GetRegexValue() const {
38667cc0636SGreg Clayton const OptionValueRegex *option_value = GetAsRegex();
38767cc0636SGreg Clayton if (option_value)
38867cc0636SGreg Clayton return option_value->GetCurrentValue();
389d78c9576SEd Maste return nullptr;
39067cc0636SGreg Clayton }
39167cc0636SGreg Clayton
GetSInt64Value(int64_t fail_value) const392b9c1b51eSKate Stone int64_t OptionValue::GetSInt64Value(int64_t fail_value) const {
39367cc0636SGreg Clayton const OptionValueSInt64 *option_value = GetAsSInt64();
39467cc0636SGreg Clayton if (option_value)
39567cc0636SGreg Clayton return option_value->GetCurrentValue();
39667cc0636SGreg Clayton return fail_value;
39767cc0636SGreg Clayton }
39867cc0636SGreg Clayton
SetSInt64Value(int64_t new_value)399b9c1b51eSKate Stone bool OptionValue::SetSInt64Value(int64_t new_value) {
40067cc0636SGreg Clayton OptionValueSInt64 *option_value = GetAsSInt64();
401b9c1b51eSKate Stone if (option_value) {
40267cc0636SGreg Clayton option_value->SetCurrentValue(new_value);
40367cc0636SGreg Clayton return true;
40467cc0636SGreg Clayton }
40567cc0636SGreg Clayton return false;
40667cc0636SGreg Clayton }
40767cc0636SGreg Clayton
GetStringValue(llvm::StringRef fail_value) const40831d97a5cSZachary Turner llvm::StringRef OptionValue::GetStringValue(llvm::StringRef fail_value) const {
40967cc0636SGreg Clayton const OptionValueString *option_value = GetAsString();
41067cc0636SGreg Clayton if (option_value)
41131d97a5cSZachary Turner return option_value->GetCurrentValueAsRef();
41267cc0636SGreg Clayton return fail_value;
41367cc0636SGreg Clayton }
41467cc0636SGreg Clayton
SetStringValue(llvm::StringRef new_value)415514d8cd8SZachary Turner bool OptionValue::SetStringValue(llvm::StringRef new_value) {
41667cc0636SGreg Clayton OptionValueString *option_value = GetAsString();
417b9c1b51eSKate Stone if (option_value) {
418514d8cd8SZachary Turner option_value->SetCurrentValue(new_value);
41967cc0636SGreg Clayton return true;
42067cc0636SGreg Clayton }
42167cc0636SGreg Clayton return false;
42267cc0636SGreg Clayton }
42367cc0636SGreg Clayton
GetUInt64Value(uint64_t fail_value) const424b9c1b51eSKate Stone uint64_t OptionValue::GetUInt64Value(uint64_t fail_value) const {
42567cc0636SGreg Clayton const OptionValueUInt64 *option_value = GetAsUInt64();
42667cc0636SGreg Clayton if (option_value)
42767cc0636SGreg Clayton return option_value->GetCurrentValue();
42867cc0636SGreg Clayton return fail_value;
42967cc0636SGreg Clayton }
43067cc0636SGreg Clayton
SetUInt64Value(uint64_t new_value)431b9c1b51eSKate Stone bool OptionValue::SetUInt64Value(uint64_t new_value) {
43267cc0636SGreg Clayton OptionValueUInt64 *option_value = GetAsUInt64();
433b9c1b51eSKate Stone if (option_value) {
43467cc0636SGreg Clayton option_value->SetCurrentValue(new_value);
43567cc0636SGreg Clayton return true;
43667cc0636SGreg Clayton }
43767cc0636SGreg Clayton return false;
43867cc0636SGreg Clayton }
43967cc0636SGreg Clayton
GetUUIDValue() const440b9c1b51eSKate Stone UUID OptionValue::GetUUIDValue() const {
44167cc0636SGreg Clayton const OptionValueUUID *option_value = GetAsUUID();
44267cc0636SGreg Clayton if (option_value)
44367cc0636SGreg Clayton return option_value->GetCurrentValue();
44467cc0636SGreg Clayton return UUID();
44567cc0636SGreg Clayton }
44667cc0636SGreg Clayton
SetUUIDValue(const UUID & uuid)447b9c1b51eSKate Stone bool OptionValue::SetUUIDValue(const UUID &uuid) {
44867cc0636SGreg Clayton OptionValueUUID *option_value = GetAsUUID();
449b9c1b51eSKate Stone if (option_value) {
45067cc0636SGreg Clayton option_value->SetCurrentValue(uuid);
45167cc0636SGreg Clayton return true;
45267cc0636SGreg Clayton }
45367cc0636SGreg Clayton return false;
45467cc0636SGreg Clayton }
45567cc0636SGreg Clayton
GetBuiltinTypeAsCString(Type t)456b9c1b51eSKate Stone const char *OptionValue::GetBuiltinTypeAsCString(Type t) {
457b9c1b51eSKate Stone switch (t) {
458b9c1b51eSKate Stone case eTypeInvalid:
459b9c1b51eSKate Stone return "invalid";
460b9c1b51eSKate Stone case eTypeArch:
461b9c1b51eSKate Stone return "arch";
462b9c1b51eSKate Stone case eTypeArgs:
463b9c1b51eSKate Stone return "arguments";
464b9c1b51eSKate Stone case eTypeArray:
465b9c1b51eSKate Stone return "array";
466b9c1b51eSKate Stone case eTypeBoolean:
467b9c1b51eSKate Stone return "boolean";
4683e7442b6SZachary Turner case eTypeChar:
4693e7442b6SZachary Turner return "char";
470b9c1b51eSKate Stone case eTypeDictionary:
471b9c1b51eSKate Stone return "dictionary";
472b9c1b51eSKate Stone case eTypeEnum:
473b9c1b51eSKate Stone return "enum";
474bc0a9a17SJim Ingham case eTypeFileLineColumn:
475bc0a9a17SJim Ingham return "file:line:column specifier";
476b9c1b51eSKate Stone case eTypeFileSpec:
477b9c1b51eSKate Stone return "file";
478b9c1b51eSKate Stone case eTypeFileSpecList:
479b9c1b51eSKate Stone return "file-list";
480b9c1b51eSKate Stone case eTypeFormat:
481b9c1b51eSKate Stone return "format";
482b9c1b51eSKate Stone case eTypeFormatEntity:
483b9c1b51eSKate Stone return "format-string";
484b9c1b51eSKate Stone case eTypeLanguage:
485b9c1b51eSKate Stone return "language";
486b9c1b51eSKate Stone case eTypePathMap:
487b9c1b51eSKate Stone return "path-map";
488b9c1b51eSKate Stone case eTypeProperties:
489b9c1b51eSKate Stone return "properties";
490b9c1b51eSKate Stone case eTypeRegex:
491b9c1b51eSKate Stone return "regex";
492b9c1b51eSKate Stone case eTypeSInt64:
493b9c1b51eSKate Stone return "int";
494b9c1b51eSKate Stone case eTypeString:
495b9c1b51eSKate Stone return "string";
496b9c1b51eSKate Stone case eTypeUInt64:
497b9c1b51eSKate Stone return "unsigned";
498b9c1b51eSKate Stone case eTypeUUID:
499b9c1b51eSKate Stone return "uuid";
50067cc0636SGreg Clayton }
501d78c9576SEd Maste return nullptr;
50267cc0636SGreg Clayton }
50367cc0636SGreg Clayton
CreateValueFromCStringForTypeMask(const char * value_cstr,uint32_t type_mask,Status & error)504b9c1b51eSKate Stone lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask(
50597206d57SZachary Turner const char *value_cstr, uint32_t type_mask, Status &error) {
50605097246SAdrian Prantl // If only 1 bit is set in the type mask for a dictionary or array then we
50705097246SAdrian Prantl // know how to decode a value from a cstring
50867cc0636SGreg Clayton lldb::OptionValueSP value_sp;
509b9c1b51eSKate Stone switch (type_mask) {
510b9c1b51eSKate Stone case 1u << eTypeArch:
511827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueArch>();
512b9c1b51eSKate Stone break;
513b9c1b51eSKate Stone case 1u << eTypeBoolean:
514827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueBoolean>(false);
515b9c1b51eSKate Stone break;
516b9c1b51eSKate Stone case 1u << eTypeChar:
517827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueChar>('\0');
518b9c1b51eSKate Stone break;
519b9c1b51eSKate Stone case 1u << eTypeFileSpec:
520827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueFileSpec>();
521b9c1b51eSKate Stone break;
522b9c1b51eSKate Stone case 1u << eTypeFormat:
523827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueFormat>(eFormatInvalid);
524b9c1b51eSKate Stone break;
525b9c1b51eSKate Stone case 1u << eTypeFormatEntity:
526827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueFormatEntity>(nullptr);
527b9c1b51eSKate Stone break;
528b9c1b51eSKate Stone case 1u << eTypeLanguage:
529827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown);
530b9c1b51eSKate Stone break;
531b9c1b51eSKate Stone case 1u << eTypeSInt64:
532827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueSInt64>();
533b9c1b51eSKate Stone break;
534b9c1b51eSKate Stone case 1u << eTypeString:
535827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueString>();
536b9c1b51eSKate Stone break;
537b9c1b51eSKate Stone case 1u << eTypeUInt64:
538827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueUInt64>();
539b9c1b51eSKate Stone break;
540b9c1b51eSKate Stone case 1u << eTypeUUID:
541827c0122SJonas Devlieghere value_sp = std::make_shared<OptionValueUUID>();
542b9c1b51eSKate Stone break;
54367cc0636SGreg Clayton }
54467cc0636SGreg Clayton
54567cc0636SGreg Clayton if (value_sp)
546*bbea3610SRaphael Isemann error = value_sp->SetValueFromString(value_cstr, eVarSetOperationAssign);
54767cc0636SGreg Clayton else
54867cc0636SGreg Clayton error.SetErrorString("unsupported type mask");
54967cc0636SGreg Clayton return value_sp;
55067cc0636SGreg Clayton }
55167cc0636SGreg Clayton
DumpQualifiedName(Stream & strm) const552b9c1b51eSKate Stone bool OptionValue::DumpQualifiedName(Stream &strm) const {
55367cc0636SGreg Clayton bool dumped_something = false;
55467cc0636SGreg Clayton lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
555b9c1b51eSKate Stone if (m_parent_sp) {
55667cc0636SGreg Clayton if (m_parent_sp->DumpQualifiedName(strm))
55767cc0636SGreg Clayton dumped_something = true;
55867cc0636SGreg Clayton }
55967cc0636SGreg Clayton ConstString name(GetName());
560b9c1b51eSKate Stone if (name) {
56167cc0636SGreg Clayton if (dumped_something)
56267cc0636SGreg Clayton strm.PutChar('.');
56367cc0636SGreg Clayton else
56467cc0636SGreg Clayton dumped_something = true;
56567cc0636SGreg Clayton strm << name;
56667cc0636SGreg Clayton }
56767cc0636SGreg Clayton return dumped_something;
56867cc0636SGreg Clayton }
56967cc0636SGreg Clayton
DeepCopy(const OptionValueSP & new_parent) const570f0f183eeSTatyana Krasnukha OptionValueSP OptionValue::DeepCopy(const OptionValueSP &new_parent) const {
571e913a754SDavid Blaikie auto clone = Clone();
572f0f183eeSTatyana Krasnukha clone->SetParent(new_parent);
573f0f183eeSTatyana Krasnukha return clone;
574f0f183eeSTatyana Krasnukha }
575f0f183eeSTatyana Krasnukha
AutoComplete(CommandInterpreter & interpreter,CompletionRequest & request)576ae34ed2cSRaphael Isemann void OptionValue::AutoComplete(CommandInterpreter &interpreter,
577ae34ed2cSRaphael Isemann CompletionRequest &request) {}
57867cc0636SGreg Clayton
SetValueFromString(llvm::StringRef value,VarSetOperationType op)57997206d57SZachary Turner Status OptionValue::SetValueFromString(llvm::StringRef value,
580b9c1b51eSKate Stone VarSetOperationType op) {
58197206d57SZachary Turner Status error;
582b9c1b51eSKate Stone switch (op) {
58367cc0636SGreg Clayton case eVarSetOperationReplace:
584b9c1b51eSKate Stone error.SetErrorStringWithFormat(
585b9c1b51eSKate Stone "%s objects do not support the 'replace' operation",
586b9c1b51eSKate Stone GetTypeAsCString());
58767cc0636SGreg Clayton break;
58867cc0636SGreg Clayton case eVarSetOperationInsertBefore:
589b9c1b51eSKate Stone error.SetErrorStringWithFormat(
590b9c1b51eSKate Stone "%s objects do not support the 'insert-before' operation",
591b9c1b51eSKate Stone GetTypeAsCString());
59267cc0636SGreg Clayton break;
59367cc0636SGreg Clayton case eVarSetOperationInsertAfter:
594b9c1b51eSKate Stone error.SetErrorStringWithFormat(
595b9c1b51eSKate Stone "%s objects do not support the 'insert-after' operation",
596b9c1b51eSKate Stone GetTypeAsCString());
59767cc0636SGreg Clayton break;
59867cc0636SGreg Clayton case eVarSetOperationRemove:
599b9c1b51eSKate Stone error.SetErrorStringWithFormat(
600b9c1b51eSKate Stone "%s objects do not support the 'remove' operation", GetTypeAsCString());
60167cc0636SGreg Clayton break;
60267cc0636SGreg Clayton case eVarSetOperationAppend:
603b9c1b51eSKate Stone error.SetErrorStringWithFormat(
604b9c1b51eSKate Stone "%s objects do not support the 'append' operation", GetTypeAsCString());
60567cc0636SGreg Clayton break;
60667cc0636SGreg Clayton case eVarSetOperationClear:
607b9c1b51eSKate Stone error.SetErrorStringWithFormat(
608b9c1b51eSKate Stone "%s objects do not support the 'clear' operation", GetTypeAsCString());
60967cc0636SGreg Clayton break;
61067cc0636SGreg Clayton case eVarSetOperationAssign:
611b9c1b51eSKate Stone error.SetErrorStringWithFormat(
612b9c1b51eSKate Stone "%s objects do not support the 'assign' operation", GetTypeAsCString());
61367cc0636SGreg Clayton break;
61467cc0636SGreg Clayton case eVarSetOperationInvalid:
615b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid operation performed on a %s object",
616b9c1b51eSKate Stone GetTypeAsCString());
61767cc0636SGreg Clayton break;
61867cc0636SGreg Clayton }
61967cc0636SGreg Clayton return error;
62067cc0636SGreg Clayton }
621