Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse MSVC inline/forceinline as inline #100

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cxxheaderparser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ class PlyLexer:
"final",
"float",
"for",
"__forceinline",
"friend",
"goto",
"if",
"__inline",
"inline",
"int",
"long",
Expand Down
2 changes: 2 additions & 0 deletions cxxheaderparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,8 @@ def _parse_type(
volatile = True
elif tok_type in _attribute_start:
self._consume_attribute(tok)
elif tok_type in ("__inline", "__forceinline"):
both["inline"] = tok
else:
break

Expand Down
55 changes: 55 additions & 0 deletions tests/test_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,58 @@ def test_method_trailing_return_with_body() -> None:
]
)
)


def test_msvc_inline() -> None:
content = """
__inline double fn1() {}
__forceinline double fn2() {}
static __inline double fn3() {}
static __forceinline double fn4() {}
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
functions=[
Function(
return_type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="double")])
),
name=PQName(segments=[NameSpecifier(name="fn1")]),
parameters=[],
inline=True,
has_body=True,
),
Function(
return_type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="double")])
),
name=PQName(segments=[NameSpecifier(name="fn2")]),
parameters=[],
inline=True,
has_body=True,
),
Function(
return_type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="double")])
),
name=PQName(segments=[NameSpecifier(name="fn3")]),
parameters=[],
static=True,
inline=True,
has_body=True,
),
Function(
return_type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="double")])
),
name=PQName(segments=[NameSpecifier(name="fn4")]),
parameters=[],
static=True,
inline=True,
has_body=True,
),
]
)
)
Loading