diff --git a/poincare/src/simplify/rules_generation/node.cpp b/poincare/src/simplify/rules_generation/node.cpp index d0b5869f3..76f64d5c5 100644 --- a/poincare/src/simplify/rules_generation/node.cpp +++ b/poincare/src/simplify/rules_generation/node.cpp @@ -9,6 +9,9 @@ Node::Node(std::string * name, std::vector * children) : if (children == nullptr) { m_children = new std::vector(); } + for (Node * child : *m_children) { + child->m_parent = this; + } } Node::~Node() { diff --git a/poincare/src/simplify/rules_generation/node.h b/poincare/src/simplify/rules_generation/node.h index 2ecbe4e9f..fb2a689bb 100644 --- a/poincare/src/simplify/rules_generation/node.h +++ b/poincare/src/simplify/rules_generation/node.h @@ -15,9 +15,9 @@ public: int flatIndexOfChildNamed(std::string name); protected: virtual void generateFields(Rule * context, std::string &indentation) = 0; -protected: std::string * m_name; std::vector * m_children; + Node * m_parent; }; #endif diff --git a/poincare/src/simplify/rules_generation/selector.cpp b/poincare/src/simplify/rules_generation/selector.cpp index b9ec4a532..7fff9c532 100644 --- a/poincare/src/simplify/rules_generation/selector.cpp +++ b/poincare/src/simplify/rules_generation/selector.cpp @@ -9,12 +9,15 @@ Selector::Selector(Type type, std::string * name, std::vector * chil } void Selector::generateFields(Rule * context, std::string &indentation) { + Selector * parent = (Selector *)m_parent; switch (m_type) { case Type::Variable: std::cout << indentation << ".m_match = ExpressionSelector::Match::Any," << std::endl; break; case Type::Wildcard: std::cout << indentation << ".m_match = ExpressionSelector::Match::Wildcard," << std::endl; + // Wildcard should always be the last element of a parent + assert(parent->m_children->back() == this); break; case Type::ExpressionType: std::cout << indentation << ".m_match = ExpressionSelector::Match::TypeAndValue," << std::endl;