Skip to content

Commit

Permalink
C, fix object types for xrefs
Browse files Browse the repository at this point in the history
Add 'identifer' to all and 'type' to types.

Fixes sphinx-doc#8341
  • Loading branch information
jakobandersen committed Jan 11, 2021
1 parent b372a99 commit 750e6ec
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sphinx/domains/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -3657,15 +3657,18 @@ class CDomain(Domain):
name = 'c'
label = 'C'
object_types = {
'function': ObjType(_('function'), 'func'),
'member': ObjType(_('member'), 'member'),
'macro': ObjType(_('macro'), 'macro'),
'type': ObjType(_('type'), 'type'),
'var': ObjType(_('variable'), 'data'),
'enum': ObjType(_('enum'), 'enum'),
'enumerator': ObjType(_('enumerator'), 'enumerator'),
'struct': ObjType(_('struct'), 'struct'),
'union': ObjType(_('union'), 'union'),
# 'identifier' is the one used for xrefs generated in signatures, not in roles
'member': ObjType(_('member'), 'var', 'member', 'data', 'identifier'),
'var': ObjType(_('variable'), 'var', 'member', 'data', 'identifier'),
'function': ObjType(_('function'), 'func', 'identifier', 'type'),
'macro': ObjType(_('macro'), 'macro', 'identifier'),
'struct': ObjType(_('struct'), 'struct', 'identifier', 'type'),
'union': ObjType(_('union'), 'union', 'identifier', 'type'),
'enum': ObjType(_('enum'), 'enum', 'identifier', 'type'),
'enumerator': ObjType(_('enumerator'), 'enumerator', 'identifier'),
'type': ObjType(_('type'), 'identifier', 'type'),
# generated object types
'functionParam': ObjType(_('function parameter'), 'identifier', 'var', 'member', 'data'), # noqa
}

directives = {
Expand Down
4 changes: 4 additions & 0 deletions tests/roots/test-domain-c-intersphinx/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude_patterns = ['_build']
extensions = [
'sphinx.ext.intersphinx',
]
62 changes: 62 additions & 0 deletions tests/roots/test-domain-c-intersphinx/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. 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`
52 changes: 52 additions & 0 deletions tests/test_domain_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""

import zlib
from xml.etree import ElementTree

import pytest

from sphinx import addnodes
from sphinx.addnodes import desc
from sphinx.domains.c import DefinitionError, DefinitionParser, Symbol, _id_prefix, _max_id
from sphinx.ext.intersphinx import load_mappings, normalize_intersphinx_mapping
from sphinx.testing import restructuredtext
from sphinx.testing.util import assert_node

Expand Down Expand Up @@ -642,3 +645,52 @@ def test_noindexentry(app):
assert_node(doctree, (addnodes.index, desc, addnodes.index, desc))
assert_node(doctree[0], addnodes.index, entries=[('single', 'f (C function)', 'c.f', '', None)])
assert_node(doctree[2], addnodes.index, entries=[])


@pytest.mark.sphinx(testroot='domain-c-intersphinx', confoverrides={'nitpicky': True})
def test_intersphinx(tempdir, app, status, warning):
origSource = """\
.. c:member:: int _member
.. c:var:: int _var
.. c:function:: void _function()
.. c:macro:: _macro
.. c:struct:: _struct
.. c:union:: _union
.. c:enum:: _enum
.. c:enumerator:: _enumerator
.. c:type:: _type
.. c:function:: void _functionParam(int param)
""" # noqa
inv_file = tempdir / 'inventory'
inv_file.write_bytes(b'''\
# Sphinx inventory version 2
# Project: C Intersphinx Test
# Version:
# The remainder of this file is compressed using zlib.
''' + zlib.compress(b'''\
_enum c:enum 1 index.html#c.$ -
_enum._enumerator c:enumerator 1 index.html#c.$ -
_enumerator c:enumerator 1 index.html#c._enum.$ -
_function c:function 1 index.html#c.$ -
_functionParam c:function 1 index.html#c.$ -
_functionParam.param c:functionParam 1 index.html#c._functionParam -
_macro c:macro 1 index.html#c.$ -
_member c:member 1 index.html#c.$ -
_struct c:struct 1 index.html#c.$ -
_type c:type 1 index.html#c.$ -
_union c:union 1 index.html#c.$ -
_var c:member 1 index.html#c.$ -
''')) # noqa
app.config.intersphinx_mapping = {
'https://localhost/intersphinx/c/': inv_file,
}
app.config.intersphinx_cache_limit = 0
# load the inventory and check if it's done correctly
normalize_intersphinx_mapping(app, app.config)
load_mappings(app)

app.builder.build_all()
ws = filter_warnings(warning, "index")
assert len(ws) == 0

0 comments on commit 750e6ec

Please sign in to comment.