Skip to content

Commit

Permalink
Merge pull request #194 from pdatkinson/develop
Browse files Browse the repository at this point in the history
scanner.py: add support for "original_type" attribute of "Argument" XML tag
  • Loading branch information
iMichka authored Sep 28, 2024
2 parents 6eb7b9e + 2eaf2c5 commit 4f3fe0c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pygccxml/parser/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
XML_AN_STATIC = "static"
XML_AN_THROW = "throw"
XML_AN_TYPE = "type"
XML_AN_ORIGINAL_TYPE = "original_type"
XML_AN_VIRTUAL = "virtual"
XML_AN_VOLATILE = "volatile"
XML_NN_ARGUMENT = "Argument"
Expand Down Expand Up @@ -558,7 +559,10 @@ def __read_argument(self, attrs):
XML_AN_NAME,
'arg%d' % len(
self.__inst.arguments))
argument.decl_type = attrs[XML_AN_TYPE]
argument.decl_type = attrs.get(
XML_AN_ORIGINAL_TYPE,
attrs.get(XML_AN_TYPE)
)
argument.default_value = attrs.get(XML_AN_DEFAULT)
self.__read_attributes(argument, attrs)
self.__inst.arguments.append(argument)
Expand Down
76 changes: 76 additions & 0 deletions tests/test_array_argument.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2014-2017 Insight Software Consortium.
# Copyright 2004-2009 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import unittest

from . import parser_test_case

from pygccxml import parser
from pygccxml import declarations


class Test(parser_test_case.parser_test_case_t):

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.header = "test_array_argument.hpp"
self.config.cflags = "-std=c++11"

def test_array_argument(self):

"""
Test to ensure that function arguments' array size are kept intact
rather than presented as pointers.
"""

decls = parser.parse([self.header], self.config)
global_ns = declarations.get_global_namespace(decls)

criteria = declarations.calldef_matcher(name="function")
free_funcs = declarations.matcher.find(criteria, global_ns)
for free_func in free_funcs:
decl_string = free_func.create_decl_string(with_defaults=False)
self.assertEqual(
decl_string,
"void ( ::test::* )( int [1024],int [512] )"
)
arg1 = free_func.arguments[0]
arg2 = free_func.arguments[1]
self.assertEqual(arg1.decl_type.decl_string, "int [1024]")
self.assertEqual(arg1.name, "arg1")
self.assertEqual(
declarations.type_traits.array_size(arg1.decl_type),
1024
)
self.assertIsInstance(
declarations.type_traits.array_item_type(arg1.decl_type),
declarations.cpptypes.int_t
)
self.assertEqual(arg2.decl_type.decl_string, "int [512]")
self.assertEqual(arg2.name, "arg2")
self.assertEqual(
declarations.type_traits.array_size(arg2.decl_type),
512
)
self.assertIsInstance(
declarations.type_traits.array_item_type(arg2.decl_type),
declarations.cpptypes.int_t
)


def create_suite():
suite = unittest.TestSuite()
suite.addTest(
unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test))
return suite


def run_suite():
unittest.TextTestRunner(verbosity=2).run(create_suite())


if __name__ == "__main__":
run_suite()
13 changes: 13 additions & 0 deletions unittests/data/test_array_argument.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2014-2017 Insight Software Consortium.
// Copyright 2004-2009 Roman Yakovenko.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt

class test
{
public:
// A constructor
test(const float & t0){};

void function(int arg1[1024], int arg2[512]) {};
};

0 comments on commit 4f3fe0c

Please sign in to comment.