Skip to content

Commit ad6345c

Browse files
authored
Merge pull request #130 from josephsnyder/add_castxml_commenting
Add comment parsing from CastXML.
2 parents aa8661e + 1a24522 commit ad6345c

File tree

10 files changed

+380
-4
lines changed

10 files changed

+380
-4
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
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/f43ef30267c850872cf1e8ea8594c5dc6a1beb7c343d63875662ee7c648dac4f9214c915499ef2e1148f2b5f866e4c518ca1a21fb5055baba7d62f4f69097ba0/download | tar zxf - -C ~/
78+
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/b580374e48d4df68f8ebef6d0e71cd8cc3f2dfa28f0090e07cc043d11cee308aeea480092fe2e93f2d4c58f822a5c013c1c7121964372d28ee4069949a378b4c/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/88c9b5954ca7417f7b519f3006dc6fe4bd194af0837168edc30007a41eaae6d4eee97cef2a72747432af14941c7f60333b77c25e208b2540dcde2d61e0d0e6f3/download | tar zxf - -C ~/
82+
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/e5962372508abd295f8a8110a20142bcbd93c235f72afba34b0abb3918a623f27465a7674b5532320e770f56fddb99019f5c47b254cea9f862a2df35630c2879/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/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

pygccxml/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)

pygccxml/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()

pygccxml/declarations/declaration.py

Lines changed: 10 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,7 @@ 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()
4042

4143
def __str__(self):
4244
"""
@@ -338,3 +340,11 @@ def _warn_deprecated():
338340
"Please use the declarations.get_dependencies_from_decl()" +
339341
"function instead.\n",
340342
DeprecationWarning)
343+
344+
@property
345+
def comment(self):
346+
return self._comment
347+
348+
@comment.setter
349+
def comment(self, comment):
350+
self._comment = comment

pygccxml/parser/linker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def visit_destructor(self):
107107
def visit_member_operator(self):
108108
self.__link_calldef()
109109

110+
def visit_comment(self):
111+
pass
112+
110113
def visit_casting_operator(self):
111114
self.__link_calldef()
112115
# FIXME: is the patch still needed as the demangled name support has

0 commit comments

Comments
 (0)