From 3658cb8407814603aceaf2970a5c1016b6c9fdc8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 6 Aug 2025 16:41:31 +0100 Subject: feat! breaking API changes before NeKernel.org 0.0.4. Signed-off-by: Amlal El Mahrouss --- dev/CompilerKit/src/StringKit.cc | 179 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 dev/CompilerKit/src/StringKit.cc (limited to 'dev/CompilerKit/src/StringKit.cc') diff --git a/dev/CompilerKit/src/StringKit.cc b/dev/CompilerKit/src/StringKit.cc new file mode 100644 index 0000000..13142a6 --- /dev/null +++ b/dev/CompilerKit/src/StringKit.cc @@ -0,0 +1,179 @@ +/* + * ======================================================== + * + * CompilerKit + * Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. + * + * ======================================================== + */ + +/** + * @file BasicString.cc + * @author Amlal (amlal@nekernel.org) + * @brief C++ string manipulation API. + * @version 0.2 + * @date 2024-01-23 + * + * @copyright Copyright (c) Amlal El Mahrouss + * + */ + +#include + +namespace CompilerKit { + +Char* BasicString::Data() { + return m_Data; +} + +const Char* BasicString::CData() const { + return m_Data; +} + +SizeType BasicString::Length() const { + return strlen(m_Data); +} + +bool BasicString::operator==(const BasicString& rhs) const { + const SizeType len = Length(); + if (rhs.Length() != len) return false; + return memcmp(m_Data, rhs.m_Data, len) == 0; +} + +bool BasicString::operator==(const Char* rhs) const { + const SizeType rhs_len = string_length(rhs); + const SizeType len = Length(); + if (rhs_len != len) return false; + return memcmp(m_Data, rhs, len) == 0; +} + +bool BasicString::operator!=(const BasicString& rhs) const { + return !(*this == rhs); +} + +bool BasicString::operator!=(const Char* rhs) const { + return !(*this == rhs); +} + +BasicString StringBuilder::Construct(const Char* data) { + if (!data || *data == 0) return BasicString(0); + + BasicString view(strlen(data)); + view += data; + + return view; +} + +BasicString StringBuilder::FromInt(const char* fmt, int i) { + if (!fmt) return BasicString(0); + + Char result[sizeof(int64_t)] = {0}; + if (!to_str(result, sizeof(int64_t), i)) return BasicString(0); + + const SizeType fmt_len = string_length(fmt); + const SizeType res_len = string_length(result); + + BasicString output(fmt_len + res_len); + bool inserted = false; + + for (SizeType idx = 0; idx < fmt_len; ++idx) { + if (!inserted && fmt[idx] == '%') { + output += result; + inserted = true; + continue; + } + output += Char{fmt[idx]}; + } + + return output; +} + +BasicString StringBuilder::FromBool(const char* fmt, bool val) { + if (!fmt) return BasicString(0); + + const Char* boolean_expr = val ? "true" : "false"; + const SizeType fmt_len = string_length(fmt); + const SizeType res_len = string_length(boolean_expr); + + BasicString output(fmt_len + res_len); + bool inserted = false; + + for (SizeType idx = 0; idx < fmt_len; ++idx) { + if (!inserted && fmt[idx] == '%') { + output += boolean_expr; + inserted = true; + continue; + } + output += Char{fmt[idx]}; + } + + return output; +} + +bool StringBuilder::Equals(const char* lhs, const char* rhs) { + const SizeType lhs_len = string_length(lhs); + const SizeType rhs_len = string_length(rhs); + + if (lhs_len != rhs_len) return false; + return memcmp(lhs, rhs, lhs_len) == 0; +} + +BasicString StringBuilder::Format(const char* fmt, const char* fmtRight) { + if (!fmt || !fmtRight) return BasicString(0); + + const SizeType fmt_len = string_length(fmt); + const SizeType rhs_len = string_length(fmtRight); + + BasicString output(fmt_len + rhs_len); + bool inserted = false; + + for (SizeType idx = 0; idx < fmt_len; ++idx) { + if (!inserted && fmt[idx] == '%') { + output += fmtRight; + inserted = true; + continue; + } + output += Char{fmt[idx]}; + } + + return output; +} + +BasicString& BasicString::operator+=(const Char* rhs) { + const SizeType rhs_len = strlen(rhs); + if (this->m_Cur + rhs_len >= this->m_Sz) { + throw std::runtime_error("out_of_bounds: BasicString"); + } + + memcpy(this->m_Data + this->m_Cur, rhs, rhs_len); + + this->m_Cur += rhs_len; + this->m_Data[this->m_Cur] = '\0'; + + return *this; +} + +BasicString& BasicString::operator+=(const BasicString& rhs) { + if (this->m_Cur + rhs.m_Cur >= this->m_Sz) { + throw std::runtime_error("out_of_bounds: BasicString"); + } + + memcpy(this->m_Data + this->m_Cur, rhs.CData(), rhs.m_Cur); + this->m_Cur += rhs.m_Cur; + this->m_Data[this->m_Cur] = '\0'; + + return *this; +} + +BasicString& BasicString::operator+=(const Char ch) { + if (this->m_Cur + 1 >= this->m_Sz) { + throw std::runtime_error("out_of_bounds.."); + } + + this->m_Data[this->m_Cur++] = ch; + this->m_Data[this->m_Cur] = '\0'; + + return *this; +} + +} // namespace CompilerKit -- cgit v1.2.3 From 85a8e5967def8164b90824c9095c3a93d62d96b2 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 9 Aug 2025 19:53:40 +0200 Subject: feat: compiler_kit: post PR compiler error fixes. Signed-off-by: Amlal --- dev/CompilerKit/Compiler.h | 2 +- dev/CompilerKit/Defines.h | 52 +++++++++++----------- dev/CompilerKit/Frontend.h | 11 ++--- dev/CompilerKit/Macros.h | 12 ++--- dev/CompilerKit/UUID.h | 2 +- dev/CompilerKit/src/Backend/Assembler32x0.cc | 2 +- dev/CompilerKit/src/Backend/Assembler64x0.cc | 2 +- dev/CompilerKit/src/Backend/AssemblerAMD64.cc | 2 +- dev/CompilerKit/src/Backend/AssemblerARM64.cc | 4 +- dev/CompilerKit/src/Backend/AssemblerPowerPC.cc | 4 +- dev/CompilerKit/src/Frontend/CCompiler64x0.cc | 9 ++-- dev/CompilerKit/src/Frontend/CCompilerARM64.cc | 9 ++-- dev/CompilerKit/src/Frontend/CCompilerPower64.cc | 9 ++-- .../src/Frontend/CPlusPlusCompilerAMD64.cc | 46 +++++++++---------- dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc | 17 +++---- dev/CompilerKit/src/StringKit.cc | 20 ++++----- dev/DebuggerKit/NeKernelContract.h | 4 +- dev/DebuggerKit/Platform.h | 2 +- dev/DebuggerKit/src/NeKernelContractCLI.cc | 3 +- dev/LibC++/__abi+unreachable.cc | 9 ++-- dev/LibC++/__abi.h | 6 +-- dev/LibC++/base_exception.h | 6 +-- dev/LibC++/defines.h | 2 +- dev/ThirdParty/Dialogs.h | 41 +++++++++-------- tools/pef-amd64-cxxdrv.cc | 7 ++- tools/pef-arm64-cdrv.cc | 7 ++- 26 files changed, 140 insertions(+), 150 deletions(-) (limited to 'dev/CompilerKit/src/StringKit.cc') diff --git a/dev/CompilerKit/Compiler.h b/dev/CompilerKit/Compiler.h index 60d63ff..46059b8 100644 --- a/dev/CompilerKit/Compiler.h +++ b/dev/CompilerKit/Compiler.h @@ -6,9 +6,9 @@ #pragma once -#include #include #include +#include #define CK_ASSEMBLY_INTERFACE : public ::CompilerKit::AssemblyInterface #define CK_ENCODER : public ::CompilerKit::EncoderInterface diff --git a/dev/CompilerKit/Defines.h b/dev/CompilerKit/Defines.h index e9d2560..ffaae0d 100644 --- a/dev/CompilerKit/Defines.h +++ b/dev/CompilerKit/Defines.h @@ -51,6 +51,8 @@ #define Char char #define Boolean bool +#include +#include #include #include #include @@ -81,20 +83,39 @@ #define rt_copy_memory(dst, src, len) memcpy(dst, src, len) #endif -#define NECTI_COPY_DELETE(KLASS) \ +#define ATTRIBUTE(X) __attribute__((X)) +#define PACKED ATTRIBUTE(packed) + +typedef char char_type; + +#define kObjectFileExt ".obj" +#define kBinaryFileExt ".bin" + +#define kAsmFileExts \ + { ".64x", ".32x", ".masm", ".s", ".S", ".asm", ".x64" } + +#define kAsmFileExtsMax (7U) + +#define NECTI_MODULE(name) extern "C" int name(int argc, char** argv) + +#ifdef MSVC +#pragma scalar_storage_order big - endian +#endif // ifdef MSVC + +#define NECTI_COPY_DELETE(KLASS) \ KLASS& operator=(const KLASS&) = delete; \ KLASS(const KLASS&) = delete; -#define NECTI_COPY_DEFAULT(KLASS) \ +#define NECTI_COPY_DEFAULT(KLASS) \ KLASS& operator=(const KLASS&) = default; \ KLASS(const KLASS&) = default; -#define NECTI_MOVE_DELETE(KLASS) \ - KLASS& operator=(KLASS&&) = delete; \ +#define NECTI_MOVE_DELETE(KLASS) \ + KLASS& operator=(KLASS&&) = delete; \ KLASS(KLASS&&) = delete; -#define NECTI_MOVE_DEFAULT(KLASS) \ - KLASS& operator=(KLASS&&) = default; \ +#define NECTI_MOVE_DEFAULT(KLASS) \ + KLASS& operator=(KLASS&&) = default; \ KLASS(KLASS&&) = default; #define CK_IMPORT_C extern "C" @@ -149,23 +170,4 @@ inline bool install_signal(Int32 signal, void (*handler)(int)) noexcept { } } // namespace CompilerKit -#define ATTRIBUTE(X) __attribute__((X)) -#define PACKED ATTRIBUTE(packed) - -typedef char char_type; - -#define kObjectFileExt ".obj" -#define kBinaryFileExt ".bin" - -#define kAsmFileExts \ - { ".64x", ".32x", ".masm", ".s", ".S", ".asm", ".x64" } - -#define kAsmFileExtsMax (7U) - -#define NECTI_MODULE(name) extern "C" int name(int argc, char** argv) - -#ifdef MSVC -#pragma scalar_storage_order big - endian -#endif // ifdef MSVC - #endif /* ifndef __NECTI_DEFINES_H__ */ diff --git a/dev/CompilerKit/Frontend.h b/dev/CompilerKit/Frontend.h index 4719c3d..0f81342 100644 --- a/dev/CompilerKit/Frontend.h +++ b/dev/CompilerKit/Frontend.h @@ -59,20 +59,17 @@ enum KeywordKind { /// \brief Compiler keyword information struct. struct CompilerKeyword { CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {} - + STLString keyword_name{""}; KeywordKind keyword_kind{kKeywordKindInvalid}; }; struct SyntaxLeafList final { struct SyntaxLeaf final { - Int32 fUserType{0U}; - CompilerKeyword fUserData{ - "", - kKeywordKindInvalid - }; + Int32 fUserType{0U}; + CompilerKeyword fUserData{"", kKeywordKindInvalid}; - STLString fUserValue{""}; + STLString fUserValue{""}; struct SyntaxLeaf* fNext{nullptr}; }; diff --git a/dev/CompilerKit/Macros.h b/dev/CompilerKit/Macros.h index ee42be5..f05729c 100644 --- a/dev/CompilerKit/Macros.h +++ b/dev/CompilerKit/Macros.h @@ -9,20 +9,20 @@ #ifndef _MACROS_H_ #define _MACROS_H_ -#define NECTI_COPY_DELETE(KLASS) \ +#define NECTI_COPY_DELETE(KLASS) \ KLASS& operator=(const KLASS&) = delete; \ KLASS(const KLASS&) = delete; -#define NECTI_COPY_DEFAULT(KLASS) \ +#define NECTI_COPY_DEFAULT(KLASS) \ KLASS& operator=(const KLASS&) = default; \ KLASS(const KLASS&) = default; -#define NECTI_MOVE_DELETE(KLASS) \ - KLASS& operator=(KLASS&&) = delete; \ +#define NECTI_MOVE_DELETE(KLASS) \ + KLASS& operator=(KLASS&&) = delete; \ KLASS(KLASS&&) = delete; -#define NECTI_MOVE_DEFAULT(KLASS) \ - KLASS& operator=(KLASS&&) = default; \ +#define NECTI_MOVE_DEFAULT(KLASS) \ + KLASS& operator=(KLASS&&) = default; \ KLASS(KLASS&&) = default; /// @note xxxx is the error placeholder, in hexadecimal. diff --git a/dev/CompilerKit/UUID.h b/dev/CompilerKit/UUID.h index 39db276..d54eec7 100644 --- a/dev/CompilerKit/UUID.h +++ b/dev/CompilerKit/UUID.h @@ -172,7 +172,7 @@ namespace Detail { process_byte(static_cast((bitCount >> 24) & 0xFF)); process_byte(static_cast((bitCount >> 16) & 0xFF)); process_byte(static_cast((bitCount >> 8) & 0xFF)); - process_byte(static_cast((bitCount) &0xFF)); + process_byte(static_cast((bitCount) & 0xFF)); memcpy(digest, m_digest, 5 * sizeof(uint32_t)); return digest; diff --git a/dev/CompilerKit/src/Backend/Assembler32x0.cc b/dev/CompilerKit/src/Backend/Assembler32x0.cc index a7cb022..8478930 100644 --- a/dev/CompilerKit/src/Backend/Assembler32x0.cc +++ b/dev/CompilerKit/src/Backend/Assembler32x0.cc @@ -22,9 +22,9 @@ #endif #include -#include #include #include +#include #include ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/dev/CompilerKit/src/Backend/Assembler64x0.cc b/dev/CompilerKit/src/Backend/Assembler64x0.cc index 6bc8842..c2dd31c 100644 --- a/dev/CompilerKit/src/Backend/Assembler64x0.cc +++ b/dev/CompilerKit/src/Backend/Assembler64x0.cc @@ -22,9 +22,9 @@ #endif #include -#include #include #include +#include #include #include #include diff --git a/dev/CompilerKit/src/Backend/AssemblerAMD64.cc b/dev/CompilerKit/src/Backend/AssemblerAMD64.cc index b085773..7e21c93 100644 --- a/dev/CompilerKit/src/Backend/AssemblerAMD64.cc +++ b/dev/CompilerKit/src/Backend/AssemblerAMD64.cc @@ -29,9 +29,9 @@ #define kAssemblerPragmaSym '#' #include -#include #include #include +#include #include #include #include diff --git a/dev/CompilerKit/src/Backend/AssemblerARM64.cc b/dev/CompilerKit/src/Backend/AssemblerARM64.cc index 331e708..ec0f16b 100644 --- a/dev/CompilerKit/src/Backend/AssemblerARM64.cc +++ b/dev/CompilerKit/src/Backend/AssemblerARM64.cc @@ -20,12 +20,12 @@ #endif #include -#include #include #include #include -#include #include +#include +#include #include #include #include diff --git a/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc b/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc index bbb5a8b..3282ccb 100644 --- a/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc +++ b/dev/CompilerKit/src/Backend/AssemblerPowerPC.cc @@ -20,12 +20,12 @@ #endif #include -#include #include #include #include -#include #include +#include +#include #include #include #include diff --git a/dev/CompilerKit/src/Frontend/CCompiler64x0.cc b/dev/CompilerKit/src/Frontend/CCompiler64x0.cc index 1221521..de76807 100644 --- a/dev/CompilerKit/src/Frontend/CCompiler64x0.cc +++ b/dev/CompilerKit/src/Frontend/CCompiler64x0.cc @@ -10,9 +10,9 @@ /// BUGS: 0 /// TODO: none -#include #include #include +#include #include #include #include @@ -141,8 +141,8 @@ class CompilerFrontend64x0 final : public CompilerKit::CompilerFrontendInterface NECTI_COPY_DEFAULT(CompilerFrontend64x0); - std::string Check(const char* text, const char* file); - CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; + std::string Check(const char* text, const char* file); + CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; const char* Language() override { return "64k C"; } }; @@ -182,7 +182,8 @@ union double_cast final { ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontend64x0::Compile(std::string text_, std::string file) { +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontend64x0::Compile(std::string text_, + std::string file) { std::string text = text_; bool typeFound = false; diff --git a/dev/CompilerKit/src/Frontend/CCompilerARM64.cc b/dev/CompilerKit/src/Frontend/CCompilerARM64.cc index 6795c67..9cfc019 100644 --- a/dev/CompilerKit/src/Frontend/CCompilerARM64.cc +++ b/dev/CompilerKit/src/Frontend/CCompilerARM64.cc @@ -10,9 +10,9 @@ /// BUGS: 0 /// TODO: none -#include #include #include +#include #include #include @@ -142,8 +142,8 @@ class CompilerFrontendARM64 final : public CompilerKit::CompilerFrontendInterfac NECTI_COPY_DEFAULT(CompilerFrontendARM64); - std::string Check(const char* text, const char* file); - CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; + std::string Check(const char* text, const char* file); + CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; const char* Language() override { return "64k C"; } }; @@ -183,7 +183,8 @@ union double_cast final { ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendARM64::Compile(std::string text, std::string file) { +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendARM64::Compile(std::string text, + std::string file) { bool typeFound = false; bool fnFound = false; diff --git a/dev/CompilerKit/src/Frontend/CCompilerPower64.cc b/dev/CompilerKit/src/Frontend/CCompilerPower64.cc index 1999f48..1888ed0 100644 --- a/dev/CompilerKit/src/Frontend/CCompilerPower64.cc +++ b/dev/CompilerKit/src/Frontend/CCompilerPower64.cc @@ -7,9 +7,9 @@ * ======================================================== */ -#include #include #include +#include #include #include #include @@ -132,8 +132,8 @@ class CompilerFrontendPower64 final : public CompilerKit::CompilerFrontendInterf NECTI_COPY_DEFAULT(CompilerFrontendPower64); - std::string Check(const char* text, const char* file); - CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; + std::string Check(const char* text, const char* file); + CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) override; const char* Language() override { return "POWER C"; } }; @@ -173,7 +173,8 @@ union double_cast final { ///////////////////////////////////////////////////////////////////////////////////////// -CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendPower64::Compile(std::string text_, std::string file) { +CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendPower64::Compile(std::string text_, + std::string file) { std::string text = text_; bool typeFound = false; diff --git a/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc b/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc index ad2b8e1..c92f2e2 100644 --- a/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc +++ b/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc @@ -15,10 +15,10 @@ #define kExitOK (EXIT_SUCCESS) #define kExitNO (EXIT_FAILURE) -#include #include #include #include +#include #include #include #include @@ -48,7 +48,6 @@ ///////////////////////////////////// /// @internal -namespace Detail { // Avoids relative_path which could discard parts of the original. std::filesystem::path expand_home(const std::filesystem::path& input) { const std::string& raw = input.string(); @@ -57,14 +56,12 @@ std::filesystem::path expand_home(const std::filesystem::path& input) { const char* home = std::getenv("HOME"); if (!home) home = std::getenv("USERPROFILE"); - if (!home) - throw std::runtime_error("Home directory not found in environment variables"); + if (!home) throw std::runtime_error("Home directory not found in environment variables"); return std::filesystem::path(home) / raw.substr(1); } return input; - } } struct CompilerRegisterMap final { @@ -90,16 +87,14 @@ struct CompilerState final { /// @brief prints an error into stdout. /// @param reason the reason of the error. /// @param file where does it originate from? -void print_error(const CompilerKit::STLString& reason, const CompilerKit::STLString& file) noexcept { +void print_error(const CompilerKit::STLString& reason, + const CompilerKit::STLString& file) noexcept { kPrintErr << kRed << "Error in " << file << ": " << reason << kWhite << std::endl; } -} // namespace Detail -static Detail::CompilerState kState; +static CompilerState kState; static Int32 kOnClassScope = 0; -static Boolean kVerbose = false; -static Int32 kErrorLimit = 0; ///////////////////////////////////////////////////////////////////////////////////////// @@ -245,7 +240,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( expr.find("<=") + strlen("<=")); auto right = text.substr(expr.find(">=") + strlen(">="), text.find(")") - 1); - // Trim whitespace + // Trim whitespace while (!right.empty() && (right.back() == ' ' || right.back() == '\t')) { right.pop_back(); } @@ -323,8 +318,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( break; accept: - CompilerKit::STLString symbol_name_fn = text; - size_t indexFnName = 0; + CompilerKit::STLString symbol_name_fn = text; + size_t indexFnName = 0; // this one is for the type. for (auto& ch : text) { @@ -369,11 +364,11 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( break; lc_write_assembly: - auto it = - std::find_if(kOriginMap.begin(), kOriginMap.end(), - [&symbol_name_fn](std::pair pair) -> bool { - return symbol_name_fn == pair.first; - }); + auto it = std::find_if( + kOriginMap.begin(), kOriginMap.end(), + [&symbol_name_fn](std::pair pair) -> bool { + return symbol_name_fn == pair.first; + }); if (it != kOriginMap.end()) { std::stringstream ss; @@ -490,8 +485,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (pairRight != valueOfVar) { if (valueOfVar[0] == '\"') { - syntax_tree.fUserValue = "segment .data64 __NECTI_LOCAL_VAR_" + varName + - ": db " + valueOfVar + ", 0\n\n"; + syntax_tree.fUserValue = "segment .data64 __NECTI_LOCAL_VAR_" + varName + ": db " + + valueOfVar + ", 0\n\n"; syntax_tree.fUserValue += instr + kRegisterList[kRegisterMap.size() - 1] + ", " + "__NECTI_LOCAL_VAR_" + varName + "\n"; kOrigin += 1UL; @@ -507,8 +502,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (((int) indexRight - 1) < 0) { if (valueOfVar[0] == '\"') { - syntax_tree.fUserValue = "segment .data64 __NECTI_LOCAL_VAR_" + varName + - ": db " + valueOfVar + ", 0\n"; + syntax_tree.fUserValue = + "segment .data64 __NECTI_LOCAL_VAR_" + varName + ": db " + valueOfVar + ", 0\n"; syntax_tree.fUserValue += instr + kRegisterList[kRegisterMap.size()] + ", " + "__NECTI_LOCAL_VAR_" + varName + "\n"; kOrigin += 1UL; @@ -521,7 +516,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( goto done; } - if (!valueOfVar.empty() && valueOfVar[0] != '\"' && valueOfVar[0] != '\'' && !isdigit(valueOfVar[0])) { + if (!valueOfVar.empty() && valueOfVar[0] != '\"' && valueOfVar[0] != '\'' && + !isdigit(valueOfVar[0])) { for (auto pair : kRegisterMap) { if (pair == valueOfVar) goto done; } @@ -819,14 +815,13 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) { kFactory.Mount(new AssemblyCPlusPlusInterfaceAMD64()); CompilerKit::install_signal(SIGSEGV, Detail::drvi_crash_handler); - + // Ensure cleanup on exit std::atexit([]() { delete kCompilerFrontend; kCompilerFrontend = nullptr; }); - for (auto index = 1UL; index < argc; ++index) { if (!argv[index]) break; @@ -835,7 +830,6 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) { skip = false; continue; } - if (strcmp(argv[index], "-cxx-verbose") == 0) { kVerbose = true; diff --git a/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc b/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc index 394014c..2d149df 100644 --- a/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc +++ b/dev/CompilerKit/src/Linker/DynamicLinker64PEF.cc @@ -13,19 +13,19 @@ /// @note Do not look up for anything with .code64/.data64/.zero64! /// It will be loaded when the program loader will start the image. - +#include +#include #include #include -#include #include #include #include -#include #include -#define kLinkerVersionStr \ - "NeKernel.org 64-Bit Linker (Preferred Executable Format) %s, (c) Amlal El Mahrouss, and NeKernel Contributors " \ - "2024-2025 " \ +#define kLinkerVersionStr \ + "NeKernel.org 64-Bit Linker (Preferred Executable Format) %s, (c) Amlal El Mahrouss, and " \ + "NeKernel Contributors " \ + "2024-2025 " \ "all rights reserved.\n" #define MemoryCopy(DST, SRC, SZ) memcpy(DST, SRC, SZ) @@ -44,10 +44,7 @@ /// @brief PEF stack size symbol. #define kLinkerStackSizeSymbol "__PEFSizeOfReserveStack" -#define kConsoleOut \ - (std::cout << "\e[0;31m" \ - << "ld64: " \ - << "\e[0;97m") +#define kConsoleOut (std::cout << "\e[0;31m" << "ld64: " << "\e[0;97m") enum { kABITypeNull = 0, diff --git a/dev/CompilerKit/src/StringKit.cc b/dev/CompilerKit/src/StringKit.cc index 13142a6..67f2f55 100644 --- a/dev/CompilerKit/src/StringKit.cc +++ b/dev/CompilerKit/src/StringKit.cc @@ -42,7 +42,7 @@ bool BasicString::operator==(const BasicString& rhs) const { bool BasicString::operator==(const Char* rhs) const { const SizeType rhs_len = string_length(rhs); - const SizeType len = Length(); + const SizeType len = Length(); if (rhs_len != len) return false; return memcmp(m_Data, rhs, len) == 0; } @@ -74,7 +74,7 @@ BasicString StringBuilder::FromInt(const char* fmt, int i) { const SizeType res_len = string_length(result); BasicString output(fmt_len + res_len); - bool inserted = false; + bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { if (!inserted && fmt[idx] == '%') { @@ -91,12 +91,12 @@ BasicString StringBuilder::FromInt(const char* fmt, int i) { BasicString StringBuilder::FromBool(const char* fmt, bool val) { if (!fmt) return BasicString(0); - const Char* boolean_expr = val ? "true" : "false"; - const SizeType fmt_len = string_length(fmt); - const SizeType res_len = string_length(boolean_expr); + const Char* boolean_expr = val ? "true" : "false"; + const SizeType fmt_len = string_length(fmt); + const SizeType res_len = string_length(boolean_expr); BasicString output(fmt_len + res_len); - bool inserted = false; + bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { if (!inserted && fmt[idx] == '%') { @@ -125,7 +125,7 @@ BasicString StringBuilder::Format(const char* fmt, const char* fmtRight) { const SizeType rhs_len = string_length(fmtRight); BasicString output(fmt_len + rhs_len); - bool inserted = false; + bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { if (!inserted && fmt[idx] == '%') { @@ -146,7 +146,7 @@ BasicString& BasicString::operator+=(const Char* rhs) { } memcpy(this->m_Data + this->m_Cur, rhs, rhs_len); - + this->m_Cur += rhs_len; this->m_Data[this->m_Cur] = '\0'; @@ -171,9 +171,9 @@ BasicString& BasicString::operator+=(const Char ch) { } this->m_Data[this->m_Cur++] = ch; - this->m_Data[this->m_Cur] = '\0'; + this->m_Data[this->m_Cur] = '\0'; return *this; } -} // namespace CompilerKit +} // namespace CompilerKit diff --git a/dev/DebuggerKit/NeKernelContract.h b/dev/DebuggerKit/NeKernelContract.h index 20d86cd..098244e 100644 --- a/dev/DebuggerKit/NeKernelContract.h +++ b/dev/DebuggerKit/NeKernelContract.h @@ -14,8 +14,8 @@ namespace DebuggerKit::NeKernel { class NeKernelContract; namespace Detail { - inline constexpr auto kDebugCmdLen = 256U; - inline constexpr auto kDebugPort = 51820; + inline constexpr auto kDebugCmdLen = 256U; + inline constexpr auto kDebugPort = 51820; inline constexpr auto kDebugMagic = "VMK1.0.0;"; inline constexpr auto kDebugVersion = 0x0100; typedef char rt_debug_cmd[kDebugCmdLen]; diff --git a/dev/DebuggerKit/Platform.h b/dev/DebuggerKit/Platform.h index b24c5d9..6a3ef7c 100644 --- a/dev/DebuggerKit/Platform.h +++ b/dev/DebuggerKit/Platform.h @@ -13,5 +13,5 @@ #include #include #else -#error !!! DebuggerKit needs a networking backend !!! +#error !!! DebuggerKit needs a networking backend !!! #endif \ No newline at end of file diff --git a/dev/DebuggerKit/src/NeKernelContractCLI.cc b/dev/DebuggerKit/src/NeKernelContractCLI.cc index 1dd87a5..0eb04d3 100644 --- a/dev/DebuggerKit/src/NeKernelContractCLI.cc +++ b/dev/DebuggerKit/src/NeKernelContractCLI.cc @@ -30,7 +30,8 @@ static void dbgi_ctrlc_handler(std::int32_t _) { NECTI_MODULE(DebuggerNeKernel) { pfd::notify("Debugger Event", - "NeKernel Debugger\n(C) 2025 Amlal El Mahrouss and NeKernel.org contributors, all rights reserved."); + "NeKernel Debugger\n(C) 2025 Amlal El Mahrouss and NeKernel.org contributors, all " + "rights reserved."); if (argc >= 5 && std::string(argv[1]) == "-k" && argv[2] != nullptr && std::string(argv[3]) == "-ip" && argv[4] != nullptr) { diff --git a/dev/LibC++/__abi+unreachable.cc b/dev/LibC++/__abi+unreachable.cc index 9f436c0..90c50e1 100644 --- a/dev/LibC++/__abi+unreachable.cc +++ b/dev/LibC++/__abi+unreachable.cc @@ -1,7 +1,7 @@ /* ------------------------------------------- - - Copyright (C) 2025 Amlal El Mahrouss, all rights reserved. - + + Copyright (C) 2025 Amlal El Mahrouss, all rights reserved. + ------------------------------------------- */ #include @@ -12,6 +12,5 @@ static const int32_t __unreachable_code = 34; extern "C" void __libcompiler_unreachable(void) { std::base_process::signal(__unreachable_code); - while (1) - ; + while (1); } \ No newline at end of file diff --git a/dev/LibC++/__abi.h b/dev/LibC++/__abi.h index d2cc52f..48d4449 100644 --- a/dev/LibC++/__abi.h +++ b/dev/LibC++/__abi.h @@ -1,7 +1,7 @@ /* ------------------------------------------- - - Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. - + + Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. + ------------------------------------------- */ #pragma once diff --git a/dev/LibC++/base_exception.h b/dev/LibC++/base_exception.h index 9a599be..29f996b 100644 --- a/dev/LibC++/base_exception.h +++ b/dev/LibC++/base_exception.h @@ -6,9 +6,9 @@ #pragma once -#include -#include #include +#include +#include #include /// @author Amlal El Mahrouss (amlal@nekernel.org) @@ -34,4 +34,4 @@ inline void __throw_bad_array_new_length(const char* what) { __throw_general(what); __builtin_unreachable(); // prevent from continuing. } -} // namespace std::base_exception +} // namespace std::base_exception::abi diff --git a/dev/LibC++/defines.h b/dev/LibC++/defines.h index 2fedac5..21c43e4 100644 --- a/dev/LibC++/defines.h +++ b/dev/LibC++/defines.h @@ -16,7 +16,7 @@ extern "C" { #ifndef __GNUC__ -typedef __SIZE_TYPE__ size_t; +typedef __SIZE_TYPE__ size_t; typedef __SSIZE_TYPE__ ssize_t; typedef void* ptr_type; diff --git a/dev/ThirdParty/Dialogs.h b/dev/ThirdParty/Dialogs.h index 84e239f..ce50b81 100644 --- a/dev/ThirdParty/Dialogs.h +++ b/dev/ThirdParty/Dialogs.h @@ -175,7 +175,7 @@ namespace internal { #elif __EMSCRIPTEN__ void start(int exit_code); #else - void start_process(std::vector const& command); + void start_process(std::vector const& command); #endif ~executor(); @@ -490,10 +490,10 @@ inline settings::settings(bool resync) { #if _WIN32 flags(flag::is_vista) = internal::is_vista(); #elif !__APPLE__ - flags(flag::has_zenity) = check_program("zenity"); + flags(flag::has_zenity) = check_program("zenity"); flags(flag::has_matedialog) = check_program("matedialog"); - flags(flag::has_qarma) = check_program("qarma"); - flags(flag::has_kdialog) = check_program("kdialog"); + flags(flag::has_qarma) = check_program("qarma"); + flags(flag::has_kdialog) = check_program("kdialog"); // If multiple helpers are available, try to default to the best one if (flags(flag::has_zenity) && flags(flag::has_kdialog)) { @@ -540,7 +540,7 @@ inline bool settings::check_program(std::string const& program) { (void) program; return false; #else - int exit_code = -1; + int exit_code = -1; internal::executor async; async.start_process({"/bin/sh", "-c", "which " + program}); async.result(&exit_code); @@ -604,7 +604,7 @@ inline std::string path::home() { if (size_max != -1) len = size_t(size_max); #endif std::vector buf(len); - struct passwd pwd, *result; + struct passwd pwd, *result; if (getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result) == 0) return result->pw_dir; #endif return "/"; @@ -717,7 +717,7 @@ inline void internal::executor::start_process(std::vector const& co } close(in[1]); - m_fd = out[0]; + m_fd = out[0]; auto flags = fcntl(m_fd, F_GETFL); fcntl(m_fd, F_SETFL, flags | O_NONBLOCK); @@ -753,7 +753,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // FIXME: do something (void) timeout; #else - char buf[BUFSIZ]; + char buf[BUFSIZ]; ssize_t received = read(m_fd, buf, BUFSIZ); // Flawfinder: ignore if (received > 0) { m_stdout += std::string(buf, received); @@ -764,7 +764,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // (this happens when the calling application handles or ignores SIG_CHLD) and results in // waitpid() failing with ECHILD. Otherwise we assume the child is running and we sleep for // a little while. - int status; + int status; pid_t child = waitpid(m_pid, &status, WNOHANG); if (child != m_pid && (child >= 0 || errno != ECHILD)) { // FIXME: this happens almost always at first iteration @@ -782,8 +782,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) inline void internal::executor::stop() { // Loop until the user closes the dialog - while (!ready()) - ; + while (!ready()); } // dll implementation @@ -879,11 +878,11 @@ inline std::vector internal::dialog::desktop_helper() const { #if __APPLE__ return {"osascript"}; #else - return {flags(flag::has_zenity) ? "zenity" + return {flags(flag::has_zenity) ? "zenity" : flags(flag::has_matedialog) ? "matedialog" - : flags(flag::has_qarma) ? "qarma" - : flags(flag::has_kdialog) ? "kdialog" - : "echo"}; + : flags(flag::has_qarma) ? "qarma" + : flags(flag::has_kdialog) ? "kdialog" + : "echo"}; #endif } @@ -1125,9 +1124,9 @@ inline internal::file_dialog::file_dialog(type in_type, std::string const& title // Split the pattern list to check whether "*" is in there; if it // is, we have to disable filters because there is no mechanism in // OS X for the user to override the filter. - std::regex sep("\\s+"); - std::string filter_list; - bool has_filter = true; + std::regex sep("\\s+"); + std::string filter_list; + bool has_filter = true; std::sregex_token_iterator iter(patterns.begin(), patterns.end(), sep, -1); std::sregex_token_iterator end; for (; iter != end; ++iter) { @@ -1236,7 +1235,7 @@ inline std::vector internal::file_dialog::vector_result() { return m_vector_result; #else std::vector ret; - auto result = m_async->result(); + auto result = m_async->result(); for (;;) { // Split result along newline characters auto i = result.find('\n'); @@ -1569,7 +1568,7 @@ inline message::message(std::string const& title, std::string const& text, if_cancel = button::ok; break; } - m_mappings[1] = if_cancel; + m_mappings[1] = if_cancel; m_mappings[256] = if_cancel; // XXX: I think this was never correct script += " with icon "; switch (_icon) { @@ -1656,7 +1655,7 @@ inline message::message(std::string const& title, std::string const& text, if (_choice == choice::yes_no_cancel) flag += "cancel"; command.push_back(flag); if (_choice == choice::yes_no || _choice == choice::yes_no_cancel) { - m_mappings[0] = button::yes; + m_mappings[0] = button::yes; m_mappings[256] = button::no; } } diff --git a/tools/pef-amd64-cxxdrv.cc b/tools/pef-amd64-cxxdrv.cc index 21b68a0..274df09 100644 --- a/tools/pef-amd64-cxxdrv.cc +++ b/tools/pef-amd64-cxxdrv.cc @@ -9,11 +9,11 @@ #include #include +#include #include #include -#include -static auto kPath = "/usr/local/lib/libCompilerKit.dylib"; +static auto kPath = "/usr/local/lib/libCompilerKit.dylib"; static auto kSymbol = "CompilerCPlusPlusAMD64"; Int32 main(Int32 argc, Char const* argv[]) { @@ -26,8 +26,7 @@ Int32 main(Int32 argc, Char const* argv[]) { return EXIT_FAILURE; } - CompilerKitEntrypoint entrypoint_cxx = - (CompilerKitEntrypoint) dlsym(handler, kSymbol); + CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dlsym(handler, kSymbol); if (!entrypoint_cxx) { kStdOut; diff --git a/tools/pef-arm64-cdrv.cc b/tools/pef-arm64-cdrv.cc index 4dbf39e..1d2822b 100644 --- a/tools/pef-arm64-cdrv.cc +++ b/tools/pef-arm64-cdrv.cc @@ -9,11 +9,11 @@ #include #include +#include #include #include -#include -static auto kPath = "/usr/local/lib/libCompilerKit.dylib"; +static auto kPath = "/usr/local/lib/libCompilerKit.dylib"; static auto kSymbol = "CompilerCLangARM64"; Int32 main(Int32 argc, Char const* argv[]) { @@ -26,8 +26,7 @@ Int32 main(Int32 argc, Char const* argv[]) { return EXIT_FAILURE; } - CompilerKitEntrypoint entrypoint_cxx = - (CompilerKitEntrypoint) dlsym(handler, kSymbol); + CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dlsym(handler, kSymbol); if (!entrypoint_cxx) { kStdOut; -- cgit v1.2.3