From b9cbae06fadec5117c166922816ab4173cae8b27 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 3 Mar 2022 20:56:21 +0100 Subject: [PATCH] SCRIPT: Add a name getter for IrVariable + add constructors and enforce the const-ness of the name of a variable --- src/Lib/Script/Ast/IrExpression.hh | 2 +- src/Lib/Script/Ast/IrVariable.cc | 22 ++++++++++++++++++++++ src/Lib/Script/Ast/IrVariable.hh | 11 ++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Lib/Script/Ast/IrExpression.hh b/src/Lib/Script/Ast/IrExpression.hh index fa03a36d..cb8bf1a4 100644 --- a/src/Lib/Script/Ast/IrExpression.hh +++ b/src/Lib/Script/Ast/IrExpression.hh @@ -26,7 +26,7 @@ private: ** the right and update the current expression pointer. */ - template <typename IrT> IrExpression *createOpElement(IrExpression *¤t, Token tok) + template <IrElementObject IrT> IrExpression *createOpElement(IrExpression *¤t, Token tok) { return dynamic_cast<IrExpression *>( IrElement::create<IrT>(nullptr, /* The parent, will be set later */ diff --git a/src/Lib/Script/Ast/IrVariable.cc b/src/Lib/Script/Ast/IrVariable.cc index 573c0130..f844b3a9 100644 --- a/src/Lib/Script/Ast/IrVariable.cc +++ b/src/Lib/Script/Ast/IrVariable.cc @@ -6,6 +6,18 @@ namespace Vivy::Script { +IrVariable::IrVariable(StrV name) noexcept + : IrElement(nullptr) + , selfName(name) +{ +} + +StrV +IrVariable::name() const noexcept +{ + return selfName; +} + std::string IrVariable::toString() const noexcept { @@ -26,6 +38,11 @@ IrVariable::innerType() const noexcept namespace Vivy::Script { +IrVPrimitive::IrVPrimitive(StrV name) noexcept + : IrVariable(name) +{ +} + IrVariable::Type IrVPrimitive::type() const noexcept { @@ -41,6 +58,11 @@ IrVPrimitive::toString() const noexcept namespace Vivy::Script { +IrVTable::IrVTable(StrV name) noexcept + : IrVariable(name) +{ +} + IrVariable::Type IrVTable::type() const noexcept { diff --git a/src/Lib/Script/Ast/IrVariable.hh b/src/Lib/Script/Ast/IrVariable.hh index 161fa99e..d25d9a5f 100644 --- a/src/Lib/Script/Ast/IrVariable.hh +++ b/src/Lib/Script/Ast/IrVariable.hh @@ -1,6 +1,7 @@ #pragma once #include "IrElement.hh" +#include "Lib/Script/FrontEnd/StrV.hh" namespace Vivy::Script { @@ -8,19 +9,25 @@ class IrVariable : public IrElement { VIVY_IR_ELEMENT(IrVariable) IrType *selfInnerType = nullptr; + const StrV selfName; + +protected: + IrVariable(StrV name) noexcept; public: enum class Type { Primitive, Table }; -public: virtual Type type() const noexcept = 0; const IrType *innerType() const noexcept; std::string toString() const noexcept override; + StrV name() const noexcept; }; class IrVPrimitive : public IrVariable { VIVY_IR_ELEMENT(IrVPrimitive) + IrVPrimitive(StrV) noexcept; + public: Type type() const noexcept override; std::string toString() const noexcept override; @@ -29,6 +36,8 @@ public: class IrVTable : public IrVariable { VIVY_IR_ELEMENT(IrVTable) + IrVTable(StrV) noexcept; + public: Type type() const noexcept override; std::string toString() const noexcept override; -- GitLab