Skip to content

Commit 4f3fe0c

Browse files
authored
Merge pull request #194 from pdatkinson/develop
scanner.py: add support for "original_type" attribute of "Argument" XML tag
2 parents 6eb7b9e + 2eaf2c5 commit 4f3fe0c

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

src/pygccxml/parser/scanner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
XML_AN_STATIC = "static"
5757
XML_AN_THROW = "throw"
5858
XML_AN_TYPE = "type"
59+
XML_AN_ORIGINAL_TYPE = "original_type"
5960
XML_AN_VIRTUAL = "virtual"
6061
XML_AN_VOLATILE = "volatile"
6162
XML_NN_ARGUMENT = "Argument"
@@ -558,7 +559,10 @@ def __read_argument(self, attrs):
558559
XML_AN_NAME,
559560
'arg%d' % len(
560561
self.__inst.arguments))
561-
argument.decl_type = attrs[XML_AN_TYPE]
562+
argument.decl_type = attrs.get(
563+
XML_AN_ORIGINAL_TYPE,
564+
attrs.get(XML_AN_TYPE)
565+
)
562566
argument.default_value = attrs.get(XML_AN_DEFAULT)
563567
self.__read_attributes(argument, attrs)
564568
self.__inst.arguments.append(argument)

tests/test_array_argument.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2014-2017 Insight Software Consortium.
2+
# Copyright 2004-2009 Roman Yakovenko.
3+
# Distributed under the Boost Software License, Version 1.0.
4+
# See http://www.boost.org/LICENSE_1_0.txt
5+
6+
import unittest
7+
8+
from . import parser_test_case
9+
10+
from pygccxml import parser
11+
from pygccxml import declarations
12+
13+
14+
class Test(parser_test_case.parser_test_case_t):
15+
16+
def __init__(self, *args):
17+
parser_test_case.parser_test_case_t.__init__(self, *args)
18+
self.header = "test_array_argument.hpp"
19+
self.config.cflags = "-std=c++11"
20+
21+
def test_array_argument(self):
22+
23+
"""
24+
Test to ensure that function arguments' array size are kept intact
25+
rather than presented as pointers.
26+
27+
"""
28+
29+
decls = parser.parse([self.header], self.config)
30+
global_ns = declarations.get_global_namespace(decls)
31+
32+
criteria = declarations.calldef_matcher(name="function")
33+
free_funcs = declarations.matcher.find(criteria, global_ns)
34+
for free_func in free_funcs:
35+
decl_string = free_func.create_decl_string(with_defaults=False)
36+
self.assertEqual(
37+
decl_string,
38+
"void ( ::test::* )( int [1024],int [512] )"
39+
)
40+
arg1 = free_func.arguments[0]
41+
arg2 = free_func.arguments[1]
42+
self.assertEqual(arg1.decl_type.decl_string, "int [1024]")
43+
self.assertEqual(arg1.name, "arg1")
44+
self.assertEqual(
45+
declarations.type_traits.array_size(arg1.decl_type),
46+
1024
47+
)
48+
self.assertIsInstance(
49+
declarations.type_traits.array_item_type(arg1.decl_type),
50+
declarations.cpptypes.int_t
51+
)
52+
self.assertEqual(arg2.decl_type.decl_string, "int [512]")
53+
self.assertEqual(arg2.name, "arg2")
54+
self.assertEqual(
55+
declarations.type_traits.array_size(arg2.decl_type),
56+
512
57+
)
58+
self.assertIsInstance(
59+
declarations.type_traits.array_item_type(arg2.decl_type),
60+
declarations.cpptypes.int_t
61+
)
62+
63+
64+
def create_suite():
65+
suite = unittest.TestSuite()
66+
suite.addTest(
67+
unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test))
68+
return suite
69+
70+
71+
def run_suite():
72+
unittest.TextTestRunner(verbosity=2).run(create_suite())
73+
74+
75+
if __name__ == "__main__":
76+
run_suite()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014-2017 Insight Software Consortium.
2+
// Copyright 2004-2009 Roman Yakovenko.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// See http://www.boost.org/LICENSE_1_0.txt
5+
6+
class test
7+
{
8+
public:
9+
// A constructor
10+
test(const float & t0){};
11+
12+
void function(int arg1[1024], int arg2[512]) {};
13+
};

0 commit comments

Comments
 (0)