Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrrect python wrapper object #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions generate-tree-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def generate_tree():
#
global modinit_preinit
global modinit_postinit

cu.add_defn("""
static PyObject *
PyGccTree_get_type(struct PyGccTree *self, void *closure)
Expand All @@ -82,7 +82,7 @@ def generate_tree():
typename='PyGccTree')

cu.add_defn(getsettable.c_defn())

pytype = PyGccWrapperTypeObject(identifier = 'PyGccTree_TypeObj',
localname = 'Tree',
tp_name = 'gcc.Tree',
Expand Down Expand Up @@ -115,7 +115,7 @@ def generate_tree():
cu.add_defn(pytype.c_defn())
modinit_preinit += pytype.c_invoke_type_ready()
modinit_postinit += pytype.c_invoke_add_to_module()

generate_tree()

type_for_code_class = {
Expand All @@ -140,7 +140,7 @@ def generate_intermediate_tree_classes():
global modinit_preinit
global modinit_postinit


for code_type in type_for_code_class.values():
# We've already built the base class:
if code_type == 'PyGccTree_TypeObj':
Expand Down Expand Up @@ -311,7 +311,7 @@ def add_type(c_expr_for_node, typename):
"FIXME")

cu.add_defn(methods.c_defn())
cu.add_defn(getsettable.c_defn())
cu.add_defn(getsettable.c_defn())
cu.add_defn(pytype.c_defn())
modinit_preinit += pytype.c_invoke_type_ready()
modinit_postinit += pytype.c_invoke_add_to_module()
Expand All @@ -325,8 +325,10 @@ def generate_tree_code_classes():
# as subclasses of the above layer:
global modinit_preinit
global modinit_postinit

for tree_type in tree_types:
if tree_type.TYPE is None:
continue
base_type = type_for_code_class[tree_type.TYPE]

cc = tree_type.camel_cased_string()
Expand Down Expand Up @@ -388,7 +390,7 @@ def add_complex_getter(name, doc):
tp_repr = '(reprfunc)PyGccRealCst_repr'

# TYPE_QUALS for various foo_TYPE classes:
if tree_type.SYM in ('VOID_TYPE', 'INTEGER_TYPE', 'REAL_TYPE',
if tree_type.SYM in ('VOID_TYPE', 'INTEGER_TYPE', 'REAL_TYPE',
'FIXED_POINT_TYPE', 'COMPLEX_TYPE', 'VECTOR_TYPE',
'ENUMERAL_TYPE', 'BOOLEAN_TYPE'):
for qual in ('const', 'volatile', 'restrict'):
Expand Down Expand Up @@ -639,19 +641,24 @@ def add_complex_getter(name, doc):
cu.add_defn(pytype.c_defn())
modinit_preinit += pytype.c_invoke_type_ready()
modinit_postinit += pytype.c_invoke_add_to_module()


cu.add_defn('\n/* Map from GCC tree codes to PyGccWrapperTypeObject* */\n')
cu.add_defn('PyGccWrapperTypeObject *pytype_for_tree_code[] = {\n')
for tree_type in tree_types:
cu.add_defn(' &PyGcc%s_TypeObj, /* %s */\n' % (tree_type.camel_cased_string(), tree_type.SYM))
if tree_type.TYPE is None:
cu.add_defn(' NULL, /* %s */\n' % (tree_type.SYM))
else:
cu.add_defn(' &PyGcc%s_TypeObj, /* %s */\n' % (tree_type.camel_cased_string(), tree_type.SYM))
cu.add_defn('};\n\n')

cu.add_defn('\n/* Map from PyGccWrapperTypeObject* to GCC tree codes*/\n')
cu.add_defn('int \n')
cu.add_defn('PyGcc_tree_type_object_as_tree_code(PyObject *cls, enum tree_code *out)\n')
cu.add_defn('{\n')
for tree_type in tree_types:
if tree_type.TYPE is None:
continue
cu.add_defn(' if (cls == (PyObject*)&PyGcc%s_TypeObj) {\n'
' *out = %s; return 0;\n'
' }\n'
Expand Down
3 changes: 2 additions & 1 deletion maketreetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def iter_tree_types():
STRING=m.group(2)[1:-1],
TYPE=m.group(3),
NARGS=int(m.group(4)))
elif line == "LAST_AND_UNUSED_TREE_CODE,\n":
yield TreeType('LAST_AND_UNUSED_TREE_CODE', None, None, 0)
else:
# print 'UNMATCHED: ', line
assert(line.startswith('#') or line.strip() == '')
f.close()

Expand Down
2 changes: 1 addition & 1 deletion tree-types.txt.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
SYM, STRING, TYPE, NARGS
#define END_OF_BASE_TREE_CODES
#define END_OF_BASE_TREE_CODES LAST_AND_UNUSED_TREE_CODE,
#include "all-tree.def"
#undef DEFTREECODE