[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 15:23:27 +08:00
|
|
|
//===-- OptionValuePathMappings.cpp ---------------------------------------===//
|
2012-08-23 01:17:09 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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-23 01:17:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionValuePathMappings.h"
|
|
|
|
|
2018-11-02 01:09:25 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2021-10-05 14:29:16 +08:00
|
|
|
|
2016-07-09 07:06:38 +08:00
|
|
|
static bool VerifyPathExists(const char *path) {
|
|
|
|
if (path && path[0])
|
2018-11-02 01:09:25 +08:00
|
|
|
return FileSystem::Instance().Exists(path);
|
2016-07-09 07:06:38 +08:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
void OptionValuePathMappings::DumpValue(const ExecutionContext *exe_ctx,
|
|
|
|
Stream &strm, uint32_t dump_mask) {
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.Printf("(%s)", GetTypeAsCString());
|
|
|
|
if (dump_mask & eDumpOptionValue) {
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.Printf(" =%s", (m_path_mappings.GetSize() > 0) ? "\n" : "");
|
|
|
|
m_path_mappings.Dump(&strm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value,
|
|
|
|
VarSetOperationType op) {
|
|
|
|
Status error;
|
2016-11-03 04:34:10 +08:00
|
|
|
Args args(value.str());
|
2012-08-23 01:17:09 +08:00
|
|
|
const size_t argc = args.GetArgumentCount();
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case eVarSetOperationClear:
|
|
|
|
Clear();
|
2016-07-09 07:06:38 +08:00
|
|
|
NotifyValueChanged();
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case eVarSetOperationReplace:
|
|
|
|
// Must be at least one index + 1 pair of paths, and the pair count must be
|
|
|
|
// even
|
|
|
|
if (argc >= 3 && (((argc - 1) & 1) == 0)) {
|
2021-09-25 05:36:49 +08:00
|
|
|
uint32_t idx;
|
2016-07-09 07:06:38 +08:00
|
|
|
const uint32_t count = m_path_mappings.GetSize();
|
2021-09-25 05:36:49 +08:00
|
|
|
if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
|
2016-07-09 07:06:38 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2021-09-25 05:36:49 +08:00
|
|
|
"invalid file list index %s, index must be 0 through %u",
|
|
|
|
args.GetArgumentAtIndex(0), count);
|
2012-08-23 01:17:09 +08:00
|
|
|
} else {
|
2016-07-09 07:06:38 +08:00
|
|
|
bool changed = false;
|
2020-04-04 08:29:32 +08:00
|
|
|
for (size_t i = 1; i < argc; idx++, i += 2) {
|
2016-07-09 07:06:38 +08:00
|
|
|
const char *orginal_path = args.GetArgumentAtIndex(i);
|
|
|
|
const char *replace_path = args.GetArgumentAtIndex(i + 1);
|
|
|
|
if (VerifyPathExists(replace_path)) {
|
2021-11-02 13:14:48 +08:00
|
|
|
if (!m_path_mappings.Replace(orginal_path, replace_path, idx,
|
|
|
|
m_notify_changes))
|
|
|
|
m_path_mappings.Append(orginal_path, replace_path,
|
|
|
|
m_notify_changes);
|
2015-01-14 05:13:08 +08:00
|
|
|
changed = true;
|
2012-08-23 01:17:09 +08:00
|
|
|
} else {
|
2020-04-01 08:08:40 +08:00
|
|
|
std::string previousError =
|
|
|
|
error.Fail() ? std::string(error.AsCString()) + "\n" : "";
|
2012-08-23 01:17:09 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2020-04-01 08:08:40 +08:00
|
|
|
"%sthe replacement path doesn't exist: \"%s\"",
|
|
|
|
previousError.c_str(), replace_path);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 07:06:38 +08:00
|
|
|
if (changed)
|
|
|
|
NotifyValueChanged();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-23 01:17:09 +08:00
|
|
|
error.SetErrorString("replace operation takes an array index followed by "
|
|
|
|
"one or more path pairs");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
case eVarSetOperationAssign:
|
|
|
|
if (argc < 2 || (argc & 1)) {
|
|
|
|
error.SetErrorString("assign operation takes one or more path pairs");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
m_path_mappings.Clear(m_notify_changes);
|
|
|
|
// Fall through to append case
|
2016-02-16 12:14:33 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2012-08-23 01:17:09 +08:00
|
|
|
case eVarSetOperationAppend:
|
|
|
|
if (argc < 2 || (argc & 1)) {
|
|
|
|
error.SetErrorString("append operation takes one or more path pairs");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
} else {
|
2016-07-09 07:06:38 +08:00
|
|
|
bool changed = false;
|
2012-08-23 01:17:09 +08:00
|
|
|
for (size_t i = 0; i < argc; i += 2) {
|
2016-07-09 07:06:38 +08:00
|
|
|
const char *orginal_path = args.GetArgumentAtIndex(i);
|
|
|
|
const char *replace_path = args.GetArgumentAtIndex(i + 1);
|
|
|
|
if (VerifyPathExists(replace_path)) {
|
2021-11-02 13:14:48 +08:00
|
|
|
m_path_mappings.Append(orginal_path, replace_path, m_notify_changes);
|
2016-07-09 07:06:38 +08:00
|
|
|
m_value_was_set = true;
|
|
|
|
changed = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2020-04-01 08:08:40 +08:00
|
|
|
std::string previousError =
|
|
|
|
error.Fail() ? std::string(error.AsCString()) + "\n" : "";
|
2016-07-09 07:06:38 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2020-04-01 08:08:40 +08:00
|
|
|
"%sthe replacement path doesn't exist: \"%s\"",
|
|
|
|
previousError.c_str(), replace_path);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 07:06:38 +08:00
|
|
|
if (changed)
|
|
|
|
NotifyValueChanged();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
2015-02-20 19:14:59 +08:00
|
|
|
// Must be at least one index + 1 pair of paths, and the pair count must be
|
2016-09-07 04:57:50 +08:00
|
|
|
// even
|
2012-08-23 01:17:09 +08:00
|
|
|
if (argc >= 3 && (((argc - 1) & 1) == 0)) {
|
2021-09-25 05:36:49 +08:00
|
|
|
uint32_t idx;
|
2012-08-23 01:17:09 +08:00
|
|
|
const uint32_t count = m_path_mappings.GetSize();
|
2021-09-25 05:36:49 +08:00
|
|
|
if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
|
2015-02-20 19:14:59 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2021-09-25 05:36:49 +08:00
|
|
|
"invalid file list index %s, index must be 0 through %u",
|
|
|
|
args.GetArgumentAtIndex(0), count);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2015-02-20 19:14:59 +08:00
|
|
|
bool changed = false;
|
|
|
|
if (op == eVarSetOperationInsertAfter)
|
2016-09-07 04:57:50 +08:00
|
|
|
++idx;
|
2020-04-01 08:08:40 +08:00
|
|
|
for (size_t i = 1; i < argc; i += 2) {
|
2016-07-09 07:06:38 +08:00
|
|
|
const char *orginal_path = args.GetArgumentAtIndex(i);
|
|
|
|
const char *replace_path = args.GetArgumentAtIndex(i + 1);
|
2015-02-20 19:14:59 +08:00
|
|
|
if (VerifyPathExists(replace_path)) {
|
2021-11-02 13:14:48 +08:00
|
|
|
m_path_mappings.Insert(orginal_path, replace_path, idx,
|
|
|
|
m_notify_changes);
|
2015-02-20 19:14:59 +08:00
|
|
|
changed = true;
|
2020-04-01 08:08:40 +08:00
|
|
|
idx++;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2020-04-01 08:08:40 +08:00
|
|
|
std::string previousError =
|
|
|
|
error.Fail() ? std::string(error.AsCString()) + "\n" : "";
|
2012-08-23 01:17:09 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2020-04-01 08:08:40 +08:00
|
|
|
"%sthe replacement path doesn't exist: \"%s\"",
|
|
|
|
previousError.c_str(), replace_path);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-09 07:06:38 +08:00
|
|
|
if (changed)
|
|
|
|
NotifyValueChanged();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-23 01:17:09 +08:00
|
|
|
error.SetErrorString("insert operation takes an array index followed by "
|
|
|
|
"one or more path pairs");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case eVarSetOperationRemove:
|
|
|
|
if (argc > 0) {
|
|
|
|
std::vector<int> remove_indexes;
|
2020-04-04 08:29:32 +08:00
|
|
|
for (size_t i = 0; i < argc; ++i) {
|
2021-09-25 05:36:49 +08:00
|
|
|
int idx;
|
|
|
|
if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx < 0 ||
|
|
|
|
idx >= (int)m_path_mappings.GetSize()) {
|
2020-04-04 08:29:32 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"invalid array index '%s', aborting remove operation",
|
|
|
|
args.GetArgumentAtIndex(i));
|
|
|
|
break;
|
|
|
|
} else
|
2012-08-23 01:17:09 +08:00
|
|
|
remove_indexes.push_back(idx);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 08:29:32 +08:00
|
|
|
// Sort and then erase in reverse so indexes are always valid
|
|
|
|
llvm::sort(remove_indexes.begin(), remove_indexes.end());
|
|
|
|
for (auto index : llvm::reverse(remove_indexes))
|
|
|
|
m_path_mappings.Remove(index, m_notify_changes);
|
|
|
|
NotifyValueChanged();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-08-23 01:17:09 +08:00
|
|
|
error.SetErrorString("remove operation takes one or more array index");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
error = OptionValue::SetValueFromString(value, op);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
return error;
|
|
|
|
}
|