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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -31,13 +31,14 @@
namespace AK {
template<typename> class Function;
template<typename>
class Function;
template <typename Out, typename... In>
template<typename Out, typename... In>
class Function<Out(In...)> {
public:
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>
Function(CallableType&& callable)
@ -82,7 +83,7 @@ public:
private:
class CallableWrapperBase {
public:
virtual ~CallableWrapperBase() { }
virtual ~CallableWrapperBase() {}
virtual Out call(In...) const = 0;
};
@ -109,4 +110,3 @@ private:
}
using AK::Function;

View file

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

View file

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

View file

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

View file

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

View file

@ -1,9 +1,9 @@
#include <AK/MappedFile.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
//#define DEBUG_MAPPED_FILE
@ -44,7 +44,7 @@ void MappedFile::unmap()
ASSERT(rc == 0);
rc = close(m_fd);
ASSERT(rc == 0);
m_file_name = { };
m_file_name = {};
m_size = 0;
m_fd = -1;
m_map = (void*)-1;
@ -74,4 +74,3 @@ MappedFile& MappedFile::operator=(MappedFile&& other)
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,27 +6,27 @@
namespace AK {
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();
return { };
return {};
}
constexpr auto call_will_be_destroyed_if_present(...) -> FalseType
{
return { };
return {};
}
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();
return { };
return {};
}
constexpr auto call_one_retain_left_if_present(...) -> FalseType
{
return { };
return {};
}
class RetainableBase {
@ -43,7 +43,7 @@ public:
}
protected:
RetainableBase() { }
RetainableBase() {}
~RetainableBase()
{
ASSERT(!m_retain_count);
@ -76,4 +76,3 @@ public:
}
using AK::Retainable;

View file

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

View file

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

View file

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

View file

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

View file

@ -38,7 +38,7 @@ String String::empty()
String String::isolated_copy() const
{
if (!m_impl)
return { };
return {};
if (!m_impl->length())
return empty();
char* buffer;
@ -50,7 +50,7 @@ String String::isolated_copy() const
String String::substring(int start, int length) const
{
if (!length)
return { };
return {};
ASSERT(m_impl);
ASSERT(start + length <= m_impl->length());
// 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
{
if (!length)
return { };
return {};
ASSERT(m_impl);
ASSERT(start + length <= m_impl->length());
// 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
{
if (is_empty())
return { };
return {};
Vector<String> v;
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
{
if (is_empty())
return { };
return {};
Vector<StringView> v;
ssize_t substart = 0;
@ -232,7 +232,7 @@ bool String::match_helper(const String& mask) const
if (!*++mask_ptr)
return true;
mp = mask_ptr;
cp = string_ptr+1;
cp = string_ptr + 1;
} else if ((*mask_ptr == *string_ptr) || (*mask_ptr == '?')) {
mask_ptr++;
string_ptr++;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -60,12 +60,12 @@
#define EXT2_SUPER_MAGIC 0xEF53
#ifdef __KERNEL__
#define EXT2_SB(sb) (&((sb)->u.ext2_sb))
# define EXT2_SB(sb) (&((sb)->u.ext2_sb))
#else
/* Assume that user mode programs are passing in an ext2fs superblock, not
* a kernel struct super_block. This will allow us to call the feature-test
* macros from user land. */
#define EXT2_SB(sb) (sb)
# define EXT2_SB(sb) (sb)
#endif
/*
@ -81,18 +81,16 @@
#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
#ifdef __KERNEL__
#define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
#define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->addr_per_block_bits)
#define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
#define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
# define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
# define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->addr_per_block_bits)
# define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
# define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
#else
#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
# define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
# define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
#endif
#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32))
@ -135,8 +133,7 @@ struct ext2_acl_entry /* Access Control List Entry */
/*
* Structure of a blocks group descriptor
*/
struct ext2_group_desc
{
struct ext2_group_desc {
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
@ -149,8 +146,7 @@ struct ext2_group_desc
__u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
};
struct ext4_group_desc
{
struct ext4_group_desc {
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
@ -164,8 +160,8 @@ struct ext4_group_desc
__u32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
__u32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
__u32 bg_inode_table_hi; /* Inodes table block MSB */
__u16 bg_free_blocks_count_hi;/* Free blocks count MSB */
__u16 bg_free_inodes_count_hi;/* Free inodes count MSB */
__u16 bg_free_blocks_count_hi; /* Free blocks count MSB */
__u16 bg_free_inodes_count_hi; /* Free inodes count MSB */
__u16 bg_used_dirs_count_hi; /* Directories count MSB */
__u16 bg_pad;
__u32 bg_reserved2[3];
@ -214,7 +210,6 @@ struct ext2_dx_countlimit {
__u16 count;
};
/*
* Macro-instructions used to manage group descriptors
*/
@ -222,20 +217,19 @@ struct ext2_dx_countlimit {
#define EXT2_MIN_DESC_SIZE_64BIT 64
#define EXT2_MAX_DESC_SIZE EXT2_MIN_BLOCK_SIZE
#define EXT2_DESC_SIZE(s) \
((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \
(s)->s_desc_size : EXT2_MIN_DESC_SIZE)
((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_INODE_SIZE(s))
/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */
#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8)
#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s))
#ifdef __KERNEL__
#define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
#define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
# define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
# define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
#else
#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_DESC_SIZE(s))
# define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_DESC_SIZE(s))
#endif
/*
@ -304,7 +298,7 @@ struct ext4_new_group_input {
};
#ifdef __GNU__ /* Needed for the Hurd */
#define _IOT_ext2_new_group_input _IOT (_IOTS(__u32), 5, _IOTS(__u16), 2, 0, 0)
# define _IOT_ext2_new_group_input _IOT(_IOTS(__u32), 5, _IOTS(__u16), 2, 0, 0)
#endif
#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
@ -314,8 +308,8 @@ struct ext4_new_group_input {
#define EXT2_IOC_GETVERSION_NEW _IOR('f', 3, long)
#define EXT2_IOC_SETVERSION_NEW _IOW('f', 4, long)
#define EXT2_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
#define EXT2_IOC_GROUP_ADD _IOW('f', 8,struct ext2_new_group_input)
#define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input)
#define EXT2_IOC_GROUP_ADD _IOW('f', 8, struct ext2_new_group_input)
#define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input)
/*
* Structure of an inode on the disk
@ -340,7 +334,7 @@ struct ext2_inode {
__u32 h_i_translator;
} hurd1;
} osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
__u32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */
__u32 i_generation; /* File version (for NFS) */
__u32 i_file_acl; /* File ACL */
__u32 i_dir_acl; /* Directory ACL */
@ -387,7 +381,7 @@ struct ext2_inode_large {
__u32 h_i_translator;
} hurd1;
} osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
__u32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */
__u32 i_generation; /* File version (for NFS) */
__u32 i_file_acl; /* File ACL */
__u32 i_dir_acl; /* Directory ACL */
@ -422,31 +416,31 @@ struct ext2_inode_large {
#define i_size_high i_dir_acl
#if defined(__KERNEL__) || defined(__linux__)
#define i_reserved1 osd1.linux1.l_i_reserved1
#define i_frag osd2.linux2.l_i_frag
#define i_fsize osd2.linux2.l_i_fsize
#define i_uid_low i_uid
#define i_gid_low i_gid
#define i_uid_high osd2.linux2.l_i_uid_high
#define i_gid_high osd2.linux2.l_i_gid_high
#define i_reserved2 osd2.linux2.l_i_reserved2
# define i_reserved1 osd1.linux1.l_i_reserved1
# define i_frag osd2.linux2.l_i_frag
# define i_fsize osd2.linux2.l_i_fsize
# define i_uid_low i_uid
# define i_gid_low i_gid
# define i_uid_high osd2.linux2.l_i_uid_high
# define i_gid_high osd2.linux2.l_i_gid_high
# define i_reserved2 osd2.linux2.l_i_reserved2
#else
#if defined(__GNU__)
# if defined(__GNU__)
#define i_translator osd1.hurd1.h_i_translator
#define i_frag osd2.hurd2.h_i_frag;
#define i_fsize osd2.hurd2.h_i_fsize;
#define i_uid_high osd2.hurd2.h_i_uid_high
#define i_gid_high osd2.hurd2.h_i_gid_high
#define i_author osd2.hurd2.h_i_author
# define i_translator osd1.hurd1.h_i_translator
# define i_frag osd2.hurd2.h_i_frag;
# define i_fsize osd2.hurd2.h_i_fsize;
# define i_uid_high osd2.hurd2.h_i_uid_high
# define i_gid_high osd2.hurd2.h_i_gid_high
# define i_author osd2.hurd2.h_i_author
#endif /* __GNU__ */
# endif /* __GNU__ */
#endif /* defined(__KERNEL__) || defined(__linux__) */
#define inode_uid(inode) ((inode).i_uid | (inode).osd2.linux2.l_i_uid_high << 16)
#define inode_gid(inode) ((inode).i_gid | (inode).osd2.linux2.l_i_gid_high << 16)
#define ext2fs_set_i_uid_high(inode,x) ((inode).osd2.linux2.l_i_uid_high = (x))
#define ext2fs_set_i_gid_high(inode,x) ((inode).osd2.linux2.l_i_gid_high = (x))
#define ext2fs_set_i_uid_high(inode, x) ((inode).osd2.linux2.l_i_uid_high = (x))
#define ext2fs_set_i_gid_high(inode, x) ((inode).osd2.linux2.l_i_gid_high = (x))
/*
* File system states
@ -476,8 +470,7 @@ struct ext2_inode_large {
#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
EXT2_MOUNT_##opt)
#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_##opt)
/*
* Maximal mount counts between two filesystem checks
*/
@ -611,12 +604,12 @@ struct ext2_super_block {
* Feature set definitions
*/
#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
( EXT2_SB(sb)->s_feature_compat & (mask) )
#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
( EXT2_SB(sb)->s_feature_incompat & (mask) )
#define EXT2_HAS_COMPAT_FEATURE(sb, mask) \
(EXT2_SB(sb)->s_feature_compat & (mask))
#define EXT2_HAS_RO_COMPAT_FEATURE(sb, mask) \
(EXT2_SB(sb)->s_feature_ro_compat & (mask))
#define EXT2_HAS_INCOMPAT_FEATURE(sb, mask) \
(EXT2_SB(sb)->s_feature_incompat & (mask))
#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
@ -644,13 +637,9 @@ struct ext2_super_block {
#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
#define EXT2_FEATURE_COMPAT_SUPP 0
#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE)
#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \
EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER | EXT2_FEATURE_RO_COMPAT_LARGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK | EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
/*
* Default values for user and/or group using reserved blocks
@ -719,8 +708,7 @@ struct ext2_dir_entry_2 {
*/
#define EXT2_DIR_PAD 4
#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
~EXT2_DIR_ROUND)
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & ~EXT2_DIR_ROUND)
/*
* This structure will be used for multiple mount protection. It will be

View file

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

View file

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

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