diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index e5a1b7ffc..591c020b3 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -9,9 +9,6 @@ class Addition : public CommutativeOperation { Type type() override; float operateApproximatevelyOn(float a, float b) override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif protected: char operatorChar() override; }; diff --git a/poincare/include/poincare/cosine.h b/poincare/include/poincare/cosine.h index af0aa391f..31f376375 100644 --- a/poincare/include/poincare/cosine.h +++ b/poincare/include/poincare/cosine.h @@ -9,9 +9,6 @@ class Cosine : public Function { float approximate(Context& context) override; Type type() override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif }; #endif diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 617787de8..e24680b3c 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -4,12 +4,6 @@ #include #include -#ifdef DEBUG -#define PRINT_AST(e) e->__printAst(0) -#else -#define PRINT_AST(e) ((void)0) -#endif - class Context; class Expression { @@ -48,13 +42,6 @@ class Expression { virtual Type type() = 0; virtual float approximate(Context& context) = 0; - /*private: - void forEachChild(ExpressionAction); - */ -#ifdef DEBUG - virtual int getPrintableVersion(char* txt) = 0; - void __printAst(int level=0); -#endif }; #endif diff --git a/poincare/include/poincare/float.h b/poincare/include/poincare/float.h index 577b6489f..245a1e8d9 100644 --- a/poincare/include/poincare/float.h +++ b/poincare/include/poincare/float.h @@ -13,9 +13,6 @@ class Float : public LeafExpression { Type type() override; Expression * clone() override; bool valueEquals(Expression * e) override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif private: float m_float; }; diff --git a/poincare/include/poincare/fraction.h b/poincare/include/poincare/fraction.h index fc30c2537..23fbe9352 100644 --- a/poincare/include/poincare/fraction.h +++ b/poincare/include/poincare/fraction.h @@ -10,9 +10,6 @@ class Fraction : public BinaryOperation { float approximate(Context& context) override; Type type() override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif }; #endif diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index aa047ce6c..79e67d534 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -46,9 +46,6 @@ class Integer : public LeafExpression { uint16_t m_numberOfDigits; // In base native_uint_max bool m_negative; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif /* // TODO: Small-int optimization union { diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 2ee17d5b4..4f567a1df 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -10,9 +10,6 @@ class Power : public BinaryOperation { float approximate(Context& context) override; Type type() override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif }; #endif diff --git a/poincare/include/poincare/product.h b/poincare/include/poincare/product.h index d90fea7a9..4b4b50be1 100644 --- a/poincare/include/poincare/product.h +++ b/poincare/include/poincare/product.h @@ -9,9 +9,6 @@ class Product : public CommutativeOperation { Type type() override; float operateApproximatevelyOn(float a, float b) override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif protected: char operatorChar() override; }; diff --git a/poincare/include/poincare/sine.h b/poincare/include/poincare/sine.h index a42024652..fe53563a0 100644 --- a/poincare/include/poincare/sine.h +++ b/poincare/include/poincare/sine.h @@ -9,9 +9,6 @@ class Sine : public Function { float approximate(Context& context) override; Type type() override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif }; #endif diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index 11eb4b130..5054bf390 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -10,9 +10,6 @@ class Subtraction : public BinaryOperation { float approximate(Context& context) override; Type type() override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif }; #endif diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index e8b9beb04..b0e1ebaba 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -12,9 +12,6 @@ class Symbol : public LeafExpression { Type type() override; Expression * clone() override; bool valueEquals(Expression * e) override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif private: char * m_name; }; diff --git a/poincare/include/poincare/tangent.h b/poincare/include/poincare/tangent.h index 58ac4bbf2..06ffbae06 100644 --- a/poincare/include/poincare/tangent.h +++ b/poincare/include/poincare/tangent.h @@ -9,9 +9,6 @@ class Tangent : public Function { float approximate(Context& context) override; Type type() override; Expression * clone() override; -#ifdef DEBUG - int getPrintableVersion(char* txt) override; -#endif }; #endif diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index 6108bc061..0783002dc 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -16,10 +16,3 @@ float Addition::operateApproximatevelyOn(float a, float b) { char Addition::operatorChar() { return '+'; } - -#ifdef DEBUG -int Addition::getPrintableVersion(char* txt) { - txt[0] = '+'; - return 1; -} -#endif diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index a665ca137..8fafad923 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -13,13 +13,3 @@ float Cosine::approximate(Context& context) { // FIXME: use cosine obviously. return m_arg->approximate(context); } - -#ifdef DEBUG -int Cosine::getPrintableVersion(char* txt) { - const char* printable = "cos"; - for(int i=0; printable[i]!='\0'; i++) { - txt[i] = printable[i]; - } - return 3; -} -#endif diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index f3cfd5d4d..cb7f19f94 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -7,11 +7,6 @@ extern "C" { #include "simplify/simplification_rules.h" -#ifdef DEBUG -#include -using namespace std; -#endif - int poincare_expression_yyparse(yyscan_t scanner, Expression ** expressionOutput); Expression::~Expression() { @@ -38,8 +33,6 @@ Expression * Expression::simplify() { const Simplification * simplification = (simplifications + i); // Pointer arithmetics Expression * simplified = simplification->simplify(result); if (simplified != nullptr) { - std::cout << "simplification " << i << " returned a non null pointer" << std::endl; - PRINT_AST(simplified); simplification_pass_was_useful = true; if (result != this) { delete result; @@ -70,18 +63,3 @@ bool Expression::valueEquals(Expression * e) { * -riden. */ return true; } - -#ifdef DEBUG -void Expression::__printAst(int level) { - char txt[255]; - for (int i(0); i__printAst(level + 2); - } -} -#endif diff --git a/poincare/src/expression_debug.cpp b/poincare/src/expression_debug.cpp new file mode 100644 index 000000000..8fb3b55b6 --- /dev/null +++ b/poincare/src/expression_debug.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +void print_expression(Expression * e, int indentationLevel) { + if (indentationLevel>0) { + for (int i=0; itype()) { + case Expression::Type::Addition: + std::cout << "Addition"; + break; + case Expression::Type::Cosine: + std::cout << "Cosine"; + break; + case Expression::Type::Float: + std::cout << "Float()"; + break; + case Expression::Type::Integer: + std::cout << "Integer("; + std::cout << e->approximate(context); + std::cout << ")"; + break; + case Expression::Type::Fraction: + std::cout << "Fraction"; + break; + case Expression::Type::Power: + std::cout << "Power"; + break; + case Expression::Type::Product: + std::cout << "Product"; + break; + case Expression::Type::Sine: + std::cout << "Sine"; + break; + case Expression::Type::Subtraction: + std::cout << "Subtraction"; + break; + case Expression::Type::Symbol: + std::cout << "Symbol"; + break; + case Expression::Type::Tangent: + std::cout << "Tangent"; + break; + } + std::cout << std::endl; + for (int i=0; inumberOfOperands(); i++) { + print_expression(e->operand(i), indentationLevel+1); + } +} diff --git a/poincare/src/expression_debug.h b/poincare/src/expression_debug.h new file mode 100644 index 000000000..ad910f589 --- /dev/null +++ b/poincare/src/expression_debug.h @@ -0,0 +1,3 @@ +#include + +void print_expression(Expression * e, int indentationLevel = 0); diff --git a/poincare/src/float.cpp b/poincare/src/float.cpp index fb5ce3163..9fa6d7b73 100644 --- a/poincare/src/float.cpp +++ b/poincare/src/float.cpp @@ -33,13 +33,3 @@ bool Float::valueEquals(Expression * e) { assert(e->type() == Expression::Type::Float); return m_float == ((Float *)e)->m_float; } - -#ifdef DEBUG -int Float::getPrintableVersion(char* txt) { - const char* printable = "float number"; - for(int i=0; printable[i]!='\0'; i++) { - txt[i] = printable[i]; - } - return strlen(printable); -} -#endif diff --git a/poincare/src/fraction.cpp b/poincare/src/fraction.cpp index fc66955ed..10893c814 100644 --- a/poincare/src/fraction.cpp +++ b/poincare/src/fraction.cpp @@ -18,10 +18,3 @@ float Fraction::approximate(Context& context) { Expression::Type Fraction::type() { return Expression::Type::Fraction; } - -#ifdef DEBUG -int Fraction::getPrintableVersion(char* txt) { - txt[0] = '/'; - return 1; -} -#endif diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index e2d3c58fc..78de87385 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -344,30 +344,6 @@ ExpressionLayout * Integer::createLayout() { return new StringLayout(buffer, size); } -#ifdef DEBUG -int Integer::getPrintableVersion(char* txt) { - Integer base = Integer(10); - Division d = Division(*this, base); - int size = 0; - while (!(d.m_remainder == Integer((native_int_t)0))) { - assert(size<255); //TODO: malloc an extra buffer - char c = char_from_digit(d.m_remainder.m_digits[0]); - txt[size++] = c; - d = Division(d.m_quotient, base); - } - txt[size] = 0; - - // Flip the string - for (int i=0, j=size-1 ; i < j ; i++, j--) { - char c = txt[i]; - txt[i] = txt[j]; - txt[j] = c; - } - - return size; -} -#endif - bool Integer::valueEquals(Expression * e) { assert(e->type() == Expression::Type::Integer); return (*this == *(Integer *)e); // FIXME: Remove operator overloading diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 718cffb5b..6eb6cb2f4 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -17,10 +17,3 @@ Expression::Type Power::type() { ExpressionLayout * Power::createLayout() { return new ExponentLayout(m_operands[0]->createLayout(), m_operands[1]->createLayout()); } - -#ifdef DEBUG -int Power::getPrintableVersion(char* txt) { - txt[0] = '^'; - return 1; -} -#endif diff --git a/poincare/src/print_ast.cpp b/poincare/src/print_ast.cpp deleted file mode 100644 index 6f6470887..000000000 --- a/poincare/src/print_ast.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include - -int __print_ast(Expression* expression, int offset) { - // TODO print my current node. - char txt[offset+1] = {' '}; - text[offset] = '\0'; - cout << txt; - - // Print my children. - for (int i(0); im_operands(); i++) { - int tmp = __print_ast(expression->operand(i), offset); - offset += tmp; - } - - return 3; -} diff --git a/poincare/src/product.cpp b/poincare/src/product.cpp index 8c0f5a58b..7fefa4ca1 100644 --- a/poincare/src/product.cpp +++ b/poincare/src/product.cpp @@ -19,10 +19,3 @@ Expression::Type Product::type() { char Product::operatorChar() { return '*'; } - -#ifdef DEBUG -int Product::getPrintableVersion(char* txt) { - txt[0] = '*'; - return 1; -} -#endif diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index b0ea15f6d..fb3d7003c 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -13,13 +13,3 @@ float Sine::approximate(Context& context) { // FIXME: use sine obviously. return m_arg->approximate(context); } - -#ifdef DEBUG -int Sine::getPrintableVersion(char* txt) { - const char* printable = "sin"; - for(int i=0; printable[i]!='\0'; i++) { - txt[i] = printable[i]; - } - return 3; -} -#endif diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index f6e6cb22b..ced5648c6 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -25,10 +25,3 @@ ExpressionLayout * Subtraction::createLayout() { children_layouts[2] = m_operands[1]->createLayout(); return new HorizontalLayout(children_layouts, 3); } - -#ifdef DEBUG -int Subtraction::getPrintableVersion(char* txt) { - txt[0] = '-'; - return 1; -} -#endif diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 9d8b04e3b..ca8c3f05f 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -38,12 +38,3 @@ bool Symbol::valueEquals(Expression * e) { assert(e->type() == Expression::Type::Symbol); return (strcmp(m_name, ((Symbol *)e)->m_name) == 0); } - -#ifdef DEBUG -int Symbol::getPrintableVersion(char* txt) { - for(int i=0; m_name[i]!='\0'; i++) { - txt[i] = m_name[i]; - } - return strlen(m_name); -} -#endif diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index 62b92d1bb..6eb92af4c 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -13,13 +13,3 @@ float Tangent::approximate(Context& context) { // FIXME: use tangent obviously. return m_arg->approximate(context); } - -#ifdef DEBUG -int Tangent::getPrintableVersion(char* txt) { - const char* printable = "tan"; - for(int i=0; printable[i]!='\0'; i++) { - txt[i] = printable[i]; - } - return 3; -} -#endif diff --git a/poincare/test/simplify_addition_integer.cpp b/poincare/test/simplify_addition_integer.cpp index 3c95a5226..724ec0d5b 100644 --- a/poincare/test/simplify_addition_integer.cpp +++ b/poincare/test/simplify_addition_integer.cpp @@ -2,39 +2,45 @@ #include #include -#ifdef DEBUG +#define DUMP_EXPRESSIONS_TO_STD_OUT 1 +#if DUMP_EXPRESSIONS_TO_STD_OUT +#include "../src/expression_debug.h" #include using namespace std; #endif void assert_simplifies_to(const char * input_string, const char * expected_string) { +#if DUMP_EXPRESSIONS_TO_STD_OUT + cout << "---- Simplification Run ----" << endl; + cout << input_string << " -> " << expected_string << endl; +#endif //Expression* tab[3] = {new Integer(1), new Integer(2), new Integer(3)}; //Expression* input = new Addition(tab, 3, false); Expression * input = Expression::parse(input_string); assert(input != nullptr); -#ifdef DEBUG +#if DUMP_EXPRESSIONS_TO_STD_OUT cout << "Input = " << endl; - PRINT_AST(input); + print_expression(input); #endif + Expression * simplified = input->simplify(); assert(simplified != nullptr); -#ifdef DEBUG +#if DUMP_EXPRESSIONS_TO_STD_OUT cout << "Simplified = " << endl; - PRINT_AST(simplified); + print_expression(simplified); #endif + Expression * expected = Expression::parse(expected_string); assert(expected != nullptr); -#ifdef DEBUG +#if DUMP_EXPRESSIONS_TO_STD_OUT cout << "Expected = " << endl; - PRINT_AST(expected); + print_expression(expected); #endif + assert(simplified->isIdenticalTo(expected)); delete expected; delete simplified; delete input; -#ifdef DEBUG - cout << "----" << endl; -#endif } QUIZ_CASE(poincare_simplify_addition_integer) {