From a102d86358b33cdcfd0dea89615947ceea20c072 Mon Sep 17 00:00:00 2001 From: Plamen Date: Fri, 26 Sep 2014 11:46:11 +0100 Subject: [PATCH 1/3] Ensure size is non-zero. --- gcc-python-tree.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc-python-tree.c b/gcc-python-tree.c index 8daa6ed1..2755400d 100644 --- a/gcc-python-tree.c +++ b/gcc-python-tree.c @@ -542,7 +542,8 @@ PyGccFunction_TypeObj_get_argument_types(struct PyGccTree * self, void *closure) { PyObject *result; PyObject *item; - int i, size; + int i; + unsigned int size; tree iter; tree head = TYPE_ARG_TYPES(self->t.inner); @@ -554,10 +555,14 @@ PyGccFunction_TypeObj_get_argument_types(struct PyGccTree * self, void *closure) } /* "size" should now be the length of the chain */ + + /* When a function with no input arguments is passed ( ex int foo()) + the previous code crashed. */ + if(size == 0) + size = 1; /* The last element in the list is a VOID_TYPE; don't add this; see dump_function_declaration() in gcc/tree-pretty-print.c */ - assert(size>0); size--; result = PyTuple_New(size); From e873f370d066105a2d08fa1baf5008e089521db9 Mon Sep 17 00:00:00 2001 From: Plamen Date: Fri, 26 Sep 2014 11:46:52 +0100 Subject: [PATCH 2/3] Support for record types and enumeral types. --- generate-tree-c.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/generate-tree-c.py b/generate-tree-c.py index 1c6df3c5..700c6f02 100644 --- a/generate-tree-c.py +++ b/generate-tree-c.py @@ -470,13 +470,29 @@ def add_complex_getter(name, doc): 'PyGccTree_New(gcc_private_make_tree(TREE_OPERAND(self->t.inner, 2)))', "The position of the first referenced bit, as a gcc.IntegerCst") - if tree_type.SYM in ('RECORD_TYPE', 'UNION_TYPE', 'QUAL_UNION_TYPE'): + if tree_type.SYM in ( 'UNION_TYPE', 'QUAL_UNION_TYPE'): add_simple_getter('fields', 'PyGcc_TreeListFromChain(TYPE_FIELDS(self->t.inner))', "The fields of this type") add_simple_getter('methods', 'PyGcc_TreeListFromChain(TYPE_METHODS(self->t.inner))', "The methods of this type") + + if tree_type.SYM in ('RECORD_TYPE'): + add_simple_getter('fields', + 'PyGcc_TreeListFromChain(TYPE_FIELDS(self->t.inner))', + "The fields of this type") + add_simple_getter('methods', + 'PyGcc_TreeListFromChain(TYPE_METHODS(self->t.inner))', + "The methods of this type") + add_simple_getter('context', + 'PyGcc_TreeListFromChain(TYPE_CONTEXT(self->t.inner))', + "The context of this type") + + if tree_type.SYM == 'ENUMERAL_TYPE': + add_simple_getter('values', + 'PyGcc_TreeListFromChain(TYPE_VALUES(self->t.inner))', + "The values of this type") if tree_type.SYM == 'IDENTIFIER_NODE': add_simple_getter('name', From e7c09dd97609fc23f85114fc15265eb91a0847df Mon Sep 17 00:00:00 2001 From: Plamen Date: Fri, 26 Sep 2014 11:52:34 +0100 Subject: [PATCH 3/3] Turn variable back into int to avoid comparison warnings. --- gcc-python-tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gcc-python-tree.c b/gcc-python-tree.c index 2755400d..17833104 100644 --- a/gcc-python-tree.c +++ b/gcc-python-tree.c @@ -542,8 +542,7 @@ PyGccFunction_TypeObj_get_argument_types(struct PyGccTree * self, void *closure) { PyObject *result; PyObject *item; - int i; - unsigned int size; + int i, size; tree iter; tree head = TYPE_ARG_TYPES(self->t.inner);