Skip to content

Commit 6901711

Browse files
committed
Fix default access for structs/union base classes
1 parent 57770df commit 6901711

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ class CppBaseDecl(dict):
384384
385385
"""
386386

387-
def __init__(self):
388-
self["access"] = "private"
387+
def __init__(self, default_access):
388+
self["access"] = default_access
389389
self["class"] = ""
390390
self["decl_name"] = ""
391391
self["decltype"] = False
@@ -530,13 +530,13 @@ def _parse_cppclass_name(c, stack):
530530
return i
531531

532532

533-
def _parse_cpp_base(stack):
534-
debug_print("Parsing base: %s", stack)
533+
def _parse_cpp_base(stack, default_access):
534+
debug_print("Parsing base: %s (access %s)", stack, default_access)
535535
inherits = []
536536
i = 0
537537
sl = len(stack)
538538
init = True
539-
base = CppBaseDecl()
539+
base = CppBaseDecl(default_access)
540540
require_ending = False
541541
while i < sl:
542542
t = stack[i]
@@ -558,7 +558,7 @@ def _parse_cpp_base(stack):
558558

559559
if t == ",":
560560
inherits.append(base)
561-
base = CppBaseDecl()
561+
base = CppBaseDecl(default_access)
562562
init = True
563563
require_ending = False
564564
continue
@@ -681,7 +681,7 @@ def _lookup_type(self, name):
681681
if n["name"] == name:
682682
return {"raw_type": self["name"] + "::" + n["name"], "type": n["name"]}
683683

684-
def __init__(self, nameStack, curTemplate, doxygen, location):
684+
def __init__(self, nameStack, curTemplate, doxygen, location, defaultAccess):
685685
self["nested_classes"] = []
686686
self["parent"] = None
687687
self["abstract"] = False
@@ -706,7 +706,7 @@ def __init__(self, nameStack, curTemplate, doxygen, location):
706706
# consume bases
707707
baseStack = nameStack[n:]
708708
if baseStack:
709-
self["inherits"] = _parse_cpp_base(baseStack)
709+
self["inherits"] = _parse_cpp_base(baseStack, defaultAccess)
710710
else:
711711
self["inherits"] = []
712712

@@ -838,7 +838,7 @@ class CppUnion(CppClass):
838838
"""
839839

840840
def __init__(self, nameStack, doxygen, location):
841-
CppClass.__init__(self, nameStack, None, doxygen, location)
841+
CppClass.__init__(self, nameStack, None, doxygen, location, "public")
842842
self["members"] = self["properties"]["public"]
843843

844844
def transform_to_union_keys(self):
@@ -2487,6 +2487,7 @@ def _evaluate_class_stack(self):
24872487
self.curTemplate,
24882488
self._get_stmt_doxygen(),
24892489
self._get_location(self.nameStack),
2490+
self.curAccessSpecifier,
24902491
)
24912492
newClass["declaration_method"] = self.nameStack[0]
24922493
self.classes_order.append(newClass) # good idea to save ordering

test/test_CppHeaderParser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,7 +3187,7 @@ def testBuildIndexImpl1(self):
31873187
self.assertEqual(
31883188
[
31893189
{
3190-
"access": "private",
3190+
"access": "public",
31913191
"class": "build_index_impl<N-1,N-1,I...>",
31923192
"decltype": False,
31933193
"decl_name": "build_index_impl",
@@ -3217,7 +3217,7 @@ def testBuildIndexImpl2(self):
32173217
self.assertEqual(
32183218
[
32193219
{
3220-
"access": "private",
3220+
"access": "public",
32213221
"class": "index_sequence<I...>",
32223222
"decltype": False,
32233223
"decl_name": "index_sequence",

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