Skip to content

C, distinguish between tag names and ordinary names #8313

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Bugs fixed
with size explicitly set in pixels) (fixed for ``'pdflatex'/'lualatex'`` only)
* #8911: C++: remove the longest matching prefix in
:confval:`cpp_index_common_prefix` instead of the first that matches.
* C, properly reject function declarations when a keyword is used
as parameter name.

Testing
--------
Expand Down
276 changes: 167 additions & 109 deletions sphinx/domains/c.py

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/roots/test-domain-c-intersphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@
- :c:member:`_functionParam.param`
- :c:var:`_functionParam.param`
- :c:data:`_functionParam.param`

- :any:`[email protected]`
- :c:member:`[email protected]`
- :c:var:`[email protected]`
- :c:data:`[email protected]`
- :any:`_struct.i`
- :c:member:`_struct.i`
- :c:var:`_struct.i`
- :c:data:`_struct.i`
2 changes: 2 additions & 0 deletions tests/roots/test-domain-c/anon-dup-decl.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. c:namespace:: anon_dup_decl_ns

.. c:struct:: anon_dup_decl

.. c:struct:: @a.A
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-domain-c/function_param_target.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. c:namespace:: function_param_target

.. c:function:: void f(int i)

- :c:var:`i`
Expand Down
90 changes: 90 additions & 0 deletions tests/roots/test-domain-c/ids-vs-tags0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.. c:member:: int _member
.. c:var:: int _var
.. c:function:: void _function()
.. c:macro:: _macro
.. c:struct:: _struct

.. c:union:: @anon

.. c:var:: int i

.. c:union:: _union
.. c:enum:: _enum

.. c:enumerator:: _enumerator

.. c:type:: _type
.. c:function:: void _functionParam(int param)


.. c:member:: void __member = _member

- :any:`_member`
- :c:member:`_member`
- :c:var:`_member`
- :c:data:`_member`

.. c:member:: void __var = _var

- :any:`_var`
- :c:member:`_var`
- :c:var:`_var`
- :c:data:`_var`

.. c:member:: void __function = _function

- :any:`_function`
- :c:func:`_function`
- :c:type:`_function`

.. c:member:: void __macro = _macro

- :any:`_macro`
- :c:macro:`_macro`

.. c:type:: _struct __struct
struct _struct __structTagged

- :any:`_struct`
- :c:struct:`_struct`
- :c:type:`_struct`

.. c:type:: _union __union
union _union __unionTagged

- :any:`_union`
- :c:union:`_union`
- :c:type:`_union`

.. c:type:: _enum __enum
enum _enum __enumTagged

- :any:`_enum`
- :c:enum:`_enum`
- :c:type:`_enum`

.. c:member:: void __enumerator = _enumerator

- :any:`_enumerator`
- :c:enumerator:`_enumerator`

.. c:type:: _type __type

- :any:`_type`
- :c:type:`_type`

.. c:member:: void __functionParam = _functionParam.param

- :any:`_functionParam.param`
- :c:member:`_functionParam.param`
- :c:var:`_functionParam.param`
- :c:data:`_functionParam.param`

- :any:`[email protected]`
- :c:member:`[email protected]`
- :c:var:`[email protected]`
- :c:data:`[email protected]`
- :any:`_struct.i`
- :c:member:`_struct.i`
- :c:var:`_struct.i`
- :c:data:`_struct.i`
27 changes: 27 additions & 0 deletions tests/roots/test-domain-c/ids-vs-tags1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. c:namespace:: ids_vs_tags

.. c:struct:: f_struct
.. c:type:: struct f_struct f_struct
.. c:union:: f_union
.. c:type:: union f_union f_union
.. c:enum:: f_enum
.. c:type:: enum f_enum f_enum

- :c:struct:`f_struct`
- :c:struct:`struct f_struct`
- :c:type:`f_struct`
- :c:type:`struct f_struct`
- :any:`f_struct`
- :any:`struct f_struct`
- :c:union:`f_union`
- :c:union:`union f_union`
- :c:type:`f_union`
- :c:type:`union f_union`
- :any:`f_union`
- :any:`union f_union`
- :c:enum:`f_enum`
- :c:enum:`enum f_enum`
- :c:type:`f_enum`
- :c:type:`enum f_enum`
- :any:`f_enum`
- :any:`enum f_enum`
22 changes: 22 additions & 0 deletions tests/roots/test-domain-c/ids-vs-tags2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. c:namespace:: ids_vs_tags2

.. c:struct:: A

.. c:union:: @B

.. c:enum:: C

.. c:enumerator:: D

- :c:enumerator:`struct A.union @B.enum C.D`
- :c:enumerator:`A.union @B.enum C.D`
- :c:enumerator:`struct [email protected] C.D`
- :c:enumerator:`struct A.union @B.C.D`
- :c:enumerator:`[email protected] C.D`
- :c:enumerator:`A.union @B.C.D`
- :c:enumerator:`struct [email protected]`
- :c:enumerator:`[email protected]`
- :c:enumerator:`struct A.enum C.D`
- :c:enumerator:`A.enum C.D`
- :c:enumerator:`struct A.C.D`
- :c:enumerator:`A.C.D`
19 changes: 19 additions & 0 deletions tests/roots/test-domain-c/ids-vs-tags3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. c:namespace:: ids_vs_tags3

.. c:function:: void f1(int i)

.. c:struct:: f1

.. c:var:: int i


.. c:struct:: f2

.. c:var:: int i

.. c:function:: void f2(int i)

- :c:var:`f1.i`, resolves to the function parameter
- :c:var:`struct f1.i`, resolves to struct f1.i
- :c:var:`f2.i`, resolves to the function parameter
- :c:var:`struct f2.i`, resolves to struct f2.i
6 changes: 4 additions & 2 deletions tests/roots/test-domain-c/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. c:namespace:: index

test-domain-c
=============

Expand All @@ -8,7 +10,7 @@ directives

:rtype: int

.. c:function:: MyStruct hello2(char *name)
.. c:function:: struct MyStruct hello2(char *name)

:rtype: MyStruct

Expand Down Expand Up @@ -46,7 +48,7 @@ directives
- :c:expr:`unsigned int`
- :c:texpr:`unsigned int`

.. c:var:: A a
.. c:var:: struct A a

- :c:expr:`a->b`
- :c:texpr:`a->b`
10 changes: 0 additions & 10 deletions tests/roots/test-domain-c/semicolon.rst

This file was deleted.

14 changes: 14 additions & 0 deletions tests/roots/test-domain-c/wrong-tags.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. c:namespace:: wrong_tag

.. c:struct:: A

.. c:var:: int i

- :c:var:`A.i`
- :c:var:`union A.i`
- :c:var:`enum A.i`

.. c:function:: void f1(union A a)
.. c:function:: void f2(enum A a)

.. c:var:: int union A.j
10 changes: 5 additions & 5 deletions tests/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ def test_html4_output(app, status, warning):
(".//a[@class='reference internal'][@href='#errmod.Error']/strong", 'Error'),
# C references
(".//span[@class='pre']", 'CFunction()'),
(".//a[@href='#c.Sphinx_DoSomething']", ''),
(".//a[@href='#c.SphinxStruct.member']", ''),
(".//a[@href='#c.SPHINX_USE_PYTHON']", ''),
(".//a[@href='#c.SphinxType']", ''),
(".//a[@href='#c.sphinx_global']", ''),
(".//a[@href='#C2-Sphinx_DoSomething']", ''),
(".//a[@href='#C2-SphinxStruct.member']", ''),
(".//a[@href='#C2-SPHINX_USE_PYTHON']", ''),
(".//a[@href='#C2-SphinxType']", ''),
(".//a[@href='#C2-sphinx_global']", ''),
# test global TOC created by toctree()
(".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='#']",
'Testing object descriptions'),
Expand Down
Loading