Mercurial > emacs
comparison lisp/emacs-lisp/check-declare.el @ 86841:885c9731dd1d
(check-declare-scan): Doc fix.
Handle declare-function third argument `t' and fourth argument.
(check-declare-verify): Doc fix. Handle `fileonly' case.
Use progn rather than prog1.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 30 Nov 2007 07:47:39 +0000 |
parents | bf4a9f989c37 |
children | 4cd2a938a117 |
comparison
equal
deleted
inserted
replaced
86840:ee629020b5a7 | 86841:885c9731dd1d |
---|---|
31 ;; The entry points are `check-declare-file' and `check-declare-directory'. | 31 ;; The entry points are `check-declare-file' and `check-declare-directory'. |
32 | 32 |
33 ;; For more information, see Info node `elisp(Declaring Functions)'. | 33 ;; For more information, see Info node `elisp(Declaring Functions)'. |
34 | 34 |
35 ;;; TODO: | 35 ;;; TODO: |
36 | |
37 ;; 1. Handle defstructs (eg uniquify-item-base in desktop.el). | |
38 | |
39 ;; 2. Handle fset (eg dired-omit-old-add-entry in dired-x.el). | |
40 | 36 |
41 ;;; Code: | 37 ;;; Code: |
42 | 38 |
43 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" | 39 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" |
44 "Name of buffer used to display any `check-declare' warnings.") | 40 "Name of buffer used to display any `check-declare' warnings.") |
74 (if ext (concat "ext:" file) | 70 (if ext (concat "ext:" file) |
75 file))) | 71 file))) |
76 | 72 |
77 (defun check-declare-scan (file) | 73 (defun check-declare-scan (file) |
78 "Scan FILE for `declare-function' calls. | 74 "Scan FILE for `declare-function' calls. |
79 Return a list with elements of the form (FNFILE FN ARGLIST), where | 75 Return a list with elements of the form (FNFILE FN ARGLIST FILEONLY), |
80 ARGLIST may be absent. This claims that FNFILE defines FN, with ARGLIST." | 76 where only the first two elements need be present. This claims that FNFILE |
77 defines FN, with ARGLIST. FILEONLY non-nil means only check that FNFILE | |
78 exists, not that it defines FN. This is for function definitions that we | |
79 don't know how to recognize (e.g. some macros)." | |
81 (let ((m (format "Scanning %s..." file)) | 80 (let ((m (format "Scanning %s..." file)) |
82 alist fnfile fn) | 81 alist fnfile fn arglist fileonly) |
83 (message "%s" m) | 82 (message "%s" m) |
84 (with-temp-buffer | 83 (with-temp-buffer |
85 (insert-file-contents file) | 84 (insert-file-contents file) |
86 (while (re-search-forward | 85 (while (re-search-forward |
87 "^[ \t]*(declare-function[ \t]+\\(\\S-+\\)[ \t]+\ | 86 "^[ \t]*(declare-function[ \t]+\\(\\S-+\\)[ \t]+\ |
88 \"\\(\\S-+\\)\"" nil t) | 87 \"\\(\\S-+\\)\"" nil t) |
89 (setq fn (match-string 1) | 88 (setq fn (match-string 1) |
90 fnfile (match-string 2) | 89 fnfile (match-string 2) |
91 fnfile (check-declare-locate fnfile (expand-file-name file)) | 90 fnfile (check-declare-locate fnfile (expand-file-name file)) |
92 alist (cons | 91 arglist (progn |
93 (list fnfile fn | 92 (skip-chars-forward " \t\n") |
94 (progn | 93 ;; Use `t' to distinguish no arglist |
95 (skip-chars-forward " \t\n") | 94 ;; specified from an empty one. |
96 ;; Use `t' to distinguish no arglist | 95 (if (looking-at "\\((\\|nil\\|t\\)") |
97 ;; specified from an empty one. | 96 (read (current-buffer)) |
98 (if (looking-at "\\((\\|nil\\)") | 97 t)) |
99 (read (current-buffer)) | 98 fileonly (progn |
100 t))) | 99 (skip-chars-forward " \t\n") |
101 alist)))) | 100 (if (looking-at "\\(t\\|'\\sw+\\)") |
101 (match-string 1))) | |
102 alist (cons (list fnfile fn arglist fileonly) alist)))) | |
102 (message "%sdone" m) | 103 (message "%sdone" m) |
103 alist)) | 104 alist)) |
104 | 105 |
105 (defun check-declare-errmsg (errlist &optional full) | 106 (defun check-declare-errmsg (errlist &optional full) |
106 "Return a string with the number of errors in ERRLIST, if any. | 107 "Return a string with the number of errors in ERRLIST, if any. |
117 | 118 |
118 (autoload 'byte-compile-arglist-signature "bytecomp") | 119 (autoload 'byte-compile-arglist-signature "bytecomp") |
119 | 120 |
120 (defun check-declare-verify (fnfile fnlist) | 121 (defun check-declare-verify (fnfile fnlist) |
121 "Check that FNFILE contains function definitions matching FNLIST. | 122 "Check that FNFILE contains function definitions matching FNLIST. |
122 Each element of FNLIST has the form (FILE FN ARGLIST), where | 123 Each element of FNLIST has the form (FILE FN ARGLIST FILEONLY), where |
123 ARGLIST is optional. This means FILE claimed FN was defined in | 124 only the first two elements need be present. This means FILE claimed FN |
124 FNFILE with the specified ARGLIST. Returns nil if all claims are | 125 was defined in FNFILE with the specified ARGLIST. FILEONLY non-nil means |
125 found to be true, otherwise a list of errors with elements of the form | 126 to only check that FNFILE exists, not that it actually defines FN. |
126 \(FILE FN TYPE), where TYPE is a string giving details of the error." | 127 |
128 Returns nil if all claims are found to be true, otherwise a list | |
129 of errors with elements of the form \(FILE FN TYPE), where TYPE | |
130 is a string giving details of the error." | |
127 (let ((m (format "Checking %s..." fnfile)) | 131 (let ((m (format "Checking %s..." fnfile)) |
128 (cflag (string-equal "c" (file-name-extension fnfile))) | 132 (cflag (string-equal "c" (file-name-extension fnfile))) |
129 (ext (string-match "^ext:" fnfile)) | 133 (ext (string-match "^ext:" fnfile)) |
130 re fn sig siglist arglist type errlist minargs maxargs) | 134 re fn sig siglist arglist type errlist minargs maxargs) |
131 (message "%s" m) | 135 (message "%s" m) |
192 (setq arglist (nth 2 e) | 196 (setq arglist (nth 2 e) |
193 type | 197 type |
194 (if (not re) | 198 (if (not re) |
195 "file not found" | 199 "file not found" |
196 (if (not (setq sig (assoc (cadr e) siglist))) | 200 (if (not (setq sig (assoc (cadr e) siglist))) |
197 "function not found" | 201 (unless (nth 3 e) ; fileonly |
202 "function not found") | |
198 (setq sig (cdr sig)) | 203 (setq sig (cdr sig)) |
199 (cond ((eq sig 'obsolete) ; check even when no arglist specified | 204 (cond ((eq sig 'obsolete) ; check even when no arglist specified |
200 "obsolete alias") | 205 "obsolete alias") |
201 ;; arglist t means no arglist specified, as | 206 ;; arglist t means no arglist specified, as |
202 ;; opposed to an empty arglist. | 207 ;; opposed to an empty arglist. |
211 (when type | 216 (when type |
212 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) | 217 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) |
213 (message "%s%s" m | 218 (message "%s%s" m |
214 (if (or re (not ext)) | 219 (if (or re (not ext)) |
215 (check-declare-errmsg errlist) | 220 (check-declare-errmsg errlist) |
216 (prog1 | 221 (progn |
217 "skipping external file" | 222 (setq errlist nil) |
218 (setq errlist nil)))) | 223 "skipping external file"))) |
219 errlist)) | 224 errlist)) |
220 | 225 |
221 (defun check-declare-sort (alist) | 226 (defun check-declare-sort (alist) |
222 "Sort a list with elements FILE (FNFILE ...). | 227 "Sort a list with elements FILE (FNFILE ...). |
223 Returned list has elements FNFILE (FILE ...)." | 228 Returned list has elements FNFILE (FILE ...)." |