summaryrefslogtreecommitdiff
path: root/sphinx/domains/cpp.py
diff options
context:
space:
mode:
authorJakob Lykke Andersen <Jakob@caput.dk>2022-04-17 17:27:30 +0200
committerJakob Lykke Andersen <Jakob@caput.dk>2022-04-17 17:27:30 +0200
commit2ec069ba9c42cb9099602a543869fa7f07741077 (patch)
tree0d1bac200bab4219cf1ff6f74814f2358a519569 /sphinx/domains/cpp.py
parent991fe26fa5683bb76a925389024d375c6bb11dba (diff)
downloadsphinx-git-2ec069ba9c42cb9099602a543869fa7f07741077.tar.gz
C and C++, support attribtues on enumerators
Fixes sphinx-doc/sphinx#10341
Diffstat (limited to 'sphinx/domains/cpp.py')
-rw-r--r--sphinx/domains/cpp.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 26a2f2cd2..98a89594f 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -3462,9 +3462,11 @@ class ASTEnum(ASTBase):
class ASTEnumerator(ASTBase):
- def __init__(self, name: ASTNestedName, init: ASTInitializer) -> None:
+ def __init__(self, name: ASTNestedName, init: Optional[ASTInitializer],
+ attrs: ASTAttributeList) -> None:
self.name = name
self.init = init
+ self.attrs = attrs
def get_id(self, version: int, objectType: str, symbol: "Symbol") -> str:
if version == 1:
@@ -3474,6 +3476,9 @@ class ASTEnumerator(ASTBase):
def _stringify(self, transform: StringifyTransform) -> str:
res = []
res.append(transform(self.name))
+ if len(self.attrs) != 0:
+ res.append(' ')
+ res.append(transform(self.attrs))
if self.init:
res.append(transform(self.init))
return ''.join(res)
@@ -3482,6 +3487,9 @@ class ASTEnumerator(ASTBase):
env: "BuildEnvironment", symbol: "Symbol") -> None:
verify_description_mode(mode)
self.name.describe_signature(signode, mode, env, symbol)
+ if len(self.attrs) != 0:
+ signode += addnodes.desc_sig_space()
+ self.attrs.describe_signature(signode)
if self.init:
self.init.describe_signature(signode, 'markType', env, symbol)
@@ -6662,6 +6670,7 @@ class DefinitionParser(BaseParser):
def _parse_enumerator(self) -> ASTEnumerator:
name = self._parse_nested_name()
+ attrs = self._parse_attribute_list()
self.skip_ws()
init = None
if self.skip_string('='):
@@ -6671,7 +6680,7 @@ class DefinitionParser(BaseParser):
return self._parse_constant_expression(inTemplate=False)
initVal = self._parse_expression_fallback([], parser)
init = ASTInitializer(initVal)
- return ASTEnumerator(name, init)
+ return ASTEnumerator(name, init, attrs)
# ==========================================================================