Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 7b07dfec rédigé par Kubat's avatar Kubat
Parcourir les fichiers

EXPR: Implement toString for IrExpression

parent b2c93379
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!25Draft: New Vivy module spec
#include "IrExpression.hh" #include "IrExpression.hh"
#include "IrFunction.hh"
#include "IrElement.hh" #include "IrElement.hh"
#include "IrVariable.hh" #include "IrVariable.hh"
#include "IrType.hh" #include "IrType.hh"
...@@ -80,7 +81,18 @@ namespace Vivy::Script ...@@ -80,7 +81,18 @@ namespace Vivy::Script
std::string std::string
IrEVariableRef::toString() const noexcept 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) ...@@ -132,7 +144,7 @@ IrEConstExpr::IrEConstExpr(const Token &singleElement)
} }
case Token::Type::QNAME: 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 ...@@ -200,7 +212,15 @@ namespace Vivy::Script
std::string std::string
IrECall::toString() const noexcept 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 * const IrFunction *
...@@ -221,7 +241,7 @@ namespace Vivy::Script ...@@ -221,7 +241,7 @@ namespace Vivy::Script
std::string std::string
IrECompOp::toString() const noexcept IrECompOp::toString() const noexcept
{ {
return "IrECompOp"; return left->toString() + ::Vivy::Script::toString(selfOpType) + right->toString();
} }
} }
...@@ -230,7 +250,7 @@ namespace Vivy::Script ...@@ -230,7 +250,7 @@ namespace Vivy::Script
std::string std::string
IrEArithmeticOp::toString() const noexcept IrEArithmeticOp::toString() const noexcept
{ {
return "IrEArithmeticOp"; return left->toString() + ::Vivy::Script::toString(selfOpType) + right->toString();
} }
} }
...@@ -239,6 +259,44 @@ namespace Vivy::Script ...@@ -239,6 +259,44 @@ namespace Vivy::Script
std::string std::string
IrELogicOp::toString() const noexcept 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 "!=";
}
} }
} }
...@@ -129,13 +129,14 @@ class IrEVariableRef : public IrExpression { ...@@ -129,13 +129,14 @@ class IrEVariableRef : public IrExpression {
VIVY_IR_ELEMENT(IrEVariableRef) VIVY_IR_ELEMENT(IrEVariableRef)
IrVariable *const referencedVariable; IrVariable *const referencedVariable;
std::vector<IrExpression *> indicies;
IrEVariableRef(IrVariable *) noexcept; IrEVariableRef(IrVariable *) noexcept;
IrEVariableRef(IrVariable *, std::vector<IrExpression *> &&); IrEVariableRef(IrVariable *, std::vector<IrExpression *> &&);
template <typename... Args> IrEVariableRef(IrVariable *var, Args &&...indicies) template <typename... Args> IrEVariableRef(IrVariable *var, Args &&...indicieArgs)
: IrEVariableRef(var, std::vector<IrExpression *>{ indicies... }) : IrEVariableRef(var, std::vector<IrExpression *>{ indicieArgs... })
{ {
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter