Skip to content

Commit

Permalink
Merge pull request #59 from robotpy/decorated-conversion-operator
Browse files Browse the repository at this point in the history
Parse extra type information for conversion operators
  • Loading branch information
virtuald authored Aug 20, 2023
2 parents 6ab0d00 + f597b69 commit dffcbf9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cxxheaderparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,9 @@ def _parse_operator_conversion(

cmods.validate(var_ok=False, meth_ok=False, msg="parsing conversion operator")

# Check for any cv decorations for the type
rtype = self._parse_cv_ptr(ctype)

# then this must be a method
self._next_token_must_be("(")

Expand All @@ -2317,7 +2320,7 @@ def _parse_operator_conversion(

if self._parse_function(
mods,
ctype,
rtype,
pqname,
op,
template,
Expand Down
74 changes: 74 additions & 0 deletions tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from cxxheaderparser.types import (
ClassDecl,
FundamentalSpecifier,
MoveReference,
NameSpecifier,
Operator,
Pointer,
PQName,
Parameter,
Reference,
Expand Down Expand Up @@ -617,3 +619,75 @@ class Foo
]
)
)


def test_conversion_operators_decorated() -> None:
content = """
struct S {
operator const native_handle_t*() const;
operator const native_handle_t&() const;
operator const native_handle_t&&() const;
};
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
classes=[
ClassScope(
class_decl=ClassDecl(
typename=PQName(
segments=[NameSpecifier(name="S")], classkey="struct"
)
),
methods=[
Operator(
return_type=Pointer(
ptr_to=Type(
typename=PQName(
segments=[NameSpecifier(name="native_handle_t")]
),
const=True,
)
),
name=PQName(segments=[NameSpecifier(name="operator")]),
parameters=[],
access="public",
const=True,
operator="conversion",
),
Operator(
return_type=Reference(
ref_to=Type(
typename=PQName(
segments=[NameSpecifier(name="native_handle_t")]
),
const=True,
)
),
name=PQName(segments=[NameSpecifier(name="operator")]),
parameters=[],
access="public",
const=True,
operator="conversion",
),
Operator(
return_type=MoveReference(
moveref_to=Type(
typename=PQName(
segments=[NameSpecifier(name="native_handle_t")]
),
const=True,
)
),
name=PQName(segments=[NameSpecifier(name="operator")]),
parameters=[],
access="public",
const=True,
operator="conversion",
),
],
)
]
)
)

0 comments on commit dffcbf9

Please sign in to comment.