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.
|
* @brief Structure for keeping track of minimum and maximum value set at each position.
|
||||||
*
|
*
|
||||||
@ -415,10 +414,13 @@ public:
|
|||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
template<class IntegerType>
|
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
|
// 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 MinMax = std::pair<IntegerType, IntegerType>;
|
||||||
using ValueType = MinMax;
|
using ValueType = MinMax;
|
||||||
using ThisType = MinMaxAccumulateTree<IntegerType>;
|
using ThisType = MinMaxAccumulateTree<IntegerType>;
|
||||||
@ -428,13 +430,12 @@ class MinMaxAccumulateTree : public LazySegmentTreeBase<std::pair<IntegerType, I
|
|||||||
|
|
||||||
static constexpr MinMax LIMITS()
|
static constexpr MinMax LIMITS()
|
||||||
{
|
{
|
||||||
return {std::numeric_limits<IntegerType>::max(),
|
return { std::numeric_limits<IntegerType>::max(), std::numeric_limits<IntegerType>::min() };
|
||||||
std::numeric_limits<IntegerType>::min()};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static MinMax Combine(const MinMax &a, const MinMax &b)
|
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)
|
void UpdateNode(NodePosition nodePos, ValueType value)
|
||||||
@ -477,7 +478,7 @@ public:
|
|||||||
right = this->leaveIndexToPosition(right);
|
right = this->leaveIndexToPosition(right);
|
||||||
this->pushDownFromRoot(left);
|
this->pushDownFromRoot(left);
|
||||||
this->pushDownFromRoot(right - 1);
|
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) {
|
for (size_t l = left, r = right; l < r; l >>= 1, r >>= 1) {
|
||||||
if (l & 1) {
|
if (l & 1) {
|
||||||
UpdateNode(l, pairValue);
|
UpdateNode(l, pairValue);
|
||||||
|
@ -528,7 +528,8 @@ QJsonDocument CutterCore::parseJson(const char *res, const char *cmd)
|
|||||||
QJsonDocument doc = QJsonDocument::fromJson(json, &jsonError);
|
QJsonDocument doc = QJsonDocument::fromJson(json, &jsonError);
|
||||||
|
|
||||||
if (jsonError.error != QJsonParseError::NoError) {
|
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()) {
|
if (json.trimmed().isEmpty()) {
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
@ -936,15 +937,15 @@ void CutterCore::seek(QString thing)
|
|||||||
|
|
||||||
void CutterCore::seekPrev()
|
void CutterCore::seekPrev()
|
||||||
{
|
{
|
||||||
CORE_LOCK ();
|
CORE_LOCK();
|
||||||
rz_core_seek_undo (core);
|
rz_core_seek_undo(core);
|
||||||
updateSeek();
|
updateSeek();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterCore::seekNext()
|
void CutterCore::seekNext()
|
||||||
{
|
{
|
||||||
CORE_LOCK ();
|
CORE_LOCK();
|
||||||
rz_core_seek_redo (core);
|
rz_core_seek_redo(core);
|
||||||
updateSeek();
|
updateSeek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
class DisassemblyTextBlockUserData: public QTextBlockUserData
|
class DisassemblyTextBlockUserData : public QTextBlockUserData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DisassemblyLine line;
|
DisassemblyLine line;
|
||||||
@ -880,9 +880,11 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
lineOffsets.emplace_back(lines[i].offset, i);
|
lineOffsets.emplace_back(lines[i].offset, i);
|
||||||
if (lines[i].arrow != RVA_INVALID) {
|
if (lines[i].arrow != RVA_INVALID) {
|
||||||
Arrow a { lines[i].offset, lines[i].arrow };
|
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;
|
return it.min == a.min && it.max == a.max;
|
||||||
}) != std::end(arrows);
|
})
|
||||||
|
!= std::end(arrows);
|
||||||
if (!contains) {
|
if (!contains) {
|
||||||
arrows.emplace_back(lines[i].offset, lines[i].arrow);
|
arrows.emplace_back(lines[i].offset, lines[i].arrow);
|
||||||
}
|
}
|
||||||
@ -897,22 +899,18 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
if (offset < lineOffsets[0].first) {
|
if (offset < lineOffsets[0].first) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
auto res = lower_bound(std::begin(lineOffsets), std::end(lineOffsets), offset, [](const LineInfo& it, RVA offset) {
|
auto res = lower_bound(std::begin(lineOffsets), std::end(lineOffsets), offset,
|
||||||
return it.first < offset;
|
[](const LineInfo &it, RVA offset) { return it.first < offset; });
|
||||||
});
|
|
||||||
if (res == std::end(lineOffsets)) {
|
if (res == std::end(lineOffsets)) {
|
||||||
return lines.size() + 2;
|
return lines.size() + 2;
|
||||||
}
|
}
|
||||||
return res->second;
|
return res->second;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
RVA visibleTop = lineOffsets[0].first, visibleBottom = lineOffsets.back().first;
|
RVA visibleTop = lineOffsets[0].first, visibleBottom = lineOffsets.back().first;
|
||||||
auto fitsInScreen = [&](const Arrow &a) {
|
auto fitsInScreen = [&](const Arrow &a) { return visibleBottom - visibleTop < a.length(); };
|
||||||
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);
|
int lScreen = fitsInScreen(l), rScreen = fitsInScreen(r);
|
||||||
if (lScreen != rScreen) {
|
if (lScreen != rScreen) {
|
||||||
return lScreen < rScreen;
|
return lScreen < rScreen;
|
||||||
@ -922,7 +920,7 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
RVA max = 0;
|
RVA max = 0;
|
||||||
RVA min = RVA_MAX;
|
RVA min = RVA_MAX;
|
||||||
for (auto& it : arrows) {
|
for (auto &it : arrows) {
|
||||||
min = std::min(it.min, min);
|
min = std::min(it.min, min);
|
||||||
max = std::max(it.max, max);
|
max = std::max(it.max, max);
|
||||||
it.level = 0;
|
it.level = 0;
|
||||||
@ -932,7 +930,7 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
if (!arrows.empty()) {
|
if (!arrows.empty()) {
|
||||||
MinMaxAccumulateTree<uint32_t> maxLevelTree(max - min + 2);
|
MinMaxAccumulateTree<uint32_t> maxLevelTree(max - min + 2);
|
||||||
for (Arrow &arrow : arrows) {
|
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;
|
RVA bottom = std::min(arrow.max - min, max - min) + 2;
|
||||||
auto minMax = maxLevelTree.rangeMinMax(top, bottom);
|
auto minMax = maxLevelTree.rangeMinMax(top, bottom);
|
||||||
if (minMax.first > 1) {
|
if (minMax.first > 1) {
|
||||||
@ -949,11 +947,12 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
const qreal pixelRatio = qhelpers::devicePixelRatio(p.device());
|
const qreal pixelRatio = qhelpers::devicePixelRatio(p.device());
|
||||||
const Arrow visibleRange { lines.first().offset, lines.last().offset };
|
const Arrow visibleRange { lines.first().offset, lines.last().offset };
|
||||||
// Draw the lines
|
// Draw the lines
|
||||||
for (const auto& arrow : arrows) {
|
for (const auto &arrow : arrows) {
|
||||||
if (!visibleRange.intersects(arrow)) {
|
if (!visibleRange.intersects(arrow)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int lineOffset = int((distanceBetweenLines * arrow.level + distanceBetweenLines) * pixelRatio);
|
int lineOffset =
|
||||||
|
int((distanceBetweenLines * arrow.level + distanceBetweenLines) * pixelRatio);
|
||||||
|
|
||||||
p.setPen(arrow.up ? penUp : penDown);
|
p.setPen(arrow.up ? penUp : penDown);
|
||||||
if (arrow.min == currOffset || arrow.max == currOffset) {
|
if (arrow.min == currOffset || arrow.max == currOffset) {
|
||||||
@ -962,7 +961,7 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
p.setPen(pen);
|
p.setPen(pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lineToPixels = [&] (int i) {
|
auto lineToPixels = [&](int i) {
|
||||||
int offset = int(arrow.up ? std::floor(pixelRatio) : -std::floor(pixelRatio));
|
int offset = int(arrow.up ? std::floor(pixelRatio) : -std::floor(pixelRatio));
|
||||||
return i * lineHeight + lineHeight / 2 + topOffset + offset;
|
return i * lineHeight + lineHeight / 2 + topOffset + offset;
|
||||||
};
|
};
|
||||||
@ -975,7 +974,8 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
// Draw the lines
|
// Draw the lines
|
||||||
p.drawLine(rightOffset, currentLineYPos, rightOffset - lineOffset, currentLineYPos); // left
|
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
|
p.drawLine(rightOffset - lineOffset, lineArrowY, rightOffset, lineArrowY); // right
|
||||||
|
|
||||||
@ -992,10 +992,10 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)
|
|||||||
arrows.clear();
|
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) {
|
if (eraseN > 0) {
|
||||||
const bool scrolledDown = lastBeginOffset > lines.first().offset;
|
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) {
|
if (scrolledDown) {
|
||||||
return l.jmpFromOffset() < r.jmpFromOffset();
|
return l.jmpFromOffset() < r.jmpFromOffset();
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
class DisassemblyTextEdit;
|
class DisassemblyTextEdit;
|
||||||
class DisassemblyScrollArea;
|
class DisassemblyScrollArea;
|
||||||
class DisassemblyContextMenu;
|
class DisassemblyContextMenu;
|
||||||
@ -159,10 +158,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
DisassemblyWidget *disas;
|
DisassemblyWidget *disas;
|
||||||
|
|
||||||
struct Arrow {
|
struct Arrow
|
||||||
Arrow(RVA v1, RVA v2)
|
{
|
||||||
: min(v1), max(v2),
|
Arrow(RVA v1, RVA v2) : min(v1), max(v2), level(0), up(false)
|
||||||
level(0), up(false)
|
|
||||||
{
|
{
|
||||||
if (min > max) {
|
if (min > max) {
|
||||||
std::swap(min, max);
|
std::swap(min, max);
|
||||||
@ -170,11 +168,12 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool contains(RVA point) const
|
inline bool contains(RVA point) const { return min <= point && max >= point; }
|
||||||
{ return min <= point && max >= point; }
|
|
||||||
|
|
||||||
inline bool intersects(const Arrow& other) const
|
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; }
|
ut64 length() const { return max - min; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user