Utilities/ClassBrowsers/idlclbr.py

changeset 2769
8cbebde7a984
parent 2302
f29e9405c851
child 2791
a9577f248f04
child 2965
d133c7edd88a
equal deleted inserted replaced
2768:eab35f6e709f 2769:8cbebde7a984
210 # can't do anything with this module 210 # can't do anything with this module
211 _modules[module] = dict 211 _modules[module] = dict
212 return dict 212 return dict
213 213
214 lineno, last_lineno_pos = 1, 0 214 lineno, last_lineno_pos = 1, 0
215 lastGlobalEntry = None
216 cur_obj = None
215 i = 0 217 i = 0
216 while True: 218 while True:
217 m = _getnext(src, i) 219 m = _getnext(src, i)
218 if not m: 220 if not m:
219 break 221 break
230 lineno = lineno + src.count('\n', last_lineno_pos, start) 232 lineno = lineno + src.count('\n', last_lineno_pos, start)
231 last_lineno_pos = start 233 last_lineno_pos = start
232 # close all interfaces/modules indented at least as much 234 # close all interfaces/modules indented at least as much
233 while classstack and \ 235 while classstack and \
234 classstack[-1][1] >= thisindent: 236 classstack[-1][1] >= thisindent:
237 if classstack[-1][0] is not None:
238 # record the end line
239 classstack[-1][0].setEndLine(lineno - 1)
235 del classstack[-1] 240 del classstack[-1]
236 if classstack: 241 if classstack:
237 # it's an interface/module method 242 # it's an interface/module method
238 cur_class = classstack[-1][0] 243 cur_class = classstack[-1][0]
239 if isinstance(cur_class, Interface) or isinstance(cur_class, Module): 244 if isinstance(cur_class, Interface) or isinstance(cur_class, Module):
240 # it's a method 245 # it's a method
241 f = Function(None, meth_name, 246 f = Function(None, meth_name,
242 file, lineno, meth_sig) 247 file, lineno, meth_sig)
243 cur_class._addmethod(meth_name, f) 248 cur_class._addmethod(meth_name, f)
244 # else it's a nested def 249 # else it's a nested def
250 else:
251 f = None
245 else: 252 else:
246 # it's a function 253 # it's a function
247 f = Function(module, meth_name, 254 f = Function(module, meth_name,
248 file, lineno, meth_sig) 255 file, lineno, meth_sig)
249 if meth_name in dict_counts: 256 if meth_name in dict_counts:
250 dict_counts[meth_name] += 1 257 dict_counts[meth_name] += 1
251 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) 258 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name])
252 else: 259 else:
253 dict_counts[meth_name] = 0 260 dict_counts[meth_name] = 0
254 dict[meth_name] = f 261 dict[meth_name] = f
262 if not classstack:
263 if lastGlobalEntry:
264 lastGlobalEntry.setEndLine(lineno - 1)
265 lastGlobalEntry = f
266 if cur_obj and isinstance(cur_obj, Function):
267 cur_obj.setEndLine(lineno - 1)
268 cur_obj = f
255 classstack.append((f, thisindent)) # Marker for nested fns 269 classstack.append((f, thisindent)) # Marker for nested fns
256 270
257 elif m.start("String") >= 0: 271 elif m.start("String") >= 0:
258 pass 272 pass
259 273
265 thisindent = indent 279 thisindent = indent
266 indent += 1 280 indent += 1
267 # close all interfaces/modules indented at least as much 281 # close all interfaces/modules indented at least as much
268 while classstack and \ 282 while classstack and \
269 classstack[-1][1] >= thisindent: 283 classstack[-1][1] >= thisindent:
284 if classstack[-1][0] is not None:
285 # record the end line
286 classstack[-1][0].setEndLine(lineno - 1)
270 del classstack[-1] 287 del classstack[-1]
271 lineno = lineno + src.count('\n', last_lineno_pos, start) 288 lineno = lineno + src.count('\n', last_lineno_pos, start)
272 last_lineno_pos = start 289 last_lineno_pos = start
273 class_name = m.group("InterfaceName") 290 class_name = m.group("InterfaceName")
274 inherit = m.group("InterfaceSupers") 291 inherit = m.group("InterfaceSupers")
282 if not classstack: 299 if not classstack:
283 dict[class_name] = cur_class 300 dict[class_name] = cur_class
284 else: 301 else:
285 cls = classstack[-1][0] 302 cls = classstack[-1][0]
286 cls._addclass(class_name, cur_class) 303 cls._addclass(class_name, cur_class)
304 if not classstack:
305 if lastGlobalEntry:
306 lastGlobalEntry.setEndLine(lineno - 1)
307 lastGlobalEntry = cur_class
308 if cur_obj and isinstance(cur_obj, Function):
309 cur_obj.setEndLine(lineno - 1)
310 cur_obj = cur_class
287 classstack.append((cur_class, thisindent)) 311 classstack.append((cur_class, thisindent))
288 312
289 elif m.start("Module") >= 0: 313 elif m.start("Module") >= 0:
290 # we found a module definition 314 # we found a module definition
291 thisindent = indent 315 thisindent = indent
292 indent += 1 316 indent += 1
293 # close all interfaces/modules indented at least as much 317 # close all interfaces/modules indented at least as much
294 while classstack and \ 318 while classstack and \
295 classstack[-1][1] >= thisindent: 319 classstack[-1][1] >= thisindent:
320 if classstack[-1][0] is not None:
321 # record the end line
322 classstack[-1][0].setEndLine(lineno - 1)
296 del classstack[-1] 323 del classstack[-1]
297 lineno = lineno + src.count('\n', last_lineno_pos, start) 324 lineno = lineno + src.count('\n', last_lineno_pos, start)
298 last_lineno_pos = start 325 last_lineno_pos = start
299 module_name = m.group("ModuleName") 326 module_name = m.group("ModuleName")
300 # remember this module 327 # remember this module
301 cur_class = Module(module, module_name, file, lineno) 328 cur_class = Module(module, module_name, file, lineno)
302 if not classstack: 329 if not classstack:
303 dict[module_name] = cur_class 330 dict[module_name] = cur_class
331 if lastGlobalEntry:
332 lastGlobalEntry.setEndLine(lineno - 1)
333 lastGlobalEntry = cur_class
334 if cur_obj and isinstance(cur_obj, Function):
335 cur_obj.setEndLine(lineno - 1)
336 cur_obj = cur_class
304 classstack.append((cur_class, thisindent)) 337 classstack.append((cur_class, thisindent))
305 338
306 elif m.start("Attribute") >= 0: 339 elif m.start("Attribute") >= 0:
307 lineno = lineno + src.count('\n', last_lineno_pos, start) 340 lineno = lineno + src.count('\n', last_lineno_pos, start)
308 last_lineno_pos = start 341 last_lineno_pos = start
319 attr.setPrivate() 352 attr.setPrivate()
320 classstack[index][0]._addattribute(attr) 353 classstack[index][0]._addattribute(attr)
321 break 354 break
322 else: 355 else:
323 index -= 1 356 index -= 1
357 if lastGlobalEntry:
358 lastGlobalEntry.setEndLine(lineno - 1)
359 lastGlobalEntry = None
324 360
325 elif m.start("Begin") >= 0: 361 elif m.start("Begin") >= 0:
326 # a begin of a block we are not interested in 362 # a begin of a block we are not interested in
327 indent += 1 363 indent += 1
328 364

eric ide

mercurial