AK: Add a forward declaration header

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.
This commit is contained in:
Andreas Kling 2020-02-14 21:41:10 +01:00
parent 8249e666fc
commit 3bbf4610d2
Notes: sideshowbarker 2024-07-19 09:20:25 +09:00
35 changed files with 178 additions and 53 deletions

View file

@ -27,6 +27,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h>
namespace AK { namespace AK {

109
AK/Forward.h Normal file
View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* 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;

View file

@ -26,10 +26,11 @@
#pragma once #pragma once
#include <AK/String.h>
#include <AK/LogStream.h> #include <AK/LogStream.h>
#include <AK/NetworkOrdered.h> #include <AK/NetworkOrdered.h>
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Vector.h>
typedef u32 in_addr_t; typedef u32 in_addr_t;

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/Forward.h>
#include <AK/IPv4Address.h> #include <AK/IPv4Address.h>
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/String.h> #include <AK/String.h>
@ -33,10 +34,6 @@
namespace AK { namespace AK {
class JsonArray;
class JsonObject;
class StringBuilder;
class JsonValue { class JsonValue {
public: public:
enum class Type { enum class Type {

View file

@ -112,4 +112,10 @@ DebugLogStream dbg()
return stream; return stream;
} }
DebugLogStream::~DebugLogStream()
{
char newline = '\n';
write(&newline, 1);
}
} }

View file

@ -62,11 +62,7 @@ private:
class DebugLogStream final : public LogStream { class DebugLogStream final : public LogStream {
public: public:
DebugLogStream() {} DebugLogStream() {}
virtual ~DebugLogStream() override virtual ~DebugLogStream() override;
{
char newline = '\n';
write(&newline, 1);
}
virtual void write(const char* characters, int length) const override virtual void write(const char* characters, int length) const override
{ {

View file

@ -27,10 +27,10 @@
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <stdarg.h> #include <AK/Vector.h>
#ifndef KERNEL #ifndef KERNEL
#include <inttypes.h> # include <inttypes.h>
#endif #endif
#ifdef KERNEL #ifdef KERNEL

View file

@ -26,12 +26,11 @@
#pragma once #pragma once
#include <AK/ByteBuffer.h> #include <AK/Forward.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/StringImpl.h> #include <AK/StringImpl.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Traits.h> #include <AK/Traits.h>
#include <AK/Vector.h>
namespace AK { namespace AK {

View file

@ -27,7 +27,7 @@
#include <AK/PrintfImplementation.h> #include <AK/PrintfImplementation.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <stdarg.h> #include <AK/String.h>
namespace AK { namespace AK {
@ -96,6 +96,11 @@ String StringBuilder::to_string()
return String((const char*)m_buffer.data(), m_length); return String((const char*)m_buffer.data(), m_length);
} }
String StringBuilder::build()
{
return to_string();
}
StringView StringBuilder::string_view() const StringView StringBuilder::string_view() const
{ {
return StringView { (const char*)m_buffer.data(), m_length }; return StringView { (const char*)m_buffer.data(), m_length };

View file

@ -26,8 +26,8 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/ByteBuffer.h>
#include <AK/Vector.h> #include <AK/Forward.h>
#include <stdarg.h> #include <stdarg.h>
namespace AK { namespace AK {
@ -45,8 +45,7 @@ public:
void appendf(const char*, ...); void appendf(const char*, ...);
void appendvf(const char*, va_list); void appendvf(const char*, va_list);
String build() { return to_string(); } String build();
String to_string(); String to_string();
ByteBuffer to_byte_buffer(); ByteBuffer to_byte_buffer();

View file

@ -24,8 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/ByteBuffer.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Vector.h>
namespace AK { namespace AK {

View file

@ -26,14 +26,11 @@
#pragma once #pragma once
#include <AK/Vector.h> #include <AK/Forward.h>
#include <AK/StdLibExtras.h>
namespace AK { namespace AK {
class ByteBuffer;
class String;
class StringImpl;
class StringView { class StringView {
public: public:
StringView() {} StringView() {}

View file

@ -24,8 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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/LogStream.h>
#include <AK/Utf8View.h>
namespace AK { namespace AK {

View file

@ -27,6 +27,7 @@
#pragma once #pragma once
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/Forward.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/Traits.h> #include <AK/Traits.h>
#include <AK/kmalloc.h> #include <AK/kmalloc.h>
@ -44,9 +45,6 @@
namespace AK { namespace AK {
template<typename T, int inline_capacity>
class Vector;
template<typename VectorType, typename ElementType> template<typename VectorType, typename ElementType>
class VectorIterator { class VectorIterator {
public: public:
@ -132,7 +130,7 @@ public:
} }
}; };
template<typename T, int inline_capacity = 0> template<typename T, int inline_capacity>
class Vector { class Vector {
public: public:
Vector() Vector()

View file

@ -26,13 +26,14 @@
#pragma once #pragma once
#include <AK/ByteBuffer.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/NonnullOwnPtrVector.h> #include <AK/NonnullOwnPtrVector.h>
#include <AK/NonnullRefPtrVector.h> #include <AK/NonnullRefPtrVector.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <LibGfx/TextAlignment.h>
#include <LibGUI/ScrollableWidget.h> #include <LibGUI/ScrollableWidget.h>
#include <LibGfx/TextAlignment.h>
class HexEditor : public GUI::ScrollableWidget { class HexEditor : public GUI::ScrollableWidget {
C_OBJECT(HexEditor) C_OBJECT(HexEditor)

View file

@ -25,6 +25,7 @@
*/ */
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h>
#include <grp.h> #include <grp.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -25,6 +25,7 @@
*/ */
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -27,6 +27,7 @@
// Has to be defined before including due to legacy Unices // Has to be defined before including due to legacy Unices
#define SYSLOG_NAMES 1 #define SYSLOG_NAMES 1
#include <AK/String.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View file

@ -26,14 +26,14 @@
#pragma once #pragma once
#include <LibELF/ELFDynamicObject.h> #include <AK/Assertions.h>
#include <LibELF/ELFImage.h>
#include <LibELF/exec_elf.h>
#include <mman.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/String.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))) #define ALIGN_ROUND_UP(x, align) ((((size_t)(x)) + align - 1) & (~(align - 1)))

View file

@ -24,12 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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/ELFDynamicObject.h>
#include <LibELF/exec_elf.h> #include <LibELF/exec_elf.h>
#include <AK/StringBuilder.h>
#include <assert.h>
#include <stdio.h> #include <stdio.h>
static const char* name_for_dtag(Elf32_Sword d_tag); static const char* name_for_dtag(Elf32_Sword d_tag);

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/Assertions.h>
#include <LibBareMetal/Memory/VirtualAddress.h> #include <LibBareMetal/Memory/VirtualAddress.h>
#include <LibELF/exec_elf.h> #include <LibELF/exec_elf.h>

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Assertions.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/ProgressBar.h> #include <LibGUI/ProgressBar.h>

View file

@ -24,12 +24,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <LibGfx/CharacterBitmap.h> #include <AK/Assertions.h>
#include <LibGfx/Bitmap.h> #include <AK/StdLibExtras.h>
#include <LibGfx/Palette.h>
#include <LibGfx/StylePainter.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/ScrollBar.h> #include <LibGUI/ScrollBar.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/CharacterBitmap.h>
#include <LibGfx/Palette.h>
#include <LibGfx/StylePainter.h>
namespace GUI { namespace GUI {

View file

@ -25,6 +25,7 @@
*/ */
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibGUI/Shortcut.h> #include <LibGUI/Shortcut.h>
namespace GUI { namespace GUI {

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/ByteBuffer.h>
#include <AK/FileSystemPath.h> #include <AK/FileSystemPath.h>
#include <AK/MappedFile.h> #include <AK/MappedFile.h>
#include <AK/NetworkOrdered.h> #include <AK/NetworkOrdered.h>

View file

@ -26,12 +26,13 @@
#pragma once #pragma once
#include "Color.h"
#include "Point.h"
#include "Rect.h"
#include "Size.h"
#include <AK/String.h> #include <AK/String.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <AK/Vector.h>
#include <LibGfx/Color.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Size.h>
#include <LibGfx/TextAlignment.h> #include <LibGfx/TextAlignment.h>
#include <LibGfx/TextElision.h> #include <LibGfx/TextElision.h>

View file

@ -24,8 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Rect.h"
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/Vector.h>
#include <LibGfx/Rect.h>
namespace Gfx { namespace Gfx {

View file

@ -27,6 +27,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h>
#include <LibHTML/CSS/StyleValue.h> #include <LibHTML/CSS/StyleValue.h>
struct StyleProperty { struct StyleProperty {

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/ByteBuffer.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
#include <LibGfx/PNGLoader.h> #include <LibGfx/PNGLoader.h>
#include <LibHTML/CSS/StyleValue.h> #include <LibHTML/CSS/StyleValue.h>

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/ByteBuffer.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
#include <LibHTML/DOM/HTMLElement.h> #include <LibHTML/DOM/HTMLElement.h>

View file

@ -26,7 +26,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/Vector.h>
namespace IPC { namespace IPC {

View file

@ -26,7 +26,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/Vector.h>
class MDBlock { class MDBlock {
public: public:

View file

@ -27,9 +27,8 @@
#pragma once #pragma once
#include "DNSQuestion.h" #include "DNSQuestion.h"
#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/Vector.h>
#define T_A 1 #define T_A 1
#define T_NS 2 #define T_NS 2

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/ByteBuffer.h>
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/URL.h> #include <AK/URL.h>
#include <AK/WeakPtr.h> #include <AK/WeakPtr.h>

View file

@ -25,6 +25,7 @@
*/ */
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h>
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
@ -69,7 +70,7 @@ int main(int argc, char** argv)
if (!ok) { if (!ok) {
new_gid = getgrnam(parts[1].characters())->gr_gid; new_gid = getgrnam(parts[1].characters())->gr_gid;
if(!new_gid) { if (!new_gid) {
fprintf(stderr, "Invalid gid: '%s'\n", parts[1].characters()); fprintf(stderr, "Invalid gid: '%s'\n", parts[1].characters());
return 1; return 1;
} }