renamed function->block to function->body

This commit is contained in:
Karma Riuk
2025-07-15 01:13:52 +02:00
parent c6daa5c2af
commit e2dfca2679
4 changed files with 14 additions and 14 deletions

View File

@@ -5,7 +5,7 @@
namespace ast { namespace ast {
function_literal::function_literal(token::token token) function_literal::function_literal(token::token token)
: token(std::move(token)), : token(std::move(token)),
block(nullptr) {}; body(nullptr) {};
std::string function_literal::token_literal() const { std::string function_literal::token_literal() const {
return token.literal; return token.literal;
@@ -22,14 +22,14 @@ namespace ast {
first = false; first = false;
} }
ss << ")"; ss << ")";
ss << block->str(); ss << body->str();
return ss.str(); return ss.str();
}; };
function_literal::~function_literal() { function_literal::~function_literal() {
for (auto& param : parameters) for (auto& param : parameters)
delete param; delete param;
if (block != nullptr) if (body != nullptr)
delete block; delete body;
} }
} // namespace ast } // namespace ast

View File

@@ -12,7 +12,7 @@ namespace ast {
function_literal(token::token); function_literal(token::token);
token::token token; token::token token;
std::vector<identifier*> parameters; std::vector<identifier*> parameters;
ast::block_stmt* block; ast::block_stmt* body;
std::string token_literal() const override; std::string token_literal() const override;
std::string str() const override; std::string str() const override;

View File

@@ -282,7 +282,7 @@ namespace parser {
delete ret; delete ret;
return nullptr; return nullptr;
} }
ret->block = parse_block(); ret->body = parse_block();
return ret; return ret;
}; };

View File

@@ -98,9 +98,9 @@ fn () {\
CHECK(fun->parameters.size() == 0); CHECK(fun->parameters.size() == 0);
// block // block
REQUIRE(fun->block->statements.size() == 1); REQUIRE(fun->body->statements.size() == 1);
ast::return_stmt* ret = ast::return_stmt* ret =
cast<ast::return_stmt>(fun->block->statements[0]); cast<ast::return_stmt>(fun->body->statements[0]);
test_boolean_literal(ret->value, true); test_boolean_literal(ret->value, true);
// full string // full string
@@ -127,9 +127,9 @@ fn (x) {\
test_identifier(fun->parameters[0], "x"); test_identifier(fun->parameters[0], "x");
// block // block
REQUIRE(fun->block->statements.size() == 1); REQUIRE(fun->body->statements.size() == 1);
ast::return_stmt* ret = ast::return_stmt* ret =
cast<ast::return_stmt>(fun->block->statements[0]); cast<ast::return_stmt>(fun->body->statements[0]);
test_infix_expression(ret->value, "x", "+", 1); test_infix_expression(ret->value, "x", "+", 1);
// full string // full string
@@ -157,9 +157,9 @@ fn (x, y) {\
test_identifier(fun->parameters[1], "y"); test_identifier(fun->parameters[1], "y");
// block // block
REQUIRE(fun->block->statements.size() == 1); REQUIRE(fun->body->statements.size() == 1);
ast::return_stmt* ret = ast::return_stmt* ret =
cast<ast::return_stmt>(fun->block->statements[0]); cast<ast::return_stmt>(fun->body->statements[0]);
test_infix_expression(ret->value, "x", "+", "y"); test_infix_expression(ret->value, "x", "+", "y");
// full string // full string
@@ -192,9 +192,9 @@ let fun = fn (x, y) {\
test_identifier(fun->parameters[1], "y"); test_identifier(fun->parameters[1], "y");
// block // block
REQUIRE(fun->block->statements.size() == 1); REQUIRE(fun->body->statements.size() == 1);
ast::return_stmt* ret = ast::return_stmt* ret =
cast<ast::return_stmt>(fun->block->statements[0]); cast<ast::return_stmt>(fun->body->statements[0]);
test_infix_expression(ret->value, "x", "+", "y"); test_infix_expression(ret->value, "x", "+", "y");
// full string // full string