[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
|
|
|
//===-- OptionValueString.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/OptionValueString.h"
|
|
|
|
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.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;
|
|
|
|
|
|
|
|
void OptionValueString::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.PutCString(" = ");
|
|
|
|
if (!m_current_value.empty() || m_value_was_set) {
|
2012-09-01 08:38:36 +08:00
|
|
|
if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
|
|
|
|
std::string expanded_escape_value;
|
|
|
|
Args::ExpandEscapedCharacters(m_current_value.c_str(),
|
|
|
|
expanded_escape_value);
|
|
|
|
if (dump_mask & eDumpOptionRaw)
|
|
|
|
strm.Printf("%s", expanded_escape_value.c_str());
|
|
|
|
else
|
|
|
|
strm.Printf("\"%s\"", expanded_escape_value.c_str());
|
2012-08-23 01:17:09 +08:00
|
|
|
} else {
|
2012-09-01 08:38:36 +08:00
|
|
|
if (dump_mask & eDumpOptionRaw)
|
|
|
|
strm.Printf("%s", m_current_value.c_str());
|
|
|
|
else
|
|
|
|
strm.Printf("\"%s\"", m_current_value.c_str());
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValueString::SetValueFromString(llvm::StringRef value,
|
|
|
|
VarSetOperationType op) {
|
|
|
|
Status error;
|
2013-03-06 10:19:38 +08:00
|
|
|
|
2015-02-20 19:14:59 +08:00
|
|
|
std::string value_str = value.str();
|
|
|
|
value = value.trim();
|
|
|
|
if (value.size() > 0) {
|
|
|
|
switch (value.front()) {
|
2013-03-06 10:19:38 +08:00
|
|
|
case '"':
|
|
|
|
case '\'': {
|
2015-02-20 19:14:59 +08:00
|
|
|
if (value.size() <= 1 || value.back() != value.front()) {
|
2013-03-06 10:19:38 +08:00
|
|
|
error.SetErrorString("mismatched quotes");
|
|
|
|
return error;
|
|
|
|
}
|
2015-05-23 03:33:54 +08:00
|
|
|
value = value.drop_front().drop_back();
|
2013-03-06 10:19:38 +08:00
|
|
|
} break;
|
|
|
|
}
|
2015-02-20 19:14:59 +08:00
|
|
|
value_str = value.str();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-03-06 10:19:38 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
switch (op) {
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
case eVarSetOperationRemove:
|
2012-12-12 06:42:19 +08:00
|
|
|
if (m_validator) {
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_validator(value_str.c_str(), m_validator_baton);
|
2012-12-12 06:42:19 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
2015-02-20 19:14:59 +08:00
|
|
|
error = OptionValue::SetValueFromString(value, op);
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationAppend: {
|
2015-01-14 05:13:08 +08:00
|
|
|
std::string new_value(m_current_value);
|
2015-02-20 19:14:59 +08:00
|
|
|
if (value.size() > 0) {
|
2015-01-14 05:13:08 +08:00
|
|
|
if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
|
|
|
|
std::string str;
|
2015-02-20 19:14:59 +08:00
|
|
|
Args::EncodeEscapeSequences(value_str.c_str(), str);
|
2015-01-14 05:13:08 +08:00
|
|
|
new_value.append(str);
|
|
|
|
} else
|
2020-01-29 03:23:46 +08:00
|
|
|
new_value.append(std::string(value));
|
2012-09-01 08:38:36 +08:00
|
|
|
}
|
2015-01-14 05:13:08 +08:00
|
|
|
if (m_validator) {
|
|
|
|
error = m_validator(new_value.c_str(), m_validator_baton);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
m_current_value.assign(new_value);
|
|
|
|
NotifyValueChanged();
|
2012-08-23 01:17:09 +08:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case eVarSetOperationClear:
|
|
|
|
Clear();
|
2015-01-14 05:13:08 +08:00
|
|
|
NotifyValueChanged();
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationReplace:
|
|
|
|
case eVarSetOperationAssign:
|
2012-12-12 06:42:19 +08:00
|
|
|
if (m_validator) {
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_validator(value_str.c_str(), m_validator_baton);
|
2012-12-12 06:42:19 +08:00
|
|
|
if (error.Fail())
|
2015-02-20 19:14:59 +08:00
|
|
|
return error;
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
m_value_was_set = true;
|
2012-09-01 08:38:36 +08:00
|
|
|
if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
|
2015-02-20 19:14:59 +08:00
|
|
|
Args::EncodeEscapeSequences(value_str.c_str(), m_current_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2016-09-24 01:48:13 +08:00
|
|
|
SetCurrentValue(value_str);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-01-14 05:13:08 +08:00
|
|
|
NotifyValueChanged();
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValueString::SetCurrentValue(llvm::StringRef value) {
|
2012-12-12 06:42:19 +08:00
|
|
|
if (m_validator) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error(m_validator(value.str().c_str(), m_validator_baton));
|
2012-12-12 06:42:19 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
2020-01-29 03:23:46 +08:00
|
|
|
m_current_value.assign(std::string(value));
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2012-12-12 06:42:19 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status OptionValueString::AppendToCurrentValue(const char *value) {
|
2012-12-12 06:42:19 +08:00
|
|
|
if (value && value[0]) {
|
|
|
|
if (m_validator) {
|
|
|
|
std::string new_value(m_current_value);
|
|
|
|
new_value.append(value);
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error(m_validator(value, m_validator_baton));
|
2012-12-12 06:42:19 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
m_current_value.assign(new_value);
|
|
|
|
} else
|
|
|
|
m_current_value.append(value);
|
|
|
|
}
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2012-12-12 06:42:19 +08:00
|
|
|
}
|