A few interrogate improvements

This commit is contained in:
rdb 2015-11-28 17:54:01 +01:00
parent eca343c712
commit 1b857d6bda
6 changed files with 63 additions and 46 deletions

View File

@ -273,17 +273,18 @@ CPPExpression(CPPIdentifier *ident, CPPScope *current_scope,
_u._variable = inst; _u._variable = inst;
return; return;
} }
CPPFunctionGroup *fgroup = decl->as_function_group(); // Actually, we can't scope function groups.
/*CPPFunctionGroup *fgroup = decl->as_function_group();
if (fgroup != NULL) { if (fgroup != NULL) {
_type = T_function; _type = T_function;
_u._fgroup = fgroup; _u._fgroup = fgroup;
return; return;
} }*/
} }
_type = T_unknown_ident; _type = T_unknown_ident;
_u._ident = ident; _u._ident = ident;
_u._ident->_native_scope = current_scope; //_u._ident->_native_scope = current_scope;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -1467,9 +1468,8 @@ output(ostream &out, int indent_level, CPPScope *scope, bool) const {
break; break;
case 'f': // Function evaluation, no parameters. case 'f': // Function evaluation, no parameters.
out << "(";
_u._op._op1->output(out, indent_level, scope, false); _u._op._op1->output(out, indent_level, scope, false);
out << "())"; out << "()";
break; break;
default: default:
@ -1555,11 +1555,9 @@ output(ostream &out, int indent_level, CPPScope *scope, bool) const {
break; break;
case POINTSAT: case POINTSAT:
out << "(";
_u._op._op1->output(out, indent_level, scope, false); _u._op._op1->output(out, indent_level, scope, false);
out << "->"; out << "->";
_u._op._op2->output(out, indent_level, scope, false); _u._op._op2->output(out, indent_level, scope, false);
out << ")";
break; break;
case '[': // Array element reference case '[': // Array element reference

View File

@ -1064,18 +1064,6 @@ write_class_details(ostream &out, Object *obj) {
} }
// Write the constructors. // Write the constructors.
if (obj->_constructors.size() == 0) {
// There is no constructor - write one that simply outputs an error.
out << "static int Dtool_Init_" + ClassName + "(PyObject *, PyObject *, PyObject *) {\n"
<< "#ifdef NDEBUG\n"
<< " Dtool_Raise_TypeError(\"cannot init constant class\");\n"
<< "#else\n"
<< " Dtool_Raise_TypeError(\"cannot init constant class " << cClassName << "\");\n"
<< "#endif\n"
<< " return -1;\n"
<< "}\n\n";
} else {
for (fi = obj->_constructors.begin(); fi != obj->_constructors.end(); ++fi) { for (fi = obj->_constructors.begin(); fi != obj->_constructors.end(); ++fi) {
Function *func = (*fi); Function *func = (*fi);
std::string fname = "static int Dtool_Init_" + ClassName + "(PyObject *self, PyObject *args, PyObject *kwds)"; std::string fname = "static int Dtool_Init_" + ClassName + "(PyObject *self, PyObject *args, PyObject *kwds)";
@ -1083,7 +1071,6 @@ write_class_details(ostream &out, Object *obj) {
string expected_params; string expected_params;
write_function_for_name(out, obj, func->_remaps, fname, expected_params, true, AT_keyword_args, RF_int); write_function_for_name(out, obj, func->_remaps, fname, expected_params, true, AT_keyword_args, RF_int);
} }
}
CPPType *cpptype = TypeManager::resolve_type(obj->_itype._cpptype); CPPType *cpptype = TypeManager::resolve_type(obj->_itype._cpptype);
@ -1764,21 +1751,17 @@ write_module_class(ostream &out, Object *obj) {
} }
} }
std::vector<std::string> bases; std::vector<CPPType*> bases;
for (di = 0; di < num_derivations; di++) { for (di = 0; di < num_derivations; di++) {
TypeIndex d_type_Index = obj->_itype.get_derivation(di); TypeIndex d_type_Index = obj->_itype.get_derivation(di);
if (!interrogate_type_is_unpublished(d_type_Index)) { if (!interrogate_type_is_unpublished(d_type_Index)) {
const InterrogateType &d_itype = idb->get_type(d_type_Index); const InterrogateType &d_itype = idb->get_type(d_type_Index);
if (is_cpp_type_legal(d_itype._cpptype)) { if (is_cpp_type_legal(d_itype._cpptype)) {
bases.push_back(make_safe_name(d_itype.get_scoped_name().c_str())); bases.push_back(d_itype._cpptype);
} }
} }
} }
if (bases.empty()) {
bases.push_back("DTOOL_SUPER_BASE");
}
{ {
SlottedFunctions::iterator rfi; SlottedFunctions::iterator rfi;
for (rfi = slots.begin(); rfi != slots.end(); rfi++) { for (rfi = slots.begin(); rfi != slots.end(); rfi++) {
@ -3032,18 +3015,28 @@ write_module_class(ostream &out, Object *obj) {
out << " initdone = true;\n"; out << " initdone = true;\n";
// Add bases. // Add bases.
if (bases.size() > 0) {
out << " // Dependent objects\n"; out << " // Dependent objects\n";
if (bases.size() > 0) {
string baseargs; string baseargs;
for (vector<string>::iterator bi = bases.begin(); bi != bases.end(); ++bi) { for (vector<CPPType*>::iterator bi = bases.begin(); bi != bases.end(); ++bi) {
baseargs += ", (PyTypeObject *)Dtool_Ptr_" + *bi; string safe_name = make_safe_name((*bi)->get_local_name(&parser));
string safe_name = make_safe_name(*bi);
if (isExportThisRun(*bi)) {
baseargs += ", (PyTypeObject *)&Dtool_" + safe_name;
out << " Dtool_PyModuleClassInit_" << safe_name << "(NULL);\n";
} else {
baseargs += ", (PyTypeObject *)Dtool_Ptr_" + safe_name;
out << " assert(Dtool_Ptr_" << safe_name << " != NULL);\n" out << " assert(Dtool_Ptr_" << safe_name << " != NULL);\n"
<< " assert(Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit != NULL);\n"
<< " Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit(NULL);\n"; << " Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit(NULL);\n";
} }
}
out << " Dtool_" << ClassName << "._PyType.tp_bases = PyTuple_Pack(" << bases.size() << baseargs << ");\n"; out << " Dtool_" << ClassName << "._PyType.tp_bases = PyTuple_Pack(" << bases.size() << baseargs << ");\n";
} else {
out << " Dtool_" << ClassName << "._PyType.tp_base = (PyTypeObject *)Dtool_Ptr_DTOOL_SUPER_BASE;\n";
} }
int num_nested = obj->_itype.number_of_nested_types(); int num_nested = obj->_itype.number_of_nested_types();

View File

@ -24,9 +24,10 @@
#include "pnotify.h" #include "pnotify.h"
#include "panda_getopt_long.h" #include "panda_getopt_long.h"
#include "preprocess_argv.h" #include "preprocess_argv.h"
#include "pset.h"
#include "vector_string.h" #include "vector_string.h"
#include <algorithm>
Filename output_code_filename; Filename output_code_filename;
string module_name; string module_name;
string library_name; string library_name;
@ -83,7 +84,7 @@ int write_python_table_native(ostream &out) {
int count = 0; int count = 0;
pset<std::string> libraries; vector_string libraries;
// out << "extern \"C\" {\n"; // out << "extern \"C\" {\n";
@ -98,7 +99,10 @@ int write_python_table_native(ostream &out) {
// module_name == interrogate_function_module_name(function_index)) { // module_name == interrogate_function_module_name(function_index)) {
// if it has a library name add it to set of libraries // if it has a library name add it to set of libraries
if (interrogate_function_has_library_name(function_index)) { if (interrogate_function_has_library_name(function_index)) {
libraries.insert(interrogate_function_library_name(function_index)); string library_name = interrogate_function_library_name(function_index);
if (std::find(libraries.begin(), libraries.end(), library_name) == libraries.end()) {
libraries.push_back(library_name);
}
} }
//} //}
} }
@ -107,13 +111,16 @@ int write_python_table_native(ostream &out) {
TypeIndex thetype = interrogate_get_type(ti); TypeIndex thetype = interrogate_get_type(ti);
if (interrogate_type_has_module_name(thetype) && module_name == interrogate_type_module_name(thetype)) { if (interrogate_type_has_module_name(thetype) && module_name == interrogate_type_module_name(thetype)) {
if (interrogate_type_has_library_name(thetype)) { if (interrogate_type_has_library_name(thetype)) {
libraries.insert(interrogate_type_library_name(thetype)); string library_name = interrogate_type_library_name(thetype);
if (std::find(libraries.begin(), libraries.end(), library_name) == libraries.end()) {
libraries.push_back(library_name);
}
} }
} }
} }
pset<std::string >::iterator ii; vector_string::const_iterator ii;
for(ii = libraries.begin(); ii != libraries.end(); ii++) { for (ii = libraries.begin(); ii != libraries.end(); ++ii) {
printf("Referencing Library %s\n", (*ii).c_str()); printf("Referencing Library %s\n", (*ii).c_str());
out << "extern LibraryDef " << *ii << "_moddef;\n"; out << "extern LibraryDef " << *ii << "_moddef;\n";
out << "extern void Dtool_" << *ii << "_RegisterTypes();\n"; out << "extern void Dtool_" << *ii << "_RegisterTypes();\n";

View File

@ -62,7 +62,8 @@ inline void *Dtool_UpcastInterface_DTOOL_SUPER_BASE(PyObject *self, Dtool_PyType
} }
int Dtool_Init_DTOOL_SUPER_BASE(PyObject *self, PyObject *args, PyObject *kwds) { int Dtool_Init_DTOOL_SUPER_BASE(PyObject *self, PyObject *args, PyObject *kwds) {
PyErr_SetString(PyExc_TypeError, "cannot init super base"); assert(self != NULL);
PyErr_Format(PyExc_TypeError, "cannot init constant class %s", Py_TYPE(self)->tp_name);
return -1; return -1;
} }

View File

@ -595,6 +595,24 @@ PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], PyModuleDef *module_def)
#else #else
PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) { PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) {
#endif #endif
// Check the version so we can print a helpful error if it doesn't match.
string version = Py_GetVersion();
if (interrogatedb_cat.is_debug()) {
interrogatedb_cat.debug()
<< "Python " << version << "\n";
}
if (version[0] != '0' + PY_MAJOR_VERSION ||
version[2] != '0' + PY_MINOR_VERSION) {
interrogatedb_cat.error()
<< "This module was compiled for Python "
<< PY_MAJOR_VERSION << "." << PY_MINOR_VERSION << ", which is incompatible "
<< "with Python " << version << ".\n";
}
// Initialize the base class of everything.
Dtool_PyModuleClassInit_DTOOL_SUPER_BASE(NULL);
// the module level function inits.... // the module level function inits....
MethodDefmap functions; MethodDefmap functions;
for (int xx = 0; defs[xx] != NULL; xx++) { for (int xx = 0; defs[xx] != NULL; xx++) {

View File

@ -37,8 +37,8 @@ PUBLISHED:
typedef BMType BitMaskType; typedef BMType BitMaskType;
enum { enum {
half_bits = BitMaskType::num_bits, half_bits = BMType::num_bits,
num_bits = BitMaskType::num_bits * 2, num_bits = BMType::num_bits * 2,
}; };
INLINE DoubleBitMask(); INLINE DoubleBitMask();