Mercurial > octave
comparison libinterp/parse-tree/pt-classdef.cc @ 28511:59dfd9ed72a3 stable
capture comments for classdef classes, properties, events, and enumerations
* parse.h, oct-parse.yy: Refactor parser rules for collecting comments
and docstrings for classdef parse tree elements.
* pt-classdef.h, pt-classdef.cc
(tree_classdef_property, tree_classdef_event, tree_classdef_enum):
Store comments and docstrings and provide access to them.
(tree_classdef_body): Store docstring for classdef object.
(tree_classdef): Provide access to classdef docstring from classdef
body object.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 28 May 2020 13:48:37 -0400 |
parents | bd51beb6205e |
children | 0a5b15007766 |
comparison
equal
deleted
inserted
replaced
28510:a3ea758870dc | 28511:59dfd9ed72a3 |
---|---|
25 | 25 |
26 #if defined (HAVE_CONFIG_H) | 26 #if defined (HAVE_CONFIG_H) |
27 # include "config.h" | 27 # include "config.h" |
28 #endif | 28 #endif |
29 | 29 |
30 #include <iostream> | |
31 | |
30 #include "ov.h" | 32 #include "ov.h" |
31 #include "ov-classdef.h" | 33 #include "ov-classdef.h" |
32 #include "pt-classdef.h" | 34 #include "pt-classdef.h" |
33 #include "pt-eval.h" | 35 #include "pt-eval.h" |
34 | 36 |
117 } | 119 } |
118 } | 120 } |
119 | 121 |
120 // Classdef property | 122 // Classdef property |
121 | 123 |
124 std::string check_for_doc_string (comment_list *comments) | |
125 { | |
126 // If the comment list ends in a block comment or full-line comment, | |
127 // then it is the doc string for this property. | |
128 | |
129 if (comments) | |
130 { | |
131 comment_elt last_elt = comments->back (); | |
132 | |
133 if (last_elt.is_block () || last_elt.is_full_line ()) | |
134 return last_elt.text (); | |
135 } | |
136 | |
137 return ""; | |
138 } | |
139 | |
140 tree_classdef_property::tree_classdef_property (tree_identifier *i, | |
141 comment_list *comments) | |
142 : m_id (i), m_expr (nullptr), m_comments (comments), | |
143 m_doc_string (check_for_doc_string (m_comments)) | |
144 { } | |
145 | |
146 tree_classdef_property::tree_classdef_property (tree_identifier *i, | |
147 tree_expression *e, | |
148 comment_list *comments) | |
149 : m_id (i), m_expr (e), m_comments (comments), | |
150 m_doc_string (check_for_doc_string (m_comments)) | |
151 { } | |
152 | |
122 // Classdef property_list | 153 // Classdef property_list |
123 | 154 |
124 tree_classdef_property_list::~tree_classdef_property_list (void) | 155 tree_classdef_property_list::~tree_classdef_property_list (void) |
125 { | 156 { |
126 while (! empty ()) | 157 while (! empty ()) |
137 | 168 |
138 // Classdef methods_block | 169 // Classdef methods_block |
139 | 170 |
140 // Classdef event | 171 // Classdef event |
141 | 172 |
173 tree_classdef_event::tree_classdef_event (tree_identifier *i, | |
174 comment_list *comments) | |
175 : m_id (i), m_comments (comments), | |
176 m_doc_string (check_for_doc_string (m_comments)) | |
177 { } | |
178 | |
142 // Classdef events_list | 179 // Classdef events_list |
143 | 180 |
144 tree_classdef_events_list::~tree_classdef_events_list (void) | 181 tree_classdef_events_list::~tree_classdef_events_list (void) |
145 { | 182 { |
146 while (! empty ()) | 183 while (! empty ()) |
153 | 190 |
154 // Classdef events_block | 191 // Classdef events_block |
155 | 192 |
156 // Classdef enum | 193 // Classdef enum |
157 | 194 |
195 tree_classdef_enum::tree_classdef_enum (tree_identifier *i, | |
196 tree_expression *e, | |
197 comment_list *comments) | |
198 : m_id (i), m_expr (e), m_comments (comments), | |
199 m_doc_string (check_for_doc_string (m_comments)) | |
200 { } | |
201 | |
158 // Classdef enum_list | 202 // Classdef enum_list |
159 | 203 |
160 tree_classdef_enum_list::~tree_classdef_enum_list (void) | 204 tree_classdef_enum_list::~tree_classdef_enum_list (void) |
161 { | 205 { |
162 while (! empty ()) | 206 while (! empty ()) |
169 | 213 |
170 // Classdef enum_block | 214 // Classdef enum_block |
171 | 215 |
172 // Classdef body | 216 // Classdef body |
173 | 217 |
218 tree_classdef_body::tree_classdef_body (void) | |
219 : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst () | |
220 { } | |
221 | |
222 tree_classdef_body::tree_classdef_body (tree_classdef_properties_block *pb) | |
223 : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (), | |
224 m_doc_string (pb ? get_doc_string (pb->leading_comment ()) : "") | |
225 { | |
226 append (pb); | |
227 } | |
228 | |
229 tree_classdef_body::tree_classdef_body (tree_classdef_methods_block *mb) | |
230 : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (), | |
231 m_doc_string (mb ? get_doc_string (mb->leading_comment ()) : "") | |
232 { | |
233 append (mb); | |
234 } | |
235 | |
236 tree_classdef_body::tree_classdef_body (tree_classdef_events_block *evb) | |
237 : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (), | |
238 m_doc_string (evb ? get_doc_string (evb->leading_comment ()) : "") | |
239 { | |
240 append (evb); | |
241 } | |
242 | |
243 tree_classdef_body::tree_classdef_body (tree_classdef_enum_block *enb) | |
244 : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (), | |
245 m_doc_string (enb ? get_doc_string (enb->leading_comment ()) : "") | |
246 { | |
247 append (enb); | |
248 } | |
249 | |
174 tree_classdef_body::~tree_classdef_body (void) | 250 tree_classdef_body::~tree_classdef_body (void) |
175 { | 251 { |
176 while (! m_properties_lst.empty ()) | 252 while (! m_properties_lst.empty ()) |
177 { | 253 { |
178 auto p = m_properties_lst.begin (); | 254 auto p = m_properties_lst.begin (); |
198 { | 274 { |
199 auto p = m_enum_lst.begin (); | 275 auto p = m_enum_lst.begin (); |
200 delete *p; | 276 delete *p; |
201 m_enum_lst.erase (p); | 277 m_enum_lst.erase (p); |
202 } | 278 } |
279 } | |
280 | |
281 std::string | |
282 tree_classdef_body::get_doc_string (comment_list *comments) const | |
283 { | |
284 // Grab the first comment from the list and use it as the doc string | |
285 // for this classdef body. | |
286 | |
287 if (comments) | |
288 { | |
289 comment_elt first_elt = comments->front (); | |
290 | |
291 return first_elt.text (); | |
292 } | |
293 | |
294 return ""; | |
203 } | 295 } |
204 | 296 |
205 // Classdef | 297 // Classdef |
206 | 298 |
207 octave_value | 299 octave_value |