diff --git a/src/Lib/Script/Ast/IrExpression.cc b/src/Lib/Script/Ast/IrExpression.cc index 10cf3fe11e0ba5b400949e907d92ea2752a0c58a..f2111cdd6085557966c7a0f19fe316cf9e9edc2f 100644 --- a/src/Lib/Script/Ast/IrExpression.cc +++ b/src/Lib/Script/Ast/IrExpression.cc @@ -1,4 +1,5 @@ #include "IrExpression.hh" +#include "IrFunction.hh" #include "IrElement.hh" #include "IrVariable.hh" #include "IrType.hh" @@ -80,7 +81,18 @@ namespace Vivy::Script std::string IrEVariableRef::toString() const noexcept { - return "IrEVariableRef"; + std::string ret = referencedVariable->toString(); + if (indicies.size() != 0) { + ret += "{"; + size_t i; + for (i = 0; i < indicies.size() - 1; i += 1) { + ret += indicies.at(i)->toString(); + ret += ","; + } + ret += indicies.at(i)->toString(); + ret += "}"; + } + return ret; } } @@ -132,7 +144,7 @@ IrEConstExpr::IrEConstExpr(const Token &singleElement) } case Token::Type::QNAME: - default: throw std::logic_error("IrEConstExpr unexpected token: " + singleElement.toString()); + throw std::logic_error("IrEConstExpr unexpected token: " + singleElement.toString()); } } @@ -200,7 +212,15 @@ namespace Vivy::Script std::string IrECall::toString() const noexcept { - return "IrECall"; + std::string ret = callPtr->parent()->name().toStdString() + "."; + ret += callPtr->name().toStdString() + "("; + size_t i; + for (i = 0; i < inArgs.size() - 1; i += 1) { + ret += inArgs.at(i)->toString(); + ret += ","; + } + ret += inArgs.at(i)->toString() + ")"; + return ret; } const IrFunction * @@ -221,7 +241,7 @@ namespace Vivy::Script std::string IrECompOp::toString() const noexcept { - return "IrECompOp"; + return left->toString() + ::Vivy::Script::toString(selfOpType) + right->toString(); } } @@ -230,7 +250,7 @@ namespace Vivy::Script std::string IrEArithmeticOp::toString() const noexcept { - return "IrEArithmeticOp"; + return left->toString() + ::Vivy::Script::toString(selfOpType) + right->toString(); } } @@ -239,6 +259,44 @@ namespace Vivy::Script std::string IrELogicOp::toString() const noexcept { - return "IrELogicOp"; + return left->toString() + ::Vivy::Script::toString(selfOpType) + right->toString(); +} +} + +namespace Vivy::Script +{ +std::string +toString(IrELogicOp::OpType op) noexcept +{ + switch (op) { + case IrELogicOp::OpType::And: return "and"; + case IrELogicOp::OpType::Or: return "or"; + case IrELogicOp::OpType::Xor: return "xor"; + } +} + +std::string +toString(IrEArithmeticOp::OpType op) noexcept +{ + switch (op) { + case IrEArithmeticOp::OpType::Sub: return "sub"; + case IrEArithmeticOp::OpType::Add: return "add"; + case IrEArithmeticOp::OpType::Mul: return "mul"; + case IrEArithmeticOp::OpType::Div: return "div"; + case IrEArithmeticOp::OpType::Mod: return "mod"; + } +} + +std::string +toString(IrECompOp::OpType op) noexcept +{ + switch (op) { + case IrECompOp::OpType::LT: return "<"; + case IrECompOp::OpType::LE: return "<="; + case IrECompOp::OpType::GT: return ">"; + case IrECompOp::OpType::GE: return ">="; + case IrECompOp::OpType::EQ: return "=="; + case IrECompOp::OpType::NEQ: return "!="; + } } } diff --git a/src/Lib/Script/Ast/IrExpression.hh b/src/Lib/Script/Ast/IrExpression.hh index 93ea0f69d200b9e1eadae501cc2f1476f533e65e..6f92db8ad7cff25bc52123738cccb786b2ccfdeb 100644 --- a/src/Lib/Script/Ast/IrExpression.hh +++ b/src/Lib/Script/Ast/IrExpression.hh @@ -129,13 +129,14 @@ class IrEVariableRef : public IrExpression { VIVY_IR_ELEMENT(IrEVariableRef) IrVariable *const referencedVariable; + std::vector<IrExpression *> indicies; IrEVariableRef(IrVariable *) noexcept; IrEVariableRef(IrVariable *, std::vector<IrExpression *> &&); - template <typename... Args> IrEVariableRef(IrVariable *var, Args &&...indicies) - : IrEVariableRef(var, std::vector<IrExpression *>{ indicies... }) + template <typename... Args> IrEVariableRef(IrVariable *var, Args &&...indicieArgs) + : IrEVariableRef(var, std::vector<IrExpression *>{ indicieArgs... }) { }