[poincare] Add parenthesis with ambiguous expressions as 1--2

Change-Id: Ibfc14113d72e907e478a7d8c425c470f664f9cf1
This commit is contained in:
Émilie Feral
2017-01-26 16:25:23 +01:00
parent 35f1404707
commit e2eebd7d9d
4 changed files with 8 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ extern "C" {
}
#include "layout/horizontal_layout.h"
#include "layout/string_layout.h"
#include "layout/parenthesis_layout.h"
Addition::Addition(Expression ** operands,
int numberOfOperands,
@@ -81,7 +82,7 @@ ExpressionLayout * Addition::createLayout() const {
children_layouts[0] = m_operands[0]->createLayout();
for (int i=1; i<m_numberOfOperands; i++) {
children_layouts[2*i-1] = new StringLayout("+", 1);
children_layouts[2*i] = m_operands[i]->createLayout();
children_layouts[2*i] = m_operands[i]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[i]->createLayout()) : m_operands[i]->createLayout();
}
return new HorizontalLayout(children_layouts, number_of_children);
}

View File

@@ -6,6 +6,7 @@ extern "C" {
#include <poincare/multiplication.h>
#include "layout/string_layout.h"
#include "layout/horizontal_layout.h"
#include "layout/parenthesis_layout.h"
Expression::Type Multiplication::type() const {
return Expression::Type::Multiplication;
@@ -15,7 +16,7 @@ ExpressionLayout * Multiplication::createLayout() const {
ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *));
children_layouts[0] = m_operands[0]->createLayout();
children_layouts[1] = new StringLayout("*", 1);
children_layouts[2] = m_operands[1]->createLayout();
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout()) : m_operands[1]->createLayout();
return new HorizontalLayout(children_layouts, 3);
}

View File

@@ -4,6 +4,7 @@ extern "C" {
#include <stdlib.h>
}
#include "layout/horizontal_layout.h"
#include "layout/parenthesis_layout.h"
#include "layout/string_layout.h"
Opposite::Opposite(Expression * operand, bool cloneOperands) {
@@ -52,7 +53,7 @@ ExpressionLayout * Opposite::createLayout() const {
ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
char string[2] = {'-', '\0'};
children_layouts[0] = new StringLayout(string, 1);
children_layouts[1] = m_operand->createLayout();
children_layouts[1] = m_operand->type() == Type::Opposite ? new ParenthesisLayout(m_operand->createLayout()) : m_operand->createLayout();
return new HorizontalLayout(children_layouts, 2);
}

View File

@@ -6,6 +6,7 @@ extern "C" {
#include <poincare/subtraction.h>
#include "layout/horizontal_layout.h"
#include "layout/string_layout.h"
#include "layout/parenthesis_layout.h"
Expression * Subtraction::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
@@ -27,7 +28,7 @@ ExpressionLayout * Subtraction::createLayout() const {
children_layouts[0] = m_operands[0]->createLayout();
char string[2] = {'-', '\0'};
children_layouts[1] = new StringLayout(string, 1);
children_layouts[2] = m_operands[1]->createLayout();
children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout()) : m_operands[1]->createLayout();
return new HorizontalLayout(children_layouts, 3);
}