Skip to content

Commit 62ed928

Browse files
committed
C, fix tag warnings for anon types
1 parent 56166fb commit 62ed928

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

sphinx/domains/c.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,18 +3787,39 @@ def _resolve_xref_inner(self, env: BuildEnvironment, fromdocname: str, builder:
37873787
# check if tags are used correctly
37883788
sName = s.get_full_nested_name()
37893789
assert len(name.names) <= len(sName.names)
3790-
for n, ns in zip(reversed(name.names), reversed(sName.names)):
3791-
if n.tag is None:
3790+
nextName = len(sName.names) - 1
3791+
# print("Matching '{}' to '{}'".format(name, sName))
3792+
for xRefName in reversed(name.names):
3793+
# find the next symbol name that matches the xref name
3794+
# potentially skipping anon names
3795+
# print("\tMatching:", xRefName)
3796+
stop = False
3797+
while True:
3798+
if nextName == -1:
3799+
stop = True
3800+
break
3801+
ns = sName.names[nextName]
3802+
nextName -= 1
3803+
if xRefName.identifier == ns.identifier:
3804+
# print("\t\tSame ident:", ns)
3805+
break
3806+
else:
3807+
# print("\t\tSkipping:", ns)
3808+
assert ns.is_anon()
3809+
if stop:
3810+
break
3811+
# print("\t\tRes(nextName={}): '{}' vs. '{}'".format(nextName, xRefName, ns))
3812+
if xRefName.tag is None:
37923813
continue
37933814
assert ns.tag is not None
3794-
assert (n.tag == '') == (ns.tag == '')
3795-
if n.tag != ns.tag:
3815+
assert (xRefName.tag == '') == (ns.tag == '')
3816+
if xRefName.tag != ns.tag:
37963817
logger.warning(
37973818
"C '%s' cross-reference uses wrong tag:"
37983819
" reference name is '%s' but found name is '%s'."
37993820
" Full reference name is '%s'."
38003821
" Full found name is '%s'.",
3801-
typ, n, ns, name, sName, location=node)
3822+
typ, xRefName, ns, name, sName, location=node)
38023823

38033824
# TODO: check role type vs. object type
38043825

tests/roots/test-domain-c/ids-vs-tags2.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
33
.. c:struct:: A
44
5-
.. c:union:: @data
5+
.. c:union:: @B
66
7-
.. c:member:: int a
7+
.. c:enum:: C
88
9-
- :c:member:`struct A.union @data.a`
10-
- :c:member:`A.a`
11-
- :c:member:`[email protected]`
12-
- :c:member:`A.a`
9+
.. c:enumerator:: D
10+
11+
- :c:enumerator:`struct A.union @B.enum C.D`
12+
- :c:enumerator:`A.union @B.enum C.D`
13+
- :c:enumerator:`struct [email protected] C.D`
14+
- :c:enumerator:`struct A.union @B.C.D`
15+
- :c:enumerator:`[email protected] C.D`
16+
- :c:enumerator:`A.union @B.C.D`
17+
- :c:enumerator:`struct [email protected]`
18+
- :c:enumerator:`[email protected]`
19+
- :c:enumerator:`struct A.enum C.D`
20+
- :c:enumerator:`A.enum C.D`
21+
- :c:enumerator:`struct A.C.D`
22+
- :c:enumerator:`A.C.D`

0 commit comments

Comments
 (0)