From 8abbc66dce2f1597e21ced8f3850ae8a1feefa83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 2 Oct 2017 16:18:47 +0200 Subject: [PATCH] [poincare] Implement default acceptsLocationInCombination in selector Change-Id: Ie77fc817f8affc4ca140ef58af755af9e212caa9 --- poincare/src/simplification/Makefile | 1 - .../simplification/selector/any_selector.cpp | 18 ------------------ .../src/simplification/selector/any_selector.h | 1 - .../src/simplification/selector/selector.cpp | 10 ++++++++++ .../src/simplification/selector/selector.h | 2 +- .../simplification/selector/type_selector.cpp | 2 +- 6 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 poincare/src/simplification/selector/any_selector.cpp diff --git a/poincare/src/simplification/Makefile b/poincare/src/simplification/Makefile index cb50a87f1..04a34867a 100644 --- a/poincare/src/simplification/Makefile +++ b/poincare/src/simplification/Makefile @@ -15,7 +15,6 @@ products += $(rulesets) objs += $(addprefix $(prefix)/,\ expression_simplify.o \ rule.o \ - selector/any_selector.o \ selector/combination.o \ selector/selector.o \ selector/type_and_identifier_selector.o \ diff --git a/poincare/src/simplification/selector/any_selector.cpp b/poincare/src/simplification/selector/any_selector.cpp deleted file mode 100644 index 420d7a209..000000000 --- a/poincare/src/simplification/selector/any_selector.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "any_selector.h" -#include "combination.h" - -namespace Poincare { -namespace Simplification { - -bool AnySelector::acceptsLocationInCombination(const Combination * combination, int location) const { - // Yes, if no other slot in the combination before me is the same - for (int i=0; iexpressionIndexForSelectorIndex(i) == combination->expressionIndexForSelectorIndex(location)) { - return false; - } - } - return immediateMatch(combination->expressionForSelectorIndex(location)); -} - -} -} diff --git a/poincare/src/simplification/selector/any_selector.h b/poincare/src/simplification/selector/any_selector.h index 2efe39429..50f5efc12 100644 --- a/poincare/src/simplification/selector/any_selector.h +++ b/poincare/src/simplification/selector/any_selector.h @@ -9,7 +9,6 @@ namespace Simplification { class AnySelector : public Selector { public: using Selector::Selector; - bool acceptsLocationInCombination(const Combination * combination, int location) const override; bool immediateMatch(const Expression * e) const override { return true; } diff --git a/poincare/src/simplification/selector/selector.cpp b/poincare/src/simplification/selector/selector.cpp index eb8c4d91b..88110e1cf 100644 --- a/poincare/src/simplification/selector/selector.cpp +++ b/poincare/src/simplification/selector/selector.cpp @@ -5,6 +5,16 @@ namespace Poincare { namespace Simplification { +bool Selector::acceptsLocationInCombination(const Combination * combination, int location) const { + // Yes, if no other slot in the combination before me is the same + for (int i=0; iexpressionIndexForSelectorIndex(i) == combination->expressionIndexForSelectorIndex(location)) { + return false; + } + } + return immediateMatch(combination->expressionForSelectorIndex(location)); +} + bool Selector::match(const Expression * e, Expression ** captures, int captureLength) const { // Test that root selector match root expression if (!immediateMatch(e)) { diff --git a/poincare/src/simplification/selector/selector.h b/poincare/src/simplification/selector/selector.h index d4adcf72a..f503d71e0 100644 --- a/poincare/src/simplification/selector/selector.h +++ b/poincare/src/simplification/selector/selector.h @@ -12,7 +12,7 @@ class Selector { public: constexpr Selector(int captureIndex = -1, const Selector * const * children = nullptr, int numberOfChildren = 0, bool childrenPartialMatch = true) : m_captureIndex(captureIndex), m_children(children), m_numberOfChildren(numberOfChildren), m_childrenPartialMatch(childrenPartialMatch) {} - virtual bool acceptsLocationInCombination(const Combination * combination, int location) const = 0; + virtual bool acceptsLocationInCombination(const Combination * combination, int location) const; virtual bool immediateMatch(const Expression * e) const = 0; bool match(const Expression * e, Expression ** captures, int captureLength) const; private: diff --git a/poincare/src/simplification/selector/type_selector.cpp b/poincare/src/simplification/selector/type_selector.cpp index 0b83864e0..dbb646aab 100644 --- a/poincare/src/simplification/selector/type_selector.cpp +++ b/poincare/src/simplification/selector/type_selector.cpp @@ -19,7 +19,7 @@ bool TypeSelector::acceptsLocationInCombination(const Combination * combination, return false; } - return immediateMatch(combination->expressionForSelectorIndex(location)); + return Selector::acceptsLocationInCombination(combination, location); } }