Skip to content

Commit

Permalink
Update clang-format formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dasaav-dsv committed Apr 11, 2024
1 parent 1ef7b4b commit 66ae1b3
Show file tree
Hide file tree
Showing 55 changed files with 388 additions and 284 deletions.
38 changes: 35 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
---
BasedOnStyle: LLVM
Language: Cpp
Standard: c++20
IndentWidth: 4
AccessModifierOffset: -4
ContinuationIndentWidth: 4 # 0?
AlignAfterOpenBracket: DontAlign
AlignOperands: DontAlign
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
DerivePointerAlignment: false
PointerAlignment: Left
ReferenceAlignment: Left
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
AlwaysBreakTemplateDeclarations: true
Cpp11BracedListStyle: false
Cpp11BracedListStyle: false
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: true
IndentPPDirectives: None
InsertNewlineAtEOF: true
2 changes: 1 addition & 1 deletion include/coresystem/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ LIBER_ASSERTS_BEGIN(CSMemory);
LIBER_ASSERT_SIZE(0x2B8);
LIBER_ASSERTS_END;
} // namespace CS
} // namespace from
} // namespace from
9 changes: 5 additions & 4 deletions include/coresystem/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class CSTaskImp {

// Get the associated CSTask instance (may be null)
liber::optref<CSTask> get() noexcept {
if (!this->inst) return std::nullopt;
if (!this->inst)
return std::nullopt;
return *this->inst;
}

Expand Down Expand Up @@ -119,8 +120,8 @@ class CSTask : private CSTaskBase {
virtual ~CSTask() LIBER_INTERFACE_ONLY;
virtual void add_task_group(const wchar_t* name) LIBER_INTERFACE_ONLY;
virtual bool unk_set_task_group(cstgi) LIBER_INTERFACE_ONLY;
virtual bool set_task_group_state(
cstgi id, bool state) LIBER_INTERFACE_ONLY;
virtual bool set_task_group_state(cstgi id,
bool state) LIBER_INTERFACE_ONLY;
virtual void debug_print() LIBER_INTERFACE_ONLY;
virtual void queue_tasks(void* unk1, void* unk2) LIBER_INTERFACE_ONLY;

Expand All @@ -136,4 +137,4 @@ LIBER_ASSERTS_BEGIN(CSTask);
LIBER_ASSERT_SIZE(0xE8);
LIBER_ASSERTS_END;
} // namespace CS
} // namespace from
} // namespace from
2 changes: 1 addition & 1 deletion include/coresystem/taskgroups.inl
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ enum class CSTaskGroup : int {
RecordHeapStats,
FrameEnd,
SIZE
};
};
4 changes: 2 additions & 2 deletions include/dantelion2/kernel_runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class DLPlainAdaptiveMutex : public DLPlainLightMutex {
DLPlainAdaptiveMutex(DLPlainAdaptiveMutex&&) noexcept = delete;

private:
[[maybe_unused]] int spin_count;
int spin_count;
};

LIBER_ASSERTS_BEGIN(DLPlainAdaptiveMutex);
LIBER_ASSERT_SIZE(0x38);
LIBER_ASSERTS_END;
} // namespace DLKR
} // namespace from
} // namespace from
23 changes: 13 additions & 10 deletions include/dantelion2/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class DLRuntimeClass {

// Potentially a method that frees a base class of
// a DLRuntimeClass, or a DLRuntimeClass from a similar structure
virtual void free_base(
DLRuntimeClass** base_of, DLKR::DLAllocator* allocator) = 0;
virtual void free_base(DLRuntimeClass** base_of,
DLKR::DLAllocator* allocator) = 0;

public:
// The size of the runtime class
Expand All @@ -146,7 +146,8 @@ class DLRuntimeClass {
// Get the constructor method (may be null)
liber::optref<DLRuntimeMethod> get_constructor() noexcept {
DLRuntimeMethod* method_ptr = this->runtime_constructor.get();
if (!method_ptr) return std::nullopt;
if (!method_ptr)
return std::nullopt;
return *method_ptr;
}

Expand All @@ -156,14 +157,16 @@ class DLRuntimeClass {
}

// Get a method by name if it exists
LIBERAPI DLRuntimeMethod* find_method(const std::string_view& method_name) noexcept;
LIBERAPI DLRuntimeMethod* find_method(
const std::string_view& method_name) noexcept;

// Get a vector of all globally registered DLRuntimeClasses
LIBERAPI static from::vector<DLRuntimeMethodHolder>&
get_registered_classes() noexcept;

// Get a vector of all globally registered DLRuntimeClass pairs
LIBERAPI static from::vector<DLRuntimeClassPair>& get_runtime_pairs() noexcept;
LIBERAPI static from::vector<DLRuntimeClassPair>&
get_runtime_pairs() noexcept;

private:
// A pointer to the base class, if the class is derived
Expand All @@ -183,8 +186,8 @@ class DLRuntimeClassImpl : public DLRuntimeClass {

virtual ~DLRuntimeClassImpl() = default;

DLRuntimeClassImpl(
const char* class_name, const wchar_t* class_name_w) noexcept
DLRuntimeClassImpl(const char* class_name,
const wchar_t* class_name_w) noexcept
: DLRuntimeClass(), _class_name(class_name),
_class_name_w(class_name_w) {}

Expand All @@ -202,8 +205,8 @@ class DLRuntimeClassImpl : public DLRuntimeClass {
char* ref_byte4() LIBER_INTERFACE_OVERRIDE;

bool unk_always_false() LIBER_INTERFACE_OVERRIDE;
void free_base(
DLRuntimeClass**, DLKR::DLAllocator*) LIBER_INTERFACE_OVERRIDE;
void free_base(DLRuntimeClass**,
DLKR::DLAllocator*) LIBER_INTERFACE_OVERRIDE;

public:
size_t class_size() const noexcept override {
Expand Down Expand Up @@ -245,4 +248,4 @@ LIBER_ASSERTS_TEMPLATE_BEGIN(DLRuntimeClassImpl, liber::dummy);
LIBER_ASSERT_SIZE(0x48);
LIBER_ASSERTS_END;
} // namespace DLRF
} // namespace from
} // namespace from
2 changes: 1 addition & 1 deletion include/dantelion2/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class DLRuntimeImpl {
virtual ~DLRuntimeImpl() LIBER_INTERFACE_ONLY;
};
} // namespace DLSY
} // namespace from
} // namespace from
11 changes: 7 additions & 4 deletions include/dantelion2/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ struct string_hash {
}

int get_hash() noexcept {
if (this->needs_hashing) this->hash_string(*this->str);
if (this->needs_hashing)
this->hash_string(*this->str);
return this->hash_value;
}

int hash_string(const T& str) noexcept {
int result = 0;
for (int chr : str) {
// To lowercase (approximate)
if (chr <= 'Z') chr += 0x20;
if (chr <= 'Z')
chr += 0x20;
// Treat backslashes identically
else if (chr == '\\') chr = '/';
else if (chr == '\\')
chr = '/';
result *= 137;
result += chr;
}
Expand Down Expand Up @@ -99,4 +102,4 @@ LIBER_ASSERTS_BEGIN(FD4BasicHashString);
LIBER_ASSERT_SIZE(0x40);
LIBER_ASSERTS_END;
} // namespace DLTX
} // namespace from
} // namespace from
50 changes: 29 additions & 21 deletions include/dantelion2/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class DLReferenceCountObject {
// be more ref() calls than unref() calls
void unref() {
int value = this->counter.fetch_add(-1, std::memory_order_seq_cst);
if (value == 1) this->deleter();
else if (value < 1) throw std::runtime_error("bad unref() call");
if (value == 1)
this->deleter();
else if (value < 1)
throw std::runtime_error("bad unref() call");
}

std::atomic_int counter;
Expand All @@ -77,7 +79,8 @@ class DLReferenceCountPtr {
template <class U>
requires std::convertible_to<U*, T*>
explicit DLReferenceCountPtr(U* raw) noexcept : raw(raw) {
if (this->get()) this->counter().ref();
if (this->get())
this->counter().ref();
}

DLReferenceCountPtr(const DLReferenceCountPtr& other) noexcept
Expand All @@ -99,22 +102,26 @@ class DLReferenceCountPtr {
}

~DLReferenceCountPtr() {
if (this->get()) this->counter().unref();
if (this->get())
this->counter().unref();
}

template <class U>
requires std::convertible_to<U*, T*>
DLReferenceCountPtr& operator=(const DLReferenceCountPtr<U>& other) {
if (this->get()) this->counter().unref();
if (this->get())
this->counter().unref();
this->raw = other->get();
if (this->get()) this->counter().ref();
if (this->get())
this->counter().ref();
return *this;
}

template <class U>
requires std::convertible_to<U*, T*>
DLReferenceCountPtr& operator=(DLReferenceCountPtr<U>&& other) {
if (this->get()) this->counter().unref();
if (this->get())
this->counter().unref();
this->raw = std::exchange(other.raw, nullptr);
return *this;
}
Expand All @@ -129,7 +136,8 @@ class DLReferenceCountPtr {
void reset(U* raw) {
this->counter().unref();
this->raw = raw;
if (raw) this->counter().ref();
if (raw)
this->counter().ref();
}

void swap(DLReferenceCountPtr& other) {
Expand Down Expand Up @@ -162,14 +170,14 @@ class DLReferenceCountPtr {

// Pointer comparison operators:
template <typename T, typename U>
inline bool operator==(
const DLReferenceCountPtr<T>& lhs, const DLReferenceCountPtr<U>& rhs) {
inline bool operator==(const DLReferenceCountPtr<T>& lhs,
const DLReferenceCountPtr<U>& rhs) {
return lhs.get() == rhs.get();
}

template <typename T, typename U>
inline std::strong_ordering operator<=>(
const DLReferenceCountPtr<T>& lhs, const DLReferenceCountPtr<U>& rhs) {
inline std::strong_ordering operator<=>(const DLReferenceCountPtr<T>& lhs,
const DLReferenceCountPtr<U>& rhs) {
return lhs.get() <=> rhs.get();
}

Expand All @@ -179,8 +187,8 @@ inline bool operator==(const DLReferenceCountPtr<U>& lhs, std::nullptr_t) {
}

template <typename T, typename U>
inline std::strong_ordering operator<=>(
const DLReferenceCountPtr<T>& lhs, std::nullptr_t) {
inline std::strong_ordering operator<=>(const DLReferenceCountPtr<T>& lhs,
std::nullptr_t) {
return lhs.get() <=> nullptr;
}

Expand All @@ -204,8 +212,8 @@ template <typename T, typename U, typename... Args>
allocator_rebind_type allocator_rebind{ allocator };
T* raw = std::allocator_traits<allocator_rebind_type>::allocate(
allocator_rebind, 1);
std::allocator_traits<allocator_rebind_type>::construct(
allocator_rebind, raw, std::forward<Args>(args)...);
std::allocator_traits<allocator_rebind_type>::construct(allocator_rebind,
raw, std::forward<Args>(args)...);
return DLUT::DLReferenceCountPtr<T>(raw);
}

Expand All @@ -217,8 +225,8 @@ template <typename T, typename... Args>
from::allocator<T> proxy_allocator{ allocator };
T* raw =
std::allocator_traits<from::allocator<T>>::allocate(proxy_allocator, 1);
std::allocator_traits<from::allocator<T>>::construct(
proxy_allocator, raw, std::forward<Args>(args)...);
std::allocator_traits<from::allocator<T>>::construct(proxy_allocator, raw,
std::forward<Args>(args)...);
return DLUT::DLReferenceCountPtr<T>(raw);
}

Expand All @@ -227,7 +235,7 @@ template <typename T, typename... Args>
requires std::derived_from<T, DLUT::DLReferenceCountObject>
[[nodiscard]] inline DLUT::DLReferenceCountPtr<T> make_refcounted(
Args&&... args) {
return allocate_refcounted(
from::allocator<T>{}, std::forward<Args>(args)...);
return allocate_refcounted(from::allocator<T>{},
std::forward<Args>(args)...);
}
} // namespace from
} // namespace from
2 changes: 1 addition & 1 deletion include/detail/base_address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ void* base_address() noexcept;

// Get an offset pointer from the process base address
void* base_offset(int offset) noexcept;
} // namespace liber
} // namespace liber
2 changes: 1 addition & 1 deletion include/detail/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ struct function<Name, void> {
liber::symbol<Name>::get())(args...);
}
};
} // namespace liber
} // namespace liber
10 changes: 5 additions & 5 deletions include/detail/literal_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ struct literal_string {
// Widen CharT to wchar_t over the array
consteval literal_string<wchar_t, N> widen() const {
wchar_t out[N]{};
std::copy(
std::begin(this->string), std::end(this->string), std::begin(out));
std::copy(std::begin(this->string), std::end(this->string),
std::begin(out));
return out;
}

// Truncate CharT to char over the array
consteval literal_string<char, N> trunc() const {
char out[N]{};
std::copy(
std::begin(this->string), std::end(this->string), std::begin(out));
std::copy(std::begin(this->string), std::end(this->string),
std::begin(out));
return out;
}

CharT string[N]{};
};
} // namespace liber
} // namespace liber
2 changes: 1 addition & 1 deletion include/detail/optref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ struct optref {
private:
std::optional<reference_wrapper_type> opt;
};
} // namespace liber
} // namespace liber
Loading

0 comments on commit 66ae1b3

Please sign in to comment.