From 64492ed9c42659d0c5f7eb2143a673dd0b5f9dc3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 23 Oct 2025 09:27:16 +0200 Subject: feat! breaking API changes in kernel. Signed-off-by: Amlal El Mahrouss --- dev/kernel/CFKit/Property.h | 4 +-- dev/kernel/FSKit/IndexableProperty.h | 2 +- dev/kernel/NeKit/Defines.h | 11 ++++--- dev/kernel/NeKit/Json.h | 46 +++++++++++++++--------------- dev/kernel/NeKit/KString.h | 26 ++++++++--------- dev/kernel/NeKit/KString.inl | 28 +++++++++--------- dev/kernel/NeKit/Ref.h | 3 ++ dev/kernel/NeKit/Variant.h | 7 +++-- dev/kernel/src/FS/HeFS+FileMgr.cc | 33 ++++++++++++++++++--- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 2 ++ dev/kernel/src/Json.cc | 2 +- dev/kernel/src/Property.cc | 4 +-- 12 files changed, 101 insertions(+), 67 deletions(-) (limited to 'dev/kernel') diff --git a/dev/kernel/CFKit/Property.h b/dev/kernel/CFKit/Property.h index 17246a63..e8f2f713 100644 --- a/dev/kernel/CFKit/Property.h +++ b/dev/kernel/CFKit/Property.h @@ -30,9 +30,9 @@ class Property { Property& operator=(const Property&) = default; Property(const Property&) = default; - BOOL StringEquals(BasicKString<>& name); + BOOL StringEquals(KBasicString<>& name); PropertyId& GetValue(); - BasicKString<>& GetKey(); + KBasicString<>& GetKey(); private: KString fName{kMaxPropLen}; diff --git a/dev/kernel/FSKit/IndexableProperty.h b/dev/kernel/FSKit/IndexableProperty.h index 8be6d7c3..d6b89d35 100644 --- a/dev/kernel/FSKit/IndexableProperty.h +++ b/dev/kernel/FSKit/IndexableProperty.h @@ -25,7 +25,7 @@ namespace Indexer { class IndexableProperty final : public Property { public: explicit IndexableProperty() : Property() { - Kernel::BasicKString<> strProp(kMaxPropLen); + Kernel::KBasicString<> strProp(kMaxPropLen); strProp += "/prop/indexable"; this->GetKey() = strProp; diff --git a/dev/kernel/NeKit/Defines.h b/dev/kernel/NeKit/Defines.h index c5f02e0a..ed979e03 100644 --- a/dev/kernel/NeKit/Defines.h +++ b/dev/kernel/NeKit/Defines.h @@ -12,7 +12,7 @@ #define NEKIT_VERSION_BCD 0x0001 #ifndef __cplusplus -#error Kernel compiles with a C++ compiler. +#error !!! Kernel compiles only with a C++ compiler. !!! #endif #if __cplusplus <= 201703L @@ -39,7 +39,7 @@ using Int32 = __INT32_TYPE__; using UShort = __UINT16_TYPE__; using UInt16 = __UINT16_TYPE__; using Short = short; -using Int16 = short; +using Int16 = __INT16_TYPE__; using UInt = __UINT32_TYPE__; using UInt32 = __UINT32_TYPE__; using Long = __INT64_TYPE__; @@ -49,11 +49,13 @@ using UInt64 = __UINT64_TYPE__; using Boolean = bool; using Bool = bool; using Char = char; +using Int8 = __INT8_TYPE__; +using Char8 = char8_t; using UChar = __UINT8_TYPE__; using UInt8 = __UINT8_TYPE__; -using SSize = Int64; -using SSizeT = Int64; +using SSize = long; +using SSizeT = long; using Size = __SIZE_TYPE__; using SizeT = __SIZE_TYPE__; using IntPtr = __INTPTR_TYPE__; @@ -83,6 +85,7 @@ typedef UInt32 PhysicalAddressKind; typedef UIntPtr VirtualAddressKind; using Void = void; +using Any = void*; using Lba = UInt64; diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h index 24357dd7..35f53b57 100644 --- a/dev/kernel/NeKit/Json.h +++ b/dev/kernel/NeKit/Json.h @@ -7,7 +7,7 @@ #pragma once -// last-rev: 02/04/25 +/// @brief Kernel JSON API. #include #include @@ -15,58 +15,58 @@ #include #include -#define kJSONMaxLen (8196) -#define kJSONLen (256) -#define kJSONNullArr "[]" -#define kJSONNullObj "{}" +#define kNeJsonMaxLen (8196) +#define kNeJsonLen (256) +#define kNeJsonNullArr "[]" +#define kNeJsonNullObj "{}" namespace Kernel { /// @brief JavaScript object class -class Json final { +class JsonObject final { public: - explicit Json() { - auto len = kJSONMaxLen; - BasicKString<> key = KString(len); - key += kJSONNullObj; + explicit JsonObject() { + auto len = kNeJsonMaxLen; + KBasicString<> key = KString(len); + key += kNeJsonNullObj; this->AsKey() = key; this->AsValue() = key; } - explicit Json(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) {} + explicit JsonObject(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) {} - ~Json() = default; + ~JsonObject() = default; - NE_COPY_DEFAULT(Json) + NE_COPY_DEFAULT(JsonObject) Bool& IsUndefined() { return fUndefined; } private: Bool fUndefined; // is this instance undefined? - BasicKString<> fKey; - BasicKString<> fValue; + KBasicString<> fKey; + KBasicString<> fValue; public: /// @brief returns the key of the json /// @return the key as string view. - BasicKString<>& AsKey() { return fKey; } + KBasicString<>& AsKey() { return fKey; } /// @brief returns the value of the json. /// @return the key as string view. - BasicKString<>& AsValue() { return fValue; } + KBasicString<>& AsValue() { return fValue; } - static Json kNull; + static JsonObject kNull; }; -/// @brief Json stream reader helper. +/// @brief JsonObject stream reader helper. struct JsonStreamReader final { - STATIC Json In(const Char* full_array) { + STATIC JsonObject In(const Char* full_array) { auto start_val = '{'; auto end_val = '}'; Boolean probe_value = false; if (full_array[0] != start_val) { - if (full_array[0] != '[') return Json::kNull; + if (full_array[0] != '[') return JsonObject::kNull; start_val = '['; end_val = ']'; @@ -79,7 +79,7 @@ struct JsonStreamReader final { SizeT key_len = 0; SizeT value_len = 0; - Json type(kJSONMaxLen, kJSONMaxLen); + JsonObject type(kNeJsonMaxLen, kNeJsonMaxLen); for (SizeT i = 1; i < len; ++i) { if (full_array[i] == '\r' || full_array[i] == '\n') continue; @@ -125,5 +125,5 @@ struct JsonStreamReader final { } }; -using JsonStream = Stream; +using JsonStream = Stream; } // namespace Kernel diff --git a/dev/kernel/NeKit/KString.h b/dev/kernel/NeKit/KString.h index ec883a2f..6a1b04d2 100644 --- a/dev/kernel/NeKit/KString.h +++ b/dev/kernel/NeKit/KString.h @@ -12,14 +12,14 @@ #include #include -#define kMinimumStringSize (8196U) - namespace Kernel { +inline auto kMinimumStringSize = 8196; + /// @brief Kernel string class, not dynamic. template -class BasicKString final { +class KBasicString final { public: - explicit BasicKString() { + explicit KBasicString() { fDataSz = kMinimumStringSize; fData = new CharKind[fDataSz]; @@ -28,7 +28,7 @@ class BasicKString final { rt_set_memory(fData, 0, fDataSz); } - explicit BasicKString(SizeT Sz) : fDataSz(Sz) { + explicit KBasicString(SizeT Sz) : fDataSz(Sz) { MUST_PASS(Sz > 1); fData = new CharKind[Sz]; @@ -37,14 +37,14 @@ class BasicKString final { rt_set_memory(fData, 0, Sz); } - ~BasicKString() { + ~KBasicString() { if (fData) { delete[] fData; fData = nullptr; } } - NE_COPY_DEFAULT(BasicKString) + NE_COPY_DEFAULT(KBasicString) CharKind* Data(); const CharKind* CData() const; @@ -53,11 +53,11 @@ class BasicKString final { bool operator==(const CharKind* rhs) const; bool operator!=(const CharKind* rhs) const; - bool operator==(const BasicKString& rhs) const; - bool operator!=(const BasicKString& rhs) const; + bool operator==(const KBasicString& rhs) const; + bool operator!=(const KBasicString& rhs) const; - BasicKString& operator+=(const CharKind* rhs); - BasicKString& operator+=(const BasicKString& rhs); + KBasicString& operator+=(const CharKind* rhs); + KBasicString& operator+=(const KBasicString& rhs); operator const char*() { return fData; } @@ -73,13 +73,13 @@ class BasicKString final { friend class KStringBuilder; }; -using KString = BasicKString<>; +using KString = KBasicString<>; using KStringOr = ErrorOr; class KStringBuilder final { public: template - static ErrorOr> Construct(const CharKind* data); + static ErrorOr> Construct(const CharKind* data); template static const CharKind* FromBool(const CharKind* fmt, bool n); template diff --git a/dev/kernel/NeKit/KString.inl b/dev/kernel/NeKit/KString.inl index 4bb48415..d238818c 100644 --- a/dev/kernel/NeKit/KString.inl +++ b/dev/kernel/NeKit/KString.inl @@ -4,7 +4,7 @@ ------------------------------------------- */ -/// @file BasicKString.inl +/// @file KBasicString.inl /// @brief Kernel String manipulation file. namespace Kernel { @@ -19,22 +19,22 @@ inline void ort_string_append(CharKind* lhs, const CharKind* rhs, Int32 cur) { } template -inline CharKind* BasicKString::Data() { +inline CharKind* KBasicString::Data() { return this->fData; } template -inline const CharKind* BasicKString::CData() const { +inline const CharKind* KBasicString::CData() const { return const_cast(this->fData); } template -inline SizeT BasicKString::Length() const { +inline SizeT KBasicString::Length() const { return this->fDataSz; } template -inline bool BasicKString::operator==(const BasicKString& rhs) const { +inline bool KBasicString::operator==(const KBasicString& rhs) const { if (rhs.Length() != this->Length()) return false; for (Size index = 0; index < this->Length(); ++index) { @@ -45,7 +45,7 @@ inline bool BasicKString::operator==(const BasicKString& rhs } template -inline bool BasicKString::operator==(const CharKind* rhs) const { +inline bool KBasicString::operator==(const CharKind* rhs) const { if (ort_string_len(rhs) != this->Length()) return false; for (Size index = 0; index < ort_string_len(rhs); ++index) { @@ -56,7 +56,7 @@ inline bool BasicKString::operator==(const CharKind* rhs) const { } template -inline bool BasicKString::operator!=(const BasicKString& rhs) const { +inline bool KBasicString::operator!=(const KBasicString& rhs) const { if (rhs.Length() != this->Length()) return false; for (Size index = 0; index < rhs.Length(); ++index) { @@ -67,7 +67,7 @@ inline bool BasicKString::operator!=(const BasicKString& rhs } template -inline bool BasicKString::operator!=(const CharKind* rhs) const { +inline bool KBasicString::operator!=(const CharKind* rhs) const { if (ort_string_len(rhs) != this->Length()) return false; for (Size index = 0; index < ort_string_len(rhs); ++index) { @@ -78,7 +78,7 @@ inline bool BasicKString::operator!=(const CharKind* rhs) const { } template -inline BasicKString& BasicKString::operator+=(const BasicKString& rhs) { +inline KBasicString& KBasicString::operator+=(const KBasicString& rhs) { if (ort_string_len(rhs.fData) > this->Length()) return *this; ort_string_append(this->fData, const_cast(rhs.fData), this->fCur); @@ -88,7 +88,7 @@ inline BasicKString& BasicKString::operator+=(const BasicKSt } template -inline BasicKString& BasicKString::operator+=(const CharKind* rhs) { +inline KBasicString& KBasicString::operator+=(const CharKind* rhs) { ort_string_append(this->fData, const_cast(rhs), this->fCur); this->fCur += ort_string_len(const_cast(rhs)); @@ -96,13 +96,13 @@ inline BasicKString& BasicKString::operator+=(const CharKind } template -inline ErrorOr> KStringBuilder::Construct(const CharKind* data) { - if (!data || *data == 0) return ErrorOr>(nullptr); +inline ErrorOr> KStringBuilder::Construct(const CharKind* data) { + if (!data || *data == 0) return ErrorOr>(nullptr); - BasicKString* view = new BasicKString(ort_string_len(data)); + KBasicString* view = new KBasicString(ort_string_len(data)); (*view) += data; - return ErrorOr>(*view); + return ErrorOr>(*view); } template inline const CharKind* KStringBuilder::FromBool(const CharKind* fmt, bool i) { diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 6f7eca21..566f7486 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -65,6 +65,9 @@ class NonNullRef final { private: Ref fRef{}; }; + +using RefAny = Ref; +using NonNullRefAny = NonNullRef; } // namespace Kernel #endif // ifndef _NEKIT_REF_H_ diff --git a/dev/kernel/NeKit/Variant.h b/dev/kernel/NeKit/Variant.h index 51548272..700c9d9a 100644 --- a/dev/kernel/NeKit/Variant.h +++ b/dev/kernel/NeKit/Variant.h @@ -33,9 +33,10 @@ class Variant final { ~Variant() = default; public: - explicit Variant(KString* stringView) : fPtr((VoidPtr) stringView), fKind(VariantKind::kString) {} + template + explicit Variant(KBasicString* stringView) : fPtr((VoidPtr) stringView), fKind(VariantKind::kString) {} - explicit Variant(Json* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} + explicit Variant(JsonObject* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} explicit Variant(nullPtr ptr) : fPtr(ptr), fKind(VariantKind::kNull) {} @@ -55,7 +56,7 @@ class Variant final { VariantKind& Kind(); private: - voidPtr fPtr{nullptr}; + VoidPtr fPtr{nullptr}; VariantKind fKind{VariantKind::kNull}; }; } // namespace Kernel diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc index 6b559cf4..33813f65 100644 --- a/dev/kernel/src/FS/HeFS+FileMgr.cc +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -19,12 +19,12 @@ HeFileSystemMgr::HeFileSystemMgr() { mParser = new HeFileSystemParser(); MUST_PASS(mParser); - kout << "We are done allocating NeFileSystemParser...\n"; + kout << "We are done allocating HeFileSystemParser...\n"; } HeFileSystemMgr::~HeFileSystemMgr() { if (mParser) { - kout << "Destroying NeFileSystemParser...\n"; + kout << "Destroying HeFileSystemParser...\n"; delete mParser; mParser = nullptr; } @@ -124,21 +124,44 @@ _Output NodePtr HeFileSystemMgr::Open(_Input const Char* path, _Input const Char } Void HeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, - _Input SizeT size) {} + _Input SizeT size) { + NE_UNUSED(node); + NE_UNUSED(flags); + NE_UNUSED(size); + NE_UNUSED(data); +} _Output VoidPtr HeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { + NE_UNUSED(node); + NE_UNUSED(flags); + NE_UNUSED(size); + return nullptr; } Void HeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, - _Input Int32 flags, _Input SizeT size) {} + _Input Int32 flags, _Input SizeT size) { + NE_UNUSED(node); + NE_UNUSED(flags); + NE_UNUSED(size); + NE_UNUSED(name); + NE_UNUSED(data); +} _Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, _Input SizeT sz) { + NE_UNUSED(node); + NE_UNUSED(flags); + NE_UNUSED(sz); + NE_UNUSED(name); + return nullptr; } _Output Bool HeFileSystemMgr::Seek(NodePtr node, SizeT off) { + NE_UNUSED(node); + NE_UNUSED(off); + return false; } @@ -146,6 +169,7 @@ _Output Bool HeFileSystemMgr::Seek(NodePtr node, SizeT off) { /// @param node /// @return kFileMgrNPos if invalid, else current offset. _Output SizeT HeFileSystemMgr::Tell(NodePtr node) { + NE_UNUSED(node); return kFileMgrNPos; } @@ -153,6 +177,7 @@ _Output SizeT HeFileSystemMgr::Tell(NodePtr node) { /// @param node /// @return False if invalid, nah? calls Seek(node, 0). _Output Bool HeFileSystemMgr::Rewind(NodePtr node) { + NE_UNUSED(node); return kFileMgrNPos; } diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 86f929c0..029fdf26 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -79,12 +79,14 @@ namespace Detail { const Utf8Char* dir_name, UInt16 flags, const BOOL delete_or_create); + /// @brief This helper makes it easier for other machines to understand HeFS encoded hashes. STATIC UInt64 hefsi_to_big_endian_64(UInt64 val) { return ((val >> 56) & 0x00000000000000FFULL) | ((val >> 40) & 0x000000000000FF00ULL) | ((val >> 24) & 0x0000000000FF0000ULL) | ((val >> 8) & 0x00000000FF000000ULL) | ((val << 8) & 0x000000FF00000000ULL) | ((val << 24) & 0x0000FF0000000000ULL) | ((val << 40) & 0x00FF000000000000ULL) | ((val << 56) & 0xFF00000000000000ULL); } + /// @brief Simple algorithm to hash directory entries for INDs. /// @param path the directory path. /// @return The hashed path. diff --git a/dev/kernel/src/Json.cc b/dev/kernel/src/Json.cc index 68ab55fc..d156c0ce 100644 --- a/dev/kernel/src/Json.cc +++ b/dev/kernel/src/Json.cc @@ -7,4 +7,4 @@ #include /// @brief Undefined object, is null in length. -RTL_INIT_OBJECT(Kernel::Json::kNull, Kernel::Json); +RTL_INIT_OBJECT(Kernel::JsonObject::kNull, Kernel::JsonObject); diff --git a/dev/kernel/src/Property.cc b/dev/kernel/src/Property.cc index 1d01293f..714fb2a4 100644 --- a/dev/kernel/src/Property.cc +++ b/dev/kernel/src/Property.cc @@ -21,14 +21,14 @@ Property::Property() = default; /// @brief Check if property's name equals to name. /// @param name string to check. /***********************************************************************************/ -Bool Property::StringEquals(BasicKString<>& name) { +Bool Property::StringEquals(KBasicString<>& name) { return this->fName && this->fName == name; } /***********************************************************************************/ /// @brief Gets the key (name) of property. /***********************************************************************************/ -BasicKString<>& Property::GetKey() { +KBasicString<>& Property::GetKey() { return this->fName; } -- cgit v1.2.3