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
This commit is contained in:
Pasha Bibko
2025-05-06 17:38:22 +01:00
parent 5339df9b36
commit f3a559490c
11 changed files with 85 additions and 99 deletions

View File

@@ -159,7 +159,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Console.cpp" />
<ClCompile Include="src\dllmain.cpp" />
<ClCompile Include="src\Logger.cpp" />
<ClCompile Include="src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>

View File

@@ -9,31 +9,25 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Header Files\Sections">
<UniqueIdentifier>{f3a1ae14-8b71-41d9-ba66-60c952867261}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="LX-Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\Console.h">
<Filter>Header Files\Sections</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\Error.h">
<Filter>Header Files\Sections</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\Logger.h">
<Filter>Header Files\Sections</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\ThrowIf.h">
<Filter>Header Files\Sections</Filter>
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View File

@@ -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();

View File

@@ -1,40 +0,0 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include <LX-Common.h>
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<DWORD, LX::DllFunc&> 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);
}

View File

@@ -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 //

View File

@@ -150,6 +150,10 @@
<ClCompile Include="src\Lexer.cpp" />
<ClCompile Include="src\Token.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\LexerErrors.h" />
<ClInclude Include="inc\LexerInfo.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@@ -21,4 +21,12 @@
<Filter>Header Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\LexerErrors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\LexerInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

25
Lexer/inc/LexerErrors.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <LX-Common.h>
#include <Lexer.h>
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;
};
}

37
Lexer/inc/LexerInfo.h Normal file
View File

@@ -0,0 +1,37 @@
#include <LX-Common.h>
#include <Lexer.h>
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;
};
}

View File

@@ -2,6 +2,9 @@
#include <Lexer.h>
#include <LexerErrors.h>
#include <LexerInfo.h>
namespace LX
{
std::string* InvalidCharInSource::s_Source = nullptr;

View File

@@ -2,6 +2,8 @@
#include <Lexer.h>
#include <LexerInfo.h>
namespace LX
{
// Creates the memory for the pointer to the source //