Mercurial > emacs
comparison lisp/emacs-lisp/check-declare.el @ 86810:bf4a9f989c37
(check-declare-locate, check-declare-verify): Handle `external' files.
(check-declare-errmsg): New function.
(check-declare-verify, check-declare-file, check-declare-directory):
Use check-declare-errmsg to report the number of problems.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 29 Nov 2007 04:23:49 +0000 |
parents | db04d9e790f1 |
children | 885c9731dd1d |
comparison
equal
deleted
inserted
replaced
86809:8ac1aa3f0181 | 86810:bf4a9f989c37 |
---|---|
46 (defun check-declare-locate (file basefile) | 46 (defun check-declare-locate (file basefile) |
47 "Return the full path of FILE. | 47 "Return the full path of FILE. |
48 Expands files with a \".c\" extension relative to the Emacs | 48 Expands files with a \".c\" extension relative to the Emacs |
49 \"src/\" directory. Otherwise, `locate-library' searches for FILE. | 49 \"src/\" directory. Otherwise, `locate-library' searches for FILE. |
50 If that fails, expands FILE relative to BASEFILE's directory part. | 50 If that fails, expands FILE relative to BASEFILE's directory part. |
51 The returned file might not exist." | 51 The returned file might not exist. If FILE has an \"ext:\" prefix, so does |
52 (if (string-equal "c" (file-name-extension file)) | 52 the result." |
53 (expand-file-name file (expand-file-name "src" source-directory)) | 53 (let ((ext (string-match "^ext:" file)) |
54 (let ((tfile (locate-library (file-name-nondirectory file)))) | 54 tfile) |
55 (if tfile | 55 (if ext |
56 (progn | 56 (setq file (substring file 4))) |
57 (setq tfile (replace-regexp-in-string "\\.elc\\'" ".el" tfile)) | 57 (setq file |
58 (if (and (not (file-exists-p tfile)) | 58 (if (string-equal "c" (file-name-extension file)) |
59 (file-exists-p (concat tfile ".gz"))) | 59 (expand-file-name file (expand-file-name "src" source-directory)) |
60 (concat tfile ".gz") | 60 (if (setq tfile (locate-library (file-name-nondirectory file))) |
61 tfile)) | 61 (progn |
62 (setq tfile (expand-file-name file (file-name-directory basefile))) | 62 (setq tfile |
63 (if (or (file-exists-p tfile) | 63 (replace-regexp-in-string "\\.elc\\'" ".el" tfile)) |
64 (string-match "\\.el\\'" tfile)) | 64 (if (and (not (file-exists-p tfile)) |
65 tfile | 65 (file-exists-p (concat tfile ".gz"))) |
66 (concat tfile ".el")))))) | 66 (concat tfile ".gz") |
67 tfile)) | |
68 (setq tfile (expand-file-name file | |
69 (file-name-directory basefile))) | |
70 (if (or (file-exists-p tfile) | |
71 (string-match "\\.el\\'" tfile)) | |
72 tfile | |
73 (concat tfile ".el"))))) | |
74 (if ext (concat "ext:" file) | |
75 file))) | |
67 | 76 |
68 (defun check-declare-scan (file) | 77 (defun check-declare-scan (file) |
69 "Scan FILE for `declare-function' calls. | 78 "Scan FILE for `declare-function' calls. |
70 Return a list with elements of the form (FNFILE FN ARGLIST), where | 79 Return a list with elements of the form (FNFILE FN ARGLIST), where |
71 ARGLIST may be absent. This claims that FNFILE defines FN, with ARGLIST." | 80 ARGLIST may be absent. This claims that FNFILE defines FN, with ARGLIST." |
91 t))) | 100 t))) |
92 alist)))) | 101 alist)))) |
93 (message "%sdone" m) | 102 (message "%sdone" m) |
94 alist)) | 103 alist)) |
95 | 104 |
105 (defun check-declare-errmsg (errlist &optional full) | |
106 "Return a string with the number of errors in ERRLIST, if any. | |
107 Normally just counts the number of elements in ERRLIST. | |
108 With optional argument FULL, sums the number of elements in each element." | |
109 (if errlist | |
110 (let ((l (length errlist))) | |
111 (when full | |
112 (setq l 0) | |
113 (dolist (e errlist) | |
114 (setq l (1+ l)))) | |
115 (format "%d problem%s found" l (if (= l 1) "" "s"))) | |
116 "OK")) | |
117 | |
96 (autoload 'byte-compile-arglist-signature "bytecomp") | 118 (autoload 'byte-compile-arglist-signature "bytecomp") |
97 | 119 |
98 (defun check-declare-verify (fnfile fnlist) | 120 (defun check-declare-verify (fnfile fnlist) |
99 "Check that FNFILE contains function definitions matching FNLIST. | 121 "Check that FNFILE contains function definitions matching FNLIST. |
100 Each element of FNLIST has the form (FILE FN ARGLIST), where | 122 Each element of FNLIST has the form (FILE FN ARGLIST), where |
102 FNFILE with the specified ARGLIST. Returns nil if all claims are | 124 FNFILE with the specified ARGLIST. Returns nil if all claims are |
103 found to be true, otherwise a list of errors with elements of the form | 125 found to be true, otherwise a list of errors with elements of the form |
104 \(FILE FN TYPE), where TYPE is a string giving details of the error." | 126 \(FILE FN TYPE), where TYPE is a string giving details of the error." |
105 (let ((m (format "Checking %s..." fnfile)) | 127 (let ((m (format "Checking %s..." fnfile)) |
106 (cflag (string-equal "c" (file-name-extension fnfile))) | 128 (cflag (string-equal "c" (file-name-extension fnfile))) |
129 (ext (string-match "^ext:" fnfile)) | |
107 re fn sig siglist arglist type errlist minargs maxargs) | 130 re fn sig siglist arglist type errlist minargs maxargs) |
108 (message "%s" m) | 131 (message "%s" m) |
132 (if ext | |
133 (setq fnfile (substring fnfile 4))) | |
109 (if (file-exists-p fnfile) | 134 (if (file-exists-p fnfile) |
110 (with-temp-buffer | 135 (with-temp-buffer |
111 (insert-file-contents fnfile) | 136 (insert-file-contents fnfile) |
112 ;; defsubst's don't _have_ to be known at compile time. | 137 ;; defsubst's don't _have_ to be known at compile time. |
113 (setq re (format (if cflag | 138 (setq re (format (if cflag |
183 arglist) | 208 arglist) |
184 sig)) | 209 sig)) |
185 "arglist mismatch"))))) | 210 "arglist mismatch"))))) |
186 (when type | 211 (when type |
187 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) | 212 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) |
188 (message "%s%s" m (if errlist "problems found" "OK")) | 213 (message "%s%s" m |
214 (if (or re (not ext)) | |
215 (check-declare-errmsg errlist) | |
216 (prog1 | |
217 "skipping external file" | |
218 (setq errlist nil)))) | |
189 errlist)) | 219 errlist)) |
190 | 220 |
191 (defun check-declare-sort (alist) | 221 (defun check-declare-sort (alist) |
192 "Sort a list with elements FILE (FNFILE ...). | 222 "Sort a list with elements FILE (FNFILE ...). |
193 Returned list has elements FNFILE (FILE ...)." | 223 Returned list has elements FNFILE (FILE ...)." |
242 (error "File `%s' not found" file)) | 272 (error "File `%s' not found" file)) |
243 (let ((m (format "Checking %s..." file)) | 273 (let ((m (format "Checking %s..." file)) |
244 errlist) | 274 errlist) |
245 (message "%s" m) | 275 (message "%s" m) |
246 (setq errlist (check-declare-files file)) | 276 (setq errlist (check-declare-files file)) |
247 (message "%s%s" m (if errlist "problems found" "OK")) | 277 (message "%s%s" m (check-declare-errmsg errlist)) |
248 errlist)) | 278 errlist)) |
249 | 279 |
250 ;;;###autoload | 280 ;;;###autoload |
251 (defun check-declare-directory (root) | 281 (defun check-declare-directory (root) |
252 "Check veracity of all `declare-function' statements under directory ROOT. | 282 "Check veracity of all `declare-function' statements under directory ROOT. |
265 "-exec" "grep" "-l" | 295 "-exec" "grep" "-l" |
266 "^[ ]*(declare-function" "{}" ";")) | 296 "^[ ]*(declare-function" "{}" ";")) |
267 (message "%s%d found" m2 (length files)) | 297 (message "%s%d found" m2 (length files)) |
268 (when files | 298 (when files |
269 (setq errlist (apply 'check-declare-files files)) | 299 (setq errlist (apply 'check-declare-files files)) |
270 (message "%s%s" m (if errlist "problems found" "OK")) | 300 (message "%s%s" m (check-declare-errmsg errlist t)) |
271 errlist))) | 301 errlist))) |
272 | 302 |
273 (provide 'check-declare) | 303 (provide 'check-declare) |
274 | 304 |
275 ;; arch-tag: a4d6cdc4-deb7-4502-b327-0e4ef3d82d96 | 305 ;; arch-tag: a4d6cdc4-deb7-4502-b327-0e4ef3d82d96 |