diff options
-rw-r--r-- | qtmips_asm/fixmatheval.cpp | 18 | ||||
-rw-r--r-- | qtmips_asm/fixmatheval.h | 8 |
2 files changed, 17 insertions, 9 deletions
diff --git a/qtmips_asm/fixmatheval.cpp b/qtmips_asm/fixmatheval.cpp index 8852938..eb7ec3f 100644 --- a/qtmips_asm/fixmatheval.cpp +++ b/qtmips_asm/fixmatheval.cpp @@ -110,10 +110,11 @@ QString FmeNodeSymbol::dump() { return name; } -FmeNodeUnaryOp::FmeNodeUnaryOp(int priority, FmeValue (*op)(FmeValue &a)) : - FmeNode(priority) { +FmeNodeUnaryOp::FmeNodeUnaryOp(int priority, FmeValue (*op)(FmeValue &a), + QString description) : FmeNode(priority) { this->operand_a = nullptr; this->op = op; + this->description = description; } FmeNodeUnaryOp::~FmeNodeUnaryOp() { @@ -141,14 +142,15 @@ bool FmeNodeUnaryOp::insert(FmeNode *node) { } QString FmeNodeUnaryOp::dump() { - return "(OP " + (operand_a? operand_a->dump(): "nullptr") + ")"; + return "(" + description + " " + (operand_a? operand_a->dump(): "nullptr") + ")"; } FmeNodeBinaryOp::FmeNodeBinaryOp(int priority, FmeValue (*op)(FmeValue &a, FmeValue &b), - FmeNode *left) : FmeNode(priority) { + FmeNode *left, QString description) : FmeNode(priority) { this->operand_a = left; this->operand_b = nullptr; this->op = op; + this->description = description; } FmeNodeBinaryOp::~FmeNodeBinaryOp() { @@ -179,7 +181,7 @@ bool FmeNodeBinaryOp::insert(FmeNode *node) { QString FmeNodeBinaryOp::dump() { return "(" + (operand_a? operand_a->dump(): "nullptr") + - " OP " + (operand_b? operand_b->dump(): "nullptr") + ")"; + " " + description + " " + (operand_b? operand_b->dump(): "nullptr") + ")"; } FmeExpression::FmeExpression() : FmeNode(0) { @@ -195,6 +197,7 @@ bool FmeExpression::parse(const QString &expression, QString &error) { int word_start = 0; bool in_word = false; bool is_unary = true; + QString optxtx; for (i = 0; true; i++) { QChar ch = 0; if (i < expression.size()) @@ -232,6 +235,7 @@ bool FmeExpression::parse(const QString &expression, QString &error) { FmeValue (*unary_op)(FmeValue &a) = nullptr; int prio = base_prio; + optxtx = ch; if (ch == '~') { prio += 90; unary_op = [](FmeValue &a) -> FmeValue { return ~a; }; @@ -285,10 +289,10 @@ bool FmeExpression::parse(const QString &expression, QString &error) { break; } if (binary_op != nullptr) { - ok = node->insert(new FmeNodeBinaryOp(prio, binary_op, child)); + ok = node->insert(new FmeNodeBinaryOp(prio, binary_op, child, optxtx)); is_unary = true; } else { - ok = node->insert(new FmeNodeUnaryOp(prio, unary_op)); + ok = node->insert(new FmeNodeUnaryOp(prio, unary_op, optxtx)); } if (!ok) { error = QString("parse stuck at \"%1\"").arg(QString(ch)); diff --git a/qtmips_asm/fixmatheval.h b/qtmips_asm/fixmatheval.h index 3312bfa..9d560ab 100644 --- a/qtmips_asm/fixmatheval.h +++ b/qtmips_asm/fixmatheval.h @@ -83,7 +83,8 @@ private: class FmeNodeUnaryOp : public FmeNode { public: - FmeNodeUnaryOp(int priority, FmeValue (*op)(FmeValue &a)); + FmeNodeUnaryOp(int priority, FmeValue (*op)(FmeValue &a), + QString description = "??"); virtual ~FmeNodeUnaryOp(); virtual bool eval(FmeValue &value, FmeSymbolDb *symdb, QString &error) override; virtual bool insert(FmeNode *node) override; @@ -92,11 +93,13 @@ public: private: FmeValue (*op)(FmeValue &a); FmeNode *operand_a; + QString description; }; class FmeNodeBinaryOp : public FmeNode { public: - FmeNodeBinaryOp(int priority, FmeValue (*op)(FmeValue &a, FmeValue &b), FmeNode *left); + FmeNodeBinaryOp(int priority, FmeValue (*op)(FmeValue &a, FmeValue &b), FmeNode *left, + QString description = "??"); virtual ~FmeNodeBinaryOp(); virtual bool eval(FmeValue &value, FmeSymbolDb *symdb, QString &error) override; virtual bool insert(FmeNode *node) override; @@ -106,6 +109,7 @@ private: FmeValue (*op)(FmeValue &a, FmeValue &b); FmeNode *operand_a; FmeNode *operand_b; + QString description; }; class FmeExpression : public FmeNode { |