Skip to content

Commit da5b7f0

Browse files
committed
Add additional properties to comment.
Add the additional properties from CastXML. Add location as a proper property Add type checks for the non-int properties.
1 parent 8de896b commit da5b7f0

File tree

2 files changed

+98
-10
lines changed

2 files changed

+98
-10
lines changed

pygccxml/declarations/comment.py

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
from . import declaration
13+
from . import location as pygccxml_location
1314

1415

1516
class comment_t(declaration.declaration_t):
@@ -22,31 +23,110 @@ def __init__(self, name='', declarations=None):
2223
2324
"""
2425
declaration.declaration_t.__init__(self, name)
25-
self.location = {}
26-
self._start_line = 0
26+
self._location = {}
27+
self._begin_line = 0
28+
self._begin_column = 0
29+
self._begin_offset = 0
2730
self._end_line = 0
31+
self._end_column = 0
32+
self._end_offset = 0
2833
self._text = ""
2934

3035
@property
31-
def start_line(self):
32-
return self._start_line
36+
def location(self):
37+
"""An instance of the location_t class
38+
which contains the file where the
39+
comment can be found.
40+
@type: location_t """
41+
return self._location
3342

34-
@start_line.setter
35-
def start_line(self, start_line):
36-
self._start_line = int(start_line)
43+
@location.setter
44+
def location(self, location):
45+
if not isinstance(location, pygccxml_location.location_t):
46+
raise ValueError(
47+
"'location' must be a location_t (got a %s instead)" %
48+
type(location).__name__)
49+
self._location = location
50+
51+
@property
52+
def begin_line(self):
53+
"""An integer value which corresponds to the
54+
line of the file where the comment begins
55+
@type: int """
56+
return self._begin_line
57+
58+
@begin_line.setter
59+
def begin_line(self, begin_line):
60+
self._begin_line = int(begin_line)
61+
62+
@property
63+
def begin_offset(self):
64+
"""An integer value which corresponds to the
65+
line of the file where the comment begins
66+
@type: int """
67+
return self._begin_offset
68+
69+
@begin_offset.setter
70+
def begin_offset(self, begin_offset):
71+
self._begin_offset = int(begin_offset)
72+
73+
@property
74+
def begin_column(self):
75+
"""An integer value which corresponds to the
76+
line of the file where the comment begins
77+
@type: int """
78+
return self._begin_column
79+
80+
@begin_column.setter
81+
def begin_column(self, begin_column):
82+
self._begin_column = int(begin_column)
3783

3884
@property
3985
def end_line(self):
86+
"""An integer value which corresponds to the
87+
line of the file where the comment ends
88+
@type: int """
4089
return self._end_line
4190

4291
@end_line.setter
4392
def end_line(self, end_line):
4493
self._end_line = int(end_line)
4594

95+
@property
96+
def end_offset(self):
97+
"""An integer value which corresponds to the
98+
line of the file where the comment ends
99+
@type: int """
100+
return self._end_offset
101+
102+
@end_offset.setter
103+
def end_offset(self, end_offset):
104+
self._end_offset = int(end_offset)
105+
106+
@property
107+
def end_column(self):
108+
"""An integer value which corresponds to the
109+
coloumn of character in a line of the file
110+
where the comment ends
111+
@type: int """
112+
return self._end_column
113+
114+
@end_column.setter
115+
def end_column(self, end_column):
116+
self._end_column = int(end_column)
117+
46118
@property
47119
def text(self):
120+
"""An list of strings where each entry in the list
121+
is one line of the comment. These comments will not
122+
end in a newline
123+
@type: list """
48124
return self._text
49125

50126
@text.setter
51127
def text(self, text):
128+
if not isinstance(text, list):
129+
raise ValueError(
130+
"'text' must be a list (got a %s instead)" %
131+
type(text).__name__)
52132
self._text = text

pygccxml/parser/scanner.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@
2020
XML_AN_ATTRIBUTES = "attributes"
2121
XML_AN_BASE_TYPE = "basetype"
2222
XML_AN_BASES = "bases"
23+
XML_AN_BEGIN_COLUMN = "begin_column"
24+
XML_AN_BEGIN_LINE = "begin_line"
25+
XML_AN_BEGIN_OFFSET = "begin_offset"
2326
XML_AN_BITS = "bits"
2427
XML_AN_COMMENT = "comment"
2528
XML_AN_CONST = "const"
2629
XML_AN_CONTEXT = "context"
2730
XML_AN_CVS_REVISION = "cvs_revision"
2831
XML_AN_CASTXML_FORMAT = "format"
2932
XML_AN_DEFAULT = "default"
33+
XML_AN_END_COLUMN = "end_column"
3034
XML_AN_END_LINE = "end_line"
35+
XML_AN_END_OFFSET = "end_offset"
3136
XML_AN_EXPLICIT = "explicit"
3237
XML_AN_EXTERN = "extern"
3338
XML_AN_FILE = "file"
@@ -36,7 +41,6 @@
3641
XML_AN_INIT = "init"
3742
XML_AN_INLINE = "inline"
3843
XML_AN_LINE = "line"
39-
XML_AN_BEGIN_LINE = "begin_line"
4044
XML_AN_MANGLED = "mangled"
4145
XML_AN_MAX = "max"
4246
XML_AN_MEMBERS = "members"
@@ -618,8 +622,12 @@ def __read_casting_operator(self, attrs):
618622

619623
def __read_comment(self, attrs):
620624
comment = self.__decl_factory.create_comment()
621-
comment._start_line = int(attrs.get(XML_AN_BEGIN_LINE))
622-
comment._end_line = int(attrs.get(XML_AN_END_LINE))
625+
comment.begin_line = int(attrs.get(XML_AN_BEGIN_LINE))
626+
comment.end_line = int(attrs.get(XML_AN_END_LINE))
627+
comment.begin_offset = int(attrs.get(XML_AN_BEGIN_OFFSET))
628+
comment.end_offset = int(attrs.get(XML_AN_END_OFFSET))
629+
comment.begin_column = int(attrs.get(XML_AN_BEGIN_COLUMN))
630+
comment.end_column = int(attrs.get(XML_AN_END_COLUMN))
623631
self.__read_location(comment, attrs, self.__name_attrs_to_skip)
624632
return comment
625633

0 commit comments

Comments
 (0)