mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
sys: Added clang-format file, formatted entire project
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <hex/pattern_language/pattern_data.hpp>
|
||||
|
||||
#define TEST(name) (hex::test::TestPattern*) new hex::test::TestPattern ## name ()
|
||||
#define TEST(name) (hex::test::TestPattern *)new hex::test::TestPattern##name()
|
||||
|
||||
namespace hex::test {
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace hex::test {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T* create(const std::string &typeName, const std::string &varName, auto ... args) {
|
||||
static T *create(const std::string &typeName, const std::string &varName, auto... args) {
|
||||
auto pattern = new T(args...);
|
||||
pattern->setTypeName(typeName);
|
||||
pattern->setVariableName(varName);
|
||||
@@ -36,37 +36,32 @@ namespace hex::test {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual std::string getSourceCode() const = 0;
|
||||
[[nodiscard]] virtual std::string getSourceCode() const = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const std::vector<PatternData*>& getPatterns() const final { return this->m_patterns; }
|
||||
[[nodiscard]] virtual const std::vector<PatternData *> &getPatterns() const final { return this->m_patterns; }
|
||||
virtual void addPattern(PatternData *pattern) final {
|
||||
this->m_patterns.push_back(pattern);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
auto failing() {
|
||||
[[nodiscard]] auto failing() {
|
||||
this->m_mode = Mode::Failing;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Mode getMode() {
|
||||
[[nodiscard]] Mode getMode() {
|
||||
return this->m_mode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static auto& getTests() {
|
||||
[[nodiscard]] static auto &getTests() {
|
||||
return TestPattern::s_tests;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<PatternData*> m_patterns;
|
||||
std::vector<PatternData *> m_patterns;
|
||||
Mode m_mode;
|
||||
|
||||
static inline std::map<std::string, TestPattern*> s_tests;
|
||||
static inline std::map<std::string, TestPattern *> s_tests;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,22 +6,19 @@ namespace hex::test {
|
||||
|
||||
class TestPatternBitfields : public TestPattern {
|
||||
public:
|
||||
TestPatternBitfields() : TestPattern("Bitfields") {
|
||||
TestPatternBitfields() : TestPattern("Bitfields") {
|
||||
auto testBitfield = create<PatternDataBitfield>("TestBitfield", "testBitfield", 0x12, (4 * 4) / 8, nullptr);
|
||||
testBitfield->setEndian(std::endian::big);
|
||||
testBitfield->setFields({
|
||||
create<PatternDataBitfieldField>("", "a", 0x12, 0, 4, testBitfield, nullptr),
|
||||
create<PatternDataBitfieldField>("", "b", 0x12, 4, 4, testBitfield, nullptr),
|
||||
create<PatternDataBitfieldField>("", "c", 0x12, 8, 4, testBitfield, nullptr),
|
||||
create<PatternDataBitfieldField>("", "d", 0x12, 12, 4, testBitfield, nullptr)
|
||||
});
|
||||
testBitfield->setFields({ create<PatternDataBitfieldField>("", "a", 0x12, 0, 4, testBitfield, nullptr),
|
||||
create<PatternDataBitfieldField>("", "b", 0x12, 4, 4, testBitfield, nullptr),
|
||||
create<PatternDataBitfieldField>("", "c", 0x12, 8, 4, testBitfield, nullptr),
|
||||
create<PatternDataBitfieldField>("", "d", 0x12, 12, 4, testBitfield, nullptr) });
|
||||
|
||||
addPattern(testBitfield);
|
||||
}
|
||||
~TestPatternBitfields() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
bitfield TestBitfield {
|
||||
a : 4;
|
||||
@@ -38,7 +35,6 @@ namespace hex::test {
|
||||
std::assert(testBitfield.d == 0x03, "Field D invalid");
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,13 @@ namespace hex::test {
|
||||
|
||||
class TestPatternEnums : public TestPattern {
|
||||
public:
|
||||
TestPatternEnums() : TestPattern("Enums"){
|
||||
TestPatternEnums() : TestPattern("Enums") {
|
||||
auto testEnum = create<PatternDataEnum>("TestEnum", "testEnum", 0x08, sizeof(u32), nullptr);
|
||||
testEnum->setEnumValues({
|
||||
{ u128(0x0000), "A" },
|
||||
{ i128(0x0C), "B" },
|
||||
{ u128(0x0D), "C" },
|
||||
{ u128(0x0E), "D" },
|
||||
{u128(0x0000), "A"},
|
||||
{ i128(0x0C), "B"},
|
||||
{ u128(0x0D), "C"},
|
||||
{ u128(0x0E), "D"},
|
||||
});
|
||||
testEnum->setEndian(std::endian::big);
|
||||
|
||||
@@ -20,8 +20,7 @@ namespace hex::test {
|
||||
}
|
||||
~TestPatternEnums() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
enum TestEnum : u32 {
|
||||
A,
|
||||
@@ -35,7 +34,6 @@ namespace hex::test {
|
||||
std::assert(testEnum == TestEnum::C, "Invalid enum value");
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,18 +6,15 @@ namespace hex::test {
|
||||
|
||||
class TestPatternExample : public TestPattern {
|
||||
public:
|
||||
TestPatternExample() : TestPattern("") {
|
||||
|
||||
TestPatternExample() : TestPattern("") {
|
||||
}
|
||||
~TestPatternExample() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternExtraSemicolon : public TestPattern {
|
||||
public:
|
||||
TestPatternExtraSemicolon() : TestPattern("ExtraSemicolon") {
|
||||
|
||||
TestPatternExtraSemicolon() : TestPattern("ExtraSemicolon") {
|
||||
}
|
||||
~TestPatternExtraSemicolon() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
struct Test {
|
||||
u32 x;;;
|
||||
@@ -29,7 +27,6 @@ namespace hex::test {
|
||||
Test test2 @ 0x10;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternFailingAssert : public TestPattern {
|
||||
public:
|
||||
TestPatternFailingAssert() : TestPattern("FailingAssert", Mode::Failing) {
|
||||
|
||||
TestPatternFailingAssert() : TestPattern("FailingAssert", Mode::Failing) {
|
||||
}
|
||||
~TestPatternFailingAssert() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
#define MSG "Error"
|
||||
|
||||
@@ -20,7 +18,6 @@ namespace hex::test {
|
||||
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternLiterals : public TestPattern {
|
||||
public:
|
||||
TestPatternLiterals() : TestPattern("Literals") {
|
||||
|
||||
TestPatternLiterals() : TestPattern("Literals") {
|
||||
}
|
||||
~TestPatternLiterals() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
#define MSG "Invalid literal"
|
||||
|
||||
@@ -26,7 +24,6 @@ namespace hex::test {
|
||||
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternMath : public TestPattern {
|
||||
public:
|
||||
TestPatternMath() : TestPattern("Math") {
|
||||
|
||||
TestPatternMath() : TestPattern("Math") {
|
||||
}
|
||||
~TestPatternMath() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
// Compare operations
|
||||
std::assert(123 == 123, "== operation error");
|
||||
@@ -70,7 +68,6 @@ namespace hex::test {
|
||||
std::assert(10F / (20F + 30F) != 10F / 20F + 10F / 30F, "/ operator distributivity error");
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternNamespaces : public TestPattern {
|
||||
public:
|
||||
TestPatternNamespaces() : TestPattern("Namespaces") {
|
||||
|
||||
TestPatternNamespaces() : TestPattern("Namespaces") {
|
||||
}
|
||||
~TestPatternNamespaces() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
namespace A {
|
||||
struct Test {
|
||||
@@ -36,7 +34,6 @@ namespace hex::test {
|
||||
std::assert(sizeof(test2) != sizeof(test3), "error differentiating two namespace types with same name");
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace hex::test {
|
||||
|
||||
class TestPatternPadding : public TestPattern {
|
||||
public:
|
||||
TestPatternPadding() : TestPattern("Padding") {
|
||||
TestPatternPadding() : TestPattern("Padding") {
|
||||
auto testStruct = create<PatternDataStruct>("TestStruct", "testStruct", 0x100, sizeof(i32) + 20 + sizeof(u8[0x10]), nullptr);
|
||||
|
||||
auto variable = create<PatternDataSigned>("s32", "variable", 0x100, sizeof(i32), nullptr);
|
||||
@@ -20,8 +20,7 @@ namespace hex::test {
|
||||
}
|
||||
~TestPatternPadding() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
struct TestStruct {
|
||||
s32 variable;
|
||||
@@ -32,7 +31,6 @@ namespace hex::test {
|
||||
TestStruct testStruct @ 0x100;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace hex::test {
|
||||
|
||||
class TestPatternPlacement : public TestPattern {
|
||||
public:
|
||||
TestPatternPlacement() : TestPattern("Placement") {
|
||||
TestPatternPlacement() : TestPattern("Placement") {
|
||||
// placementVar
|
||||
{
|
||||
addPattern(create<PatternDataUnsigned>("u32", "placementVar", 0x00, sizeof(u32), nullptr));
|
||||
@@ -18,18 +18,15 @@ namespace hex::test {
|
||||
placementArray->setEntries(create<PatternDataUnsigned>("u8", "", 0x10, sizeof(u8), nullptr), 10);
|
||||
addPattern(placementArray);
|
||||
}
|
||||
|
||||
}
|
||||
~TestPatternPlacement() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
u32 placementVar @ 0x00;
|
||||
u8 placementArray[10] @ 0x10;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace hex::test {
|
||||
|
||||
class TestPatternPointers : public TestPattern {
|
||||
public:
|
||||
TestPatternPointers() : TestPattern("Pointers") {
|
||||
TestPatternPointers() : TestPattern("Pointers") {
|
||||
// placementPointer
|
||||
{
|
||||
auto placementPointer = create<PatternDataPointer>("", "placementPointer", 0x0C, sizeof(u8), nullptr);
|
||||
@@ -16,17 +16,14 @@ namespace hex::test {
|
||||
placementPointer->setPointedAtPattern(pointedTo);
|
||||
addPattern(placementPointer);
|
||||
}
|
||||
|
||||
}
|
||||
~TestPatternPointers() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
u32 *placementPointer : u8 @ 0x0C;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternRValues : public TestPattern {
|
||||
public:
|
||||
TestPatternRValues() : TestPattern("RValues") {
|
||||
|
||||
TestPatternRValues() : TestPattern("RValues") {
|
||||
}
|
||||
~TestPatternRValues() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
union C {
|
||||
u8 y;
|
||||
@@ -34,7 +32,6 @@ namespace hex::test {
|
||||
std::assert(a.b.c.y == a.b.c.array[0], "RValue array access test failed!");
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace hex::test {
|
||||
|
||||
class TestPatternStructs : public TestPattern {
|
||||
public:
|
||||
TestPatternStructs() : TestPattern("Structs") {
|
||||
TestPatternStructs() : TestPattern("Structs") {
|
||||
auto testStruct = create<PatternDataStruct>("TestStruct", "testStruct", 0x100, sizeof(i32) + sizeof(u8[0x10]), nullptr);
|
||||
|
||||
auto variable = create<PatternDataSigned>("s32", "variable", 0x100, sizeof(i32), nullptr);
|
||||
@@ -19,8 +19,7 @@ namespace hex::test {
|
||||
}
|
||||
~TestPatternStructs() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
struct TestStruct {
|
||||
s32 variable;
|
||||
@@ -30,7 +29,6 @@ namespace hex::test {
|
||||
TestStruct testStruct @ 0x100;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,13 +6,11 @@ namespace hex::test {
|
||||
|
||||
class TestPatternSucceedingAssert : public TestPattern {
|
||||
public:
|
||||
TestPatternSucceedingAssert() : TestPattern("SucceedingAssert") {
|
||||
|
||||
TestPatternSucceedingAssert() : TestPattern("SucceedingAssert") {
|
||||
}
|
||||
~TestPatternSucceedingAssert() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
#define MSG "Error"
|
||||
|
||||
@@ -23,7 +21,6 @@ namespace hex::test {
|
||||
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace hex::test {
|
||||
|
||||
class TestPatternUnions : public TestPattern {
|
||||
public:
|
||||
TestPatternUnions() : TestPattern("Unions") {
|
||||
TestPatternUnions() : TestPattern("Unions") {
|
||||
auto testUnion = create<PatternDataUnion>("TestUnion", "testUnion", 0x200, sizeof(u128), nullptr);
|
||||
|
||||
auto array = create<PatternDataStaticArray>("s32", "array", 0x200, sizeof(i32[2]), nullptr);
|
||||
@@ -19,8 +19,7 @@ namespace hex::test {
|
||||
}
|
||||
~TestPatternUnions() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
[[nodiscard]] std::string getSourceCode() const override {
|
||||
return R"(
|
||||
union TestUnion {
|
||||
s32 array[2];
|
||||
@@ -30,7 +29,6 @@ namespace hex::test {
|
||||
TestUnion testUnion @ 0x200;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user