File tree Expand file tree Collapse file tree 6 files changed +80
-1
lines changed Expand file tree Collapse file tree 6 files changed +80
-1
lines changed Original file line number Diff line number Diff line change @@ -542,6 +542,17 @@ Additional attributes for various :py:class:`gcc.Type` subclasses:
542542 The :py:class: `gcc.Type ` that this type points to. In the above
543543 example (`int * `), this would be the `int ` type.
544544
545+ .. py :class :: gcc.EnumeralType
546+
547+ Subclass of :py:class: `gcc.Type ` representing an enumeral type.
548+
549+ .. py :attribute :: values
550+
551+ A list of tuple representing the constants defined in this
552+ enumeration. Each tuple consists of two elements; the first
553+ being the name of the constant, a :py:class: `gcc.IdentifierNode `;
554+ and the second being the value, a :py:class: `gcc.Constant `.
555+
545556.. py :class :: gcc.ArrayType
546557
547558 Subclass of :py:class: `gcc.Type ` representing an array type. For example,
Original file line number Diff line number Diff line change @@ -1152,7 +1152,7 @@ PyGcc_TreeMakeListFromTreeList(tree t)
11521152 Extract a list of objects for the values
11531153 */
11541154PyObject *
1155- gcc_tree_list_of_pairs_from_tree_list_chain (tree t )
1155+ PyGcc_TreeMakeListOfPairsFromTreeListChain (tree t )
11561156{
11571157 PyObject * result = NULL ;
11581158
Original file line number Diff line number Diff line change @@ -485,6 +485,11 @@ def add_complex_getter(name, doc):
485485 'PyGcc_TreeListFromChain(TYPE_METHODS(self->t.inner))' ,
486486 "The methods of this type" )
487487
488+ if tree_type .SYM == 'ENUMERAL_TYPE' :
489+ add_simple_getter ('values' ,
490+ 'PyGcc_TreeMakeListOfPairsFromTreeListChain(TYPE_VALUES(self->t.inner))' ,
491+ "The values of this type" )
492+
488493 if tree_type .SYM == 'IDENTIFIER_NODE' :
489494 add_simple_getter ('name' ,
490495 'PyGccStringOrNone(IDENTIFIER_POINTER(self->t.inner))' ,
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright 2015 Tom Tromey <tom@tromey.com>
3+
4+ This is free software: you can redistribute it and/or modify it
5+ under the terms of the GNU General Public License as published by
6+ the Free Software Foundation, either version 3 of the License, or
7+ (at your option) any later version.
8+
9+ This program is distributed in the hope that it will be useful, but
10+ WITHOUT ANY WARRANTY; without even the implied warranty of
11+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ General Public License for more details.
13+
14+ You should have received a copy of the GNU General Public License
15+ along with this program. If not, see
16+ <http://www.gnu.org/licenses/>.
17+ */
18+
19+ enum the_enum
20+ {
21+ ONE = 1 ,
22+ TWO = 2 ,
23+ MINUS_ONE = -1
24+ };
25+
26+ /* We need a variable because some versions of gcc don't call
27+ PLUGIN_FINISH_TYPE for an enum. */
28+ enum the_enum variable ;
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ # Copyright 2015 Tom Tromey <tom@tromey.com>
3+ #
4+ # This is free software: you can redistribute it and/or modify it
5+ # under the terms of the GNU General Public License as published by
6+ # the Free Software Foundation, either version 3 of the License, or
7+ # (at your option) any later version.
8+ #
9+ # This program is distributed in the hope that it will be useful, but
10+ # WITHOUT ANY WARRANTY; without even the implied warranty of
11+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ # General Public License for more details.
13+ #
14+ # You should have received a copy of the GNU General Public License
15+ # along with this program. If not, see
16+ # <http://www.gnu.org/licenses/>.
17+
18+ import gcc
19+
20+ def on_decl (v , * args , ** kwargs ):
21+ if v .name != 'variable' :
22+ return
23+
24+ t = v .type
25+ print (t .name )
26+ print ('length = %d' % len (t .values ))
27+ for (name , value ) in t .values :
28+ print ('%s = %s' % (name , value ))
29+
30+ gcc .register_callback (gcc .PLUGIN_FINISH_DECL , on_decl )
Original file line number Diff line number Diff line change 1+ the_enum
2+ length = 3
3+ ONE = 1
4+ TWO = 2
5+ MINUS_ONE = -1
You can’t perform that action at this time.
0 commit comments