mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Improved logging capabilities
This commit is contained in:
@@ -18,13 +18,26 @@ namespace LX
|
|||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Different priorities in the logger //
|
||||||
|
enum class Priority
|
||||||
|
{
|
||||||
|
HIGH, // Shows in all logs
|
||||||
|
LOW // Default
|
||||||
|
};
|
||||||
|
|
||||||
// Variadic template to allow an undefined ammount of arguments //
|
// Variadic template to allow an undefined ammount of arguments //
|
||||||
template<Format format = Format::AUTO, typename... Args>
|
template<Priority priority = Priority::LOW, Format format = Format::AUTO, typename... Args>
|
||||||
requires AllLogable<Args...> // <- Checks all types can be outputted to the console
|
requires AllLogable<Args...> // <- Checks all types can be outputted to the console
|
||||||
|
|
||||||
// Logs information (if the log is initalised) //
|
// Logs information (if the log is initalised) //
|
||||||
static void out(Args... args)
|
static void out(Args... args)
|
||||||
{
|
{
|
||||||
|
// Returns if not high enough priority //
|
||||||
|
if constexpr (priority == Priority::LOW)
|
||||||
|
{
|
||||||
|
RETURN_IF(s_Priority == Priority::HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
// Prints out the args ending with a new line unless specified //
|
// Prints out the args ending with a new line unless specified //
|
||||||
if constexpr (format == Format::AUTO) { ((*s_LogFile << ... << args) << "\n"); }
|
if constexpr (format == Format::AUTO) { ((*s_LogFile << ... << args) << "\n"); }
|
||||||
|
|
||||||
@@ -48,11 +61,14 @@ namespace LX
|
|||||||
*s_LogFile << '\n' << BREAK << '\n';
|
*s_LogFile << '\n' << BREAK << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initalises the log (Called by DllMain) //
|
// Initalises the log //
|
||||||
static void Init();
|
static void Init(Priority _default);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Keeps the pointer hidden to stop accidental changes //
|
// Keeps the pointer hidden to stop accidental changes //
|
||||||
static std::ofstream* s_LogFile;
|
static std::ofstream* s_LogFile;
|
||||||
|
|
||||||
|
// The current priority of the log output //
|
||||||
|
static Priority s_Priority;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
namespace LX
|
namespace LX
|
||||||
{
|
{
|
||||||
// Allocates memory for the log file pointer //
|
// Allocates memory for the log file pointer //
|
||||||
std::ofstream* Log::s_LogFile = nullptr;
|
|
||||||
|
|
||||||
void Log::Init()
|
std::ofstream* Log::s_LogFile = nullptr;
|
||||||
|
Log::Priority Log::s_Priority;
|
||||||
|
|
||||||
|
void Log::Init(Priority _default)
|
||||||
{
|
{
|
||||||
// The actual object holding the log file //
|
// The actual object holding the log file //
|
||||||
// Has to be done like this to stop MSVC complaining //
|
// Has to be done like this to stop MSVC complaining //
|
||||||
@@ -14,5 +16,8 @@ namespace LX
|
|||||||
// Opens the log file and assigns it to the log pointer //
|
// Opens the log file and assigns it to the log pointer //
|
||||||
actualLog.open("log");
|
actualLog.open("log");
|
||||||
s_LogFile = &actualLog;
|
s_LogFile = &actualLog;
|
||||||
|
|
||||||
|
// Assigns the priority //
|
||||||
|
s_Priority = _default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ extern "C" int __declspec(dllexport) GenIR(const char* a_inpPath, const char* a_
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Initalises the log //
|
// Initalises the log //
|
||||||
LX::Log::Init();
|
LX::Log::Init(LX::Log::Priority::HIGH);
|
||||||
|
|
||||||
// Turns the file paths into the C++ type for handling them //
|
// Turns the file paths into the C++ type for handling them //
|
||||||
std::filesystem::path inpPath = a_inpPath;
|
std::filesystem::path inpPath = a_inpPath;
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ namespace LX
|
|||||||
|
|
||||||
for (auto& token : tokens)
|
for (auto& token : tokens)
|
||||||
{
|
{
|
||||||
Log::out
|
Log::out<Log::Priority::HIGH>
|
||||||
(
|
(
|
||||||
std::left,
|
std::left,
|
||||||
"{ Line: ", std::setw(3), token.line,
|
"{ Line: ", std::setw(3), token.line,
|
||||||
|
|||||||
@@ -11,23 +11,23 @@ namespace LX::AST
|
|||||||
|
|
||||||
void NumberLiteral::Log(unsigned depth)
|
void NumberLiteral::Log(unsigned depth)
|
||||||
{
|
{
|
||||||
Log::out(std::string(depth, '\t'), "Number: ", m_Number);
|
Log::out<Log::Priority::HIGH>(std::string(depth, '\t'), "Number: ", m_Number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Operation::Log(unsigned depth)
|
void Operation::Log(unsigned depth)
|
||||||
{
|
{
|
||||||
Log::out(std::string(depth, '\t'), "Operation {", ToString(m_Operand), "}:");
|
Log::out<Log::Priority::HIGH>(std::string(depth, '\t'), "Operation {", ToString(m_Operand), "}:");
|
||||||
|
|
||||||
Log::out(std::string(depth + 1, '\t'), "LHS:");
|
Log::out<Log::Priority::HIGH>(std::string(depth + 1, '\t'), "LHS:");
|
||||||
m_Lhs->Log(depth + 2);
|
m_Lhs->Log(depth + 2);
|
||||||
|
|
||||||
Log::out(std::string(depth + 1, '\t'), "RHS:");
|
Log::out<Log::Priority::HIGH>(std::string(depth + 1, '\t'), "RHS:");
|
||||||
m_Rhs->Log(depth + 2);
|
m_Rhs->Log(depth + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReturnStatement::Log(unsigned depth)
|
void ReturnStatement::Log(unsigned depth)
|
||||||
{
|
{
|
||||||
Log::out<Log::Format::NONE>(std::string(depth, '\t'), "Return");
|
Log::out<Log::Priority::HIGH, Log::Format::NONE>(std::string(depth, '\t'), "Return");
|
||||||
|
|
||||||
if (m_Val != nullptr)
|
if (m_Val != nullptr)
|
||||||
{
|
{
|
||||||
@@ -37,26 +37,26 @@ namespace LX::AST
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log::out<Log::Format::NONE>('\n');
|
Log::out<Log::Priority::HIGH, Log::Format::NONE>('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VariableDeclaration::Log(unsigned depth)
|
void VariableDeclaration::Log(unsigned depth)
|
||||||
{
|
{
|
||||||
Log::out(std::string(depth, '\t'), "Variable declaration: ", m_Name);
|
Log::out<Log::Priority::HIGH>(std::string(depth, '\t'), "Variable declaration: ", m_Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VariableAssignment::Log(unsigned depth)
|
void VariableAssignment::Log(unsigned depth)
|
||||||
{
|
{
|
||||||
Log::out(std::string(depth, '\t'), "Variable assignment:");
|
Log::out<Log::Priority::HIGH>(std::string(depth, '\t'), "Variable assignment:");
|
||||||
|
|
||||||
Log::out(std::string(depth + 1, '\t'), "To: ", m_Name);
|
Log::out<Log::Priority::HIGH>(std::string(depth + 1, '\t'), "To: ", m_Name);
|
||||||
Log::out(std::string(depth + 1, '\t'), "Value:");
|
Log::out<Log::Priority::HIGH>(std::string(depth + 1, '\t'), "Value:");
|
||||||
m_Value->Log(depth + 2);
|
m_Value->Log(depth + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VariableAccess::Log(unsigned depth)
|
void VariableAccess::Log(unsigned depth)
|
||||||
{
|
{
|
||||||
Log::out(std::string(depth, '\t'), "Variable: ", m_Name);
|
Log::out<Log::Priority::HIGH>(std::string(depth, '\t'), "Variable: ", m_Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,7 @@ This is my custom compiled language written in C++ based off of the LLVM toolcha
|
|||||||
- Structs / Classes (Polymorphism + vtables)
|
- Structs / Classes (Polymorphism + vtables)
|
||||||
|
|
||||||
### Codebase
|
### Codebase
|
||||||
- Errors
|
- New features
|
||||||
- All simple errors (no members) use the same type
|
|
||||||
- Logging
|
|
||||||
- Choose what is logged (if any)
|
|
||||||
- Refactor
|
|
||||||
- Parser needs folders
|
|
||||||
- Better .h files
|
|
||||||
|
|
||||||
### Stuff I want to do later (unordered)
|
### Stuff I want to do later (unordered)
|
||||||
- I/O manager (Console, Files)
|
- I/O manager (Console, Files)
|
||||||
|
|||||||
Reference in New Issue
Block a user