From 635aae921f68e330247a32af32541fbbda3cdaa3 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 18 Feb 2024 16:05:14 +0800 Subject: [PATCH] fix compile warnings --- build_with_warnings.sh | 5 +++++ include/pocketpy/expr.h | 2 -- include/pocketpy/frame.h | 1 - include/pocketpy/linalg.h | 8 -------- include/pocketpy/vm.h | 17 +++++------------ src/io.cpp | 1 - src/lexer.cpp | 6 +++--- src/linalg.cpp | 3 --- src/pocketpy.cpp | 1 - src/vm.cpp | 3 --- 10 files changed, 13 insertions(+), 34 deletions(-) create mode 100644 build_with_warnings.sh diff --git a/build_with_warnings.sh b/build_with_warnings.sh new file mode 100644 index 00000000..bde1e437 --- /dev/null +++ b/build_with_warnings.sh @@ -0,0 +1,5 @@ +SRC=$(find src/ -name "*.cpp") + +FLAGS="-std=c++17 -O1 -stdlib=libc++ -Iinclude -W -Wno-unused-parameter -Wno-sign-compare" + +clang++ $FLAGS -o main -O1 src2/main.cpp $SRC diff --git a/include/pocketpy/expr.h b/include/pocketpy/expr.h index 78dfa0dd..29bdf411 100644 --- a/include/pocketpy/expr.h +++ b/include/pocketpy/expr.h @@ -27,13 +27,11 @@ struct Expr{ // for OP_DELETE_XXX [[nodiscard]] virtual bool emit_del(CodeEmitContext* ctx) { - PK_UNUSED(ctx); return false; } // for OP_STORE_XXX [[nodiscard]] virtual bool emit_store(CodeEmitContext* ctx) { - PK_UNUSED(ctx); return false; } }; diff --git a/include/pocketpy/frame.h b/include/pocketpy/frame.h index 2db27667..ad3ad113 100644 --- a/include/pocketpy/frame.h +++ b/include/pocketpy/frame.h @@ -20,7 +20,6 @@ struct FastLocals{ PyObject* operator[](int i) const { return a[i]; } FastLocals(const CodeObject* co, PyObject** a): varnames_inv(&co->varnames_inv), a(a) {} - FastLocals(const FastLocals& other): varnames_inv(other.varnames_inv), a(other.a) {} PyObject** try_get_name(StrName name); NameDict_ to_namedict(); diff --git a/include/pocketpy/linalg.h b/include/pocketpy/linalg.h index e6904e7c..a77b4bbe 100644 --- a/include/pocketpy/linalg.h +++ b/include/pocketpy/linalg.h @@ -10,7 +10,6 @@ struct Vec2{ float x, y; Vec2() : x(0.0f), y(0.0f) {} Vec2(float x, float y) : x(x), y(y) {} - Vec2(const Vec2& v) = default; Vec2 operator+(const Vec2& v) const { return Vec2(x + v.x, y + v.y); } Vec2 operator-(const Vec2& v) const { return Vec2(x - v.x, y - v.y); } @@ -34,7 +33,6 @@ struct Vec3{ float x, y, z; Vec3() : x(0.0f), y(0.0f), z(0.0f) {} Vec3(float x, float y, float z) : x(x), y(y), z(z) {} - Vec3(const Vec3& v) = default; Vec3 operator+(const Vec3& v) const { return Vec3(x + v.x, y + v.y, z + v.z); } Vec3 operator-(const Vec3& v) const { return Vec3(x - v.x, y - v.y, z - v.z); } @@ -57,7 +55,6 @@ struct Vec4{ float x, y, z, w; Vec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} Vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {} - Vec4(const Vec4& v) = default; Vec4 operator+(const Vec4& v) const { return Vec4(x + v.x, y + v.y, z + v.z, w + v.w); } Vec4 operator-(const Vec4& v) const { return Vec4(x - v.x, y - v.y, z - v.z, w - v.w); } @@ -88,7 +85,6 @@ struct Mat3x3{ Mat3x3(); Mat3x3(float, float, float, float, float, float, float, float, float); - Mat3x3(const Mat3x3& other) = default; static Mat3x3 zeros(); static Mat3x3 ones(); @@ -122,7 +118,6 @@ struct PyVec2: Vec2 { PyVec2() : Vec2() {} PyVec2(const Vec2& v) : Vec2(v) {} - PyVec2(const PyVec2& v) = default; Vec2* _() { return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); @@ -133,7 +128,6 @@ struct PyVec3: Vec3 { PyVec3() : Vec3() {} PyVec3(const Vec3& v) : Vec3(v) {} - PyVec3(const PyVec3& v) = default; Vec3* _() { return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); @@ -144,7 +138,6 @@ struct PyVec4: Vec4{ PyVec4(): Vec4(){} PyVec4(const Vec4& v): Vec4(v){} - PyVec4(const PyVec4& v) = default; Vec4* _(){ return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); @@ -155,7 +148,6 @@ struct PyMat3x3: Mat3x3{ PyMat3x3(): Mat3x3(){} PyMat3x3(const Mat3x3& other): Mat3x3(other){} - PyMat3x3(const PyMat3x3& other) = default; Mat3x3* _(){ return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index 654622e2..5a06a7cb 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -29,19 +29,17 @@ namespace pkpy{ #define DEF_NATIVE_2(ctype, ptype) \ template<> inline ctype py_cast(VM* vm, PyObject* obj) { \ vm->check_non_tagged_type(obj, vm->ptype); \ - return PK_OBJ_GET(ctype, obj); \ + return PK_OBJ_GET(ctype, obj); \ } \ template<> inline ctype _py_cast(VM* vm, PyObject* obj) { \ - PK_UNUSED(vm); \ - return PK_OBJ_GET(ctype, obj); \ + return PK_OBJ_GET(ctype, obj); \ } \ template<> inline ctype& py_cast(VM* vm, PyObject* obj) { \ vm->check_non_tagged_type(obj, vm->ptype); \ - return PK_OBJ_GET(ctype, obj); \ + return PK_OBJ_GET(ctype, obj); \ } \ template<> inline ctype& _py_cast(VM* vm, PyObject* obj) { \ - PK_UNUSED(vm); \ - return PK_OBJ_GET(ctype, obj); \ + return PK_OBJ_GET(ctype, obj); \ } \ inline PyObject* py_var(VM* vm, const ctype& value) { return vm->heap.gcnew(vm->ptype, value);} \ inline PyObject* py_var(VM* vm, ctype&& value) { return vm->heap.gcnew(vm->ptype, std::move(value));} @@ -56,7 +54,7 @@ struct PyTypeInfo{ StrName name; bool subclass_enabled; - std::vector annotated_fields; + std::vector annotated_fields = {}; // cached special methods // unary operators @@ -316,7 +314,6 @@ public: template PyObject* bind_notimplemented_constructor(__T&& type) { return bind_constructor<-1>(std::forward<__T>(type), [](VM* vm, ArgsView args){ - PK_UNUSED(args); vm->NotImplementedError(); return vm->None; }); @@ -473,7 +470,6 @@ template<> inline T py_cast(VM* vm, PyObject* obj){ \ return 0; \ } \ template<> inline T _py_cast(VM* vm, PyObject* obj){ \ - PK_UNUSED(vm); \ if(is_small_int(obj)) return (T)(PK_BITS(obj) >> 2); \ return (T)PK_OBJ_GET(i64, obj); \ } @@ -534,12 +530,10 @@ PY_VAR_INT(unsigned long long) #undef PY_VAR_INT inline PyObject* py_var(VM* vm, float _val){ - PK_UNUSED(vm); return tag_float(static_cast(_val)); } inline PyObject* py_var(VM* vm, double _val){ - PK_UNUSED(vm); return tag_float(static_cast(_val)); } @@ -591,7 +585,6 @@ inline PyObject* py_var(VM* vm, std::string_view val){ } inline PyObject* py_var(VM* vm, NoReturn val){ - PK_UNUSED(val); return vm->None; } diff --git a/src/io.cpp b/src/io.cpp index 13be5671..b5365848 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -36,7 +36,6 @@ unsigned char* _default_import_handler(const char* name_p, int name_size, int* o unsigned char* buffer = new unsigned char[buffer_size]; fseek(fp, 0, SEEK_SET); size_t sz = io_fread(buffer, 1, buffer_size, fp); - PK_UNUSED(sz); fclose(fp); *out_size = buffer_size; return buffer; diff --git a/src/lexer.cpp b/src/lexer.cpp index 978a5c20..4d296ce0 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -64,11 +64,11 @@ static bool is_unicode_Lo_char(uint32_t c) { // https://docs.python.org/3/reference/lexical_analysis.html#indentation if(spaces > indents.top()){ indents.push(spaces); - nexts.push_back(Token{TK("@indent"), token_start, 0, current_line, brackets_level}); + nexts.push_back(Token{TK("@indent"), token_start, 0, current_line, brackets_level, {}}); } else if(spaces < indents.top()){ while(spaces < indents.top()){ indents.pop(); - nexts.push_back(Token{TK("@dedent"), token_start, 0, current_line, brackets_level}); + nexts.push_back(Token{TK("@dedent"), token_start, 0, current_line, brackets_level, {}}); } if(spaces != indents.top()){ return false; @@ -467,7 +467,7 @@ static bool is_unicode_Lo_char(uint32_t c) { Lexer::Lexer(VM* vm, std::shared_ptr src) : vm(vm), src(src) { this->token_start = src->source.c_str(); this->curr_char = src->source.c_str(); - this->nexts.push_back(Token{TK("@sof"), token_start, 0, current_line, brackets_level}); + this->nexts.push_back(Token{TK("@sof"), token_start, 0, current_line, brackets_level, {}}); this->indents.push(0); } diff --git a/src/linalg.cpp b/src/linalg.cpp index 72b232f2..0b96f3ec 100644 --- a/src/linalg.cpp +++ b/src/linalg.cpp @@ -422,19 +422,16 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float // @staticmethod vm->bind(type, "zeros()", [](VM* vm, ArgsView args){ - PK_UNUSED(args); return VAR_T(PyMat3x3, Mat3x3::zeros()); }, {}, BindType::STATICMETHOD); // @staticmethod vm->bind(type, "ones()", [](VM* vm, ArgsView args){ - PK_UNUSED(args); return VAR_T(PyMat3x3, Mat3x3::ones()); }, {}, BindType::STATICMETHOD); // @staticmethod vm->bind(type, "identity()", [](VM* vm, ArgsView args){ - PK_UNUSED(args); return VAR_T(PyMat3x3, Mat3x3::identity()); }, {}, BindType::STATICMETHOD); diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 16049a20..1b7b0f4a 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -1460,7 +1460,6 @@ void VM::post_init(){ // type bind__getitem__(tp_type, [](VM* vm, PyObject* self, PyObject* _){ - PK_UNUSED(_); return self; // for generics }); diff --git a/src/vm.cpp b/src/vm.cpp index c7f09948..9c2f4274 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -79,9 +79,6 @@ namespace pkpy{ _main = nullptr; _last_exception = nullptr; _import_handler = [](const char* name_p, int name_size, int* out_size) -> unsigned char*{ - PK_UNUSED(name_p); - PK_UNUSED(name_size); - PK_UNUSED(out_size); return nullptr; }; init_builtin_types();