changeset 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 cd8648d81eb3
children a75958448281
files lisp/emacs-lisp/check-declare.el
diffstat 1 files changed, 65 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/check-declare.el	Thu Nov 22 04:17:44 2007 +0000
+++ b/lisp/emacs-lisp/check-declare.el	Thu Nov 22 04:18:54 2007 +0000
@@ -34,7 +34,7 @@
 
 ;; 1. Handle defstructs (eg uniquify-item-base in desktop.el).
 
-;; 2. Check C files (look in src/)?
+;; 2. Argument checking for functions defined in C.
 
 ;;; Code:
 
@@ -56,7 +56,15 @@
         (setq fn (match-string 1)
               fnfile (match-string 2))
         (or (file-name-absolute-p fnfile)
-            (setq fnfile (expand-file-name fnfile (file-name-directory file))))
+            (setq fnfile
+                  (expand-file-name fnfile
+                                    ;; .c files are assumed to be
+                                    ;; relative to the Emacs src/ directory.
+                                    (if (string-equal
+                                         "c" (file-name-extension fnfile))
+                                        (expand-file-name "src"
+                                                          source-directory)
+                                      (file-name-directory file)))))
         (setq alist (cons
                      (list fnfile fn
                            (progn
@@ -80,59 +88,64 @@
 found to be true, otherwise a list of errors with elements of the form
 \(FILE FN TYPE), where TYPE is a string giving details of the error."
   (let ((m (format "Checking %s..." fnfile))
+        (cflag (string-equal "c" (file-name-extension fnfile)))
         re fn sig siglist arglist type errlist)
     (message "%s" m)
-    (if (string-equal (file-name-extension fnfile) "c")
-        (progn
-          (message "%sskipping C file" m)
-          nil)
-      (or (file-exists-p fnfile)
-          (setq fnfile (concat fnfile ".el")))
-      (if (file-exists-p fnfile)
-          (with-temp-buffer
-            (insert-file-contents fnfile)
-            ;; defsubst's don't _have_ to be known at compile time.
-            (setq re (format "^[ \t]*(\\(def\\(?:un\\|subst\\|\
+    (or cflag
+        (file-exists-p fnfile)
+        (setq fnfile (concat fnfile ".el")))
+    (if (file-exists-p fnfile)
+        (with-temp-buffer
+          (insert-file-contents fnfile)
+          ;; defsubst's don't _have_ to be known at compile time.
+          (setq re (format (if cflag
+                               "^[ \t]*\\(DEFUN\\)[ \t]*([ \t]*\"%s\""
+                             "^[ \t]*(\\(def\\(?:un\\|subst\\|\
 ine-derived-mode\\|ine-minor-mode\\|alias[ \t]+'\\)\\)\
-\[ \t]*%s\\([ \t;]+\\|$\\)"
-                             (regexp-opt (mapcar 'cadr fnlist) t)))
-            (while (re-search-forward re nil t)
-              (skip-chars-forward " \t\n")
-              (setq fn (match-string 2)
-                    sig (cond ((string-equal (match-string 1)
-                                             "define-derived-mode")
-                               '(0 . 0))
-                              ((string-equal (match-string 1)
-                                             "define-minor-mode")
-                               '(0 . 1))
-                              ;; Can't easily check alias arguments.
-                              ((string-equal (match-string 1)
-                                             "defalias")
-                               t)
-                              (t
-                               (if (looking-at "\\((\\|nil\\)")
-                                   (byte-compile-arglist-signature
-                                    (read (current-buffer))))))
-                    ;; alist of functions and arglist signatures.
-                    siglist (cons (cons fn sig) siglist)))))
-      (dolist (e fnlist)
-        (setq arglist (nth 2 e)
-              type
-              (if re                   ; re non-nil means found a file
-                  (if (setq sig (assoc (cadr e) siglist))
-                      ;; Recall we use t to mean no arglist specified,
-                      ;; to distinguish from an empty arglist.
-                      (unless (or (eq arglist t)
-                                  (eq sig t))
-                        (unless (equal (byte-compile-arglist-signature arglist)
-                                       (cdr sig))
-                          "arglist mismatch"))
-                    "function not found")
-                "file not found"))
-        (when type
-          (setq errlist (cons (list (car e) (cadr e) type) errlist))))
-      (message "%s%s" m (if errlist "problems found" "OK"))
-      errlist)))
+\[ \t]*%s\\([ \t;]+\\|$\\)")
+                           (regexp-opt (mapcar 'cadr fnlist) t)))
+          (while (re-search-forward re nil t)
+            (skip-chars-forward " \t\n")
+            (setq fn (match-string 2)
+                  ;; (min . max) for a fixed number of arguments, or
+                  ;; arglists with optional elements.
+                  ;; (min) for arglists with &rest.
+                  sig (cond ((string-equal (match-string 1)
+                                           "define-derived-mode")
+                             '(0 . 0))
+                            ((string-equal (match-string 1)
+                                           "define-minor-mode")
+                             '(0 . 1))
+                            ;; Can't easily check alias arguments.
+                            ((string-equal (match-string 1)
+                                           "defalias")
+                             t)
+                            (t
+                             (if (looking-at "\\((\\|nil\\)")
+                                 (byte-compile-arglist-signature
+                                  (read (current-buffer))))))
+                  ;; alist of functions and arglist signatures.
+                  siglist (cons (cons fn sig) siglist)))))
+    (dolist (e fnlist)
+      (setq arglist (nth 2 e)
+            type
+            (if re                   ; re non-nil means found a file
+                (if (setq sig (assoc (cadr e) siglist))
+                    ;; Recall we use t to mean no arglist specified,
+                    ;; to distinguish from an empty arglist.
+                    ;; FIXME c arg checking not yet implemented.
+                    (unless (or cflag
+                                (eq arglist t)
+                                (eq sig t))
+                      (unless (equal (byte-compile-arglist-signature arglist)
+                                     (cdr sig))
+                        "arglist mismatch"))
+                  "function not found")
+              "file not found"))
+      (when type
+        (setq errlist (cons (list (car e) (cadr e) type) errlist))))
+    (message "%s%s" m (if errlist "problems found" "OK"))
+    errlist))
 
 (defun check-declare-sort (alist)
   "Sort a list with elements FILE (FNFILE ...).