[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
|
|
|
//===-- OptionValueBoolean.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/OptionValueBoolean.h"
|
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
#include "lldb/Host/PosixApi.h"
|
2018-04-10 17:03:59 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-03-22 02:25:04 +08:00
|
|
|
#include "lldb/Utility/StringList.h"
|
2014-06-27 13:17:41 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,
|
|
|
|
Stream &strm, uint32_t dump_mask) {
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.Printf("(%s)", GetTypeAsCString());
|
|
|
|
// if (dump_mask & eDumpOptionName)
|
|
|
|
// DumpQualifiedName (strm);
|
|
|
|
if (dump_mask & eDumpOptionValue) {
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.PutCString(" = ");
|
|
|
|
strm.PutCString(m_current_value ? "true" : "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,
|
|
|
|
VarSetOperationType op) {
|
|
|
|
Status error;
|
2012-08-23 01:17:09 +08:00
|
|
|
switch (op) {
|
|
|
|
case eVarSetOperationClear:
|
2015-02-20 19:14:59 +08:00
|
|
|
Clear();
|
2015-01-14 05:13:08 +08:00
|
|
|
NotifyValueChanged();
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationReplace:
|
|
|
|
case eVarSetOperationAssign: {
|
|
|
|
bool success = false;
|
2018-04-10 17:03:59 +08:00
|
|
|
bool value = OptionArgParser::ToBoolean(value_str, false, &success);
|
2012-08-23 01:17:09 +08:00
|
|
|
if (success) {
|
|
|
|
m_value_was_set = true;
|
|
|
|
m_current_value = value;
|
2015-02-20 19:14:59 +08:00
|
|
|
NotifyValueChanged();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2015-02-20 19:14:59 +08:00
|
|
|
if (value_str.size() == 0)
|
|
|
|
error.SetErrorString("invalid boolean string value <empty>");
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2012-08-23 01:17:09 +08:00
|
|
|
error.SetErrorStringWithFormat("invalid boolean string value: '%s'",
|
|
|
|
value_str.str().c_str());
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
case eVarSetOperationRemove:
|
|
|
|
case eVarSetOperationAppend:
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
error = OptionValue::SetValueFromString(value_str, op);
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 15:41:23 +08:00
|
|
|
void OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,
|
|
|
|
CompletionRequest &request) {
|
2019-10-09 00:29:36 +08:00
|
|
|
llvm::StringRef autocomplete_entries[] = {"true", "false", "on", "off",
|
|
|
|
"yes", "no", "1", "0"};
|
2012-08-23 08:22:02 +08:00
|
|
|
|
2019-10-09 00:29:36 +08:00
|
|
|
auto entries = llvm::makeArrayRef(autocomplete_entries);
|
2016-11-17 09:37:42 +08:00
|
|
|
|
|
|
|
// only suggest "true" or "false" by default
|
2018-07-14 02:28:14 +08:00
|
|
|
if (request.GetCursorArgumentPrefix().empty())
|
2016-11-17 09:37:42 +08:00
|
|
|
entries = entries.take_front(2);
|
|
|
|
|
2019-09-23 16:59:21 +08:00
|
|
|
for (auto entry : entries)
|
|
|
|
request.TryCompleteCurrentArg(entry);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|