Megatest

Check-in [91a6aa298f]
Login
Overview
Comment:Added code analysis tool
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | re-re-factor-server
Files: files | file ages | folders
SHA1: 91a6aa298f7d4ffd5082abdf43a8b84114106eb1
User & Date: matt on 2014-02-10 22:39:27
Other Links: branch diff | manifest | tags
Context
2014-02-10
23:53
It works - making dot files of .scm files check-in: 3061292702 user: matt tags: re-re-factor-server
22:39
Added code analysis tool check-in: 91a6aa298f user: matt tags: re-re-factor-server
19:56
Re-re-factor server handling check-in: f68ed29f16 user: matt tags: re-re-factor-server
Changes

Added utils/plot-code.scm version [060b469cc0].



















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/mfs/pkgs/chicken/4.8.0.5/bin/csi -nbq

(use regex srfi-69)

(define targs (string-split (cadddr (argv)) ","))
(define files (cddddr (argv)))

(define filedat-defns (make-hash-table))
(define filedat-usages (make-hash-table))

(define defn-rx (regexp "^\\s*\\(define\\s+\\(([^\\s\\)]+).*"))
(define all-regexs (make-hash-table))

(define all-fns '())

(define (print-err . data)
  (with-output-to-port (current-error-port)
    (lambda ()
      (apply print data))))

;; Gather the functions
;;
(for-each 
 (lambda (fname)
   (print-err "Processing file " fname)
   (with-input-from-file fname
     (lambda ()
       (let loop ((inl (read-line)))
	 (if (not (eof-object? inl))
	     (let ((match (string-match defn-rx inl)))
	       (if match 
		   (let ((fnname (cadr match)))
		     ;; (print "   " fnname)
		     (set! all-fns (cons fnname all-fns))
		     (hash-table-set! 
		      filedat-defns 
		      fname
		      (cons fnname (hash-table-ref/default filedat-defns fname '())))
		     ))
	       (loop (read-line))))))))
 files)

;; fill up the regex hash
(print-err "Make the huge regex hash")
(for-each
 (lambda (fnname)
   (hash-table-set! all-regexs fnname (regexp (conc "^(|.*[^a-zA-Z]+)" fnname "([^a-zA-Z]+|)$"))))
 (cons "toplevel" all-fns))

(define breadcrumbs (make-hash-table))

(print-err "Make the quick check regex")
(define have-function-rx (regexp (conc "(" (string-intersperse all-fns "|")
				       ")")))

(define (look-for-all-calls inl fnname)
  (if (string-search have-function-rx inl)
      (let loop ((hed (car all-fns))
		 (tal (cdr all-fns))
		 (res '()))
	(let ((match (string-match (hash-table-ref all-regexs fnname) inl)))
	  (if match
	      (let ((newres (cons hed res)))
		(if (not (null? tal))
		    newres
		    (loop (car tal)
			  (cdr tal)
			  newres)))
	      (if (null? tal)
		  res
		  (loop (car tal)(cdr tal) res)))))
      '()))
  
;; Gather the usages
(print "digraph G {")
(define curr-cluster-num 0)
(define function-calls '())

(for-each
 (lambda (fname)
   (print-err "Processing file " fname)
   (print "subgraph cluster_" curr-cluster-num " {")
   (set! curr-cluster-num (+ curr-cluster-num 1))
   (with-input-from-file fname
     (lambda ()
       (with-output-to-port (current-error-port)
	 (lambda ()
	   (print "Analyzing file " fname)))
       (print "label=\"" fname "\";")
       (let loop ((inl    (read-line))
		  (fnname "toplevel"))
	 (if (not (eof-object? inl))
	     (let ((match (string-match defn-rx inl)))
	       (if match
		   (let ((func-name (cadr match)))
		     (print "\"" func-name "\";")
		     (hash-table-set! breadcrumbs func-name #t)
		     (loop (read-line)
			   func-name))
		   (let ((calls (look-for-all-calls inl fnname)))
		     (if (not (null? calls))
			 (set! function-calls (cons (list fnname calls) function-calls)))
			 ;; (print "Function: " fnname " calls: " calls))
		     (loop (read-line) fnname))))))))
   (print "}"))
 targs)

(for-each 
 (lambda (function-call)
   (let ((fnname (car function-call))
	 (calls  (cadr function-call)))
     (for-each
      (lambda (callname)
	(print (if (hash-table-ref/default breadcrumbs callname #f) "" "// ")
	       "\"" fnname "\" -> \"" callname "\";"))
      calls)))
 function-calls)

(print "}")

;; (exit)