Skip to content

Commit 6637e87

Browse files
pygccxml Upstreamthewtex
authored andcommitted
ENH: pygccxml v2.4.0 (reduced)
This corresponds to commit hash ce011e1bc57248d205cfda60dd51b3182acbe106 from upstream repository https://github.com/CastXML/pygccxml
1 parent f8322d7 commit 6637e87

File tree

12 files changed

+352
-40
lines changed

12 files changed

+352
-40
lines changed

__init__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Distributed under the Boost Software License, Version 1.0.
44
# See http://www.boost.org/LICENSE_1_0.txt
55

6-
"""Python CastXML or GCC-XML front end.
6+
"""Python CastXML front end.
77
88
This package provides functionality to extract and inspect
99
declarations from C/C++ header files. This is accomplished
10-
by invoking an external tool like CastXML or GCC-XML,
10+
by invoking an external tool like CastXML,
1111
which parses a header file and dumps the declarations as a
1212
XML file. This XML file is then read by pygccxml and the contents
1313
are made available as appropriate Python objects.
@@ -26,6 +26,7 @@
2626
2727
"""
2828

29+
import sys
2930
import warnings
3031

3132
from . import declarations
@@ -38,7 +39,16 @@
3839
# to know what is deprecated.
3940
warnings.simplefilter("always", DeprecationWarning)
4041

41-
# TODO:
42-
# 1. Add "explicit" property for constructors
42+
version = sys.version_info
4343

44-
__version__ = '2.0.1'
44+
if version < (3, 8):
45+
import importlib_metadata as metadata
46+
elif version < (3, 9, 10) or (3, 10, 0) <= version < (3, 10, 2):
47+
try:
48+
import importlib_metadata as metadata
49+
except ModuleNotFoundError:
50+
from importlib import metadata
51+
else:
52+
from importlib import metadata
53+
54+
__version__ = metadata.version("pygccxml")

declarations/calldef.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def __init__(
165165
self._calling_convention = None
166166
self._has_inline = None
167167
self._mangled = mangled
168+
self._overrides = None
168169

169170
def _get__cmp__call_items(self):
170171
"""
@@ -242,6 +243,16 @@ def optional_args(self):
242243
value"""
243244
return self.arguments[len(self.required_args):]
244245

246+
@property
247+
def overrides(self):
248+
"""If a function is marked as an overrides, contains
249+
the declaration which this function overrides."""
250+
return self._overrides
251+
252+
@overrides.setter
253+
def overrides(self, overrides):
254+
self._overrides = overrides
255+
245256
@property
246257
def does_throw(self):
247258
"""If False, than function does not throw any exception.

declarations/comment.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
"""
7+
Describe a C++ comment declaration.
8+
9+
"""
10+
11+
from . import location as pygccxml_location
12+
13+
14+
class comment_t(object):
15+
16+
def __init__(self, name='', declarations=None):
17+
"""
18+
Creates an object that describes a C++ comment declaration.
19+
20+
Args:
21+
22+
"""
23+
self._location = {}
24+
self._begin_line = 0
25+
self._begin_column = 0
26+
self._begin_offset = 0
27+
self._end_line = 0
28+
self._end_column = 0
29+
self._end_offset = 0
30+
self._text = ""
31+
32+
@property
33+
def location(self):
34+
"""An instance of the location_t class
35+
which contains the file where the
36+
comment can be found.
37+
@type: location_t """
38+
return self._location
39+
40+
@location.setter
41+
def location(self, location):
42+
if not isinstance(location, pygccxml_location.location_t):
43+
raise ValueError(
44+
"'location' must be a location_t (got a %s instead)" %
45+
type(location).__name__)
46+
self._location = location
47+
48+
@property
49+
def begin_line(self):
50+
"""An integer value which corresponds to the
51+
line of the file where the comment begins
52+
@type: int """
53+
return self._begin_line
54+
55+
@begin_line.setter
56+
def begin_line(self, begin_line):
57+
self._begin_line = int(begin_line)
58+
59+
@property
60+
def begin_offset(self):
61+
"""An integer value representing the
62+
number of bytes from the beginning of the
63+
file to the start of the comment
64+
@type: int """
65+
return self._begin_offset
66+
67+
@begin_offset.setter
68+
def begin_offset(self, begin_offset):
69+
self._begin_offset = int(begin_offset)
70+
71+
@property
72+
def begin_column(self):
73+
"""An integer value which corresponds to the
74+
column of the file where the comment begins
75+
@type: int """
76+
return self._begin_column
77+
78+
@begin_column.setter
79+
def begin_column(self, begin_column):
80+
self._begin_column = int(begin_column)
81+
82+
@property
83+
def end_line(self):
84+
"""An integer value which corresponds to the
85+
line of the file where the comment ends
86+
@type: int """
87+
return self._end_line
88+
89+
@end_line.setter
90+
def end_line(self, end_line):
91+
self._end_line = int(end_line)
92+
93+
@property
94+
def end_offset(self):
95+
"""An integer value representing the
96+
number of bytes from the beginning of the
97+
file to the end of the comment
98+
@type: int """
99+
return self._end_offset
100+
101+
@end_offset.setter
102+
def end_offset(self, end_offset):
103+
self._end_offset = int(end_offset)
104+
105+
@property
106+
def end_column(self):
107+
"""An integer value which corresponds to the
108+
column of character in a line of the file
109+
where the comment ends
110+
@type: int """
111+
return self._end_column
112+
113+
@end_column.setter
114+
def end_column(self, end_column):
115+
self._end_column = int(end_column)
116+
117+
@property
118+
def text(self):
119+
"""A list of strings where each entry in the list
120+
is one line of the comment. These comments will not
121+
end in a newline
122+
@type: list """
123+
return self._text
124+
125+
@text.setter
126+
def text(self, text):
127+
if not isinstance(text, list):
128+
raise ValueError(
129+
"'text' must be a list (got a %s instead)" %
130+
type(text).__name__)
131+
self._text = text

declarations/decl_factory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .calldef_members import destructor_t
1313
from .calldef_members import member_operator_t
1414
from .calldef_members import casting_operator_t
15+
from .comment import comment_t
1516
from .free_calldef import free_function_t
1617
from .free_calldef import free_operator_t
1718
from .enumeration import enumeration_t
@@ -89,3 +90,7 @@ def create_typedef(self, *arguments, **keywords):
8990
def create_variable(self, *arguments, **keywords):
9091
"""creates instance of class that describes variable declaration"""
9192
return variable_t(*arguments, **keywords)
93+
94+
def create_comment(self, *arguments, **keywords):
95+
"""creates instance of class that describes variable declaration"""
96+
return comment_t(*arguments, **keywords)

declarations/decl_visitor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ def visit_typedef(self):
5757

5858
def visit_variable(self):
5959
raise NotImplementedError()
60+
61+
def visit_comment(self):
62+
raise NotImplementedError()

declarations/declaration.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from . import declaration_utils
1515
from . import algorithms_cache
16+
from . import comment
1617

1718

1819
class declaration_t(object):
@@ -37,6 +38,8 @@ def __init__(
3738
self._cache = algorithms_cache.declaration_algs_cache_t()
3839
self._partial_name = None
3940
self._decorated_name = None
41+
self._comment = comment.comment_t()
42+
self._deprecation = None
4043

4144
def __str__(self):
4245
"""
@@ -338,3 +341,19 @@ def _warn_deprecated():
338341
"Please use the declarations.get_dependencies_from_decl()" +
339342
"function instead.\n",
340343
DeprecationWarning)
344+
345+
@property
346+
def comment(self):
347+
return self._comment
348+
349+
@comment.setter
350+
def comment(self, comment):
351+
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

declarations/type_traits.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -483,29 +483,21 @@ def is_fundamental(type_):
483483
string_equivalences = [
484484
(
485485
'::std::basic_string<char,std::char_traits<char>,'
486-
'std::allocator<char> >'),
487-
(
488-
'::std::basic_string<char, std::char_traits<char>, '
489-
'std::allocator<char> >'),
486+
'std::allocator<char>>'),
490487
'::std::basic_string<char>', '::std::string']
491488

492489
wstring_equivalences = [
493490
(
494491
'::std::basic_string<wchar_t,std::char_traits<wchar_t>,' +
495-
'std::allocator<wchar_t> >'),
496-
(
497-
'::std::basic_string<wchar_t, std::char_traits<wchar_t>, ' +
498-
'std::allocator<wchar_t> >'),
492+
'std::allocator<wchar_t>>'),
499493
'::std::basic_string<wchar_t>', '::std::wstring']
500494

501495
ostream_equivalences = [
502-
'::std::basic_ostream<char, std::char_traits<char> >',
503-
'::std::basic_ostream<char,std::char_traits<char> >',
496+
'::std::basic_ostream<char,std::char_traits<char>>',
504497
'::std::basic_ostream<char>', '::std::ostream']
505498

506499
wostream_equivalences = [
507-
'::std::basic_ostream<wchar_t, std::char_traits<wchar_t> >',
508-
'::std::basic_ostream<wchar_t,std::char_traits<wchar_t> >',
500+
'::std::basic_ostream<wchar_t,std::char_traits<wchar_t>>',
509501
'::std::basic_ostream<wchar_t>', '::std::wostream']
510502

511503

@@ -521,7 +513,7 @@ def is_std_string(type_):
521513
type_ = remove_alias(type_)
522514
type_ = remove_reference(type_)
523515
type_ = remove_cv(type_)
524-
return type_.decl_string in string_equivalences
516+
return type_.decl_string.replace(' ', '') in string_equivalences
525517

526518

527519
def is_std_wstring(type_):
@@ -536,7 +528,7 @@ def is_std_wstring(type_):
536528
type_ = remove_alias(type_)
537529
type_ = remove_reference(type_)
538530
type_ = remove_cv(type_)
539-
return type_.decl_string in wstring_equivalences
531+
return type_.decl_string.replace(' ', '') in wstring_equivalences
540532

541533

542534
def is_std_ostream(type_):
@@ -551,7 +543,7 @@ def is_std_ostream(type_):
551543
type_ = remove_alias(type_)
552544
type_ = remove_reference(type_)
553545
type_ = remove_cv(type_)
554-
return type_.decl_string in ostream_equivalences
546+
return type_.decl_string.replace(' ', '') in ostream_equivalences
555547

556548

557549
def is_std_wostream(type_):
@@ -566,4 +558,4 @@ def is_std_wostream(type_):
566558
type_ = remove_alias(type_)
567559
type_ = remove_reference(type_)
568560
type_ = remove_cv(type_)
569-
return type_.decl_string in wostream_equivalences
561+
return type_.decl_string.replace(' ', '') in wostream_equivalences

0 commit comments

Comments
 (0)