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,18 +3,18 @@
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/RetainPtr.h> #include <AK/RetainPtr.h>
#include <AK/StringImpl.h> #include <AK/StringImpl.h>
#include <AK/StringView.h>
#include <AK/Traits.h> #include <AK/Traits.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <AK/StringView.h>
#include <AK/kstdio.h> #include <AK/kstdio.h>
namespace AK { namespace AK {
class String { class String {
public: public:
~String() { } ~String() {}
String() { } String() {}
String(StringView view) String(StringView view)
: m_impl(StringImpl::create(view.characters(), view.length())) : m_impl(StringImpl::create(view.characters(), view.length()))
@ -96,7 +96,11 @@ public:
bool is_empty() const { return length() == 0; } bool is_empty() const { return length() == 0; }
ssize_t length() const { return m_impl ? m_impl->length() : 0; } ssize_t length() const { return m_impl ? m_impl->length() : 0; }
const char* characters() const { return m_impl ? m_impl->characters() : nullptr; } 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; bool ends_with(const String&) const;
@ -131,7 +135,7 @@ public:
static String copy(const BufferType& buffer, ShouldChomp should_chomp = NoChomp) static String copy(const BufferType& buffer, ShouldChomp should_chomp = NoChomp)
{ {
if (buffer.is_null()) if (buffer.is_null())
return { }; return {};
if (buffer.is_empty()) if (buffer.is_empty())
return empty(); return empty();
return String((const char*)buffer.data(), buffer.size(), should_chomp); return String((const char*)buffer.data(), buffer.size(), should_chomp);

View file

@ -1,13 +1,13 @@
#pragma once #pragma once
#ifdef KERNEL #ifdef KERNEL
#include <Kernel/Assertions.h> # include <Kernel/Assertions.h>
#else #else
#include <assert.h> # include <assert.h>
#ifndef __serenity__ # ifndef __serenity__
#define ASSERT assert # define ASSERT assert
#define ASSERT_NOT_REACHED assert(false) # define ASSERT_NOT_REACHED assert(false)
#endif # endif
#endif #endif
namespace AK { namespace AK {
@ -17,4 +17,3 @@ inline void not_implemented() { ASSERT(false); }
} }
using AK::not_implemented; using AK::not_implemented;

View file

@ -3,5 +3,5 @@
template<typename T> template<typename T>
class Badge { class Badge {
friend T; friend T;
Badge() { } Badge() {}
}; };

View file

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

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "Types.h"
#include "StdLibExtras.h" #include "StdLibExtras.h"
#include <AK/Retainable.h> #include "Types.h"
#include <AK/RetainPtr.h> #include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/kmalloc.h> #include <AK/kmalloc.h>
namespace AK { namespace AK {
@ -28,8 +28,16 @@ public:
m_data = nullptr; m_data = nullptr;
} }
byte& operator[](int i) { ASSERT(i < m_size); return m_data[i]; } byte& operator[](int i)
const byte& operator[](int i) const { ASSERT(i < m_size); return m_data[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; } bool is_empty() const { return !m_size; }
int size() const { return m_size; } int size() const { return m_size; }
@ -52,11 +60,16 @@ public:
void grow(int size); void grow(int size);
private: private:
enum ConstructionMode { Uninitialized, Copy, Wrap, Adopt }; enum ConstructionMode {
explicit ByteBufferImpl(int); // For ConstructionMode=Uninitialized Uninitialized,
Copy,
Wrap,
Adopt
};
explicit ByteBufferImpl(int); // For ConstructionMode=Uninitialized
ByteBufferImpl(const void*, int, ConstructionMode); // For ConstructionMode=Copy ByteBufferImpl(const void*, int, ConstructionMode); // For ConstructionMode=Copy
ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
ByteBufferImpl() { } ByteBufferImpl() {}
byte* m_data { nullptr }; byte* m_data { nullptr };
int m_size { 0 }; int m_size { 0 };
@ -65,8 +78,8 @@ private:
class ByteBuffer { class ByteBuffer {
public: public:
ByteBuffer() { } ByteBuffer() {}
ByteBuffer(std::nullptr_t) { } ByteBuffer(std::nullptr_t) {}
ByteBuffer(const ByteBuffer& other) ByteBuffer(const ByteBuffer& other)
: m_impl(other.m_impl.copy_ref()) : m_impl(other.m_impl.copy_ref())
{ {
@ -101,8 +114,16 @@ public:
bool operator!() const { return is_null(); } bool operator!() const { return is_null(); }
bool is_null() const { return m_impl == nullptr; } 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)
byte operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[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(); } bool is_empty() const { return !m_impl || m_impl->is_empty(); }
ssize_t size() const { return m_impl ? m_impl->size() : 0; } ssize_t size() const { return m_impl ? m_impl->size() : 0; }
@ -121,7 +142,7 @@ public:
ByteBuffer isolated_copy() const ByteBuffer isolated_copy() const
{ {
if (!m_impl) if (!m_impl)
return { }; return {};
return copy(m_impl->pointer(), m_impl->size()); return copy(m_impl->pointer(), m_impl->size());
} }
@ -135,9 +156,9 @@ public:
ByteBuffer slice(ssize_t offset, ssize_t size) const ByteBuffer slice(ssize_t offset, ssize_t size) const
{ {
if (is_null()) if (is_null())
return { }; return {};
if (offset >= this->size()) if (offset >= this->size())
return { }; return {};
if (offset + size >= this->size()) if (offset + size >= this->size())
size = this->size() - offset; size = this->size() - offset;
return copy(offset_pointer(offset), size); return copy(offset_pointer(offset), size);
@ -241,4 +262,3 @@ inline Retained<ByteBufferImpl> ByteBufferImpl::adopt(void* data, int size)
} }
using AK::ByteBuffer; using AK::ByteBuffer;

View file

@ -60,9 +60,14 @@ public:
} }
const T& operator*() const { return m_queue.m_elements[m_index]; } const T& operator*() const { return m_queue.m_elements[m_index]; }
private: private:
friend class CircularQueue; 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; const CircularQueue& m_queue;
int m_index { 0 }; int m_index { 0 };
}; };
@ -82,4 +87,3 @@ private:
} }
using AK::CircularQueue; using AK::CircularQueue;

View file

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

View file

@ -1,7 +1,7 @@
#include "FileSystemPath.h" #include "FileSystemPath.h"
#include "StringBuilder.h"
#include "Vector.h" #include "Vector.h"
#include "kstdio.h" #include "kstdio.h"
#include "StringBuilder.h"
namespace AK { namespace AK {
@ -14,7 +14,7 @@ FileSystemPath::FileSystemPath(const String& s)
bool FileSystemPath::canonicalize(bool resolve_symbolic_links) bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
{ {
// FIXME: Implement "resolve_symbolic_links" // FIXME: Implement "resolve_symbolic_links"
(void) resolve_symbolic_links; (void)resolve_symbolic_links;
auto parts = m_string.split('/'); auto parts = m_string.split('/');
Vector<String> canonical_parts; Vector<String> canonical_parts;

View file

@ -6,7 +6,7 @@ namespace AK {
class FileSystemPath { class FileSystemPath {
public: public:
FileSystemPath() { } FileSystemPath() {}
explicit FileSystemPath(const String&); explicit FileSystemPath(const String&);
bool is_valid() const { return m_is_valid; } bool is_valid() const { return m_is_valid; }

View file

@ -31,13 +31,14 @@
namespace AK { namespace AK {
template<typename> class Function; template<typename>
class Function;
template <typename Out, typename... In> template<typename Out, typename... In>
class Function<Out(In...)> { class Function<Out(In...)> {
public: public:
Function() = default; Function() = default;
Function(std::nullptr_t) { } Function(std::nullptr_t) {}
template<typename CallableType, class = typename EnableIf<!(IsPointer<CallableType>::value && IsFunction<typename RemovePointer<CallableType>::Type>::value) && IsRvalueReference<CallableType&&>::value>::Type> template<typename CallableType, class = typename EnableIf<!(IsPointer<CallableType>::value && IsFunction<typename RemovePointer<CallableType>::Type>::value) && IsRvalueReference<CallableType&&>::value>::Type>
Function(CallableType&& callable) Function(CallableType&& callable)
@ -82,7 +83,7 @@ public:
private: private:
class CallableWrapperBase { class CallableWrapperBase {
public: public:
virtual ~CallableWrapperBase() { } virtual ~CallableWrapperBase() {}
virtual Out call(In...) const = 0; virtual Out call(In...) const = 0;
}; };
@ -109,4 +110,3 @@ private:
} }
using AK::Function; 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))); return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
} }

View file

@ -32,7 +32,7 @@ private:
}; };
public: public:
HashMap() { } HashMap() {}
HashMap(HashMap&& other) HashMap(HashMap&& other)
: m_table(move(other.m_table)) : m_table(move(other.m_table))
@ -115,13 +115,13 @@ private:
template<typename K, typename V> template<typename K, typename V>
void HashMap<K, V>::set(const K& key, V&& value) void HashMap<K, V>::set(const K& key, V&& value)
{ {
m_table.set(Entry{key, move(value)}); m_table.set(Entry { key, move(value) });
} }
template<typename K, typename V> template<typename K, typename V>
void HashMap<K, V>::set(const K& key, const V& value) void HashMap<K, V>::set(const K& key, const V& value)
{ {
m_table.set(Entry{key, value}); m_table.set(Entry { key, value });
} }
template<typename K, typename V> template<typename K, typename V>
@ -148,4 +148,3 @@ auto HashMap<K, V>::find(const K& key) const -> ConstIteratorType
} }
using AK::HashMap; using AK::HashMap;

View file

@ -2,15 +2,16 @@
#include "Assertions.h" #include "Assertions.h"
#include "DoublyLinkedList.h" #include "DoublyLinkedList.h"
#include "Traits.h"
#include "StdLibExtras.h" #include "StdLibExtras.h"
#include "Traits.h"
#include "kstdio.h" #include "kstdio.h"
//#define HASHTABLE_DEBUG //#define HASHTABLE_DEBUG
namespace AK { namespace AK {
template<typename T, typename = Traits<T>> class HashTable; template<typename T, typename = Traits<T>>
class HashTable;
template<typename T, typename TraitsForT> template<typename T, typename TraitsForT>
class HashTable { class HashTable {
@ -20,7 +21,7 @@ private:
}; };
public: public:
HashTable() { } HashTable() {}
explicit HashTable(HashTable&& other) explicit HashTable(HashTable&& other)
: m_buckets(other.m_buckets) : m_buckets(other.m_buckets)
, m_size(other.m_size) , m_size(other.m_size)
@ -112,6 +113,7 @@ public:
return; return;
} }
} }
private: private:
friend class HashTable; 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) 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; return;
} }
} }
private: private:
friend class HashTable; 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) 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++; m_size++;
} }
template<typename T, typename TraitsForT> template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::rehash(int new_capacity) void HashTable<T, TraitsForT>::rehash(int new_capacity)
{ {
@ -308,14 +310,14 @@ void HashTable<T, TraitsForT>::rehash(int new_capacity)
} }
} }
delete [] old_buckets; delete[] old_buckets;
} }
template<typename T, typename TraitsForT> template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::clear() void HashTable<T, TraitsForT>::clear()
{ {
if (m_buckets) { if (m_buckets) {
delete [] m_buckets; delete[] m_buckets;
m_buckets = nullptr; m_buckets = nullptr;
} }
m_capacity = 0; m_capacity = 0;
@ -429,4 +431,3 @@ void HashTable<T, TraitsForT>::dump() const
} }
using AK::HashTable; using AK::HashTable;

View file

@ -5,47 +5,54 @@
namespace AK { namespace AK {
template<typename T> class InlineLinkedListNode { template<typename T>
class InlineLinkedListNode {
public: public:
InlineLinkedListNode(); InlineLinkedListNode();
void set_prev(T*); void set_prev(T*);
void set_next(T*); void set_next(T*);
T* prev() const; T* prev() const;
T* next() const; T* next() const;
}; };
template<typename T> inline InlineLinkedListNode<T>::InlineLinkedListNode() template<typename T>
inline InlineLinkedListNode<T>::InlineLinkedListNode()
{ {
set_prev(0); set_prev(0);
set_next(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; 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; 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; 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; return static_cast<const T*>(this)->m_next;
} }
template<typename T> class InlineLinkedList { template<typename T>
class InlineLinkedList {
public: public:
InlineLinkedList() { } InlineLinkedList() {}
bool is_empty() const { return !m_head; } bool is_empty() const { return !m_head; }
size_t size_slow() const; size_t size_slow() const;
void clear(); void clear();
@ -75,7 +82,8 @@ private:
T* m_tail { nullptr }; 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; size_t size = 0;
for (T* node = m_head; node; node = node->next()) 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; return size;
} }
template<typename T> inline void InlineLinkedList<T>::clear() template<typename T>
inline void InlineLinkedList<T>::clear()
{ {
m_head = 0; m_head = 0;
m_tail = 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) { if (!m_head) {
ASSERT(!m_tail); ASSERT(!m_tail);
@ -107,7 +117,8 @@ template<typename T> inline void InlineLinkedList<T>::prepend(T* node)
m_head = 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) { if (!m_tail) {
ASSERT(!m_head); ASSERT(!m_head);
@ -125,7 +136,8 @@ template<typename T> inline void InlineLinkedList<T>::append(T* node)
m_tail = 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()) { if (node->prev()) {
ASSERT(node != m_head); 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(); T* node = head();
if (node) if (node)
@ -152,7 +165,8 @@ template<typename T> inline T* InlineLinkedList<T>::remove_head()
return node; return node;
} }
template<typename T> inline T* InlineLinkedList<T>::remove_tail() template<typename T>
inline T* InlineLinkedList<T>::remove_tail()
{ {
T* node = tail(); T* node = tail();
if (node) if (node)
@ -160,7 +174,8 @@ template<typename T> inline T* InlineLinkedList<T>::remove_tail()
return node; 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()) if (!other.head())
return; return;

View file

@ -1,9 +1,9 @@
#include <AK/MappedFile.h> #include <AK/MappedFile.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h>
//#define DEBUG_MAPPED_FILE //#define DEBUG_MAPPED_FILE
@ -14,7 +14,7 @@ MappedFile::MappedFile(const String& file_name)
{ {
m_size = PAGE_SIZE; m_size = PAGE_SIZE;
m_fd = open(m_file_name.characters(), O_RDONLY | O_CLOEXEC); m_fd = open(m_file_name.characters(), O_RDONLY | O_CLOEXEC);
if (m_fd != -1) { if (m_fd != -1) {
struct stat st; struct stat st;
fstat(m_fd, &st); fstat(m_fd, &st);
@ -44,7 +44,7 @@ void MappedFile::unmap()
ASSERT(rc == 0); ASSERT(rc == 0);
rc = close(m_fd); rc = close(m_fd);
ASSERT(rc == 0); ASSERT(rc == 0);
m_file_name = { }; m_file_name = {};
m_size = 0; m_size = 0;
m_fd = -1; m_fd = -1;
m_map = (void*)-1; m_map = (void*)-1;
@ -74,4 +74,3 @@ MappedFile& MappedFile::operator=(MappedFile&& other)
} }
} }

View file

@ -6,7 +6,7 @@ namespace AK {
class MappedFile { class MappedFile {
public: public:
MappedFile() { } MappedFile() {}
explicit MappedFile(const String& file_name); explicit MappedFile(const String& file_name);
MappedFile(MappedFile&&); MappedFile(MappedFile&&);
~MappedFile(); ~MappedFile();
@ -30,4 +30,3 @@ private:
} }
using AK::MappedFile; using AK::MappedFile;

View file

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

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#define AK_MAKE_NONCOPYABLE(c) \ #define AK_MAKE_NONCOPYABLE(c) \
private: \ private: \
c(const c&) = delete; \ c(const c&) = delete; \
c& operator=(const c&) = delete; c& operator=(const c&) = delete;

View file

@ -1,24 +1,34 @@
#pragma once #pragma once
#include "StdLibExtras.h" #include "StdLibExtras.h"
#include "Types.h"
#include "Traits.h" #include "Traits.h"
#include "Types.h"
namespace AK { namespace AK {
template<typename T> template<typename T>
class OwnPtr { class OwnPtr {
public: public:
OwnPtr() { } OwnPtr() {}
explicit OwnPtr(T* ptr) : m_ptr(ptr) { } explicit OwnPtr(T* ptr)
OwnPtr(OwnPtr&& other) : m_ptr(other.leak_ptr()) { } : m_ptr(ptr)
template<typename U> OwnPtr(OwnPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ptr())) { } {
OwnPtr(std::nullptr_t) { }; }
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() ~OwnPtr()
{ {
clear(); clear();
#ifdef SANITIZE_PTRS #ifdef SANITIZE_PTRS
if constexpr(sizeof(T*) == 8) if constexpr (sizeof(T*) == 8)
m_ptr = (T*)(0xe1e1e1e1e1e1e1e1); m_ptr = (T*)(0xe1e1e1e1e1e1e1e1);
else else
m_ptr = (T*)(0xe1e1e1e1); m_ptr = (T*)(0xe1e1e1e1);
@ -91,7 +101,8 @@ private:
T* m_ptr = nullptr; T* m_ptr = nullptr;
}; };
template<class T, class... Args> inline OwnPtr<T> template<class T, class... Args>
inline OwnPtr<T>
make(Args&&... args) make(Args&&... args)
{ {
return OwnPtr<T>(new T(AK::forward<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::make;
using AK::OwnPtr;

View file

@ -8,7 +8,7 @@ bool is_less_than(const T& a, const T& b)
return a < b; return a < b;
} }
template <typename Iterator, typename LessThan> template<typename Iterator, typename LessThan>
void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than) void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than)
{ {
int size = end - start; int size = end - start;
@ -24,7 +24,7 @@ void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than)
int i = 1; int i = 1;
for (int j = 1; j < size; ++j) { for (int j = 1; j < size; ++j) {
if (less_than(*(start + j), pivot)) { if (less_than(*(start + j), pivot)) {
swap(*(start+j), *(start + i)); swap(*(start + j), *(start + i));
++i; ++i;
} }
} }

View file

@ -1,38 +1,80 @@
#pragma once #pragma once
#include <AK/Types.h>
#include <AK/Retained.h> #include <AK/Retained.h>
#include <AK/Types.h>
namespace AK { namespace AK {
template<typename T> template<typename T>
class RetainPtr { class RetainPtr {
public: public:
enum AdoptTag { Adopt }; enum AdoptTag {
Adopt
};
RetainPtr() { } RetainPtr() {}
RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retain_if_not_null(m_ptr); } RetainPtr(const T* ptr)
RetainPtr(T* ptr) : m_ptr(ptr) { retain_if_not_null(m_ptr); } : m_ptr(const_cast<T*>(ptr))
RetainPtr(T& object) : m_ptr(&object) { m_ptr->retain(); } {
RetainPtr(const T& object) : m_ptr(const_cast<T*>(&object)) { m_ptr->retain(); } retain_if_not_null(m_ptr);
RetainPtr(AdoptTag, T& object) : m_ptr(&object) { } }
RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { } RetainPtr(T* ptr)
RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { } : m_ptr(ptr)
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())) { } retain_if_not_null(m_ptr);
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(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() ~RetainPtr()
{ {
clear(); clear();
#ifdef SANITIZE_PTRS #ifdef SANITIZE_PTRS
if constexpr(sizeof(T*) == 8) if constexpr (sizeof(T*) == 8)
m_ptr = (T*)(0xe0e0e0e0e0e0e0e0); m_ptr = (T*)(0xe0e0e0e0e0e0e0e0);
else else
m_ptr = (T*)(0xe0e0e0e0); m_ptr = (T*)(0xe0e0e0e0);
#endif #endif
} }
RetainPtr(std::nullptr_t) { } RetainPtr(std::nullptr_t) {}
RetainPtr& operator=(RetainPtr&& other) RetainPtr& operator=(RetainPtr&& other)
{ {
@ -143,4 +185,3 @@ private:
} }
using AK::RetainPtr; using AK::RetainPtr;

View file

@ -6,27 +6,27 @@
namespace AK { namespace AK {
template<class T> template<class T>
constexpr auto call_will_be_destroyed_if_present(T* object) -> decltype(object->will_be_destroyed(), TrueType { }) constexpr auto call_will_be_destroyed_if_present(T* object) -> decltype(object->will_be_destroyed(), TrueType {})
{ {
object->will_be_destroyed(); object->will_be_destroyed();
return { }; return {};
} }
constexpr auto call_will_be_destroyed_if_present(...) -> FalseType constexpr auto call_will_be_destroyed_if_present(...) -> FalseType
{ {
return { }; return {};
} }
template<class T> template<class T>
constexpr auto call_one_retain_left_if_present(T* object) -> decltype(object->one_retain_left(), TrueType { }) constexpr auto call_one_retain_left_if_present(T* object) -> decltype(object->one_retain_left(), TrueType {})
{ {
object->one_retain_left(); object->one_retain_left();
return { }; return {};
} }
constexpr auto call_one_retain_left_if_present(...) -> FalseType constexpr auto call_one_retain_left_if_present(...) -> FalseType
{ {
return { }; return {};
} }
class RetainableBase { class RetainableBase {
@ -43,7 +43,7 @@ public:
} }
protected: protected:
RetainableBase() { } RetainableBase() {}
~RetainableBase() ~RetainableBase()
{ {
ASSERT(!m_retain_count); ASSERT(!m_retain_count);
@ -76,4 +76,3 @@ public:
} }
using AK::Retainable; using AK::Retainable;

View file

@ -4,15 +4,15 @@
#include <AK/Types.h> #include <AK/Types.h>
#ifdef __clang__ #ifdef __clang__
#define CONSUMABLE(initial_state) __attribute__((consumable(initial_state))) # define CONSUMABLE(initial_state) __attribute__((consumable(initial_state)))
#define CALLABLE_WHEN(...) __attribute__((callable_when(__VA_ARGS__))) # define CALLABLE_WHEN(...) __attribute__((callable_when(__VA_ARGS__)))
#define SET_TYPESTATE(state) __attribute__((set_typestate(state))) # define SET_TYPESTATE(state) __attribute__((set_typestate(state)))
#define RETURN_TYPESTATE(state) __attribute__((return_typestate(state))) # define RETURN_TYPESTATE(state) __attribute__((return_typestate(state)))
#else #else
#define CONSUMABLE(initial_state) # define CONSUMABLE(initial_state)
#define CALLABLE_WHEN(state) # define CALLABLE_WHEN(state)
#define SET_TYPESTATE(state) # define SET_TYPESTATE(state)
#define RETURN_TYPESTATE(state) # define RETURN_TYPESTATE(state)
#endif #endif
namespace AK { namespace AK {
@ -34,30 +34,75 @@ inline void release_if_not_null(T* ptr)
template<typename T> template<typename T>
class CONSUMABLE(unconsumed) Retained { class CONSUMABLE(unconsumed) Retained {
public: 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)
RETURN_TYPESTATE(unconsumed) Retained(T& object) : m_ptr(&object) { m_ptr->retain(); } Retained(const T& object)
template<typename U> RETURN_TYPESTATE(unconsumed) Retained(U& object) : m_ptr(&static_cast<T&>(object)) { m_ptr->retain(); } : m_ptr(const_cast<T*>(&object))
RETURN_TYPESTATE(unconsumed) Retained(AdoptTag, T& object) : m_ptr(&object) { } {
RETURN_TYPESTATE(unconsumed) Retained(Retained& other) : m_ptr(&other.copy_ref().leak_ref()) { } m_ptr->retain();
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)
RETURN_TYPESTATE(unconsumed) Retained(const Retained& other) : m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref()) { } Retained(T& object)
template<typename U> RETURN_TYPESTATE(unconsumed) Retained(const Retained<U>& other) : m_ptr(&const_cast<Retained<U>&>(other).copy_ref().leak_ref()) { } : 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() ~Retained()
{ {
release_if_not_null(m_ptr); release_if_not_null(m_ptr);
m_ptr = nullptr; m_ptr = nullptr;
#ifdef SANITIZE_PTRS #ifdef SANITIZE_PTRS
if constexpr(sizeof(T*) == 8) if constexpr (sizeof(T*) == 8)
m_ptr = (T*)(0xb0b0b0b0b0b0b0b0); m_ptr = (T*)(0xb0b0b0b0b0b0b0b0);
else else
m_ptr = (T*)(0xb0b0b0b0); m_ptr = (T*)(0xb0b0b0b0);
#endif #endif
} }
CALLABLE_WHEN(unconsumed) Retained& operator=(Retained&& other) CALLABLE_WHEN(unconsumed)
Retained& operator=(Retained&& other)
{ {
if (this != &other) { if (this != &other) {
release_if_not_null(m_ptr); release_if_not_null(m_ptr);
@ -67,7 +112,8 @@ public:
} }
template<typename U> 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)) { if (this != static_cast<void*>(&other)) {
release_if_not_null(m_ptr); release_if_not_null(m_ptr);
@ -76,7 +122,8 @@ public:
return *this; return *this;
} }
CALLABLE_WHEN(unconsumed) Retained& operator=(T& object) CALLABLE_WHEN(unconsumed)
Retained& operator=(T& object)
{ {
if (m_ptr != &object) if (m_ptr != &object)
release_if_not_null(m_ptr); release_if_not_null(m_ptr);
@ -85,12 +132,14 @@ public:
return *this; return *this;
} }
CALLABLE_WHEN(unconsumed) Retained copy_ref() const CALLABLE_WHEN(unconsumed)
Retained copy_ref() const
{ {
return Retained(*m_ptr); return Retained(*m_ptr);
} }
CALLABLE_WHEN(unconsumed) SET_TYPESTATE(consumed) CALLABLE_WHEN(unconsumed)
SET_TYPESTATE(consumed)
T& leak_ref() T& leak_ref()
{ {
ASSERT(m_ptr); ASSERT(m_ptr);
@ -99,20 +148,60 @@ public:
return *leakedPtr; return *leakedPtr;
} }
CALLABLE_WHEN(unconsumed) T* ptr() { ASSERT(m_ptr); return m_ptr; } CALLABLE_WHEN(unconsumed)
CALLABLE_WHEN(unconsumed) const T* ptr() const { ASSERT(m_ptr); return m_ptr; } 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)
CALLABLE_WHEN(unconsumed) const T* operator->() const { ASSERT(m_ptr); return m_ptr; } 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)
CALLABLE_WHEN(unconsumed) const T& operator*() const { ASSERT(m_ptr); return *m_ptr; } 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)
CALLABLE_WHEN(unconsumed) operator const T*() const { ASSERT(m_ptr); return m_ptr; } operator T*()
{
ASSERT(m_ptr);
return m_ptr;
}
CALLABLE_WHEN(unconsumed)
operator const T*() const
{
ASSERT(m_ptr);
return m_ptr;
}
private: private:
Retained() { } Retained() {}
T* m_ptr { nullptr }; T* m_ptr { nullptr };
}; };
@ -125,5 +214,5 @@ inline Retained<T> adopt(T& object)
} }
using AK::Retained;
using AK::adopt; using AK::adopt;
using AK::Retained;

View file

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

View file

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

View file

@ -1,10 +1,10 @@
#pragma once #pragma once
#ifdef KERNEL #ifdef KERNEL
#include <Kernel/StdLib.h> # include <Kernel/StdLib.h>
#else #else
#include <stdlib.h> # include <stdlib.h>
#include <string.h> # include <string.h>
#endif #endif
#define UNUSED_PARAM(x) (void)x #define UNUSED_PARAM(x) (void)x
@ -27,8 +27,7 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
"rep movsl\n" "rep movsl\n"
: "=S"(src), "=D"(dest), "=c"(count) : "=S"(src), "=D"(dest), "=c"(count)
: "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) [[gnu::always_inline]] inline void fast_dword_fill(dword* dest, dword value, size_t count)
@ -37,13 +36,12 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
"rep stosl\n" "rep stosl\n"
: "=D"(dest), "=c"(count) : "=D"(dest), "=c"(count)
: "D"(dest), "c"(count), "a"(value) : "D"(dest), "c"(count), "a"(value)
: "memory" : "memory");
);
} }
inline constexpr dword round_up_to_power_of_two(dword value, dword power_of_two) inline constexpr dword round_up_to_power_of_two(dword value, dword power_of_two)
{ {
return ((value - 1) & ~ (power_of_two - 1)) + power_of_two; return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
} }
namespace AK { namespace AK {
@ -60,7 +58,6 @@ inline T max(const T& a, const T& b)
return a < b ? b : a; return a < b ? b : a;
} }
template<typename T, typename U> template<typename T, typename U>
static inline T ceil_div(T a, U b) static inline T ceil_div(T a, U b)
{ {
@ -72,16 +69,16 @@ static inline T ceil_div(T a, U b)
} }
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic push # pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconsumed" # pragma clang diagnostic ignored "-Wconsumed"
#endif #endif
template <typename T> template<typename T>
T&& move(T& arg) T&& move(T& arg)
{ {
return static_cast<T&&>(arg); return static_cast<T&&>(arg);
} }
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic pop # pragma clang diagnostic pop
#endif #endif
template<typename T> template<typename T>
@ -107,26 +104,37 @@ template<typename T, typename U>
void swap(T& a, U& b) void swap(T& a, U& b)
{ {
U tmp = move((U&)a); U tmp = move((U&)a);
a = (T&&)move(b); a = (T &&) move(b);
b = move(tmp); b = move(tmp);
} }
template<bool B, class T = void> template<bool B, class T = void>
struct EnableIf struct EnableIf {
{
}; };
template<class T> template<class T>
struct EnableIf<true, T> struct EnableIf<true, T> {
{
typedef T Type; typedef T Type;
}; };
template<class T> struct RemoveConst { typedef T Type; }; template<class T>
template<class T> struct RemoveConst<const T> { typedef T Type; }; struct RemoveConst {
template<class T> struct RemoveVolatile { typedef T Type; }; typedef T Type;
template<class T> struct RemoveVolatile<const T> { typedef T Type; }; };
template<class T> struct RemoveCV { 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; typedef typename RemoveVolatile<typename RemoveConst<T>::Type>::Type Type;
}; };
@ -143,69 +151,145 @@ typedef IntegralConstant<bool, false> FalseType;
typedef IntegralConstant<bool, true> TrueType; typedef IntegralConstant<bool, true> TrueType;
template<class T> template<class T>
struct __IsPointerHelper : FalseType { }; struct __IsPointerHelper : FalseType {
};
template<class T> template<class T>
struct __IsPointerHelper<T*> : TrueType { }; struct __IsPointerHelper<T*> : TrueType {
};
template<class T> 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...)> : TrueType { }; 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile> : TrueType { }; struct IsFunction<Ret(Args..., ...)> : 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile> : TrueType { }; 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &> : TrueType { }; 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &> : TrueType { }; struct IsFunction<Ret(Args..., ...)&> : 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &> : TrueType { }; 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &&> : TrueType { }; 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &&> : TrueType { }; struct IsFunction<Ret(Args..., ...) &&> : 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>
template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &&> : TrueType { }; 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>
template<class T> struct IsRvalueReference<T&&> : TrueType { }; struct IsRvalueReference : FalseType {
};
template<class T>
struct IsRvalueReference<T&&> : TrueType {
};
template<class T> struct RemovePointer { typedef T Type; }; template<class T>
template<class T> struct RemovePointer<T*> { typedef T Type; }; struct RemovePointer {
template<class T> struct RemovePointer<T* const> { typedef T Type; }; 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<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> template<typename T, typename U>
struct IsSame { struct IsSame {
enum { value = 0 }; enum {
value = 0
};
}; };
template<typename T> template<typename T>
struct IsSame<T, 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::ceil_div;
using AK::exchange;
using AK::forward;
using AK::IsSame; using AK::IsSame;
using AK::max;
using AK::min;
using AK::move;
using AK::swap;

View file

@ -38,7 +38,7 @@ String String::empty()
String String::isolated_copy() const String String::isolated_copy() const
{ {
if (!m_impl) if (!m_impl)
return { }; return {};
if (!m_impl->length()) if (!m_impl->length())
return empty(); return empty();
char* buffer; char* buffer;
@ -50,7 +50,7 @@ String String::isolated_copy() const
String String::substring(int start, int length) const String String::substring(int start, int length) const
{ {
if (!length) if (!length)
return { }; return {};
ASSERT(m_impl); ASSERT(m_impl);
ASSERT(start + length <= m_impl->length()); ASSERT(start + length <= m_impl->length());
// FIXME: This needs some input bounds checking. // FIXME: This needs some input bounds checking.
@ -60,7 +60,7 @@ String String::substring(int start, int length) const
StringView String::substring_view(int start, int length) const StringView String::substring_view(int start, int length) const
{ {
if (!length) if (!length)
return { }; return {};
ASSERT(m_impl); ASSERT(m_impl);
ASSERT(start + length <= m_impl->length()); ASSERT(start + length <= m_impl->length());
// FIXME: This needs some input bounds checking. // FIXME: This needs some input bounds checking.
@ -70,7 +70,7 @@ StringView String::substring_view(int start, int length) const
Vector<String> String::split(const char separator) const Vector<String> String::split(const char separator) const
{ {
if (is_empty()) if (is_empty())
return { }; return {};
Vector<String> v; Vector<String> v;
ssize_t substart = 0; ssize_t substart = 0;
@ -94,7 +94,7 @@ Vector<String> String::split(const char separator) const
Vector<StringView> String::split_view(const char separator) const Vector<StringView> String::split_view(const char separator) const
{ {
if (is_empty()) if (is_empty())
return { }; return {};
Vector<StringView> v; Vector<StringView> v;
ssize_t substart = 0; ssize_t substart = 0;
@ -232,7 +232,7 @@ bool String::match_helper(const String& mask) const
if (!*++mask_ptr) if (!*++mask_ptr)
return true; return true;
mp = mask_ptr; mp = mask_ptr;
cp = string_ptr+1; cp = string_ptr + 1;
} else if ((*mask_ptr == *string_ptr) || (*mask_ptr == '?')) { } else if ((*mask_ptr == *string_ptr) || (*mask_ptr == '?')) {
mask_ptr++; mask_ptr++;
string_ptr++; string_ptr++;

View file

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

View file

@ -9,7 +9,7 @@ namespace AK {
class StringBuilder { class StringBuilder {
public: public:
explicit StringBuilder(ssize_t initial_capacity = 16); explicit StringBuilder(ssize_t initial_capacity = 16);
~StringBuilder() { } ~StringBuilder() {}
void append(const String&); void append(const String&);
void append(char); void append(char);
@ -30,4 +30,3 @@ private:
} }
using AK::StringBuilder; using AK::StringBuilder;

View file

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

View file

@ -1,12 +1,15 @@
#pragma once #pragma once
#include "Retainable.h"
#include "RetainPtr.h" #include "RetainPtr.h"
#include "Retainable.h"
#include "Types.h" #include "Types.h"
namespace AK { namespace AK {
enum ShouldChomp { NoChomp, Chomp }; enum ShouldChomp {
NoChomp,
Chomp
};
class StringImpl : public Retainable<StringImpl> { class StringImpl : public Retainable<StringImpl> {
public: public:
@ -22,7 +25,11 @@ public:
ssize_t length() const { return m_length; } ssize_t length() const { return m_length; }
const char* characters() const { return m_characters; } 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 unsigned hash() const
{ {
@ -32,10 +39,17 @@ public:
} }
private: private:
enum ConstructTheEmptyStringImplTag { ConstructTheEmptyStringImpl }; enum ConstructTheEmptyStringImplTag {
explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { } ConstructTheEmptyStringImpl
};
explicit StringImpl(ConstructTheEmptyStringImplTag)
: m_characters("")
{
}
enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer }; enum ConstructWithInlineBufferTag {
ConstructWithInlineBuffer
};
StringImpl(ConstructWithInlineBufferTag, ssize_t length); StringImpl(ConstructWithInlineBufferTag, ssize_t length);
void compute_hash() const; 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::Chomp;
using AK::string_hash; using AK::string_hash;
using AK::StringImpl;

View file

@ -1,12 +1,12 @@
#include <AK/StringView.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/StringView.h>
namespace AK { namespace AK {
Vector<StringView> StringView::split_view(const char separator) const Vector<StringView> StringView::split_view(const char separator) const
{ {
if (is_empty()) if (is_empty())
return { }; return {};
Vector<StringView> v; Vector<StringView> v;
ssize_t substart = 0; ssize_t substart = 0;
@ -30,7 +30,7 @@ Vector<StringView> StringView::split_view(const char separator) const
StringView StringView::substring_view(int start, int length) const StringView StringView::substring_view(int start, int length) const
{ {
if (!length) if (!length)
return { }; return {};
ASSERT(start + length <= m_length); ASSERT(start + length <= m_length);
return { m_characters + start, length }; return { m_characters + start, length };
} }
@ -50,5 +50,4 @@ unsigned StringView::to_uint(bool& ok) const
return value; return value;
} }
} }

View file

@ -8,9 +8,17 @@ class String;
class StringView { class StringView {
public: public:
StringView() { } StringView() {}
StringView(const char* characters, int length) : m_characters(characters), m_length(length) { } StringView(const char* characters, int length)
StringView(const unsigned char* characters, int length) : m_characters((const char*)characters), m_length(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) StringView(const char* cstring)
: m_characters(cstring) : m_characters(cstring)
{ {

View file

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

View file

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

View file

@ -30,8 +30,8 @@ typedef signed_dword int32_t;
typedef signed_qword int64_t; typedef signed_qword int64_t;
#else #else
#include <stdint.h> # include <stdint.h>
#include <sys/types.h> # include <sys/types.h>
typedef uint8_t byte; typedef uint8_t byte;
typedef uint16_t word; typedef uint16_t word;
@ -48,9 +48,11 @@ constexpr unsigned KB = 1024;
constexpr unsigned MB = KB * KB; constexpr unsigned MB = KB * KB;
constexpr unsigned GB = KB * KB * KB; constexpr unsigned GB = KB * KB * KB;
enum class IterationDecision { Continue, Abort }; enum class IterationDecision {
Continue,
Abort
};
namespace std { namespace std {
typedef decltype(nullptr) nullptr_t; typedef decltype(nullptr) nullptr_t;
} }

View file

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

View file

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

View file

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

View file

@ -1,25 +1,26 @@
#pragma once #pragma once
#ifdef KERNEL #ifdef KERNEL
#define AK_MAKE_ETERNAL \ # define AK_MAKE_ETERNAL \
public: \ public: \
void* operator new(size_t size) { return kmalloc_eternal(size); } \ void* operator new(size_t size) { return kmalloc_eternal(size); } \
private: \
private:
#else #else
#define AK_MAKE_ETERNAL # define AK_MAKE_ETERNAL
#endif #endif
#ifdef KERNEL #ifdef KERNEL
#include <Kernel/kmalloc.h> # include <Kernel/kmalloc.h>
#else #else
#include <stdlib.h> # include <stdlib.h>
#define kcalloc calloc # define kcalloc calloc
#define kmalloc malloc # define kmalloc malloc
#define kfree free # define kfree free
#define krealloc realloc # define krealloc realloc
#ifdef __serenity__ # ifdef __serenity__
inline void* operator new(size_t size) inline void* operator new(size_t size)
{ {
return kmalloc(size); return kmalloc(size);
@ -44,6 +45,6 @@ inline void* operator new(size_t, void* ptr)
{ {
return ptr; return ptr;
} }
#endif # endif
#endif #endif

View file

@ -169,7 +169,6 @@ template<typename PutChFunc>
return fieldWidth; return fieldWidth;
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth) [[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
{ {
@ -183,7 +182,7 @@ template<typename PutChFunc>
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap) [[gnu::always_inline]] inline int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
{ {
const char *p; const char* p;
int ret = 0; int ret = 0;
char* bufptr = buffer; char* bufptr = buffer;
@ -195,7 +194,7 @@ template<typename PutChFunc>
unsigned long_qualifiers = 0; unsigned long_qualifiers = 0;
bool alternate_form = 0; bool alternate_form = 0;
if (*p == '%' && *(p + 1)) { if (*p == '%' && *(p + 1)) {
one_more: one_more:
++p; ++p;
if (*p == ' ') { if (*p == ' ') {
leftPad = true; leftPad = true;
@ -223,87 +222,81 @@ one_more:
if (*(p + 1)) if (*(p + 1))
goto one_more; goto one_more;
} }
switch( *p ) switch (*p) {
{ case 's': {
case 's': const char* sp = va_arg(ap, const char*);
{ ret += print_string(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
const char* sp = va_arg(ap, const char*); } break;
ret += print_string(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
}
break;
case 'd': case 'd':
ret += print_signed_number(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth); ret += print_signed_number(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth);
break; break;
case 'u': case 'u':
ret += print_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth); ret += print_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
break; break;
case 'Q': case 'Q':
ret += print_qword(putch, bufptr, va_arg(ap, qword), leftPad, zeroPad, fieldWidth); ret += print_qword(putch, bufptr, va_arg(ap, qword), leftPad, zeroPad, fieldWidth);
break; break;
case 'q': case 'q':
ret += print_hex(putch, bufptr, va_arg(ap, qword), 16); ret += print_hex(putch, bufptr, va_arg(ap, qword), 16);
break; break;
#ifndef KERNEL #ifndef KERNEL
case 'f': case 'f':
// FIXME: Print as float! // FIXME: Print as float!
ret += print_number(putch, bufptr, (int)va_arg(ap, double), leftPad, zeroPad, fieldWidth); ret += print_number(putch, bufptr, (int)va_arg(ap, double), leftPad, zeroPad, fieldWidth);
break; break;
#endif #endif
case 'o': case 'o':
if (alternate_form) { if (alternate_form) {
putch(bufptr, '0'); putch(bufptr, '0');
++ret;
}
ret += print_octal_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
break;
case 'x':
if (alternate_form) {
putch(bufptr, '0');
putch(bufptr, 'x');
ret += 2;
}
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
break;
case 'w':
ret += print_hex(putch, bufptr, va_arg(ap, int), 4);
break;
case 'b':
ret += print_hex(putch, bufptr, va_arg(ap, int), 2);
break;
case 'c':
putch(bufptr, (char)va_arg(ap, int));
++ret; ++ret;
break; }
ret += print_octal_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
break;
case '%': case 'x':
putch(bufptr, '%'); if (alternate_form) {
++ret;
break;
case 'p':
putch(bufptr, '0'); putch(bufptr, '0');
putch(bufptr, 'x'); putch(bufptr, 'x');
ret += 2; ret += 2;
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8); }
break; ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
break;
case 'w':
ret += print_hex(putch, bufptr, va_arg(ap, int), 4);
break;
case 'b':
ret += print_hex(putch, bufptr, va_arg(ap, int), 2);
break;
case 'c':
putch(bufptr, (char)va_arg(ap, int));
++ret;
break;
case '%':
putch(bufptr, '%');
++ret;
break;
case 'p':
putch(bufptr, '0');
putch(bufptr, 'x');
ret += 2;
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
break;
} }
} } else {
else {
putch(bufptr, *p); putch(bufptr, *p);
++ret; ++ret;
} }
} }
return ret; return ret;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,13 +1,13 @@
#pragma once #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 "IRCLogBuffer.h"
#include "IRCWindow.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 IRCChannel;
class IRCQuery; class IRCQuery;
@ -17,6 +17,7 @@ class CNotifier;
class IRCClient final : public CObject { class IRCClient final : public CObject {
friend class IRCChannel; friend class IRCChannel;
friend class IRCQuery; friend class IRCQuery;
public: public:
IRCClient(); IRCClient();
virtual ~IRCClient() override; virtual ~IRCClient() override;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <LibGUI/GFrame.h>
#include <LibCore/CTimer.h>
#include <AK/Noncopyable.h> #include <AK/Noncopyable.h>
#include <LibCore/CTimer.h>
#include <LibGUI/GFrame.h>
class Field; class Field;
class GButton; class GButton;
@ -13,7 +13,7 @@ class SquareLabel;
class Square { class Square {
AK_MAKE_NONCOPYABLE(Square) AK_MAKE_NONCOPYABLE(Square)
public: public:
Square() { } Square() {}
~Square(); ~Square();
Field* field { nullptr }; Field* field { nullptr };
@ -27,12 +27,14 @@ public:
SquareButton* button { nullptr }; SquareButton* button { nullptr };
SquareLabel* label { 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 { class Field final : public GFrame {
friend class Square; friend class Square;
friend class SquareLabel; friend class SquareLabel;
public: public:
Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent); Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent);
virtual ~Field() override; virtual ~Field() override;
@ -66,9 +68,15 @@ private:
void flood_fill(Square&); 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); void set_face(Face);
int m_rows { 9 }; int m_rows { 9 };

View file

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

View file

@ -2,8 +2,8 @@
class Alarm { class Alarm {
public: public:
Alarm() { } Alarm() {}
virtual ~Alarm() { } virtual ~Alarm() {}
virtual bool is_ringing() const = 0; virtual bool is_ringing() const = 0;
}; };

View file

@ -1,17 +1,24 @@
#pragma once #pragma once
#include <Kernel/kstdio.h>
#include <Kernel/i386.h> #include <Kernel/i386.h>
#include <Kernel/kstdio.h>
#ifdef DEBUG #ifdef DEBUG
[[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func); [[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
#define ASSERT(expr) (static_cast<bool>(expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) # define ASSERT(expr) (static_cast<bool>(expr) ? (void)0 : __assertion_failed(# expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#define ASSERT_NOT_REACHED() ASSERT(false) # define ASSERT_NOT_REACHED() ASSERT(false)
#else #else
#define ASSERT(expr) # define ASSERT(expr)
#define ASSERT_NOT_REACHED() CRASH() # define ASSERT_NOT_REACHED() CRASH()
#endif #endif
#define CRASH() do { asm volatile("ud2"); } while(0) #define CRASH() \
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0) 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_DISABLED() ASSERT(!(cpu_flags() & 0x200))
#define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpu_flags() & 0x200) #define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpu_flags() & 0x200)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,4 +18,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; } virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "RandomDevice"; } 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 bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "ZeroDevice"; } virtual const char* class_name() const override { return "ZeroDevice"; }
}; };

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,7 +8,7 @@ struct InodeMetadata;
class InodeIdentifier { class InodeIdentifier {
public: public:
InodeIdentifier() { } InodeIdentifier() {}
InodeIdentifier(dword fsid, dword inode) InodeIdentifier(dword fsid, dword inode)
: m_fsid(fsid) : m_fsid(fsid)
, m_index(inode) , m_index(inode)
@ -39,4 +39,3 @@ private:
dword m_fsid { 0 }; dword m_fsid { 0 };
dword m_index { 0 }; dword m_index { 0 };
}; };

View file

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

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <Kernel/Lock.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/Lock.h>
class Process; class Process;
@ -11,6 +11,7 @@ class ProcFSInode;
class ProcFS final : public FS { class ProcFS final : public FS {
friend class ProcFSInode; friend class ProcFSInode;
public: public:
[[gnu::pure]] static ProcFS& the(); [[gnu::pure]] static ProcFS& the();
@ -34,7 +35,7 @@ private:
ProcFS(); ProcFS();
struct ProcFSDirectoryEntry { struct ProcFSDirectoryEntry {
ProcFSDirectoryEntry() { } ProcFSDirectoryEntry() {}
ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<ByteBuffer(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RetainPtr<ProcFSInode>&& a_inode = nullptr) ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<ByteBuffer(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RetainPtr<ProcFSInode>&& a_inode = nullptr)
: name(a_name) : name(a_name)
, proc_file_type(a_proc_file_type) , proc_file_type(a_proc_file_type)
@ -69,6 +70,7 @@ struct ProcFSInodeCustomData {
class ProcFSInode final : public Inode { class ProcFSInode final : public Inode {
friend class ProcFS; friend class ProcFS;
public: public:
virtual ~ProcFSInode() override; virtual ~ProcFSInode() override;

View file

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

View file

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

File diff suppressed because it is too large Load diff

View file

@ -3,140 +3,141 @@
* everything we need. (cross fingers) Other header files may have * everything we need. (cross fingers) Other header files may have
* also defined the types that we need. * also defined the types that we need.
*/ */
#if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && \ #if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && !defined(_EXT2_TYPES_H))
!defined(_EXT2_TYPES_H)) # define _EXT2_TYPES_H
#define _EXT2_TYPES_H
#define __S8_TYPEDEF __signed__ char # define __S8_TYPEDEF __signed__ char
#define __U8_TYPEDEF unsigned char # define __U8_TYPEDEF unsigned char
#define __S16_TYPEDEF __signed__ short # define __S16_TYPEDEF __signed__ short
#define __U16_TYPEDEF unsigned short # define __U16_TYPEDEF unsigned short
#define __S32_TYPEDEF __signed__ int # define __S32_TYPEDEF __signed__ int
#define __U32_TYPEDEF unsigned int # define __U32_TYPEDEF unsigned int
#define __S64_TYPEDEF __signed__ long long # define __S64_TYPEDEF __signed__ long long
#define __U64_TYPEDEF unsigned long long # define __U64_TYPEDEF unsigned long long
#ifdef __U8_TYPEDEF # ifdef __U8_TYPEDEF
typedef __U8_TYPEDEF __u8; typedef __U8_TYPEDEF __u8;
#else # else
typedef unsigned char __u8; typedef unsigned char __u8;
#endif # endif
#ifdef __S8_TYPEDEF # ifdef __S8_TYPEDEF
typedef __S8_TYPEDEF __s8; typedef __S8_TYPEDEF __s8;
#else # else
typedef signed char __s8; typedef signed char __s8;
#endif # endif
#ifdef __U16_TYPEDEF # ifdef __U16_TYPEDEF
typedef __U16_TYPEDEF __u16; typedef __U16_TYPEDEF __u16;
#else # else
#if (4 == 2) # if (4 == 2)
typedef unsigned int __u16; typedef unsigned int __u16;
#else # else
#if (2 == 2) # if (2 == 2)
typedef unsigned short __u16; typedef unsigned short __u16;
#else # else
?==error: undefined 16 bit type ? == error : undefined 16 bit type
#endif /* SIZEOF_SHORT == 2 */ # endif /* SIZEOF_SHORT == 2 */
#endif /* SIZEOF_INT == 2 */ # endif /* SIZEOF_INT == 2 */
#endif /* __U16_TYPEDEF */ # endif /* __U16_TYPEDEF */
#ifdef __S16_TYPEDEF # ifdef __S16_TYPEDEF
typedef __S16_TYPEDEF __s16; typedef __S16_TYPEDEF __s16;
#else # else
#if (4 == 2) # if (4 == 2)
typedef int __s16; typedef int __s16;
#else # else
#if (2 == 2) # if (2 == 2)
typedef short __s16; typedef short __s16;
#else # else
?==error: undefined 16 bit type ? == error
#endif /* SIZEOF_SHORT == 2 */ : undefined 16 bit type
#endif /* SIZEOF_INT == 2 */ # endif /* SIZEOF_SHORT == 2 */
#endif /* __S16_TYPEDEF */ # endif /* SIZEOF_INT == 2 */
# endif /* __S16_TYPEDEF */
# ifdef __U32_TYPEDEF
#ifdef __U32_TYPEDEF
typedef __U32_TYPEDEF __u32; typedef __U32_TYPEDEF __u32;
#else # else
#if (4 == 4) # if (4 == 4)
typedef unsigned int __u32; typedef unsigned int __u32;
#else # else
#if (4 == 4) # if (4 == 4)
typedef unsigned long __u32; typedef unsigned long __u32;
#else # else
#if (2 == 4) # if (2 == 4)
typedef unsigned short __u32; typedef unsigned short __u32;
#else # else
?== error: undefined 32 bit type ? == error
#endif /* SIZEOF_SHORT == 4 */ : undefined 32 bit type
#endif /* SIZEOF_LONG == 4 */ # endif /* SIZEOF_SHORT == 4 */
#endif /* SIZEOF_INT == 4 */ # endif /* SIZEOF_LONG == 4 */
#endif /* __U32_TYPEDEF */ # endif /* SIZEOF_INT == 4 */
# endif /* __U32_TYPEDEF */
#ifdef __S32_TYPEDEF # ifdef __S32_TYPEDEF
typedef __S32_TYPEDEF __s32; typedef __S32_TYPEDEF __s32;
#else # else
#if (4 == 4) # if (4 == 4)
typedef int __s32; typedef int __s32;
#else # else
#if (4 == 4) # if (4 == 4)
typedef long __s32; typedef long __s32;
#else # else
#if (2 == 4) # if (2 == 4)
typedef short __s32; typedef short __s32;
#else # else
?== error: undefined 32 bit type ? == error
#endif /* SIZEOF_SHORT == 4 */ : undefined 32 bit type
#endif /* SIZEOF_LONG == 4 */ # endif /* SIZEOF_SHORT == 4 */
#endif /* SIZEOF_INT == 4 */ # endif /* SIZEOF_LONG == 4 */
#endif /* __S32_TYPEDEF */ # endif /* SIZEOF_INT == 4 */
# endif /* __S32_TYPEDEF */
#ifdef __U64_TYPEDEF # ifdef __U64_TYPEDEF
typedef __U64_TYPEDEF __u64; typedef __U64_TYPEDEF __u64;
#else # else
#if (4 == 8) # if (4 == 8)
typedef unsigned int __u64; typedef unsigned int __u64;
#else # else
#if (4 == 8) # if (4 == 8)
typedef unsigned long __u64; typedef unsigned long __u64;
#else # else
#if (8 == 8) # if (8 == 8)
typedef unsigned long long __u64; typedef unsigned long long __u64;
#endif /* SIZEOF_LONG_LONG == 8 */ # endif /* SIZEOF_LONG_LONG == 8 */
#endif /* SIZEOF_LONG == 8 */ # endif /* SIZEOF_LONG == 8 */
#endif /* SIZEOF_INT == 8 */ # endif /* SIZEOF_INT == 8 */
#endif /* __U64_TYPEDEF */ # endif /* __U64_TYPEDEF */
#ifdef __S64_TYPEDEF # ifdef __S64_TYPEDEF
typedef __S64_TYPEDEF __s64; typedef __S64_TYPEDEF __s64;
#else # else
#if (4 == 8) # if (4 == 8)
typedef int __s64; typedef int __s64;
#else # else
#if (4 == 8) # if (4 == 8)
typedef long __s64; typedef long __s64;
#else # else
#if (8 == 8) # if (8 == 8)
#if defined(__GNUC__) # if defined(__GNUC__)
typedef __signed__ long long __s64; typedef __signed__ long long __s64;
#else # else
typedef signed long long __s64; typedef signed long long __s64;
#endif /* __GNUC__ */ # endif /* __GNUC__ */
#endif /* SIZEOF_LONG_LONG == 8 */ # endif /* SIZEOF_LONG_LONG == 8 */
#endif /* SIZEOF_LONG == 8 */ # endif /* SIZEOF_LONG == 8 */
#endif /* SIZEOF_INT == 8 */ # endif /* SIZEOF_INT == 8 */
#endif /* __S64_TYPEDEF */ # endif /* __S64_TYPEDEF */
#undef __S8_TYPEDEF # undef __S8_TYPEDEF
#undef __U8_TYPEDEF # undef __U8_TYPEDEF
#undef __S16_TYPEDEF # undef __S16_TYPEDEF
#undef __U16_TYPEDEF # undef __U16_TYPEDEF
#undef __S32_TYPEDEF # undef __S32_TYPEDEF
#undef __U32_TYPEDEF # undef __U32_TYPEDEF
#undef __S64_TYPEDEF # undef __S64_TYPEDEF
#undef __U64_TYPEDEF # undef __U64_TYPEDEF
#endif /* _*_TYPES_H */ #endif /* _*_TYPES_H */

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