diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-08 01:57:30 -0500 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-08 01:57:30 -0500 |
| commit | 2ddaf86857828500235e8b8a65c11bb2dd91b8be (patch) | |
| tree | 46899c14955bf356be2331e63c181afd4089d982 | |
| parent | 9f7c44f1577f194cb76b03ac45a2af542a86c8b9 (diff) | |
chore! breaking API changes and new APIs introduced.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
20 files changed, 174 insertions, 177 deletions
diff --git a/include/CompilerKit/AST.h b/include/CompilerKit/AST.h index 3987f13..2cefed7 100644 --- a/include/CompilerKit/AST.h +++ b/include/CompilerKit/AST.h @@ -8,15 +8,16 @@ #include <CompilerKit/CodeGenerator.h> #include <vector> +#include "CompilerKit/Detail/Config.h" -#define CK_COMPILER_FRONTEND : public ::CompilerKit::CompilerFrontendInterface +#define CK_COMPILER_FRONTEND : public ::CompilerKit::ICompilerFrontend namespace CompilerKit { inline static auto kInvalidFrontend = "(null)"; struct SyntaxLeafList; struct SyntaxLeafList; -struct CompilerKeyword; +struct SyntaxKeyword; /// =========================================================== /// /// @note we want to do that to separate keywords. @@ -59,34 +60,40 @@ enum KeywordKind { kKeywordKindGreaterEq, kKeywordKindLessEq, kKeywordKindPtr, + kKeywordKindClassStart, + kKeywordKindClassEnd, + kKeywordKindMethodStart, + kKeywordKindMethodEnd, kKeywordKindCount = kKeywordKindPtr - kKeywordKindNamespace + 1, }; /// =========================================================== /// /// \brief Compiler keyword information struct. /// =========================================================== /// -struct CompilerKeyword { - CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {} +struct SyntaxKeyword { + SyntaxKeyword(STLString name, KeywordKind kind) : fKeywordName(name), fKeywordKind(kind) {} - STLString keyword_name{""}; - KeywordKind keyword_kind{kKeywordKindInvalid}; + STLString fKeywordName{""}; + KeywordKind fKeywordKind{kKeywordKindInvalid}; }; struct SyntaxLeafList final { struct SyntaxLeaf final { - Int32 fUserType{0U}; - CompilerKeyword fUserData{"", kKeywordKindInvalid}; + Int32 fUserType{0U}; + SyntaxKeyword fUserData{"", kKeywordKindInvalid}; STLString fUserValue{""}; struct SyntaxLeaf* fNext{nullptr}; }; - std::vector<SyntaxLeaf> fLeafList; - SizeType fNumLeafs{0}; + using ArrayType = std::vector<SyntaxLeaf>; - SizeType SizeOf() { return fNumLeafs; } - std::vector<SyntaxLeaf>& Get() { return fLeafList; } - SyntaxLeaf& At(SizeType index) { return fLeafList[index]; } + ArrayType fLeafList; + SizeType fNumLeafs{0}; + + SizeType NumLeafs() { return fNumLeafs; } + ArrayType& Get() { return fLeafList; } + SyntaxLeaf& At(const SizeType& index) { return fLeafList[index]; } }; /// =========================================================== /// @@ -95,7 +102,7 @@ struct SyntaxLeafList final { /// \param needle the string we search for. /// \return if we found it or not. /// =========================================================== /// -bool find_word(STLString haystack, STLString needle) noexcept; +bool ast_find_needle(STLString haystack, STLString needle) noexcept; /// =========================================================== /// /// find a word within strict conditions and returns a range of it. @@ -103,30 +110,29 @@ bool find_word(STLString haystack, STLString needle) noexcept; /// \param needle /// \return position of needle. /// =========================================================== /// -SizeType find_word_range(STLString haystack, STLString needle) noexcept; +SizeType ast_find_needle_range(STLString haystack, STLString needle) noexcept; /// =========================================================== /// /// @brief Compiler backend, implements a frontend, such as C, C++... /// See Toolchain, for some examples. /// =========================================================== /// -class CompilerFrontendInterface { +class ICompilerFrontend { public: - explicit CompilerFrontendInterface() = default; - virtual ~CompilerFrontendInterface() = default; + explicit ICompilerFrontend() = default; + virtual ~ICompilerFrontend() = default; - NECTI_COPY_DEFAULT(CompilerFrontendInterface); + NECTI_COPY_DEFAULT(ICompilerFrontend) /// =========================================================== /// - // NOTE: cast this to your user defined ast. + /// NOTE: cast this to your user defined ast. /// =========================================================== /// - typedef VoidPtr AstType; + using AstType = VoidPtr; /// =========================================================== /// //! @brief Compile a syntax tree ouf of the text. //! Also takes the source file name for metadata. /// =========================================================== /// - - virtual CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) = 0; + virtual SyntaxLeafList::SyntaxLeaf Compile(STLString text, STLString file) = 0; /// =========================================================== /// //! @brief What language are we dealing with? diff --git a/include/CompilerKit/AST.inl b/include/CompilerKit/AST.inl index 3dc9456..c051815 100644 --- a/include/CompilerKit/AST.inl +++ b/include/CompilerKit/AST.inl @@ -9,7 +9,7 @@ namespace CompilerKit { /// \param haystack base string /// \param needle the string we search for. /// \return if we found it or not. -inline bool find_word(STLString haystack, STLString needle) noexcept { +inline bool ast_find_needle(STLString haystack, STLString needle) noexcept { auto index = haystack.find(needle); // check for needle validity. @@ -31,7 +31,7 @@ inline bool find_word(STLString haystack, STLString needle) noexcept { /// \param haystack /// \param needle /// \return position of needle. -inline SizeType find_word_range(STLString haystack, STLString needle) noexcept { +inline SizeType ast_find_needle_range(STLString haystack, STLString needle) noexcept { auto index = haystack.find(needle); // check for needle validity. @@ -50,14 +50,14 @@ inline SizeType find_word_range(STLString haystack, STLString needle) noexcept { /// =========================================================== /// //! @brief What language are we dealing with? /// =========================================================== /// -inline const char* CompilerFrontendInterface::Language() { +inline const char* ICompilerFrontend::Language() { return kInvalidFrontend; } /// =========================================================== /// /// @brief Checks if language is a valid frontend. /// =========================================================== /// -inline bool CompilerFrontendInterface::IsValid() { +inline bool ICompilerFrontend::IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; } } // namespace CompilerKit
\ No newline at end of file diff --git a/include/CompilerKit/Detail/32x0.h b/include/CompilerKit/Detail/32x0.h index fc3e0e9..7172a2d 100644 --- a/include/CompilerKit/Detail/32x0.h +++ b/include/CompilerKit/Detail/32x0.h @@ -9,8 +9,8 @@ #include <CompilerKit/Detail/Config.h> #include <vector> -// @brief Open32x0 support. -// @file Detail/32x0.h +/// @brief Open32x0 support. +/// @file Detail/32x0.h #define CK_ASM_OPCODE(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ {.fName = __NAME, .fOpcode = __OPCODE, .fFunct3 = __FUNCT3, .fFunct7 = __FUNCT7}, diff --git a/include/CompilerKit/Detail/64x0.h b/include/CompilerKit/Detail/64x0.h index ba539f6..ad909dc 100644 --- a/include/CompilerKit/Detail/64x0.h +++ b/include/CompilerKit/Detail/64x0.h @@ -9,8 +9,8 @@ #include <CompilerKit/Detail/Config.h> #include <vector> -// @brief Open64x0 support. -// @file Detail/64x0.h +/// @brief Open64x0 support. +/// @file Detail/64x0.h #define CK_ASM_OPCODE(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ {.fName = __NAME, .fOpcode = __OPCODE, .fFunct3 = __FUNCT3, .fFunct7 = __FUNCT7}, diff --git a/include/CompilerKit/Detail/AMD64.h b/include/CompilerKit/Detail/AMD64.h index a123c02..053b0b0 100644 --- a/include/CompilerKit/Detail/AMD64.h +++ b/include/CompilerKit/Detail/AMD64.h @@ -9,8 +9,8 @@ #include <CompilerKit/Detail/Config.h> #include <vector> -// @brief AMD64 support. -// @file Detail/AMD64.h +/// @brief AMD64 support. +/// @file Detail/AMD64.h #define CK_ASM_OPCODE(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE}, diff --git a/include/CompilerKit/ErrorOr.h b/include/CompilerKit/ErrorOr.h index 100624e..db8339a 100644 --- a/include/CompilerKit/ErrorOr.h +++ b/include/CompilerKit/ErrorOr.h @@ -29,6 +29,8 @@ class ErrorOr final { ~ErrorOr() = default; public: + using RefType = Ref<T>; + explicit ErrorOr(ErrorT err) : mId(err) {} explicit ErrorOr(std::nullptr_t null) {} explicit ErrorOr(T klass) : mRef(klass) {} @@ -36,7 +38,7 @@ class ErrorOr final { ErrorOr& operator=(const ErrorOr&) = default; ErrorOr(const ErrorOr&) = default; - Ref<T>& Leak() { return mRef; } + RefType& Leak() { return mRef; } ErrorT Error() { return mId; } @@ -45,8 +47,8 @@ class ErrorOr final { explicit operator bool() { return mRef; } private: - Ref<T> mRef; - ErrorT mId{0}; + RefType mRef; + ErrorT mId{0}; }; using ErrorOrAny = ErrorOr<VoidPtr>; diff --git a/include/CompilerKit/Utilities/Assembler.h b/include/CompilerKit/Utilities/Assembler.h index afe95d1..ef1cf18 100644 --- a/include/CompilerKit/Utilities/Assembler.h +++ b/include/CompilerKit/Utilities/Assembler.h @@ -17,18 +17,20 @@ namespace CompilerKit { /// @return A numbercast of 32-bit width. inline NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { if (lineBuffer.empty()) return {}; + if (lineBuffer.find(numberKey) == STLString::npos) return {}; auto pos = lineBuffer.find(numberKey) + numberKey.size(); - while (lineBuffer[pos] == ' ') { - ++pos; - } + if (pos > lineBuffer.size()) return {}; + if ((pos + 1) > lineBuffer.size()) return {}; + + while (lineBuffer[pos] == ' ') ++pos; switch (lineBuffer[pos + 1]) { case 'x': { if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 16); !res) { if (errno != 0) { - CompilerKit::Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit"); + Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit"); throw std::runtime_error("invalid_hex"); } } @@ -44,7 +46,7 @@ inline NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { case 'b': { if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 2); !res) { if (errno != 0) { - CompilerKit::Detail::print_error("invalid binary number:" + lineBuffer, "CompilerKit"); + Detail::print_error("invalid binary number:" + lineBuffer, "CompilerKit"); throw std::runtime_error("invalid_bin"); } } @@ -60,7 +62,7 @@ inline NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { case 'o': { if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 7); !res) { if (errno != 0) { - CompilerKit::Detail::print_error("invalid octal number: " + lineBuffer, "CompilerKit"); + Detail::print_error("invalid octal number: " + lineBuffer, "CompilerKit"); throw std::runtime_error("invalid_octal"); } } @@ -76,7 +78,7 @@ inline NumberCast32 GetNumber32(STLString lineBuffer, STLString numberKey) { default: { if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 10); !res) { if (errno != 0) { - CompilerKit::Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit"); + Detail::print_error("invalid hex number: " + lineBuffer, "CompilerKit"); throw std::runtime_error("invalid_hex"); } } diff --git a/include/CompilerKit/Utilities/DLL.h b/include/CompilerKit/Utilities/DLL.h index 5bfe032..490017e 100644 --- a/include/CompilerKit/Utilities/DLL.h +++ b/include/CompilerKit/Utilities/DLL.h @@ -10,21 +10,18 @@ #include <dlfcn.h> #include <mutex> -struct CompilerKitDylibTraits; +namespace CompilerKit { +struct DLLTraits final { + typedef Int32 (*Entrypoint)(Int32 argc, Char const* argv[]); + using DLL = VoidPtr; -typedef Int32 (*CompilerKitEntrypoint)(Int32 argc, Char const* argv[]); -typedef VoidPtr CompilerKitDylib; + DLL fDylib{nullptr}; + Entrypoint fEntrypoint{nullptr}; + std::mutex fMutex; -struct CompilerKitDylibTraits final { - CompilerKitDylib fDylib{nullptr}; - CompilerKitEntrypoint fEntrypoint{nullptr}; - std::mutex fMutex; + explicit operator bool() { return fDylib && fEntrypoint; } - explicit operator bool() { - return fDylib && fEntrypoint; - } - - CompilerKitDylibTraits& operator()(const Char* path, const Char* fEntrypoint) { + DLLTraits& operator()(const Char* path, const Char* fEntrypoint) { std::lock_guard<std::mutex> lock(this->fMutex); if (!path || !fEntrypoint) return *this; @@ -40,7 +37,7 @@ struct CompilerKitDylibTraits final { return *this; } - this->fEntrypoint = (CompilerKitEntrypoint) dlsym(this->fDylib, fEntrypoint); + this->fEntrypoint = (Entrypoint) dlsym(this->fDylib, fEntrypoint); if (!this->fEntrypoint) { dlclose(this->fDylib); @@ -52,11 +49,11 @@ struct CompilerKitDylibTraits final { return *this; } - NECTI_COPY_DELETE(CompilerKitDylibTraits); + NECTI_COPY_DELETE(DLLTraits) - CompilerKitDylibTraits() = default; + explicit DLLTraits() = default; - ~CompilerKitDylibTraits() { + ~DLLTraits() { if (this->fDylib) { dlclose(this->fDylib); this->fDylib = nullptr; @@ -65,3 +62,4 @@ struct CompilerKitDylibTraits final { this->fEntrypoint = nullptr; } }; +} // namespace CompilerKit
\ No newline at end of file diff --git a/src/CompilerKit/src/Assemblers/Assembler+64x0.cc b/src/CompilerKit/src/Assemblers/Assembler+64x0.cc index 3fd588a..35a6bb2 100644 --- a/src/CompilerKit/src/Assemblers/Assembler+64x0.cc +++ b/src/CompilerKit/src/Assemblers/Assembler+64x0.cc @@ -267,7 +267,7 @@ asm_fail_exit: static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the ld // that we need this symbol. - if (CompilerKit::find_word(line, "extern_segment")) { + if (CompilerKit::ast_find_needle(line, "extern_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_extern_segment_bin"); @@ -327,7 +327,7 @@ static bool asm_read_attributes(std::string line) { // public_segment is a special keyword used by Assembler64x0 to tell the AE output stage to // mark this section as a header. it currently supports .code64, .data64., // .zero64 - else if (CompilerKit::find_word(line, "public_segment")) { + else if (CompilerKit::ast_find_needle(line, "public_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_public_segment_bin"); @@ -413,9 +413,9 @@ bool is_valid_64x0(std::string str) { std::string CompilerKit::Encoder64x0::CheckLine(std::string line, std::string file) { std::string err_str; - if (line.empty() || CompilerKit::find_word(line, "extern_segment") || - CompilerKit::find_word(line, "public_segment") || line.find('#') != std::string::npos || - CompilerKit::find_word(line, ";")) { + if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") || + CompilerKit::ast_find_needle(line, "public_segment") || line.find('#') != std::string::npos || + CompilerKit::ast_find_needle(line, ";")) { if (line.find('#') != std::string::npos) { line.erase(line.find('#')); } else if (line.find(';') != std::string::npos) { @@ -497,7 +497,7 @@ std::string CompilerKit::Encoder64x0::CheckLine(std::string line, std::string fi // if it is like that -> addr1, 0x0 if (auto it = std::find(filter_inst.begin(), filter_inst.end(), opcode64x0.fName); it == filter_inst.cend()) { - if (CompilerKit::find_word(line, opcode64x0.fName)) { + if (CompilerKit::ast_find_needle(line, opcode64x0.fName)) { if (!isspace(line[line.find(opcode64x0.fName) + strlen(opcode64x0.fName)])) { err_str += "\nMissing space between "; err_str += opcode64x0.fName; @@ -612,11 +612,11 @@ bool CompilerKit::Encoder64x0::WriteNumber(const std::size_t& pos, std::string& ///////////////////////////////////////////////////////////////////////////////////////// bool CompilerKit::Encoder64x0::WriteLine(std::string line, std::string file) { - if (CompilerKit::find_word(line, "public_segment ")) return true; + if (CompilerKit::ast_find_needle(line, "public_segment ")) return true; for (auto& opcode64x0 : kOpcodes64x0) { // strict check here - if (CompilerKit::find_word(line, opcode64x0.fName) && CompilerKit::Detail::algorithm::is_valid_64x0(line)) { + if (CompilerKit::ast_find_needle(line, opcode64x0.fName) && CompilerKit::Detail::algorithm::is_valid_64x0(line)) { std::string name(opcode64x0.fName); std::string jump_label, cpy_jump_label; diff --git a/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc index 5b3d665..e69d4b6 100644 --- a/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc +++ b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cc @@ -338,7 +338,7 @@ asm_fail_exit: static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the ld // that we need this symbol. - if (CompilerKit::find_word(line, "extern_segment")) { + if (CompilerKit::ast_find_needle(line, "extern_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_extern_segment_bin"); @@ -397,7 +397,7 @@ static bool asm_read_attributes(std::string line) { // public_segment is a special keyword used by AssemblerAMD64 to tell the AE output stage to // mark this section as a header. it currently supports .code64, .data64 and // .zero64. - else if (CompilerKit::find_word(line, "public_segment")) { + else if (CompilerKit::ast_find_needle(line, "public_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_public_segment_bin"); @@ -494,9 +494,9 @@ bool is_valid_amd64(std::string str) { std::string CompilerKit::EncoderAMD64::CheckLine(std::string line, std::string file) { std::string err_str; - if (line.empty() || CompilerKit::find_word(line, "extern_segment") || - CompilerKit::find_word(line, "public_segment") || - CompilerKit::find_word(line, kAssemblerPragmaSymStr) || CompilerKit::find_word(line, ";") || + if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") || + CompilerKit::ast_find_needle(line, "public_segment") || + CompilerKit::ast_find_needle(line, kAssemblerPragmaSymStr) || CompilerKit::ast_find_needle(line, ";") || line[0] == kAssemblerPragmaSym) { if (line.find(';') != std::string::npos) { line.erase(line.find(';')); @@ -547,7 +547,7 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string line, std::string f } } for (auto& opcodeAMD64 : kOpcodesAMD64) { - if (CompilerKit::find_word(line, opcodeAMD64.fName)) { + if (CompilerKit::ast_find_needle(line, opcodeAMD64.fName)) { return err_str; } } @@ -952,7 +952,7 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string ///////////////////////////////////////////////////////////////////////////////////////// bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) { - if (CompilerKit::find_word(line, "public_segment ")) return true; + if (CompilerKit::ast_find_needle(line, "public_segment ")) return true; struct RegMapAMD64 { CompilerKit::STLString fName; @@ -970,7 +970,7 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string line, std::string file) { for (auto& opcodeAMD64 : kOpcodesAMD64) { // strict check here - if (CompilerKit::find_word(line, opcodeAMD64.fName) && + if (CompilerKit::ast_find_needle(line, opcodeAMD64.fName) && CompilerKit::Detail::algorithm::is_valid_amd64(line)) { foundInstruction = true; std::string name(opcodeAMD64.fName); diff --git a/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc b/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc index 3bce0ff..c4e4fb6 100644 --- a/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc +++ b/src/CompilerKit/src/Assemblers/Assembler+ARM64.cc @@ -272,7 +272,7 @@ asm_fail_exit: static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the li // that we need this symbol. - if (CompilerKit::find_word(line, "extern_segment")) { + if (CompilerKit::ast_find_needle(line, "extern_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_extern_segment_bin"); @@ -331,7 +331,7 @@ static bool asm_read_attributes(std::string line) { // public_segment is a special keyword used by Assembler to tell the AE output stage to // mark this section as a header. it currently supports .code64, .data64., // .zero64 - else if (CompilerKit::find_word(line, "public_segment")) { + else if (CompilerKit::ast_find_needle(line, "public_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_public_segment_bin"); @@ -417,9 +417,9 @@ bool is_valid_arm64(std::string str) { std::string CompilerKit::EncoderARM64::CheckLine(std::string line, std::string file) { std::string err_str; - if (line.empty() || CompilerKit::find_word(line, "extern_segment") || - CompilerKit::find_word(line, "public_segment") || line.find('#') != std::string::npos || - CompilerKit::find_word(line, ";")) { + if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") || + CompilerKit::ast_find_needle(line, "public_segment") || line.find('#') != std::string::npos || + CompilerKit::ast_find_needle(line, ";")) { if (line.find('#') != std::string::npos) { line.erase(line.find('#')); } else if (line.find(';') != std::string::npos) { @@ -578,7 +578,7 @@ bool CompilerKit::EncoderARM64::WriteNumber(const std::size_t& pos, std::string& ///////////////////////////////////////////////////////////////////////////////////////// bool CompilerKit::EncoderARM64::WriteLine(std::string line, std::string file) { - if (CompilerKit::find_word(line, "public_segment")) return false; + if (CompilerKit::ast_find_needle(line, "public_segment")) return false; if (!CompilerKit::Detail::algorithm::is_valid_arm64(line)) return false; diff --git a/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc b/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc index 4bb9876..6c698bd 100644 --- a/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc +++ b/src/CompilerKit/src/Assemblers/Assembler+PowerPC.cc @@ -272,7 +272,7 @@ asm_fail_exit: static bool asm_read_attributes(std::string line) { // extern_segment is the opposite of public_segment, it signals to the li // that we need this symbol. - if (CompilerKit::find_word(line, "extern_segment")) { + if (CompilerKit::ast_find_needle(line, "extern_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid extern_segment directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_extern_segment_bin"); @@ -331,7 +331,7 @@ static bool asm_read_attributes(std::string line) { // public_segment is a special keyword used by AssemblerPower to tell the AE output stage to // mark this section as a header. it currently supports .code64, .data64., // .zero64 - else if (CompilerKit::find_word(line, "public_segment")) { + else if (CompilerKit::ast_find_needle(line, "public_segment")) { if (kOutputAsBinary) { CompilerKit::Detail::print_error("Invalid public_segment directive in flat binary mode.", "CompilerKit"); throw std::runtime_error("invalid_public_segment_bin"); @@ -417,9 +417,9 @@ bool is_valid_power64(std::string str) { std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string file) { std::string err_str; - if (line.empty() || CompilerKit::find_word(line, "extern_segment") || - CompilerKit::find_word(line, "public_segment") || line.find('#') != std::string::npos || - CompilerKit::find_word(line, ";")) { + if (line.empty() || CompilerKit::ast_find_needle(line, "extern_segment") || + CompilerKit::ast_find_needle(line, "public_segment") || line.find('#') != std::string::npos || + CompilerKit::ast_find_needle(line, ";")) { if (line.find('#') != std::string::npos) { line.erase(line.find('#')); } else if (line.find(';') != std::string::npos) { @@ -485,7 +485,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string std::vector<std::string> filter_inst = {"blr", "bl", "sc"}; for (auto& opcode_risc : kOpcodesPowerPC) { - if (CompilerKit::find_word(line, opcode_risc.name)) { + if (CompilerKit::ast_find_needle(line, opcode_risc.name)) { for (auto& op : operands_inst) { // if only the instruction was found. if (line == op) { @@ -499,7 +499,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string line, std::string // if it is like that -> addr1, 0x0 if (auto it = std::find(filter_inst.begin(), filter_inst.end(), opcode_risc.name); it == filter_inst.cend()) { - if (CompilerKit::find_word(line, opcode_risc.name)) { + if (CompilerKit::ast_find_needle(line, opcode_risc.name)) { if (!isspace(line[line.find(opcode_risc.name) + strlen(opcode_risc.name)])) { err_str += "\nMissing space between "; err_str += opcode_risc.name; @@ -615,12 +615,12 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t& pos, std::strin ///////////////////////////////////////////////////////////////////////////////////////// bool CompilerKit::EncoderPowerPC::WriteLine(std::string line, std::string file) { - if (CompilerKit::find_word(line, "public_segment")) return false; + if (CompilerKit::ast_find_needle(line, "public_segment")) return false; if (!CompilerKit::Detail::algorithm::is_valid_power64(line)) return false; for (auto& opcode_risc : kOpcodesPowerPC) { // strict check here - if (CompilerKit::find_word(line, opcode_risc.name)) { + if (CompilerKit::ast_find_needle(line, opcode_risc.name)) { std::string name(opcode_risc.name); std::string jump_label, cpy_jump_label; std::vector<size_t> found_registers_index; diff --git a/src/CompilerKit/src/Compilers/CCompiler+64x0.cc b/src/CompilerKit/src/Compilers/CCompiler+64x0.cc index 8437722..06768eb 100644 --- a/src/CompilerKit/src/Compilers/CCompiler+64x0.cc +++ b/src/CompilerKit/src/Compilers/CCompiler+64x0.cc @@ -130,7 +130,7 @@ static bool kIfFound = false; static size_t kBracesCount = 0UL; /* @brief C compiler backend for C */ -class CompilerFrontend64x0 final : public CompilerKit::CompilerFrontendInterface { +class CompilerFrontend64x0 final : public CompilerKit::ICompilerFrontend { public: explicit CompilerFrontend64x0() = default; ~CompilerFrontend64x0() override = default; @@ -821,7 +821,7 @@ cc_next: // extern does not declare anything, it extern_segments a variable. // so that's why it's not declare upper. - if (CompilerKit::find_word(ln, "extern")) { + if (CompilerKit::ast_find_needle(ln, "extern")) { auto substr = ln.substr(ln.find("extern") + strlen("extern")); kCompilerVariables.push_back({.fValue = substr}); } @@ -878,7 +878,7 @@ cc_next: skip_braces_check: for (auto& key : kCompilerTypes) { - if (CompilerKit::find_word(ln, key.fName)) { + if (CompilerKit::ast_find_needle(ln, key.fName)) { if (isdigit(ln[ln.find(key.fName) + key.fName.size() + 1])) { err_str += "\nNumber cannot be set for "; err_str += key.fName; @@ -951,9 +951,9 @@ skip_braces_check: } if (ln.find('(') != std::string::npos) { - if (ln.find(';') == std::string::npos && !CompilerKit::find_word(ln, "|") && - !CompilerKit::find_word(ln, "||") && !CompilerKit::find_word(ln, "&") && - !CompilerKit::find_word(ln, "&&") && !CompilerKit::find_word(ln, "~")) { + if (ln.find(';') == std::string::npos && !CompilerKit::ast_find_needle(ln, "|") && + !CompilerKit::ast_find_needle(ln, "||") && !CompilerKit::ast_find_needle(ln, "&") && + !CompilerKit::ast_find_needle(ln, "&&") && !CompilerKit::ast_find_needle(ln, "~")) { bool found_func = false; size_t i = ln.find('('); std::vector<char> opens; @@ -1105,7 +1105,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE { std::vector<std::string> access_keywords = {"->", "."}; for (auto& access_ident : access_keywords) { - if (CompilerKit::find_word(leaf.fUserValue, access_ident)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, access_ident)) { for (auto& struc : kState.kStructMap) { /// TODO: } @@ -1113,7 +1113,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE { } for (auto& keyword : keywords) { - if (CompilerKit::find_word(leaf.fUserValue, keyword)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, keyword)) { std::size_t cnt = 0UL; for (auto& reg : kState.kStackFrame) { @@ -1137,7 +1137,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE { } } - if (CompilerKit::find_word(leaf.fUserValue, needle)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, needle)) { if (leaf.fUserValue.find("extern_segment " + needle) != std::string::npos) { std::string range = "extern_segment " + needle; leaf.fUserValue.replace(leaf.fUserValue.find("extern_segment " + needle), diff --git a/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc b/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc index 45ec9a3..ad4227b 100644 --- a/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc +++ b/src/CompilerKit/src/Compilers/CCompiler+ARM64.cc @@ -132,7 +132,7 @@ static bool kIfFound = false; static size_t kBracesCount = 0UL; /* @brief C compiler backend for C */ -class CompilerFrontendARM64 final : public CompilerKit::CompilerFrontendInterface { +class CompilerFrontendARM64 final : public CompilerKit::ICompilerFrontend { public: explicit CompilerFrontendARM64() = default; ~CompilerFrontendARM64() override = default; @@ -821,7 +821,7 @@ cc_next: // extern does not declare anything, it extern_segments a variable. // so that's why it's not declare upper. - if (CompilerKit::find_word(ln, "extern")) { + if (CompilerKit::ast_find_needle(ln, "extern")) { auto substr = ln.substr(ln.find("extern") + strlen("extern")); kCompilerVariables.push_back({.fValue = substr}); } @@ -878,7 +878,7 @@ cc_next: skip_braces_check: for (auto& key : kCompilerTypes) { - if (CompilerKit::find_word(ln, key.fName)) { + if (CompilerKit::ast_find_needle(ln, key.fName)) { if (isdigit(ln[ln.find(key.fName) + key.fName.size() + 1])) { err_str += "\nNumber cannot be set for "; err_str += key.fName; @@ -951,9 +951,9 @@ skip_braces_check: } if (ln.find('(') != std::string::npos) { - if (ln.find(';') == std::string::npos && !CompilerKit::find_word(ln, "|") && - !CompilerKit::find_word(ln, "||") && !CompilerKit::find_word(ln, "&") && - !CompilerKit::find_word(ln, "&&") && !CompilerKit::find_word(ln, "~")) { + if (ln.find(';') == std::string::npos && !CompilerKit::ast_find_needle(ln, "|") && + !CompilerKit::ast_find_needle(ln, "||") && !CompilerKit::ast_find_needle(ln, "&") && + !CompilerKit::ast_find_needle(ln, "&&") && !CompilerKit::ast_find_needle(ln, "~")) { bool found_func = false; size_t i = ln.find('('); std::vector<char> opens; @@ -1105,7 +1105,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE { std::vector<std::string> access_keywords = {"->", "."}; for (auto& access_ident : access_keywords) { - if (CompilerKit::find_word(leaf.fUserValue, access_ident)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, access_ident)) { for (auto& struc : kState.kStructMap) { /// TODO: } @@ -1113,7 +1113,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE { } for (auto& keyword : keywords) { - if (CompilerKit::find_word(leaf.fUserValue, keyword)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, keyword)) { std::size_t cnt = 0UL; for (auto& reg : kState.kStackFrame) { @@ -1137,7 +1137,7 @@ class AssemblyCCInterface final CK_ASSEMBLY_INTERFACE { } } - if (CompilerKit::find_word(leaf.fUserValue, needle)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, needle)) { if (leaf.fUserValue.find("extern_segment " + needle) != std::string::npos) { std::string range = "extern_segment " + needle; leaf.fUserValue.replace(leaf.fUserValue.find("extern_segment " + needle), diff --git a/src/CompilerKit/src/Compilers/CCompiler+Power64.cc b/src/CompilerKit/src/Compilers/CCompiler+Power64.cc index 7d5dc74..e123c3d 100644 --- a/src/CompilerKit/src/Compilers/CCompiler+Power64.cc +++ b/src/CompilerKit/src/Compilers/CCompiler+Power64.cc @@ -115,7 +115,7 @@ static bool kIfFound = false; static size_t kBracesCount = 0UL; /* @brief C compiler backend for C */ -class CompilerFrontendPower64 final : public CompilerKit::CompilerFrontendInterface { +class CompilerFrontendPower64 final : public CompilerKit::ICompilerFrontend { public: explicit CompilerFrontendPower64() = default; ~CompilerFrontendPower64() override = default; @@ -833,7 +833,7 @@ cc_next: // extern does not declare anything, it extern_segments a variable. // so that's why it's not declare upper. - if (CompilerKit::find_word(ln, "extern")) { + if (CompilerKit::ast_find_needle(ln, "extern")) { auto substr = ln.substr(ln.find("extern") + strlen("extern")); kCompilerVariables.push_back({.fValue = substr}); } @@ -890,7 +890,7 @@ cc_next: skip_braces_check: for (auto& key : kCompilerTypes) { - if (CompilerKit::find_word(ln, key.fName)) { + if (CompilerKit::ast_find_needle(ln, key.fName)) { if (isdigit(ln[ln.find(key.fName) + key.fName.size() + 1])) { err_str += "\nNumber cannot be set for "; err_str += key.fName; @@ -963,9 +963,9 @@ skip_braces_check: } if (ln.find('(') != std::string::npos) { - if (ln.find(';') == std::string::npos && !CompilerKit::find_word(ln, "|") && - !CompilerKit::find_word(ln, "||") && !CompilerKit::find_word(ln, "&") && - !CompilerKit::find_word(ln, "&&") && !CompilerKit::find_word(ln, "~")) { + if (ln.find(';') == std::string::npos && !CompilerKit::ast_find_needle(ln, "|") && + !CompilerKit::ast_find_needle(ln, "||") && !CompilerKit::ast_find_needle(ln, "&") && + !CompilerKit::ast_find_needle(ln, "&&") && !CompilerKit::ast_find_needle(ln, "~")) { bool found_func = false; size_t i = ln.find('('); std::vector<char> opens; @@ -1117,7 +1117,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE { std::vector<std::string> access_keywords = {"->", "."}; for (auto& access_ident : access_keywords) { - if (CompilerKit::find_word(leaf.fUserValue, access_ident)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, access_ident)) { for (auto& struc : kState.kStructMap) { /// TODO: } @@ -1125,7 +1125,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE { } for (auto& keyword : keywords) { - if (CompilerKit::find_word(leaf.fUserValue, keyword)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, keyword)) { std::size_t cnt = 0UL; for (auto& reg : kState.kStackFrame) { @@ -1149,7 +1149,7 @@ class AssemblyMountpointCLang final CK_ASSEMBLY_INTERFACE { } } - if (CompilerKit::find_word(leaf.fUserValue, needle)) { + if (CompilerKit::ast_find_needle(leaf.fUserValue, needle)) { if (leaf.fUserValue.find("extern_segment ") != std::string::npos) { std::string range = "extern_segment "; leaf.fUserValue.replace(leaf.fUserValue.find(range), range.size(), ""); diff --git a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc index d93256d..c54cc53 100644 --- a/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc +++ b/src/CompilerKit/src/Compilers/CPlusPlusCompiler+AMD64.cc @@ -96,7 +96,7 @@ static Int32 kMachine = CompilerKit::AssemblyFactory::kArchAMD64; ///////////////////////////////////////// -static std::vector<CompilerKit::CompilerKeyword> kKeywords; +static std::vector<CompilerKit::SyntaxKeyword> kKeywords; ///////////////////////////////////////// @@ -166,11 +166,11 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (text.empty()) return syntax_tree; std::size_t index = 0UL; - std::vector<std::pair<CompilerKit::CompilerKeyword, std::size_t>> keywords_list; + std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list; for (auto& keyword : kKeywords) { - if (text.find(keyword.keyword_name) != std::string::npos) { - switch (keyword.keyword_kind) { + if (text.find(keyword.fKeywordName) != std::string::npos) { + switch (keyword.fKeywordKind) { case CompilerKit::kKeywordKindCommentInline: { break; } @@ -178,22 +178,22 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( break; } - std::size_t pos = text.find(keyword.keyword_name); + std::size_t pos = text.find(keyword.fKeywordName); if (pos == std::string::npos) continue; // can't go before start of string if (pos > 0 && text[pos - 1] == '+' && - keyword.keyword_kind == CompilerKit::kKeywordKindVariableAssign) + keyword.fKeywordKind == CompilerKit::kKeywordKindVariableAssign) continue; if (pos > 0 && text[pos - 1] == '-' && - keyword.keyword_kind == CompilerKit::kKeywordKindVariableAssign) + keyword.fKeywordKind == CompilerKit::kKeywordKindVariableAssign) continue; // don't go out of range - if ((pos + keyword.keyword_name.size()) < text.size() && - text[pos + keyword.keyword_name.size()] == '=' && - keyword.keyword_kind == CompilerKit::kKeywordKindVariableAssign) + if ((pos + keyword.fKeywordName.size()) < text.size() && + text[pos + keyword.fKeywordName.size()] == '=' && + keyword.fKeywordKind == CompilerKit::kKeywordKindVariableAssign) continue; keywords_list.emplace_back(std::make_pair(keyword, index)); @@ -202,15 +202,15 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( } for (auto& keyword : keywords_list) { - if (text.find(keyword.first.keyword_name) == CompilerKit::STLString::npos) continue; + if (text.find(keyword.first.fKeywordName) == CompilerKit::STLString::npos) continue; - switch (keyword.first.keyword_kind) { + switch (keyword.first.fKeywordKind) { case CompilerKit::KeywordKind::kKeywordKindClass: { ++kOnClassScope; break; } case CompilerKit::KeywordKind::kKeywordKindIf: { - std::size_t keywordPos = text.find(keyword.first.keyword_name); + std::size_t keywordPos = text.find(keyword.first.fKeywordName); std::size_t openParen = text.find("(", keywordPos); std::size_t closeParen = text.find(")", openParen); @@ -225,7 +225,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( if (expr.find(">=") != CompilerKit::STLString::npos) { auto left = text.substr( - text.find(keyword.first.keyword_name) + keyword.first.keyword_name.size() + 2, + text.find(keyword.first.fKeywordName) + keyword.first.fKeywordName.size() + 2, expr.find("<=") + strlen("<=")); auto right = text.substr(expr.find(">=") + strlen(">="), text.find(")") - 1); @@ -282,7 +282,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( CompilerKit::STLString symbol_name_fn = text; - symbol_name_fn.erase(symbol_name_fn.find(keyword.first.keyword_name)); + symbol_name_fn.erase(symbol_name_fn.find(keyword.first.fKeywordName)); for (auto& ch : symbol_name_fn) { if (ch == ' ') ch = '_'; @@ -388,43 +388,43 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( case CompilerKit::KeywordKind::kKeywordKindVariableAssign: { CompilerKit::STLString valueOfVar = ""; - if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindVariableInc) { + if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableInc) { valueOfVar = text.substr(text.find("+=") + 2); - } else if (keyword.first.keyword_kind == + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableDec) { valueOfVar = text.substr(text.find("-=") + 2); - } else if (keyword.first.keyword_kind == + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableAssign) { valueOfVar = text.substr(text.find("=") + 1); - } else if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { break; } while (valueOfVar.find(";") != CompilerKit::STLString::npos && - keyword.first.keyword_kind != CompilerKit::KeywordKind::kKeywordKindEndInstr) { + keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindEndInstr) { valueOfVar.erase(valueOfVar.find(";")); } CompilerKit::STLString varName = text; - if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindVariableInc) { + if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableInc) { varName.erase(varName.find("+=")); - } else if (keyword.first.keyword_kind == + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableDec) { varName.erase(varName.find("-=")); - } else if (keyword.first.keyword_kind == + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableAssign) { varName.erase(varName.find("=")); - } else if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { varName.erase(varName.find(";")); } static bool typeFound = false; for (auto& keyword : kKeywords) { - if (keyword.keyword_kind == CompilerKit::kKeywordKindType) { - if (text.find(keyword.keyword_name) != CompilerKit::STLString::npos) { - if (text[text.find(keyword.keyword_name)] == ' ') { + if (keyword.fKeywordKind == CompilerKit::kKeywordKindType) { + if (text.find(keyword.fKeywordName) != CompilerKit::STLString::npos) { + if (text[text.find(keyword.fKeywordName)] == ' ') { typeFound = false; continue; } @@ -439,8 +439,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( std::vector<CompilerKit::STLString> newVars; if (typeFound && - keyword.first.keyword_kind != CompilerKit::KeywordKind::kKeywordKindVariableInc && - keyword.first.keyword_kind != CompilerKit::KeywordKind::kKeywordKindVariableDec) { + keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindVariableInc && + keyword.first.fKeywordKind != CompilerKit::KeywordKind::kKeywordKindVariableDec) { if (kRegisterMap.size() > kRegisterList.size()) { ++kFunctionEmbedLevel; } @@ -531,9 +531,9 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( done: for (auto& keyword : kKeywords) { - if (keyword.keyword_kind == CompilerKit::kKeywordKindType && - varName.find(keyword.keyword_name) != CompilerKit::STLString::npos) { - varName.erase(varName.find(keyword.keyword_name), keyword.keyword_name.size()); + if (keyword.fKeywordKind == CompilerKit::kKeywordKindType && + varName.find(keyword.fKeywordName) != CompilerKit::STLString::npos) { + varName.erase(varName.find(keyword.fKeywordName), keyword.fKeywordName.size()); break; } } @@ -546,20 +546,20 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile( kRegisterMap.insert(kRegisterMap.end(), newVars.begin(), newVars.end()); if (keyword.second > 0 && - kKeywords[keyword.second - 1].keyword_kind == CompilerKit::kKeywordKindType || - kKeywords[keyword.second - 1].keyword_kind == CompilerKit::kKeywordKindTypePtr) { + kKeywords[keyword.second - 1].fKeywordKind == CompilerKit::kKeywordKindType || + kKeywords[keyword.second - 1].fKeywordKind == CompilerKit::kKeywordKindTypePtr) { syntax_tree.fUserValue = "\n"; continue; } - if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { + if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindEndInstr) { syntax_tree.fUserValue = "\n"; continue; } - if (keyword.first.keyword_kind == CompilerKit::KeywordKind::kKeywordKindVariableInc) { + if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableInc) { instr = "add "; - } else if (keyword.first.keyword_kind == + } else if (keyword.first.fKeywordKind == CompilerKit::KeywordKind::kKeywordKindVariableDec) { instr = "sub "; } diff --git a/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc index 4cf42dc..4e34ab3 100644 --- a/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc +++ b/src/CompilerKit/src/Preprocessor/Preprocessor+Generic.cc @@ -290,7 +290,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) { } for (auto macro : kMacros) { - if (CompilerKit::find_word(hdr_line, macro.fName)) { + if (CompilerKit::ast_find_needle(hdr_line, macro.fName)) { if (hdr_line.substr(hdr_line.find(macro.fName)).find(macro.fName + '(') != CompilerKit::STLString::npos) { if (!macro.fArgs.empty()) { diff --git a/src/Tools/cppdrv.cc b/src/Tools/cppdrv.cc index 05ffcec..95d4c3a 100644 --- a/src/Tools/cppdrv.cc +++ b/src/Tools/cppdrv.cc @@ -4,14 +4,11 @@ ======================================== */ -/// @file cxxdrv.cc +/// @file cppdrv.cc /// @brief NeCTI frontend preprocessor. #include <CompilerKit/Detail/Config.h> #include <CompilerKit/ErrorID.h> -#include <cstring> -#include <iostream> -#include <vector> CK_IMPORT_C int CPlusPlusPreprocessorMain(int argc, char const* argv[]); diff --git a/src/Tools/pef-amd64-cxxdrv.cc b/src/Tools/pef-amd64-cxxdrv.cc index 9c29a88..fa03d25 100644 --- a/src/Tools/pef-amd64-cxxdrv.cc +++ b/src/Tools/pef-amd64-cxxdrv.cc @@ -4,8 +4,8 @@ ======================================== */ -/// @file cxxdrv.cc -/// @brief NeCTI C++ frontend compiler. +/// @file pef-amd64-cxxdrv.cc +/// @brief NeCTI C++ frontend compiler for AMD64. #include <CompilerKit/Detail/Config.h> #include <CompilerKit/ErrorID.h> @@ -21,10 +21,10 @@ static auto kPath = "/usr/lib/libCompilerKit.so"; static auto kSymbol = "CompilerCPlusPlusAMD64"; Int32 main(Int32 argc, Char const* argv[]) { - CompilerKitDylibTraits dylib; + CompilerKit::DLLTraits dylib; dylib(kPath, kSymbol); - CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dylib.fEntrypoint; + CompilerKit::DLLTraits::Entrypoint entrypoint_cxx = reinterpret_cast<CompilerKit::DLLTraits::Entrypoint>(dylib.fEntrypoint); if (!entrypoint_cxx) { kStdOut; diff --git a/src/Tools/pef-arm64-cdrv.cc b/src/Tools/pef-arm64-cdrv.cc index 97812b7..3e6c3b2 100644 --- a/src/Tools/pef-arm64-cdrv.cc +++ b/src/Tools/pef-arm64-cdrv.cc @@ -4,8 +4,8 @@ ======================================== */ -/// @file cxxdrv.cc -/// @brief NeCTI C++ frontend compiler. +/// @file pef-arm-cdrv.cc +/// @brief NeCTI ARm64 C frontend compiler. #include <CompilerKit/Detail/Config.h> #include <CompilerKit/ErrorID.h> @@ -21,28 +21,20 @@ static auto kPath = "/usr/lib/libCompilerKit.so"; static auto kSymbol = "CompilerCLangARM64"; Int32 main(Int32 argc, Char const* argv[]) { - CompilerKitDylib handler = dlopen(kPath, RTLD_LAZY | RTLD_GLOBAL); + CompilerKit::DLLTraits dylib; + dylib(kPath, kSymbol); - if (!handler) { - kStdOut; - std::printf("error: Could not load dylib in %s: %s\n", kPath, dlerror()); - - return EXIT_FAILURE; - } - - CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dlsym(handler, kSymbol); + CompilerKit::DLLTraits::Entrypoint entrypoint_cxx = + reinterpret_cast<CompilerKit::DLLTraits::Entrypoint>(dylib.fEntrypoint); if (!entrypoint_cxx) { kStdOut; std::printf("error: Could not find entrypoint in %s: %s\n", kPath, dlerror()); - dlclose(handler); return EXIT_FAILURE; } auto ret = (entrypoint_cxx(argc, argv) == NECTI_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE; - dlclose(handler); - return ret; } |
