diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2019-09-26 22:52:04 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-05 14:11:51 +1000 |
commit | a9a745e4b4838749a47857f1d0c95de52dc85f58 (patch) | |
tree | 60469e58476c5a68999ad0a2e8d58dbca8a6abb8 /py/objtype.c | |
parent | 312c699491830daacd33f032a6d6fc6cc6ff0c96 (diff) |
py: Use preprocessor to detect error reporting level (terse/detailed).
Instead of compiler-level if-logic. This is necessary to know what error
strings are included in the build at the preprocessor stage, so that string
compression can be implemented.
Diffstat (limited to 'py/objtype.c')
-rw-r--r-- | py/objtype.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/py/objtype.c b/py/objtype.c index 0f49ad2d4..3a5a3403b 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -348,14 +348,13 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw); } if (init_ret != mp_const_none) { - if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { - mp_raise_TypeError("__init__() should return None"); - } else { - mp_raise_msg_varg(&mp_type_TypeError, - "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)); - } + #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE + mp_raise_TypeError("__init__() should return None"); + #else + mp_raise_msg_varg(&mp_type_TypeError, + "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)); + #endif } - } // If the type had a native base that was not explicitly initialised @@ -864,12 +863,12 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons mp_obj_t member[2] = {MP_OBJ_NULL, MP_OBJ_NULL}; mp_obj_t call = mp_obj_instance_get_call(self_in, member); if (call == MP_OBJ_NULL) { - if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { - mp_raise_TypeError("object not callable"); - } else { - mp_raise_msg_varg(&mp_type_TypeError, - "'%s' object isn't callable", mp_obj_get_type_str(self_in)); - } + #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE + mp_raise_TypeError("object not callable"); + #else + mp_raise_msg_varg(&mp_type_TypeError, + "'%s' object isn't callable", mp_obj_get_type_str(self_in)); + #endif } mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); if (call == MP_OBJ_SENTINEL) { @@ -989,11 +988,11 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); if (self->make_new == NULL) { - if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { - mp_raise_TypeError("cannot create instance"); - } else { - mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name); - } + #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE + mp_raise_TypeError("cannot create instance"); + #else + mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name); + #endif } // make new instance @@ -1111,12 +1110,12 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) mp_obj_type_t *t = MP_OBJ_TO_PTR(bases_items[i]); // TODO: Verify with CPy, tested on function type if (t->make_new == NULL) { - if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { - mp_raise_TypeError("type isn't an acceptable base type"); - } else { - mp_raise_msg_varg(&mp_type_TypeError, - "type '%q' isn't an acceptable base type", t->name); - } + #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE + mp_raise_TypeError("type isn't an acceptable base type"); + #else + mp_raise_msg_varg(&mp_type_TypeError, + "type '%q' isn't an acceptable base type", t->name); + #endif } #if ENABLE_SPECIAL_ACCESSORS if (mp_obj_is_instance_type(t)) { |