interrogatedb: Add new functions to interrogate_interface.h:

- `interrogate_function_is_constructor()`
- `interrogate_function_is_destructor()`
- `interrogate_wrapper_parameter_is_optional()`
- `interrogate_wrapper_parameter_is_scoped_enum()`
- `interrogate_wrapper_parameter_is_final()`

Only `interrogate_wrapper_parameter_is_optional()` requires a rebuild of the database with the new changes.
This commit is contained in:
rdb 2022-05-10 15:40:02 +02:00
parent 6ab6acfbaf
commit 3d55945535
10 changed files with 317 additions and 141 deletions

File diff suppressed because it is too large Load Diff

View File

@ -327,6 +327,9 @@ make_wrapper_entry(FunctionIndex function_index) {
if ((*pi)._has_name) {
param._parameter_flags |= InterrogateFunctionWrapper::PF_has_name;
}
if ((*pi)._remap->has_default_value()) {
param._parameter_flags |= InterrogateFunctionWrapper::PF_is_optional;
}
iwrapper._parameters.push_back(param);
}

View File

@ -1777,6 +1777,16 @@ get_function(CPPInstance *function, string description,
ifunction->_flags |= InterrogateFunction::F_operator_typecast;
}
if (ftype->_flags & CPPFunctionType::F_constructor) {
// This is a constructor.
ifunction->_flags |= InterrogateFunction::F_constructor;
}
if (ftype->_flags & CPPFunctionType::F_destructor) {
// This is a destructor.
ifunction->_flags |= InterrogateFunction::F_destructor;
}
if (function->_storage_class & CPPInstance::SC_virtual) {
// This is a virtual function.
ifunction->_flags |= InterrogateFunction::F_virtual;
@ -2749,7 +2759,8 @@ define_struct_type(InterrogateType &itype, CPPStructType *cpptype,
function->_storage_class |= CPPInstance::SC_inline | CPPInstance::SC_defaulted;
function->_vis = V_published;
FunctionIndex index = get_function(function, "", cpptype, cpptype->get_scope(), 0);
FunctionIndex index = get_function(function, "", cpptype, cpptype->get_scope(),
InterrogateFunction::F_constructor);
if (find(itype._constructors.begin(), itype._constructors.end(),
index) == itype._constructors.end()) {
itype._constructors.push_back(index);
@ -2775,7 +2786,8 @@ define_struct_type(InterrogateType &itype, CPPStructType *cpptype,
function->_storage_class |= CPPInstance::SC_inline | CPPInstance::SC_defaulted;
function->_vis = V_published;
FunctionIndex index = get_function(function, "", cpptype, cpptype->get_scope(), 0);
FunctionIndex index = get_function(function, "", cpptype, cpptype->get_scope(),
InterrogateFunction::F_constructor);
if (find(itype._constructors.begin(), itype._constructors.end(),
index) == itype._constructors.end()) {
itype._constructors.push_back(index);
@ -2816,7 +2828,7 @@ define_struct_type(InterrogateType &itype, CPPStructType *cpptype,
itype._destructor = get_function(function, "",
cpptype, cpptype->get_scope(),
0);
InterrogateFunction::F_destructor);
itype._flags |= InterrogateType::F_implicit_destructor;
}
}

View File

@ -968,6 +968,17 @@ read_new(std::istream &in, InterrogateModuleDef *def) {
add_type(index, type);
num_types--;
// Older versions of interrogate were not setting these flags.
const InterrogateType &itype = get_type(index);
FunctionIndex dtor = itype.get_destructor();
if (dtor != 0) {
update_function(dtor)._flags |= InterrogateFunction::F_destructor;
}
for (int i = 0; i < itype.number_of_constructors(); ++i) {
FunctionIndex ctor = itype.get_constructor(i);
update_function(ctor)._flags |= InterrogateFunction::F_constructor;
}
}
}

View File

@ -54,6 +54,22 @@ is_operator_typecast() const {
return (_flags & F_operator_typecast) != 0;
}
/**
* Returns true if the function is a constructor.
*/
INLINE bool InterrogateFunction::
is_constructor() const {
return (_flags & F_constructor) != 0;
}
/**
* Returns true if the function is a destructor.
*/
INLINE bool InterrogateFunction::
is_destructor() const {
return (_flags & F_destructor) != 0;
}
/**
* Return the class that owns the method, if is_method() returns true.
*/

View File

@ -38,6 +38,8 @@ public:
INLINE bool is_method() const;
INLINE bool is_unary_op() const;
INLINE bool is_operator_typecast() const;
INLINE bool is_constructor() const;
INLINE bool is_destructor() const;
INLINE TypeIndex get_class() const;
INLINE bool has_scoped_name() const;
@ -70,6 +72,8 @@ private:
F_setter = 0x0020,
F_unary_op = 0x0040,
F_operator_typecast = 0x0080,
F_constructor = 0x0100,
F_destructor = 0x0200,
};
int _flags;
@ -97,6 +101,7 @@ public:
std::string _expression;
friend class InterrogateBuilder;
friend class InterrogateDatabase;
friend class InterfaceMakerC;
friend class InterfaceMakerPythonSimple;
friend class InterfaceMakerPythonNative;

View File

@ -148,6 +148,17 @@ parameter_is_this(int n) const {
return false;
}
/**
*
*/
INLINE bool InterrogateFunctionWrapper::
parameter_is_optional(int n) const {
if (n >= 0 && n < (int)_parameters.size()) {
return (_parameters[n]._parameter_flags & PF_is_optional) != 0;
}
return false;
}
/**
*
*/

View File

@ -45,6 +45,7 @@ public:
INLINE bool parameter_has_name(int n) const;
INLINE const std::string &parameter_get_name(int n) const;
INLINE bool parameter_is_this(int n) const;
INLINE bool parameter_is_optional(int n) const;
INLINE const std::string &get_unique_name() const;
@ -66,6 +67,7 @@ private:
enum ParameterFlags {
PF_has_name = 0x0001,
PF_is_this = 0x0002,
PF_is_optional = 0x0004,
};
int _flags;

View File

@ -266,6 +266,18 @@ interrogate_function_class(FunctionIndex function) {
return InterrogateDatabase::get_ptr()->get_function(function).get_class();
}
bool
interrogate_function_is_constructor(FunctionIndex function) {
// cerr << "interrogate_function_is_constructor(" << function << ")\n";
return InterrogateDatabase::get_ptr()->get_function(function).is_constructor();
}
bool
interrogate_function_is_destructor(FunctionIndex function) {
// cerr << "interrogate_function_is_destructor(" << function << ")\n";
return InterrogateDatabase::get_ptr()->get_function(function).is_destructor();
}
bool
interrogate_function_has_module_name(FunctionIndex function) {
// cerr << "interrogate_function_has_module_name(" << function << ")\n";
@ -411,6 +423,12 @@ interrogate_wrapper_parameter_is_this(FunctionWrapperIndex wrapper, int n) {
return InterrogateDatabase::get_ptr()->get_wrapper(wrapper).parameter_is_this(n);
}
bool
interrogate_wrapper_parameter_is_optional(FunctionWrapperIndex wrapper, int n) {
// cerr << "interrogate_wrapper_is_optional(" << wrapper << ", " << n << ")\n";
return InterrogateDatabase::get_ptr()->get_wrapper(wrapper).parameter_is_optional(n);
}
bool
interrogate_wrapper_has_pointer(FunctionWrapperIndex wrapper) {
// cerr << "interrogate_wrapper_has_pointer(" << wrapper << ")\n";
@ -674,6 +692,12 @@ interrogate_type_is_enum(TypeIndex type) {
return InterrogateDatabase::get_ptr()->get_type(type).is_enum();
}
bool
interrogate_type_is_scoped_enum(TypeIndex type) {
// cerr << "interrogate_type_is_scoped_enum(" << type << ")\n";
return InterrogateDatabase::get_ptr()->get_type(type).is_scoped_enum();
}
int
interrogate_type_number_of_enum_values(TypeIndex type) {
// cerr << "interrogate_type_number_of_enum_values(" << type << ")\n";
@ -828,6 +852,12 @@ interrogate_type_get_derivation(TypeIndex type, int n) {
return InterrogateDatabase::get_ptr()->get_type(type).get_derivation(n);
}
bool
interrogate_type_is_final(TypeIndex type) {
// cerr << "interrogate_type_is_final(" << type << ")\n";
return InterrogateDatabase::get_ptr()->get_type(type).is_final();
}
bool
interrogate_type_derivation_has_upcast(TypeIndex type, int n) {
// cerr << "interrogate_type_derivation_has_upcast(" << type << ", " << n <<

View File

@ -210,6 +210,8 @@ EXPCL_INTERROGATEDB const char *interrogate_function_prototype(FunctionIndex fun
// if the function is a class method.
EXPCL_INTERROGATEDB bool interrogate_function_is_method(FunctionIndex function);
EXPCL_INTERROGATEDB TypeIndex interrogate_function_class(FunctionIndex function);
EXPCL_INTERROGATEDB bool interrogate_function_is_constructor(FunctionIndex function);
EXPCL_INTERROGATEDB bool interrogate_function_is_destructor(FunctionIndex function);
// This returns the module name reported for the function, if available.
EXPCL_INTERROGATEDB bool interrogate_function_has_module_name(FunctionIndex function);
@ -299,6 +301,7 @@ EXPCL_INTERROGATEDB TypeIndex interrogate_wrapper_parameter_type(FunctionWrapper
EXPCL_INTERROGATEDB bool interrogate_wrapper_parameter_has_name(FunctionWrapperIndex wrapper, int n);
EXPCL_INTERROGATEDB const char *interrogate_wrapper_parameter_name(FunctionWrapperIndex wrapper, int n);
EXPCL_INTERROGATEDB bool interrogate_wrapper_parameter_is_this(FunctionWrapperIndex wrapper, int n);
EXPCL_INTERROGATEDB bool interrogate_wrapper_parameter_is_optional(FunctionWrapperIndex wrapper, int n);
// This returns a pointer to a function that may be called to invoke the
// function, if the -fptrs option to return function pointers was specified to
@ -423,6 +426,7 @@ EXPCL_INTERROGATEDB TypeIndex interrogate_type_wrapped_type(TypeIndex type);
// If interrogate_type_is_enum() returns true, this is an enumerated type,
// which means it may take any one of a number of named integer values.
EXPCL_INTERROGATEDB bool interrogate_type_is_enum(TypeIndex type);
EXPCL_INTERROGATEDB bool interrogate_type_is_scoped_enum(TypeIndex type);
EXPCL_INTERROGATEDB int interrogate_type_number_of_enum_values(TypeIndex type);
EXPCL_INTERROGATEDB const char *interrogate_type_enum_value_name(TypeIndex type, int n);
EXPCL_INTERROGATEDB const char *interrogate_type_enum_value_scoped_name(TypeIndex type, int n);
@ -499,6 +503,7 @@ EXPCL_INTERROGATEDB FunctionIndex interrogate_type_get_cast(TypeIndex type, int
// list of base classes for this particular type.
EXPCL_INTERROGATEDB int interrogate_type_number_of_derivations(TypeIndex type);
EXPCL_INTERROGATEDB TypeIndex interrogate_type_get_derivation(TypeIndex type, int n);
EXPCL_INTERROGATEDB bool interrogate_type_is_final(TypeIndex type);
// For each base class, we might need to define an explicit upcast or downcast
// operation to convert the pointer to the derived class to an appropriate