Add clang-format linter CI jobs (#2604)

This commit is contained in:
Alexis Ehret 2021-02-19 15:32:58 +01:00 committed by GitHub
parent 0553d3ffdb
commit a47c2bb5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 48 deletions

46
.github/workflows/linter.yml vendored Normal file
View File

@ -0,0 +1,46 @@
name: "Linter"
on:
push:
pull_request:
jobs:
changes:
runs-on: ubuntu-latest
outputs:
clang-format: ${{ steps.filter.outputs.clang-format }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
clang-format:
- '**.cpp'
- '**.c'
- '**.h'
- '.github/workflows/linter.yml'
clang-format:
needs: changes
runs-on: ubuntu-20.04
if: ${{ needs.changes.outputs.clang-format == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install wget
run: sudo apt --assume-yes install wget
- name: Install automatic llvm (stable branch)
run: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
- name: Install clang-format-11
run: sudo apt --assume-yes install clang-format-11
- name: Install gitpython
run: sudo pip install gitpython
- name: Run clang-format
run: |
find ./src -regex '.*\.\(cpp\|h\|c\)' -exec clang-format -style=file --dry-run --Werror {} \;

View File

@ -396,7 +396,6 @@ public:
}
};
/**
* @brief Structure for keeping track of minimum and maximum value set at each position.
*
@ -415,10 +414,13 @@ public:
* @endcode
*/
template<class IntegerType>
class MinMaxAccumulateTree : public LazySegmentTreeBase<std::pair<IntegerType, IntegerType>, std::pair<IntegerType, IntegerType>, MinMaxAccumulateTree<IntegerType>>
class MinMaxAccumulateTree : public LazySegmentTreeBase<std::pair<IntegerType, IntegerType>,
std::pair<IntegerType, IntegerType>,
MinMaxAccumulateTree<IntegerType>>
{
// Could work with other types but that would require changing LIMITS
static_assert (std::is_integral<IntegerType>::value, "Template argument IntegerType must be integer");
static_assert(std::is_integral<IntegerType>::value,
"Template argument IntegerType must be integer");
using MinMax = std::pair<IntegerType, IntegerType>;
using ValueType = MinMax;
using ThisType = MinMaxAccumulateTree<IntegerType>;
@ -428,8 +430,7 @@ class MinMaxAccumulateTree : public LazySegmentTreeBase<std::pair<IntegerType, I
static constexpr MinMax LIMITS()
{
return {std::numeric_limits<IntegerType>::max(),
std::numeric_limits<IntegerType>::min()};
return { std::numeric_limits<IntegerType>::max(), std::numeric_limits<IntegerType>::min() };
}
static MinMax Combine(const MinMax &a, const MinMax &b)

View File

@ -528,7 +528,8 @@ QJsonDocument CutterCore::parseJson(const char *res, const char *cmd)
QJsonDocument doc = QJsonDocument::fromJson(json, &jsonError);
if (jsonError.error != QJsonParseError::NoError) {
// don't call trimmed() before knowing that parsing failed to avoid copying huge jsons all the time
// don't call trimmed() before knowing that parsing failed to avoid copying huge jsons all
// the time
if (json.trimmed().isEmpty()) {
return doc;
}

View File

@ -880,9 +880,11 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
lineOffsets.emplace_back(lines[i].offset, i);
if (lines[i].arrow != RVA_INVALID) {
Arrow a { lines[i].offset, lines[i].arrow };
bool contains = std::find_if(std::begin(arrows), std::end(arrows), [&](const Arrow& it) {
bool contains = std::find_if(std::begin(arrows), std::end(arrows),
[&](const Arrow &it) {
return it.min == a.min && it.max == a.max;
}) != std::end(arrows);
})
!= std::end(arrows);
if (!contains) {
arrows.emplace_back(lines[i].offset, lines[i].arrow);
}
@ -897,20 +899,16 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
if (offset < lineOffsets[0].first) {
return -2;
}
auto res = lower_bound(std::begin(lineOffsets), std::end(lineOffsets), offset, [](const LineInfo& it, RVA offset) {
return it.first < offset;
});
auto res = lower_bound(std::begin(lineOffsets), std::end(lineOffsets), offset,
[](const LineInfo &it, RVA offset) { return it.first < offset; });
if (res == std::end(lineOffsets)) {
return lines.size() + 2;
}
return res->second;
};
RVA visibleTop = lineOffsets[0].first, visibleBottom = lineOffsets.back().first;
auto fitsInScreen = [&](const Arrow &a) {
return visibleBottom - visibleTop < a.length();
};
auto fitsInScreen = [&](const Arrow &a) { return visibleBottom - visibleTop < a.length(); };
std::sort(std::begin(arrows), std::end(arrows), [&](const Arrow &l, const Arrow &r) {
int lScreen = fitsInScreen(l), rScreen = fitsInScreen(r);
@ -953,7 +951,8 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
if (!visibleRange.intersects(arrow)) {
continue;
}
int lineOffset = int((distanceBetweenLines * arrow.level + distanceBetweenLines) * pixelRatio);
int lineOffset =
int((distanceBetweenLines * arrow.level + distanceBetweenLines) * pixelRatio);
p.setPen(arrow.up ? penUp : penDown);
if (arrow.min == currOffset || arrow.max == currOffset) {
@ -975,7 +974,8 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
// Draw the lines
p.drawLine(rightOffset, currentLineYPos, rightOffset - lineOffset, currentLineYPos); // left
p.drawLine(rightOffset - lineOffset, currentLineYPos, rightOffset - lineOffset, lineArrowY); // horizontal
p.drawLine(rightOffset - lineOffset, currentLineYPos, rightOffset - lineOffset,
lineArrowY); // horizontal
p.drawLine(rightOffset - lineOffset, lineArrowY, rightOffset, lineArrowY); // right

View File

@ -14,7 +14,6 @@
#include <vector>
class DisassemblyTextEdit;
class DisassemblyScrollArea;
class DisassemblyContextMenu;
@ -159,10 +158,9 @@ public:
private:
DisassemblyWidget *disas;
struct Arrow {
Arrow(RVA v1, RVA v2)
: min(v1), max(v2),
level(0), up(false)
struct Arrow
{
Arrow(RVA v1, RVA v2) : min(v1), max(v2), level(0), up(false)
{
if (min > max) {
std::swap(min, max);
@ -170,11 +168,12 @@ private:
}
}
inline bool contains(RVA point) const
{ return min <= point && max >= point; }
inline bool contains(RVA point) const { return min <= point && max >= point; }
inline bool intersects(const Arrow &other) const
{ return std::max(min, other.min) <= std::min(max, other.max); }
{
return std::max(min, other.min) <= std::min(max, other.max);
}
ut64 length() const { return max - min; }