From f3a559490ca60b7e1ceecc61c114a9765ab8c8db Mon Sep 17 00:00:00 2001
From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com>
Date: Tue, 6 May 2025 17:38:22 +0100
Subject: [PATCH] General clean up
- Moved some classes from Lexer.h to seperate (non-Global files)
- Deleted dllmain as it wasn't used for the most part
---
Common/Common.vcxproj | 1 -
Common/Common.vcxproj.filters | 14 +++--------
Common/inc/Logger.h | 3 ---
Common/src/dllmain.cpp | 40 -----------------------------
IR-Generator/inc/Lexer.h | 47 ++---------------------------------
Lexer/Lexer.vcxproj | 4 +++
Lexer/Lexer.vcxproj.filters | 8 ++++++
Lexer/inc/LexerErrors.h | 25 +++++++++++++++++++
Lexer/inc/LexerInfo.h | 37 +++++++++++++++++++++++++++
Lexer/src/Lexer.cpp | 3 +++
Lexer/src/Token.cpp | 2 ++
11 files changed, 85 insertions(+), 99 deletions(-)
delete mode 100644 Common/src/dllmain.cpp
create mode 100644 Lexer/inc/LexerErrors.h
create mode 100644 Lexer/inc/LexerInfo.h
diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj
index 4d04ade..8744c21 100644
--- a/Common/Common.vcxproj
+++ b/Common/Common.vcxproj
@@ -159,7 +159,6 @@
-
Create
diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters
index eb71ae7..333be8b 100644
--- a/Common/Common.vcxproj.filters
+++ b/Common/Common.vcxproj.filters
@@ -9,31 +9,25 @@
{93995380-89BD-4b04-88EB-625FBE52EBFB}
h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
- {f3a1ae14-8b71-41d9-ba66-60c952867261}
-
Header Files
- Header Files\Sections
+ Header Files
- Header Files\Sections
+ Header Files
- Header Files\Sections
+ Header Files
- Header Files\Sections
+ Header Files
-
- Source Files
-
Source Files
diff --git a/Common/inc/Logger.h b/Common/inc/Logger.h
index 2887d9a..e53daeb 100644
--- a/Common/inc/Logger.h
+++ b/Common/inc/Logger.h
@@ -37,9 +37,6 @@ namespace LX
}
private:
- // Allows ProcAttach to manage the log //
- friend bool ProcAttach(HMODULE hModule);
-
// Initalises the log (Called by DllMain) //
static void Init();
diff --git a/Common/src/dllmain.cpp b/Common/src/dllmain.cpp
deleted file mode 100644
index dbcd676..0000000
--- a/Common/src/dllmain.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-// dllmain.cpp : Defines the entry point for the DLL application.
-#include
-
-namespace LX
-{
- // All the different functions that can be called by the system //
- // Currently all empty but here for easier future development //
-
- using DllFunc = bool(HMODULE);
-
- static bool ProcAttach(HMODULE hModule)
- {
- Log::Init(); // Initalises the log before the main process starts
- return true;
- }
-
- static bool ProcDetach(HMODULE hModule)
- {
- return true;
- }
-
- static bool ThreadAttach(HMODULE hModule) { return true; }
- static bool ThreadDetach(HMODULE hModule) { return true; }
-}
-
-BOOL __stdcall DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
-{
- // All the functions that might be called with their relevant state //
- static const std::unordered_map funcs =
- {
- { DLL_PROCESS_ATTACH, LX::ProcAttach },
- { DLL_PROCESS_DETACH, LX::ProcDetach },
- { DLL_THREAD_ATTACH , LX::ThreadAttach },
- { DLL_THREAD_DETACH , LX::ThreadDetach }
- };
-
- // Returns the output of the relavant function //
- return funcs.at(ul_reason_for_call)(hModule);
-}
-
diff --git a/IR-Generator/inc/Lexer.h b/IR-Generator/inc/Lexer.h
index 2fdaa7e..3d29019 100644
--- a/IR-Generator/inc/Lexer.h
+++ b/IR-Generator/inc/Lexer.h
@@ -7,51 +7,8 @@
namespace LX
{
- // Error type with index and character to alert the user that LX does not understand that symbol //
- struct InvalidCharInSource : public RuntimeError
- {
- GENERATE_LX_ERROR_REQUIRED_FUNCTION_DECLARATIONS;
-
- InvalidCharInSource(std::streamsize _col, std::streamsize _line, std::streamsize _index, char _invalid);
-
- static std::string* s_Source;
- static std::filesystem::path* s_SourceFile;
-
- std::streamsize col;
- std::streamsize line;
- std::streamsize index;
-
- char invalid;
- };
-
// Struct to store the current information of the lexer //
- struct LexerInfo
- {
- // Current trackers of where in the source it is //
-
- std::streamsize line = 1; // <- Lines start on 1 (probably because of non-programmer's)
- std::streamsize index = 0;
- std::streamsize column = 0; // <- Columns start on 1 (probably because of non-programmer's)
-
- // Trackers for when a multi-char token started //
-
- std::streamsize startOfWord = 0;
- std::streamsize startOfNumberLiteral = 0;
- std::streamsize startOfStringLiteral = 0;
-
- // Different flags of the lexer //
- // Stored as a bitset to minimse memory allocated (basically no difference, because only one exists at any given time) //
-
- bool isAlpha : 1 = false;
- bool isNumeric : 1 = false;
- bool inComment : 1 = false;
- bool inStringLiteral : 1 = false;
- bool isNextCharAlpha : 1 = false;
- bool isNextCharNumeric : 1 = false;
- bool wasLastCharAlpha : 1 = false;
- bool wasLastCharNumeric : 1 = false;
- bool lexingNumber : 1 = false;
- };
+ struct LexerInfo;
// Data type to store a more computer readable version of files
struct __declspec(novtable) Token final
@@ -104,7 +61,7 @@ namespace LX
// Constructor of the tokens to set their info //
Token(const TokenType _type, const LexerInfo& info, std::streamsize _length);
- //
+ // Works out the contents of the token and returns them as it is not stored in the token //
std::string GetContents() const;
// Type of the token //
diff --git a/Lexer/Lexer.vcxproj b/Lexer/Lexer.vcxproj
index b8dc572..a55931d 100644
--- a/Lexer/Lexer.vcxproj
+++ b/Lexer/Lexer.vcxproj
@@ -150,6 +150,10 @@
+
+
+
+
diff --git a/Lexer/Lexer.vcxproj.filters b/Lexer/Lexer.vcxproj.filters
index 3ebbd43..2238084 100644
--- a/Lexer/Lexer.vcxproj.filters
+++ b/Lexer/Lexer.vcxproj.filters
@@ -21,4 +21,12 @@
Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
\ No newline at end of file
diff --git a/Lexer/inc/LexerErrors.h b/Lexer/inc/LexerErrors.h
new file mode 100644
index 0000000..94a314e
--- /dev/null
+++ b/Lexer/inc/LexerErrors.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include
+
+#include
+
+namespace LX
+{
+ // Error type with index and character to alert the user that LX does not understand that symbol //
+ struct InvalidCharInSource : public RuntimeError
+ {
+ GENERATE_LX_ERROR_REQUIRED_FUNCTION_DECLARATIONS;
+
+ InvalidCharInSource(std::streamsize _col, std::streamsize _line, std::streamsize _index, char _invalid);
+
+ static std::string* s_Source;
+ static std::filesystem::path* s_SourceFile;
+
+ std::streamsize col;
+ std::streamsize line;
+ std::streamsize index;
+
+ char invalid;
+ };
+}
diff --git a/Lexer/inc/LexerInfo.h b/Lexer/inc/LexerInfo.h
new file mode 100644
index 0000000..f50efbd
--- /dev/null
+++ b/Lexer/inc/LexerInfo.h
@@ -0,0 +1,37 @@
+#include
+
+#include
+
+namespace LX
+{
+ // Struct to store the current information of the lexer //
+ struct LexerInfo
+ {
+ // Current trackers of where in the source it is //
+
+ std::streamsize line = 1; // <- Lines start on 1 (probably because of non-programmer's)
+ std::streamsize index = 0;
+ std::streamsize column = 0; // <- Columns start on 1 (probably because of non-programmer's). THEN WHY IS THIS SET TO 0
+
+ // Trackers for when a multi-char token started //
+
+ std::streamsize startOfWord = 0;
+ std::streamsize startOfNumberLiteral = 0;
+ std::streamsize startOfStringLiteral = 0;
+
+ // Different flags of the lexer //
+ // Stored as a bitset to minimse memory allocated //
+ // - Basically no difference, because only one exists at any given time //
+ // - But it is a cool C++ feature I like so I use it //
+
+ bool isAlpha : 1 = false;
+ bool isNumeric : 1 = false;
+ bool inComment : 1 = false;
+ bool inStringLiteral : 1 = false;
+ bool isNextCharAlpha : 1 = false;
+ bool isNextCharNumeric : 1 = false;
+ bool wasLastCharAlpha : 1 = false;
+ bool wasLastCharNumeric : 1 = false;
+ bool lexingNumber : 1 = false;
+ };
+}
diff --git a/Lexer/src/Lexer.cpp b/Lexer/src/Lexer.cpp
index 043eed1..1553404 100644
--- a/Lexer/src/Lexer.cpp
+++ b/Lexer/src/Lexer.cpp
@@ -2,6 +2,9 @@
#include
+#include
+#include
+
namespace LX
{
std::string* InvalidCharInSource::s_Source = nullptr;
diff --git a/Lexer/src/Token.cpp b/Lexer/src/Token.cpp
index 2101aee..1c30c43 100644
--- a/Lexer/src/Token.cpp
+++ b/Lexer/src/Token.cpp
@@ -2,6 +2,8 @@
#include
+#include
+
namespace LX
{
// Creates the memory for the pointer to the source //