From d6360045f1535def08c3d20e4207e7c1ae81ae72 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Fri, 11 Feb 2022 15:43:28 +0100
Subject: [PATCH] WIP: Remove the `parse` method from IrElement, use a template
 base solution to avoid defining a method that makes no sens for some base
 classes

---
 src/Lib/Script/Ast/IrAttribute.hh         |  2 +-
 src/Lib/Script/Ast/IrCallableSignature.cc |  2 +-
 src/Lib/Script/Ast/IrCallableSignature.hh |  2 +-
 src/Lib/Script/Ast/IrElement.hh           |  1 -
 src/Lib/Script/Ast/IrExpression.cc        | 36 -----------------------
 src/Lib/Script/Ast/IrExpression.hh        |  2 +-
 src/Lib/Script/Ast/IrFunction.cc          | 12 --------
 src/Lib/Script/Ast/IrFunction.hh          |  3 --
 src/Lib/Script/Ast/IrImport.hh            |  2 +-
 src/Lib/Script/Ast/IrInstruction.hh       |  2 +-
 src/Lib/Script/Ast/IrJob.cc               | 12 --------
 src/Lib/Script/Ast/IrJob.hh               |  3 --
 src/Lib/Script/Ast/IrModule.hh            |  2 +-
 src/Lib/Script/Ast/IrOption.hh            |  2 +-
 src/Lib/Script/Ast/IrRoot.hh              |  2 +-
 src/Lib/Script/Ast/IrType.cc              | 12 --------
 src/Lib/Script/Ast/IrType.hh              |  4 +--
 src/Lib/Script/Ast/IrVariable.cc          | 12 --------
 src/Lib/Script/Ast/IrVariable.hh          |  2 --
 19 files changed, 10 insertions(+), 105 deletions(-)

diff --git a/src/Lib/Script/Ast/IrAttribute.hh b/src/Lib/Script/Ast/IrAttribute.hh
index 0371e989..a9f824a5 100644
--- a/src/Lib/Script/Ast/IrAttribute.hh
+++ b/src/Lib/Script/Ast/IrAttribute.hh
@@ -22,7 +22,7 @@ class IrAttribute : public IrElement {
 
 public:
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 
     std::vector<StrV> attribute(const std::string &name) const noexcept;
     std::vector<StrV> attribute(StrV askedName) const noexcept;
diff --git a/src/Lib/Script/Ast/IrCallableSignature.cc b/src/Lib/Script/Ast/IrCallableSignature.cc
index 563fad09..e0846b23 100644
--- a/src/Lib/Script/Ast/IrCallableSignature.cc
+++ b/src/Lib/Script/Ast/IrCallableSignature.cc
@@ -11,7 +11,7 @@ IrCallableSignature::toString() const noexcept
 void
 IrCallableSignature::parse(std::vector<Token> *)
 {
-    throw std::logic_error("Not implemented");
+    throw std::logic_error("IrCallableSignature::parse => Not implemented");
 }
 
 const std::vector<IrType *> &
diff --git a/src/Lib/Script/Ast/IrCallableSignature.hh b/src/Lib/Script/Ast/IrCallableSignature.hh
index 7b03626d..4100da33 100644
--- a/src/Lib/Script/Ast/IrCallableSignature.hh
+++ b/src/Lib/Script/Ast/IrCallableSignature.hh
@@ -17,7 +17,7 @@ private:
 
 public:
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 
     const std::vector<IrType *> &inTypes() const noexcept;
     const IrType *retType() const noexcept;
diff --git a/src/Lib/Script/Ast/IrElement.hh b/src/Lib/Script/Ast/IrElement.hh
index cc70e756..5ee9aa8e 100644
--- a/src/Lib/Script/Ast/IrElement.hh
+++ b/src/Lib/Script/Ast/IrElement.hh
@@ -123,7 +123,6 @@ public:
     void setAttribute(IrAttribute *a) noexcept;
 
     virtual std::string toString() const noexcept = 0;
-    virtual void parse(std::vector<Token> *)      = 0;
 
     /*
     ** Get attributes for an element!
diff --git a/src/Lib/Script/Ast/IrExpression.cc b/src/Lib/Script/Ast/IrExpression.cc
index 7669714d..967812df 100644
--- a/src/Lib/Script/Ast/IrExpression.cc
+++ b/src/Lib/Script/Ast/IrExpression.cc
@@ -78,12 +78,6 @@ IrEVariableRef::toString() const noexcept
 {
     return "IrEVariableRef";
 }
-
-void
-IrEVariableRef::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
 
 /*
@@ -168,12 +162,6 @@ IrEConstExpr::toString() const noexcept
         case IrType::PrimitiveType::Bool: return inner.boolean ? std::string("true") : std::string("false");
     }
 }
-
-void
-IrEConstExpr::parse(std::vector<Token> *)
-{
-    throw std::logic_error("IrEConstExpr::parse Not implemented");
-}
 }
 
 /*
@@ -188,12 +176,6 @@ IrECall::toString() const noexcept
     return "IrECall";
 }
 
-void
-IrECall::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
-
 const IrFunction *IrECall::call() const noexcept
 {
     return callPtr;
@@ -212,12 +194,6 @@ IrECompOp::toString() const noexcept
 {
     return "IrECompOp";
 }
-
-void
-IrECompOp::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
 
 namespace Vivy::Script
@@ -227,12 +203,6 @@ IrEArithmeticOp::toString() const noexcept
 {
     return "IrEArithmeticOp";
 }
-
-void
-IrEArithmeticOp::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
 
 namespace Vivy::Script
@@ -242,10 +212,4 @@ IrELogicOp::toString() const noexcept
 {
     return "IrELogicOp";
 }
-
-void
-IrELogicOp::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
diff --git a/src/Lib/Script/Ast/IrExpression.hh b/src/Lib/Script/Ast/IrExpression.hh
index 95688f62..2de5505a 100644
--- a/src/Lib/Script/Ast/IrExpression.hh
+++ b/src/Lib/Script/Ast/IrExpression.hh
@@ -24,7 +24,7 @@ protected:
 
 public:
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 
     Type type() const noexcept;
     virtual IrType *innerType() const noexcept;
diff --git a/src/Lib/Script/Ast/IrFunction.cc b/src/Lib/Script/Ast/IrFunction.cc
index 99bab6d9..dc7ce0c4 100644
--- a/src/Lib/Script/Ast/IrFunction.cc
+++ b/src/Lib/Script/Ast/IrFunction.cc
@@ -11,12 +11,6 @@ IrFunction::IrFunction(StrV name, const std::vector<IrType *> &argInTypes, const
 {
 }
 
-void
-IrFunction::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
-
 const IrModule *
 IrFunction::parent() const noexcept
 {
@@ -64,12 +58,6 @@ IrImportedFunction::toString() const noexcept
     return "IrImportedFunction";
 }
 
-void
-IrImportedFunction::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Unsuported parse operation on imported function");
-}
-
 IrFunction::Type
 IrImportedFunction::type() const noexcept
 {
diff --git a/src/Lib/Script/Ast/IrFunction.hh b/src/Lib/Script/Ast/IrFunction.hh
index 9ba35e0f..fb4446bc 100644
--- a/src/Lib/Script/Ast/IrFunction.hh
+++ b/src/Lib/Script/Ast/IrFunction.hh
@@ -24,7 +24,6 @@ public:
     IrModule *parent() noexcept override;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
     const IrType *retType() const noexcept;
     const std::vector<IrType *> &args() const noexcept;
     StrV name() const noexcept;
@@ -43,8 +42,6 @@ class IrImportedFunction : public IrFunction {
 
     IrImportedFunction(IrModule *p, const IrFunction *original, StrV name) noexcept;
 
-    void parse(std::vector<Token> *) override;
-
 public:
     std::string toString() const noexcept override;
     Type type() const noexcept override;
diff --git a/src/Lib/Script/Ast/IrImport.hh b/src/Lib/Script/Ast/IrImport.hh
index 6f79fdcd..401e2cf0 100644
--- a/src/Lib/Script/Ast/IrImport.hh
+++ b/src/Lib/Script/Ast/IrImport.hh
@@ -50,7 +50,7 @@ public:
     const IrModule *parent() const noexcept override;
     IrModule *parent() noexcept override;
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 
     Type type() const noexcept { return importType; }
     const IrElement *imported() const noexcept { return importedElement; }
diff --git a/src/Lib/Script/Ast/IrInstruction.hh b/src/Lib/Script/Ast/IrInstruction.hh
index 832c2397..1ee058c1 100644
--- a/src/Lib/Script/Ast/IrInstruction.hh
+++ b/src/Lib/Script/Ast/IrInstruction.hh
@@ -10,6 +10,6 @@ private:
 
 public:
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 };
 }
diff --git a/src/Lib/Script/Ast/IrJob.cc b/src/Lib/Script/Ast/IrJob.cc
index d6d393bc..6f5fdc58 100644
--- a/src/Lib/Script/Ast/IrJob.cc
+++ b/src/Lib/Script/Ast/IrJob.cc
@@ -51,12 +51,6 @@ IrImportedJob::toString() const noexcept
     return "IrJob";
 }
 
-void
-IrJob::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
-
 IrJob::Type
 IrImportedJob::type() const noexcept
 {
@@ -105,12 +99,6 @@ IrJob::type() const noexcept
     return Type::Local;
 }
 
-void
-IrImportedJob::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Unsuported parse operation on imported job");
-}
-
 const IrInstruction *
 IrJob::body() const noexcept
 {
diff --git a/src/Lib/Script/Ast/IrJob.hh b/src/Lib/Script/Ast/IrJob.hh
index 28b59b98..800fea39 100644
--- a/src/Lib/Script/Ast/IrJob.hh
+++ b/src/Lib/Script/Ast/IrJob.hh
@@ -40,7 +40,6 @@ public:
     IrModule *parent() noexcept override;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
 
     const std::vector<IrType *> &args() const noexcept;
     const IrOption *options() const noexcept;
@@ -67,8 +66,6 @@ class IrImportedJob : public IrJob {
 
     IrImportedJob(IrModule *p, IrJob *original, StrV name) noexcept;
 
-    void parse(std::vector<Token> *) override;
-
 public:
     std::string toString() const noexcept override;
     Type type() const noexcept override;
diff --git a/src/Lib/Script/Ast/IrModule.hh b/src/Lib/Script/Ast/IrModule.hh
index 7da7b612..75c386e3 100644
--- a/src/Lib/Script/Ast/IrModule.hh
+++ b/src/Lib/Script/Ast/IrModule.hh
@@ -22,7 +22,7 @@ public:
     IrRoot *parent() noexcept override;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 
     StrV name() const noexcept { return moduleName; }
 
diff --git a/src/Lib/Script/Ast/IrOption.hh b/src/Lib/Script/Ast/IrOption.hh
index 6e4fae6d..7057ceac 100644
--- a/src/Lib/Script/Ast/IrOption.hh
+++ b/src/Lib/Script/Ast/IrOption.hh
@@ -45,7 +45,7 @@ public:
     bool isEmpty() const noexcept;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 
     static IrOption *empty() noexcept;
 };
diff --git a/src/Lib/Script/Ast/IrRoot.hh b/src/Lib/Script/Ast/IrRoot.hh
index 6d31e207..1c4d5d87 100644
--- a/src/Lib/Script/Ast/IrRoot.hh
+++ b/src/Lib/Script/Ast/IrRoot.hh
@@ -16,7 +16,7 @@ public:
     IrRoot *parent() noexcept override;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *tokens) override;
+    void parse(std::vector<Token> *tokens);
 
     const IrModule *module(const std::string &name) const noexcept;
     IrModule *module(const std::string &name) noexcept;
diff --git a/src/Lib/Script/Ast/IrType.cc b/src/Lib/Script/Ast/IrType.cc
index 9b9b0312..972e4a8b 100644
--- a/src/Lib/Script/Ast/IrType.cc
+++ b/src/Lib/Script/Ast/IrType.cc
@@ -106,12 +106,6 @@ void IrTAss::assertInnerType(AssType type) const
         throw std::runtime_error("Expected inner type " + std::to_string(static_cast<int>(t)) + " but was type " + std::to_string(static_cast<int>(innerType())));
     }
 }
-
-void
-IrTAss::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
 
 /*
@@ -142,12 +136,6 @@ IrTOption::toString() const noexcept
 {
     return "IrTOption";
 }
-
-void
-IrTOption::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
 
 /*
diff --git a/src/Lib/Script/Ast/IrType.hh b/src/Lib/Script/Ast/IrType.hh
index e6f9ad3e..7b09d2b7 100644
--- a/src/Lib/Script/Ast/IrType.hh
+++ b/src/Lib/Script/Ast/IrType.hh
@@ -44,7 +44,6 @@ public:
     unsigned int getArrayDimensionAt(unsigned int level) const;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
 };
 
 class IrTOption final : public IrType {
@@ -59,7 +58,6 @@ public:
     const IrOption *innerType() const noexcept;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
 };
 
 class IrTPrimitive final : public IrType {
@@ -87,7 +85,7 @@ public:
     unsigned int getArrayDimensionAt(unsigned int level) const;
 
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
+    void parse(std::vector<Token> *);
 };
 
 [[maybe_unused]] static bool
diff --git a/src/Lib/Script/Ast/IrVariable.cc b/src/Lib/Script/Ast/IrVariable.cc
index b4506443..573c0130 100644
--- a/src/Lib/Script/Ast/IrVariable.cc
+++ b/src/Lib/Script/Ast/IrVariable.cc
@@ -37,12 +37,6 @@ IrVPrimitive::toString() const noexcept
 {
     return "IrVPrimitive";
 }
-
-void
-IrVPrimitive::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
 
 namespace Vivy::Script
@@ -58,10 +52,4 @@ IrVTable::toString() const noexcept
 {
     return "IrVTable";
 }
-
-void
-IrVTable::parse(std::vector<Token> *)
-{
-    throw std::logic_error("Not implemented");
-}
 }
diff --git a/src/Lib/Script/Ast/IrVariable.hh b/src/Lib/Script/Ast/IrVariable.hh
index 6ca0a278..161fa99e 100644
--- a/src/Lib/Script/Ast/IrVariable.hh
+++ b/src/Lib/Script/Ast/IrVariable.hh
@@ -24,7 +24,6 @@ class IrVPrimitive : public IrVariable {
 public:
     Type type() const noexcept override;
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
 };
 
 class IrVTable : public IrVariable {
@@ -33,6 +32,5 @@ class IrVTable : public IrVariable {
 public:
     Type type() const noexcept override;
     std::string toString() const noexcept override;
-    void parse(std::vector<Token> *) override;
 };
 }
-- 
GitLab