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;
return;
}
CPPFunctionGroup *fgroup = decl->as_function_group();
// Actually, we can't scope function groups.
/*CPPFunctionGroup *fgroup = decl->as_function_group();
if (fgroup != NULL) {
_type = T_function;
_u._fgroup = fgroup;
return;
}
}*/
}
_type = T_unknown_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;
case 'f': // Function evaluation, no parameters.
out << "(";
_u._op._op1->output(out, indent_level, scope, false);
out << "())";
out << "()";
break;
default:
@ -1555,11 +1555,9 @@ output(ostream &out, int indent_level, CPPScope *scope, bool) const {
break;
case POINTSAT:
out << "(";
_u._op._op1->output(out, indent_level, scope, false);
out << "->";
_u._op._op2->output(out, indent_level, scope, false);
out << ")";
break;
case '[': // Array element reference

View File

@ -1064,25 +1064,12 @@ write_class_details(ostream &out, Object *obj) {
}
// 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";
for (fi = obj->_constructors.begin(); fi != obj->_constructors.end(); ++fi) {
Function *func = (*fi);
std::string fname = "static int Dtool_Init_" + ClassName + "(PyObject *self, PyObject *args, PyObject *kwds)";
} else {
for (fi = obj->_constructors.begin(); fi != obj->_constructors.end(); ++fi) {
Function *func = (*fi);
std::string fname = "static int Dtool_Init_" + ClassName + "(PyObject *self, PyObject *args, PyObject *kwds)";
string expected_params;
write_function_for_name(out, obj, func->_remaps, fname, expected_params, true, AT_keyword_args, RF_int);
}
string expected_params;
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);
@ -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++) {
TypeIndex d_type_Index = obj->_itype.get_derivation(di);
if (!interrogate_type_is_unpublished(d_type_Index)) {
const InterrogateType &d_itype = idb->get_type(d_type_Index);
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;
for (rfi = slots.begin(); rfi != slots.end(); rfi++) {
@ -3032,18 +3015,28 @@ write_module_class(ostream &out, Object *obj) {
out << " initdone = true;\n";
// Add bases.
out << " // Dependent objects\n";
if (bases.size() > 0) {
out << " // Dependent objects\n";
string baseargs;
for (vector<string>::iterator bi = bases.begin(); bi != bases.end(); ++bi) {
baseargs += ", (PyTypeObject *)Dtool_Ptr_" + *bi;
string safe_name = make_safe_name(*bi);
for (vector<CPPType*>::iterator bi = bases.begin(); bi != bases.end(); ++bi) {
string safe_name = make_safe_name((*bi)->get_local_name(&parser));
out << " assert(Dtool_Ptr_" << safe_name << " != NULL);\n"
<< " Dtool_Ptr_" << safe_name << "->_Dtool_ModuleClassInit(NULL);\n";
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"
<< " assert(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";
} else {
out << " Dtool_" << ClassName << "._PyType.tp_base = (PyTypeObject *)Dtool_Ptr_DTOOL_SUPER_BASE;\n";
}
int num_nested = obj->_itype.number_of_nested_types();

View File

@ -24,9 +24,10 @@
#include "pnotify.h"
#include "panda_getopt_long.h"
#include "preprocess_argv.h"
#include "pset.h"
#include "vector_string.h"
#include <algorithm>
Filename output_code_filename;
string module_name;
string library_name;
@ -83,7 +84,7 @@ int write_python_table_native(ostream &out) {
int count = 0;
pset<std::string> libraries;
vector_string libraries;
// out << "extern \"C\" {\n";
@ -98,7 +99,10 @@ int write_python_table_native(ostream &out) {
// module_name == interrogate_function_module_name(function_index)) {
// if it has a library name add it to set of libraries
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);
if (interrogate_type_has_module_name(thetype) && module_name == interrogate_type_module_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;
for(ii = libraries.begin(); ii != libraries.end(); ii++) {
vector_string::const_iterator ii;
for (ii = libraries.begin(); ii != libraries.end(); ++ii) {
printf("Referencing Library %s\n", (*ii).c_str());
out << "extern LibraryDef " << *ii << "_moddef;\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) {
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;
}

View File

@ -595,6 +595,24 @@ PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], PyModuleDef *module_def)
#else
PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) {
#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....
MethodDefmap functions;
for (int xx = 0; defs[xx] != NULL; xx++) {

View File

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