Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions pygccxml/declarations/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
self._partial_name = None
self._decorated_name = None
self._comment = comment.comment_t()
self._deprecation = None

def __str__(self):
"""
Expand Down Expand Up @@ -348,3 +349,11 @@ def comment(self):
@comment.setter
def comment(self, comment):
self._comment = comment

@property
def deprecation(self):
return self._deprecation

@deprecation.setter
def deprecation(self, deprecation):
self._deprecation = deprecation
8 changes: 8 additions & 0 deletions pygccxml/parser/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
XML_AN_CVS_REVISION = "cvs_revision"
XML_AN_CASTXML_FORMAT = "format"
XML_AN_DEFAULT = "default"
XML_AN_DEPRECATION = "deprecation"
XML_AN_END_COLUMN = "end_column"
XML_AN_END_LINE = "end_line"
XML_AN_END_OFFSET = "end_offset"
Expand Down Expand Up @@ -309,6 +310,7 @@ def startElement(self, name, attrs):
if isinstance(obj, declarations.class_t):
self.__read_bases(obj, attrs)
self.__read_artificial(obj, attrs)
self.__read_deprecation(obj, attrs)
self.__read_mangled(obj, attrs)
self.__read_attributes(obj, attrs)

Expand Down Expand Up @@ -384,6 +386,12 @@ def __read_mangled(self, decl, attrs):
mangled = mangled[:self.__mangled_suffix_len]
decl.mangled = mangled

def __read_deprecation(self, decl, attrs):
deprecation = attrs.get(XML_AN_DEPRECATION)
# the following patch is defined here for performance reasons
if isinstance(deprecation, str):
decl.deprecation = deprecation

def __read_attributes(self, decl, attrs):
attribute = attrs.get(XML_AN_ATTRIBUTES)
if attribute is not None and \
Expand Down
21 changes: 21 additions & 0 deletions unittests/data/test_deprecation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 Insight Software Consortium.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt

namespace deprecation {


class __attribute__((deprecated("Test class Deprecated"))) test
{
public:
test();
__attribute__((deprecated("One arg constructor is Deprecated"))) test(int a);

int hello();
void __attribute__((deprecated("Function is deprecated"))) goodbye();
};
enum __attribute__((deprecated("Enumeration is Deprecated"))) com_enum {
One = 1,
Two = 2
};
}
2 changes: 2 additions & 0 deletions unittests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from . import test_hash
from . import test_null_comparison
from . import test_comments
from . import test_deprecation
from . import test_warn_missing_include_dirs
from . import test_overrides

Expand Down Expand Up @@ -161,6 +162,7 @@
test_hash,
test_null_comparison,
test_comments,
test_deprecation,
test_warn_missing_include_dirs,
test_overrides,
]
Expand Down
87 changes: 87 additions & 0 deletions unittests/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2014-2020 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):
global_ns = None

def __init__(self, *args):
parser_test_case.parser_test_case_t.__init__(self, *args)
self.header = "test_deprecation.hpp"
self.global_ns = None
self.config.castxml_epic_version = 1

def _check_text_content(self, list, comment_decl):
if comment_decl:
self.assertEqual(list, comment_decl)
else:
print("No text in comment to check")

def setUp(self):

if not self.global_ns:
decls = parser.parse([self.header], self.config)
Test.global_ns = declarations.get_global_namespace(decls)
Test.xml_generator_from_xml_file = \
self.config.xml_generator_from_xml_file
self.xml_generator_from_xml_file = Test.xml_generator_from_xml_file

self.global_ns = Test.global_ns

def test(self):
"""
Check the comment parsing
"""

if self.config.castxml_epic_version != 1:
# Run this test only with castxml epic version == 1
return
tnamespace = self.global_ns.namespace("deprecation")

tenumeration = tnamespace.enumeration("com_enum")
self.assertIn("deprecation", dir(tenumeration))
self._check_text_content('Enumeration is Deprecated',
tenumeration.deprecation)

tclass = tnamespace.class_("test")
self.assertIn("deprecation", dir(tclass))
self._check_text_content("Test class Deprecated", tclass.deprecation)

tmethod = tclass.member_functions()[0]
tmethod_dep = tclass.member_functions()[1]

self.assertIn("deprecation", dir(tmethod))
self.assertIsNone(tmethod.deprecation)
self._check_text_content("Function is deprecated",
tmethod_dep.deprecation)

tconstructor = tclass.constructors()[0]
tconstructor_dep = tclass.constructors()[1]

self.assertIsNone(tconstructor.deprecation)
self.assertIn("deprecation", dir(tconstructor_dep))
self._check_text_content("One arg constructor is Deprecated",
tconstructor_dep.deprecation)


def create_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
return suite


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


if __name__ == "__main__":
run_suite()