comparison lisp/emacs-lisp/check-declare.el @ 86278:2f50908378c9

(check-declare-verify): Skip C files for now. Handle define-minor-mode, and defalias (with no argument checking).
author Glenn Morris <rgm@gnu.org>
date Wed, 21 Nov 2007 09:03:05 +0000
parents d6eda104caa6
children a80b13d94c3c
comparison
equal deleted inserted replaced
86277:a8503aaf3a82 86278:2f50908378c9
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 ;;; 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
37 ;; 2. Check C files (look in src/)?
36 38
37 ;;; Code: 39 ;;; Code:
38 40
39 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" 41 (defconst check-declare-warning-buffer "*Check Declarations Warnings*"
40 "Name of buffer used to display any `check-declare' warnings.") 42 "Name of buffer used to display any `check-declare' warnings.")
78 found to be true, otherwise a list of errors with elements of the form 80 found to be true, otherwise a list of errors with elements of the form
79 \(FILE FN TYPE), where TYPE is a string giving details of the error." 81 \(FILE FN TYPE), where TYPE is a string giving details of the error."
80 (let ((m (format "Checking %s..." fnfile)) 82 (let ((m (format "Checking %s..." fnfile))
81 re fn sig siglist arglist type errlist) 83 re fn sig siglist arglist type errlist)
82 (message "%s" m) 84 (message "%s" m)
83 (or (file-exists-p fnfile) 85 (if (string-equal (file-name-extension fnfile) "c")
84 (setq fnfile (concat fnfile ".el"))) 86 (progn
85 (if (file-exists-p fnfile) 87 (message "%sskipping C file" m)
86 (with-temp-buffer 88 nil)
87 (insert-file-contents fnfile) 89 (or (file-exists-p fnfile)
88 ;; defsubst's don't _have_ to be known at compile time. 90 (setq fnfile (concat fnfile ".el")))
89 (setq re (format "^[ \t]*(\\(def\\(?:un\\|subst\\|\ 91 (if (file-exists-p fnfile)
90 ine-derived-mode\\)\\)\[ \t]+%s\\([ \t;]+\\|$\\)" 92 (with-temp-buffer
91 (regexp-opt (mapcar 'cadr fnlist) t))) 93 (insert-file-contents fnfile)
92 (while (re-search-forward re nil t) 94 ;; defsubst's don't _have_ to be known at compile time.
93 (skip-chars-forward " \t\n") 95 (setq re (format "^[ \t]*(\\(def\\(?:un\\|subst\\|\
94 (setq fn (match-string 2) 96 ine-derived-mode\\|ine-minor-mode\\|alias[ \t]+'\\)\\)\
95 sig (if (string-equal "define-derived-mode" 97 \[ \t]*%s\\([ \t;]+\\|$\\)"
96 (match-string 1)) 98 (regexp-opt (mapcar 'cadr fnlist) t)))
97 '(0 . 0) 99 (while (re-search-forward re nil t)
98 (if (looking-at "\\((\\|nil\\)") 100 (skip-chars-forward " \t\n")
99 (byte-compile-arglist-signature 101 (setq fn (match-string 2)
100 (read (current-buffer))))) 102 sig (cond ((string-equal (match-string 1)
101 ;; alist of functions and arglist signatures. 103 "define-derived-mode")
102 siglist (cons (cons fn sig) siglist))))) 104 '(0 . 0))
103 (dolist (e fnlist) 105 ((string-equal (match-string 1)
104 (setq arglist (nth 2 e) 106 "define-minor-mode")
105 type 107 '(0 . 1))
106 (if re ; re non-nil means found a file 108 ;; Can't easily check alias arguments.
107 (if (setq sig (assoc (cadr e) siglist)) 109 ((string-equal (match-string 1)
108 ;; Recall we use t to mean no arglist specified, 110 "defalias")
109 ;; to distinguish from an empty arglist. 111 t)
110 (unless (eq arglist t) 112 (t
111 (unless (equal (byte-compile-arglist-signature arglist) 113 (if (looking-at "\\((\\|nil\\)")
112 (cdr sig)) 114 (byte-compile-arglist-signature
113 "arglist mismatch")) 115 (read (current-buffer))))))
114 "function not found") 116 ;; alist of functions and arglist signatures.
115 "file not found")) 117 siglist (cons (cons fn sig) siglist)))))
116 (when type 118 (dolist (e fnlist)
117 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) 119 (setq arglist (nth 2 e)
118 (message "%s%s" m (if errlist "problems found" "OK")) 120 type
119 errlist)) 121 (if re ; re non-nil means found a file
122 (if (setq sig (assoc (cadr e) siglist))
123 ;; Recall we use t to mean no arglist specified,
124 ;; to distinguish from an empty arglist.
125 (unless (or (eq arglist t)
126 (eq sig t))
127 (unless (equal (byte-compile-arglist-signature arglist)
128 (cdr sig))
129 "arglist mismatch"))
130 "function not found")
131 "file not found"))
132 (when type
133 (setq errlist (cons (list (car e) (cadr e) type) errlist))))
134 (message "%s%s" m (if errlist "problems found" "OK"))
135 errlist)))
120 136
121 (defun check-declare-sort (alist) 137 (defun check-declare-sort (alist)
122 "Sort a list with elements FILE (FNFILE ...). 138 "Sort a list with elements FILE (FNFILE ...).
123 Returned list has elements FNFILE (FILE ...)." 139 Returned list has elements FNFILE (FILE ...)."
124 (let (file fnfile rest sort a) 140 (let (file fnfile rest sort a)