Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -15,7 +15,9 @@ void CommandGroup::AddSequential(Command* command) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
}
if (!AssertUnlocked("Cannot add new command to command group")) return;
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence);
@@ -23,7 +25,9 @@ void CommandGroup::AddSequential(Command* command) {
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
for (auto&& requirement : command->GetRequirements()) Requires(requirement);
for (auto&& requirement : command->GetRequirements()) {
Requires(requirement);
}
}
void CommandGroup::AddSequential(Command* command, double timeout) {
@@ -31,7 +35,9 @@ void CommandGroup::AddSequential(Command* command, double timeout) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
}
if (!AssertUnlocked("Cannot add new command to command group")) return;
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
if (timeout < 0.0) {
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
return;
@@ -44,7 +50,9 @@ void CommandGroup::AddSequential(Command* command, double timeout) {
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
for (auto&& requirement : command->GetRequirements()) Requires(requirement);
for (auto&& requirement : command->GetRequirements()) {
Requires(requirement);
}
}
void CommandGroup::AddParallel(Command* command) {
@@ -52,7 +60,9 @@ void CommandGroup::AddParallel(Command* command) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
}
if (!AssertUnlocked("Cannot add new command to command group")) return;
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild);
@@ -60,7 +70,9 @@ void CommandGroup::AddParallel(Command* command) {
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
for (auto&& requirement : command->GetRequirements()) Requires(requirement);
for (auto&& requirement : command->GetRequirements()) {
Requires(requirement);
}
}
void CommandGroup::AddParallel(Command* command, double timeout) {
@@ -68,7 +80,9 @@ void CommandGroup::AddParallel(Command* command, double timeout) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
}
if (!AssertUnlocked("Cannot add new command to command group")) return;
if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
if (timeout < 0.0) {
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
return;
@@ -81,26 +95,36 @@ void CommandGroup::AddParallel(Command* command, double timeout) {
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
for (auto&& requirement : command->GetRequirements()) Requires(requirement);
for (auto&& requirement : command->GetRequirements()) {
Requires(requirement);
}
}
bool CommandGroup::IsInterruptible() const {
if (!Command::IsInterruptible()) return false;
if (!Command::IsInterruptible()) {
return false;
}
if (m_currentCommandIndex != -1 &&
static_cast<size_t>(m_currentCommandIndex) < m_commands.size()) {
Command* cmd = m_commands[m_currentCommandIndex].m_command;
if (!cmd->IsInterruptible()) return false;
if (!cmd->IsInterruptible()) {
return false;
}
}
for (const auto& child : m_children) {
if (!child->m_command->IsInterruptible()) return false;
if (!child->m_command->IsInterruptible()) {
return false;
}
}
return true;
}
int CommandGroup::GetSize() const { return m_children.size(); }
int CommandGroup::GetSize() const {
return m_children.size();
}
void CommandGroup::Initialize() {}
@@ -115,7 +139,9 @@ void CommandGroup::End() {}
void CommandGroup::Interrupted() {}
void CommandGroup::_Initialize() { m_currentCommandIndex = -1; }
void CommandGroup::_Initialize() {
m_currentCommandIndex = -1;
}
void CommandGroup::_Execute() {
CommandGroupEntry* entry;
@@ -132,7 +158,9 @@ void CommandGroup::_Execute() {
// If a command is prepared to run
if (cmd != nullptr) {
// If command timed out, cancel it so it's removed from the Scheduler
if (entry->IsTimedOut()) cmd->_Cancel();
if (entry->IsTimedOut()) {
cmd->_Cancel();
}
// If command finished or was canceled, remove it from Scheduler
if (cmd->Run()) {
@@ -219,7 +247,9 @@ void CommandGroup::_End() {
m_children.clear();
}
void CommandGroup::_Interrupted() { _End(); }
void CommandGroup::_Interrupted() {
_End();
}
void CommandGroup::CancelConflicts(Command* command) {
for (auto childIter = m_children.begin(); childIter != m_children.end();) {
@@ -235,6 +265,8 @@ void CommandGroup::CancelConflicts(Command* command) {
break;
}
}
if (!erased) childIter++;
if (!erased) {
childIter++;
}
}
}