Skip to content
Snippets Groups Projects
Commit 94031881 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Clear symbol tables when leaving blocks

This allows to free memory that is no more needed
parent 624da57b
Branches
Tags
1 merge request!37Feature/language
......@@ -81,6 +81,8 @@ parser(const std::string& filename)
ExecutionPolicy exec_all;
root_node->execute(exec_all);
std::cout << *(root_node->m_symbol_table) << '\n';
root_node->m_symbol_table->clearValues();
};
if (not SignalManager::pauseOnError()) {
......@@ -103,5 +105,5 @@ parser(const std::string& filename)
read_input input(filename);
parse_and_execute(input);
}
std::cout << "Parsed: " << filename << '\n';
std::cout << "Executed successfuly: " << filename << '\n';
}
......@@ -17,6 +17,9 @@ class ASTNodeListProcessor final : public INodeProcessor
child->execute(exec_policy);
}
if (not(m_node.is_root() or m_node.is_type<language::for_statement_block>()))
m_node.m_symbol_table->clearValues();
return {};
}
......
......@@ -37,6 +37,8 @@ class DoWhileProcessor final : public INodeProcessor
},
m_node.children[1]->execute(exec_policy)));
} while (continuation_test);
m_node.children[0]->m_symbol_table->clearValues();
return {};
}
......
......@@ -38,6 +38,8 @@ class ForProcessor final : public INodeProcessor
m_node.children[2]->execute(exec_policy);
}
m_node.m_symbol_table->clearValues();
return {};
}
......
......@@ -26,14 +26,21 @@ class IfProcessor final : public INodeProcessor
if (is_true) {
Assert(m_node.children[1] != nullptr);
m_node.children[1]->execute(exec_policy);
if (m_node.children[1]->m_symbol_table != m_node.m_symbol_table)
m_node.children[1]->m_symbol_table->clearValues();
} else {
if (m_node.children.size() == 3) {
// else statement
Assert(m_node.children[2] != nullptr);
m_node.children[2]->execute(exec_policy);
if (m_node.children[2]->m_symbol_table != m_node.m_symbol_table)
m_node.children[2]->m_symbol_table->clearValues();
}
}
if (m_node.children[0]->m_symbol_table != m_node.m_symbol_table)
m_node.children[0]->m_symbol_table->clearValues();
return {};
}
......
......@@ -36,6 +36,7 @@ class WhileProcessor final : public INodeProcessor
}
}
m_node.children[1]->m_symbol_table->clearValues();
return {};
}
......
......@@ -263,6 +263,14 @@ class SymbolTable
return os;
}
void
clearValues()
{
for (auto& symbol : m_symbol_list) {
symbol.attributes().value() = DataVariant{};
}
}
auto
find(const std::string& symbol, const TAO_PEGTL_NAMESPACE::position& use_position)
{
......
......@@ -5,14 +5,6 @@
SynchronizerManager* SynchronizerManager::m_instance{nullptr};
SynchronizerManager::~SynchronizerManager()
{
if (m_connectivity_synchronizer_map.size() > 0) {
std::cerr << __FILE__ << ':' << __LINE__ << ": warning: some connectivities are still registered\n";
;
}
}
void
SynchronizerManager::create()
{
......@@ -24,6 +16,16 @@ void
SynchronizerManager::destroy()
{
Assert(m_instance != nullptr, "SynchronizerManager was not created!");
if (m_instance->m_connectivity_synchronizer_map.size() > 0) {
std::stringstream error;
error << ": some connectivities are still registered\n";
for (const auto& i_connectivity_synchronizer : m_instance->m_connectivity_synchronizer_map) {
error << " - connectivity " << rang::fgB::magenta << i_connectivity_synchronizer.first << rang::style::reset
<< '\n';
}
throw UnexpectedError(error.str());
}
delete m_instance;
m_instance = nullptr;
}
......
......@@ -18,10 +18,10 @@ class SynchronizerManager
static SynchronizerManager* m_instance;
SynchronizerManager(const SynchronizerManager&) = delete;
SynchronizerManager(SynchronizerManager&) = delete;
SynchronizerManager(SynchronizerManager&&) = delete;
SynchronizerManager() = default;
~SynchronizerManager();
~SynchronizerManager() = default;
public:
static void create();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment