Stop generating empty arrays.

This commit is contained in:
Martin v. Löwis 2006-02-26 23:40:20 +00:00
parent 59090a7334
commit 8d0701daf1
2 changed files with 60 additions and 129 deletions

View file

@ -353,10 +353,11 @@ class PyTypesDeclareVisitor(PickleVisitor):
def visitProduct(self, prod, name):
self.emit("PyTypeObject *%s_type;" % name, 0)
self.emit("static PyObject* ast2obj_%s(void*);" % name, 0)
self.emit("char *%s_fields[]={" % name,0)
for f in prod.fields:
self.emit('"%s",' % f.name, 1)
self.emit("};", 0)
if prod.fields:
self.emit("char *%s_fields[]={" % name,0)
for f in prod.fields:
self.emit('"%s",' % f.name, 1)
self.emit("};", 0)
def visitSum(self, sum, name):
self.emit("PyTypeObject *%s_type;" % name, 0)
@ -374,10 +375,11 @@ class PyTypesDeclareVisitor(PickleVisitor):
def visitConstructor(self, cons, name):
self.emit("PyTypeObject *%s_type;" % cons.name, 0)
self.emit("char *%s_fields[]={" % cons.name, 0)
for t in cons.fields:
self.emit('"%s",' % t.name, 1)
self.emit("};",0)
if cons.fields:
self.emit("char *%s_fields[]={" % cons.name, 0)
for t in cons.fields:
self.emit('"%s",' % t.name, 1)
self.emit("};",0)
class PyTypesVisitor(PickleVisitor):
@ -450,8 +452,12 @@ static PyObject* ast2obj_bool(bool b)
self.emit("}", 0)
def visitProduct(self, prod, name):
self.emit('%s_type = make_type("%s", &PyBaseObject_Type, %s_fields, %d);' %
(name, name, name, len(prod.fields)), 1)
if prod.fields:
fields = name.value+"_fields"
else:
fields = "NULL"
self.emit('%s_type = make_type("%s", &PyBaseObject_Type, %s, %d);' %
(name, name, fields, len(prod.fields)), 1)
def visitSum(self, sum, name):
self.emit('%s_type = make_type("%s", &PyBaseObject_Type, NULL, 0);' % (name, name), 1)
@ -460,8 +466,12 @@ static PyObject* ast2obj_bool(bool b)
self.visitConstructor(t, name, simple)
def visitConstructor(self, cons, name, simple):
self.emit('%s_type = make_type("%s", %s_type, %s_fields, %d);' %
(cons.name, cons.name, name, cons.name, len(cons.fields)), 1)
if cons.fields:
fields = cons.name.value+"_fields"
else:
fields = "NULL"
self.emit('%s_type = make_type("%s", %s_type, %s, %d);' %
(cons.name, cons.name, name, fields, len(cons.fields)), 1)
if simple:
self.emit("%s_singleton = PyType_GenericNew(%s_type, NULL, NULL);" %
(cons.name, cons.name), 1)