Ver código fonte

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.
Andreas Kling 5 anos atrás
pai
commit
3bbf4610d2

+ 1 - 0
AK/FileSystemPath.h

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

+ 109 - 0
AK/Forward.h

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

+ 2 - 1
AK/IPv4Address.h

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

+ 1 - 4
AK/JsonValue.h

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

+ 6 - 0
AK/LogStream.cpp

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

+ 1 - 5
AK/LogStream.h

@@ -62,11 +62,7 @@ private:
 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
     {

+ 2 - 2
AK/String.cpp

@@ -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

+ 1 - 2
AK/String.h

@@ -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 {
 

+ 6 - 1
AK/StringBuilder.cpp

@@ -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 {
 
@@ -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 };

+ 3 - 4
AK/StringBuilder.h

@@ -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 {
@@ -45,8 +45,7 @@ public:
     void appendf(const char*, ...);
     void appendvf(const char*, va_list);
 
-    String build() { return to_string(); }
-
+    String build();
     String to_string();
     ByteBuffer to_byte_buffer();
 

+ 2 - 0
AK/StringView.cpp

@@ -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 {
 

+ 2 - 5
AK/StringView.h

@@ -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() {}

+ 2 - 1
AK/Utf8View.cpp

@@ -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 {
 

+ 2 - 4
AK/Vector.h

@@ -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>
@@ -44,9 +45,6 @@
 
 namespace AK {
 
-template<typename T, int inline_capacity>
-class Vector;
-
 template<typename VectorType, typename ElementType>
 class VectorIterator {
 public:
@@ -132,7 +130,7 @@ public:
     }
 };
 
-template<typename T, int inline_capacity = 0>
+template<typename T, int inline_capacity>
 class Vector {
 public:
     Vector()

+ 2 - 1
Applications/HexEditor/HexEditor.h

@@ -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)

+ 1 - 0
Libraries/LibC/grp.cpp

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

+ 1 - 0
Libraries/LibC/pwd.cpp

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

+ 1 - 0
Libraries/LibC/syslog.cpp

@@ -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>

+ 5 - 5
Libraries/LibELF/ELFDynamicLoader.h

@@ -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)))
 

+ 2 - 4
Libraries/LibELF/ELFDynamicObject.cpp

@@ -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);

+ 1 - 0
Libraries/LibELF/ELFDynamicObject.h

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

+ 1 - 0
Libraries/LibGUI/ProgressBar.cpp

@@ -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>

+ 5 - 3
Libraries/LibGUI/ScrollBar.cpp

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

+ 1 - 0
Libraries/LibGUI/Shortcut.cpp

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

+ 1 - 0
Libraries/LibGfx/PNGLoader.cpp

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

+ 5 - 4
Libraries/LibGfx/Painter.h

@@ -26,12 +26,13 @@
 
 #pragma once
 
-#include "Color.h"
-#include "Point.h"
-#include "Rect.h"
-#include "Size.h"
 #include <AK/String.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/TextElision.h>
 

+ 2 - 1
Libraries/LibGfx/Rect.cpp

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

+ 1 - 0
Libraries/LibHTML/CSS/StyleDeclaration.h

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

+ 1 - 0
Libraries/LibHTML/CSS/StyleValue.cpp

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

+ 1 - 0
Libraries/LibHTML/DOM/HTMLImageElement.h

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

+ 1 - 1
Libraries/LibIPC/Message.h

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

+ 1 - 1
Libraries/LibMarkdown/MDBlock.h

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

+ 1 - 2
Servers/LookupServer/DNSRequest.h

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

+ 1 - 0
Servers/ProtocolServer/Download.h

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

+ 2 - 1
Userland/chown.cpp

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