398 @param module module name associated with the source text |
398 @param module module name associated with the source text |
399 @type str |
399 @type str |
400 @return dictionary containing the extracted data |
400 @return dictionary containing the extracted data |
401 @rtype dict |
401 @rtype dict |
402 """ |
402 """ |
|
403 def calculateEndline(lineno, lines, indent): |
|
404 """ |
|
405 Function to calculate the end line of a class or method/function. |
|
406 |
|
407 @param lineno line number to start at |
|
408 @type int |
|
409 @param lines list of source lines |
|
410 @type list of str |
|
411 @param indent indent length the class/method/function definition |
|
412 @type int |
|
413 @return end line of the class/method/function |
|
414 @rtype int |
|
415 """ |
|
416 # start with zero based line after start line |
|
417 while lineno < len(lines): |
|
418 line = lines[lineno] |
|
419 if line.strip(): |
|
420 # line contains some text |
|
421 lineIndent = _indent(line.replace(line.lstrip(), "")) |
|
422 if lineIndent <= indent: |
|
423 return lineno |
|
424 lineno += 1 |
|
425 |
|
426 # nothing found |
|
427 return -1 |
|
428 |
403 # convert eol markers the Python style |
429 # convert eol markers the Python style |
404 src = src.replace("\r\n", "\n").replace("\r", "\n") |
430 src = src.replace("\r\n", "\n").replace("\r", "\n") |
|
431 srcLines = src.splitlines() |
405 |
432 |
406 dictionary = {} |
433 dictionary = {} |
407 dict_counts = {} |
434 dict_counts = {} |
408 |
435 |
409 classstack = [] # stack of (class, indent) pairs |
436 classstack = [] # stack of (class, indent) pairs |
491 meth_name = "{0}_{1:d}".format( |
517 meth_name = "{0}_{1:d}".format( |
492 meth_name, dict_counts[meth_name]) |
518 meth_name, dict_counts[meth_name]) |
493 else: |
519 else: |
494 dict_counts[meth_name] = 0 |
520 dict_counts[meth_name] = 0 |
495 dictionary[meth_name] = f |
521 dictionary[meth_name] = f |
496 if not classstack: |
522 endlineno = calculateEndline(lineno, srcLines, thisindent) |
497 if lastGlobalEntry: |
523 f.setEndLine(endlineno) |
498 lastGlobalEntry.setEndLine(lineno - 1) |
|
499 lastGlobalEntry = f |
|
500 if cur_obj and isinstance(cur_obj, Function): |
524 if cur_obj and isinstance(cur_obj, Function): |
501 cur_obj.setEndLine(lineno - 1) |
525 cur_obj.setEndLine(lineno - 1) |
502 cur_obj = f |
526 cur_obj = f |
503 classstack.append((f, thisindent)) # Marker for nested fns |
527 classstack.append((f, thisindent)) # Marker for nested fns |
504 |
528 |
549 names.append(n) |
573 names.append(n) |
550 inherit = names |
574 inherit = names |
551 # remember this class |
575 # remember this class |
552 cur_class = Class(module, class_name, inherit, |
576 cur_class = Class(module, class_name, inherit, |
553 file, lineno) |
577 file, lineno) |
|
578 endlineno = calculateEndline(lineno, srcLines, thisindent) |
|
579 cur_class.setEndLine(endlineno) |
554 if not classstack: |
580 if not classstack: |
555 if class_name in dict_counts: |
581 if class_name in dict_counts: |
556 dict_counts[class_name] += 1 |
582 dict_counts[class_name] += 1 |
557 class_name = "{0}_{1:d}".format( |
583 class_name = "{0}_{1:d}".format( |
558 class_name, dict_counts[class_name]) |
584 class_name, dict_counts[class_name]) |
559 else: |
585 else: |
560 dict_counts[class_name] = 0 |
586 dict_counts[class_name] = 0 |
561 dictionary[class_name] = cur_class |
587 dictionary[class_name] = cur_class |
562 else: |
588 else: |
563 classstack[-1][0]._addclass(class_name, cur_class) |
589 classstack[-1][0]._addclass(class_name, cur_class) |
564 if not classstack: |
|
565 if lastGlobalEntry: |
|
566 lastGlobalEntry.setEndLine(lineno - 1) |
|
567 lastGlobalEntry = cur_class |
|
568 classstack.append((cur_class, thisindent)) |
590 classstack.append((cur_class, thisindent)) |
569 |
591 |
570 elif m.start("Attribute") >= 0: |
592 elif m.start("Attribute") >= 0: |
571 lineno = lineno + src.count('\n', last_lineno_pos, start) |
593 lineno = lineno + src.count('\n', last_lineno_pos, start) |
572 last_lineno_pos = start |
594 last_lineno_pos = start |
601 if "@@Globals@@" not in dictionary: |
623 if "@@Globals@@" not in dictionary: |
602 dictionary["@@Globals@@"] = ClbrBaseClasses.ClbrBase( |
624 dictionary["@@Globals@@"] = ClbrBaseClasses.ClbrBase( |
603 module, "Globals", file, lineno) |
625 module, "Globals", file, lineno) |
604 dictionary["@@Globals@@"]._addglobal( |
626 dictionary["@@Globals@@"]._addglobal( |
605 Attribute(module, variable_name, file, lineno)) |
627 Attribute(module, variable_name, file, lineno)) |
606 if lastGlobalEntry: |
|
607 lastGlobalEntry.setEndLine(lineno - 1) |
|
608 lastGlobalEntry = None |
|
609 else: |
628 else: |
610 index = -1 |
629 index = -1 |
611 while index >= -len(classstack): |
630 while index >= -len(classstack): |
612 if classstack[index][1] >= thisindent: |
631 if classstack[index][1] >= thisindent: |
613 index -= 1 |
632 index -= 1 |