Add clang-format file

Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
This commit is contained in:
Robin Burchell 2019-05-28 11:53:16 +02:00 committed by Andreas Kling
parent c11351ac50
commit 0dc9af5f7e
Notes: sideshowbarker 2024-07-19 13:51:55 +09:00
286 changed files with 3244 additions and 2424 deletions

13
.clang-format Normal file
View file

@ -0,0 +1,13 @@
---
Language: Cpp
BasedOnStyle: WebKit
SpaceAfterTemplateKeyword: false
AlignEscapedNewlines: true
AlignTrailingComments: true
BreakBeforeInheritanceComma: true
BreakConstructorInitializers: BeforeComma
IndentPPDirectives: AfterHash
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
AfterEnum: true

View file

@ -3,9 +3,9 @@
#include <AK/ByteBuffer.h>
#include <AK/RetainPtr.h>
#include <AK/StringImpl.h>
#include <AK/StringView.h>
#include <AK/Traits.h>
#include <AK/Vector.h>
#include <AK/StringView.h>
#include <AK/kstdio.h>
namespace AK {
@ -96,7 +96,11 @@ public:
bool is_empty() const { return length() == 0; }
ssize_t length() const { return m_impl ? m_impl->length() : 0; }
const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
char operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
char operator[](ssize_t i) const
{
ASSERT(m_impl);
return (*m_impl)[i];
}
bool ends_with(const String&) const;

View file

@ -17,4 +17,3 @@ inline void not_implemented() { ASSERT(false); }
}
using AK::not_implemented;

View file

@ -1,9 +1,9 @@
#pragma once
#include "Assertions.h"
#include "StdLibExtras.h"
#include "Types.h"
#include "kmalloc.h"
#include "Assertions.h"
namespace AK {
@ -77,4 +77,3 @@ private:
}
using AK::Bitmap;

View file

@ -1,9 +1,9 @@
#pragma once
#include "Types.h"
#include "StdLibExtras.h"
#include <AK/Retainable.h>
#include "Types.h"
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/kmalloc.h>
namespace AK {
@ -28,8 +28,16 @@ public:
m_data = nullptr;
}
byte& operator[](int i) { ASSERT(i < m_size); return m_data[i]; }
const byte& operator[](int i) const { ASSERT(i < m_size); return m_data[i]; }
byte& operator[](int i)
{
ASSERT(i < m_size);
return m_data[i];
}
const byte& operator[](int i) const
{
ASSERT(i < m_size);
return m_data[i];
}
bool is_empty() const { return !m_size; }
int size() const { return m_size; }
@ -52,7 +60,12 @@ public:
void grow(int size);
private:
enum ConstructionMode { Uninitialized, Copy, Wrap, Adopt };
enum ConstructionMode {
Uninitialized,
Copy,
Wrap,
Adopt
};
explicit ByteBufferImpl(int); // For ConstructionMode=Uninitialized
ByteBufferImpl(const void*, int, ConstructionMode); // For ConstructionMode=Copy
ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
@ -101,8 +114,16 @@ public:
bool operator!() const { return is_null(); }
bool is_null() const { return m_impl == nullptr; }
byte& operator[](ssize_t i) { ASSERT(m_impl); return (*m_impl)[i]; }
byte operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
byte& operator[](ssize_t i)
{
ASSERT(m_impl);
return (*m_impl)[i];
}
byte operator[](ssize_t i) const
{
ASSERT(m_impl);
return (*m_impl)[i];
}
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
ssize_t size() const { return m_impl ? m_impl->size() : 0; }
@ -241,4 +262,3 @@ inline Retained<ByteBufferImpl> ByteBufferImpl::adopt(void* data, int size)
}
using AK::ByteBuffer;

View file

@ -60,9 +60,14 @@ public:
}
const T& operator*() const { return m_queue.m_elements[m_index]; }
private:
friend class CircularQueue;
ConstIterator(const CircularQueue& queue, const int index) : m_queue(queue), m_index(index) { }
ConstIterator(const CircularQueue& queue, const int index)
: m_queue(queue)
, m_index(index)
{
}
const CircularQueue& m_queue;
int m_index { 0 };
};
@ -82,4 +87,3 @@ private:
}
using AK::CircularQueue;

View file

@ -9,8 +9,14 @@ template<typename T>
class DoublyLinkedList {
private:
struct Node {
explicit Node(const T& v) : value(v) { }
explicit Node(T&& v) : value(move(v)) { }
explicit Node(const T& v)
: value(v)
{
}
explicit Node(T&& v)
: value(move(v))
{
}
T value;
Node* next { nullptr };
Node* prev { nullptr };
@ -33,15 +39,30 @@ public:
m_tail = nullptr;
}
T& first() { ASSERT(head()); return head()->value; }
const T& first() const { ASSERT(head()); return head()->value; }
T& last() { ASSERT(head()); return tail()->value; }
const T& last() const { ASSERT(head()); return tail()->value; }
T& first()
{
ASSERT(head());
return head()->value;
}
const T& first() const
{
ASSERT(head());
return head()->value;
}
T& last()
{
ASSERT(head());
return tail()->value;
}
const T& last() const
{
ASSERT(head());
return tail()->value;
}
void append(T&& value)
{
append_node(new Node(move(value)));
}
void append(const T& value)
@ -62,14 +83,22 @@ public:
public:
bool operator!=(const Iterator& other) const { return m_node != other.m_node; }
bool operator==(const Iterator& other) const { return m_node == other.m_node; }
Iterator& operator++() { m_node = m_node->next; return *this; }
Iterator& operator++()
{
m_node = m_node->next;
return *this;
}
T& operator*() { return m_node->value; }
T* operator->() { return &m_node->value; }
bool is_end() const { return !m_node; }
static Iterator universal_end() { return Iterator(nullptr); }
private:
friend class DoublyLinkedList;
explicit Iterator(DoublyLinkedList::Node* node) : m_node(node) { }
explicit Iterator(DoublyLinkedList::Node* node)
: m_node(node)
{
}
DoublyLinkedList::Node* m_node;
};
@ -80,14 +109,22 @@ public:
public:
bool operator!=(const ConstIterator& other) const { return m_node != other.m_node; }
bool operator==(const ConstIterator& other) const { return m_node == other.m_node; }
ConstIterator& operator++() { m_node = m_node->next; return *this; }
ConstIterator& operator++()
{
m_node = m_node->next;
return *this;
}
const T& operator*() const { return m_node->value; }
const T* operator->() const { return &m_node->value; }
bool is_end() const { return !m_node; }
static ConstIterator universal_end() { return ConstIterator(nullptr); }
private:
friend class DoublyLinkedList;
explicit ConstIterator(const DoublyLinkedList::Node* node) : m_node(node) { }
explicit ConstIterator(const DoublyLinkedList::Node* node)
: m_node(node)
{
}
const DoublyLinkedList::Node* m_node;
};
@ -163,4 +200,3 @@ private:
}
using AK::DoublyLinkedList;

View file

@ -1,7 +1,7 @@
#include "FileSystemPath.h"
#include "StringBuilder.h"
#include "Vector.h"
#include "kstdio.h"
#include "StringBuilder.h"
namespace AK {

View file

@ -31,7 +31,8 @@
namespace AK {
template<typename> class Function;
template<typename>
class Function;
template<typename Out, typename... In>
class Function<Out(In...)> {
@ -109,4 +110,3 @@ private:
}
using AK::Function;

View file

@ -17,4 +17,3 @@ inline unsigned pair_int_hash(dword key1, dword key2)
{
return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
}

View file

@ -148,4 +148,3 @@ auto HashMap<K, V>::find(const K& key) const -> ConstIteratorType
}
using AK::HashMap;

View file

@ -2,15 +2,16 @@
#include "Assertions.h"
#include "DoublyLinkedList.h"
#include "Traits.h"
#include "StdLibExtras.h"
#include "Traits.h"
#include "kstdio.h"
//#define HASHTABLE_DEBUG
namespace AK {
template<typename T, typename = Traits<T>> class HashTable;
template<typename T, typename = Traits<T>>
class HashTable;
template<typename T, typename TraitsForT>
class HashTable {
@ -112,6 +113,7 @@ public:
return;
}
}
private:
friend class HashTable;
explicit Iterator(HashTable& table, bool is_end, typename DoublyLinkedList<T>::Iterator bucket_iterator = DoublyLinkedList<T>::Iterator::universal_end(), int bucket_index = 0)
@ -190,6 +192,7 @@ public:
return;
}
}
private:
friend class HashTable;
ConstIterator(const HashTable& table, bool is_end, typename DoublyLinkedList<T>::ConstIterator bucket_iterator = DoublyLinkedList<T>::ConstIterator::universal_end(), int bucket_index = 0)
@ -285,7 +288,6 @@ void HashTable<T, TraitsForT>::set(const T& value)
m_size++;
}
template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::rehash(int new_capacity)
{
@ -429,4 +431,3 @@ void HashTable<T, TraitsForT>::dump() const
}
using AK::HashTable;

View file

@ -5,7 +5,8 @@
namespace AK {
template<typename T> class InlineLinkedListNode {
template<typename T>
class InlineLinkedListNode {
public:
InlineLinkedListNode();
@ -16,33 +17,39 @@ public:
T* next() const;
};
template<typename T> inline InlineLinkedListNode<T>::InlineLinkedListNode()
template<typename T>
inline InlineLinkedListNode<T>::InlineLinkedListNode()
{
set_prev(0);
set_next(0);
}
template<typename T> inline void InlineLinkedListNode<T>::set_prev(T* prev)
template<typename T>
inline void InlineLinkedListNode<T>::set_prev(T* prev)
{
static_cast<T*>(this)->m_prev = prev;
}
template<typename T> inline void InlineLinkedListNode<T>::set_next(T* next)
template<typename T>
inline void InlineLinkedListNode<T>::set_next(T* next)
{
static_cast<T*>(this)->m_next = next;
}
template<typename T> inline T* InlineLinkedListNode<T>::prev() const
template<typename T>
inline T* InlineLinkedListNode<T>::prev() const
{
return static_cast<const T*>(this)->m_prev;
}
template<typename T> inline T* InlineLinkedListNode<T>::next() const
template<typename T>
inline T* InlineLinkedListNode<T>::next() const
{
return static_cast<const T*>(this)->m_next;
}
template<typename T> class InlineLinkedList {
template<typename T>
class InlineLinkedList {
public:
InlineLinkedList() {}
@ -75,7 +82,8 @@ private:
T* m_tail { nullptr };
};
template<typename T> inline size_t InlineLinkedList<T>::size_slow() const
template<typename T>
inline size_t InlineLinkedList<T>::size_slow() const
{
size_t size = 0;
for (T* node = m_head; node; node = node->next())
@ -83,13 +91,15 @@ template<typename T> inline size_t InlineLinkedList<T>::size_slow() const
return size;
}
template<typename T> inline void InlineLinkedList<T>::clear()
template<typename T>
inline void InlineLinkedList<T>::clear()
{
m_head = 0;
m_tail = 0;
}
template<typename T> inline void InlineLinkedList<T>::prepend(T* node)
template<typename T>
inline void InlineLinkedList<T>::prepend(T* node)
{
if (!m_head) {
ASSERT(!m_tail);
@ -107,7 +117,8 @@ template<typename T> inline void InlineLinkedList<T>::prepend(T* node)
m_head = node;
}
template<typename T> inline void InlineLinkedList<T>::append(T* node)
template<typename T>
inline void InlineLinkedList<T>::append(T* node)
{
if (!m_tail) {
ASSERT(!m_head);
@ -125,7 +136,8 @@ template<typename T> inline void InlineLinkedList<T>::append(T* node)
m_tail = node;
}
template<typename T> inline void InlineLinkedList<T>::remove(T* node)
template<typename T>
inline void InlineLinkedList<T>::remove(T* node)
{
if (node->prev()) {
ASSERT(node != m_head);
@ -144,7 +156,8 @@ template<typename T> inline void InlineLinkedList<T>::remove(T* node)
}
}
template<typename T> inline T* InlineLinkedList<T>::remove_head()
template<typename T>
inline T* InlineLinkedList<T>::remove_head()
{
T* node = head();
if (node)
@ -152,7 +165,8 @@ template<typename T> inline T* InlineLinkedList<T>::remove_head()
return node;
}
template<typename T> inline T* InlineLinkedList<T>::remove_tail()
template<typename T>
inline T* InlineLinkedList<T>::remove_tail()
{
T* node = tail();
if (node)
@ -160,7 +174,8 @@ template<typename T> inline T* InlineLinkedList<T>::remove_tail()
return node;
}
template<typename T> inline void InlineLinkedList<T>::append(InlineLinkedList<T>& other)
template<typename T>
inline void InlineLinkedList<T>::append(InlineLinkedList<T>& other)
{
if (!other.head())
return;

View file

@ -1,9 +1,9 @@
#include <AK/MappedFile.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
//#define DEBUG_MAPPED_FILE
@ -74,4 +74,3 @@ MappedFile& MappedFile::operator=(MappedFile&& other)
}
}

View file

@ -30,4 +30,3 @@ private:
}
using AK::MappedFile;

View file

@ -18,7 +18,8 @@ template<typename T>
}
template<typename T>
class [[gnu::packed]] NetworkOrdered {
class [[gnu::packed]] NetworkOrdered
{
public:
NetworkOrdered()
: m_network_value(0)

View file

@ -1,8 +1,8 @@
#pragma once
#include "StdLibExtras.h"
#include "Types.h"
#include "Traits.h"
#include "Types.h"
namespace AK {
@ -10,9 +10,19 @@ template<typename T>
class OwnPtr {
public:
OwnPtr() {}
explicit OwnPtr(T* ptr) : m_ptr(ptr) { }
OwnPtr(OwnPtr&& other) : m_ptr(other.leak_ptr()) { }
template<typename U> OwnPtr(OwnPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ptr())) { }
explicit OwnPtr(T* ptr)
: m_ptr(ptr)
{
}
OwnPtr(OwnPtr&& other)
: m_ptr(other.leak_ptr())
{
}
template<typename U>
OwnPtr(OwnPtr<U>&& other)
: m_ptr(static_cast<T*>(other.leak_ptr()))
{
}
OwnPtr(std::nullptr_t) {};
~OwnPtr()
{
@ -91,7 +101,8 @@ private:
T* m_ptr = nullptr;
};
template<class T, class... Args> inline OwnPtr<T>
template<class T, class... Args>
inline OwnPtr<T>
make(Args&&... args)
{
return OwnPtr<T>(new T(AK::forward<Args>(args)...));
@ -105,6 +116,5 @@ struct Traits<OwnPtr<T>> {
}
using AK::OwnPtr;
using AK::make;
using AK::OwnPtr;

View file

@ -1,27 +1,69 @@
#pragma once
#include <AK/Types.h>
#include <AK/Retained.h>
#include <AK/Types.h>
namespace AK {
template<typename T>
class RetainPtr {
public:
enum AdoptTag { Adopt };
enum AdoptTag {
Adopt
};
RetainPtr() {}
RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retain_if_not_null(m_ptr); }
RetainPtr(T* ptr) : m_ptr(ptr) { retain_if_not_null(m_ptr); }
RetainPtr(T& object) : m_ptr(&object) { m_ptr->retain(); }
RetainPtr(const T& object) : m_ptr(const_cast<T*>(&object)) { m_ptr->retain(); }
RetainPtr(AdoptTag, T& object) : m_ptr(&object) { }
RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
template<typename U> RetainPtr(Retained<U>&& other) : m_ptr(static_cast<T*>(&other.leak_ref())) { }
template<typename U> RetainPtr(RetainPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ref())) { }
RetainPtr(const RetainPtr& other) : m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref()) { }
template<typename U> RetainPtr(const RetainPtr<U>& other) : m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref()) { }
RetainPtr(const T* ptr)
: m_ptr(const_cast<T*>(ptr))
{
retain_if_not_null(m_ptr);
}
RetainPtr(T* ptr)
: m_ptr(ptr)
{
retain_if_not_null(m_ptr);
}
RetainPtr(T& object)
: m_ptr(&object)
{
m_ptr->retain();
}
RetainPtr(const T& object)
: m_ptr(const_cast<T*>(&object))
{
m_ptr->retain();
}
RetainPtr(AdoptTag, T& object)
: m_ptr(&object)
{
}
RetainPtr(RetainPtr& other)
: m_ptr(other.copy_ref().leak_ref())
{
}
RetainPtr(RetainPtr&& other)
: m_ptr(other.leak_ref())
{
}
template<typename U>
RetainPtr(Retained<U>&& other)
: m_ptr(static_cast<T*>(&other.leak_ref()))
{
}
template<typename U>
RetainPtr(RetainPtr<U>&& other)
: m_ptr(static_cast<T*>(other.leak_ref()))
{
}
RetainPtr(const RetainPtr& other)
: m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref())
{
}
template<typename U>
RetainPtr(const RetainPtr<U>& other)
: m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref())
{
}
~RetainPtr()
{
clear();
@ -143,4 +185,3 @@ private:
}
using AK::RetainPtr;

View file

@ -76,4 +76,3 @@ public:
}
using AK::Retainable;

View file

@ -34,17 +34,61 @@ inline void release_if_not_null(T* ptr)
template<typename T>
class CONSUMABLE(unconsumed) Retained {
public:
enum AdoptTag { Adopt };
enum AdoptTag {
Adopt
};
RETURN_TYPESTATE(unconsumed) Retained(const T& object) : m_ptr(const_cast<T*>(&object)) { m_ptr->retain(); }
RETURN_TYPESTATE(unconsumed) Retained(T& object) : m_ptr(&object) { m_ptr->retain(); }
template<typename U> RETURN_TYPESTATE(unconsumed) Retained(U& object) : m_ptr(&static_cast<T&>(object)) { m_ptr->retain(); }
RETURN_TYPESTATE(unconsumed) Retained(AdoptTag, T& object) : m_ptr(&object) { }
RETURN_TYPESTATE(unconsumed) Retained(Retained& other) : m_ptr(&other.copy_ref().leak_ref()) { }
RETURN_TYPESTATE(unconsumed) Retained(Retained&& other) : m_ptr(&other.leak_ref()) { }
template<typename U> RETURN_TYPESTATE(unconsumed) Retained(Retained<U>&& other) : m_ptr(static_cast<T*>(&other.leak_ref())) { }
RETURN_TYPESTATE(unconsumed) Retained(const Retained& other) : m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref()) { }
template<typename U> RETURN_TYPESTATE(unconsumed) Retained(const Retained<U>& other) : m_ptr(&const_cast<Retained<U>&>(other).copy_ref().leak_ref()) { }
RETURN_TYPESTATE(unconsumed)
Retained(const T& object)
: m_ptr(const_cast<T*>(&object))
{
m_ptr->retain();
}
RETURN_TYPESTATE(unconsumed)
Retained(T& object)
: m_ptr(&object)
{
m_ptr->retain();
}
template<typename U>
RETURN_TYPESTATE(unconsumed)
Retained(U& object)
: m_ptr(&static_cast<T&>(object))
{
m_ptr->retain();
}
RETURN_TYPESTATE(unconsumed)
Retained(AdoptTag, T& object)
: m_ptr(&object)
{
}
RETURN_TYPESTATE(unconsumed)
Retained(Retained& other)
: m_ptr(&other.copy_ref().leak_ref())
{
}
RETURN_TYPESTATE(unconsumed)
Retained(Retained&& other)
: m_ptr(&other.leak_ref())
{
}
template<typename U>
RETURN_TYPESTATE(unconsumed)
Retained(Retained<U>&& other)
: m_ptr(static_cast<T*>(&other.leak_ref()))
{
}
RETURN_TYPESTATE(unconsumed)
Retained(const Retained& other)
: m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref())
{
}
template<typename U>
RETURN_TYPESTATE(unconsumed)
Retained(const Retained<U>& other)
: m_ptr(&const_cast<Retained<U>&>(other).copy_ref().leak_ref())
{
}
~Retained()
{
release_if_not_null(m_ptr);
@ -57,7 +101,8 @@ public:
#endif
}
CALLABLE_WHEN(unconsumed) Retained& operator=(Retained&& other)
CALLABLE_WHEN(unconsumed)
Retained& operator=(Retained&& other)
{
if (this != &other) {
release_if_not_null(m_ptr);
@ -67,7 +112,8 @@ public:
}
template<typename U>
CALLABLE_WHEN(unconsumed) Retained& operator=(Retained<U>&& other)
CALLABLE_WHEN(unconsumed)
Retained& operator=(Retained<U>&& other)
{
if (this != static_cast<void*>(&other)) {
release_if_not_null(m_ptr);
@ -76,7 +122,8 @@ public:
return *this;
}
CALLABLE_WHEN(unconsumed) Retained& operator=(T& object)
CALLABLE_WHEN(unconsumed)
Retained& operator=(T& object)
{
if (m_ptr != &object)
release_if_not_null(m_ptr);
@ -85,12 +132,14 @@ public:
return *this;
}
CALLABLE_WHEN(unconsumed) Retained copy_ref() const
CALLABLE_WHEN(unconsumed)
Retained copy_ref() const
{
return Retained(*m_ptr);
}
CALLABLE_WHEN(unconsumed) SET_TYPESTATE(consumed)
CALLABLE_WHEN(unconsumed)
SET_TYPESTATE(consumed)
T& leak_ref()
{
ASSERT(m_ptr);
@ -99,17 +148,57 @@ public:
return *leakedPtr;
}
CALLABLE_WHEN(unconsumed) T* ptr() { ASSERT(m_ptr); return m_ptr; }
CALLABLE_WHEN(unconsumed) const T* ptr() const { ASSERT(m_ptr); return m_ptr; }
CALLABLE_WHEN(unconsumed)
T* ptr()
{
ASSERT(m_ptr);
return m_ptr;
}
CALLABLE_WHEN(unconsumed)
const T* ptr() const
{
ASSERT(m_ptr);
return m_ptr;
}
CALLABLE_WHEN(unconsumed) T* operator->() { ASSERT(m_ptr); return m_ptr; }
CALLABLE_WHEN(unconsumed) const T* operator->() const { ASSERT(m_ptr); return m_ptr; }
CALLABLE_WHEN(unconsumed)
T* operator->()
{
ASSERT(m_ptr);
return m_ptr;
}
CALLABLE_WHEN(unconsumed)
const T* operator->() const
{
ASSERT(m_ptr);
return m_ptr;
}
CALLABLE_WHEN(unconsumed) T& operator*() { ASSERT(m_ptr); return *m_ptr; }
CALLABLE_WHEN(unconsumed) const T& operator*() const { ASSERT(m_ptr); return *m_ptr; }
CALLABLE_WHEN(unconsumed)
T& operator*()
{
ASSERT(m_ptr);
return *m_ptr;
}
CALLABLE_WHEN(unconsumed)
const T& operator*() const
{
ASSERT(m_ptr);
return *m_ptr;
}
CALLABLE_WHEN(unconsumed) operator T*() { ASSERT(m_ptr); return m_ptr; }
CALLABLE_WHEN(unconsumed) operator const T*() const { ASSERT(m_ptr); return m_ptr; }
CALLABLE_WHEN(unconsumed)
operator T*()
{
ASSERT(m_ptr);
return m_ptr;
}
CALLABLE_WHEN(unconsumed)
operator const T*() const
{
ASSERT(m_ptr);
return m_ptr;
}
private:
Retained() {}
@ -125,5 +214,5 @@ inline Retained<T> adopt(T& object)
}
using AK::Retained;
using AK::adopt;
using AK::Retained;

View file

@ -8,7 +8,10 @@ template<typename T>
class SinglyLinkedList {
private:
struct Node {
explicit Node(T&& v) : value(v) { }
explicit Node(T&& v)
: value(v)
{
}
T value;
Node* next { nullptr };
};
@ -38,10 +41,26 @@ public:
m_tail = nullptr;
}
T& first() { ASSERT(head()); return head()->value; }
const T& first() const { ASSERT(head()); return head()->value; }
T& last() { ASSERT(head()); return tail()->value; }
const T& last() const { ASSERT(head()); return tail()->value; }
T& first()
{
ASSERT(head());
return head()->value;
}
const T& first() const
{
ASSERT(head());
return head()->value;
}
T& last()
{
ASSERT(head());
return tail()->value;
}
const T& last() const
{
ASSERT(head());
return tail()->value;
}
T take_first()
{
@ -79,13 +98,21 @@ public:
class Iterator {
public:
bool operator!=(const Iterator& other) { return m_node != other.m_node; }
Iterator& operator++() { m_node = m_node->next; return *this; }
Iterator& operator++()
{
m_node = m_node->next;
return *this;
}
T& operator*() { return m_node->value; }
bool is_end() const { return !m_node; }
static Iterator universal_end() { return Iterator(nullptr); }
private:
friend class SinglyLinkedList;
explicit Iterator(SinglyLinkedList::Node* node) : m_node(node) { }
explicit Iterator(SinglyLinkedList::Node* node)
: m_node(node)
{
}
SinglyLinkedList::Node* m_node;
};
@ -95,13 +122,21 @@ public:
class ConstIterator {
public:
bool operator!=(const ConstIterator& other) { return m_node != other.m_node; }
ConstIterator& operator++() { m_node = m_node->next; return *this; }
ConstIterator& operator++()
{
m_node = m_node->next;
return *this;
}
const T& operator*() const { return m_node->value; }
bool is_end() const { return !m_node; }
static ConstIterator universal_end() { return ConstIterator(nullptr); }
private:
friend class SinglyLinkedList;
explicit ConstIterator(const SinglyLinkedList::Node* node) : m_node(node) { }
explicit ConstIterator(const SinglyLinkedList::Node* node)
: m_node(node)
{
}
const SinglyLinkedList::Node* m_node;
};
@ -142,4 +177,3 @@ private:
}
using AK::SinglyLinkedList;

View file

@ -1,5 +1,5 @@
#include <AK/StdLibExtras.h>
#include <AK/Assertions.h>
#include <AK/StdLibExtras.h>
#include <AK/Types.h>
#include <AK/kstdio.h>
@ -20,8 +20,7 @@ void* mmx_memcpy(void* dest, const void* src, size_t len)
"rep movsb\n"
: "=S"(src_ptr), "=D"(dest_ptr), "=c"(prologue)
: "0"(src_ptr), "1"(dest_ptr), "2"(prologue)
: "memory"
);
: "memory");
}
for (dword i = len / 64; i; --i) {
asm volatile(
@ -40,12 +39,14 @@ void* mmx_memcpy(void* dest, const void* src, size_t len)
"movq %%mm4, 32(%1)\n"
"movq %%mm5, 40(%1)\n"
"movq %%mm6, 48(%1)\n"
"movq %%mm7, 56(%1)\n"
:: "r" (src_ptr), "r" (dest_ptr) : "memory");
"movq %%mm7, 56(%1)\n" ::"r"(src_ptr),
"r"(dest_ptr)
: "memory");
src_ptr += 64;
dest_ptr += 64;
}
asm volatile("emms":::"memory");
asm volatile("emms" ::
: "memory");
// Whatever remains we'll have to memcpy.
len %= 64;
if (len)
@ -62,7 +63,9 @@ static inline uint32_t divq(uint64_t n, uint32_t d)
uint32_t n0 = n;
uint32_t q;
uint32_t r;
asm volatile("divl %4" : "=d"(r), "=a"(q) : "0"(n1), "1"(n0), "rm"(d));
asm volatile("divl %4"
: "=d"(r), "=a"(q)
: "0"(n1), "1"(n0), "rm"(d));
return q;
}
@ -149,5 +152,4 @@ uint64_t __udivmoddi4(uint64_t n, uint64_t d, uint64_t* r)
return q;
}
#endif
}

View file

@ -27,8 +27,7 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
"rep movsl\n"
: "=S"(src), "=D"(dest), "=c"(count)
: "S"(src), "D"(dest), "c"(count)
: "memory"
);
: "memory");
}
[[gnu::always_inline]] inline void fast_dword_fill(dword* dest, dword value, size_t count)
@ -37,8 +36,7 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
"rep stosl\n"
: "=D"(dest), "=c"(count)
: "D"(dest), "c"(count), "a"(value)
: "memory"
);
: "memory");
}
inline constexpr dword round_up_to_power_of_two(dword value, dword power_of_two)
@ -60,7 +58,6 @@ inline T max(const T& a, const T& b)
return a < b ? b : a;
}
template<typename T, typename U>
static inline T ceil_div(T a, U b)
{
@ -112,21 +109,32 @@ void swap(T& a, U& b)
}
template<bool B, class T = void>
struct EnableIf
{
struct EnableIf {
};
template<class T>
struct EnableIf<true, T>
{
struct EnableIf<true, T> {
typedef T Type;
};
template<class T> struct RemoveConst { typedef T Type; };
template<class T> struct RemoveConst<const T> { typedef T Type; };
template<class T> struct RemoveVolatile { typedef T Type; };
template<class T> struct RemoveVolatile<const T> { typedef T Type; };
template<class T> struct RemoveCV {
template<class T>
struct RemoveConst {
typedef T Type;
};
template<class T>
struct RemoveConst<const T> {
typedef T Type;
};
template<class T>
struct RemoveVolatile {
typedef T Type;
};
template<class T>
struct RemoveVolatile<const T> {
typedef T Type;
};
template<class T>
struct RemoveCV {
typedef typename RemoveVolatile<typename RemoveConst<T>::Type>::Type Type;
};
@ -143,69 +151,145 @@ typedef IntegralConstant<bool, false> FalseType;
typedef IntegralConstant<bool, true> TrueType;
template<class T>
struct __IsPointerHelper : FalseType { };
struct __IsPointerHelper : FalseType {
};
template<class T>
struct __IsPointerHelper<T*> : TrueType { };
struct __IsPointerHelper<T*> : TrueType {
};
template<class T>
struct IsPointer : __IsPointerHelper<typename RemoveCV<T>::Type> { };
struct IsPointer : __IsPointerHelper<typename RemoveCV<T>::Type> {
};
template<class> struct IsFunction : FalseType { };
template<class>
struct IsFunction : FalseType {
};
template<class Ret, class... Args> struct IsFunction<Ret(Args...)> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...)> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile> : TrueType { };
template<class Ret, class... Args>
struct IsFunction<Ret(Args...)> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...)> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) const> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) const> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) volatile> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) volatile> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) const volatile> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) const volatile> : TrueType {
};
template<class Ret, class... Args> struct IsFunction<Ret(Args...) &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile &> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &> : TrueType { };
template<class Ret, class... Args>
struct IsFunction<Ret(Args...)&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...)&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) const&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) const&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) volatile&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) volatile&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) const volatile&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) const volatile&> : TrueType {
};
template<class Ret, class... Args> struct IsFunction<Ret(Args...) &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile &&> : TrueType { };
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &&> : TrueType { };
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) &&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) &&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) const&&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) const&&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) volatile&&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) volatile&&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args...) const volatile&&> : TrueType {
};
template<class Ret, class... Args>
struct IsFunction<Ret(Args..., ...) const volatile&&> : TrueType {
};
template<class T> struct IsRvalueReference : FalseType { };
template<class T> struct IsRvalueReference<T&&> : TrueType { };
template<class T>
struct IsRvalueReference : FalseType {
};
template<class T>
struct IsRvalueReference<T&&> : TrueType {
};
template<class T> struct RemovePointer { typedef T Type; };
template<class T> struct RemovePointer<T*> { typedef T Type; };
template<class T> struct RemovePointer<T* const> { typedef T Type; };
template<class T> struct RemovePointer<T* volatile> { typedef T Type; };
template<class T> struct RemovePointer<T* const volatile> { typedef T Type; };
template<class T>
struct RemovePointer {
typedef T Type;
};
template<class T>
struct RemovePointer<T*> {
typedef T Type;
};
template<class T>
struct RemovePointer<T* const> {
typedef T Type;
};
template<class T>
struct RemovePointer<T* volatile> {
typedef T Type;
};
template<class T>
struct RemovePointer<T* const volatile> {
typedef T Type;
};
template<typename T, typename U>
struct IsSame {
enum { value = 0 };
enum {
value = 0
};
};
template<typename T>
struct IsSame<T, T> {
enum { value = 1 };
enum {
value = 1
};
};
}
using AK::min;
using AK::max;
using AK::move;
using AK::forward;
using AK::exchange;
using AK::swap;
using AK::ceil_div;
using AK::exchange;
using AK::forward;
using AK::IsSame;
using AK::max;
using AK::min;
using AK::move;
using AK::swap;

View file

@ -1,7 +1,7 @@
#include "StringBuilder.h"
#include <LibC/stdarg.h>
#include "printf.cpp"
#include <AK/StdLibExtras.h>
#include <LibC/stdarg.h>
namespace AK {
@ -45,7 +45,8 @@ void StringBuilder::appendvf(const char* fmt, va_list ap)
{
printf_internal([this](char*&, char ch) {
append(ch);
}, nullptr, fmt, ap);
},
nullptr, fmt, ap);
}
void StringBuilder::appendf(const char* fmt, ...)
@ -71,4 +72,3 @@ String StringBuilder::to_string()
}
}

View file

@ -30,4 +30,3 @@ private:
}
using AK::StringBuilder;

View file

@ -1,7 +1,7 @@
#include "StringImpl.h"
#include "HashTable.h"
#include "StdLibExtras.h"
#include "kmalloc.h"
#include "HashTable.h"
//#define DEBUG_STRINGIMPL
@ -26,7 +26,8 @@ static StringImpl* s_the_empty_stringimpl = nullptr;
StringImpl& StringImpl::the_empty_stringimpl()
{
if (!s_the_empty_stringimpl)
s_the_empty_stringimpl = new StringImpl(ConstructTheEmptyStringImpl);;
s_the_empty_stringimpl = new StringImpl(ConstructTheEmptyStringImpl);
;
return *s_the_empty_stringimpl;
}
@ -168,4 +169,3 @@ void StringImpl::compute_hash() const
}
}

View file

@ -1,12 +1,15 @@
#pragma once
#include "Retainable.h"
#include "RetainPtr.h"
#include "Retainable.h"
#include "Types.h"
namespace AK {
enum ShouldChomp { NoChomp, Chomp };
enum ShouldChomp {
NoChomp,
Chomp
};
class StringImpl : public Retainable<StringImpl> {
public:
@ -22,7 +25,11 @@ public:
ssize_t length() const { return m_length; }
const char* characters() const { return m_characters; }
char operator[](ssize_t i) const { ASSERT(i >= 0 && i < m_length); return m_characters[i]; }
char operator[](ssize_t i) const
{
ASSERT(i >= 0 && i < m_length);
return m_characters[i];
}
unsigned hash() const
{
@ -32,10 +39,17 @@ public:
}
private:
enum ConstructTheEmptyStringImplTag { ConstructTheEmptyStringImpl };
explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { }
enum ConstructTheEmptyStringImplTag {
ConstructTheEmptyStringImpl
};
explicit StringImpl(ConstructTheEmptyStringImplTag)
: m_characters("")
{
}
enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer };
enum ConstructWithInlineBufferTag {
ConstructWithInlineBuffer
};
StringImpl(ConstructWithInlineBufferTag, ssize_t length);
void compute_hash() const;
@ -63,6 +77,6 @@ inline dword string_hash(const char* characters, int length)
}
using AK::StringImpl;
using AK::Chomp;
using AK::string_hash;
using AK::StringImpl;

View file

@ -1,5 +1,5 @@
#include <AK/StringView.h>
#include <AK/AKString.h>
#include <AK/StringView.h>
namespace AK {
@ -50,5 +50,4 @@ unsigned StringView::to_uint(bool& ok) const
return value;
}
}

View file

@ -9,8 +9,16 @@ class String;
class StringView {
public:
StringView() {}
StringView(const char* characters, int length) : m_characters(characters), m_length(length) { }
StringView(const unsigned char* characters, int length) : m_characters((const char*)characters), m_length(length) { }
StringView(const char* characters, int length)
: m_characters(characters)
, m_length(length)
{
}
StringView(const unsigned char* characters, int length)
: m_characters((const char*)characters)
, m_length(length)
{
}
StringView(const char* cstring)
: m_characters(cstring)
{

View file

@ -5,7 +5,12 @@ namespace AK {
template<typename T>
class TemporaryChange {
public:
TemporaryChange(T& variable, T value) : m_variable(variable), m_old_value(variable) { m_variable = value; }
TemporaryChange(T& variable, T value)
: m_variable(variable)
, m_old_value(variable)
{
m_variable = value;
}
~TemporaryChange() { m_variable = m_old_value; }
private:

View file

@ -1,13 +1,12 @@
#pragma once
#include "kstdio.h"
#include "HashFunctions.h"
#include "kstdio.h"
namespace AK {
template<typename T>
struct Traits
{
struct Traits {
};
template<>
@ -38,4 +37,3 @@ struct Traits<T*> {
};
}

View file

@ -48,9 +48,11 @@ constexpr unsigned KB = 1024;
constexpr unsigned MB = KB * KB;
constexpr unsigned GB = KB * KB * KB;
enum class IterationDecision { Continue, Abort };
enum class IterationDecision {
Continue,
Abort
};
namespace std {
typedef decltype(nullptr) nullptr_t;
}

View file

@ -112,8 +112,16 @@ public:
return m_outline_buffer;
}
const T& at(int i) const { ASSERT(i >= 0 && i < m_size); return data()[i]; }
T& at(int i) { ASSERT(i >= 0 && i < m_size); return data()[i]; }
const T& at(int i) const
{
ASSERT(i >= 0 && i < m_size);
return data()[i];
}
T& at(int i)
{
ASSERT(i >= 0 && i < m_size);
return data()[i];
}
const T& operator[](int i) const { return at(i); }
T& operator[](int i) { return at(i); }
@ -314,8 +322,16 @@ public:
bool operator<(const Iterator& other) { return m_index < other.m_index; }
bool operator>(const Iterator& other) { return m_index > other.m_index; }
bool operator>=(const Iterator& other) { return m_index >= other.m_index; }
Iterator& operator++() { ++m_index; return *this; }
Iterator& operator--() { --m_index; return *this; }
Iterator& operator++()
{
++m_index;
return *this;
}
Iterator& operator--()
{
--m_index;
return *this;
}
Iterator operator-(int value) { return { m_vector, m_index - value }; }
Iterator operator+(int value) { return { m_vector, m_index + value }; }
Iterator& operator=(const Iterator& other)
@ -325,9 +341,14 @@ public:
}
T& operator*() { return m_vector[m_index]; }
int operator-(const Iterator& other) { return m_index - other.m_index; }
private:
friend class Vector;
Iterator(Vector& vector, int index) : m_vector(vector), m_index(index) { }
Iterator(Vector& vector, int index)
: m_vector(vector)
, m_index(index)
{
}
Vector& m_vector;
int m_index { 0 };
};
@ -342,8 +363,16 @@ public:
bool operator<(const ConstIterator& other) { return m_index < other.m_index; }
bool operator>(const ConstIterator& other) { return m_index > other.m_index; }
bool operator>=(const ConstIterator& other) { return m_index >= other.m_index; }
ConstIterator& operator++() { ++m_index; return *this; }
ConstIterator& operator--() { --m_index; return *this; }
ConstIterator& operator++()
{
++m_index;
return *this;
}
ConstIterator& operator--()
{
--m_index;
return *this;
}
ConstIterator operator-(int value) { return { m_vector, m_index - value }; }
ConstIterator operator+(int value) { return { m_vector, m_index + value }; }
ConstIterator& operator=(const ConstIterator& other)
@ -353,9 +382,14 @@ public:
}
const T& operator*() const { return m_vector[m_index]; }
int operator-(const ConstIterator& other) { return m_index - other.m_index; }
private:
friend class Vector;
ConstIterator(const Vector& vector, const int index) : m_vector(vector), m_index(index) { }
ConstIterator(const Vector& vector, const int index)
: m_vector(vector)
, m_index(index)
{
}
const Vector& m_vector;
int m_index { 0 };
};
@ -377,8 +411,16 @@ private:
T* slot(int i) { return &data()[i]; }
const T* slot(int i) const { return &data()[i]; }
T* inline_buffer() { static_assert(inline_capacity > 0); return reinterpret_cast<T*>(m_inline_buffer_storage); }
const T* inline_buffer() const { static_assert(inline_capacity > 0); return reinterpret_cast<const T*>(m_inline_buffer_storage); }
T* inline_buffer()
{
static_assert(inline_capacity > 0);
return reinterpret_cast<T*>(m_inline_buffer_storage);
}
const T* inline_buffer() const
{
static_assert(inline_capacity > 0);
return reinterpret_cast<const T*>(m_inline_buffer_storage);
}
int m_size { 0 };
int m_capacity { 0 };

View file

@ -4,11 +4,13 @@
namespace AK {
template<typename T> class OwnPtr;
template<typename T>
class OwnPtr;
template<typename T>
class WeakPtr {
friend class Weakable<T>;
public:
WeakPtr() {}
WeakPtr(std::nullptr_t) {}
@ -48,7 +50,10 @@ public:
bool operator==(const OwnPtr<T>& other) const { return ptr() == other.ptr(); }
private:
WeakPtr(RetainPtr<WeakLink<T>>&& link) : m_link(move(link)) { }
WeakPtr(RetainPtr<WeakLink<T>>&& link)
: m_link(move(link))
{
}
RetainPtr<WeakLink<T>> m_link;
};
@ -64,4 +69,3 @@ inline WeakPtr<T> Weakable<T>::make_weak_ptr()
}
using AK::WeakPtr;

View file

@ -1,23 +1,29 @@
#pragma once
#include "Assertions.h"
#include "Retainable.h"
#include "RetainPtr.h"
#include "Retainable.h"
namespace AK {
template<typename T> class Weakable;
template<typename T> class WeakPtr;
template<typename T>
class Weakable;
template<typename T>
class WeakPtr;
template<typename T>
class WeakLink : public Retainable<WeakLink<T>> {
friend class Weakable<T>;
public:
T* ptr() { return static_cast<T*>(m_ptr); }
const T* ptr() const { return static_cast<const T*>(m_ptr); }
private:
explicit WeakLink(T& weakable) : m_ptr(&weakable) { }
explicit WeakLink(T& weakable)
: m_ptr(&weakable)
{
}
T* m_ptr;
};
@ -25,6 +31,7 @@ template<typename T>
class Weakable {
private:
class Link;
public:
WeakPtr<T> make_weak_ptr();

View file

@ -4,6 +4,7 @@
# define AK_MAKE_ETERNAL \
public: \
void* operator new(size_t size) { return kmalloc_eternal(size); } \
\
private:
#else
# define AK_MAKE_ETERNAL

View file

@ -169,7 +169,6 @@ template<typename PutChFunc>
return fieldWidth;
}
template<typename PutChFunc>
[[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
{
@ -223,14 +222,11 @@ one_more:
if (*(p + 1))
goto one_more;
}
switch( *p )
{
case 's':
{
switch (*p) {
case 's': {
const char* sp = va_arg(ap, const char*);
ret += print_string(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
}
break;
} break;
case 'd':
ret += print_signed_number(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth);
@ -297,13 +293,10 @@ one_more:
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
break;
}
}
else {
} else {
putch(bufptr, *p);
++ret;
}
}
return ret;
}

View file

@ -1,10 +1,10 @@
#pragma once
#include <AK/Vector.h>
#include <LibGUI/GTableView.h>
#include <LibGUI/GDirectoryModel.h>
#include <LibGUI/GItemView.h>
#include <LibGUI/GStackWidget.h>
#include <LibGUI/GDirectoryModel.h>
#include <LibGUI/GTableView.h>
#include <sys/stat.h>
class DirectoryView final : public GStackWidget {
@ -26,7 +26,12 @@ public:
Function<void(String)> on_status_message;
Function<void(int done, int total)> on_thumbnail_progress;
enum ViewMode { Invalid, List, Icon };
enum ViewMode
{
Invalid,
List,
Icon
};
void set_view_mode(ViewMode);
ViewMode view_mode() const { return m_view_mode; }

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GWidget.h>
#include <AK/Function.h>
#include <LibGUI/GWidget.h>
class GlyphEditorWidget;
class GlyphMapWidget;

View file

@ -1,5 +1,5 @@
#include <LibGUI/GFrame.h>
#include <AK/Function.h>
#include <LibGUI/GFrame.h>
class GlyphEditorWidget final : public GFrame {
public:

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GFrame.h>
#include <AK/Function.h>
#include <LibGUI/GFrame.h>
class GlyphMapWidget final : public GFrame {
public:

View file

@ -1,9 +1,9 @@
#pragma once
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include "IRCClient.h"
#include "IRCWindow.h"
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
class GAction;
class GStackWidget;

View file

@ -1,11 +1,11 @@
#pragma once
#include "IRCLogBuffer.h"
#include <AK/AKString.h>
#include <AK/CircularQueue.h>
#include <AK/Vector.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include "IRCLogBuffer.h"
#include <AK/Retainable.h>
#include <AK/Vector.h>
class IRCClient;
class IRCChannelMemberListModel;

View file

@ -1,13 +1,16 @@
#pragma once
#include <LibGUI/GModel.h>
#include <AK/Function.h>
#include <LibGUI/GModel.h>
class IRCChannel;
class IRCChannelMemberListModel final : public GModel {
public:
enum Column { Name };
enum Column
{
Name
};
static Retained<IRCChannelMemberListModel> create(IRCChannel& channel) { return adopt(*new IRCChannelMemberListModel(channel)); }
virtual ~IRCChannelMemberListModel() override;

View file

@ -1,13 +1,13 @@
#pragma once
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <AK/CircularQueue.h>
#include <AK/Function.h>
#include <LibCore/CTCPSocket.h>
#include <LibCore/CConfigFile.h>
#include "IRCLogBuffer.h"
#include "IRCWindow.h"
#include <AK/AKString.h>
#include <AK/CircularQueue.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <LibCore/CConfigFile.h>
#include <LibCore/CTCPSocket.h>
class IRCChannel;
class IRCQuery;
@ -17,6 +17,7 @@ class CNotifier;
class IRCClient final : public CObject {
friend class IRCChannel;
friend class IRCQuery;
public:
IRCClient();
virtual ~IRCClient() override;

View file

@ -2,8 +2,8 @@
#include <AK/AKString.h>
#include <AK/CircularQueue.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <SharedGraphics/Color.h>
class IRCLogBufferModel;

View file

@ -6,7 +6,8 @@ class IRCLogBuffer;
class IRCLogBufferModel final : public GModel {
public:
enum Column {
enum Column
{
Timestamp = 0,
Name,
Text,

View file

@ -1,11 +1,11 @@
#pragma once
#include "IRCLogBuffer.h"
#include <AK/AKString.h>
#include <AK/CircularQueue.h>
#include <AK/Vector.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include "IRCLogBuffer.h"
#include <AK/Retainable.h>
#include <AK/Vector.h>
class IRCClient;
class IRCWindow;

View file

@ -11,7 +11,8 @@ class GTextEditor;
class IRCWindow : public GWidget {
public:
enum Type {
enum Type
{
Server,
Channel,
Query,

View file

@ -1,14 +1,15 @@
#pragma once
#include <LibGUI/GModel.h>
#include <AK/Function.h>
#include <LibGUI/GModel.h>
class IRCClient;
class IRCWindow;
class IRCWindowListModel final : public GModel {
public:
enum Column {
enum Column
{
Name,
};

View file

@ -1,5 +1,5 @@
#include <LibGUI/GFrame.h>
#include <AK/CircularQueue.h>
#include <LibGUI/GFrame.h>
class GraphWidget final : public GFrame {
public:

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GWidget.h>
#include <LibCore/CFile.h>
#include <LibGUI/GWidget.h>
class GLabel;
class GraphWidget;

View file

@ -3,15 +3,16 @@
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <AK/Vector.h>
#include <LibGUI/GModel.h>
#include <LibCore/CFile.h>
#include <LibGUI/GModel.h>
#include <unistd.h>
class GraphWidget;
class ProcessModel final : public GModel {
public:
enum Column {
enum Column
{
Icon = 0,
Name,
CPU,

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GTableView.h>
#include <AK/Function.h>
#include <LibGUI/GTableView.h>
#include <unistd.h>
class GraphWidget;
@ -19,4 +19,3 @@ public:
private:
virtual void model_notification(const GModelNotification&) override;
};

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GButton.h>
#include "WindowIdentifier.h"
#include <LibGUI/GButton.h>
class TaskbarButton final : public GButton {
public:

View file

@ -1,6 +1,6 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include "WindowList.h"
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
class TaskbarWindow final : public GWindow {
public:

View file

@ -18,6 +18,7 @@ public:
{
return m_client_id == other.m_client_id && m_window_id == other.m_window_id;
}
private:
int m_client_id { -1 };
int m_window_id { -1 };

View file

@ -1,10 +1,10 @@
#pragma once
#include "WindowIdentifier.h"
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <SharedGraphics/Rect.h>
#include <LibGUI/GButton.h>
#include "WindowIdentifier.h"
#include <SharedGraphics/Rect.h>
class Window {
public:
@ -64,7 +64,8 @@ class WindowList {
public:
static WindowList& the();
template<typename Callback> void for_each_window(Callback callback)
template<typename Callback>
void for_each_window(Callback callback)
{
for (auto& it : m_windows)
callback(*it.value);

View file

@ -3,12 +3,12 @@
#include <AK/AKString.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <SharedGraphics/Rect.h>
#include <LibGUI/GFrame.h>
#include <LibCore/CConfigFile.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CTimer.h>
#include <LibCore/CConfigFile.h>
#include <LibGUI/GFrame.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <SharedGraphics/Rect.h>
class Font;
@ -45,7 +45,6 @@ private:
void invalidate_cursor();
void set_window_title(const String&);
void inject_string(const String&);
void unimplemented_escape();
void unimplemented_xterm_escape();
@ -107,7 +106,11 @@ private:
bool dirty { false };
word length { 0 };
};
Line& line(size_t index) { ASSERT(index < m_rows); return *m_lines[index]; }
Line& line(size_t index)
{
ASSERT(index < m_rows);
return *m_lines[index];
}
Line** m_lines { nullptr };
@ -125,7 +128,8 @@ private:
void execute_escape_sequence(byte final);
void execute_xterm_command();
enum EscapeState {
enum EscapeState
{
Normal,
ExpectBracket,
ExpectParameter,

View file

@ -1,11 +1,12 @@
#pragma once
#include <LibGUI/GWidget.h>
#include <AK/Vector.h>
#include "VBWidget.h"
#include <AK/Vector.h>
#include <LibGUI/GWidget.h>
class VBForm : public GWidget {
friend class VBWidget;
public:
explicit VBForm(const String& name, GWidget* parent = nullptr);
virtual ~VBForm() override;
@ -43,7 +44,8 @@ private:
void add_to_selection(VBWidget&);
void remove_from_selection(VBWidget&);
void delete_selected_widgets();
template<typename Callback> void for_each_selected_widget(Callback);
template<typename Callback>
void for_each_selected_widget(Callback);
VBWidget* single_selected_widget();

View file

@ -9,6 +9,7 @@ class VBWidget;
class VBProperty {
friend class VBWidget;
public:
VBProperty(VBWidget&, const String& name, const GVariant& value);
VBProperty(VBWidget&, const String& name, Function<GVariant(const GWidget&)>&& getter, Function<void(GWidget&, const GVariant&)>&& setter);

View file

@ -1,12 +1,12 @@
#pragma once
#include <SharedGraphics/Rect.h>
#include "VBWidgetType.h"
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/Retainable.h>
#include <AK/Retained.h>
#include <AK/Weakable.h>
#include <AK/HashMap.h>
#include <AK/Function.h>
#include "VBWidgetType.h"
#include <SharedGraphics/Rect.h>
class GPainter;
class GVariant;
@ -15,7 +15,18 @@ class VBForm;
class VBProperty;
class VBWidgetPropertyModel;
enum class Direction { None, Left, UpLeft, Up, UpRight, Right, DownRight, Down, DownLeft };
enum class Direction
{
None,
Left,
UpLeft,
Up,
UpRight,
Right,
DownRight,
Down,
DownLeft
};
template<typename Callback>
inline void for_each_direction(Callback callback)
{
@ -29,8 +40,10 @@ inline void for_each_direction(Callback callback)
callback(Direction::DownLeft);
}
class VBWidget : public Retainable<VBWidget>, public Weakable<VBWidget> {
class VBWidget : public Retainable<VBWidget>
, public Weakable<VBWidget> {
friend class VBWidgetPropertyModel;
public:
static Retained<VBWidget> create(VBWidgetType type, VBForm& form) { return adopt(*new VBWidget(type, form)); }
~VBWidget();

View file

@ -7,7 +7,8 @@ class VBProperty;
class VBWidgetPropertyModel : public GModel {
public:
enum Column {
enum Column
{
Name = 0,
Value,
__Count

View file

@ -1,9 +1,9 @@
#pragma once
#include "VBWidgetType.h"
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/AKString.h>
class GWidget;
class VBProperty;
@ -11,7 +11,8 @@ class VBWidget;
class VBWidgetRegistry {
public:
template<typename Callback> static void for_each_widget_type(Callback callback)
template<typename Callback>
static void for_each_widget_type(Callback callback)
{
for (unsigned i = 1; i < (unsigned)VBWidgetType::__Count; ++i)
callback((VBWidgetType)i);

View file

@ -1,6 +1,7 @@
#pragma once
enum class VBWidgetType {
enum class VBWidgetType
{
None = 0,
GWidget,
GButton,

View file

@ -1,8 +1,8 @@
#pragma once
#include <LibGUI/GFrame.h>
#include <LibCore/CTimer.h>
#include <AK/Noncopyable.h>
#include <LibCore/CTimer.h>
#include <LibGUI/GFrame.h>
class Field;
class GButton;
@ -27,12 +27,14 @@ public:
SquareButton* button { nullptr };
SquareLabel* label { nullptr };
template<typename Callback> void for_each_neighbor(Callback);
template<typename Callback>
void for_each_neighbor(Callback);
};
class Field final : public GFrame {
friend class Square;
friend class SquareLabel;
public:
Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent);
virtual ~Field() override;
@ -66,9 +68,15 @@ private:
void flood_fill(Square&);
template<typename Callback> void for_each_square(Callback);
template<typename Callback>
void for_each_square(Callback);
enum class Face { Default, Good, Bad };
enum class Face
{
Default,
Good,
Bad
};
void set_face(Face);
int m_rows { 9 };

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GWidget.h>
#include <AK/CircularQueue.h>
#include <LibGUI/GWidget.h>
class SnakeGame : public GWidget {
public:

View file

@ -1,7 +1,7 @@
#pragma once
#include <Kernel/kstdio.h>
#include <Kernel/i386.h>
#include <Kernel/kstdio.h>
#ifdef DEBUG
[[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
@ -11,7 +11,14 @@
# define ASSERT(expr)
# define ASSERT_NOT_REACHED() CRASH()
#endif
#define CRASH() do { asm volatile("ud2"); } while(0)
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
#define CRASH() \
do { \
asm volatile("ud2"); \
} while (0)
#define RELEASE_ASSERT(x) \
do { \
if (!(x)) \
CRASH(); \
} while (0)
#define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpu_flags() & 0x200))
#define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpu_flags() & 0x200)

View file

@ -35,4 +35,3 @@ private:
ConsoleImplementation* m_implementation { nullptr };
CircularQueue<char, 16384> m_logbuffer;
};

View file

@ -1,10 +1,10 @@
#pragma once
#include <AK/Types.h>
#include <AK/AKString.h>
#include <SharedGraphics/Size.h>
#include <Kernel/PhysicalAddress.h>
#include <AK/Types.h>
#include <Kernel/Devices/BlockDevice.h>
#include <Kernel/PhysicalAddress.h>
#include <SharedGraphics/Size.h>
class BXVGADevice final : public BlockDevice {
AK_MAKE_ETERNAL

View file

@ -10,7 +10,10 @@ public:
virtual bool is_seekable() const override { return true; }
protected:
BlockDevice(unsigned major, unsigned minor) : Device(major, minor) { }
BlockDevice(unsigned major, unsigned minor)
: Device(major, minor)
{
}
private:
virtual bool is_block_device() const final { return true; }

View file

@ -7,7 +7,10 @@ public:
virtual ~CharacterDevice() override;
protected:
CharacterDevice(unsigned major, unsigned minor) : Device(major, minor) { }
CharacterDevice(unsigned major, unsigned minor)
: Device(major, minor)
{
}
private:
virtual bool is_character_device() const final { return true; }

View file

@ -23,4 +23,3 @@ public:
protected:
DiskDevice();
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/Devices/DiskDevice.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/RetainPtr.h>
#include <AK/Types.h>
#include <Kernel/Devices/DiskDevice.h>
#include <stdio.h>
class FileBackedDiskDevice final : public DiskDevice {
@ -30,4 +30,3 @@ private:
DiskOffset m_file_length { 0 };
unsigned m_block_size { 0 };
};

View file

@ -16,4 +16,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "FullDevice"; }
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/Lock.h>
#include <AK/RetainPtr.h>
#include <Kernel/Devices/DiskDevice.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/Lock.h>
#include <Kernel/PCI.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VM/PhysicalPage.h>
@ -14,7 +14,8 @@ struct PhysicalRegionDescriptor {
word end_of_table { 0 };
};
class IDEDiskDevice final : public IRQHandler, public DiskDevice {
class IDEDiskDevice final : public IRQHandler
, public DiskDevice {
AK_MAKE_ETERNAL
public:
static Retained<IDEDiskDevice> create();
@ -58,4 +59,3 @@ private:
word m_bus_master_base { 0 };
Lockable<bool> m_dma_enabled;
};

View file

@ -1,15 +1,16 @@
#pragma once
#include <AK/Types.h>
#include <AK/DoublyLinkedList.h>
#include <AK/CircularQueue.h>
#include <Kernel/Devices/CharacterDevice.h>
#include "IRQHandler.h"
#include "KeyCode.h"
#include <AK/CircularQueue.h>
#include <AK/DoublyLinkedList.h>
#include <AK/Types.h>
#include <Kernel/Devices/CharacterDevice.h>
class KeyboardClient;
class KeyboardDevice final : public IRQHandler, public CharacterDevice {
class KeyboardDevice final : public IRQHandler
, public CharacterDevice {
AK_MAKE_ETERNAL
public:
using Event = KeyEvent;

View file

@ -18,4 +18,3 @@ private:
virtual bool can_read(FileDescriptor&) const override;
virtual const char* class_name() const override { return "NullDevice"; }
};

View file

@ -1,11 +1,12 @@
#pragma once
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/MousePacket.h>
#include <Kernel/IRQHandler.h>
#include <AK/CircularQueue.h>
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/MousePacket.h>
class PS2MouseDevice final : public IRQHandler, public CharacterDevice {
class PS2MouseDevice final : public IRQHandler
, public CharacterDevice {
public:
PS2MouseDevice();
virtual ~PS2MouseDevice() override;

View file

@ -18,4 +18,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "RandomDevice"; }
};

View file

@ -16,4 +16,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "ZeroDevice"; }
};

View file

@ -26,4 +26,3 @@ private:
HashTable<SlavePTY*> m_slave_ptys;
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/UnixTypes.h>
#include <Kernel/FileSystem/DiskBackedFileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/ext2_fs.h>
#include <Kernel/FileSystem/DiskBackedFileSystem.h>
#include <Kernel/UnixTypes.h>
struct ext2_group_desc;
struct ext2_inode;
@ -13,6 +13,7 @@ class Ext2FS;
class Ext2FSInode final : public Inode {
friend class Ext2FS;
public:
virtual ~Ext2FSInode() override;
@ -59,6 +60,7 @@ private:
class Ext2FS final : public DiskBackedFS {
friend class Ext2FSInode;
public:
static Retained<Ext2FS> create(Retained<DiskDevice>&&);
virtual ~Ext2FS() override;

View file

@ -1,15 +1,18 @@
#pragma once
#include <Kernel/DoubleBuffer.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/File.h>
#include <Kernel/UnixTypes.h>
class FileDescriptor;
class FIFO final : public File {
public:
enum class Direction : byte {
Neither, Reader, Writer
enum class Direction : byte
{
Neither,
Reader,
Writer
};
static RetainPtr<FIFO> from_fifo_id(dword);

View file

@ -1,14 +1,14 @@
#pragma once
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/LinearAddress.h>
#include <AK/Badge.h>
#include <AK/ByteBuffer.h>
#include <AK/CircularQueue.h>
#include <AK/Retainable.h>
#include <AK/Badge.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/Net/Socket.h>
class File;
@ -119,4 +119,3 @@ private:
SocketRole m_socket_role { SocketRole::None };
FIFO::Direction m_fifo_direction { FIFO::Direction::Neither };
};

View file

@ -1,20 +1,20 @@
#pragma once
#include <Kernel/Devices/DiskDevice.h>
#include "InodeIdentifier.h"
#include "InodeMetadata.h"
#include "UnixTypes.h"
#include <AK/AKString.h>
#include <AK/ByteBuffer.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/kstdio.h>
#include <Kernel/Lock.h>
#include <AK/Retainable.h>
#include <AK/WeakPtr.h>
#include <AK/kstdio.h>
#include <Kernel/Devices/DiskDevice.h>
#include <Kernel/KResult.h>
#include <Kernel/Lock.h>
static const dword mepoch = 476763780;
@ -25,6 +25,7 @@ class VMObject;
class FS : public Retainable<FS> {
friend class Inode;
public:
virtual ~FS();
@ -93,4 +94,3 @@ struct Traits<InodeIdentifier> {
};
}

View file

@ -1,12 +1,12 @@
#pragma once
#include <AK/Retainable.h>
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/Retainable.h>
#include <AK/WeakPtr.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/KResult.h>
#include <Kernel/Lock.h>
@ -17,6 +17,7 @@ class VMObject;
class Inode : public Retainable<Inode> {
friend class VFS;
friend class FS;
public:
virtual ~Inode();
@ -89,4 +90,3 @@ private:
RetainPtr<LocalSocket> m_socket;
bool m_metadata_dirty { false };
};

View file

@ -39,4 +39,3 @@ private:
dword m_fsid { 0 };
dword m_index { 0 };
};

View file

@ -84,5 +84,3 @@ struct InodeMetadata {
unsigned major_device { 0 };
unsigned minor_device { 0 };
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/Lock.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/Lock.h>
class Process;
@ -11,6 +11,7 @@ class ProcFSInode;
class ProcFS final : public FS {
friend class ProcFSInode;
public:
[[gnu::pure]] static ProcFS& the();
@ -69,6 +70,7 @@ struct ProcFSInodeCustomData {
class ProcFSInode final : public Inode {
friend class ProcFS;
public:
virtual ~ProcFSInode() override;

View file

@ -1,9 +1,9 @@
#pragma once
#include <AK/HashMap.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/UnixTypes.h>
#include <AK/HashMap.h>
class SynthFSInode;
@ -47,6 +47,7 @@ struct SynthFSInodeCustomData {
class SynthFSInode final : public Inode {
friend class SynthFS;
friend class DevPtsFS;
public:
virtual ~SynthFSInode() override;

View file

@ -1,14 +1,14 @@
#pragma once
#include "FileSystem.h"
#include "InodeIdentifier.h"
#include "InodeMetadata.h"
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/Vector.h>
#include <AK/Function.h>
#include "InodeIdentifier.h"
#include "InodeMetadata.h"
#include "FileSystem.h"
#include <Kernel/KResult.h>
#define O_RDONLY 0
@ -116,4 +116,3 @@ private:
Vector<OwnPtr<Mount>> m_mounts;
HashMap<dword, Device*> m_devices;
};

View file

@ -89,10 +89,8 @@
#else
# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
# define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
# define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
#endif
#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32))
@ -135,8 +133,7 @@ struct ext2_acl_entry /* Access Control List Entry */
/*
* Structure of a blocks group descriptor
*/
struct ext2_group_desc
{
struct ext2_group_desc {
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
@ -149,8 +146,7 @@ struct ext2_group_desc
__u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
};
struct ext4_group_desc
{
struct ext4_group_desc {
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
@ -214,7 +210,6 @@ struct ext2_dx_countlimit {
__u16 count;
};
/*
* Macro-instructions used to manage group descriptors
*/
@ -222,8 +217,7 @@ struct ext2_dx_countlimit {
#define EXT2_MIN_DESC_SIZE_64BIT 64
#define EXT2_MAX_DESC_SIZE EXT2_MIN_BLOCK_SIZE
#define EXT2_DESC_SIZE(s) \
((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \
(s)->s_desc_size : EXT2_MIN_DESC_SIZE)
((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
@ -476,8 +470,7 @@ struct ext2_inode_large {
#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
EXT2_MOUNT_##opt)
#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_##opt)
/*
* Maximal mount counts between two filesystem checks
*/
@ -644,13 +637,9 @@ struct ext2_super_block {
#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
#define EXT2_FEATURE_COMPAT_SUPP 0
#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE)
#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \
EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER | EXT2_FEATURE_RO_COMPAT_LARGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK | EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
/*
* Default values for user and/or group using reserved blocks
@ -719,8 +708,7 @@ struct ext2_dir_entry_2 {
*/
#define EXT2_DIR_PAD 4
#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
~EXT2_DIR_ROUND)
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & ~EXT2_DIR_ROUND)
/*
* This structure will be used for multiple mount protection. It will be

View file

@ -3,8 +3,7 @@
* everything we need. (cross fingers) Other header files may have
* also defined the types that we need.
*/
#if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && \
!defined(_EXT2_TYPES_H))
#if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && !defined(_EXT2_TYPES_H))
# define _EXT2_TYPES_H
# define __S8_TYPEDEF __signed__ char
@ -51,12 +50,12 @@ typedef int __s16;
# if (2 == 2)
typedef short __s16;
# else
?==error: undefined 16 bit type
? == error
: undefined 16 bit type
# endif /* SIZEOF_SHORT == 2 */
# endif /* SIZEOF_INT == 2 */
# endif /* __S16_TYPEDEF */
# ifdef __U32_TYPEDEF
typedef __U32_TYPEDEF __u32;
# else
@ -69,7 +68,8 @@ typedef unsigned long __u32;
# if (2 == 4)
typedef unsigned short __u32;
# else
?== error: undefined 32 bit type
? == error
: undefined 32 bit type
# endif /* SIZEOF_SHORT == 4 */
# endif /* SIZEOF_LONG == 4 */
# endif /* SIZEOF_INT == 4 */
@ -87,7 +87,8 @@ typedef long __s32;
# if (2 == 4)
typedef short __s32;
# else
?== error: undefined 32 bit type
? == error
: undefined 32 bit type
# endif /* SIZEOF_SHORT == 4 */
# endif /* SIZEOF_LONG == 4 */
# endif /* SIZEOF_INT == 4 */

View file

@ -7,27 +7,36 @@ namespace IO {
inline byte in8(word port)
{
byte value;
asm volatile("inb %1, %0":"=a"(value):"Nd"(port));
asm volatile("inb %1, %0"
: "=a"(value)
: "Nd"(port));
return value;
}
inline word in16(word port)
{
word value;
asm volatile("inw %1, %0":"=a"(value):"Nd"(port));
asm volatile("inw %1, %0"
: "=a"(value)
: "Nd"(port));
return value;
}
inline dword in32(word port)
{
dword value;
asm volatile("inl %1, %0":"=a"(value):"Nd"(port));
asm volatile("inl %1, %0"
: "=a"(value)
: "Nd"(port));
return value;
}
inline void repeated_in16(word port, byte* buffer, int buffer_size)
{
asm volatile("rep insw" : "+D"(buffer), "+c"(buffer_size) : "d"(port) : "memory");
asm volatile("rep insw"
: "+D"(buffer), "+c"(buffer_size)
: "d"(port)
: "memory");
}
inline void out8(word port, byte value)
@ -47,7 +56,9 @@ inline void out32(word port, dword value)
inline void repeated_out16(word port, const byte* data, int data_size)
{
asm volatile("rep outsw" : "+S"(data), "+c"(data_size) : "d"(port));
asm volatile("rep outsw"
: "+S"(data), "+c"(data_size)
: "d"(port));
}
}

View file

@ -18,4 +18,3 @@ protected:
private:
byte m_irq_number { 0 };
};

View file

@ -3,19 +3,30 @@
#include <AK/Assertions.h>
#include <LibC/errno_numbers.h>
enum KSuccessTag { KSuccess };
enum KSuccessTag
{
KSuccess
};
class KResult {
public:
explicit KResult(int negative_e) : m_error(negative_e) { ASSERT(negative_e <= 0); }
KResult(KSuccessTag) : m_error(0) { }
explicit KResult(int negative_e)
: m_error(negative_e)
{
ASSERT(negative_e <= 0);
}
KResult(KSuccessTag)
: m_error(0)
{
}
operator int() const { return m_error; }
bool is_success() const { return m_error == ESUCCESS; }
bool is_error() const { return !is_success(); }
private:
template<typename T> friend class KResultOr;
template<typename T>
friend class KResultOr;
KResult() {}
int m_error { 0 };
@ -27,7 +38,8 @@ public:
KResultOr(KResult error)
: m_error(error)
, m_is_error(true)
{ }
{
}
KResultOr(T&& value)
{
@ -54,9 +66,21 @@ public:
}
bool is_error() const { return m_is_error; }
KResult error() const { ASSERT(m_is_error); return m_error; }
T& value() { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); }
const T& value() const { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); }
KResult error() const
{
ASSERT(m_is_error);
return m_error;
}
T& value()
{
ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
const T& value() const
{
ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
T release_value()
{
@ -71,4 +95,3 @@ private:
KResult m_error;
bool m_is_error { false };
};

View file

@ -2,7 +2,8 @@
#include <AK/Types.h>
enum KeyCode : byte {
enum KeyCode : byte
{
Key_Invalid = 0,
Key_Escape,
Key_Tab,
@ -113,7 +114,8 @@ enum KeyCode : byte {
Key_Shift = Key_LeftShift,
};
enum KeyModifier {
enum KeyModifier
{
Mod_None = 0x00,
Mod_Alt = 0x01,
Mod_Ctrl = 0x02,

View file

@ -5,7 +5,10 @@
class LinearAddress {
public:
LinearAddress() {}
explicit LinearAddress(dword address) : m_address(address) { }
explicit LinearAddress(dword address)
: m_address(address)
{
}
bool is_null() const { return m_address == 0; }

View file

@ -2,9 +2,9 @@
#include <AK/Assertions.h>
#include <AK/Types.h>
#include <Kernel/i386.h>
#include <Kernel/Scheduler.h>
#include <Kernel/KSyms.h>
#include <Kernel/Scheduler.h>
#include <Kernel/i386.h>
class Thread;
extern Thread* current;
@ -22,7 +22,10 @@ static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
class Lock {
public:
Lock(const char* name = nullptr) : m_name(name) { }
Lock(const char* name = nullptr)
: m_name(name)
{
}
~Lock() {}
void lock();
@ -40,7 +43,11 @@ private:
class Locker {
public:
[[gnu::always_inline]] inline explicit Locker(Lock& l) : m_lock(l) { lock(); }
[[gnu::always_inline]] inline explicit Locker(Lock& l)
: m_lock(l)
{
lock();
}
[[gnu::always_inline]] inline ~Locker() { unlock(); }
[[gnu::always_inline]] inline void unlock() { m_lock.unlock(); }
[[gnu::always_inline]] inline void lock() { m_lock.lock(); }
@ -124,7 +131,10 @@ template<typename T>
class Lockable {
public:
Lockable() {}
Lockable(T&& resource) : m_resource(move(resource)) { }
Lockable(T&& resource)
: m_resource(move(resource))
{
}
Lock& lock() { return m_lock; }
T& resource() { return m_resource; }
@ -138,4 +148,3 @@ private:
T m_resource;
Lock m_lock;
};

Some files were not shown because too many files have changed in this diff Show more