uncommented tracers and using a macro to enable it

or disable it
This commit is contained in:
Karma Riuk
2025-07-14 20:15:18 +02:00
parent 1cda075f57
commit f0f748f7f5
2 changed files with 18 additions and 10 deletions

View File

@@ -107,7 +107,7 @@ namespace parser {
} }
ast::expression* parser::parse_expression(precedence prec) { ast::expression* parser::parse_expression(precedence prec) {
// TRACE_FUNCTION; TRACE_FUNCTION;
auto prefix_it = prefix_parse_fns.find(current.type); auto prefix_it = prefix_parse_fns.find(current.type);
if (prefix_it == prefix_parse_fns.end()) { if (prefix_it == prefix_parse_fns.end()) {
unkown_prefix_error(current); unkown_prefix_error(current);
@@ -166,7 +166,7 @@ namespace parser {
} }
ast::expression_stmt* parser::parse_expression_stmt() { ast::expression_stmt* parser::parse_expression_stmt() {
// TRACE_FUNCTION; TRACE_FUNCTION;
ast::expression_stmt* stmt = new ast::expression_stmt(current); ast::expression_stmt* stmt = new ast::expression_stmt(current);
stmt->expression = parse_expression(); stmt->expression = parse_expression();
@@ -230,12 +230,12 @@ namespace parser {
}; };
ast::expression* parser::parse_integer() { ast::expression* parser::parse_integer() {
// TRACE_FUNCTION; TRACE_FUNCTION;
return new ast::integer_literal(current, std::stoi(current.literal)); return new ast::integer_literal(current, std::stoi(current.literal));
}; };
ast::expression* parser::parse_boolean() { ast::expression* parser::parse_boolean() {
// TRACE_FUNCTION; TRACE_FUNCTION;
return new ast::boolean_literal( return new ast::boolean_literal(
current, current,
current.type == token::type::TRUE current.type == token::type::TRUE
@@ -243,7 +243,7 @@ namespace parser {
}; };
ast::expression* parser::parse_prefix_expr() { ast::expression* parser::parse_prefix_expr() {
// TRACE_FUNCTION; TRACE_FUNCTION;
ast::prefix_expr* ret = new ast::prefix_expr(current, current.literal); ast::prefix_expr* ret = new ast::prefix_expr(current, current.literal);
next_token(); next_token();
ret->right = parse_expression(precedence::PREFIX); ret->right = parse_expression(precedence::PREFIX);
@@ -251,7 +251,7 @@ namespace parser {
}; };
ast::expression* parser::parse_grouped_expr() { ast::expression* parser::parse_grouped_expr() {
// TRACE_FUNCTION; TRACE_FUNCTION;
next_token(); next_token();
ast::expression* ret = parse_expression(precedence::LOWEST); ast::expression* ret = parse_expression(precedence::LOWEST);
@@ -264,7 +264,7 @@ namespace parser {
}; };
ast::expression* parser::parse_if_then_else() { ast::expression* parser::parse_if_then_else() {
// TRACE_FUNCTION; TRACE_FUNCTION;
ast::if_then_else* ret = new ast::if_then_else(current); ast::if_then_else* ret = new ast::if_then_else(current);
if (!expect_next(token::type::LPAREN)) { if (!expect_next(token::type::LPAREN)) {
delete ret; delete ret;
@@ -299,7 +299,7 @@ namespace parser {
}; };
ast::block_stmt* parser::parse_block() { ast::block_stmt* parser::parse_block() {
// TRACE_FUNCTION; TRACE_FUNCTION;
ast::block_stmt* ret = new ast::block_stmt(current); ast::block_stmt* ret = new ast::block_stmt(current);
// ret->statements.push_back(parse_statement()); // ret->statements.push_back(parse_statement());
next_token(); next_token();
@@ -317,7 +317,7 @@ namespace parser {
} }
ast::expression* parser::parse_infix_expr(ast::expression* left) { ast::expression* parser::parse_infix_expr(ast::expression* left) {
// TRACE_FUNCTION; TRACE_FUNCTION;
ast::infix_expr* ret = ast::infix_expr* ret =
new ast::infix_expr(current, current.literal, left); new ast::infix_expr(current, current.literal, left);
precedence prec = precedence_for(current.type); precedence prec = precedence_for(current.type);

View File

@@ -1,4 +1,4 @@
#pragma once
#include <iostream> #include <iostream>
#include <string> #include <string>
@@ -19,4 +19,12 @@ namespace {
}; };
} // namespace } // namespace
#ifndef TRACE
#define TRACE 0
#endif
#if TRACE
#define TRACE_FUNCTION FunctionTracer tracer(__FUNCTION__); #define TRACE_FUNCTION FunctionTracer tracer(__FUNCTION__);
#else
#define TRACE_FUNCTION
#endif