mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch 'c_array_declarator' into merge_c_array_declarator
This commit is contained in:
commit
b1e732fd8f
5
CHANGES
5
CHANGES
@ -81,9 +81,14 @@ Deprecated
|
|||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
* C, parse array declarators with static, qualifiers, and VLA specification.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #7516: autodoc: crashes if target object raises an error on accessing
|
||||||
|
its attributes
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -792,20 +792,60 @@ class ASTDeclSpecs(ASTBase):
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
class ASTArray(ASTBase):
|
class ASTArray(ASTBase):
|
||||||
def __init__(self, size: ASTExpression):
|
def __init__(self, static: bool, const: bool, volatile: bool, restrict: bool,
|
||||||
|
vla: bool, size: ASTExpression):
|
||||||
|
self.static = static
|
||||||
|
self.const = const
|
||||||
|
self.volatile = volatile
|
||||||
|
self.restrict = restrict
|
||||||
|
self.vla = vla
|
||||||
self.size = size
|
self.size = size
|
||||||
|
if vla:
|
||||||
|
assert size is None
|
||||||
|
if size is not None:
|
||||||
|
assert not vla
|
||||||
|
|
||||||
def _stringify(self, transform: StringifyTransform) -> str:
|
def _stringify(self, transform: StringifyTransform) -> str:
|
||||||
if self.size:
|
el = []
|
||||||
return '[' + transform(self.size) + ']'
|
if self.static:
|
||||||
else:
|
el.append('static')
|
||||||
return '[]'
|
if self.restrict:
|
||||||
|
el.append('restrict')
|
||||||
|
if self.volatile:
|
||||||
|
el.append('volatile')
|
||||||
|
if self.const:
|
||||||
|
el.append('const')
|
||||||
|
if self.vla:
|
||||||
|
return '[' + ' '.join(el) + '*]'
|
||||||
|
elif self.size:
|
||||||
|
el.append(transform(self.size))
|
||||||
|
return '[' + ' '.join(el) + ']'
|
||||||
|
|
||||||
def describe_signature(self, signode: TextElement, mode: str,
|
def describe_signature(self, signode: TextElement, mode: str,
|
||||||
env: "BuildEnvironment", symbol: "Symbol") -> None:
|
env: "BuildEnvironment", symbol: "Symbol") -> None:
|
||||||
verify_description_mode(mode)
|
verify_description_mode(mode)
|
||||||
signode.append(nodes.Text("["))
|
signode.append(nodes.Text("["))
|
||||||
if self.size:
|
addSpace = False
|
||||||
|
|
||||||
|
def _add(signode: TextElement, text: str) -> bool:
|
||||||
|
if addSpace:
|
||||||
|
signode += nodes.Text(' ')
|
||||||
|
signode += addnodes.desc_annotation(text, text)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self.static:
|
||||||
|
addSpace = _add(signode, 'static')
|
||||||
|
if self.restrict:
|
||||||
|
addSpace = _add(signode, 'restrict')
|
||||||
|
if self.volatile:
|
||||||
|
addSpace = _add(signode, 'volatile')
|
||||||
|
if self.const:
|
||||||
|
addSpace = _add(signode, 'const')
|
||||||
|
if self.vla:
|
||||||
|
signode.append(nodes.Text('*'))
|
||||||
|
elif self.size:
|
||||||
|
if addSpace:
|
||||||
|
signode += nodes.Text(' ')
|
||||||
self.size.describe_signature(signode, mode, env, symbol)
|
self.size.describe_signature(signode, mode, env, symbol)
|
||||||
signode.append(nodes.Text("]"))
|
signode.append(nodes.Text("]"))
|
||||||
|
|
||||||
@ -2595,18 +2635,45 @@ class DefinitionParser(BaseParser):
|
|||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
if typed and self.skip_string('['):
|
if typed and self.skip_string('['):
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
if self.skip_string(']'):
|
static = False
|
||||||
arrayOps.append(ASTArray(None))
|
const = False
|
||||||
continue
|
volatile = False
|
||||||
|
restrict = False
|
||||||
|
while True:
|
||||||
|
if not static:
|
||||||
|
if self.skip_word_and_ws('static'):
|
||||||
|
static = True
|
||||||
|
continue
|
||||||
|
if not const:
|
||||||
|
if self.skip_word_and_ws('const'):
|
||||||
|
const = True
|
||||||
|
continue
|
||||||
|
if not volatile:
|
||||||
|
if self.skip_word_and_ws('volatile'):
|
||||||
|
volatile = True
|
||||||
|
continue
|
||||||
|
if not restrict:
|
||||||
|
if self.skip_word_and_ws('restrict'):
|
||||||
|
restrict = True
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
vla = False if static else self.skip_string_and_ws('*')
|
||||||
|
if vla:
|
||||||
|
if not self.skip_string(']'):
|
||||||
|
self.fail("Expected ']' in end of array operator.")
|
||||||
|
size = None
|
||||||
|
else:
|
||||||
|
if self.skip_string(']'):
|
||||||
|
size = None
|
||||||
|
else:
|
||||||
|
|
||||||
def parser() -> ASTExpression:
|
def parser():
|
||||||
return self._parse_expression()
|
return self._parse_expression()
|
||||||
|
size = self._parse_expression_fallback([']'], parser)
|
||||||
value = self._parse_expression_fallback([']'], parser)
|
self.skip_ws()
|
||||||
if not self.skip_string(']'):
|
if not self.skip_string(']'):
|
||||||
self.fail("Expected ']' in end of array operator.")
|
self.fail("Expected ']' in end of array operator.")
|
||||||
arrayOps.append(ASTArray(value))
|
arrayOps.append(ASTArray(static, const, volatile, restrict, vla, size))
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
param = self._parse_parameters(paramMode)
|
param = self._parse_parameters(paramMode)
|
||||||
|
@ -582,9 +582,9 @@ class Documenter:
|
|||||||
isprivate = membername.startswith('_')
|
isprivate = membername.startswith('_')
|
||||||
|
|
||||||
keep = False
|
keep = False
|
||||||
if getattr(member, '__sphinx_mock__', False):
|
if safe_getattr(member, '__sphinx_mock__', False):
|
||||||
# mocked module or object
|
# mocked module or object
|
||||||
keep = False
|
pass
|
||||||
elif want_all and membername.startswith('__') and \
|
elif want_all and membername.startswith('__') and \
|
||||||
membername.endswith('__') and len(membername) > 4:
|
membername.endswith('__') and len(membername) > 4:
|
||||||
# special __methods__
|
# special __methods__
|
||||||
|
@ -362,6 +362,21 @@ def test_function_definitions():
|
|||||||
check('function', 'void f(enum E e)', {1: 'f'})
|
check('function', 'void f(enum E e)', {1: 'f'})
|
||||||
check('function', 'void f(union E e)', {1: 'f'})
|
check('function', 'void f(union E e)', {1: 'f'})
|
||||||
|
|
||||||
|
# array declarators
|
||||||
|
check('function', 'void f(int arr[])', {1: 'f'})
|
||||||
|
check('function', 'void f(int arr[*])', {1: 'f'})
|
||||||
|
cvrs = ['', 'const', 'volatile', 'restrict', 'restrict volatile const']
|
||||||
|
for cvr in cvrs:
|
||||||
|
space = ' ' if len(cvr) != 0 else ''
|
||||||
|
check('function', 'void f(int arr[{}*])'.format(cvr), {1: 'f'})
|
||||||
|
check('function', 'void f(int arr[{}])'.format(cvr), {1: 'f'})
|
||||||
|
check('function', 'void f(int arr[{}{}42])'.format(cvr, space), {1: 'f'})
|
||||||
|
check('function', 'void f(int arr[static{}{} 42])'.format(space, cvr), {1: 'f'})
|
||||||
|
check('function', 'void f(int arr[{}{}static 42])'.format(cvr, space), {1: 'f'},
|
||||||
|
output='void f(int arr[static{}{} 42])'.format(space, cvr))
|
||||||
|
check('function', 'void f(int arr[const static volatile 42])', {1: 'f'},
|
||||||
|
output='void f(int arr[static volatile const 42])')
|
||||||
|
|
||||||
|
|
||||||
def test_union_definitions():
|
def test_union_definitions():
|
||||||
check('struct', 'A', {1: 'A'})
|
check('struct', 'A', {1: 'A'})
|
||||||
|
Loading…
Reference in New Issue
Block a user