Skip to content

Commit

Permalink
Add clang-format file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rburchell authored and awesomekling committed May 28, 2019
1 parent c11351a commit 0dc9af5
Show file tree
Hide file tree
Showing 286 changed files with 3,242 additions and 2,422 deletions.
13 changes: 13 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
14 changes: 9 additions & 5 deletions AK/AKString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -96,7 +96,11 @@ class String {
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;

Expand Down Expand Up @@ -131,7 +135,7 @@ class String {
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);
Expand Down
13 changes: 6 additions & 7 deletions AK/Assertions.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,4 +17,3 @@ inline void not_implemented() { ASSERT(false); }
}

using AK::not_implemented;

2 changes: 1 addition & 1 deletion AK/Badge.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
template<typename T>
class Badge {
friend T;
Badge() { }
Badge() {}
};
3 changes: 1 addition & 2 deletions AK/Bitmap.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "Assertions.h"
#include "StdLibExtras.h"
#include "Types.h"
#include "kmalloc.h"
#include "Assertions.h"

namespace AK {

Expand Down Expand Up @@ -77,4 +77,3 @@ class Bitmap {
}

using AK::Bitmap;

52 changes: 36 additions & 16 deletions AK/ByteBuffer.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -28,8 +28,16 @@ class ByteBufferImpl : public Retainable<ByteBufferImpl> {
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; }

Expand All @@ -52,11 +60,16 @@ class ByteBufferImpl : public Retainable<ByteBufferImpl> {
void grow(int size);

private:
enum ConstructionMode { Uninitialized, Copy, Wrap, Adopt };
explicit ByteBufferImpl(int); // For ConstructionMode=Uninitialized
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(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
ByteBufferImpl() {}

byte* m_data { nullptr };
int m_size { 0 };
Expand All @@ -65,8 +78,8 @@ class ByteBufferImpl : public Retainable<ByteBufferImpl> {

class ByteBuffer {
public:
ByteBuffer() { }
ByteBuffer(std::nullptr_t) { }
ByteBuffer() {}
ByteBuffer(std::nullptr_t) {}
ByteBuffer(const ByteBuffer& other)
: m_impl(other.m_impl.copy_ref())
{
Expand Down Expand Up @@ -101,8 +114,16 @@ class ByteBuffer {
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; }

Expand All @@ -121,7 +142,7 @@ class ByteBuffer {
ByteBuffer isolated_copy() const
{
if (!m_impl)
return { };
return {};
return copy(m_impl->pointer(), m_impl->size());
}

Expand All @@ -135,9 +156,9 @@ class ByteBuffer {
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);
Expand Down Expand Up @@ -241,4 +262,3 @@ inline Retained<ByteBufferImpl> ByteBufferImpl::adopt(void* data, int size)
}

using AK::ByteBuffer;

8 changes: 6 additions & 2 deletions AK/CircularQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ class CircularQueue {
}

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 };
};
Expand All @@ -82,4 +87,3 @@ class CircularQueue {
}

using AK::CircularQueue;

64 changes: 50 additions & 14 deletions AK/DoublyLinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,15 +39,30 @@ class DoublyLinkedList {
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)
Expand All @@ -62,14 +83,22 @@ class DoublyLinkedList {
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;
};

Expand All @@ -80,14 +109,22 @@ class DoublyLinkedList {
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;
};

Expand Down Expand Up @@ -163,4 +200,3 @@ class DoublyLinkedList {
}

using AK::DoublyLinkedList;

4 changes: 2 additions & 2 deletions AK/FileSystemPath.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "FileSystemPath.h"
#include "StringBuilder.h"
#include "Vector.h"
#include "kstdio.h"
#include "StringBuilder.h"

namespace AK {

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion AK/FileSystemPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AK {

class FileSystemPath {
public:
FileSystemPath() { }
FileSystemPath() {}
explicit FileSystemPath(const String&);

bool is_valid() const { return m_is_valid; }
Expand Down
Loading

0 comments on commit 0dc9af5

Please sign in to comment.