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

Begin Node::execute implementation

The idea is to replace the execute_node function by some more object-like
implementation. One should benefit
- improved readability
- performances by pre-computing of symbols location (no more symbol_table->find
during execution)

This first implementation uses inheritance as a first step. We will then
evaluate the benefit of a variant/visitor alternative then.
parent 3fc0d097
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -300,6 +300,17 @@ dataTypePromotion(const DataType& data_type_1, const DataType& data_type_2)
using DataVariant = std::variant<std::monostate, bool, int64_t, double>;
class SymbolTable;
class INodeProcessor
{
public:
virtual void execute() = 0;
INodeProcessor(const INodeProcessor& node) = delete;
INodeProcessor() {}
~INodeProcessor() {}
};
struct Node : public parse_tree::basic_node<Node>
{
......@@ -361,6 +372,15 @@ struct Node : public parse_tree::basic_node<Node>
Type m_type{Type::undefined};
std::shared_ptr<INodeProcessor> m_node_processor;
PUGS_INLINE
void
execute()
{
m_node_processor->execute();
}
DataType m_data_type{DataType::undefined_t};
DataVariant m_value;
};
......@@ -570,6 +590,22 @@ using selector = parse_tree::selector<Rule,
simplify_for_post::on<for_post>,
rearrange::on<product, expression>>;
class RootNode final : public INodeProcessor
{
Node& m_node;
public:
RootNode(Node& node) : m_node{node} {}
void
execute()
{
pout() << "executing root !\n";
for (auto& child : m_node.children) {
child->execute();
}
}
};
namespace internal
{
void
......@@ -577,6 +613,7 @@ build_node_type(Node& n)
{
if (n.is_root()) {
n.m_type = Node::Type::root;
n.m_node_processor = std::make_shared<RootNode>(n);
} else if (n.is<language::bloc>()) {
n.m_type = Node::Type::bloc;
} else if (n.is<language::declaration>()) {
......@@ -1935,6 +1972,8 @@ parser(const std::string& filename)
language::execute_node(*root_node);
language::print(*root_node);
// root_node->execute();
}
catch (const parse_error& e) {
const auto p = e.positions.front();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment