mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Throw a bison error when functions have wrong number of
arguments Change-Id: I33f0a9b7cad3b1fde2df25ecfdc568187b79f248
This commit is contained in:
@@ -38,11 +38,10 @@ bool TextFieldDelegateApp::textFieldShouldFinishEditing(TextField * textField, I
|
||||
bool TextFieldDelegateApp::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
|
||||
if (textField->textFieldShouldFinishEditing(event) && textField->isEditing()) {
|
||||
Expression * exp = Expression::parse(textField->text());
|
||||
bool invalidText = (exp == nullptr || !exp->hasValidNumberOfArguments());
|
||||
if (exp != nullptr) {
|
||||
delete exp;
|
||||
}
|
||||
if (invalidText) {
|
||||
if (exp == nullptr) {
|
||||
textField->app()->displayWarning(I18n::Message::SyntaxError);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
BoundedStaticHierarchy();
|
||||
BoundedStaticHierarchy(Expression * const * operands, int numberOfOperands, bool cloneOperands = true);
|
||||
int numberOfOperands() const override { return m_numberOfOperands; }
|
||||
bool hasValidNumberOfArguments() const override;
|
||||
bool hasValidNumberOfOperands(int numberOfOperands) const override;
|
||||
private:
|
||||
int m_numberOfOperands;
|
||||
};
|
||||
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
Expression::Type type() const override;
|
||||
Complex<T> * clone() const override;
|
||||
bool isCommutative() const override;
|
||||
bool hasValidNumberOfArguments() const override;
|
||||
void replaceOperand(const Expression * oldOperand, Expression * newOperand, bool deleteOldOperand) override {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ public:
|
||||
static bool shouldStopProcessing();
|
||||
|
||||
/* Hierarchy */
|
||||
virtual bool hasValidNumberOfArguments() const; // FIXME: Remove?
|
||||
virtual const Expression * operand(int i) const = 0;
|
||||
virtual int numberOfOperands() const = 0;
|
||||
virtual Expression * clone() const = 0;
|
||||
|
||||
@@ -20,8 +20,8 @@ public:
|
||||
|
||||
virtual void setArgument(ListData * listData, int numberOfEntries, bool clone);
|
||||
int numberOfOperands() const override { return T; }
|
||||
bool hasValidNumberOfArguments() const override;
|
||||
Expression * const * operands() const override { return m_operands; }
|
||||
virtual bool hasValidNumberOfOperands(int numberOfOperands) const;
|
||||
protected:
|
||||
void build(Expression * const * operands, int numberOfOperands, bool cloneOperands);
|
||||
Expression * m_operands[T];
|
||||
|
||||
@@ -20,8 +20,8 @@ BoundedStaticHierarchy<T>::BoundedStaticHierarchy(Expression * const * operands,
|
||||
}
|
||||
|
||||
template<int T>
|
||||
bool BoundedStaticHierarchy<T>::hasValidNumberOfArguments() const {
|
||||
return true;
|
||||
bool BoundedStaticHierarchy<T>::hasValidNumberOfOperands(int numberOfOperands) const {
|
||||
return numberOfOperands >= 1 && numberOfOperands <= T;
|
||||
}
|
||||
|
||||
template class Poincare::BoundedStaticHierarchy<2>;
|
||||
|
||||
@@ -156,11 +156,6 @@ bool Complex<T>::isCommutative() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Complex<T>:: hasValidNumberOfArguments() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Complex<T>::toScalar() const {
|
||||
if (m_b != 0) {
|
||||
|
||||
@@ -54,15 +54,6 @@ bool Expression::shouldStopProcessing() {
|
||||
return sCircuitBreaker();
|
||||
}
|
||||
|
||||
bool Expression::hasValidNumberOfArguments() const {
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
if (!operand(i)->hasValidNumberOfArguments()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ExpressionLayout * Expression::createLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
switch (floatDisplayMode) {
|
||||
case FloatDisplayMode::Default:
|
||||
|
||||
@@ -181,7 +181,7 @@ exp:
|
||||
| LEFT_PARENTHESIS exp RIGHT_PARENTHESIS { Poincare::Expression * terms[1] = {$2}; $$ = new Poincare::Parenthesis(terms, false); }
|
||||
/* MATRICES_ARE_DEFINED */
|
||||
| LEFT_BRACKET mtxData RIGHT_BRACKET { $$ = new Poincare::ExpressionMatrix($2); }
|
||||
| FUNCTION LEFT_PARENTHESIS lstData RIGHT_PARENTHESIS { $$ = $1; $1->setArgument($3, $3->numberOfOperands(), true); delete $3; }
|
||||
| FUNCTION LEFT_PARENTHESIS lstData RIGHT_PARENTHESIS { $$ = $1; if (!$1->hasValidNumberOfOperands($3->numberOfOperands())) { delete $1; delete $3; YYERROR; } ; $1->setArgument($3, $3->numberOfOperands(), true); delete $3; }
|
||||
|
||||
final_exp:
|
||||
exp { $$ = $1; }
|
||||
@@ -190,4 +190,5 @@ final_exp:
|
||||
|
||||
void poincare_expression_yyerror(Poincare::Expression ** expressionOutput, const char * msg) {
|
||||
// Handle the error!
|
||||
// TODO: handle explicitely different type of errors (division by 0, missing parenthesis). This should call back the container to display a pop up with a message corresponding to the error?
|
||||
}
|
||||
|
||||
@@ -32,16 +32,15 @@ void StaticHierarchy<T>::setArgument(ListData * listData, int numberOfOperands,
|
||||
}
|
||||
|
||||
template<int T>
|
||||
bool StaticHierarchy<T>::hasValidNumberOfArguments() const {
|
||||
//return Hierarchy::hasValidNumberOfArguments();
|
||||
return true;
|
||||
bool StaticHierarchy<T>::hasValidNumberOfOperands(int numberOfOperands) const {
|
||||
return numberOfOperands == T;
|
||||
}
|
||||
|
||||
template<int T>
|
||||
void StaticHierarchy<T>::build(Expression * const * operands, int numberOfOperands, bool cloneOperands) {
|
||||
assert(operands != nullptr);
|
||||
int clippedNumberOfOperands = numberOfOperands > T ? T : numberOfOperands;
|
||||
for (int i=0; i<clippedNumberOfOperands; i++) {
|
||||
assert(numberOfOperands <= T);
|
||||
for (int i=0; i < numberOfOperands; i++) {
|
||||
assert(operands[i] != nullptr);
|
||||
if (cloneOperands) {
|
||||
m_operands[i] = operands[i]->clone();
|
||||
|
||||
Reference in New Issue
Block a user