Utilities/ClassBrowsers/rbclbr.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2525
8b507a9a2d40
parent 2769
8cbebde7a984
child 3057
10516539f238
equal deleted inserted replaced
2790:6686a3326df8 2791:a9577f248f04
281 # can't do anything with this module 281 # can't do anything with this module
282 _modules[module] = dict 282 _modules[module] = dict
283 return dict 283 return dict
284 284
285 lineno, last_lineno_pos = 1, 0 285 lineno, last_lineno_pos = 1, 0
286 cur_obj = None
287 lastGlobalEntry = None
286 i = 0 288 i = 0
287 while True: 289 while True:
288 m = _getnext(src, i) 290 m = _getnext(src, i)
289 if not m: 291 if not m:
290 break 292 break
307 elif meth_name.startswith('self::'): 309 elif meth_name.startswith('self::'):
308 meth_name = meth_name[6:] 310 meth_name = meth_name[6:]
309 # close all classes/modules indented at least as much 311 # close all classes/modules indented at least as much
310 while classstack and \ 312 while classstack and \
311 classstack[-1][1] >= thisindent: 313 classstack[-1][1] >= thisindent:
314 if classstack[-1][0] is not None:
315 # record the end line
316 classstack[-1][0].setEndLine(lineno - 1)
312 del classstack[-1] 317 del classstack[-1]
313 while acstack and \ 318 while acstack and \
314 acstack[-1][1] >= thisindent: 319 acstack[-1][1] >= thisindent:
315 del acstack[-1] 320 del acstack[-1]
316 if classstack: 321 if classstack:
341 dict_counts[meth_name] += 1 346 dict_counts[meth_name] += 1
342 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) 347 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name])
343 else: 348 else:
344 dict_counts[meth_name] = 0 349 dict_counts[meth_name] = 0
345 dict[meth_name] = f 350 dict[meth_name] = f
351 if not classstack:
352 if lastGlobalEntry:
353 lastGlobalEntry.setEndLine(lineno - 1)
354 lastGlobalEntry = f
355 if cur_obj and isinstance(cur_obj, Function):
356 cur_obj.setEndLine(lineno - 1)
357 cur_obj = f
346 classstack.append((f, thisindent)) # Marker for nested fns 358 classstack.append((f, thisindent)) # Marker for nested fns
347 359
348 elif m.start("String") >= 0: 360 elif m.start("String") >= 0:
349 pass 361 pass
350 362
356 368
357 elif m.start("Class") >= 0: 369 elif m.start("Class") >= 0:
358 # we found a class definition 370 # we found a class definition
359 thisindent = indent 371 thisindent = indent
360 indent += 1 372 indent += 1
373 lineno = lineno + src.count('\n', last_lineno_pos, start)
374 last_lineno_pos = start
361 # close all classes/modules indented at least as much 375 # close all classes/modules indented at least as much
362 while classstack and \ 376 while classstack and \
363 classstack[-1][1] >= thisindent: 377 classstack[-1][1] >= thisindent:
378 if classstack[-1][0] is not None:
379 # record the end line
380 classstack[-1][0].setEndLine(lineno - 1)
364 del classstack[-1] 381 del classstack[-1]
365 lineno = lineno + src.count('\n', last_lineno_pos, start)
366 last_lineno_pos = start
367 class_name = m.group("ClassName") or m.group("ClassName2") 382 class_name = m.group("ClassName") or m.group("ClassName2")
368 inherit = m.group("ClassSupers") 383 inherit = m.group("ClassSupers")
369 if inherit: 384 if inherit:
370 # the class inherits from other classes 385 # the class inherits from other classes
371 inherit = inherit[1:].strip() 386 inherit = inherit[1:].strip()
384 cur_class = cls.classes[class_name] 399 cur_class = cls.classes[class_name]
385 elif cls.name == class_name or class_name == "self": 400 elif cls.name == class_name or class_name == "self":
386 cur_class = cls 401 cur_class = cls
387 else: 402 else:
388 cls._addclass(class_name, cur_class) 403 cls._addclass(class_name, cur_class)
404 if not classstack:
405 if lastGlobalEntry:
406 lastGlobalEntry.setEndLine(lineno - 1)
407 lastGlobalEntry = cur_class
408 cur_obj = cur_class
389 classstack.append((cur_class, thisindent)) 409 classstack.append((cur_class, thisindent))
390 while acstack and \ 410 while acstack and \
391 acstack[-1][1] >= thisindent: 411 acstack[-1][1] >= thisindent:
392 del acstack[-1] 412 del acstack[-1]
393 acstack.append(["public", thisindent]) # default access control is 'public' 413 acstack.append(["public", thisindent]) # default access control is 'public'
394 414
395 elif m.start("Module") >= 0: 415 elif m.start("Module") >= 0:
396 # we found a module definition 416 # we found a module definition
397 thisindent = indent 417 thisindent = indent
398 indent += 1 418 indent += 1
419 lineno = lineno + src.count('\n', last_lineno_pos, start)
420 last_lineno_pos = start
399 # close all classes/modules indented at least as much 421 # close all classes/modules indented at least as much
400 while classstack and \ 422 while classstack and \
401 classstack[-1][1] >= thisindent: 423 classstack[-1][1] >= thisindent:
424 if classstack[-1][0] is not None:
425 # record the end line
426 classstack[-1][0].setEndLine(lineno - 1)
402 del classstack[-1] 427 del classstack[-1]
403 lineno = lineno + src.count('\n', last_lineno_pos, start)
404 last_lineno_pos = start
405 module_name = m.group("ModuleName") 428 module_name = m.group("ModuleName")
406 # remember this class 429 # remember this class
407 cur_class = Module(module, module_name, file, lineno) 430 cur_class = Module(module, module_name, file, lineno)
408 if not classstack: 431 if not classstack:
409 if module_name in dict: 432 if module_name in dict:
416 cur_class = cls.classes[module_name] 439 cur_class = cls.classes[module_name]
417 elif cls.name == module_name: 440 elif cls.name == module_name:
418 cur_class = cls 441 cur_class = cls
419 else: 442 else:
420 cls._addclass(module_name, cur_class) 443 cls._addclass(module_name, cur_class)
444 if not classstack:
445 if lastGlobalEntry:
446 lastGlobalEntry.setEndLine(lineno - 1)
447 lastGlobalEntry = cur_class
448 cur_obj = cur_class
421 classstack.append((cur_class, thisindent)) 449 classstack.append((cur_class, thisindent))
422 while acstack and \ 450 while acstack and \
423 acstack[-1][1] >= thisindent: 451 acstack[-1][1] >= thisindent:
424 del acstack[-1] 452 del acstack[-1]
425 acstack.append(["public", thisindent]) # default access control is 'public' 453 acstack.append(["public", thisindent]) # default access control is 'public'
472 attr = Attribute(module, m.group("AttributeName"), file, lineno) 500 attr = Attribute(module, m.group("AttributeName"), file, lineno)
473 classstack[index][0]._addattribute(attr) 501 classstack[index][0]._addattribute(attr)
474 break 502 break
475 else: 503 else:
476 index -= 1 504 index -= 1
505 if lastGlobalEntry:
506 lastGlobalEntry.setEndLine(lineno - 1)
507 lastGlobalEntry = None
477 508
478 elif m.start("Attr") >= 0: 509 elif m.start("Attr") >= 0:
479 lineno = lineno + src.count('\n', last_lineno_pos, start) 510 lineno = lineno + src.count('\n', last_lineno_pos, start)
480 last_lineno_pos = start 511 last_lineno_pos = start
481 index = -1 512 index = -1

eric ide

mercurial