Skip to content

TYPE_METHODS on record types #6

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

Merged
merged 1 commit into from
May 15, 2014
Merged
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
4 changes: 4 additions & 0 deletions docs/tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ Additional attributes for various :py:class:`gcc.Type` subclasses:

The fields of this type, as a list of :py:class:`gcc.FieldDecl` instances

.. py:attribute:: methods

The methods of this type, as a list of :py:class:`gcc.MethodType` instances

You can look up C structures by looking within the top-level
:py:class:`gcc.Block` within the current translation unit. For example,
given this sample C code:
Expand Down
3 changes: 3 additions & 0 deletions generate-tree-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ def add_complex_getter(name, doc):
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 == 'IDENTIFIER_NODE':
add_simple_getter('name',
Expand Down
45 changes: 45 additions & 0 deletions tests/examples/cplusplus/methods/input.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2014 Philip Herron <[email protected]>
Copyright 2011 Red Hat, Inc.

This is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/

class test {
int a, b;
public:
test (int, int);
int somefunc (void);
};

test::test (int x, int y)
{
a = x;
b = y;
}

int test::somefunc (void)
{
return a * b;
}


/*
PEP-7
Local variables:
c-basic-offset: 4
indent-tabs-mode: nil
End:
*/
33 changes: 33 additions & 0 deletions tests/examples/cplusplus/methods/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Philip Herron <[email protected]>
# Copyright 2011 Red Hat, Inc.
#
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.

import gcc
import pprint

def gccPassHook(passname, _):
if passname.name == '*free_lang_data':
for i in gcc.get_translation_units ():
gns = gcc.get_global_namespace ()
for decl in gns.declarations:
if decl.is_builtin is False:
pp = pprint.PrettyPrinter(indent=4)
pp.pprint (str (decl.type))
pp.pprint (decl.type.fields)
pp.pprint (decl.type.methods)

gcc.register_callback (gcc.PLUGIN_PASS_EXECUTION, gccPassHook)
9 changes: 9 additions & 0 deletions tests/examples/cplusplus/methods/stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'struct test'
[gcc.FieldDecl('a'), gcc.FieldDecl('b'), gcc.TypeDecl('test')]
[ gcc.FunctionDecl('test'),
gcc.FunctionDecl('__base_ctor '),
gcc.FunctionDecl('__comp_ctor '),
gcc.FunctionDecl('test'),
gcc.FunctionDecl('__base_ctor '),
gcc.FunctionDecl('__comp_ctor '),
gcc.FunctionDecl('somefunc')]