Skip to content

Commit 6fb8d1c

Browse files
authored
Merge branch '4.x' into 9524_SphinxTestApp_outdir
2 parents a4b540f + a4a0b97 commit 6fb8d1c

File tree

138 files changed

+4360
-4169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+4360
-4169
lines changed

CHANGES

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Features added
2020
* #9445: py domain: ``:py:property:`` directive supports ``:classmethod:``
2121
option to describe the class property
2222
* #9524: test: SphinxTestApp can take ``builddir`` as an argument
23+
* #9535: C and C++, support more fundamental types, including GNU extensions.
2324

2425
Bugs fixed
2526
----------
@@ -31,10 +32,16 @@ Bugs fixed
3132
* #9522: autodoc: PEP 585 style typehints having arguments (ex. ``list[int]``)
3233
are not displayed well
3334
* #9481: autosummary: some warnings contain non-existing filenames
35+
* #9568: autosummary: summarise overlined sectioned headings correctly
3436
* #9481: c domain: some warnings contain non-existing filenames
3537
* #9481: cpp domain: some warnings contain non-existing filenames
3638
* #9456: html search: abbreation marks are inserted to the search result if
3739
failed to fetch the content of the page
40+
* #9267: html theme: CSS and JS files added by theme were loaded twice
41+
* #9535 comment: C++, fix parsing of defaulted function parameters that are
42+
function pointers.
43+
* #9564: smartquotes: don't adjust typography for text with
44+
language-highlighted ``:code:`` role.
3845

3946
Testing
4047
--------
@@ -59,8 +66,8 @@ Bugs fixed
5966

6067
* #9504: autodoc: generate incorrect reference to the parent class if the target
6168
class inherites the class having ``_name`` attribute
62-
* #9537: autodoc: Some objects under ``typing`` module are not displayed well
63-
with the HEAD of 3.10
69+
* #9537, #9589: autodoc: Some objects under ``typing`` module are not displayed
70+
well with the HEAD of 3.10
6471
* #9512: sphinx-build: crashed with the HEAD of Python 3.10
6572

6673
Testing

doc/usage/configuration.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,11 @@ that use Sphinx's HTMLWriter class.
13091309

13101310
.. confval:: html_use_opensearch
13111311

1312-
If nonempty, an `OpenSearch <https://www.opensearch.org/>`_ description
1313-
file will be output, and all pages will contain a ``<link>`` tag referring
1314-
to it. Since OpenSearch doesn't support relative URLs for its search page
1315-
location, the value of this option must be the base URL from which these
1316-
documents are served (without trailing slash), e.g.
1312+
If nonempty, an `OpenSearch <https://github.com/dewitt/opensearch>`_
1313+
description file will be output, and all pages will contain a ``<link>``
1314+
tag referring to it. Since OpenSearch doesn't support relative URLs for
1315+
its search page location, the value of this option must be the base URL
1316+
from which these documents are served (without trailing slash), e.g.
13171317
``"https://docs.python.org"``. The default is ``''``.
13181318

13191319
.. confval:: html_file_suffix

sphinx/builders/html/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,14 @@ def init_highlighter(self) -> None:
287287

288288
if dark_style is not None:
289289
self.dark_highlighter = PygmentsBridge('html', dark_style)
290-
self.add_css_file('pygments_dark.css',
291-
media='(prefers-color-scheme: dark)',
292-
id='pygments_dark_css')
290+
self.app.add_css_file('pygments_dark.css',
291+
media='(prefers-color-scheme: dark)',
292+
id='pygments_dark_css')
293293
else:
294294
self.dark_highlighter = None
295295

296296
def init_css_files(self) -> None:
297+
self.css_files = []
297298
self.add_css_file('pygments.css', priority=200)
298299
self.add_css_file(self._get_style_filename(), priority=200)
299300

@@ -311,6 +312,7 @@ def add_css_file(self, filename: str, **kwargs: Any) -> None:
311312
self.css_files.append(Stylesheet(filename, **kwargs))
312313

313314
def init_js_files(self) -> None:
315+
self.script_files = []
314316
self.add_js_file('documentation_options.js', id="documentation_options",
315317
data_url_root='', priority=200)
316318
self.add_js_file('jquery.js', priority=200)

sphinx/domains/c.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@
9292
_string_re = re.compile(r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'"
9393
r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S)
9494

95+
_simple_type_sepcifiers_re = re.compile(r"""(?x)
96+
\b(
97+
void|_Bool|bool
98+
# Integer
99+
# -------
100+
|((signed|unsigned)\s+)?(char|(
101+
((long\s+long|long|short)\s+)?int
102+
))
103+
|__uint128|__int128
104+
# extensions
105+
|((signed|unsigned)\s+)?__int(8|16|32|64|128)
106+
# Floating-point
107+
# --------------
108+
|(float|double|long\s+double)(\s+(_Complex|complex|_Imaginary|imaginary))?
109+
|(_Complex|complex|_Imaginary|imaginary)\s+(float|double|long\s+double)
110+
|_Decimal(32|64|128)
111+
# extensions
112+
|__float80|_Float64x|__float128|_Float128|__ibm128
113+
|__fp16
114+
# Fixed-point, extension
115+
|(_Sat\s+)?((signed|unsigned)\s+)?((short|long|long\s+long)\s+)?(_Fract|fract|_Accum|accum)
116+
# Integer types that could be prefixes of the previous ones
117+
# ---------------------------------------------------------
118+
|((signed|unsigned)\s+)?(long\s+long|long|short)
119+
|signed|unsigned
120+
)\b
121+
""")
122+
95123

96124
class _DuplicateSymbolError(Exception):
97125
def __init__(self, symbol: "Symbol", declaration: "ASTDeclaration") -> None:
@@ -609,14 +637,20 @@ class ASTTrailingTypeSpec(ASTBase):
609637

610638
class ASTTrailingTypeSpecFundamental(ASTTrailingTypeSpec):
611639
def __init__(self, name: str) -> None:
612-
self.name = name
640+
self.names = name.split()
613641

614642
def _stringify(self, transform: StringifyTransform) -> str:
615-
return self.name
643+
return ' '.join(self.names)
616644

617645
def describe_signature(self, signode: TextElement, mode: str,
618646
env: "BuildEnvironment", symbol: "Symbol") -> None:
619-
signode += addnodes.desc_sig_keyword_type(self.name, self.name)
647+
first = True
648+
for n in self.names:
649+
if not first:
650+
signode += addnodes.desc_sig_space()
651+
else:
652+
first = False
653+
signode += addnodes.desc_sig_keyword_type(n, n)
620654

621655

622656
class ASTTrailingTypeSpecName(ASTTrailingTypeSpec):
@@ -2123,15 +2157,6 @@ def dump(self, indent: int) -> str:
21232157

21242158

21252159
class DefinitionParser(BaseParser):
2126-
# those without signedness and size modifiers
2127-
# see https://en.cppreference.com/w/cpp/language/types
2128-
_simple_fundamental_types = (
2129-
'void', '_Bool', 'bool', 'char', 'int', 'float', 'double',
2130-
'__int64',
2131-
)
2132-
2133-
_prefix_keys = ('struct', 'enum', 'union')
2134-
21352160
@property
21362161
def language(self) -> str:
21372162
return 'C'
@@ -2556,40 +2581,16 @@ def _parse_nested_name(self) -> ASTNestedName:
25562581
return ASTNestedName(names, rooted)
25572582

25582583
def _parse_trailing_type_spec(self) -> ASTTrailingTypeSpec:
2559-
# fundamental types
2584+
# fundamental types, https://en.cppreference.com/w/c/language/type
2585+
# and extensions
25602586
self.skip_ws()
2561-
for t in self._simple_fundamental_types:
2562-
if self.skip_word(t):
2563-
return ASTTrailingTypeSpecFundamental(t)
2564-
2565-
# TODO: this could/should be more strict
2566-
elements = []
2567-
if self.skip_word_and_ws('signed'):
2568-
elements.append('signed')
2569-
elif self.skip_word_and_ws('unsigned'):
2570-
elements.append('unsigned')
2571-
while 1:
2572-
if self.skip_word_and_ws('short'):
2573-
elements.append('short')
2574-
elif self.skip_word_and_ws('long'):
2575-
elements.append('long')
2576-
else:
2577-
break
2578-
if self.skip_word_and_ws('char'):
2579-
elements.append('char')
2580-
elif self.skip_word_and_ws('int'):
2581-
elements.append('int')
2582-
elif self.skip_word_and_ws('double'):
2583-
elements.append('double')
2584-
elif self.skip_word_and_ws('__int64'):
2585-
elements.append('__int64')
2586-
if len(elements) > 0:
2587-
return ASTTrailingTypeSpecFundamental(' '.join(elements))
2587+
if self.match(_simple_type_sepcifiers_re):
2588+
return ASTTrailingTypeSpecFundamental(self.matched_text)
25882589

25892590
# prefixed
25902591
prefix = None
25912592
self.skip_ws()
2592-
for k in self._prefix_keys:
2593+
for k in ('struct', 'enum', 'union'):
25932594
if self.skip_word_and_ws(k):
25942595
prefix = k
25952596
break

sphinx/domains/cpp.py

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,31 @@
334334
'while', 'xor', 'xor_eq'
335335
]
336336

337+
338+
_simple_type_sepcifiers_re = re.compile(r"""(?x)
339+
\b(
340+
auto|void|bool
341+
# Integer
342+
# -------
343+
|((signed|unsigned)\s+)?(char|__int128|(
344+
((long\s+long|long|short)\s+)?int
345+
))
346+
|wchar_t|char(8|16|32)_t
347+
# extensions
348+
|((signed|unsigned)\s+)?__int(64|128)
349+
# Floating-point
350+
# --------------
351+
|(float|double|long\s+double)(\s+(_Complex|_Imaginary))?
352+
|(_Complex|_Imaginary)\s+(float|double|long\s+double)
353+
# extensions
354+
|__float80|_Float64x|__float128|_Float128
355+
# Integer types that could be prefixes of the previous ones
356+
# ---------------------------------------------------------
357+
|((signed|unsigned)\s+)?(long\s+long|long|short)
358+
|signed|unsigned
359+
)\b
360+
""")
361+
337362
_max_id = 4
338363
_id_prefix = [None, '', '_CPPv2', '_CPPv3', '_CPPv4']
339364
# Ids are used in lookup keys which are used across pickled files,
@@ -449,11 +474,23 @@
449474
'long long int': 'x',
450475
'signed long long': 'x',
451476
'signed long long int': 'x',
477+
'__int64': 'x',
452478
'unsigned long long': 'y',
453479
'unsigned long long int': 'y',
480+
'__int128': 'n',
481+
'signed __int128': 'n',
482+
'unsigned __int128': 'o',
454483
'float': 'f',
455484
'double': 'd',
456485
'long double': 'e',
486+
'__float80': 'e', '_Float64x': 'e',
487+
'__float128': 'g', '_Float128': 'g',
488+
'float _Complex': 'Cf', '_Complex float': 'Cf',
489+
'double _Complex': 'Cd', '_Complex double': 'Cd',
490+
'long double _Complex': 'Ce', '_Complex long double': 'Ce',
491+
'float _Imaginary': 'f', '_Imaginary float': 'f',
492+
'double _Imaginary': 'd', '_Imaginary double': 'd',
493+
'long double _Imaginary': 'e', '_Imaginary long double': 'e',
457494
'auto': 'Da',
458495
'decltype(auto)': 'Dc',
459496
'std::nullptr_t': 'Dn'
@@ -1817,31 +1854,38 @@ def describe_signature(self, signode: TextElement, mode: str,
18171854

18181855
class ASTTrailingTypeSpecFundamental(ASTTrailingTypeSpec):
18191856
def __init__(self, name: str) -> None:
1820-
self.name = name
1857+
self.names = name.split()
18211858

18221859
def _stringify(self, transform: StringifyTransform) -> str:
1823-
return self.name
1860+
return ' '.join(self.names)
18241861

18251862
def get_id(self, version: int) -> str:
18261863
if version == 1:
18271864
res = []
1828-
for a in self.name.split(' '):
1865+
for a in self.names:
18291866
if a in _id_fundamental_v1:
18301867
res.append(_id_fundamental_v1[a])
18311868
else:
18321869
res.append(a)
18331870
return '-'.join(res)
18341871

1835-
if self.name not in _id_fundamental_v2:
1872+
txt = str(self)
1873+
if txt not in _id_fundamental_v2:
18361874
raise Exception(
18371875
'Semi-internal error: Fundamental type "%s" can not be mapped '
1838-
'to an id. Is it a true fundamental type? If not so, the '
1839-
'parser should have rejected it.' % self.name)
1840-
return _id_fundamental_v2[self.name]
1876+
'to an ID. Is it a true fundamental type? If not so, the '
1877+
'parser should have rejected it.' % txt)
1878+
return _id_fundamental_v2[txt]
18411879

18421880
def describe_signature(self, signode: TextElement, mode: str,
18431881
env: "BuildEnvironment", symbol: "Symbol") -> None:
1844-
signode += addnodes.desc_sig_keyword_type(self.name, self.name)
1882+
first = True
1883+
for n in self.names:
1884+
if not first:
1885+
signode += addnodes.desc_sig_space()
1886+
else:
1887+
first = False
1888+
signode += addnodes.desc_sig_keyword_type(n, n)
18451889

18461890

18471891
class ASTTrailingTypeSpecDecltypeAuto(ASTTrailingTypeSpec):
@@ -4996,15 +5040,6 @@ def dump(self, indent: int) -> str:
49965040

49975041

49985042
class DefinitionParser(BaseParser):
4999-
# those without signedness and size modifiers
5000-
# see https://en.cppreference.com/w/cpp/language/types
5001-
_simple_fundemental_types = (
5002-
'void', 'bool', 'char', 'wchar_t', 'char8_t', 'char16_t', 'char32_t',
5003-
'int', 'float', 'double', 'auto'
5004-
)
5005-
5006-
_prefix_keys = ('class', 'struct', 'enum', 'union', 'typename')
5007-
50085043
@property
50095044
def language(self) -> str:
50105045
return 'C++'
@@ -5821,33 +5856,11 @@ def _parse_nested_name(self, memberPointer: bool = False) -> ASTNestedName:
58215856
# ==========================================================================
58225857

58235858
def _parse_trailing_type_spec(self) -> ASTTrailingTypeSpec:
5824-
# fundemental types
5859+
# fundamental types, https://en.cppreference.com/w/cpp/language/type
5860+
# and extensions
58255861
self.skip_ws()
5826-
for t in self._simple_fundemental_types:
5827-
if self.skip_word(t):
5828-
return ASTTrailingTypeSpecFundamental(t)
5829-
5830-
# TODO: this could/should be more strict
5831-
elements = []
5832-
if self.skip_word_and_ws('signed'):
5833-
elements.append('signed')
5834-
elif self.skip_word_and_ws('unsigned'):
5835-
elements.append('unsigned')
5836-
while 1:
5837-
if self.skip_word_and_ws('short'):
5838-
elements.append('short')
5839-
elif self.skip_word_and_ws('long'):
5840-
elements.append('long')
5841-
else:
5842-
break
5843-
if self.skip_word_and_ws('char'):
5844-
elements.append('char')
5845-
elif self.skip_word_and_ws('int'):
5846-
elements.append('int')
5847-
elif self.skip_word_and_ws('double'):
5848-
elements.append('double')
5849-
if len(elements) > 0:
5850-
return ASTTrailingTypeSpecFundamental(' '.join(elements))
5862+
if self.match(_simple_type_sepcifiers_re):
5863+
return ASTTrailingTypeSpecFundamental(self.matched_text)
58515864

58525865
# decltype
58535866
self.skip_ws()
@@ -5867,7 +5880,7 @@ def _parse_trailing_type_spec(self) -> ASTTrailingTypeSpec:
58675880
# prefixed
58685881
prefix = None
58695882
self.skip_ws()
5870-
for k in self._prefix_keys:
5883+
for k in ('class', 'struct', 'enum', 'union', 'typename'):
58715884
if self.skip_word_and_ws(k):
58725885
prefix = k
58735886
break
@@ -5923,13 +5936,6 @@ def _parse_parameters_and_qualifiers(self, paramMode: str) -> ASTParametersQuali
59235936
'Expecting "," or ")" in parameters-and-qualifiers, '
59245937
'got "%s".' % self.current_char)
59255938

5926-
# TODO: why did we have this bail-out?
5927-
# does it hurt to parse the extra stuff?
5928-
# it's needed for pointer to member functions
5929-
if paramMode != 'function' and False:
5930-
return ASTParametersQualifiers(
5931-
args, None, None, None, None, None, None, None)
5932-
59335939
self.skip_ws()
59345940
const = self.skip_word_and_ws('const')
59355941
volatile = self.skip_word_and_ws('volatile')
@@ -5976,7 +5982,8 @@ def _parse_parameters_and_qualifiers(self, paramMode: str) -> ASTParametersQuali
59765982

59775983
self.skip_ws()
59785984
initializer = None
5979-
if self.skip_string('='):
5985+
# if this is a function pointer we should not swallow an initializer
5986+
if paramMode == 'function' and self.skip_string('='):
59805987
self.skip_ws()
59815988
valid = ('0', 'delete', 'default')
59825989
for w in valid:

0 commit comments

Comments
 (0)