瀏覽代碼

refactor & fix: 调整警告级别并修复部分GCC问题

* 修复未使用参数问题
SongZihuan 3 年之前
父節點
當前提交
dc12940a3a

+ 6 - 6
CMakeLists.txt

@@ -11,11 +11,11 @@ project(aFun
 
 # CMake系统的相关设定
 set(CMAKE_C_STANDARD 11)
-set(C_EXTENSIONS ON)  # 启动编译器拓展
+set(C_EXTENSIONS OFF)  # 启动编译器拓展
 set(C_STANDARD_REQUIRED OFF)
 
 set(CMAKE_CXX_STANDARD 20)
-set(CXX_EXTENSIONS ON)  # 启动编译器拓展
+set(CXX_EXTENSIONS OFF)  # 启动编译器拓展
 set(CXX_STANDARD_REQUIRED OFF)
 
 set(BUILD_SHARED_LIBS OFF)  # 默认编译静态库 (该设定不可被修改)
@@ -43,8 +43,8 @@ unset(fpic_enable)
 
 if (MSVC)
     if(CMAKE_BUILD_TYPE EQUAL Debug)
-        set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Debug /Wall")
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Debug /Wall")
+        set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Debug /W4")
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Debug /W4")
     else()
         set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /Wall")
         set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /GR /EHsc /Wall")
@@ -52,8 +52,8 @@ if (MSVC)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
 else()
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexec-charset=UTF-8 -Wall")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexec-charset=UTF-8 -Wall")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic -ansi")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic -ansi")
 endif()
 
 # 相关参数

+ 2 - 2
include/core/code.h

@@ -78,10 +78,10 @@ namespace aFuncore {
 
         union CodeData {
             char *element;  // union 内不使用 std::string
-            struct {  // NOLINT 不需要初始化
+            struct Block {  // NOLINT 不需要初始化
                 BlockType block_type;
                 ByteCode *son;
-            };
+            } block;
             AFUN_INLINE CodeData();
         } data;
 

+ 2 - 2
include/core/code.inline.h

@@ -32,13 +32,13 @@ namespace aFuncore {
     Code::ByteCode::BlockType Code::ByteCode::getBlockType() const {
         if (type != code_block)
             return block_p;
-        return data.block_type;
+        return data.block.block_type;
     }
 
     Code::ByteCode *Code::ByteCode::getSon() const {
         if (type != code_block)
             return nullptr;
-        return data.son;
+        return data.block.son;
     }
 
     Code::ByteCode *Code::ByteCode::toNext() const {

+ 1 - 1
include/interface/it-init.inline.h

@@ -9,7 +9,7 @@ namespace aFunit {
                                       aFuntool::Logger &afun_logger_,
                                       aFuntool::Logger &core_logger_,
                                       aFuntool::Logger &sys_logger_) :
-        InitInfo(base_dir_, factor_, sys_logger_, sys_logger_), afun_logger{afun_logger_} {
+        InitInfo(base_dir_, factor_, core_logger_, sys_logger_), afun_logger{afun_logger_} {
 
     }
 

+ 1 - 1
include/tool/log.h

@@ -64,7 +64,7 @@ namespace aFuntool {
         AFUN_STATIC void writeConsole(LogLevel level,
                                  const char *id, pid_t tid,
                                  const char *ti, time_t t,
-                                 const char *file, int line, const char *func,
+                                 const char *file, int line,
                                  const char *info);
         void writeLogAsyn(LogLevel level,
                           const char *id, pid_t tid,

+ 18 - 18
src/core/code.cpp

@@ -5,20 +5,20 @@ namespace aFuncore {
     Code::~Code(){
         ByteCode *next_tmp;
         while (code != nullptr) {
-            if (code->type != ByteCode::code_block || code->data.son == nullptr) {
+            if (code->type != ByteCode::code_block || code->data.block.son == nullptr) {
                 if (code->next == nullptr) {
                     if (code->father == nullptr)
                         next_tmp = nullptr;
                     else {
                         next_tmp = code->father;
-                        next_tmp->data.son = nullptr;
+                        next_tmp->data.block.son = nullptr;
                     }
                 } else
                     next_tmp = code->next;
                 delete code;
                 code = next_tmp;
             } else
-                code = code->data.son;
+                code = code->data.block.son;
         }
         delete code;
     }
@@ -36,8 +36,8 @@ namespace aFuncore {
         const Code::ByteCode *tmp = code;
         while (tmp != nullptr) {
             tmp->display();
-            if (tmp->type == ByteCode::code_block && tmp->data.son != nullptr) {
-                tmp = tmp->data.son;
+            if (tmp->type == ByteCode::code_block && tmp->data.block.son != nullptr) {
+                tmp = tmp->data.block.son;
                 continue;
             }
 
@@ -76,8 +76,8 @@ if(!(write)){ \
         const Code::ByteCode *tmp = code;
         while (tmp != nullptr) {
             Done(tmp->write_v1(f, debug));
-            if (tmp->type == ByteCode::code_block && tmp->data.son != nullptr) {
-                tmp = tmp->data.son;
+            if (tmp->type == ByteCode::code_block && tmp->data.block.son != nullptr) {
+                tmp = tmp->data.block.son;
                 continue;
             }
 
@@ -175,8 +175,8 @@ RETURN:
             std::string code_md5 = tmp->getMD5_v1();
             MD5Update(md5, (unsigned char *) code_md5.c_str(), code_md5.size());
 
-            if (tmp->type == ByteCode::code_block && tmp->data.son != nullptr) {
-                tmp = tmp->data.son;
+            if (tmp->type == ByteCode::code_block && tmp->data.block.son != nullptr) {
+                tmp = tmp->data.block.son;
                 continue;
             }
 
@@ -339,8 +339,8 @@ RETURN_FALSE:
         this->prefix = prefix;
         this->line = line;
 
-        this->data.block_type = block_type;
-        this->data.son = son;
+        this->data.block.block_type = block_type;
+        this->data.block.son = son;
 
         for (Code::ByteCode *tmp = son; tmp != nullptr; tmp = tmp->next)
             tmp->father = this;
@@ -393,7 +393,7 @@ RETURN_FALSE:
         if (type == code_element)
             aFuntool::cout << " element: " << data.element << "\n";
         else if (type == code_block)
-            aFuntool::cout << " block: '" << (char)(data.block_type) << "' son: " << data.son << "\n";
+            aFuntool::cout << " block: '" << (char)(data.block.block_type) << "' son: " << data.block.son << "\n";
         else
             aFuntool::cout << "\n";
     }
@@ -419,12 +419,12 @@ if(!(write)){           \
                 Done(aFuntool::byteWriteStr(f, (data.element)));
                 break;
             case code_block:
-                if (data.son == nullptr)
+                if (data.block.son == nullptr)
                     Done(aFuntool::byteWriteInt(f, static_cast<int8_t>(4)));  // 空 block 标注为 4
                 else
                     Done(aFuntool::byteWriteInt(f, static_cast<int8_t>(code_block)));
                 Done(aFuntool::byteWriteInt(f, static_cast<int8_t>(prefix)));
-                Done(aFuntool::byteWriteInt(f, static_cast<int8_t>(data.block_type)));
+                Done(aFuntool::byteWriteInt(f, static_cast<int8_t>(data.block.block_type)));
                 break;
             default:
                 break;
@@ -482,13 +482,13 @@ if(!(write)){           \
         }
 
         if (to_son) {
-            if (type != code_block || data.son != nullptr) {
+            if (type != code_block || data.block.son != nullptr) {
                 errorLog(aFunCoreLogger, "Read son with bad type.");
                 delete ret;
                 return nullptr;
             }
             ret->father = this;
-            data.son = ret;
+            data.block.son = ret;
         } else
             connect(ret);
         return ret;
@@ -509,8 +509,8 @@ if(!(write)){           \
         if (prefix == aFuntool::NUL)
             head[1] = '-';
         if (type == code_block) {
-            head[2] = data.son == nullptr ? 'n' : 's';
-            head[3] = data.block_type;
+            head[2] = data.block.son == nullptr ? 'n' : 's';
+            head[3] = data.block.block_type;
         }
 
         MD5Update(md5, (unsigned char *) head, strlen((char *) head));

+ 2 - 2
src/core/msg.cpp

@@ -15,7 +15,7 @@ namespace aFuncore {
         }
     }
 
-    void NormalMessage::topProgress(Inter &inter, Activation &activation){
+    void NormalMessage::topProgress(Inter &inter, Activation &){
         inter.getOutMessageStream().pushMessage("NORMAL", new NormalMessage(std::move(*this)));
     }
 
@@ -27,7 +27,7 @@ namespace aFuncore {
         }
     }
 
-    void ErrorMessage::topProgress(Inter &inter_, Activation &activation){
+    void ErrorMessage::topProgress(Inter &inter_, Activation &){
         inter_.getOutMessageStream().pushMessage("ERROR", new ErrorMessage(std::move(*this)));
     }
 

+ 4 - 4
src/core/object-value.cpp

@@ -169,7 +169,7 @@ namespace aFuncore {
         return false;
     }
 
-    bool CallBackVar::isCallBack(Inter &inter, Activation &activation) {
+    bool CallBackVar::isCallBack(Inter &, Activation &) {
         return true;
     }
 
@@ -187,9 +187,9 @@ namespace aFuncore {
         import = code_->getSon()->toNext()->getElement();
     }
 
-    std::list<Function::CallFunction::ArgCodeList> *ImportFunction::CallFunc::getArgCodeList(Inter &inter_,
-                                                                                             Activation &activation,
-                                                                                             const Code::ByteCode *call) {
+    std::list<Function::CallFunction::ArgCodeList> *ImportFunction::CallFunc::getArgCodeList(Inter &,
+                                                                                             Activation &,
+                                                                                             const Code::ByteCode *) {
         return acl;
     }
 

+ 2 - 2
src/core/object.cpp

@@ -39,11 +39,11 @@ namespace aFuncore {
             warningLog(aFunCoreLogger, "After Object destructAll, list is not empty");
     }
 
-    void Object::destruct(Inter &inter) {
+    void Object::destruct(Inter &) {
         /* 什么都不做, 但virtual函数不能是inline */
     }
 
-    void Object::linkObject(std::queue<Object *> &queue) {
+    void Object::linkObject(std::queue<Object *> &) {
         /* 什么都不做, 但virtual函数不能是inline */
     }
 

+ 1 - 1
src/main-build.cpp

@@ -1,5 +1,5 @@
 #include "__main.h"
 
-int mainBuild(ff_FFlags *ff) {
+int mainBuild(ff_FFlags *) {
     return 0;
 }

+ 1 - 1
src/main-cl.cpp

@@ -1,5 +1,5 @@
 #include "__main.h"
 
-int mainCL(ff_FFlags *ff) {
+int mainCL(ff_FFlags *) {
     return 0;
 }

+ 2 - 2
src/main-run.cpp

@@ -13,7 +13,7 @@ static void runCodeThread(aFun::Inter &inter, aFun::Code &code, std::mutex &mute
     is_end = true;
 }
 
-static int runCode(aFun::Code &code, aFun::Environment &env, aFun::Inter &inter, int argc, char **argv) {
+static int runCode(aFun::Code &code, aFun::Environment &, aFun::Inter &inter) {
     std::mutex mutex;
     bool is_end = false;
     auto thread = std::thread(runCodeThread, std::ref(inter), std::ref(code), std::ref(mutex), std::ref(is_end));
@@ -51,7 +51,7 @@ int mainRun(ff_FFlags *ff) {
                 return EXIT_FAILURE;
             auto env = aFun::Environment(argc - 1, argv + 1);
             auto inter = aFun::Inter(env);
-            return runCode(code, env, inter, argc, argv);
+            return runCode(code, env, inter);
         } catch (aFun::readerFileOpenError &e) {
             aFun::cout << "Cannot open file: " << argv[0] << "\n";
             return EXIT_FAILURE;

+ 2 - 2
src/tool/log.cpp

@@ -198,7 +198,7 @@ namespace aFuntool {
     void LogFactory::writeConsole(LogLevel level,
                                   const char *id, pid_t tid,
                                   const char *ti, time_t t,
-                                  const char *file, int line, const char *func,
+                                  const char *file, int line,
                                   const char *info){
         if (level < log_warning) {
             cout << "\r* " << LogLevelName[level] << "/[" << id << "] " << tid;
@@ -323,7 +323,7 @@ namespace aFuntool {
             writeLog(level, logger->id_.c_str(), tid, ti, t, file, line, func, tmp);
 
         if (pc)
-            writeConsole(level, logger->id_.c_str(), tid, ti, t, file, line, func, tmp);
+            writeConsole(level, logger->id_.c_str(), tid, ti, t, file, line, tmp);
 
         ul.unlock();
         if (async_)

+ 1 - 0
test/src/core-reader.cpp

@@ -16,6 +16,7 @@ public:
             memset(dest, 'w', len - 5);
             return len - 5;
         }
+        mode = read_mode_finished;
         return 0;
     }
 };

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

@@ -21,7 +21,7 @@ class Func1 : public Function {
             }
         }
 
-        std::list<ArgCodeList> *getArgCodeList(Inter &inter_, Activation &activation, const Code::ByteCode *call) override {
+        std::list<ArgCodeList> *getArgCodeList(Inter &, Activation &, const Code::ByteCode *) override {
             return acl;
         }
 
@@ -75,7 +75,7 @@ public:
 
     ~Literaler1() override = default;
 
-    void getObject(const std::string &literal, char prefix, Inter &inter, Activation &activation) override {
+    void getObject(const std::string &literal, char prefix, Inter &inter, Activation &) override {
         aFuntool::cout << "Literaler1: " << literal  << "prefix: " << (prefix == NUL ? '-' : prefix) << "\n";
         new ExeActivation(func_code, inter);
     }
@@ -92,7 +92,7 @@ public:
 
     ~CBV1() override = default;
 
-    void callBack(Inter &inter, Activation &activation) override {
+    void callBack(Inter &inter, Activation &) override {
         aFuntool::cout << "CallBackVar callback\n";
         new ExeActivation(func_code, inter);
     }

+ 1 - 1
test/src/tool-exit.cpp

@@ -10,7 +10,7 @@ void exit_func_push2(void *) {
     std::cout << "I am exit push-2" << std::endl;
 }
 
-int main(int argc, char **argv) {
+int main() {
     int exit_code = 0;
     try {
         aFunAtExit(exit_func_push1, nullptr);

+ 1 - 1
test/src/tool-hash.cpp

@@ -1,7 +1,7 @@
 #include "aFuntool.h"
 using namespace aFuntool;
 
-int main(int argc, char **argv) {
+int main() {
     std::cout << time33("HelloWorld") << std::endl;
     return 0;
 }

+ 1 - 1
test/src/tool-logger.cpp

@@ -1,7 +1,7 @@
 #include "aFuntool.h"
 using namespace aFuntool;
 
-int main(int argc, char **argv){
+int main(){
     int exit_code = 0;
     try {
         std::string base_path = getHomePath();