Skip to content

Commit a369bf5

Browse files
committed
Merge pull request #35 from tromey/qualifier-changes
Qualifier changes
2 parents 703ab48 + 348790e commit a369bf5

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

docs/tree.rst

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,38 @@ Types
421421
.. note:: This attribute is not usable from within `lto1`; attempting
422422
to use it there will lead to a `RuntimeError` exception.
423423

424+
Additional attributes for various :py:class:`gcc.Type` subclasses:
425+
426+
.. py:attribute:: const
427+
428+
(Boolean) Does this type have the `const` modifier?
429+
430+
.. py:attribute:: const_equivalent
431+
432+
The :py:class:`gcc.Type` for the `const` version of this type
433+
434+
.. py:attribute:: volatile
435+
436+
(Boolean) Does this type have the `volatile` modifier?
437+
438+
.. py:attribute:: volatile_equivalent
439+
440+
The :py:class:`gcc.Type` for the `volatile` version of this type
441+
442+
.. py:attribute:: restrict
443+
444+
(Boolean) Does this type have the `restrict` modifier?
445+
446+
.. py:attribute:: restrict_equivalent
447+
448+
The :py:class:`gcc.Type` for the `restrict` version of this type
449+
450+
.. py:attribute:: unqualified_equivalent
451+
452+
The :py:class:`gcc.Type` for the version of this type that does
453+
not have any qualifiers.
454+
455+
424456
The standard C types are accessible via class methods of :py:class:`gcc.Type`.
425457
They are only created by GCC after plugins are loaded, and so they're
426458
only visible during callbacks, not during the initial run of the code.
@@ -549,33 +581,6 @@ Types
549581
550582
The :py:class:`gcc.Type` that this type points to
551583

552-
Additional attributes for various :py:class:`gcc.Type` subclasses:
553-
554-
.. py:attribute:: const
555-
556-
(Boolean) Does this type have the `const` modifier?
557-
558-
.. py:attribute:: const_equivalent
559-
560-
The :py:class:`gcc.Type` for the `const` version of this type
561-
562-
.. py:attribute:: volatile
563-
564-
(Boolean) Does this type have the `volatile` modifier?
565-
566-
.. py:attribute:: volatile_equivalent
567-
568-
The :py:class:`gcc.Type` for the `volatile` version of this type
569-
570-
.. py:attribute:: restrict
571-
572-
(Boolean) Does this type have the `restrict` modifier?
573-
574-
.. py:attribute:: restrict_equivalent
575-
576-
The :py:class:`gcc.Type` for the `restrict` version of this type
577-
578-
579584
.. py:class:: gcc.FunctionType
580585
581586
Subclass of :py:class:`gcc.Type` representing the type of a given function

generate-tree-c.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,11 @@ def add_complex_getter(name, doc):
396396
'PyBool_FromLong(TYPE_QUALS(self->t.inner) & TYPE_QUAL_%s)' % qual.upper(),
397397
"Boolean: does this type have the '%s' modifier?" % qual)
398398
add_simple_getter('%s_equivalent' % qual,
399-
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, TYPE_QUAL_%s)))' % qual.upper(),
399+
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, TYPE_QUALS(self->t.inner) | TYPE_QUAL_%s)))' % qual.upper(),
400400
'The gcc.Type for the %s version of this type' % qual)
401+
add_simple_getter('unqualified_equivalent',
402+
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, 0)))',
403+
'The gcc.Type for the unqualified version of this type')
401404
if tree_type.SYM == 'RECORD_TYPE':
402405
add_simple_getter('const',
403406
'PyBool_FromLong(TYPE_READONLY(self->t.inner))',

tests/plugin/types/script.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def dump_integer_type(t):
3939
dump_integer_type(gcc.Type.unsigned_char())
4040
dump_integer_type(gcc.Type.signed_char())
4141

42+
print(gcc.Type.char().const)
43+
print(gcc.Type.char().const_equivalent.const)
44+
print(gcc.Type.char().const_equivalent.restrict_equivalent.const)
45+
print(gcc.Type.char().const_equivalent.volatile_equivalent.const)
46+
print(gcc.Type.char().const_equivalent.volatile_equivalent.unqualified_equivalent.const)
47+
4248
def dump_real_type(t):
4349
print('gcc.Type: %r' % str(t))
4450
print(' t.const: %r' % t.const)

tests/plugin/types/stdout.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ gcc.Type: 'signed char'
1212
t.min_value.constant: -128
1313
t.max_value.constant: 127
1414
t.sizeof: 1
15+
False
16+
True
17+
True
18+
True
19+
False
1520
gcc.Type: 'float'
1621
t.const: False
1722
t.precision: 32

0 commit comments

Comments
 (0)