home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / browser2.zip / br-stat.el < prev    next >
Lisp/Scheme  |  1995-02-17  |  4KB  |  99 lines

  1. ;;; CLASS BROWSER FOR C++
  2. ;;; $Id: br-stat.el,v 3.1 1995/02/17 18:19:36 mmann Exp $
  3. ;;;
  4. ;;; **********************************************************************
  5. ;;; Copyright (C) 1993, 1994 Gerd Moellmann. All rights reserved.
  6. ;;; Altenbergstr. 6, D-40235 Duesseldorf, Germany
  7. ;;; 100025.3303@COMPUSERVE.COM
  8. ;;; Suggestions, comments and requests for improvements are welcome.
  9. ;;; **********************************************************************
  10. ;;;
  11. ;;; This version works with both Emacs version 18 and 19, and I want
  12. ;;; to keep it that way. It requires the CL-19 Common Lisp compatibility
  13. ;;; package for Emacs 18 and 19.
  14. ;;;
  15. ;;; This contains code that displays statistics for a class tree.
  16. ;;; 
  17.  
  18. ;; This file may be made part of the Emacs distribution at the option
  19. ;; of the FSF.
  20.  
  21. ;; This code is distributed in the hope that it will be useful,
  22. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  23. ;; accepts responsibility to anyone for the consequences of using it
  24. ;; or for whether it serves any particular purpose or works at all,
  25. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  26. ;; License for full details.
  27.  
  28. ;; Everyone is granted permission to copy, modify and redistribute
  29. ;; this code, but only under the conditions described in the
  30. ;; GNU Emacs General Public License.   A copy of this license is
  31. ;; supposed to have been given to you along with GNU Emacs so you
  32. ;; can know your rights and responsibilities.  It should be in a
  33. ;; file named COPYING.  Among other things, the copyright notice
  34. ;; and this notice must be preserved on all copies.
  35.  
  36. (require 'cl-19 "cl")
  37. (require 'backquote)
  38. (require 'br-struc)
  39. (require 'br-macro)
  40.  
  41. ;;;
  42. ;;; Provide the following statistics in a buffer:
  43. ;;;
  44. ;;; (1) Number of classes
  45. ;;; (2) Number of classes with multiple base classes
  46. ;;; (3) Number of member functions, variables etc.
  47. ;;;
  48. ;;; Must be called with current buffer = tree buffer because it
  49. ;;; accesses buffer-local variables.
  50. ;;;
  51. ;;; ###autoload
  52.  
  53. (defun tree-statistics ()
  54.   (interactive)
  55.   (let ((tree-file (buffer-file-name)))
  56.     (with-output-to-temp-buffer "*Tree Statistics*"
  57.       (multiple-value-bind (classes member-functions member-variables
  58.                     static-functions static-variables)
  59.       (tree-stats)
  60.     (set-buffer standard-output)
  61.     (erase-buffer)
  62.     (insert "STATISTICS FOR TREE " (or tree-file "unknown") ":\n\n")
  63.     (tree-stat-print "Number of classes:" classes)
  64.     (tree-stat-print "Number of member funtions:" member-functions)
  65.     (tree-stat-print "Number of member variables:" member-variables)
  66.     (tree-stat-print "Number of static functions:" static-functions)
  67.     (tree-stat-print "Number of static variables:" static-variables)))))
  68.  
  69. ;;;
  70. ;;; Print TITLE, indent to column 40 and print integer value VALUE.
  71. ;;; 
  72.  
  73. (defun tree-stat-print (title value)
  74.   (insert title)
  75.   (indent-to 40)
  76.   (insert (format "%d\n" value)))
  77.  
  78. ;;;
  79. ;;; Return multiple values describing statistics of a tree.
  80. ;;; 
  81.  
  82. (defun* tree-stats (&aux (classes 0)
  83.              (member-functions 0)
  84.              (member-variables 0)
  85.              (static-functions 0)
  86.              (static-variables 0))
  87.   (dotrees (tree @tree-obarray)
  88.     (incf classes)
  89.     (incf member-functions (length (tree-member-functions tree)))
  90.     (incf member-variables (length (tree-member-variables tree)))
  91.     (incf static-functions (length (tree-static-functions tree)))
  92.     (incf static-variables (length (tree-static-variables tree))))
  93.   (values classes member-functions member-variables
  94.       static-functions static-variables))
  95.  
  96. (provide 'br-stat)
  97.  
  98. ;;; end of `br-stat.el'.
  99.