[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- OptionValueArray.cpp ----------------------------------------------===//
|
2012-08-22 17:17:09 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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
|
2012-08-22 17:17:09 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionValueArray.h"
|
|
|
|
|
2018-04-17 18:53:35 +00:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2012-08-22 17:17:09 +00:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
void OptionValueArray::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
|
|
|
|
uint32_t dump_mask) {
|
|
|
|
const Type array_element_type = ConvertTypeMaskToType(m_type_mask);
|
|
|
|
if (dump_mask & eDumpOptionType) {
|
|
|
|
if ((GetType() == eTypeArray) && (m_type_mask != eTypeInvalid))
|
|
|
|
strm.Printf("(%s of %ss)", GetTypeAsCString(),
|
|
|
|
GetBuiltinTypeAsCString(array_element_type));
|
|
|
|
else
|
|
|
|
strm.Printf("(%s)", GetTypeAsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
if (dump_mask & eDumpOptionValue) {
|
2018-10-26 00:00:17 +00:00
|
|
|
const bool one_line = dump_mask & eDumpOptionCommand;
|
2012-08-22 17:17:09 +00:00
|
|
|
const uint32_t size = m_values.size();
|
2018-10-26 00:00:17 +00:00
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.Printf(" =%s", (m_values.size() > 0 && !one_line) ? "\n" : "");
|
|
|
|
if (!one_line)
|
|
|
|
strm.IndentMore();
|
2012-08-22 17:17:09 +00:00
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
2018-10-26 00:00:17 +00:00
|
|
|
if (!one_line) {
|
|
|
|
strm.Indent();
|
|
|
|
strm.Printf("[%u]: ", i);
|
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
const uint32_t extra_dump_options = m_raw_value_dump ? eDumpOptionRaw : 0;
|
|
|
|
switch (array_element_type) {
|
|
|
|
default:
|
|
|
|
case eTypeArray:
|
|
|
|
case eTypeDictionary:
|
|
|
|
case eTypeProperties:
|
|
|
|
case eTypeFileSpecList:
|
|
|
|
case eTypePathMap:
|
|
|
|
m_values[i]->DumpValue(exe_ctx, strm, dump_mask | extra_dump_options);
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
case eTypeBoolean:
|
2015-01-12 20:44:02 +00:00
|
|
|
case eTypeChar:
|
2012-08-22 17:17:09 +00:00
|
|
|
case eTypeEnum:
|
|
|
|
case eTypeFileSpec:
|
2020-07-16 11:34:50 -07:00
|
|
|
case eTypeFileLineColumn:
|
2012-08-22 17:17:09 +00:00
|
|
|
case eTypeFormat:
|
|
|
|
case eTypeSInt64:
|
|
|
|
case eTypeString:
|
|
|
|
case eTypeUInt64:
|
|
|
|
case eTypeUUID:
|
|
|
|
// No need to show the type for dictionaries of simple items
|
|
|
|
m_values[i]->DumpValue(exe_ctx, strm, (dump_mask & (~eDumpOptionType)) |
|
|
|
|
extra_dump_options);
|
|
|
|
break;
|
|
|
|
}
|
2018-10-26 00:00:17 +00:00
|
|
|
|
|
|
|
if (!one_line) {
|
|
|
|
if (i < (size - 1))
|
|
|
|
strm.EOL();
|
|
|
|
} else {
|
|
|
|
strm << ' ';
|
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
2018-10-26 00:00:17 +00:00
|
|
|
if (!one_line)
|
|
|
|
strm.IndentLess();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 11:00:22 -07:00
|
|
|
llvm::json::Value OptionValueArray::ToJSON(const ExecutionContext *exe_ctx) {
|
|
|
|
llvm::json::Array json_array;
|
|
|
|
const uint32_t size = m_values.size();
|
|
|
|
for (uint32_t i = 0; i < size; ++i)
|
|
|
|
json_array.emplace_back(m_values[i]->ToJSON(exe_ctx));
|
|
|
|
return json_array;
|
|
|
|
}
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status OptionValueArray::SetValueFromString(llvm::StringRef value,
|
|
|
|
VarSetOperationType op) {
|
2016-11-02 20:34:10 +00:00
|
|
|
Args args(value.str());
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error = SetArgs(args, op);
|
2015-02-13 14:31:06 +00:00
|
|
|
if (error.Success())
|
|
|
|
NotifyValueChanged();
|
|
|
|
return error;
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::OptionValueSP
|
2017-05-12 04:51:55 +00:00
|
|
|
OptionValueArray::GetSubValue(const ExecutionContext *exe_ctx,
|
2023-05-02 00:17:52 -07:00
|
|
|
llvm::StringRef name, Status &error) const {
|
2016-11-17 18:08:12 +00:00
|
|
|
if (name.empty() || name.front() != '[') {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"invalid value path '%s', %s values only support '[<index>]' subvalues "
|
|
|
|
"where <index> is a positive or negative array index",
|
|
|
|
name.str().c_str(), GetTypeAsCString());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
|
2016-11-17 18:08:12 +00:00
|
|
|
name = name.drop_front();
|
|
|
|
llvm::StringRef index, sub_value;
|
|
|
|
std::tie(index, sub_value) = name.split(']');
|
|
|
|
if (index.size() == name.size()) {
|
|
|
|
// Couldn't find a closing bracket
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t array_count = m_values.size();
|
|
|
|
int32_t idx = 0;
|
|
|
|
if (index.getAsInteger(0, idx))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
uint32_t new_idx = UINT32_MAX;
|
|
|
|
if (idx < 0) {
|
|
|
|
// Access from the end of the array if the index is negative
|
|
|
|
new_idx = array_count - idx;
|
|
|
|
} else {
|
|
|
|
// Just a standard index
|
|
|
|
new_idx = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_idx < array_count) {
|
|
|
|
if (m_values[new_idx]) {
|
|
|
|
if (!sub_value.empty())
|
2023-05-02 00:17:52 -07:00
|
|
|
return m_values[new_idx]->GetSubValue(exe_ctx, sub_value, error);
|
2016-11-17 18:08:12 +00:00
|
|
|
else
|
|
|
|
return m_values[new_idx];
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-17 18:08:12 +00:00
|
|
|
if (array_count == 0)
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"index %i is not valid for an empty array", idx);
|
|
|
|
else if (idx > 0)
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"index %i out of range, valid values are 0 through %" PRIu64,
|
|
|
|
idx, (uint64_t)(array_count - 1));
|
|
|
|
else
|
|
|
|
error.SetErrorStringWithFormat("negative index %i out of range, "
|
|
|
|
"valid values are -1 through "
|
|
|
|
"-%" PRIu64,
|
|
|
|
idx, (uint64_t)array_count);
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
|
|
|
return OptionValueSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t OptionValueArray::GetArgs(Args &args) const {
|
2016-11-17 18:08:12 +00:00
|
|
|
args.Clear();
|
2012-08-22 17:17:09 +00:00
|
|
|
const uint32_t size = m_values.size();
|
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
2023-05-14 19:58:16 -07:00
|
|
|
auto string_value = m_values[i]->GetValueAs<llvm::StringRef>();
|
2023-05-01 20:34:51 -07:00
|
|
|
if (string_value)
|
|
|
|
args.AppendArgument(*string_value);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
|
|
|
|
return args.GetArgumentCount();
|
|
|
|
}
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) {
|
|
|
|
Status error;
|
2012-08-22 17:17:09 +00:00
|
|
|
const size_t argc = args.GetArgumentCount();
|
|
|
|
switch (op) {
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
error.SetErrorString("unsupported operation");
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
if (argc > 1) {
|
2021-09-24 23:36:49 +02:00
|
|
|
uint32_t idx;
|
2012-08-22 17:17:09 +00:00
|
|
|
const uint32_t count = GetSize();
|
2021-09-24 23:36:49 +02:00
|
|
|
if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
|
2012-08-22 17:17:09 +00:00
|
|
|
error.SetErrorStringWithFormat(
|
2021-09-24 23:36:49 +02:00
|
|
|
"invalid insert array index %s, index must be 0 through %u",
|
|
|
|
args.GetArgumentAtIndex(0), count);
|
2012-08-22 17:17:09 +00:00
|
|
|
} else {
|
|
|
|
if (op == eVarSetOperationInsertAfter)
|
|
|
|
++idx;
|
|
|
|
for (size_t i = 1; i < argc; ++i, ++idx) {
|
2015-01-15 20:08:35 +00:00
|
|
|
lldb::OptionValueSP value_sp(CreateValueFromCStringForTypeMask(
|
2012-08-22 17:17:09 +00:00
|
|
|
args.GetArgumentAtIndex(i), m_type_mask, error));
|
|
|
|
if (value_sp) {
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
if (idx >= m_values.size())
|
|
|
|
m_values.push_back(value_sp);
|
|
|
|
else
|
|
|
|
m_values.insert(m_values.begin() + idx, value_sp);
|
|
|
|
} else {
|
|
|
|
error.SetErrorString(
|
|
|
|
"array of complex types must subclass OptionValueArray");
|
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
} else {
|
|
|
|
error.SetErrorString("insert operation takes an array index followed by "
|
|
|
|
"one or more values");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
case eVarSetOperationRemove:
|
|
|
|
if (argc > 0) {
|
2015-01-15 20:08:35 +00:00
|
|
|
const uint32_t size = m_values.size();
|
2012-08-22 17:17:09 +00:00
|
|
|
std::vector<int> remove_indexes;
|
|
|
|
bool all_indexes_valid = true;
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < argc; ++i) {
|
2021-09-24 23:36:49 +02:00
|
|
|
size_t idx;
|
|
|
|
if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx >= size) {
|
2012-08-22 17:17:09 +00:00
|
|
|
all_indexes_valid = false;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
remove_indexes.push_back(idx);
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
if (all_indexes_valid) {
|
|
|
|
size_t num_remove_indexes = remove_indexes.size();
|
|
|
|
if (num_remove_indexes) {
|
|
|
|
// Sort and then erase in reverse so indexes are always valid
|
|
|
|
if (num_remove_indexes > 1) {
|
2022-07-23 15:07:49 +02:00
|
|
|
llvm::sort(remove_indexes);
|
2012-08-22 17:17:09 +00:00
|
|
|
for (std::vector<int>::const_reverse_iterator
|
|
|
|
pos = remove_indexes.rbegin(),
|
|
|
|
end = remove_indexes.rend();
|
|
|
|
pos != end; ++pos) {
|
|
|
|
m_values.erase(m_values.begin() + *pos);
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2012-08-22 17:17:09 +00:00
|
|
|
// Only one index
|
|
|
|
m_values.erase(m_values.begin() + remove_indexes.front());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"invalid array index '%s', aborting remove operation",
|
|
|
|
args.GetArgumentAtIndex(i));
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 17:17:09 +00:00
|
|
|
error.SetErrorString("remove operation takes one or more array indices");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
case eVarSetOperationClear:
|
|
|
|
Clear();
|
2016-02-16 04:14:33 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-08-22 17:17:09 +00:00
|
|
|
case eVarSetOperationReplace:
|
|
|
|
if (argc > 1) {
|
2021-09-24 23:36:49 +02:00
|
|
|
uint32_t idx;
|
2012-08-22 17:17:09 +00:00
|
|
|
const uint32_t count = GetSize();
|
2021-09-24 23:36:49 +02:00
|
|
|
if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
|
2012-08-22 17:17:09 +00:00
|
|
|
error.SetErrorStringWithFormat(
|
2021-09-24 23:36:49 +02:00
|
|
|
"invalid replace array index %s, index must be 0 through %u",
|
|
|
|
args.GetArgumentAtIndex(0), count);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2012-08-22 17:17:09 +00:00
|
|
|
for (size_t i = 1; i < argc; ++i, ++idx) {
|
|
|
|
lldb::OptionValueSP value_sp(CreateValueFromCStringForTypeMask(
|
|
|
|
args.GetArgumentAtIndex(i), m_type_mask, error));
|
|
|
|
if (value_sp) {
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
if (idx < count)
|
|
|
|
m_values[idx] = value_sp;
|
|
|
|
else
|
|
|
|
m_values.push_back(value_sp);
|
|
|
|
} else {
|
|
|
|
error.SetErrorString(
|
|
|
|
"array of complex types must subclass OptionValueArray");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 17:17:09 +00:00
|
|
|
error.SetErrorString("replace operation takes an array index followed by "
|
|
|
|
"one or more values");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationAssign:
|
|
|
|
m_values.clear();
|
|
|
|
// Fall through to append case
|
2022-08-08 11:31:49 -07:00
|
|
|
[[fallthrough]];
|
2012-08-22 17:17:09 +00:00
|
|
|
case eVarSetOperationAppend:
|
|
|
|
for (size_t i = 0; i < argc; ++i) {
|
|
|
|
lldb::OptionValueSP value_sp(CreateValueFromCStringForTypeMask(
|
|
|
|
args.GetArgumentAtIndex(i), m_type_mask, error));
|
|
|
|
if (value_sp) {
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
m_value_was_set = true;
|
|
|
|
AppendValue(value_sp);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2012-08-22 17:17:09 +00:00
|
|
|
error.SetErrorString(
|
|
|
|
"array of complex types must subclass OptionValueArray");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-08-22 17:17:09 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2021-02-20 00:49:42 +03:00
|
|
|
OptionValueSP
|
|
|
|
OptionValueArray::DeepCopy(const OptionValueSP &new_parent) const {
|
|
|
|
auto copy_sp = OptionValue::DeepCopy(new_parent);
|
|
|
|
// copy_sp->GetAsArray cannot be used here as it doesn't work for derived
|
|
|
|
// types that override GetType returning a different value.
|
|
|
|
auto *array_value_ptr = static_cast<OptionValueArray *>(copy_sp.get());
|
|
|
|
lldbassert(array_value_ptr);
|
|
|
|
|
|
|
|
for (auto &value : array_value_ptr->m_values)
|
|
|
|
value = value->DeepCopy(copy_sp);
|
|
|
|
|
|
|
|
return copy_sp;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|