Skip to content

Commit 4dacd58

Browse files
committed
python-native: When a base class is unpublished, now looks recursively
for published base classes to inherit from This also required changing interrogatedb to record hierarchy for unpublished classes
1 parent 807c6e0 commit 4dacd58

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

src/interrogate/interfaceMakerPythonNative.cxx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,15 +2080,7 @@ write_module_class(ostream &out, Object *obj) {
20802080
}
20812081

20822082
std::vector<CPPType*> bases;
2083-
for (di = 0; di < num_derivations; di++) {
2084-
TypeIndex d_type_Index = obj->_itype.get_derivation(di);
2085-
if (!interrogate_type_is_unpublished(d_type_Index)) {
2086-
const InterrogateType &d_itype = idb->get_type(d_type_Index);
2087-
if (is_cpp_type_legal(d_itype._cpptype)) {
2088-
bases.push_back(d_itype._cpptype);
2089-
}
2090-
}
2091-
}
2083+
get_legal_bases(obj->_itype, bases);
20922084

20932085
{
20942086
SlottedFunctions::iterator rfi;
@@ -8161,6 +8153,27 @@ is_cpp_type_legal(CPPType *in_ctype) {
81618153

81628154
return false;
81638155
}
8156+
8157+
/**
8158+
* Returns a list of base classes. If one of the base classes is illegal,
8159+
* uses that class' bases.
8160+
*/
8161+
void InterfaceMakerPythonNative::
8162+
get_legal_bases(const InterrogateType &itype, std::vector<CPPType*> &result) {
8163+
int num_derivations = itype.number_of_derivations();
8164+
for (int di = 0; di < num_derivations; ++di) {
8165+
TypeIndex d_type_Index = itype.get_derivation(di);
8166+
8167+
InterrogateDatabase *idb = InterrogateDatabase::get_ptr();
8168+
const InterrogateType &d_itype = idb->get_type(d_type_Index);
8169+
if (!interrogate_type_is_unpublished(d_type_Index) && is_cpp_type_legal(d_itype._cpptype)) {
8170+
result.push_back(d_itype._cpptype);
8171+
} else {
8172+
get_legal_bases(d_itype, result);
8173+
}
8174+
}
8175+
}
8176+
81648177
/**
81658178
81668179
*/

src/interrogate/interfaceMakerPythonNative.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class InterfaceMakerPythonNative : public InterfaceMakerPython {
196196
bool is_remap_coercion_possible(FunctionRemap *remap);
197197
bool is_function_legal(Function *func);
198198
bool is_cpp_type_legal(CPPType *ctype);
199+
void get_legal_bases(const InterrogateType &itype, std::vector<CPPType*> &result);
199200
bool isExportThisRun(CPPType *ctype);
200201
bool isExportThisRun(Function *func);
201202
bool isFunctionWithThis( Function *func);

src/interrogate/interrogateBuilder.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,25 @@ define_struct_type(InterrogateType &itype, CPPStructType *cpptype,
25872587
if (TypeManager::involves_unpublished(cpptype)) {
25882588
itype._flags &= ~InterrogateType::F_fully_defined;
25892589
itype._flags |= InterrogateType::F_unpublished;
2590+
2591+
// However, we still must record its base classes, so that we can record
2592+
// the full type hierarchy where an intermediate type is not published.
2593+
if (itype._derivations.empty()) {
2594+
for (const CPPStructType::Base &base : cpptype->_derivation) {
2595+
if (base._vis <= V_public) {
2596+
CPPType *base_type = TypeManager::resolve_type(base._base, cpptype->_scope);
2597+
TypeIndex base_index = get_type(base_type, false);
2598+
if (base_index != 0) {
2599+
InterrogateType::Derivation d;
2600+
d._flags = 0;
2601+
d._base = base_index;
2602+
d._upcast = 0;
2603+
d._downcast = 0;
2604+
itype._derivations.push_back(d);
2605+
}
2606+
}
2607+
}
2608+
}
25902609
return;
25912610
}
25922611
if (TypeManager::involves_protected(cpptype)) {

0 commit comments

Comments
 (0)