Skip to content

Commit 8c69970

Browse files
authored
Merge pull request #66 from robotpy/fn-operator
breaking change: Remove operator type and make part of Function
2 parents 09eb5af + c3fbe4c commit 8c69970

File tree

6 files changed

+128
-93
lines changed

6 files changed

+128
-93
lines changed

cxxheaderparser/parser.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
NameSpecifier,
3838
NamespaceAlias,
3939
NamespaceDecl,
40-
Operator,
4140
PQNameSegment,
4241
Parameter,
4342
PQName,
@@ -1825,33 +1824,19 @@ def _parse_function(
18251824
if (is_class_block or multiple_name_segments) and not is_typedef:
18261825
props.update(dict.fromkeys(mods.meths.keys(), True))
18271826

1828-
method: Method
1829-
1830-
if op:
1831-
method = Operator(
1832-
return_type,
1833-
pqname,
1834-
params,
1835-
vararg,
1836-
doxygen=doxygen,
1837-
operator=op,
1838-
template=template,
1839-
access=self._current_access,
1840-
**props, # type: ignore
1841-
)
1842-
else:
1843-
method = Method(
1844-
return_type,
1845-
pqname,
1846-
params,
1847-
vararg,
1848-
doxygen=doxygen,
1849-
constructor=constructor,
1850-
destructor=destructor,
1851-
template=template,
1852-
access=self._current_access,
1853-
**props, # type: ignore
1854-
)
1827+
method = Method(
1828+
return_type,
1829+
pqname,
1830+
params,
1831+
vararg,
1832+
doxygen=doxygen,
1833+
constructor=constructor,
1834+
destructor=destructor,
1835+
template=template,
1836+
operator=op,
1837+
access=self._current_access,
1838+
**props, # type: ignore
1839+
)
18551840

18561841
self._parse_method_end(method)
18571842

@@ -1883,6 +1868,7 @@ def _parse_function(
18831868
vararg,
18841869
doxygen=doxygen,
18851870
template=template,
1871+
operator=op,
18861872
**props,
18871873
)
18881874
self._parse_fn_end(fn)

cxxheaderparser/types.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ class Function:
550550
#: calling convention
551551
msvc_convention: typing.Optional[str] = None
552552

553+
#: The operator type (+, +=, etc).
554+
#:
555+
#: If this object is a Function, then this is a free operator function. If
556+
#: this object is a Method, then it is an operator method.
557+
#:
558+
#: In the case of a conversion operator (such as 'operator bool'), this
559+
#: is the string "conversion" and the full Type is found in return_type
560+
operator: typing.Optional[str] = None
561+
553562

554563
@dataclass
555564
class Method(Function):
@@ -585,19 +594,6 @@ class Method(Function):
585594
override: bool = False
586595

587596

588-
@dataclass
589-
class Operator(Method):
590-
"""
591-
Represents an operator method
592-
"""
593-
594-
#: The operator type (+, +=, etc).
595-
#:
596-
#: In the case of a conversion operator (such as 'operator bool'), this
597-
#: is the string "conversion" and the full Type is found in return_type
598-
operator: str = ""
599-
600-
601597
@dataclass
602598
class FriendDecl:
603599
"""

tests/test_class.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Method,
1515
MoveReference,
1616
NameSpecifier,
17-
Operator,
1817
PQName,
1918
Parameter,
2019
Pointer,
@@ -369,7 +368,7 @@ class M {
369368
access="public",
370369
constructor=True,
371370
),
372-
Operator(
371+
Method(
373372
return_type=Type(
374373
typename=PQName(
375374
segments=[FundamentalSpecifier(name="int")]
@@ -399,7 +398,7 @@ class M {
399398
const=True,
400399
operator="()",
401400
),
402-
Operator(
401+
Method(
403402
return_type=Reference(
404403
ref_to=Type(
405404
typename=PQName(

tests/test_doxygen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Method,
1515
MoveReference,
1616
NameSpecifier,
17-
Operator,
1817
PQName,
1918
Parameter,
2019
Pointer,

tests/test_fn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
Function,
88
FunctionType,
99
FundamentalSpecifier,
10+
Method,
1011
MoveReference,
1112
NameSpecifier,
12-
Operator,
1313
PQName,
1414
Parameter,
1515
Pointer,
@@ -888,7 +888,7 @@ def test_method_w_reference() -> None:
888888
)
889889
),
890890
methods=[
891-
Operator(
891+
Method(
892892
return_type=Reference(
893893
ref_to=Type(
894894
typename=PQName(

0 commit comments

Comments
 (0)