mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] In context, return 0 if constant has not been assigned
Change-Id: I3a338a7de54c55500982a8a0dd32a1193f8db504
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/float.h>
|
||||
|
||||
class Integer;
|
||||
|
||||
//TODO: We should probably make a COPY of the expressions we store
|
||||
|
||||
@@ -16,6 +19,7 @@ class Context {
|
||||
int symbolIndex(const Symbol * symbol) const;
|
||||
static constexpr uint16_t k_maxNumberOfExpressions = 26;
|
||||
Expression * m_expressions[k_maxNumberOfExpressions];
|
||||
static Float * defaultExpression();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,14 +8,24 @@ Context::Context()
|
||||
}
|
||||
}
|
||||
|
||||
Float * Context::defaultExpression() {
|
||||
static Float * defaultExpression = new Float(0);
|
||||
return defaultExpression;
|
||||
}
|
||||
|
||||
int Context::symbolIndex(const Symbol * symbol) const {
|
||||
int index = symbol->name() - 'A';
|
||||
assert(index < k_maxNumberOfExpressions);
|
||||
return index;
|
||||
}
|
||||
|
||||
const Expression * Context::expressionForSymbol(const Symbol * symbol) {
|
||||
int index = symbolIndex(symbol);
|
||||
if (index < 0 || index >= k_maxNumberOfExpressions) {
|
||||
return nullptr;
|
||||
}
|
||||
if (m_expressions[index] == nullptr) {
|
||||
return defaultExpression();
|
||||
}
|
||||
return m_expressions[index];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user