AK: Make it possible to not using AK classes into the global namespace

This patch adds the `USING_AK_GLOBALLY` macro which is enabled by
default, but can be overridden by build flags.

This is a step towards integrating Jakt and AK types.
This commit is contained in:
Andreas Kling 2022-11-26 12:18:30 +01:00
parent e50a43652e
commit ae3ffdd521
124 changed files with 276 additions and 12 deletions

View file

@ -32,4 +32,6 @@ template<IterableContainer Container>
}
#if USING_AK_GLOBALLY
using AK::all_of;
#endif

View file

@ -29,4 +29,6 @@ template<IterableContainer Container>
}
#if USING_AK_GLOBALLY
using AK::any_of;
#endif

View file

@ -123,4 +123,6 @@ struct ArbitrarySizedEnum : public T {
}
#if USING_AK_GLOBALLY
using AK::ArbitrarySizedEnum;
#endif

View file

@ -111,5 +111,7 @@ constexpr static auto iota_array(T const offset = {})
}
#if USING_AK_GLOBALLY
using AK::Array;
using AK::iota_array;
#endif

View file

@ -442,5 +442,7 @@ public:
};
}
#if USING_AK_GLOBALLY
using AK::Atomic;
using AK::full_memory_barrier;
#endif

View file

@ -83,5 +83,7 @@ public:
}
#if USING_AK_GLOBALLY
using AK::AtomicRefCounted;
using AK::AtomicRefCountedBase;
#endif

View file

@ -6,6 +6,8 @@
#pragma once
#include <AK/Platform.h>
namespace AK {
template<typename T>
@ -26,4 +28,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Badge;
#endif

View file

@ -22,5 +22,7 @@ namespace AK {
[[nodiscard]] String encode_base64(ReadonlyBytes);
}
#if USING_AK_GLOBALLY
using AK::decode_base64;
using AK::encode_base64;
#endif

View file

@ -108,4 +108,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::BinaryHeap;
#endif

View file

@ -67,4 +67,6 @@ constexpr auto binary_search(
}
#if USING_AK_GLOBALLY
using AK::binary_search;
#endif

View file

@ -6,6 +6,8 @@
#pragma once
#include <AK/Platform.h>
namespace AK {
template<typename T, typename U>
@ -24,4 +26,6 @@ template<typename T, typename U>
}
#if USING_AK_GLOBALLY
using AK::bit_cast;
#endif

View file

@ -239,5 +239,7 @@ private:
}
#if USING_AK_GLOBALLY
using AK::InputBitStream;
using AK::OutputBitStream;
#endif

View file

@ -191,4 +191,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Bitmap;
#endif

View file

@ -369,4 +369,6 @@ protected:
}
#if USING_AK_GLOBALLY
using AK::BitmapView;
#endif

View file

@ -194,4 +194,6 @@ private:
};
}
#if USING_AK_GLOBALLY
using AK::Buffered;
#endif

View file

@ -197,5 +197,7 @@ inline Atomic<FlatPtr> BumpAllocator<use_mmap, size>::s_unused_allocation_cache
}
#if USING_AK_GLOBALLY
using AK::BumpAllocator;
using AK::UniformBumpAllocator;
#endif

View file

@ -55,4 +55,6 @@ struct ByteReader {
}
#if USING_AK_GLOBALLY
using AK::ByteReader;
#endif

View file

@ -172,6 +172,7 @@ constexpr u32 to_ascii_base36_digit(u32 digit)
}
#if USING_AK_GLOBALLY
using AK::is_ascii;
using AK::is_ascii_alpha;
using AK::is_ascii_alphanumeric;
@ -199,3 +200,4 @@ using AK::parse_ascii_hex_digit;
using AK::to_ascii_base36_digit;
using AK::to_ascii_lowercase;
using AK::to_ascii_uppercase;
#endif

View file

@ -452,5 +452,7 @@ constexpr Checked<T> make_checked(T value)
}
#if USING_AK_GLOBALLY
using AK::Checked;
using AK::make_checked;
#endif

View file

@ -41,4 +41,6 @@ public:
}
#if USING_AK_GLOBALLY
using AK::CircularDeque;
#endif

View file

@ -120,4 +120,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::CircularDuplexStream;
#endif

View file

@ -133,4 +133,6 @@ protected:
}
#if USING_AK_GLOBALLY
using AK::CircularQueue;
#endif

View file

@ -281,10 +281,12 @@ static constexpr Complex<T> cexp(Complex<T> const& a)
}
}
# if USING_AK_GLOBALLY
using AK::approx_eq;
using AK::cexp;
using AK::Complex;
using AK::complex_imag_unit;
using AK::complex_real_unit;
# endif
#endif

View file

@ -121,6 +121,7 @@ concept FallibleFunction = requires(Func&& func, Args&&... args) {
// clang-format on
}
#if USING_AK_GLOBALLY
using AK::Concepts::Arithmetic;
using AK::Concepts::ArrayLike;
using AK::Concepts::Enum;
@ -138,3 +139,4 @@ using AK::Concepts::Signed;
using AK::Concepts::SpecializationOf;
using AK::Concepts::Unsigned;
using AK::Concepts::VoidFunction;
#endif

View file

@ -39,9 +39,11 @@ static constexpr Array<StringView, 12> short_month_names = {
}
#if USING_AK_GLOBALLY
using AK::long_day_names;
using AK::long_month_names;
using AK::micro_day_names;
using AK::mini_day_names;
using AK::short_day_names;
using AK::short_month_names;
#endif

View file

@ -143,4 +143,6 @@ public:
}
#if USING_AK_GLOBALLY
using AK::DateTimeLexer;
#endif

View file

@ -26,6 +26,8 @@ inline String demangle(StringView name)
}
# if USING_AK_GLOBALLY
using AK::demangle;
# endif
#endif

View file

@ -436,5 +436,7 @@ private:
}
#if USING_AK_GLOBALLY
using AK::DisjointChunks;
using AK::DisjointSpans;
#endif

View file

@ -344,4 +344,6 @@ struct Traits<AK::DistinctNumeric<T, X, Opts...>> : public GenericTraits<AK::Dis
static constexpr auto hash(DistinctNumeric<T, X, Opts...> const& d) { return Traits<T>::hash(d.value()); }
};
#if USING_AK_GLOBALLY
using AK::DistinctNumeric;
#endif

View file

@ -201,4 +201,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::DoublyLinkedList;
#endif

View file

@ -145,6 +145,8 @@ requires(HasFormatter<T>) struct Formatter<BigEndian<T>> : Formatter<T> {
}
#if USING_AK_GLOBALLY
using AK::BigEndian;
using AK::LittleEndian;
using AK::NetworkOrdered;
#endif

View file

@ -125,5 +125,7 @@ public:
}
#if USING_AK_GLOBALLY
using AK::Error;
using AK::ErrorOr;
#endif

View file

@ -168,7 +168,9 @@ private:
}
# if USING_AK_GLOBALLY
using AK::InputFileStream;
using AK::OutputFileStream;
# endif
#endif

View file

@ -181,4 +181,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::FixedArray;
#endif

View file

@ -389,4 +389,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::FixedPoint;
#endif

View file

@ -232,6 +232,7 @@ constexpr float convert_to_native_float(I input) { return float_to_float<SingleF
}
#if USING_AK_GLOBALLY
using AK::DoubleFloatingPointBits;
using AK::FloatExtractor;
using AK::FloatingPointBits;
@ -242,3 +243,4 @@ using AK::convert_from_native_float;
using AK::convert_to_native_double;
using AK::convert_to_native_float;
using AK::float_to_float;
#endif

View file

@ -80,6 +80,8 @@ FloatingPointParseResults<T> parse_first_hexfloat_until_zero_character(char cons
}
#if USING_AK_GLOBALLY
using AK::parse_first_floating_point;
using AK::parse_first_hexfloat_until_zero_character;
using AK::parse_floating_point_completely;
#endif

View file

@ -101,4 +101,6 @@ struct Traits<FlyString> : public GenericTraits<FlyString> {
}
#if USING_AK_GLOBALLY
using AK::FlyString;
#endif

View file

@ -698,16 +698,17 @@ struct Formatter<ErrorOr<T, ErrorType>> : Formatter<FormatString> {
} // namespace AK
#ifdef KERNEL
#if USING_AK_GLOBALLY
# ifdef KERNEL
using AK::critical_dmesgln;
using AK::dmesgln;
#else
# else
using AK::out;
using AK::outln;
using AK::warn;
using AK::warnln;
#endif
# endif
using AK::dbgln;
@ -715,8 +716,10 @@ using AK::CheckedFormatString;
using AK::FormatIfSupported;
using AK::FormatString;
#define dbgln_if(flag, fmt, ...) \
do { \
if constexpr (flag) \
dbgln(fmt, ##__VA_ARGS__); \
} while (0)
# define dbgln_if(flag, fmt, ...) \
do { \
if constexpr (flag) \
dbgln(fmt, ##__VA_ARGS__); \
} while (0)
#endif

View file

@ -146,6 +146,7 @@ class [[nodiscard]] ErrorOr;
}
#if USING_AK_GLOBALLY
using AK::Array;
using AK::Atomic;
using AK::Badge;
@ -199,9 +200,11 @@ using AK::Utf8CodePointIterator;
using AK::Utf8View;
using AK::Vector;
#ifdef KERNEL
# ifdef KERNEL
using AK::LockRefPtr;
using AK::LockRefPtrTraits;
using AK::NonnullLockRefPtr;
using AK::NonnullLockRefPtrVector;
# endif
#endif

View file

@ -265,4 +265,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Function;
#endif

View file

@ -19,5 +19,7 @@ FuzzyMatchResult fuzzy_match(StringView needle, StringView haystack);
}
#if USING_AK_GLOBALLY
using AK::fuzzy_match;
using AK::FuzzyMatchResult;
#endif

View file

@ -239,7 +239,9 @@ constexpr auto is_quote = is_any_of("'\""sv);
}
#if USING_AK_GLOBALLY
using AK::GenericLexer;
using AK::is_any_of;
using AK::is_path_separator;
using AK::is_quote;
#endif

View file

@ -6,6 +6,8 @@
#pragma once
#include <AK/Platform.h>
namespace AK {
template<typename T, typename... Ts>
@ -63,6 +65,7 @@ template<typename T, typename... Ts>
}
}
#if USING_AK_GLOBALLY
using AK::first_is_larger_or_equal_than_all_of;
using AK::first_is_larger_or_equal_than_one_of;
using AK::first_is_larger_than_all_of;
@ -72,3 +75,4 @@ using AK::first_is_smaller_or_equal_than_all_of;
using AK::first_is_smaller_or_equal_than_one_of;
using AK::first_is_smaller_than_all_of;
using AK::first_is_smaller_than_one_of;
#endif

View file

@ -243,5 +243,7 @@ private:
}
#if USING_AK_GLOBALLY
using AK::HashMap;
using AK::OrderedHashMap;
#endif

View file

@ -724,5 +724,8 @@ private:
};
}
#if USING_AK_GLOBALLY
using AK::HashSetResult;
using AK::HashTable;
using AK::OrderedHashTable;
#endif

View file

@ -39,6 +39,8 @@ String encode_hex(ReadonlyBytes);
}
#if USING_AK_GLOBALLY
using AK::decode_hex;
using AK::decode_hex_digit;
using AK::encode_hex;
#endif

View file

@ -43,4 +43,6 @@ private:
};
}
#if USING_AK_GLOBALLY
using AK::IDAllocator;
#endif

View file

@ -176,4 +176,6 @@ struct Formatter<IPv4Address> : Formatter<String> {
}
#if USING_AK_GLOBALLY
using AK::IPv4Address;
#endif

View file

@ -299,4 +299,6 @@ struct Formatter<IPv6Address> : Formatter<String> {
}
#if USING_AK_GLOBALLY
using AK::IPv6Address;
#endif

View file

@ -461,5 +461,7 @@ using IntrusiveList = Detail::IntrusiveList<
}
#if USING_AK_GLOBALLY
using AK::IntrusiveList;
using AK::IntrusiveListNode;
#endif

View file

@ -35,4 +35,6 @@ using IntrusiveListRelaxedConst = Detail::IntrusiveListRelaxedConst<
}
#if USING_AK_GLOBALLY
using AK::IntrusiveListRelaxedConst;
#endif

View file

@ -235,5 +235,7 @@ using IntrusiveRedBlackTree = Detail::IntrusiveRedBlackTree<
}
#if USING_AK_GLOBALLY
using AK::IntrusiveRedBlackTree;
using AK::IntrusiveRedBlackTreeNode;
#endif

View file

@ -6,6 +6,8 @@
#pragma once
#include <AK/Platform.h>
namespace AK {
enum class IterationDecision {
@ -15,4 +17,6 @@ enum class IterationDecision {
}
#if USING_AK_GLOBALLY
using AK::IterationDecision;
#endif

View file

@ -114,4 +114,6 @@ inline typename Builder::OutputType JsonArray::serialized() const
}
#if USING_AK_GLOBALLY
using AK::JsonArray;
#endif

View file

@ -225,4 +225,6 @@ struct JsonArraySerializer<void> {
}
#if USING_AK_GLOBALLY
using AK::JsonArraySerializer;
#endif

View file

@ -243,4 +243,6 @@ inline typename Builder::OutputType JsonValue::serialized() const
}
#if USING_AK_GLOBALLY
using AK::JsonObject;
#endif

View file

@ -262,4 +262,6 @@ ErrorOr<JsonObjectSerializer<Builder>> JsonArraySerializer<Builder>::add_object(
}
#if USING_AK_GLOBALLY
using AK::JsonObjectSerializer;
#endif

View file

@ -35,4 +35,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::JsonParser;
#endif

View file

@ -95,5 +95,7 @@ public:
}
#if USING_AK_GLOBALLY
using AK::JsonPath;
using AK::JsonPathElement;
#endif

View file

@ -290,4 +290,6 @@ struct Formatter<JsonValue> : Formatter<StringView> {
}
#if USING_AK_GLOBALLY
using AK::JsonValue;
#endif

View file

@ -114,4 +114,6 @@ struct LEB128 {
}
#if USING_AK_GLOBALLY
using AK::LEB128;
#endif

View file

@ -95,4 +95,6 @@ struct Formatter<LexicalPath> : Formatter<StringView> {
};
#if USING_AK_GLOBALLY
using AK::LexicalPath;
#endif

View file

@ -775,4 +775,6 @@ constexpr T ceil(T num)
#undef AARCH64_INSTRUCTION
}
#if USING_AK_GLOBALLY
using AK::round_to;
#endif

View file

@ -76,5 +76,7 @@ inline bool timing_safe_compare(void const* b1, void const* b2, size_t len)
}
#if USING_AK_GLOBALLY
using AK::secure_zero;
using AK::timing_safe_compare;
#endif

View file

@ -272,7 +272,9 @@ private:
}
#if USING_AK_GLOBALLY
using AK::DuplexMemoryStream;
using AK::InputMemoryStream;
using AK::InputStream;
using AK::OutputMemoryStream;
#endif

View file

@ -40,4 +40,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::NeverDestroyed;
#endif

View file

@ -63,4 +63,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::NoAllocationGuard;
#endif

View file

@ -185,8 +185,10 @@ struct Formatter<NonnullOwnPtr<T>> : Formatter<const T*> {
}
#if !defined(KERNEL)
#if USING_AK_GLOBALLY
# if !defined(KERNEL)
using AK::adopt_own;
using AK::make;
#endif
# endif
using AK::NonnullOwnPtr;
#endif

View file

@ -17,4 +17,6 @@ class NonnullOwnPtrVector : public NonnullPtrVector<NonnullOwnPtr<T>, inline_cap
}
#if USING_AK_GLOBALLY
using AK::NonnullOwnPtrVector;
#endif

View file

@ -256,6 +256,8 @@ struct Traits<NonnullRefPtr<T>> : public GenericTraits<NonnullRefPtr<T>> {
static bool equals(NonnullRefPtr<T> const& a, NonnullRefPtr<T> const& b) { return a.ptr() == b.ptr(); }
};
#if USING_AK_GLOBALLY
using AK::adopt_ref;
using AK::make_ref_counted;
using AK::NonnullRefPtr;
#endif

View file

@ -18,4 +18,6 @@ class NonnullRefPtrVector : public NonnullPtrVector<NonnullRefPtr<T>, inline_cap
}
#if USING_AK_GLOBALLY
using AK::NonnullRefPtrVector;
#endif

View file

@ -83,7 +83,9 @@ static inline String human_readable_digital_time(i64 time_in_seconds)
}
#if USING_AK_GLOBALLY
using AK::human_readable_digital_time;
using AK::human_readable_size;
using AK::human_readable_size_long;
using AK::human_readable_time;
#endif

View file

@ -129,4 +129,6 @@ struct NumericLimits<long double> {
}
#if USING_AK_GLOBALLY
using AK::NumericLimits;
#endif

View file

@ -364,4 +364,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Optional;
#endif

View file

@ -224,7 +224,9 @@ struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
}
#if USING_AK_GLOBALLY
using AK::adopt_nonnull_own_or_enomem;
using AK::adopt_own_if_nonnull;
using AK::OwnPtr;
using AK::try_make;
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -7,6 +7,10 @@
#pragma once
#ifndef USING_AK_GLOBALLY
# define USING_AK_GLOBALLY 1
#endif
#ifdef __i386__
# define AK_ARCH_I386 1
#endif

View file

@ -56,4 +56,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Ptr32;
#endif

View file

@ -83,4 +83,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Queue;
#endif

View file

@ -151,4 +151,6 @@ void quick_sort(Collection& collection)
}
#if USING_AK_GLOBALLY
using AK::quick_sort;
#endif

View file

@ -55,6 +55,8 @@ u32 get_random_uniform(u32 max_bounds);
}
#if USING_AK_GLOBALLY
using AK::fill_with_random;
using AK::get_random;
using AK::get_random_uniform;
#endif

View file

@ -16,4 +16,6 @@ enum class RecursionDecision {
}
#if USING_AK_GLOBALLY
using AK::RecursionDecision;
#endif

View file

@ -587,4 +587,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::RedBlackTree;
#endif

View file

@ -29,4 +29,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::RefCountForwarder;
#endif

View file

@ -72,5 +72,7 @@ public:
}
#if USING_AK_GLOBALLY
using AK::RefCounted;
using AK::RefCountedBase;
#endif

View file

@ -340,7 +340,9 @@ inline ErrorOr<NonnullRefPtr<T>> adopt_nonnull_ref_or_enomem(T* object)
}
#if USING_AK_GLOBALLY
using AK::adopt_ref_if_nonnull;
using AK::RefPtr;
using AK::static_ptr_cast;
using AK::try_make_ref_counted;
#endif

View file

@ -118,4 +118,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Result;
#endif

View file

@ -50,5 +50,7 @@ private:
}
#if USING_AK_GLOBALLY
using AK::ArmedScopeGuard;
using AK::ScopeGuard;
#endif

View file

@ -62,4 +62,6 @@ public:
}
#if USING_AK_GLOBALLY
using AK::ScopeLogger;
#endif

View file

@ -34,4 +34,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::ScopedValueRollback;
#endif

View file

@ -134,4 +134,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Singleton;
#endif

View file

@ -302,4 +302,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::SinglyLinkedList;
#endif

View file

@ -139,4 +139,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::SinglyLinkedListWithCount;
#endif

View file

@ -123,4 +123,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::SourceGenerator;
#endif

View file

@ -49,4 +49,6 @@ struct AK::Formatter<AK::SourceLocation> : AK::Formatter<FormatString> {
}
};
#if USING_AK_GLOBALLY
using AK::SourceLocation;
#endif

View file

@ -266,6 +266,8 @@ using Bytes = Span<u8>;
}
#if USING_AK_GLOBALLY
using AK::Bytes;
using AK::ReadonlyBytes;
using AK::Span;
#endif

View file

@ -74,4 +74,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::Stack;
#endif

View file

@ -31,4 +31,6 @@ private:
}
#if USING_AK_GLOBALLY
using AK::StackInfo;
#endif

View file

@ -614,6 +614,8 @@ template<typename T, typename... Ts>
inline constexpr bool IsOneOfIgnoringCV = (IsSameIgnoringCV<T, Ts> || ...);
}
#if USING_AK_GLOBALLY
using AK::Detail::AddConst;
using AK::Detail::AddConstToReferencedType;
using AK::Detail::AddLvalueReference;
@ -683,3 +685,4 @@ using AK::Detail::RemoveVolatile;
using AK::Detail::TrueType;
using AK::Detail::UnderlyingType;
using AK::Detail::Void;
#endif

View file

@ -178,6 +178,7 @@ __DEFINE_GENERIC_ABS(long double, 0.0L, fabsl);
}
#if USING_AK_GLOBALLY
using AK::array_size;
using AK::ceil_div;
using AK::clamp;
@ -189,3 +190,4 @@ using AK::mix;
using AK::RawPtr;
using AK::swap;
using AK::to_underlying;
#endif

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