Mercurial > emacs
comparison lisp/emacs-lisp/check-declare.el @ 86300:96fee69c65a2
(check-declare-verify): Implement arglist checking for C files.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 22 Nov 2007 06:20:53 +0000 |
parents | a80b13d94c3c |
children | 9525bd421fdb |
comparison
equal
deleted
inserted
replaced
86299:061a530122b6 | 86300:96fee69c65a2 |
---|---|
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. Argument checking for functions defined in C. | |
38 | 36 |
39 ;;; Code: | 37 ;;; Code: |
40 | 38 |
41 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" | 39 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" |
42 "Name of buffer used to display any `check-declare' warnings.") | 40 "Name of buffer used to display any `check-declare' warnings.") |
87 FNFILE with the specified ARGLIST. Returns nil if all claims are | 85 FNFILE with the specified ARGLIST. Returns nil if all claims are |
88 found to be true, otherwise a list of errors with elements of the form | 86 found to be true, otherwise a list of errors with elements of the form |
89 \(FILE FN TYPE), where TYPE is a string giving details of the error." | 87 \(FILE FN TYPE), where TYPE is a string giving details of the error." |
90 (let ((m (format "Checking %s..." fnfile)) | 88 (let ((m (format "Checking %s..." fnfile)) |
91 (cflag (string-equal "c" (file-name-extension fnfile))) | 89 (cflag (string-equal "c" (file-name-extension fnfile))) |
92 re fn sig siglist arglist type errlist) | 90 re fn sig siglist arglist type errlist minargs maxargs) |
93 (message "%s" m) | 91 (message "%s" m) |
94 (or cflag | 92 (or cflag |
95 (file-exists-p fnfile) | 93 (file-exists-p fnfile) |
96 (setq fnfile (concat fnfile ".el"))) | 94 (setq fnfile (concat fnfile ".el"))) |
97 (if (file-exists-p fnfile) | 95 (if (file-exists-p fnfile) |
108 (skip-chars-forward " \t\n") | 106 (skip-chars-forward " \t\n") |
109 (setq fn (match-string 2) | 107 (setq fn (match-string 2) |
110 ;; (min . max) for a fixed number of arguments, or | 108 ;; (min . max) for a fixed number of arguments, or |
111 ;; arglists with optional elements. | 109 ;; arglists with optional elements. |
112 ;; (min) for arglists with &rest. | 110 ;; (min) for arglists with &rest. |
113 sig (cond ((string-equal (match-string 1) | 111 sig (cond (cflag |
112 (re-search-forward "," nil t 3) | |
113 (skip-chars-forward " \t\n") | |
114 ;; Assuming minargs and maxargs on same line. | |
115 (when (looking-at "\\([0-9]+\\)[ \t]*,[ \t]*\ | |
116 \\([0-9]+\\|MANY\\|UNEVALLED\\)") | |
117 (setq minargs (string-to-number (match-string 1)) | |
118 maxargs (match-string 2)) | |
119 (cons minargs (unless (string-match "[^0-9]" | |
120 maxargs) | |
121 (string-to-number maxargs))))) | |
122 ((string-equal (match-string 1) | |
114 "define-derived-mode") | 123 "define-derived-mode") |
115 '(0 . 0)) | 124 '(0 . 0)) |
116 ((string-equal (match-string 1) | 125 ((string-equal (match-string 1) |
117 "define-minor-mode") | 126 "define-minor-mode") |
118 '(0 . 1)) | 127 '(0 . 1)) |
131 type | 140 type |
132 (if re ; re non-nil means found a file | 141 (if re ; re non-nil means found a file |
133 (if (setq sig (assoc (cadr e) siglist)) | 142 (if (setq sig (assoc (cadr e) siglist)) |
134 ;; Recall we use t to mean no arglist specified, | 143 ;; Recall we use t to mean no arglist specified, |
135 ;; to distinguish from an empty arglist. | 144 ;; to distinguish from an empty arglist. |
136 ;; FIXME c arg checking not yet implemented. | 145 (unless (or (eq arglist t) |
137 (unless (or cflag | |
138 (eq arglist t) | |
139 (eq sig t)) | 146 (eq sig t)) |
140 (unless (equal (byte-compile-arglist-signature arglist) | 147 (unless (equal (byte-compile-arglist-signature arglist) |
141 (cdr sig)) | 148 (cdr sig)) |
142 "arglist mismatch")) | 149 "arglist mismatch")) |
143 "function not found") | 150 "function not found") |