Skip to content

Commit

Permalink
Bump to clang-format-14 (supercollider#6196)
Browse files Browse the repository at this point in the history
Bumps clang-format, the Ubuntu version on the CI, adds some rules to .clang-format to reduce the number of changes, and reformats several files causing mostly small minor changes, with the exception of getopt.c which did some odd things with the macro indentation of #ifs.

Since many can't access the old clang-format without building from source, this is quite a pressing issue.

* bump clang-format version from 8 to 14
* add new rules for clang-format 14
* bump to ubuntu-22.04 in linting step b/c of clang-format version bump
* reformat develop with clang-14
  • Loading branch information
capital-G authored May 20, 2024
1 parent 51d4d23 commit 2027bac
Show file tree
Hide file tree
Showing 32 changed files with 264 additions and 324 deletions.
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ NamespaceIndentation: None
SortIncludes: false
SpaceBeforeCtorInitializerColon: false
TabWidth: 4
SpaceInEmptyBlock: false
PackConstructorInitializers: CurrentLine
AllowShortFunctionsOnASingleLine: All
AllowShortBlocksOnASingleLine: Always
AllowShortLoopsOnASingleLine: false
ForEachMacros: ['Q_FOREACH', 'foreach']
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterForeachMacros: true
6 changes: 3 additions & 3 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
- cron: '0 0 * * 0' # run weekly to refresh cache
jobs:
lint:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
outputs:
sc-version: ${{ steps.set-version.outputs.version }}
steps:
Expand All @@ -29,9 +29,9 @@ jobs:
lintspaces -e .editorconfig SCClassLibrary/**/*.sc || true # ignore failure
- name: lint cpp files
run: |
sudo apt-get install -y clang-format-8
sudo apt-get install -y clang-format-14
echo "Running tools/clang-format.py lintall"
tools/clang-format.py -c clang-format-8 -d clang-format-diff-8 lintall || exit 1
tools/clang-format.py -c clang-format-14 -d clang-format-diff-14 lintall || exit 1
echo "Lint successful"
- name: set version string for artifacts
id: set-version
Expand Down
4 changes: 3 additions & 1 deletion QtCollider/widgets/QcFileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ private Q_SLOTS:
if (res == QDialog::Accepted) {
QStringList files = dialog->selectedFiles();
QVariantList varFiles;
Q_FOREACH (QString f, files) { varFiles << QVariant(f); }
Q_FOREACH (QString f, files) {
varFiles << QVariant(f);
}
Q_EMIT(accepted(varFiles));
} else {
Q_EMIT(rejected());
Expand Down
4 changes: 3 additions & 1 deletion QtCollider/widgets/QcGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,9 @@ void QcGraph::paintEvent(QPaintEvent*) {
QList<QcGraphModel::Connection> conns = _model.connections();

if (conns.count()) {
Q_FOREACH (QcGraphModel::Connection c, conns) { addCurve(lines, c.a, c.b); }
Q_FOREACH (QcGraphModel::Connection c, conns) {
addCurve(lines, c.a, c.b);
}

} else {
QcGraphElement* e1 = elems[0];
Expand Down
24 changes: 11 additions & 13 deletions common/SC_AllocPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,16 @@ class AllocPool {
static size_t SmallBinIndex(size_t inSize) { return inSize >> 4; }

static size_t BinIndex2(size_t inSize) {
return ((inSize < 1024) ? (inSize >> 4)
: (inSize < 2048)
? 56 + (inSize >> 7)
: (inSize < 4096) ? 64 + (inSize >> 8)
: (inSize < 8192) ? 72 + (inSize >> 9)
: (inSize < 16384) ? 80 + (inSize >> 10)
: (inSize < 32768) ? 88 + (inSize >> 11)
: (inSize < 65536)
? 96 + (inSize >> 12)
: (inSize < 131072) ? 104 + (inSize >> 13)
: (inSize < 262144) ? 112 + (inSize >> 14) : 127);
return ((inSize < 1024) ? (inSize >> 4)
: (inSize < 2048) ? 56 + (inSize >> 7)
: (inSize < 4096) ? 64 + (inSize >> 8)
: (inSize < 8192) ? 72 + (inSize >> 9)
: (inSize < 16384) ? 80 + (inSize >> 10)
: (inSize < 32768) ? 88 + (inSize >> 11)
: (inSize < 65536) ? 96 + (inSize >> 12)
: (inSize < 131072) ? 104 + (inSize >> 13)
: (inSize < 262144) ? 112 + (inSize >> 14)
: 127);
}

static size_t BinIndex(size_t inSize) {
Expand Down Expand Up @@ -211,8 +210,7 @@ class AllocPool {
if (binBits >= bitValue) {
binBits = (~(bitValue - 1) & binBits);
} else {
for (++word; word < 4 && !mBinBlocks[word]; ++word) {
}
for (++word; word < 4 && !mBinBlocks[word]; ++word) {}
if (word == 4)
return -1;
binBits = mBinBlocks[word];
Expand Down
99 changes: 48 additions & 51 deletions common/SC_VFP11.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inline void initVFP() {
__asm__ __volatile__("fmrx %[tmp], fpscr\n\t"
"orr %[tmp], %[tmp], #(3 << 16)\n\t" /* set vector size to 4 */
"fmxr fpscr, %[tmp]\n\t"
: [ tmp ] "=&r"(tmp)
: [tmp] "=&r"(tmp)
:
: "cc", "memory");
#endif
Expand All @@ -23,7 +23,7 @@ inline void releaseVFP() {
__asm__ __volatile__("fmrx %[tmp], fpscr\n\t"
"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ tmp ] "=&r"(tmp)
: [tmp] "=&r"(tmp)
:
: "cc", "memory");
#endif
Expand All @@ -50,7 +50,7 @@ inline void vfill(float* dest, float val, int len) {

"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ dst ] "+&r"(dest), [ src1 ] "+&r"(v), [ len ] "+&r"(len), [ tmp ] "=&r"(tmp)
: [dst] "+&r"(dest), [src1] "+&r"(v), [len] "+&r"(len), [tmp] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13",
"s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26",
Expand All @@ -63,49 +63,49 @@ inline void vfill(float* dest, float val, int len) {
inline void vmuladd(float* dest, float* a, float* b, float* c, int len) {
#if !TARGET_IPHONE_SIMULATOR
int tmp;
__asm__ __volatile__("fmrx %[tmp], fpscr\n\t"
"orr %[tmp], %[tmp], #(3 << 16)\n\t" /* set vector size to 4 */
"fmxr fpscr, %[tmp]\n\t"
__asm__ __volatile__(
"fmrx %[tmp], fpscr\n\t"
"orr %[tmp], %[tmp], #(3 << 16)\n\t" /* set vector size to 4 */
"fmxr fpscr, %[tmp]\n\t"

"fldmias %[src2]!, {s0-s3}\n\t"
"fldmias %[src1]!, {s8-s11}\n\t"
"fldmias %[src3]!, {s24-s27}\n\t"
"fldmias %[src2]!, {s4-s7}\n\t"
"fldmias %[src1]!, {s12-s15}\n\t"
"fldmias %[src3]!, {s28-s31}\n\t"
"fmacs s8, s0, s24\n\t"
"1:\n\t"
"subs %[len], %[len], #16\n\t"
"fmacs s12, s4, s28\n\t"
"fldmiasge %[src2]!, {s0-s3}\n\t"
"fldmiasge %[src1]!, {s16-s19}\n\t"
"fldmiasge %[src3]!, {s24-s27}\n\t"
"fldmiasge %[src2]!, {s4-s7}\n\t"
"fldmiasge %[src1]!, {s20-s23}\n\t"
"fldmiasge %[src3]!, {s28-s31}\n\t"
"fmacsge s16, s0, s24\n\t"
"fstmias %[dst]!, {s8-s11}\n\t"
"fstmias %[dst]!, {s12-s15}\n\t"
"fmacsge s20, s4, s28\n\t"
"fldmiasgt %[src2]!, {s0-s3}\n\t"
"fldmiasgt %[src1]!, {s8-s11}\n\t"
"fldmiasgt %[src3]!, {s24-s27}\n\t"
"fldmiasgt %[src2]!, {s4-s7}\n\t"
"fldmiasgt %[src1]!, {s12-s15}\n\t"
"fldmiasgt %[src3]!, {s28-s31}\n\t"
"fmacsge s8, s0, s24\n\t"
"fstmiasge %[dst]!, {s16-s19}\n\t"
"fstmiasge %[dst]!, {s20-s23}\n\t"
"bgt 1b\n\t"
"fldmias %[src2]!, {s0-s3}\n\t"
"fldmias %[src1]!, {s8-s11}\n\t"
"fldmias %[src3]!, {s24-s27}\n\t"
"fldmias %[src2]!, {s4-s7}\n\t"
"fldmias %[src1]!, {s12-s15}\n\t"
"fldmias %[src3]!, {s28-s31}\n\t"
"fmacs s8, s0, s24\n\t"
"1:\n\t"
"subs %[len], %[len], #16\n\t"
"fmacs s12, s4, s28\n\t"
"fldmiasge %[src2]!, {s0-s3}\n\t"
"fldmiasge %[src1]!, {s16-s19}\n\t"
"fldmiasge %[src3]!, {s24-s27}\n\t"
"fldmiasge %[src2]!, {s4-s7}\n\t"
"fldmiasge %[src1]!, {s20-s23}\n\t"
"fldmiasge %[src3]!, {s28-s31}\n\t"
"fmacsge s16, s0, s24\n\t"
"fstmias %[dst]!, {s8-s11}\n\t"
"fstmias %[dst]!, {s12-s15}\n\t"
"fmacsge s20, s4, s28\n\t"
"fldmiasgt %[src2]!, {s0-s3}\n\t"
"fldmiasgt %[src1]!, {s8-s11}\n\t"
"fldmiasgt %[src3]!, {s24-s27}\n\t"
"fldmiasgt %[src2]!, {s4-s7}\n\t"
"fldmiasgt %[src1]!, {s12-s15}\n\t"
"fldmiasgt %[src3]!, {s28-s31}\n\t"
"fmacsge s8, s0, s24\n\t"
"fstmiasge %[dst]!, {s16-s19}\n\t"
"fstmiasge %[dst]!, {s20-s23}\n\t"
"bgt 1b\n\t"

"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ dst ] "+&r"(dest), [ src1 ] "+&r"(a), [ src2 ] "+&r"(b), [ src3 ] "+&r"(c),
[ len ] "+&r"(len), [ tmp ] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13",
"s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26",
"s27", "s28", "s29", "s30", "s31", "cc", "memory");
"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [dst] "+&r"(dest), [src1] "+&r"(a), [src2] "+&r"(b), [src3] "+&r"(c), [len] "+&r"(len), [tmp] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", "s16",
"s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", "cc",
"memory");
#endif
}

Expand Down Expand Up @@ -141,8 +141,7 @@ inline void vscalarmul(float* dest, float scalar, float* b, int len) {

"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ dst ] "+&r"(dest), [ src1 ] "+&r"(s), [ src2 ] "+&r"(b), [ len ] "+&r"(len),
[ tmp ] "=&r"(tmp)
: [dst] "+&r"(dest), [src1] "+&r"(s), [src2] "+&r"(b), [len] "+&r"(len), [tmp] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13",
"s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26",
Expand Down Expand Up @@ -184,8 +183,7 @@ inline void vmul(float* dest, float* a, const float* b, int len) {

"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ dst ] "+&r"(dest), [ src1 ] "+&r"(a), [ src2 ] "+&r"(b), [ len ] "+&r"(len),
[ tmp ] "=&r"(tmp)
: [dst] "+&r"(dest), [src1] "+&r"(a), [src2] "+&r"(b), [len] "+&r"(len), [tmp] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13",
"s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26",
Expand Down Expand Up @@ -228,8 +226,7 @@ inline void vadd(float* dest, float* a, const float* b, int len) {

"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ dst ] "+&r"(dest), [ src1 ] "+&r"(a), [ src2 ] "+&r"(b), [ len ] "+&r"(len),
[ tmp ] "=&r"(tmp)
: [dst] "+&r"(dest), [src1] "+&r"(a), [src2] "+&r"(b), [len] "+&r"(len), [tmp] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13",
"s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26",
Expand Down Expand Up @@ -260,7 +257,7 @@ inline void vcopy(float* dest, float* a, int len) {

"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [ dst ] "+&r"(dest), [ src1 ] "+&r"(a), [ len ] "+&r"(len), [ tmp ] "=&r"(tmp)
: [dst] "+&r"(dest), [src1] "+&r"(a), [len] "+&r"(len), [tmp] "=&r"(tmp)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13",
"s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26",
Expand Down
4 changes: 3 additions & 1 deletion editors/sc-ide/core/main_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ int main(int argc, char* argv[]) {
sessions->newSession();
}

foreach (QString argument, arguments) { main->documentManager()->open(argument); }
foreach (QString argument, arguments) {
main->documentManager()->open(argument);
}

win->restoreDocuments();

Expand Down
12 changes: 3 additions & 9 deletions editors/sc-ide/core/sc_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ void ScProcess::onResponse(const QString& selector, const QString& data) {
Introspection newIntrospection = watcher->result();
mIntrospection = std::move(newIntrospection);
emit introspectionChanged();
} catch (std::exception& e) {
MainWindow::instance()->showStatusMessage(e.what());
}
} catch (std::exception& e) { MainWindow::instance()->showStatusMessage(e.what()); }
watcher->deleteLater();
});

Expand Down Expand Up @@ -383,9 +381,7 @@ void ScProcess::updateTextMirrorForDocument(Document* doc, int position, int cha

try {
sendSelectorAndData(mIpcSocket, QStringLiteral("updateDocText"), argList);
} catch (std::exception const& e) {
scPost(QStringLiteral("Exception during ScIDE_Send: %1\n").arg(e.what()));
}
} catch (std::exception const& e) { scPost(QStringLiteral("Exception during ScIDE_Send: %1\n").arg(e.what())); }
}

void ScProcess::updateSelectionMirrorForDocument(Document* doc, int start, int range) {
Expand All @@ -403,9 +399,7 @@ void ScProcess::updateSelectionMirrorForDocument(Document* doc, int start, int r

try {
sendSelectorAndData(mIpcSocket, QStringLiteral("updateDocSelection"), argList);
} catch (std::exception const& e) {
scPost(QStringLiteral("Exception during ScIDE_Send: %1\n").arg(e.what()));
}
} catch (std::exception const& e) { scPost(QStringLiteral("Exception during ScIDE_Send: %1\n").arg(e.what())); }
}

} // namespace ScIDE
4 changes: 1 addition & 3 deletions editors/sc-ide/widgets/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,9 +1440,7 @@ void MainWindow::showSettings() {
int result = dialog.exec();
if (result == QDialog::Accepted)
mMain->applySettings();
} catch (std::exception const& e) {
qWarning() << "Error while executing settings dialog:" << e.what();
}
} catch (std::exception const& e) { qWarning() << "Error while executing settings dialog:" << e.what(); }
showingSettings = false;
}

Expand Down
15 changes: 6 additions & 9 deletions editors/sc-ide/widgets/settings/sclang_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,18 @@ void SclangPage::readLanguageConfig() {
try {
bool postInlineWarnings = inlineWarnings.as<bool>();
ui->sclang_post_inline_warnings->setChecked(postInlineWarnings);
} catch (...) {
qDebug() << "Warning: Cannot parse config file entry \"postInlineWarnings\"";
}
} catch (...) { qDebug() << "Warning: Cannot parse config file entry \"postInlineWarnings\""; }
}

const Node& excludeDefaultPaths = doc["excludeDefaultPaths"];
if (excludeDefaultPaths) {
try {
bool excludeDefaultPathsBool = excludeDefaultPaths.as<bool>();
ui->sclang_exclude_default_paths->setChecked(excludeDefaultPathsBool);
} catch (...) {
qDebug() << "Warning: Cannot parse config file entry \"excludeDefaultPaths\"";
}
} catch (...) { qDebug() << "Warning: Cannot parse config file entry \"excludeDefaultPaths\""; }
}
}
} catch (std::exception&) {
}
} catch (std::exception&) {}

sclangConfigDirty = false;
}
Expand Down Expand Up @@ -256,7 +251,9 @@ QStringList SclangPage::availableLanguageConfigFiles() {
fileFilters << "sclang_conf*.yaml";
QFileInfoList configFileList = qdir.entryInfoList(fileFilters);
QStringList canonicalPaths;
foreach (QFileInfo aFile, configFileList) { canonicalPaths.append(aFile.canonicalFilePath()); }
foreach (QFileInfo aFile, configFileList) {
canonicalPaths.append(aFile.canonicalFilePath());
}
return canonicalPaths;
}

Expand Down
6 changes: 2 additions & 4 deletions include/plugin_interface/SC_RGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,14 @@ inline double RGen::exprandrng(double lo, double hi) { return lo * exp(log(hi /

inline double RGen::exprand(double scale) {
double z;
while ((z = drand()) == 0.0) {
}
while ((z = drand()) == 0.0) {}
return -log(z) * scale;
}

/// Bilateral exponentially distributed random double from -scale to +scale.
inline double RGen::biexprand(double scale) {
double z;
while ((z = drand2(1.)) == 0.0 || z == -1.0) {
}
while ((z = drand2(1.)) == 0.0 || z == -1.0) {}
if (z > 0.0)
z = log(z);
else
Expand Down
4 changes: 1 addition & 3 deletions lang/LangPrimSource/OSCData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,7 @@ void init_OSC(int port) {

try {
gUDPport.reset(new InPort::UDP(port, HandlerType::OSC));
} catch (std::exception const& e) {
postfl("No networking: %s", e.what());
}
} catch (std::exception const& e) { postfl("No networking: %s", e.what()); }
}

int prOpenOSCUDPPort(VMGlobals* g, int numArgsPushed);
Expand Down
4 changes: 1 addition & 3 deletions lang/LangPrimSource/PyrArchiverT.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ template <class S> class PyrArchiver {
} catch (std::exception& ex) {
error(ex.what());
err = errFailed;
} catch (...) {
err = errFailed;
}
} catch (...) { err = errFailed; }
// postfl("<-readArchive\n");
return err;
}
Expand Down
4 changes: 1 addition & 3 deletions lang/LangPrimSource/SC_Clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ template <typename Clock> int prClock_New(struct VMGlobals* g, int numArgsPushed
try {
Clock* clock = new Clock(g, slotRawObject(a), tempo, beats, seconds);
SetPtr(slotRawObject(a)->slots + 1, clock);
} catch (int err) {
return err;
}
} catch (int err) { return err; }

return errNone;
}
Expand Down
Loading

0 comments on commit 2027bac

Please sign in to comment.