Skip to content

Commit

Permalink
Fixed and improved visit function implementation in FunctionDeclarati…
Browse files Browse the repository at this point in the history
…onExpression.
  • Loading branch information
nthnn committed Oct 12, 2024
1 parent 7ae637d commit 2c694a7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/ast/expression/FunctionDeclarationExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <core/SymbolTable.hpp>
#include <parser/Token.hpp>

FunctionDeclarationExpression& FunctionDeclarationExpression::operator=(FunctionDeclarationExpression&& other) noexcept {
FunctionDeclarationExpression& FunctionDeclarationExpression::operator=(
FunctionDeclarationExpression&& other
) noexcept {
if(this != &other) {
this->address = std::move(other.address);
this->parameters = std::move(other.parameters);
Expand All @@ -37,14 +39,21 @@ DynamicObject FunctionDeclarationExpression::visit(
__attribute__((unused))
#endif
) {
return DynamicObject(std::make_shared<FunctionDeclarationExpression>(std::move(*this)));
return DynamicObject(
std::make_shared<FunctionDeclarationExpression>(
std::move(*this)
)
);
}

Token FunctionDeclarationExpression::getFunctionImage() const {
return *this->address;
}

DynamicObject FunctionDeclarationExpression::call(SymbolTable& symbols, const std::vector<DynamicObject>& args) {
DynamicObject FunctionDeclarationExpression::call(
const SymbolTable& symbols,
const std::vector<DynamicObject>& args
) {
if(args.size() != this->parameters.size())
#ifdef _MSC_VER
# pragma warning(disable : 5272)
Expand All @@ -54,7 +63,7 @@ DynamicObject FunctionDeclarationExpression::call(SymbolTable& symbols, const st
"Argument count mismatch"
);

SymbolTable localSymbols(&symbols);
SymbolTable localSymbols(const_cast<SymbolTable&>(symbols));
for(size_t i = 0; i < args.size(); ++i)
localSymbols.setSymbol(
this->parameters[i]->getImage(),
Expand Down

0 comments on commit 2c694a7

Please sign in to comment.