From a28b641bf3b3106b872bed1b5305d6d3f7e9b487 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 24 Oct 2022 01:03:28 +0200 Subject: [PATCH] interrogatedb: Indicate whether types/function wrappers are deprecated --- dtool/metalibs/dtoolconfig/pydtool.cxx | 34 ++++++++++++++++++- dtool/src/interrogate/functionRemap.cxx | 4 +++ dtool/src/interrogate/interrogateBuilder.cxx | 4 +++ .../interrogateFunctionWrapper.I | 8 +++++ .../interrogateFunctionWrapper.h | 2 ++ dtool/src/interrogatedb/interrogateType.I | 10 ++++++ dtool/src/interrogatedb/interrogateType.h | 2 ++ .../interrogatedb/interrogate_interface.cxx | 12 +++++++ .../src/interrogatedb/interrogate_interface.h | 4 +++ 9 files changed, 79 insertions(+), 1 deletion(-) diff --git a/dtool/metalibs/dtoolconfig/pydtool.cxx b/dtool/metalibs/dtoolconfig/pydtool.cxx index 3d0e149bc9..38b6e6359a 100644 --- a/dtool/metalibs/dtoolconfig/pydtool.cxx +++ b/dtool/metalibs/dtoolconfig/pydtool.cxx @@ -90,6 +90,7 @@ static PyObject *_inP07ytrD_M(PyObject *self, PyObject *args); static PyObject *_inP07ytYaah(PyObject *self, PyObject *args); static PyObject *_inP07yt2otr(PyObject *self, PyObject *args); static PyObject *_inP07ytNP_b(PyObject *self, PyObject *args); +static PyObject *_inP07ytrrrN(PyObject *self, PyObject *args); static PyObject *_inP07ytjolz(PyObject *self, PyObject *args); static PyObject *_inP07ytt_JD(PyObject *self, PyObject *args); static PyObject *_inP07ytwEts(PyObject *self, PyObject *args); @@ -122,6 +123,7 @@ static PyObject *_inP07ytNHcs(PyObject *self, PyObject *args); static PyObject *_inP07ytqHrb(PyObject *self, PyObject *args); static PyObject *_inP07ytaOqq(PyObject *self, PyObject *args); static PyObject *_inP07ytpTBb(PyObject *self, PyObject *args); +static PyObject *_inP07ytZUkn(PyObject *self, PyObject *args); static PyObject *_inP07ytqWOw(PyObject *self, PyObject *args); static PyObject *_inP07ytHu7x(PyObject *self, PyObject *args); static PyObject *_inP07ytwGnA(PyObject *self, PyObject *args); @@ -1327,6 +1329,20 @@ _inP07ytNP_b(PyObject *, PyObject *args) { return nullptr; } +/* + * Python simple wrapper for + * bool interrogate_wrapper_is_deprecated(FunctionWrapperIndex wrapper) + */ +static PyObject * +_inP07ytrrrN(PyObject *, PyObject *args) { + int param0; + if (PyArg_ParseTuple(args, "i", ¶m0)) { + bool return_value = (::interrogate_wrapper_is_deprecated)((FunctionWrapperIndex)param0); + return PyBool_FromLong(return_value); + } + return nullptr; +} + /* * Python simple wrapper for * bool interrogate_wrapper_has_comment(FunctionWrapperIndex wrapper) @@ -1866,6 +1882,20 @@ _inP07ytpTBb(PyObject *, PyObject *args) { return nullptr; } +/* + * Python simple wrapper for + * bool interrogate_type_is_deprecated(TypeIndex type) + */ +static PyObject * +_inP07ytZUkn(PyObject *, PyObject *args) { + int param0; + if (PyArg_ParseTuple(args, "i", ¶m0)) { + bool return_value = (::interrogate_type_is_deprecated)((TypeIndex)param0); + return PyBool_FromLong(return_value); + } + return nullptr; +} + /* * Python simple wrapper for * char const *interrogate_type_name(TypeIndex type) @@ -2950,6 +2980,7 @@ static PyMethodDef python_simple_funcs[] = { { "interrogate_wrapper_is_copy_constructor", &_inP07ytYaah, METH_VARARGS, nullptr }, { "interrogate_wrapper_is_coerce_constructor", &_inP07yt2otr, METH_VARARGS, nullptr }, { "interrogate_wrapper_is_extension", &_inP07ytNP_b, METH_VARARGS, nullptr }, + { "interrogate_wrapper_is_deprecated", &_inP07ytrrrN, METH_VARARGS, nullptr }, { "interrogate_wrapper_has_comment", &_inP07ytjolz, METH_VARARGS, nullptr }, { "interrogate_wrapper_comment", &_inP07ytt_JD, METH_VARARGS, nullptr }, { "interrogate_wrapper_has_return_value", &_inP07ytwEts, METH_VARARGS, nullptr }, @@ -2982,6 +3013,7 @@ static PyMethodDef python_simple_funcs[] = { { "interrogate_get_type_by_scoped_name", &_inP07ytqHrb, METH_VARARGS, nullptr }, { "interrogate_get_type_by_true_name", &_inP07ytaOqq, METH_VARARGS, nullptr }, { "interrogate_type_is_global", &_inP07ytpTBb, METH_VARARGS, nullptr }, + { "interrogate_type_is_deprecated", &_inP07ytZUkn, METH_VARARGS, nullptr }, { "interrogate_type_name", &_inP07ytqWOw, METH_VARARGS, nullptr }, { "interrogate_type_scoped_name", &_inP07ytHu7x, METH_VARARGS, nullptr }, { "interrogate_type_true_name", &_inP07ytwGnA, METH_VARARGS, nullptr }, @@ -3050,7 +3082,7 @@ static PyMethodDef python_simple_funcs[] = { #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef python_simple_module = { PyModuleDef_HEAD_INIT, - "interrogatedb", + "panda3d.interrogatedb", nullptr, -1, python_simple_funcs, diff --git a/dtool/src/interrogate/functionRemap.cxx b/dtool/src/interrogate/functionRemap.cxx index 597bda5d59..c4c1282a68 100644 --- a/dtool/src/interrogate/functionRemap.cxx +++ b/dtool/src/interrogate/functionRemap.cxx @@ -324,6 +324,10 @@ make_wrapper_entry(FunctionIndex function_index) { iwrapper._flags |= InterrogateFunctionWrapper::F_extension; } + if (_cppfunc->_attributes.has_attribute("deprecated")) { + iwrapper._flags |= InterrogateFunctionWrapper::F_deprecated; + } + Parameters::const_iterator pi; for (pi = _parameters.begin(); pi != _parameters.end(); diff --git a/dtool/src/interrogate/interrogateBuilder.cxx b/dtool/src/interrogate/interrogateBuilder.cxx index 9a2f2a161d..9ce9e57a1f 100644 --- a/dtool/src/interrogate/interrogateBuilder.cxx +++ b/dtool/src/interrogate/interrogateBuilder.cxx @@ -2381,6 +2381,10 @@ get_type(CPPType *type, bool global) { } } + if (type->_attributes.has_attribute("deprecated")) { + itype._flags |= InterrogateType::F_deprecated; + } + if (forced || !in_ignoretype(true_name)) { itype._flags |= InterrogateType::F_fully_defined; diff --git a/dtool/src/interrogatedb/interrogateFunctionWrapper.I b/dtool/src/interrogatedb/interrogateFunctionWrapper.I index 111eba10c1..93fff488b0 100644 --- a/dtool/src/interrogatedb/interrogateFunctionWrapper.I +++ b/dtool/src/interrogatedb/interrogateFunctionWrapper.I @@ -87,6 +87,14 @@ is_extension() const { return (_flags & F_extension) != 0; } +/** + * @since 1.11.0 + */ +INLINE bool InterrogateFunctionWrapper:: +is_deprecated() const { + return (_flags & F_deprecated) != 0; +} + /** * */ diff --git a/dtool/src/interrogatedb/interrogateFunctionWrapper.h b/dtool/src/interrogatedb/interrogateFunctionWrapper.h index 6c41a46cab..3fca6f3400 100644 --- a/dtool/src/interrogatedb/interrogateFunctionWrapper.h +++ b/dtool/src/interrogatedb/interrogateFunctionWrapper.h @@ -37,6 +37,7 @@ public: INLINE bool is_copy_constructor() const; INLINE bool is_coerce_constructor() const; INLINE bool is_extension() const; + INLINE bool is_deprecated() const; INLINE bool has_return_value() const; INLINE TypeIndex get_return_type() const; @@ -68,6 +69,7 @@ private: F_copy_constructor = 0x0008, F_coerce_constructor = 0x0010, F_extension = 0x0020, + F_deprecated = 0x0040, }; enum ParameterFlags { diff --git a/dtool/src/interrogatedb/interrogateType.I b/dtool/src/interrogatedb/interrogateType.I index c8a4d601b2..64c164e83e 100644 --- a/dtool/src/interrogatedb/interrogateType.I +++ b/dtool/src/interrogatedb/interrogateType.I @@ -20,6 +20,16 @@ is_global() const { return (_flags & F_global) != 0; } +/** + * Returns true if the type is marked as 'deprecated'. + * + * @since 1.11.0 + */ +INLINE bool InterrogateType:: +is_deprecated() const { + return (_flags & F_deprecated) != 0; +} + /** * */ diff --git a/dtool/src/interrogatedb/interrogateType.h b/dtool/src/interrogatedb/interrogateType.h index 0e6ade73d4..c9f67aff26 100644 --- a/dtool/src/interrogatedb/interrogateType.h +++ b/dtool/src/interrogatedb/interrogateType.h @@ -34,6 +34,7 @@ public: void operator = (const InterrogateType ©); INLINE bool is_global() const; + INLINE bool is_deprecated() const; INLINE bool has_scoped_name() const; INLINE const std::string &get_scoped_name() const; @@ -141,6 +142,7 @@ private: F_array = 0x400000, F_scoped_enum = 0x800000, F_final =0x1000000, + F_deprecated =0x2000000, }; public: diff --git a/dtool/src/interrogatedb/interrogate_interface.cxx b/dtool/src/interrogatedb/interrogate_interface.cxx index e4dbef1a76..a0b4ff356a 100644 --- a/dtool/src/interrogatedb/interrogate_interface.cxx +++ b/dtool/src/interrogatedb/interrogate_interface.cxx @@ -455,6 +455,12 @@ interrogate_wrapper_is_extension(FunctionWrapperIndex wrapper) { return InterrogateDatabase::get_ptr()->get_wrapper(wrapper).is_extension(); } +bool +interrogate_wrapper_is_deprecated(FunctionWrapperIndex wrapper) { + // cerr << "interrogate_wrapper_is_deprecated(" << wrapper << ")\n"; + return InterrogateDatabase::get_ptr()->get_wrapper(wrapper).is_deprecated(); +} + bool interrogate_wrapper_has_comment(FunctionWrapperIndex wrapper) { // cerr << "interrogate_wrapper_has_comment(" << wrapper << ")\n"; @@ -661,6 +667,12 @@ interrogate_type_is_global(TypeIndex type) { return InterrogateDatabase::get_ptr()->get_type(type).is_global(); } +bool +interrogate_type_is_deprecated(TypeIndex type) { + // cerr << "interrogate_type_is_deprecated(" << type << ")\n"; + return InterrogateDatabase::get_ptr()->get_type(type).is_deprecated(); +} + const char * interrogate_type_name(TypeIndex type) { // cerr << "interrogate_type_name(" << type << ")\n"; diff --git a/dtool/src/interrogatedb/interrogate_interface.h b/dtool/src/interrogatedb/interrogate_interface.h index 5c776e70eb..6ae1bdcb24 100644 --- a/dtool/src/interrogatedb/interrogate_interface.h +++ b/dtool/src/interrogatedb/interrogate_interface.h @@ -289,6 +289,9 @@ EXPCL_INTERROGATEDB bool interrogate_wrapper_is_coerce_constructor(FunctionWrapp // function defined in the C++ code. EXPCL_INTERROGATEDB bool interrogate_wrapper_is_extension(FunctionWrapperIndex wrapper); +// This returns true if function is marked as deprecated. +EXPCL_INTERROGATEDB bool interrogate_wrapper_is_deprecated(FunctionWrapperIndex wrapper); + // This returns the C++ comment written for the function wrapper, usually from // the .cpp file. There may be a different comment for each overload of a // given function. @@ -401,6 +404,7 @@ EXPCL_INTERROGATEDB TypeIndex interrogate_get_type_by_name(const char *type_name EXPCL_INTERROGATEDB TypeIndex interrogate_get_type_by_scoped_name(const char *type_name); EXPCL_INTERROGATEDB TypeIndex interrogate_get_type_by_true_name(const char *type_name); EXPCL_INTERROGATEDB bool interrogate_type_is_global(TypeIndex type); +EXPCL_INTERROGATEDB bool interrogate_type_is_deprecated(TypeIndex type); EXPCL_INTERROGATEDB const char *interrogate_type_name(TypeIndex type); EXPCL_INTERROGATEDB const char *interrogate_type_scoped_name(TypeIndex type); EXPCL_INTERROGATEDB const char *interrogate_type_true_name(TypeIndex type);