From dcbbc83ac7215101cea17bd858ff5b9b57ef82b7 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Wed, 18 Mar 2020 09:57:23 +0100 Subject: [PATCH] C++, fix minor space issues in declarators --- sphinx/domains/cpp.py | 20 ++++++++++---------- tests/test_domain_cpp.py | 24 +++++++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index df365b555..7f7558cb3 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -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) diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index d78ee9cfe..759ff8148 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -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 C()', {2: 'I0E1Cv'})