Retain doxygen comments for using declarations and type aliases
This commit is contained in:
parent
f1708bf9b8
commit
73a81d3107
@ -992,7 +992,9 @@ class CxxParser:
|
|||||||
|
|
||||||
self.visitor.on_using_namespace(state, names)
|
self.visitor.on_using_namespace(state, names)
|
||||||
|
|
||||||
def _parse_using_declaration(self, tok: LexToken) -> None:
|
def _parse_using_declaration(
|
||||||
|
self, tok: LexToken, doxygen: typing.Optional[str]
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
using_declaration: "using" ["typename"] ["::"] nested_name_specifier unqualified_id ";"
|
using_declaration: "using" ["typename"] ["::"] nested_name_specifier unqualified_id ";"
|
||||||
| "using" "::" unqualified_id ";"
|
| "using" "::" unqualified_id ";"
|
||||||
@ -1004,12 +1006,15 @@ class CxxParser:
|
|||||||
typename, _ = self._parse_pqname(
|
typename, _ = self._parse_pqname(
|
||||||
tok, fn_ok=True, compound_ok=True, fund_ok=True
|
tok, fn_ok=True, compound_ok=True, fund_ok=True
|
||||||
)
|
)
|
||||||
decl = UsingDecl(typename, self._current_access)
|
decl = UsingDecl(typename, self._current_access, doxygen)
|
||||||
|
|
||||||
self.visitor.on_using_declaration(self.state, decl)
|
self.visitor.on_using_declaration(self.state, decl)
|
||||||
|
|
||||||
def _parse_using_typealias(
|
def _parse_using_typealias(
|
||||||
self, id_tok: LexToken, template: typing.Optional[TemplateDecl]
|
self,
|
||||||
|
id_tok: LexToken,
|
||||||
|
template: typing.Optional[TemplateDecl],
|
||||||
|
doxygen: typing.Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
alias_declaration: "using" IDENTIFIER "=" type_id ";"
|
alias_declaration: "using" IDENTIFIER "=" type_id ";"
|
||||||
@ -1023,7 +1028,7 @@ class CxxParser:
|
|||||||
|
|
||||||
dtype = self._parse_cv_ptr(parsed_type)
|
dtype = self._parse_cv_ptr(parsed_type)
|
||||||
|
|
||||||
alias = UsingAlias(id_tok.value, dtype, template, self._current_access)
|
alias = UsingAlias(id_tok.value, dtype, template, self._current_access, doxygen)
|
||||||
|
|
||||||
self.visitor.on_using_alias(self.state, alias)
|
self.visitor.on_using_alias(self.state, alias)
|
||||||
|
|
||||||
@ -1052,9 +1057,9 @@ class CxxParser:
|
|||||||
raise CxxParseError(
|
raise CxxParseError(
|
||||||
"unexpected using-declaration when parsing alias-declaration", tok
|
"unexpected using-declaration when parsing alias-declaration", tok
|
||||||
)
|
)
|
||||||
self._parse_using_declaration(tok)
|
self._parse_using_declaration(tok, doxygen)
|
||||||
else:
|
else:
|
||||||
self._parse_using_typealias(tok, template)
|
self._parse_using_typealias(tok, template, doxygen)
|
||||||
|
|
||||||
# All using things end with a semicolon
|
# All using things end with a semicolon
|
||||||
self._next_token_must_be(";")
|
self._next_token_must_be(";")
|
||||||
|
@ -866,6 +866,9 @@ class UsingDecl:
|
|||||||
#: If within a class, the access level for this decl
|
#: If within a class, the access level for this decl
|
||||||
access: typing.Optional[str] = None
|
access: typing.Optional[str] = None
|
||||||
|
|
||||||
|
#: Documentation if present
|
||||||
|
doxygen: typing.Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class UsingAlias:
|
class UsingAlias:
|
||||||
@ -886,3 +889,6 @@ class UsingAlias:
|
|||||||
|
|
||||||
#: If within a class, the access level for this decl
|
#: If within a class, the access level for this decl
|
||||||
access: typing.Optional[str] = None
|
access: typing.Optional[str] = None
|
||||||
|
|
||||||
|
#: Documentation if present
|
||||||
|
doxygen: typing.Optional[str] = None
|
||||||
|
@ -26,6 +26,7 @@ from cxxheaderparser.types import (
|
|||||||
Type,
|
Type,
|
||||||
Typedef,
|
Typedef,
|
||||||
UsingDecl,
|
UsingDecl,
|
||||||
|
UsingAlias,
|
||||||
Value,
|
Value,
|
||||||
Variable,
|
Variable,
|
||||||
)
|
)
|
||||||
@ -436,3 +437,53 @@ def test_doxygen_attribute() -> None:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_doxygen_using_decl() -> None:
|
||||||
|
content = """
|
||||||
|
// clang-format off
|
||||||
|
|
||||||
|
/// Comment
|
||||||
|
using ns::ClassName;
|
||||||
|
"""
|
||||||
|
data = parse_string(content, cleandoc=True)
|
||||||
|
|
||||||
|
assert data == ParsedData(
|
||||||
|
namespace=NamespaceScope(
|
||||||
|
using=[
|
||||||
|
UsingDecl(
|
||||||
|
typename=PQName(
|
||||||
|
segments=[
|
||||||
|
NameSpecifier(name="ns"),
|
||||||
|
NameSpecifier(name="ClassName"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
doxygen="/// Comment",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_doxygen_using_alias() -> None:
|
||||||
|
content = """
|
||||||
|
// clang-format off
|
||||||
|
|
||||||
|
/// Comment
|
||||||
|
using alias = sometype;
|
||||||
|
"""
|
||||||
|
data = parse_string(content, cleandoc=True)
|
||||||
|
|
||||||
|
assert data == ParsedData(
|
||||||
|
namespace=NamespaceScope(
|
||||||
|
using_alias=[
|
||||||
|
UsingAlias(
|
||||||
|
alias="alias",
|
||||||
|
type=Type(
|
||||||
|
typename=PQName(segments=[NameSpecifier(name="sometype")])
|
||||||
|
),
|
||||||
|
doxygen="/// Comment",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user