فهرست منبع

refactor & feat: 定义虚继承

SongZihuan 3 سال پیش
والد
کامیت
2d7fe33772
6فایلهای تغییر یافته به همراه13 افزوده شده و 33 حذف شده
  1. 2 3
      include/core/msg.h
  2. 1 5
      include/core/msg.inline.h
  3. 5 8
      include/core/value.h
  4. 0 12
      include/core/value.inline.h
  5. 2 2
      src/core/msg.cpp
  6. 3 3
      test/src/run-code.cpp

+ 2 - 3
include/core/msg.h

@@ -26,9 +26,8 @@ namespace aFuncore {
     class Activation;
     class Inter;
 
-    class TopMessage : public Message {
+    class TopMessage : public virtual Message {
     public:
-        explicit inline TopMessage(const std::string &type_);
         virtual void topProgress(Inter &inter, Activation &activation) = 0;
     };
 
@@ -45,7 +44,7 @@ namespace aFuncore {
 
     class AFUN_CORE_EXPORT ErrorMessage : public TopMessage {
     public:
-        explicit ErrorMessage(const std::string &error_type_, const std::string &error_info_, Activation *activation);
+        explicit ErrorMessage(std::string error_type_, std::string error_info_, Activation *activation);
         void topProgress(Inter &inter_, Activation &activation) override;
         inline std::string getErrorType();
         inline std::string getErrorInfo();

+ 1 - 5
include/core/msg.inline.h

@@ -7,11 +7,7 @@ namespace aFuncore {
 
     }
 
-    inline TopMessage::TopMessage(const std::string &type_) : Message(type_) {
-
-    }
-
-    inline NormalMessage::NormalMessage(Object *obj_) : TopMessage("NORMAL"), obj {obj_} {
+    inline NormalMessage::NormalMessage(Object *obj_) : Message("NORMAL"), obj {obj_} {
 
     }
 

+ 5 - 8
include/core/value.h

@@ -18,11 +18,10 @@ namespace aFuncore {
         ~Object() override = default;
     };
 
-    class AFUN_CORE_EXPORT Function : public Object {
+    class AFUN_CORE_EXPORT Function : public virtual Object {
     public:
         class AFUN_CORE_EXPORT CallFunction;
 
-        inline Function(const std::string &type_, Inter &inter_);
         virtual CallFunction *getCallFunction(Code::ByteCode *code, Inter &inter) = 0;
         virtual inline bool isInfix();
     };
@@ -45,17 +44,15 @@ namespace aFuncore {
         Object *ret = nullptr;
     };
 
-    class AFUN_CORE_EXPORT Literaler : public Object {
+    class AFUN_CORE_EXPORT Literaler : public virtual Object {
     public:
-        inline Literaler(const std::string &type_, Inter &inter_);
         virtual void getObject(const std::string &literal, char prefix, Inter &inter, Activation &activation) = 0;
     };
 
-    class AFUN_CORE_EXPORT CallBackVar : public Object {
+    class AFUN_CORE_EXPORT CallBackVar : public virtual Object {
     public:
-        inline CallBackVar(const std::string &type_, Inter &inter_);
-        virtual inline bool isCallBack(Inter &inte, Activation &activation);
-        virtual void callBack(Inter &inte, Activation &activation) = 0;
+        virtual inline bool isCallBack(Inter &inter, Activation &activation);
+        virtual void callBack(Inter &inter, Activation &activation) = 0;
     };
 };
 

+ 0 - 12
include/core/value.inline.h

@@ -3,22 +3,10 @@
 #include "value.h"
 
 namespace aFuncore {
-    inline Function::Function(const std::string &type_, Inter &inter_) : Object(type_ + ":Function", inter_) {
-
-    }
-
     inline bool Function::isInfix() {
         return false;
     }
 
-    inline Literaler::Literaler(const std::string &type_, Inter &inter_) : Object(type_ + ":Literaler", inter_) {
-
-    }
-
-    inline CallBackVar::CallBackVar(const std::string &type_, Inter &inter_) : Object(type_ + ":CallBackVar", inter_) {
-
-    }
-
     inline bool CallBackVar::isCallBack(Inter &inter, Activation &activation) {
         return true;
     }

+ 2 - 2
src/core/msg.cpp

@@ -12,8 +12,8 @@ namespace aFuncore {
         aFuntool::printf_stdout(0, "NORMAL: %p\n", obj);  // TODO-szh 使用 Event
     }
 
-    ErrorMessage::ErrorMessage(const std::string &error_type_, const std::string &error_info_, Activation *activation)  // TODO-szh 使用Event
-            : TopMessage("ERROR"), error_type{error_type_}, error_info{error_info_}, inter{activation->inter}{
+    ErrorMessage::ErrorMessage(std::string error_type_, std::string error_info_, Activation *activation)  // TODO-szh 使用Event
+            : Message("ERROR"), error_type{std::move(error_type_)}, error_info{std::move(error_info_)}, inter{activation->inter}{
         for (NULL; activation != nullptr; activation = activation->toPrev()) {
             if (activation->getFileLine() != 0)
                 trackback.push_front({activation->getFilePath(), activation->getFileLine()});

+ 3 - 3
test/src/run-code.cpp

@@ -32,7 +32,7 @@ class Func1 : public Function {
 
     Code func_code;
 public:
-    explicit Func1(Inter &inter_) : Function("Function", inter_), func_code {"run-code.aun"} {
+    explicit Func1(Inter &inter_) : Object("Function", inter_), func_code {"run-code.aun"} {
         func_code.getByteCode()->connect(
                 new Code::ByteCode(func_code, Code::ByteCode::block_p,
                                    new Code::ByteCode(func_code, "test-var", 1), 0));
@@ -50,7 +50,7 @@ public:
 class Literaler1 : public Literaler {
     Code func_code;
 public:
-    explicit Literaler1(Inter &inter_) : Literaler("Data", inter_), func_code{"run-code.aun"} {
+    explicit Literaler1(Inter &inter_) : Object("Data", inter_), func_code{"run-code.aun"} {
         func_code.getByteCode()->connect(
                 new Code::ByteCode(func_code, Code::ByteCode::block_p,
                                    new Code::ByteCode(func_code, "test-var", 1), 0));
@@ -67,7 +67,7 @@ public:
 class CBV1 : public CallBackVar {
     Code func_code;
 public:
-    explicit CBV1(Inter &inter_) : CallBackVar("CBV1", inter_), func_code{"run-code.aun"} {
+    explicit CBV1(Inter &inter_) : Object("CBV1", inter_), func_code{"run-code.aun"} {
         func_code.getByteCode()->connect(
                 new Code::ByteCode(func_code, Code::ByteCode::block_p,
                                    new Code::ByteCode(func_code, "test-var", 1), 0));