Skip to content

Commit cc0d4a0

Browse files
committed
Correctly detect templates for 'using' statements
1 parent 7634566 commit cc0d4a0

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ class CppVariable(_CppVariable):
12071207

12081208
Vars = []
12091209

1210-
def __init__(self, nameStack, doxygen, location, **kwargs):
1210+
def __init__(self, nameStack, doxygen, location, is_var=True, **kwargs):
12111211
debug_print("var trace %s", nameStack)
12121212
if len(nameStack) and nameStack[0] == "extern":
12131213
self["extern"] = True
@@ -1297,7 +1297,8 @@ def __init__(self, nameStack, doxygen, location, **kwargs):
12971297
pass
12981298

12991299
self.init()
1300-
CppVariable.Vars.append(self) # save and resolve later
1300+
if is_var:
1301+
CppVariable.Vars.append(self) # save and resolve later
13011302

13021303
def _filter_name(self, name):
13031304
name = name.replace(" :", ":").replace(": ", ":")
@@ -3359,7 +3360,10 @@ def _evaluate_stack(self, token=None):
33593360
alias = self.nameStack[1]
33603361
ns, stack = _split_namespace(self.nameStack[3:])
33613362
atype = CppVariable(
3362-
stack, self._get_stmt_doxygen(), self._get_location(stack)
3363+
stack,
3364+
self._get_stmt_doxygen(),
3365+
self._get_location(stack),
3366+
is_var=False,
33633367
)
33643368

33653369
# namespace refers to the embedded type
@@ -3374,7 +3378,10 @@ def _evaluate_stack(self, token=None):
33743378
# from a base class
33753379
ns, stack = _split_namespace(self.nameStack[1:])
33763380
atype = CppVariable(
3377-
stack, self._get_stmt_doxygen(), self._get_location(stack)
3381+
stack,
3382+
self._get_stmt_doxygen(),
3383+
self._get_location(stack),
3384+
is_var=False,
33783385
)
33793386
alias = atype["type"]
33803387
atype["using_type"] = "declaration"
@@ -3383,6 +3390,9 @@ def _evaluate_stack(self, token=None):
33833390
else:
33843391
atype["namespace"] = ns
33853392

3393+
atype["template"] = self.curTemplate
3394+
self.curTemplate = None
3395+
33863396
if atype["type"].startswith("typename "):
33873397
atype["raw_type"] = "typename " + ns + atype["type"][9:]
33883398
else:

test/test_CppHeaderParser.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,5 +4110,30 @@ def test_fn(self):
41104110
self.assertEqual(et2["params"], "<5, 6>")
41114111

41124112

4113+
class UsingTemplateTest(unittest.TestCase):
4114+
def setUp(self):
4115+
self.cppHeader = CppHeaderParser.CppHeader(
4116+
"""
4117+
class X {
4118+
template <typename T>
4119+
using TT = U<T>;
4120+
};
4121+
4122+
""",
4123+
"string",
4124+
)
4125+
4126+
def test_fn(self):
4127+
u = self.cppHeader.classes["X"]["using"]
4128+
self.assertEqual(len(u), 1)
4129+
tt = u["TT"]
4130+
4131+
self.assertEqual(tt["access"], "private")
4132+
self.assertEqual(tt["raw_type"], "U<T >")
4133+
self.assertEqual(tt["type"], "U<T >")
4134+
self.assertEqual(tt["typealias"], "TT")
4135+
self.assertEqual(tt["template"], "template<typename T>")
4136+
4137+
41134138
if __name__ == "__main__":
41144139
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