4 Commits
1.2.0 ... 1.2.2

Author SHA1 Message Date
Dustin Spicuzza
f1708bf9b8 Merge pull request #85 from robotpy/static-inline
Allow fields to be marked inline
2023-11-19 12:50:09 -05:00
Dustin Spicuzza
cafb594179 Allow fields to be marked inline
- Fixes #84
2023-11-19 12:47:09 -05:00
Dustin Spicuzza
0e732f1d43 Merge pull request #82 from robotpy/trailing-return-type-body
Consume function body if present after trailing return type
2023-11-13 23:27:15 -05:00
Dustin Spicuzza
42bc6b60ad Consume function body if present after trailing return type
- Fixes #81
2023-11-13 23:23:40 -05:00
4 changed files with 108 additions and 2 deletions

View File

@@ -1914,11 +1914,12 @@ class CxxParser:
fn_template = fn_template[0]
fn_template.raw_requires_post = self._parse_requires(rtok)
if self.lex.token_if("ARROW"):
self._parse_trailing_return_type(fn)
if self.lex.token_if("{"):
self._discard_contents("{", "}")
fn.has_body = True
elif self.lex.token_if("ARROW"):
self._parse_trailing_return_type(fn)
def _parse_method_end(self, method: Method) -> None:
"""
@@ -1963,6 +1964,9 @@ class CxxParser:
method.ref_qualifier = tok_value
elif tok_value == "->":
self._parse_trailing_return_type(method)
if self.lex.token_if("{"):
self._discard_contents("{", "}")
method.has_body = True
break
elif tok_value == "throw":
tok = self._next_token_must_be("(")

View File

@@ -848,6 +848,7 @@ class Field:
constexpr: bool = False
mutable: bool = False
static: bool = False
inline: bool = False
doxygen: typing.Optional[str] = None

View File

@@ -3336,3 +3336,40 @@ def test_constructor_outside_class() -> None:
]
)
)
def test_class_inline_static() -> None:
content = """
struct X {
inline static bool Foo = 1;
};
"""
data = parse_string(content, cleandoc=True)
assert data == ParsedData(
namespace=NamespaceScope(
classes=[
ClassScope(
class_decl=ClassDecl(
typename=PQName(
segments=[NameSpecifier(name="X")], classkey="struct"
)
),
fields=[
Field(
access="public",
type=Type(
typename=PQName(
segments=[FundamentalSpecifier(name="bool")]
)
),
name="Foo",
value=Value(tokens=[Token(value="1")]),
static=True,
inline=True,
)
],
)
]
)
)

View File

@@ -1194,3 +1194,67 @@ def test_auto_decltype_return() -> None:
]
)
)
def test_fn_trailing_return_with_body() -> None:
content = """
auto test() -> void
{
}
"""
data = parse_string(content, cleandoc=True)
assert data == ParsedData(
namespace=NamespaceScope(
functions=[
Function(
return_type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="void")])
),
name=PQName(segments=[NameSpecifier(name="test")]),
parameters=[],
has_body=True,
has_trailing_return=True,
)
]
)
)
def test_method_trailing_return_with_body() -> None:
content = """
struct X {
auto test() -> void
{
}
};
"""
data = parse_string(content, cleandoc=True)
assert data == ParsedData(
namespace=NamespaceScope(
classes=[
ClassScope(
class_decl=ClassDecl(
typename=PQName(
segments=[NameSpecifier(name="X")], classkey="struct"
)
),
methods=[
Method(
return_type=Type(
typename=PQName(
segments=[FundamentalSpecifier(name="void")]
)
),
name=PQName(segments=[NameSpecifier(name="test")]),
parameters=[],
has_body=True,
has_trailing_return=True,
access="public",
)
],
)
]
)
)