Skip to content

Commit f399f97

Browse files
authored
Add declaration object for deprecation message. (#138)
* Add declaration object for deprecation message. Pass the newly captured deprecation information from CastXML to the declarations of those objects. * Make requested updates Fix copy/paste copyright header to only be for the year 2021 Fix variable names in the text checking function. Use the latest version of CastXML for testing too.
1 parent b68f336 commit f399f97

File tree

6 files changed

+127
-2
lines changed

6 files changed

+127
-2
lines changed

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ jobs:
7575
- name: Setup castxml for Linux
7676
if: matrix.os == 'ubuntu-18.04' && matrix.castxml == 'castxml'
7777
run: |
78-
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/b580374e48d4df68f8ebef6d0e71cd8cc3f2dfa28f0090e07cc043d11cee308aeea480092fe2e93f2d4c58f822a5c013c1c7121964372d28ee4069949a378b4c/download | tar zxf - -C ~/
78+
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/bdbb67a10c5f8d1b738cd19cb074f409d4803e8077cb8c1072ef4eaf738fa871a73643f9c8282d58cae28d188df842c82ad6620b6d590b0396a0172a27438dce/download | tar zxf - -C ~/
7979
- name: Setup castxml for Mac
8080
if: matrix.os == 'macos-latest'
8181
run: |
82-
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/e5962372508abd295f8a8110a20142bcbd93c235f72afba34b0abb3918a623f27465a7674b5532320e770f56fddb99019f5c47b254cea9f862a2df35630c2879/download | tar zxf - -C ~/
82+
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/5d937e938f7b882a3a3e7941e68f8312d0898aaf2082e00003dd362b1ba70b98b0a08706a1be28e71652a6a0f1e66f89768b5eaa20e5a100592d5b3deefec3f0/download | tar zxf - -C ~/
8383
- name: Setup castxml config
8484
if: matrix.compiler == 'gcc' && matrix.version == '7'
8585
run: mv unittests/configs/gcc7.cfg unittests/xml_generator.cfg;

pygccxml/declarations/declaration.py

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
self._partial_name = None
4040
self._decorated_name = None
4141
self._comment = comment.comment_t()
42+
self._deprecation = None
4243

4344
def __str__(self):
4445
"""
@@ -348,3 +349,11 @@ def comment(self):
348349
@comment.setter
349350
def comment(self, comment):
350351
self._comment = comment
352+
353+
@property
354+
def deprecation(self):
355+
return self._deprecation
356+
357+
@deprecation.setter
358+
def deprecation(self, deprecation):
359+
self._deprecation = deprecation

pygccxml/parser/scanner.py

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
XML_AN_CVS_REVISION = "cvs_revision"
3131
XML_AN_CASTXML_FORMAT = "format"
3232
XML_AN_DEFAULT = "default"
33+
XML_AN_DEPRECATION = "deprecation"
3334
XML_AN_END_COLUMN = "end_column"
3435
XML_AN_END_LINE = "end_line"
3536
XML_AN_END_OFFSET = "end_offset"
@@ -309,6 +310,7 @@ def startElement(self, name, attrs):
309310
if isinstance(obj, declarations.class_t):
310311
self.__read_bases(obj, attrs)
311312
self.__read_artificial(obj, attrs)
313+
self.__read_deprecation(obj, attrs)
312314
self.__read_mangled(obj, attrs)
313315
self.__read_attributes(obj, attrs)
314316

@@ -384,6 +386,12 @@ def __read_mangled(self, decl, attrs):
384386
mangled = mangled[:self.__mangled_suffix_len]
385387
decl.mangled = mangled
386388

389+
def __read_deprecation(self, decl, attrs):
390+
deprecation = attrs.get(XML_AN_DEPRECATION)
391+
# the following patch is defined here for performance reasons
392+
if isinstance(deprecation, str):
393+
decl.deprecation = deprecation
394+
387395
def __read_attributes(self, decl, attrs):
388396
attribute = attrs.get(XML_AN_ATTRIBUTES)
389397
if attribute is not None and \

unittests/data/test_deprecation.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2021 Insight Software Consortium.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See http://www.boost.org/LICENSE_1_0.txt
4+
5+
namespace deprecation {
6+
7+
8+
class __attribute__((deprecated("Test class Deprecated"))) test
9+
{
10+
public:
11+
test();
12+
__attribute__((deprecated("One arg constructor is Deprecated"))) test(int a);
13+
14+
int hello();
15+
void __attribute__((deprecated("Function is deprecated"))) goodbye();
16+
};
17+
enum __attribute__((deprecated("Enumeration is Deprecated"))) com_enum {
18+
One = 1,
19+
Two = 2
20+
};
21+
}

unittests/test_all.py

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
from . import test_hash
8585
from . import test_null_comparison
8686
from . import test_comments
87+
from . import test_deprecation
8788
from . import test_warn_missing_include_dirs
8889
from . import test_overrides
8990

@@ -161,6 +162,7 @@
161162
test_hash,
162163
test_null_comparison,
163164
test_comments,
165+
test_deprecation,
164166
test_warn_missing_include_dirs,
165167
test_overrides,
166168
]

unittests/test_deprecation.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2021 Insight Software Consortium.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See http://www.boost.org/LICENSE_1_0.txt
4+
5+
import unittest
6+
7+
from . import parser_test_case
8+
9+
from pygccxml import parser
10+
from pygccxml import declarations
11+
12+
13+
class Test(parser_test_case.parser_test_case_t):
14+
global_ns = None
15+
16+
def __init__(self, *args):
17+
parser_test_case.parser_test_case_t.__init__(self, *args)
18+
self.header = "test_deprecation.hpp"
19+
self.global_ns = None
20+
self.config.castxml_epic_version = 1
21+
22+
def _check_text_content(self, desired_text, deprecation_string):
23+
if deprecation_string:
24+
self.assertEqual(desired_text, deprecation_string)
25+
else:
26+
print("No text in deprecation attribute to check")
27+
28+
def setUp(self):
29+
if not self.global_ns:
30+
decls = parser.parse([self.header], self.config)
31+
Test.global_ns = declarations.get_global_namespace(decls)
32+
Test.xml_generator_from_xml_file = \
33+
self.config.xml_generator_from_xml_file
34+
self.xml_generator_from_xml_file = Test.xml_generator_from_xml_file
35+
36+
self.global_ns = Test.global_ns
37+
38+
def test(self):
39+
"""
40+
Check the comment parsing
41+
"""
42+
43+
if self.config.castxml_epic_version != 1:
44+
# Run this test only with castxml epic version == 1
45+
return
46+
tnamespace = self.global_ns.namespace("deprecation")
47+
48+
tenumeration = tnamespace.enumeration("com_enum")
49+
self.assertIn("deprecation", dir(tenumeration))
50+
self._check_text_content('Enumeration is Deprecated',
51+
tenumeration.deprecation)
52+
53+
tclass = tnamespace.class_("test")
54+
self.assertIn("deprecation", dir(tclass))
55+
self._check_text_content("Test class Deprecated", tclass.deprecation)
56+
57+
tmethod = tclass.member_functions()[0]
58+
tmethod_dep = tclass.member_functions()[1]
59+
60+
self.assertIn("deprecation", dir(tmethod))
61+
self.assertIsNone(tmethod.deprecation)
62+
self._check_text_content("Function is deprecated",
63+
tmethod_dep.deprecation)
64+
65+
tconstructor = tclass.constructors()[0]
66+
tconstructor_dep = tclass.constructors()[1]
67+
68+
self.assertIsNone(tconstructor.deprecation)
69+
self.assertIn("deprecation", dir(tconstructor_dep))
70+
self._check_text_content("One arg constructor is Deprecated",
71+
tconstructor_dep.deprecation)
72+
73+
74+
def create_suite():
75+
suite = unittest.TestSuite()
76+
suite.addTest(unittest.makeSuite(Test))
77+
return suite
78+
79+
80+
def run_suite():
81+
unittest.TextTestRunner(verbosity=2).run(create_suite())
82+
83+
84+
if __name__ == "__main__":
85+
run_suite()

0 commit comments

Comments
 (0)