Procházet zdrojové kódy

refactor: 使用初始化列表取代部分赋值

SongZihuan před 3 roky
rodič
revize
e69f891680

+ 4 - 5
include/core/inter.h

@@ -53,11 +53,10 @@ namespace aFuncore {
         struct LiteralRegex;
     public:
         typedef enum InterStatus {
-            inter_creat = 0,
-            inter_init = 1,  // 执行初始化程序
-            inter_normal = 2,  // 正常执行
-            inter_stop = 3,  // 当前运算退出
-            inter_exit = 4,  // 解释器退出
+            inter_init = 0,  // 执行初始化程序
+            inter_normal = 1,  // 正常执行
+            inter_stop = 2,  // 当前运算退出
+            inter_exit = 3,  // 解释器退出
         } InterStatus;
 
         typedef enum Prefix {

+ 1 - 1
include/core/object-value.h

@@ -108,7 +108,7 @@ namespace aFuncore {
         inline Object *setObject(Object *res);
         inline Object *getObject();
     private:
-        Object *ret = nullptr;
+        Object *ret;
     };
 
     class AFUN_CORE_EXPORT Literaler : public virtual Object {

+ 3 - 4
include/core/reader.inline.h

@@ -4,10 +4,9 @@
 
 namespace aFuncore {
     inline Reader::Reader(aFuntool::FilePath path_, aFuntool::FileLine line_)
-            : path{std::move(path_)}, line{line_}, read_end{false}, read_error{false} {
-        buf = aFuntool::safeCalloc<char>(DEFAULT_BUF_SIZE + 1);
-        buf_size = DEFAULT_BUF_SIZE;  // buf_size 不包括NUL
-        read = buf;
+            : path{std::move(path_)}, line{line_}, read_end{false}, read_error{false},
+              buf{aFuntool::safeCalloc<char>(DEFAULT_BUF_SIZE + 1)}, buf_size{DEFAULT_BUF_SIZE}, read{buf} {
+
     }
 
     size_t Reader::countRead() const {

+ 3 - 6
include/interface/it-reader.inline.h

@@ -5,17 +5,14 @@
 
 namespace aFunit {
     inline StringReader::StringReader(std::string str_, const aFuntool::FilePath &path_)
-        : Reader{path_, 0}, str{std::move(str_)} {
-        index = 0;
-        len = str.size();
+        : Reader{path_, 0}, str{std::move(str_)}, index{0}, len{str.size()} {
+
     }
 
     inline FileReader::FileReader(const aFuntool::FilePath &path_)
-        : Reader{path_, 0} {
-        file = aFuntool::fileOpen(path_, "rb");
+        : Reader{path_, 0}, file{aFuntool::fileOpen(path_, "rb")}, no_first{false} {
         if (file == nullptr)
             throw readerFileOpenError(path_);
-        no_first = false;
     }
 }
 

+ 2 - 3
include/tool/log.inline.h

@@ -4,9 +4,8 @@
 
 namespace aFuntool {
     inline aFuntool::Logger::Logger(LogFactory &factor, std::string id, LogLevel level, bool exit) noexcept
-        : factor_{factor}, id_ {std::move(id)} {
-        level_ = level;
-        exit_ = exit;
+        : factor_{factor}, id_{std::move(id)}, level_{level}, exit_{exit} {
+
     }
 }
 

+ 2 - 4
src/core/activation.cpp

@@ -238,10 +238,8 @@ namespace aFuncore {
 
     }
 
-    FuncActivation::FuncActivation(Function *func_, Inter &inter_) : Activation(inter_), call{nullptr}, acl_begin{}, acl_end{} {
-        on_tail = false;  // 跳过所有阶段
-        status = func_get_func;
-        func = func_;
+    FuncActivation::FuncActivation(Function *func_, Inter &inter_)
+        : Activation(inter_), call{nullptr}, acl_begin{}, acl_end{}, on_tail{false}, status{func_get_func}, func{func_}  {
         func->addReference();
     }
 

+ 2 - 13
src/core/inter.cpp

@@ -6,25 +6,14 @@
 
 namespace aFuncore {
     Inter::Inter(Environment &env_)
-            : out{}, in{}, env{env_}{
-        status = inter_creat;
-
-        activation = nullptr;
-
-        status = inter_init;
+            : out{}, in{}, env{env_}, status{inter_init}, activation{nullptr} {
         env++;
     }
 
     Inter::Inter(const Inter &base_inter)
-            : out{}, in{}, env{base_inter.env}{
-        status = inter_creat;
-
-        activation = nullptr;
-
+            : out{}, in{}, env{base_inter.env}, status{inter_init}, activation{nullptr}{
         for (auto &i: base_inter.literal)
             literal.push_back(i);
-
-        status = inter_normal;
         env++;
     }