Skip to content

Missing support for GNU extension types like _Complex or _Fract #9535

@marxin

Description

@marxin

I'm currently working on the transition of the GNU C compiler (GCC) manuals and I noticed there are unsupported C extensions like:

.. c:function:: complex long foo(int)
.. c:function:: _Complex long foo(int)
.. c:function:: long fract __satfractunssisq (unsigned int a)

  My function.

where I see the following parsing error:

/home/marxin/Programming/texi2rst-generated/sphinx/demo/demo.rst:66: WARNING: Invalid C declaration: Expected identifier, got user-defined keyword: complex. Remove it from c_extra_keywords to allow it as identifier.
Currently c_extra_keywords is ['alignas', 'alignof', 'bool', 'complex', 'imaginary', 'noreturn', 'static_assert', 'thread_local']. [error at 7]
  complex long foo(int)
  -------^
/home/marxin/Programming/texi2rst-generated/sphinx/demo/demo.rst:67: WARNING: Invalid C declaration: Expected identifier in nested name, got keyword: _Complex [error at 8]
  _Complex long foo(int)
  --------^
/home/marxin/Programming/texi2rst-generated/sphinx/demo/demo.rst:68: WARNING: Error in declarator or parameters
Invalid C declaration: Expecting "(" in parameters. [error at 11]
  long fract __satfractunssisq (unsigned int a)
  -----------^

Right now, there's some special casing for e.g. 'unsigned' type:

sphinx/sphinx/domains/c.py

Lines 2566 to 2585 in 6ac326e

elements = []
if self.skip_word_and_ws('signed'):
elements.append('signed')
elif self.skip_word_and_ws('unsigned'):
elements.append('unsigned')
while 1:
if self.skip_word_and_ws('short'):
elements.append('short')
elif self.skip_word_and_ws('long'):
elements.append('long')
else:
break
if self.skip_word_and_ws('char'):
elements.append('char')
elif self.skip_word_and_ws('int'):
elements.append('int')
elif self.skip_word_and_ws('double'):
elements.append('double')
elif self.skip_word_and_ws('__int64'):
elements.append('__int64')

One possible fix is adding the mentioned C extension handling for the following types:
https://gcc.gnu.org/onlinedocs/gcc/Fixed-Point.html
https://gcc.gnu.org/onlinedocs/gcc/Complex.html

or I can see a domain parser can become public via an API entry point:

sphinx/sphinx/domains/c.py

Lines 2128 to 2131 in 6ac326e

_simple_fundamental_types = (
'void', '_Bool', 'bool', 'char', 'int', 'float', 'double',
'__int64',
)

What do you think?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions