Ver código fonte

fix compile warnings

blueloveTH 2 anos atrás
pai
commit
635aae921f

+ 5 - 0
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

+ 0 - 2
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;
     }
 };

+ 0 - 1
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();

+ 0 - 8
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);

+ 5 - 12
include/pocketpy/vm.h

@@ -29,19 +29,17 @@ namespace pkpy{
 #define DEF_NATIVE_2(ctype, ptype)                                      \
     template<> inline ctype py_cast<ctype>(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<ctype>(VM* vm, PyObject* obj) {    \
-        PK_UNUSED(vm);                                                  \
-        return PK_OBJ_GET(ctype, obj);                                     \
+        return PK_OBJ_GET(ctype, obj);                                  \
     }                                                                   \
     template<> inline ctype& py_cast<ctype&>(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<ctype&>(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<ctype>(vm->ptype, value);}     \
     inline PyObject* py_var(VM* vm, ctype&& value) { return vm->heap.gcnew<ctype>(vm->ptype, std::move(value));}
@@ -56,7 +54,7 @@ struct PyTypeInfo{
     StrName name;
     bool subclass_enabled;
 
-    std::vector<StrName> annotated_fields;
+    std::vector<StrName> annotated_fields = {};
 
     // cached special methods
     // unary operators
@@ -316,7 +314,6 @@ public:
     template<typename T, typename __T>
     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<T>(VM* vm, PyObject* obj){  \
     return 0;                                               \
 }                                                           \
 template<> inline T _py_cast<T>(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<f64>(_val));
 }
 
 inline PyObject* py_var(VM* vm, double _val){
-    PK_UNUSED(vm);
     return tag_float(static_cast<f64>(_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;
 }
 

+ 0 - 1
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;

+ 3 - 3
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<SourceData> 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);
     }
 

+ 0 - 3
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);
 

+ 0 - 1
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
     });
 

+ 0 - 3
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();