Skip to content

Commit 32fb1bb

Browse files
committed
Fix base classes with namespaces
- Fixes robotpy#39
1 parent 561449c commit 32fb1bb

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def _fix_classname(self):
408408
if self["..."]:
409409
s += "..."
410410

411-
self["class"] = s
411+
return s
412412

413413

414414
def _consume_parens(stack):
@@ -564,7 +564,14 @@ def _parse_cpp_base(stack, default_access):
564564
continue
565565

566566
if require_ending:
567-
raise CppParseError("expected comma, found '%s'" % t)
567+
if t == "::":
568+
if "decl_params" in base:
569+
base["decl_name"] = base._fix_classname()
570+
del base["decl_params"]
571+
base["..."]
572+
require_ending = False
573+
else:
574+
raise CppParseError("expected comma, found '%s'" % t)
568575

569576
if t == "(":
570577
s = stack[i:]
@@ -585,7 +592,7 @@ def _parse_cpp_base(stack, default_access):
585592
# backwards compat
586593
inherits.append(base)
587594
for base in inherits:
588-
base._fix_classname()
595+
base["class"] = base._fix_classname()
589596

590597
return inherits
591598

test/test_CppHeaderParser.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,6 +3792,7 @@ def test_fn(self):
37923792
self.assertEqual(props[0]["name"], "x")
37933793
self.assertEqual(props[1]["name"], "y")
37943794

3795+
37953796
class Deleted_TestCase(unittest.TestCase):
37963797
def setUp(self):
37973798
self.cppHeader = CppHeaderParser.CppHeader(
@@ -3809,5 +3810,33 @@ def test_fn(self):
38093810
self.assertEqual(m["constructor"], True)
38103811
self.assertEqual(m["deleted"], True)
38113812

3813+
3814+
class BaseTemplateNs_TestCase(unittest.TestCase):
3815+
def setUp(self):
3816+
self.cppHeader = CppHeaderParser.CppHeader(
3817+
"""
3818+
class A : public B<int, int>::C {};
3819+
""",
3820+
"string",
3821+
)
3822+
3823+
def test_fn(self):
3824+
c = self.cppHeader.classes["A"]
3825+
self.assertEqual("A", c["name"])
3826+
self.assertEqual(
3827+
[
3828+
{
3829+
"access": "public",
3830+
"class": "B<int,int>::C",
3831+
"decl_name": "B<int,int>::C",
3832+
"virtual": False,
3833+
"...": False,
3834+
"decltype": False,
3835+
}
3836+
],
3837+
c["inherits"],
3838+
)
3839+
3840+
38123841
if __name__ == "__main__":
38133842
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy