Mercurial > emacs
comparison lisp/emacs-lisp/check-declare.el @ 86297:a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
(check-declare-verify): Handle .c files (without arg checking).
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 22 Nov 2007 04:18:54 +0000 |
parents | 2f50908378c9 |
children | 96fee69c65a2 |
comparison
equal
deleted
inserted
replaced
86296:cd8648d81eb3 | 86297:a80b13d94c3c |
---|---|
32 | 32 |
33 ;;; TODO: | 33 ;;; TODO: |
34 | 34 |
35 ;; 1. Handle defstructs (eg uniquify-item-base in desktop.el). | 35 ;; 1. Handle defstructs (eg uniquify-item-base in desktop.el). |
36 | 36 |
37 ;; 2. Check C files (look in src/)? | 37 ;; 2. Argument checking for functions defined in C. |
38 | 38 |
39 ;;; Code: | 39 ;;; Code: |
40 | 40 |
41 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" | 41 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" |
42 "Name of buffer used to display any `check-declare' warnings.") | 42 "Name of buffer used to display any `check-declare' warnings.") |
54 "^[ \t]*(declare-function[ \t]+\\(\\S-+\\)[ \t]+\ | 54 "^[ \t]*(declare-function[ \t]+\\(\\S-+\\)[ \t]+\ |
55 \"\\(\\S-+\\)\"" nil t) | 55 \"\\(\\S-+\\)\"" nil t) |
56 (setq fn (match-string 1) | 56 (setq fn (match-string 1) |
57 fnfile (match-string 2)) | 57 fnfile (match-string 2)) |
58 (or (file-name-absolute-p fnfile) | 58 (or (file-name-absolute-p fnfile) |
59 (setq fnfile (expand-file-name fnfile (file-name-directory file)))) | 59 (setq fnfile |
60 (expand-file-name fnfile | |
61 ;; .c files are assumed to be | |
62 ;; relative to the Emacs src/ directory. | |
63 (if (string-equal | |
64 "c" (file-name-extension fnfile)) | |
65 (expand-file-name "src" | |
66 source-directory) | |
67 (file-name-directory file))))) | |
60 (setq alist (cons | 68 (setq alist (cons |
61 (list fnfile fn | 69 (list fnfile fn |
62 (progn | 70 (progn |
63 (skip-chars-forward " \t\n") | 71 (skip-chars-forward " \t\n") |
64 ;; Use `t' to distinguish no arglist | 72 ;; Use `t' to distinguish no arglist |
78 ARGLIST is optional. This means FILE claimed FN was defined in | 86 ARGLIST is optional. This means FILE claimed FN was defined in |
79 FNFILE with the specified ARGLIST. Returns nil if all claims are | 87 FNFILE with the specified ARGLIST. Returns nil if all claims are |
80 found to be true, otherwise a list of errors with elements of the form | 88 found to be true, otherwise a list of errors with elements of the form |
81 \(FILE FN TYPE), where TYPE is a string giving details of the error." | 89 \(FILE FN TYPE), where TYPE is a string giving details of the error." |
82 (let ((m (format "Checking %s..." fnfile)) | 90 (let ((m (format "Checking %s..." fnfile)) |
91 (cflag (string-equal "c" (file-name-extension fnfile))) | |
83 re fn sig siglist arglist type errlist) | 92 re fn sig siglist arglist type errlist) |
84 (message "%s" m) | 93 (message "%s" m) |
85 (if (string-equal (file-name-extension fnfile) "c") | 94 (or cflag |
86 (progn | 95 (file-exists-p fnfile) |
87 (message "%sskipping C file" m) | 96 (setq fnfile (concat fnfile ".el"))) |
88 nil) | 97 (if (file-exists-p fnfile) |
89 (or (file-exists-p fnfile) | 98 (with-temp-buffer |
90 (setq fnfile (concat fnfile ".el"))) | 99 (insert-file-contents fnfile) |
91 (if (file-exists-p fnfile) | 100 ;; defsubst's don't _have_ to be known at compile time. |
92 (with-temp-buffer | 101 (setq re (format (if cflag |
93 (insert-file-contents fnfile) | 102 "^[ \t]*\\(DEFUN\\)[ \t]*([ \t]*\"%s\"" |
94 ;; defsubst's don't _have_ to be known at compile time. | 103 "^[ \t]*(\\(def\\(?:un\\|subst\\|\ |
95 (setq re (format "^[ \t]*(\\(def\\(?:un\\|subst\\|\ | |
96 ine-derived-mode\\|ine-minor-mode\\|alias[ \t]+'\\)\\)\ | 104 ine-derived-mode\\|ine-minor-mode\\|alias[ \t]+'\\)\\)\ |
97 \[ \t]*%s\\([ \t;]+\\|$\\)" | 105 \[ \t]*%s\\([ \t;]+\\|$\\)") |
98 (regexp-opt (mapcar 'cadr fnlist) t))) | 106 (regexp-opt (mapcar 'cadr fnlist) t))) |
99 (while (re-search-forward re nil t) | 107 (while (re-search-forward re nil t) |
100 (skip-chars-forward " \t\n") | 108 (skip-chars-forward " \t\n") |
101 (setq fn (match-string 2) | 109 (setq fn (match-string 2) |
102 sig (cond ((string-equal (match-string 1) | 110 ;; (min . max) for a fixed number of arguments, or |
103 "define-derived-mode") | 111 ;; arglists with optional elements. |
104 '(0 . 0)) | 112 ;; (min) for arglists with &rest. |
105 ((string-equal (match-string 1) | 113 sig (cond ((string-equal (match-string 1) |
106 "define-minor-mode") | 114 "define-derived-mode") |
107 '(0 . 1)) | 115 '(0 . 0)) |
108 ;; Can't easily check alias arguments. | 116 ((string-equal (match-string 1) |
109 ((string-equal (match-string 1) | 117 "define-minor-mode") |
110 "defalias") | 118 '(0 . 1)) |
111 t) | 119 ;; Can't easily check alias arguments. |
112 (t | 120 ((string-equal (match-string 1) |
113 (if (looking-at "\\((\\|nil\\)") | 121 "defalias") |
114 (byte-compile-arglist-signature | 122 t) |
115 (read (current-buffer)))))) | 123 (t |
116 ;; alist of functions and arglist signatures. | 124 (if (looking-at "\\((\\|nil\\)") |
117 siglist (cons (cons fn sig) siglist))))) | 125 (byte-compile-arglist-signature |
118 (dolist (e fnlist) | 126 (read (current-buffer)))))) |
119 (setq arglist (nth 2 e) | 127 ;; alist of functions and arglist signatures. |
120 type | 128 siglist (cons (cons fn sig) siglist))))) |
121 (if re ; re non-nil means found a file | 129 (dolist (e fnlist) |
122 (if (setq sig (assoc (cadr e) siglist)) | 130 (setq arglist (nth 2 e) |
123 ;; Recall we use t to mean no arglist specified, | 131 type |
124 ;; to distinguish from an empty arglist. | 132 (if re ; re non-nil means found a file |
125 (unless (or (eq arglist t) | 133 (if (setq sig (assoc (cadr e) siglist)) |
126 (eq sig t)) | 134 ;; Recall we use t to mean no arglist specified, |
127 (unless (equal (byte-compile-arglist-signature arglist) | 135 ;; to distinguish from an empty arglist. |
128 (cdr sig)) | 136 ;; FIXME c arg checking not yet implemented. |
129 "arglist mismatch")) | 137 (unless (or cflag |
130 "function not found") | 138 (eq arglist t) |
131 "file not found")) | 139 (eq sig t)) |
132 (when type | 140 (unless (equal (byte-compile-arglist-signature arglist) |
133 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) | 141 (cdr sig)) |
134 (message "%s%s" m (if errlist "problems found" "OK")) | 142 "arglist mismatch")) |
135 errlist))) | 143 "function not found") |
144 "file not found")) | |
145 (when type | |
146 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) | |
147 (message "%s%s" m (if errlist "problems found" "OK")) | |
148 errlist)) | |
136 | 149 |
137 (defun check-declare-sort (alist) | 150 (defun check-declare-sort (alist) |
138 "Sort a list with elements FILE (FNFILE ...). | 151 "Sort a list with elements FILE (FNFILE ...). |
139 Returned list has elements FNFILE (FILE ...)." | 152 Returned list has elements FNFILE (FILE ...)." |
140 (let (file fnfile rest sort a) | 153 (let (file fnfile rest sort a) |