mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Add clang-format linter CI jobs (#2604)
This commit is contained in:
parent
0553d3ffdb
commit
a47c2bb5aa
46
.github/workflows/linter.yml
vendored
Normal file
46
.github/workflows/linter.yml
vendored
Normal 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 {} \;
|
@ -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,13 +430,12 @@ 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)
|
||||
{
|
||||
return {std::min(a.first, b.first), std::max(a.second, b.second)};
|
||||
return { std::min(a.first, b.first), std::max(a.second, b.second) };
|
||||
}
|
||||
|
||||
void UpdateNode(NodePosition nodePos, ValueType value)
|
||||
@ -477,7 +478,7 @@ public:
|
||||
right = this->leaveIndexToPosition(right);
|
||||
this->pushDownFromRoot(left);
|
||||
this->pushDownFromRoot(right - 1);
|
||||
MinMax pairValue{value, value};
|
||||
MinMax pairValue { value, value };
|
||||
for (size_t l = left, r = right; l < r; l >>= 1, r >>= 1) {
|
||||
if (l & 1) {
|
||||
UpdateNode(l, pairValue);
|
||||
|
@ -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;
|
||||
}
|
||||
@ -936,15 +937,15 @@ void CutterCore::seek(QString thing)
|
||||
|
||||
void CutterCore::seekPrev()
|
||||
{
|
||||
CORE_LOCK ();
|
||||
rz_core_seek_undo (core);
|
||||
CORE_LOCK();
|
||||
rz_core_seek_undo(core);
|
||||
updateSeek();
|
||||
}
|
||||
|
||||
void CutterCore::seekNext()
|
||||
{
|
||||
CORE_LOCK ();
|
||||
rz_core_seek_redo (core);
|
||||
CORE_LOCK();
|
||||
rz_core_seek_redo(core);
|
||||
updateSeek();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
class DisassemblyTextBlockUserData: public QTextBlockUserData
|
||||
class DisassemblyTextBlockUserData : public QTextBlockUserData
|
||||
{
|
||||
public:
|
||||
DisassemblyLine line;
|
||||
@ -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) {
|
||||
return it.min == a.min && it.max == a.max;
|
||||
}) != std::end(arrows);
|
||||
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);
|
||||
if (!contains) {
|
||||
arrows.emplace_back(lines[i].offset, lines[i].arrow);
|
||||
}
|
||||
@ -897,22 +899,18 @@ 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) {
|
||||
std::sort(std::begin(arrows), std::end(arrows), [&](const Arrow &l, const Arrow &r) {
|
||||
int lScreen = fitsInScreen(l), rScreen = fitsInScreen(r);
|
||||
if (lScreen != rScreen) {
|
||||
return lScreen < rScreen;
|
||||
@ -922,7 +920,7 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
||||
|
||||
RVA max = 0;
|
||||
RVA min = RVA_MAX;
|
||||
for (auto& it : arrows) {
|
||||
for (auto &it : arrows) {
|
||||
min = std::min(it.min, min);
|
||||
max = std::max(it.max, max);
|
||||
it.level = 0;
|
||||
@ -932,7 +930,7 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
||||
if (!arrows.empty()) {
|
||||
MinMaxAccumulateTree<uint32_t> maxLevelTree(max - min + 2);
|
||||
for (Arrow &arrow : arrows) {
|
||||
RVA top = arrow.min >= min ? arrow.min - min + 1: 0;
|
||||
RVA top = arrow.min >= min ? arrow.min - min + 1 : 0;
|
||||
RVA bottom = std::min(arrow.max - min, max - min) + 2;
|
||||
auto minMax = maxLevelTree.rangeMinMax(top, bottom);
|
||||
if (minMax.first > 1) {
|
||||
@ -949,11 +947,12 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
||||
const qreal pixelRatio = qhelpers::devicePixelRatio(p.device());
|
||||
const Arrow visibleRange { lines.first().offset, lines.last().offset };
|
||||
// Draw the lines
|
||||
for (const auto& arrow : arrows) {
|
||||
for (const auto &arrow : arrows) {
|
||||
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) {
|
||||
@ -962,7 +961,7 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
||||
p.setPen(pen);
|
||||
}
|
||||
|
||||
auto lineToPixels = [&] (int i) {
|
||||
auto lineToPixels = [&](int i) {
|
||||
int offset = int(arrow.up ? std::floor(pixelRatio) : -std::floor(pixelRatio));
|
||||
return i * lineHeight + lineHeight / 2 + topOffset + offset;
|
||||
};
|
||||
@ -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
|
||||
|
||||
@ -992,10 +992,10 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
||||
arrows.clear();
|
||||
}
|
||||
|
||||
const size_t eraseN = arrows.size() > arrowsSize ? arrows.size() - arrowsSize: 0;
|
||||
const size_t eraseN = arrows.size() > arrowsSize ? arrows.size() - arrowsSize : 0;
|
||||
if (eraseN > 0) {
|
||||
const bool scrolledDown = lastBeginOffset > lines.first().offset;
|
||||
std::sort(std::begin(arrows), std::end(arrows), [&](const Arrow& l, const Arrow& r) {
|
||||
std::sort(std::begin(arrows), std::end(arrows), [&](const Arrow &l, const Arrow &r) {
|
||||
if (scrolledDown) {
|
||||
return l.jmpFromOffset() < r.jmpFromOffset();
|
||||
} else {
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
class DisassemblyTextEdit;
|
||||
class DisassemblyScrollArea;
|
||||
class DisassemblyContextMenu;
|
||||
@ -159,22 +158,22 @@ 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) {
|
||||
if (min > max) {
|
||||
std::swap(min, max);
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
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); }
|
||||
inline bool intersects(const Arrow &other) const
|
||||
{
|
||||
return std::max(min, other.min) <= std::min(max, other.max);
|
||||
}
|
||||
|
||||
ut64 length() const { return max - min; }
|
||||
|
||||
@ -182,10 +181,10 @@ private:
|
||||
|
||||
RVA jmpToffset() const { return up ? min : max; }
|
||||
|
||||
RVA min;
|
||||
RVA max;
|
||||
RVA min;
|
||||
RVA max;
|
||||
uint32_t level;
|
||||
bool up;
|
||||
bool up;
|
||||
};
|
||||
|
||||
const size_t arrowsSize = 128;
|
||||
|
Loading…
Reference in New Issue
Block a user