Skip to content

Qualifier changes #35

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 3 commits into from
Nov 20, 2015
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
59 changes: 32 additions & 27 deletions docs/tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,38 @@ Types
.. note:: This attribute is not usable from within `lto1`; attempting
to use it there will lead to a `RuntimeError` exception.

Additional attributes for various :py:class:`gcc.Type` subclasses:

.. py:attribute:: const

(Boolean) Does this type have the `const` modifier?

.. py:attribute:: const_equivalent

The :py:class:`gcc.Type` for the `const` version of this type

.. py:attribute:: volatile

(Boolean) Does this type have the `volatile` modifier?

.. py:attribute:: volatile_equivalent

The :py:class:`gcc.Type` for the `volatile` version of this type

.. py:attribute:: restrict

(Boolean) Does this type have the `restrict` modifier?

.. py:attribute:: restrict_equivalent

The :py:class:`gcc.Type` for the `restrict` version of this type

.. py:attribute:: unqualified_equivalent

The :py:class:`gcc.Type` for the version of this type that does
not have any qualifiers.


The standard C types are accessible via class methods of :py:class:`gcc.Type`.
They are only created by GCC after plugins are loaded, and so they're
only visible during callbacks, not during the initial run of the code.
Expand Down Expand Up @@ -549,33 +581,6 @@ Types

The :py:class:`gcc.Type` that this type points to

Additional attributes for various :py:class:`gcc.Type` subclasses:

.. py:attribute:: const

(Boolean) Does this type have the `const` modifier?

.. py:attribute:: const_equivalent

The :py:class:`gcc.Type` for the `const` version of this type

.. py:attribute:: volatile

(Boolean) Does this type have the `volatile` modifier?

.. py:attribute:: volatile_equivalent

The :py:class:`gcc.Type` for the `volatile` version of this type

.. py:attribute:: restrict

(Boolean) Does this type have the `restrict` modifier?

.. py:attribute:: restrict_equivalent

The :py:class:`gcc.Type` for the `restrict` version of this type


.. py:class:: gcc.FunctionType

Subclass of :py:class:`gcc.Type` representing the type of a given function
Expand Down
5 changes: 4 additions & 1 deletion generate-tree-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,11 @@ def add_complex_getter(name, doc):
'PyBool_FromLong(TYPE_QUALS(self->t.inner) & TYPE_QUAL_%s)' % qual.upper(),
"Boolean: does this type have the '%s' modifier?" % qual)
add_simple_getter('%s_equivalent' % qual,
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, TYPE_QUAL_%s)))' % qual.upper(),
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, TYPE_QUALS(self->t.inner) | TYPE_QUAL_%s)))' % qual.upper(),
'The gcc.Type for the %s version of this type' % qual)
add_simple_getter('unqualified_equivalent',
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, 0)))',
'The gcc.Type for the unqualified version of this type')
if tree_type.SYM == 'RECORD_TYPE':
add_simple_getter('const',
'PyBool_FromLong(TYPE_READONLY(self->t.inner))',
Expand Down
6 changes: 6 additions & 0 deletions tests/plugin/types/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def dump_integer_type(t):
dump_integer_type(gcc.Type.unsigned_char())
dump_integer_type(gcc.Type.signed_char())

print(gcc.Type.char().const)
print(gcc.Type.char().const_equivalent.const)
print(gcc.Type.char().const_equivalent.restrict_equivalent.const)
print(gcc.Type.char().const_equivalent.volatile_equivalent.const)
print(gcc.Type.char().const_equivalent.volatile_equivalent.unqualified_equivalent.const)

def dump_real_type(t):
print('gcc.Type: %r' % str(t))
print(' t.const: %r' % t.const)
Expand Down
5 changes: 5 additions & 0 deletions tests/plugin/types/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ gcc.Type: 'signed char'
t.min_value.constant: -128
t.max_value.constant: 127
t.sizeof: 1
False
True
True
True
False
gcc.Type: 'float'
t.const: False
t.precision: 32
Expand Down