[poincare] Fix implemenation of AnySelector

Change-Id: I8b17cf9e06a22bdcb84787a03fb9011b08dc93c4
This commit is contained in:
Émilie Feral
2017-10-02 11:48:44 +02:00
parent d00948171a
commit 1853d31827
3 changed files with 20 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ 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 \

View File

@@ -0,0 +1,18 @@
#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; i<location; i++) {
if (combination->expressionIndexForSelectorIndex(i) == combination->expressionIndexForSelectorIndex(location)) {
return false;
}
}
return immediateMatch(combination->expressionForSelectorIndex(location));
}
}
}

View File

@@ -9,9 +9,7 @@ namespace Simplification {
class AnySelector : public Selector {
public:
using Selector::Selector;
bool acceptsLocationInCombination(const Combination * combination, int location) const override {
return true;
}
bool acceptsLocationInCombination(const Combination * combination, int location) const override;
bool immediateMatch(const Expression * e) const override {
return true;
}