mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-04 18:09:03 +00:00
Improved syntax for functions
Added logging system for AST nodes as well.
This commit is contained in:
@@ -1,17 +1,43 @@
|
||||
#include <AST.h>
|
||||
|
||||
namespace LX
|
||||
{
|
||||
std::string ToString(std::unique_ptr<AST::Node>& node)
|
||||
{
|
||||
if (node == nullptr) { return "NULL Node"; }
|
||||
#include <fstream>
|
||||
|
||||
switch (node->m_Type)
|
||||
namespace LX::AST
|
||||
{
|
||||
void Node::Log(std::ofstream* log, unsigned depth)
|
||||
{
|
||||
(*log) << std::string(depth, '\t') << "NULL node";
|
||||
}
|
||||
|
||||
void NumberLiteral::Log(std::ofstream* log, unsigned depth)
|
||||
{
|
||||
(*log) << std::string(depth, '\t');
|
||||
(*log) << "Number: " << m_Number << "\n";
|
||||
}
|
||||
|
||||
void Operation::Log(std::ofstream* log, unsigned depth)
|
||||
{
|
||||
(*log) << std::string(depth, '\t');
|
||||
(*log) << "Operation {" << ToString(m_Operand) << "}:\n";
|
||||
(*log) << std::string(depth + 1, '\t') << "LHS:\n";
|
||||
m_Lhs.get()->Log(log, depth + 2);
|
||||
(*log) << std::string(depth + 1, '\t') << "RHS:\n";
|
||||
m_Rhs.get()->Log(log, depth + 2);
|
||||
}
|
||||
|
||||
void ReturnStatement::Log(std::ofstream* log, unsigned depth)
|
||||
{
|
||||
(*log) << std::string(depth, '\t');
|
||||
|
||||
if (m_Val == nullptr)
|
||||
{
|
||||
case AST::Node::IDENTIFIER: return "IDENTIFIER";
|
||||
case AST::Node::OPERATION: return "OPERATION";
|
||||
case AST::Node::RETURN_STATEMENT: return "return";
|
||||
case AST::Node::NUMBER_LITERAL: return "number";
|
||||
(*log) << "Return\n";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
(*log) << "Return:\n";
|
||||
m_Val->Log(log, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user