Skip to content

Commit

Permalink
Merge pull request #100 from robotpy/msvc-inline
Browse files Browse the repository at this point in the history
Parse MSVC inline/forceinline as inline
  • Loading branch information
virtuald committed Jun 9, 2024
2 parents 914838c + a7b156d commit 544c253
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
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,
),
]
)
)

0 comments on commit 544c253

Please sign in to comment.