From e534b659c1ecfba5cca5afe05779e3f142b20def Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Tue, 29 Mar 2016 12:49:30 +0200 Subject: [PATCH] Poincare: Add hand-generated Simplifications This will be generated by a compiler Change-Id: I5ae606417ecd4e86a61c38be65fc6a4f44e9c3d5 --- .../src/simplify/simplification_rules.cpp | 99 +++++++++++++++++++ poincare/src/simplify/simplification_rules.h | 9 ++ 2 files changed, 108 insertions(+) create mode 100644 poincare/src/simplify/simplification_rules.cpp create mode 100644 poincare/src/simplify/simplification_rules.h diff --git a/poincare/src/simplify/simplification_rules.cpp b/poincare/src/simplify/simplification_rules.cpp new file mode 100644 index 000000000..017256085 --- /dev/null +++ b/poincare/src/simplify/simplification_rules.cpp @@ -0,0 +1,99 @@ +#include "simplification_rules.h" +#include "simplification_generator.h" + +const ExpressionSelector additionCommutativeSelector[5] = { + { + .m_match = ExpressionSelector::Match::TypeAndValue, + .m_expressionType = Expression::Type::Addition, + .m_numberOfChildren = 2 + }, + { + .m_match = ExpressionSelector::Match::Any, + .m_numberOfChildren = 0 + }, + { + .m_match = ExpressionSelector::Match::TypeAndValue, + .m_expressionType = Expression::Type::Addition, + .m_numberOfChildren = 2, + }, + { + .m_match = ExpressionSelector::Match::Any, + .m_numberOfChildren = 0 + }, + { + .m_match = ExpressionSelector::Match::Any, + .m_numberOfChildren = 0 + } +}; + +const ExpressionBuilder additionCommutativeBuilder[4] = { + { + .m_action = ExpressionBuilder::Action::BuildFromTypeAndValue, + .m_expressionType = Expression::Type::Addition, + .m_numberOfChildren = 3 + }, + { + .m_action = ExpressionBuilder::Action::Clone, + .m_matchIndex = 1, + .m_numberOfChildren = 0 + }, + { + .m_action = ExpressionBuilder::Action::Clone, + .m_matchIndex = 3, + .m_numberOfChildren = 0 + }, + { + .m_action = ExpressionBuilder::Action::Clone, + .m_matchIndex = 4, + .m_numberOfChildren = 0 + } +}; + +const ExpressionSelector additionIntegerSelector[3] = { + { + .m_match = ExpressionSelector::Match::TypeAndValue, + .m_expressionType = Expression::Type::Addition, + .m_numberOfChildren = 2 + }, + { + .m_match = ExpressionSelector::Match::TypeAndValue, + .m_expressionType = Expression::Type::Integer, + .m_numberOfChildren = 0 + }, + { + .m_match = ExpressionSelector::Match::TypeAndValue, + .m_expressionType = Expression::Type::Integer, + .m_numberOfChildren = 0 + } +}; + +const ExpressionBuilder additionIntegerBuilder[3] = { + { + .m_action = ExpressionBuilder::Action::CallExternalGenerator, + .m_generator = &SimplificationGenerator::AddIntegers, + .m_numberOfChildren = 2 + }, + { + .m_action = ExpressionBuilder::Action::Clone, + .m_matchIndex = 1, + .m_numberOfChildren = 0 + }, + { + .m_action = ExpressionBuilder::Action::Clone, + .m_matchIndex = 2, + .m_numberOfChildren = 0 + } +}; + +const Simplification simplifications[2] = { + { + .m_selector = (ExpressionSelector *)additionCommutativeSelector, + .m_builder = (ExpressionBuilder *)additionCommutativeBuilder + }, + { + .m_selector = (ExpressionSelector *)additionIntegerSelector, + .m_builder = (ExpressionBuilder *)additionIntegerBuilder + } +}; + +const int numberOfSimplifications = 2; diff --git a/poincare/src/simplify/simplification_rules.h b/poincare/src/simplify/simplification_rules.h new file mode 100644 index 000000000..35367dbd1 --- /dev/null +++ b/poincare/src/simplify/simplification_rules.h @@ -0,0 +1,9 @@ +#ifndef POINCARE_SIMPLIFY_SIMPLIFICATION_RULES_H +#define POINCARE_SIMPLIFY_SIMPLIFICATION_RULES_H + +#include "simplification.h" + +extern const Simplification simplifications[]; +extern const int numberOfSimplifications; + +#endif