Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanner.py: add support for "original_type" attribute of "Argument" XML tag #194

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]) {};
};
Loading