Skip to content

Commit

Permalink
AK: Add a forward declaration header
Browse files Browse the repository at this point in the history
You can now #include <AK/Forward.h> to get most of the AK types as
forward declarations.

Header dependency explosion is one of the main contributors to compile
times at the moment, so this is a step towards smaller include graphs.
  • Loading branch information
awesomekling committed Feb 14, 2020
1 parent 8249e66 commit 3bbf461
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 52 deletions.
1 change: 1 addition & 0 deletions AK/FileSystemPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#pragma once

#include <AK/String.h>
#include <AK/Vector.h>

namespace AK {

Expand Down
109 changes: 109 additions & 0 deletions AK/Forward.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2020, Andreas Kling <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

namespace AK {

class Bitmap;
class ByteBuffer;
class IPv4Address;
class JsonArray;
class JsonObject;
class JsonValue;
class String;
class StringBuilder;
class StringImpl;
class StringView;
class URL;

template<typename T>
class SinglyLinkedList;

template<typename T>
class DoublyLinkedList;

template<typename T>
class InlineLinkedList;

template<typename T, int capacity>
class CircularQueue;

template<typename T>
class Badge;

template<typename T>
class FixedArray;

template<typename>
class Function;

template<typename Out, typename... In>
class Function<Out(In...)>;

template<typename T>
class NonnullRefPtr;

template<typename T>
class NonnullOwnPtr;

template<typename T>
class RefPtr;

template<typename T>
class OwnPtr;

template<typename T>
class WeakPtr;

template<typename T, int inline_capacity = 0>
class Vector;

}

using AK::Badge;
using AK::Bitmap;
using AK::ByteBuffer;
using AK::CircularQueue;
using AK::DoublyLinkedList;
using AK::FixedArray;
using AK::Function;
using AK::InlineLinkedList;
using AK::IPv4Address;
using AK::JsonArray;
using AK::JsonObject;
using AK::JsonValue;
using AK::NonnullOwnPtr;
using AK::NonnullRefPtr;
using AK::OwnPtr;
using AK::RefPtr;
using AK::SinglyLinkedList;
using AK::String;
using AK::StringBuilder;
using AK::StringImpl;
using AK::StringView;
using AK::URL;
using AK::Vector;
3 changes: 2 additions & 1 deletion AK/IPv4Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

#pragma once

#include <AK/String.h>
#include <AK/LogStream.h>
#include <AK/NetworkOrdered.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Vector.h>

typedef u32 in_addr_t;

Expand Down
5 changes: 1 addition & 4 deletions AK/JsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@

#pragma once

#include <AK/Forward.h>
#include <AK/IPv4Address.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>

namespace AK {

class JsonArray;
class JsonObject;
class StringBuilder;

class JsonValue {
public:
enum class Type {
Expand Down
6 changes: 6 additions & 0 deletions AK/LogStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ DebugLogStream dbg()
return stream;
}

DebugLogStream::~DebugLogStream()
{
char newline = '\n';
write(&newline, 1);
}

}
6 changes: 1 addition & 5 deletions AK/LogStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ class LogStream {
class DebugLogStream final : public LogStream {
public:
DebugLogStream() {}
virtual ~DebugLogStream() override
{
char newline = '\n';
write(&newline, 1);
}
virtual ~DebugLogStream() override;

virtual void write(const char* characters, int length) const override
{
Expand Down
4 changes: 2 additions & 2 deletions AK/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <stdarg.h>
#include <AK/Vector.h>

#ifndef KERNEL
#include <inttypes.h>
# include <inttypes.h>
#endif

#ifdef KERNEL
Expand Down
3 changes: 1 addition & 2 deletions AK/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

#pragma once

#include <AK/ByteBuffer.h>
#include <AK/Forward.h>
#include <AK/RefPtr.h>
#include <AK/StringImpl.h>
#include <AK/StringView.h>
#include <AK/Traits.h>
#include <AK/Vector.h>

namespace AK {

Expand Down
7 changes: 6 additions & 1 deletion AK/StringBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <AK/PrintfImplementation.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
#include <stdarg.h>
#include <AK/String.h>

namespace AK {

Expand Down Expand Up @@ -96,6 +96,11 @@ String StringBuilder::to_string()
return String((const char*)m_buffer.data(), m_length);
}

String StringBuilder::build()
{
return to_string();
}

StringView StringBuilder::string_view() const
{
return StringView { (const char*)m_buffer.data(), m_length };
Expand Down
7 changes: 3 additions & 4 deletions AK/StringBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#pragma once

#include <AK/String.h>
#include <AK/Vector.h>
#include <AK/ByteBuffer.h>
#include <AK/Forward.h>
#include <stdarg.h>

namespace AK {
Expand All @@ -45,8 +45,7 @@ class StringBuilder {
void appendf(const char*, ...);
void appendvf(const char*, va_list);

String build() { return to_string(); }

String build();
String to_string();
ByteBuffer to_byte_buffer();

Expand Down
2 changes: 2 additions & 0 deletions AK/StringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>

namespace AK {

Expand Down
7 changes: 2 additions & 5 deletions AK/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@

#pragma once

#include <AK/Vector.h>
#include <AK/Forward.h>
#include <AK/StdLibExtras.h>

namespace AK {

class ByteBuffer;
class String;
class StringImpl;

class StringView {
public:
StringView() {}
Expand Down
3 changes: 2 additions & 1 deletion AK/Utf8View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <AK/Utf8View.h>
#include <AK/Assertions.h>
#include <AK/LogStream.h>
#include <AK/Utf8View.h>

namespace AK {

Expand Down
6 changes: 2 additions & 4 deletions AK/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#pragma once

#include <AK/Assertions.h>
#include <AK/Forward.h>
#include <AK/StdLibExtras.h>
#include <AK/Traits.h>
#include <AK/kmalloc.h>
Expand All @@ -44,9 +45,6 @@

namespace AK {

template<typename T, int inline_capacity>
class Vector;

template<typename VectorType, typename ElementType>
class VectorIterator {
public:
Expand Down Expand Up @@ -132,7 +130,7 @@ class TypedTransfer {
}
};

template<typename T, int inline_capacity = 0>
template<typename T, int inline_capacity>
class Vector {
public:
Vector()
Expand Down
3 changes: 2 additions & 1 deletion Applications/HexEditor/HexEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

#pragma once

#include <AK/ByteBuffer.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/StdLibExtras.h>
#include <LibGfx/TextAlignment.h>
#include <LibGUI/ScrollableWidget.h>
#include <LibGfx/TextAlignment.h>

class HexEditor : public GUI::ScrollableWidget {
C_OBJECT(HexEditor)
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibC/grp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include <AK/String.h>
#include <AK/Vector.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibC/pwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include <AK/String.h>
#include <AK/Vector.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibC/syslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// Has to be defined before including due to legacy Unices
#define SYSLOG_NAMES 1

#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <stdio.h>
#include <string.h>
Expand Down
10 changes: 5 additions & 5 deletions Libraries/LibELF/ELFDynamicLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

#pragma once

#include <LibELF/ELFDynamicObject.h>
#include <LibELF/ELFImage.h>
#include <LibELF/exec_elf.h>
#include <mman.h>

#include <AK/Assertions.h>
#include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <LibELF/ELFDynamicObject.h>
#include <LibELF/ELFImage.h>
#include <LibELF/exec_elf.h>
#include <sys/mman.h>

#define ALIGN_ROUND_UP(x, align) ((((size_t)(x)) + align - 1) & (~(align - 1)))

Expand Down
6 changes: 2 additions & 4 deletions Libraries/LibELF/ELFDynamicObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibELF/ELFDynamicObject.h>
#include <LibELF/exec_elf.h>

#include <AK/StringBuilder.h>

#include <assert.h>
#include <stdio.h>

static const char* name_for_dtag(Elf32_Sword d_tag);
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibELF/ELFDynamicObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#pragma once

#include <AK/Assertions.h>
#include <LibBareMetal/Memory/VirtualAddress.h>
#include <LibELF/exec_elf.h>

Expand Down
1 change: 1 addition & 0 deletions Libraries/LibGUI/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <AK/Assertions.h>
#include <AK/StringBuilder.h>
#include <LibGUI/Painter.h>
#include <LibGUI/ProgressBar.h>
Expand Down
Loading

0 comments on commit 3bbf461

Please sign in to comment.