From 32fb1bb34898bba5f12be1dd0a76b4703f4e17c9 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Tue, 3 Mar 2020 12:02:03 -0500 Subject: [PATCH] Fix base classes with namespaces - Fixes #39 --- CppHeaderParser/CppHeaderParser.py | 13 ++++++++++--- test/test_CppHeaderParser.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CppHeaderParser/CppHeaderParser.py b/CppHeaderParser/CppHeaderParser.py index 9686d4e..56739b0 100644 --- a/CppHeaderParser/CppHeaderParser.py +++ b/CppHeaderParser/CppHeaderParser.py @@ -408,7 +408,7 @@ def _fix_classname(self): if self["..."]: s += "..." - self["class"] = s + return s def _consume_parens(stack): @@ -564,7 +564,14 @@ def _parse_cpp_base(stack, default_access): continue if require_ending: - raise CppParseError("expected comma, found '%s'" % t) + if t == "::": + if "decl_params" in base: + base["decl_name"] = base._fix_classname() + del base["decl_params"] + base["..."] + require_ending = False + else: + raise CppParseError("expected comma, found '%s'" % t) if t == "(": s = stack[i:] @@ -585,7 +592,7 @@ def _parse_cpp_base(stack, default_access): # backwards compat inherits.append(base) for base in inherits: - base._fix_classname() + base["class"] = base._fix_classname() return inherits diff --git a/test/test_CppHeaderParser.py b/test/test_CppHeaderParser.py index f61acc2..d23cb23 100644 --- a/test/test_CppHeaderParser.py +++ b/test/test_CppHeaderParser.py @@ -3792,6 +3792,7 @@ def test_fn(self): self.assertEqual(props[0]["name"], "x") self.assertEqual(props[1]["name"], "y") + class Deleted_TestCase(unittest.TestCase): def setUp(self): self.cppHeader = CppHeaderParser.CppHeader( @@ -3809,5 +3810,33 @@ def test_fn(self): self.assertEqual(m["constructor"], True) self.assertEqual(m["deleted"], True) + +class BaseTemplateNs_TestCase(unittest.TestCase): + def setUp(self): + self.cppHeader = CppHeaderParser.CppHeader( + """ +class A : public B::C {}; +""", + "string", + ) + + def test_fn(self): + c = self.cppHeader.classes["A"] + self.assertEqual("A", c["name"]) + self.assertEqual( + [ + { + "access": "public", + "class": "B::C", + "decl_name": "B::C", + "virtual": False, + "...": False, + "decltype": False, + } + ], + c["inherits"], + ) + + if __name__ == "__main__": unittest.main()