Skip to content
Snippets Groups Projects
Commit c7cfa2d2 authored by Mattias Ajander's avatar Mattias Ajander
Browse files

Destructor for scope, prevent functions with the same name as built in functions

parent 7abc93c2
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
#include "ast/BlockNode.h"
#include "ast/declaration/VariableNode.h"
#include "ast/expression/ExpressionNode.h"
#include "parser/BuiltIn.h"
#include "parser/Registry.h"
#include "parser/Scope.h"
#include "token/Token.h"
......
......@@ -28,6 +28,12 @@ FunctionNode::~FunctionNode()
Node* FunctionNode::evaluate() const
{
// Check if the function is built-in
if (BuiltIn::functions.find(identifier) != BuiltIn::functions.end())
{
throw RuntimeError(get_location(), "Cannot overwrite built-in function: " + identifier);
}
// Register the function in the registry
Registry::instance().add_function(const_cast<FunctionNode*>(this));
// Add the function to the current scope
......
......@@ -4,7 +4,13 @@ namespace funk
{
Scope::Scope() {}
Scope::~Scope() {}
Scope::~Scope()
{
for (auto& scope : scopes)
{
for (auto& [name, node] : scope) { delete node; }
}
}
Scope& Scope::instance()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment