mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C++, fix minor space issues in declarators
This commit is contained in:
parent
f6cb7f1a43
commit
dcbbc83ac7
@ -2288,8 +2288,7 @@ class ASTDeclaratorPtr(ASTDeclarator):
|
||||
return self.next.function_params
|
||||
|
||||
def require_space_after_declSpecs(self) -> bool:
|
||||
# TODO: if has paramPack, then False ?
|
||||
return True
|
||||
return self.next.require_space_after_declSpecs()
|
||||
|
||||
def _stringify(self, transform: StringifyTransform) -> str:
|
||||
res = ['*']
|
||||
@ -2304,7 +2303,7 @@ class ASTDeclaratorPtr(ASTDeclarator):
|
||||
res.append(' ')
|
||||
res.append('const')
|
||||
if self.const or self.volatile or len(self.attrs) > 0:
|
||||
if self.next.require_space_after_declSpecs:
|
||||
if self.next.require_space_after_declSpecs():
|
||||
res.append(' ')
|
||||
res.append(transform(self.next))
|
||||
return ''.join(res)
|
||||
@ -2364,7 +2363,7 @@ class ASTDeclaratorPtr(ASTDeclarator):
|
||||
signode += nodes.Text(' ')
|
||||
_add_anno(signode, 'const')
|
||||
if self.const or self.volatile or len(self.attrs) > 0:
|
||||
if self.next.require_space_after_declSpecs:
|
||||
if self.next.require_space_after_declSpecs():
|
||||
signode += nodes.Text(' ')
|
||||
self.next.describe_signature(signode, mode, env, symbol)
|
||||
|
||||
@ -2394,7 +2393,7 @@ class ASTDeclaratorRef(ASTDeclarator):
|
||||
res = ['&']
|
||||
for a in self.attrs:
|
||||
res.append(transform(a))
|
||||
if len(self.attrs) > 0 and self.next.require_space_after_declSpecs:
|
||||
if len(self.attrs) > 0 and self.next.require_space_after_declSpecs():
|
||||
res.append(' ')
|
||||
res.append(transform(self.next))
|
||||
return ''.join(res)
|
||||
@ -2425,7 +2424,7 @@ class ASTDeclaratorRef(ASTDeclarator):
|
||||
signode += nodes.Text("&")
|
||||
for a in self.attrs:
|
||||
a.describe_signature(signode)
|
||||
if len(self.attrs) > 0 and self.next.require_space_after_declSpecs:
|
||||
if len(self.attrs) > 0 and self.next.require_space_after_declSpecs():
|
||||
signode += nodes.Text(' ')
|
||||
self.next.describe_signature(signode, mode, env, symbol)
|
||||
|
||||
@ -2507,9 +2506,11 @@ class ASTDeclaratorMemPtr(ASTDeclarator):
|
||||
res.append(transform(self.className))
|
||||
res.append('::*')
|
||||
if self.volatile:
|
||||
res.append(' volatile')
|
||||
res.append('volatile')
|
||||
if self.const:
|
||||
res.append(' const')
|
||||
if self.volatile:
|
||||
res.append(' ')
|
||||
res.append('const')
|
||||
if self.next.require_space_after_declSpecs():
|
||||
res.append(' ')
|
||||
res.append(transform(self.next))
|
||||
@ -2565,8 +2566,7 @@ class ASTDeclaratorMemPtr(ASTDeclarator):
|
||||
signode += nodes.Text(' ')
|
||||
_add_anno(signode, 'const')
|
||||
if self.next.require_space_after_declSpecs():
|
||||
if self.volatile or self.const:
|
||||
signode += nodes.Text(' ')
|
||||
signode += nodes.Text(' ')
|
||||
self.next.describe_signature(signode, mode, env, symbol)
|
||||
|
||||
|
||||
|
@ -461,6 +461,13 @@ def test_function_definitions():
|
||||
with pytest.raises(DefinitionError):
|
||||
parse('function', 'int foo(D d=x(a')
|
||||
check('function', 'int foo(const A&... a)', {1: "foo__ACRDp", 2: "3fooDpRK1A"})
|
||||
check('function', 'int foo(const A&...)', {1: "foo__ACRDp", 2: "3fooDpRK1A"})
|
||||
check('function', 'int foo(const A*... a)', {1: "foo__ACPDp", 2: "3fooDpPK1A"})
|
||||
check('function', 'int foo(const A*...)', {1: "foo__ACPDp", 2: "3fooDpPK1A"})
|
||||
check('function', 'int foo(const int A::*... a)', {2: "3fooDpM1AKi"})
|
||||
check('function', 'int foo(const int A::*...)', {2: "3fooDpM1AKi"})
|
||||
#check('function', 'int foo(int (*a)(A)...)', {1: "foo__ACRDp", 2: "3fooDpPK1A"})
|
||||
#check('function', 'int foo(int (*)(A)...)', {1: "foo__ACRDp", 2: "3fooDpPK1A"})
|
||||
check('function', 'virtual void f()', {1: "f", 2: "1fv"})
|
||||
# test for ::nestedName, from issue 1738
|
||||
check("function", "result(int val, ::std::error_category const &cat)",
|
||||
@ -502,18 +509,21 @@ def test_function_definitions():
|
||||
check('function', 'void f(int C::*)', {2: '1fM1Ci'})
|
||||
check('function', 'void f(int C::* p)', {2: '1fM1Ci'})
|
||||
check('function', 'void f(int ::C::* p)', {2: '1fM1Ci'})
|
||||
check('function', 'void f(int C::* const)', {2: '1fKM1Ci'})
|
||||
check('function', 'void f(int C::* const&)', {2: '1fRKM1Ci'})
|
||||
check('function', 'void f(int C::* volatile)', {2: '1fVM1Ci'})
|
||||
check('function', 'void f(int C::* const volatile)', {2: '1fVKM1Ci'},
|
||||
output='void f(int C::* volatile const)')
|
||||
check('function', 'void f(int C::* volatile const)', {2: '1fVKM1Ci'})
|
||||
check('function', 'void f(int C::*const)', {2: '1fKM1Ci'})
|
||||
check('function', 'void f(int C::*const&)', {2: '1fRKM1Ci'})
|
||||
check('function', 'void f(int C::*volatile)', {2: '1fVM1Ci'})
|
||||
check('function', 'void f(int C::*const volatile)', {2: '1fVKM1Ci'},
|
||||
output='void f(int C::*volatile const)')
|
||||
check('function', 'void f(int C::*volatile const)', {2: '1fVKM1Ci'})
|
||||
check('function', 'void f(int (C::*)(float, double))', {2: '1fM1CFifdE'})
|
||||
check('function', 'void f(int (C::* p)(float, double))', {2: '1fM1CFifdE'})
|
||||
check('function', 'void f(int (::C::* p)(float, double))', {2: '1fM1CFifdE'})
|
||||
check('function', 'void f(void (C::*)() const &)', {2: '1fM1CKRFvvE'})
|
||||
check('function', 'int C::* f(int, double)', {2: '1fid'})
|
||||
check('function', 'void f(int C::* *)', {2: '1fPM1Ci'})
|
||||
check('function', 'void f(int C::* *p)', {2: '1fPM1Ci'})
|
||||
check('function', 'void f(int C::**)', {2: '1fPM1Ci'})
|
||||
check('function', 'void f(int C::*const *p)', {2: '1fPKM1Ci'})
|
||||
check('function', 'void f(int C::*const*)', {2: '1fPKM1Ci'})
|
||||
|
||||
# exceptions from return type mangling
|
||||
check('function', 'template<typename T> C()', {2: 'I0E1Cv'})
|
||||
|
Loading…
Reference in New Issue
Block a user