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

FIX: Try to fix the CI + linking problems + FMT

- Solves linking problems with the scripts (not implemented constructors)
- Apply clang format
- Solves compilation problems
parent cbf5417c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!25Draft: New Vivy module spec
Pipeline #2872 réussi
...@@ -6,6 +6,13 @@ namespace Vivy::Script ...@@ -6,6 +6,13 @@ namespace Vivy::Script
{ {
IrElement::IrElement(IrElement *p) noexcept { setParent(p); } IrElement::IrElement(IrElement *p) noexcept { setParent(p); }
void
IrElement::throwUnexpectedToken(const Token &tok) const
{
throw std::runtime_error("Unexpected token in location " + tok.location().toString() + ": " +
tok.toString());
}
IrElement::~IrElement() noexcept IrElement::~IrElement() noexcept
{ {
std::erase_if(childElements, [this](IrElement *child) noexcept -> bool { std::erase_if(childElements, [this](IrElement *child) noexcept -> bool {
......
...@@ -116,6 +116,8 @@ protected: ...@@ -116,6 +116,8 @@ protected:
void detachElementFromParent() noexcept; void detachElementFromParent() noexcept;
void addChild(IrElement *) noexcept; void addChild(IrElement *) noexcept;
void throwUnexpectedToken(const Token &tok) const;
public: public:
virtual ~IrElement() noexcept; virtual ~IrElement() noexcept;
......
...@@ -242,8 +242,20 @@ IrECall::args() const noexcept ...@@ -242,8 +242,20 @@ IrECall::args() const noexcept
} }
} }
/*
** IrECompOp
*/
namespace Vivy::Script namespace Vivy::Script
{ {
IrECompOp::IrECompOp(OpType type, IrExpression *&&leftA, IrExpression *&&rightA) noexcept
: IrExpression(nullptr, Type::ArithmeticOp)
, selfOpType(type)
, left(leftA)
, right(rightA)
{
}
std::string std::string
IrECompOp::toString() const noexcept IrECompOp::toString() const noexcept
{ {
...@@ -251,8 +263,21 @@ IrECompOp::toString() const noexcept ...@@ -251,8 +263,21 @@ IrECompOp::toString() const noexcept
} }
} }
/*
** IrEArithmeticOp
*/
namespace Vivy::Script namespace Vivy::Script
{ {
IrEArithmeticOp::IrEArithmeticOp(OpType type, IrExpression *&&leftA,
IrExpression *&&rightA) noexcept
: IrExpression(nullptr, Type::ArithmeticOp)
, selfOpType(type)
, left(leftA)
, right(rightA)
{
}
std::string std::string
IrEArithmeticOp::toString() const noexcept IrEArithmeticOp::toString() const noexcept
{ {
...@@ -260,8 +285,20 @@ IrEArithmeticOp::toString() const noexcept ...@@ -260,8 +285,20 @@ IrEArithmeticOp::toString() const noexcept
} }
} }
/*
** IrELogicOp
*/
namespace Vivy::Script namespace Vivy::Script
{ {
IrELogicOp::IrELogicOp(OpType type, IrExpression *&&leftA, IrExpression *&&rightA) noexcept
: IrExpression(nullptr, Type::LogicOp)
, selfOpType(type)
, left(leftA)
, right(rightA)
{
}
std::string std::string
IrELogicOp::toString() const noexcept IrELogicOp::toString() const noexcept
{ {
...@@ -269,6 +306,10 @@ IrELogicOp::toString() const noexcept ...@@ -269,6 +306,10 @@ IrELogicOp::toString() const noexcept
} }
} }
/*
** Free functions
*/
namespace Vivy::Script namespace Vivy::Script
{ {
std::string std::string
...@@ -307,6 +348,10 @@ toString(IrECompOp::OpType op) noexcept ...@@ -307,6 +348,10 @@ toString(IrECompOp::OpType op) noexcept
} }
} }
/*
** Binary expressions' type from tokens
*/
namespace Vivy::Script namespace Vivy::Script
{ {
IrELogicOp::OpType IrELogicOp::OpType
......
...@@ -20,6 +20,35 @@ private: ...@@ -20,6 +20,35 @@ private:
Type selfType; Type selfType;
IrType *selfInnerType = nullptr; IrType *selfInnerType = nullptr;
/*
** Helper for the parser, create a binary expression, insert the last expression at
** the right and update the current expression pointer.
*/
template <typename IrT> IrExpression *createOpElement(IrExpression *&current, Token tok)
{
return dynamic_cast<IrExpression *>(
IrElement::create<IrT>(nullptr, /* The parent, will be set later */
IrT::getOpFromToken(tok), /* The type of operation (+,-,...) */
std::move(nullptr), /* We leave the left empty for now */
std::move(current) /* We add everything to the right */
));
}
/*
** Helper for the parser, update the left expression of a binary expression or throw
** an error if there was already somthing.
*/
template <typename IrT> void updateLeft(IrExpression *current, IrExpression *newLeft, Token tok)
{
IrT *typpedCurrent = dynamic_cast<IrT *>(current);
if (typpedCurrent->left != nullptr)
throw std::runtime_error("Unexpected token in expression parsing: " + tok.toString());
typpedCurrent->left = newLeft;
newLeft->setParent(current);
}
protected: protected:
IrExpression(IrElement *p, Type) noexcept; IrExpression(IrElement *p, Type) noexcept;
......
...@@ -5,47 +5,31 @@ auto throwUnexpectedToken = [](const Token &tok) { ...@@ -5,47 +5,31 @@ auto throwUnexpectedToken = [](const Token &tok) {
tok.toString()); tok.toString());
}; };
auto createOpElement = []<typename IrT>(IrExpression *&current, Token tok) -> IrT* {
return dynamic_cast<IrExpression *>(IrElement::create<IrT>(
nullptr, /* The parent, will be set later */
IrT::getOpFromToken(tok), /* The type of operation (+,-,...) */
std::move(nullptr), /* We leave the left empty for now */
std::move(current) /* We add everything to the right */
));
};
/* <|!!|> The left will be left empty (nullptr) */ /* <|!!|> The left will be left empty (nullptr) */
auto updateExprWithInfixOperator = [throwUnexpectedToken, createOpElement]( auto updateExprWithInfixOperator = [this, throwUnexpectedToken](IrExpression *&current,
IrExpression *&current, Token tok) -> void Token tok) -> void {
{
/* operation -> new current, add old into right */ /* operation -> new current, add old into right */
if (current->isInfixOperator()) if (current->isInfixOperator())
throwUnexpectedToken(tok); throwUnexpectedToken(tok);
current = current = (tok.isSimple(TOKEN_LIST_ARITHMETIC_OP))
(tok.isSimple(TOKEN_LIST_ARITHMETIC_OP)) ? createOpElement<IrEArithmeticOp>(current, tok) ? createOpElement<IrEArithmeticOp>(current, tok)
: (tok.isSimple(TOKEN_LIST_LOGIC_OP)) ? createOpElement<IrELogicOp>(current, tok) : (tok.isSimple(TOKEN_LIST_LOGIC_OP)) ? createOpElement<IrELogicOp>(current, tok)
: (tok.isSimple(TOKEN_LIST_COMP_OP)) ? createOpElement<IrECompOp>(current, tok) : (tok.isSimple(TOKEN_LIST_COMP_OP))
: throw std::runtime_error("Can't create an infix operation from token " + tok.toString()); ? createOpElement<IrECompOp>(current, tok)
}; : throw std::runtime_error("Can't create an infix operation from token " +
tok.toString());
auto updateLeft = []<typename IrT>(IrExpression *current, IrExpression *newLeft) -> void {
IrT *typpedCurrent = dynamic_cast<IrT *>(current);
if (typpedCurrent->left != nullptr)
throw std::runtime_error("Unexpected token in expression parsing: " + tok.toString());
typpedCurrent->left = newLeft;
newLeft->setParent(current);
}; };
auto updateExprWithConstExpr = [updateLeft](IrExpression *&current, Token tok) -> void { auto updateExprWithConstExpr = [this](IrExpression *&current, Token tok) -> void {
IrExpression *newLeft = IrElement::create<IrEConstExpr>(current, tok); IrExpression *newLeft = IrElement::create<IrEConstExpr>(current, tok);
/* (... `op` <- currentExpression) newLeft -> currentExpression */ /* (... `op` <- currentExpression) newLeft -> currentExpression */
if (current != nullptr) { if (current != nullptr) {
switch (current->type()) { switch (current->type()) {
case Type::CompOp: return <IrECompOp>(current, newLeft); case Type::CompOp: return updateLeft<IrECompOp>(current, newLeft, tok);
case Type::ArithmeticOp: return updateLeft<IrEArithmeticOp>(current, newLeft); case Type::ArithmeticOp: return updateLeft<IrEArithmeticOp>(current, newLeft, tok);
case Type::LogicOp: return updateLeft<IrELogicOp>(current, newLeft); case Type::LogicOp: return updateLeft<IrELogicOp>(current, newLeft, tok);
case Type::ConstExpr: case Type::ConstExpr:
case Type::Call: case Type::Call:
case Type::VariableRef: throw std::runtime_error("Invalid expression"); case Type::VariableRef: throw std::runtime_error("Invalid expression");
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter