diff options
author | Jakob Lykke Andersen <jakobandersen@users.noreply.github.com> | 2021-03-14 12:45:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-14 12:45:12 +0300 |
commit | c89bda11d1bb758b557f1cffb593d002ec1e4131 (patch) | |
tree | d7e07438348c7d61917048739ca987dc5a1e1703 /sphinx/domains | |
parent | 17bb78997c7fc5f821d0e235188b637b8fe0fb88 (diff) | |
parent | dfc759e0392591de10f1ce064a89c7d52aa7aa85 (diff) |
Merge pull request #8999 from jakobandersen/c_cpp_render_fixes
C, C++ render fixes
Diffstat (limited to 'sphinx/domains')
-rw-r--r-- | sphinx/domains/c.py | 17 | ||||
-rw-r--r-- | sphinx/domains/cpp.py | 31 |
2 files changed, 34 insertions, 14 deletions
diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 0fecbad6d..0c5f41ba1 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -182,10 +182,19 @@ class ASTNestedName(ASTBase): verify_description_mode(mode) # just print the name part, with template args, not template params if mode == 'noneIsName': - signode += nodes.Text(str(self)) + if self.rooted: + signode += nodes.Text('.') + for i in range(len(self.names)): + if i != 0: + signode += nodes.Text('.') + n = self.names[i] + n.describe_signature(signode, mode, env, '', symbol) elif mode == 'param': - name = str(self) - signode += nodes.emphasis(name, name) + assert not self.rooted, str(self) + assert len(self.names) == 1 + node = nodes.emphasis() + self.names[0].describe_signature(node, 'noneIsName', env, '', symbol) + signode += node elif mode == 'markType' or mode == 'lastIsName' or mode == 'markName': # Each element should be a pending xref targeting the complete # prefix. @@ -869,7 +878,7 @@ class ASTArray(ASTBase): elif self.size: if addSpace: signode += nodes.Text(' ') - self.size.describe_signature(signode, mode, env, symbol) + self.size.describe_signature(signode, 'markType', env, symbol) signode.append(nodes.Text("]")) diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 3bd764de5..52b9ad23c 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -179,7 +179,6 @@ T = TypeVar('T') declarator -> ptr-declarator | noptr-declarator parameters-and-qualifiers trailing-return-type - (TODO: for now we don't support trailing-eturn-type) ptr-declarator -> noptr-declarator | ptr-operator ptr-declarator @@ -718,8 +717,7 @@ class ASTNestedName(ASTBase): res.append('') for i in range(len(self.names)): n = self.names[i] - t = self.templates[i] - if t: + if self.templates[i]: res.append("template " + transform(n)) else: res.append(transform(n)) @@ -730,10 +728,23 @@ class ASTNestedName(ASTBase): verify_description_mode(mode) # just print the name part, with template args, not template params if mode == 'noneIsName': - signode += nodes.Text(str(self)) + if self.rooted: + signode += nodes.Text('::') + for i in range(len(self.names)): + if i != 0: + signode += nodes.Text('::') + n = self.names[i] + if self.templates[i]: + signode += nodes.Text("template") + signode += nodes.Text(" ") + n.describe_signature(signode, mode, env, '', symbol) elif mode == 'param': - name = str(self) - signode += nodes.emphasis(name, name) + assert not self.rooted, str(self) + assert len(self.names) == 1 + assert not self.templates[0] + node = nodes.emphasis() + self.names[0].describe_signature(node, 'noneIsName', env, '', symbol) + signode += node elif mode == 'markType' or mode == 'lastIsName' or mode == 'markName': # Each element should be a pending xref targeting the complete # prefix. however, only the identifier part should be a link, such @@ -1250,7 +1261,7 @@ class ASTSizeofParamPack(ASTExpression): def describe_signature(self, signode: TextElement, mode: str, env: "BuildEnvironment", symbol: "Symbol") -> None: signode.append(nodes.Text('sizeof...(')) - self.identifier.describe_signature(signode, mode, env, + self.identifier.describe_signature(signode, 'markType', env, symbol=symbol, prefix="", templateArgs="") signode.append(nodes.Text(')')) @@ -2199,7 +2210,7 @@ class ASTArray(ASTBase): verify_description_mode(mode) signode.append(nodes.Text("[")) if self.size: - self.size.describe_signature(signode, mode, env, symbol) + self.size.describe_signature(signode, 'markType', env, symbol) signode.append(nodes.Text("]")) @@ -2667,7 +2678,7 @@ class ASTDeclaratorMemPtr(ASTDeclarator): def describe_signature(self, signode: TextElement, mode: str, env: "BuildEnvironment", symbol: "Symbol") -> None: verify_description_mode(mode) - self.className.describe_signature(signode, mode, env, symbol) + self.className.describe_signature(signode, 'markType', env, symbol) signode += nodes.Text('::*') def _add_anno(signode: TextElement, text: str) -> None: @@ -6171,7 +6182,7 @@ class DefinitionParser(BaseParser): typed=typed) else: paramMode = 'type' - if outer == 'member': # i.e., member + if outer == 'member': named = True elif outer == 'operatorCast': paramMode = 'operatorCast' |