aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters2002-05-28 17:40:47 +0000
committerColin Walters2002-05-28 17:40:47 +0000
commitccb3c8deafcbbeb4029fb8e09b0c4f930783f253 (patch)
tree50dd275a4e80aa4cd312998ed9ecf5348ea256a3
parent9d118494d548336c25dec20726145fd4e795b84b (diff)
downloademacs-ccb3c8deafcbbeb4029fb8e09b0c4f930783f253.tar.gz
emacs-ccb3c8deafcbbeb4029fb8e09b0c4f930783f253.zip
(byte-compile-last-line): Deleted.
(byte-compile-delete-first): New function. (byte-compile-read-position): New variable. (byte-compile-last-position): New variable. (byte-compile-current-buffer): New variable. (byte-compile-log-1): Use it. (byte-compile-set-symbol-position): New function. (byte-compile-obsolete, byte-compile-callargs-warn) (byte-compile-arglist-warn, byte-compile-arglist-warn) (byte-compile-print-syms, byte-compile-file-form-defmumble) (byte-compile-check-lambda-list, byte-compile-lambda) (byte-compile-form, byte-compile-variable-ref) (byte-compile-subr-wrong-args, byte-compile-negation-optimizer) (byte-compile-condition-case, byte-compile-defun) (byte-compile-defvar, byte-compile-autoload) (byte-compile-lambda-form): Use it. (byte-compile-from-buffer): Set it, and bind `read-with-symbol-positions' and `read-symbol-positions-list'. (byte-compile-debug): New variable.
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/bytecomp.el226
2 files changed, 164 insertions, 66 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 571d66e41f5..5261d443980 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -3,8 +3,10 @@
3 * textmodes/sgml-mode.el (xml-mode): New alias for `sgml-mode'. 3 * textmodes/sgml-mode.el (xml-mode): New alias for `sgml-mode'.
4 4
5 * emacs-lisp/bytecomp.el (byte-compile-last-line): Deleted. 5 * emacs-lisp/bytecomp.el (byte-compile-last-line): Deleted.
6 (byte-compile-delete-first): New function.
6 (byte-compile-read-position): New variable. 7 (byte-compile-read-position): New variable.
7 (byte-compile-last-position): New variable. 8 (byte-compile-last-position): New variable.
9 (byte-compile-current-buffer): New variable.
8 (byte-compile-log-1): Use it. 10 (byte-compile-log-1): Use it.
9 (byte-compile-set-symbol-position): New function. 11 (byte-compile-set-symbol-position): New function.
10 (byte-compile-obsolete, byte-compile-callargs-warn) 12 (byte-compile-obsolete, byte-compile-callargs-warn)
@@ -19,6 +21,8 @@
19 (byte-compile-from-buffer): Set it, and bind 21 (byte-compile-from-buffer): Set it, and bind
20 `read-with-symbol-positions' and `read-symbol-positions-list'. 22 `read-with-symbol-positions' and `read-symbol-positions-list'.
21 23
24 * emacs-lisp/bytecomp.el (byte-compile-debug): New variable.
25
222002-05-28 Kim F. Storm <storm@cua.dk> 262002-05-28 Kim F. Storm <storm@cua.dk>
23 27
24 * files.el (read-directory-name): New function. 28 * files.el (read-directory-name): New function.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index f569a292816..9ec39ff339b 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -10,7 +10,7 @@
10 10
11;;; This version incorporates changes up to version 2.10 of the 11;;; This version incorporates changes up to version 2.10 of the
12;;; Zawinski-Furuseth compiler. 12;;; Zawinski-Furuseth compiler.
13(defconst byte-compile-version "$Revision: 2.95 $") 13(defconst byte-compile-version "$Revision: 2.96 $")
14 14
15;; This file is part of GNU Emacs. 15;; This file is part of GNU Emacs.
16 16
@@ -380,6 +380,8 @@ specify different fields to sort on."
380 :type '(choice (const name) (const callers) (const calls) 380 :type '(choice (const name) (const callers) (const calls)
381 (const calls+callers) (const nil))) 381 (const calls+callers) (const nil)))
382 382
383(defvar byte-compile-debug nil)
384
383;; (defvar byte-compile-overwrite-file t 385;; (defvar byte-compile-overwrite-file t
384;; "If nil, old .elc files are deleted before the new is saved, and .elc 386;; "If nil, old .elc files are deleted before the new is saved, and .elc
385;; files will have the same modes as the corresponding .el file. Otherwise, 387;; files will have the same modes as the corresponding .el file. Otherwise,
@@ -794,6 +796,7 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
794(defvar byte-compile-current-form nil) 796(defvar byte-compile-current-form nil)
795(defvar byte-compile-dest-file nil) 797(defvar byte-compile-dest-file nil)
796(defvar byte-compile-current-file nil) 798(defvar byte-compile-current-file nil)
799(defvar byte-compile-current-buffer nil)
797 800
798(defmacro byte-compile-log (format-string &rest args) 801(defmacro byte-compile-log (format-string &rest args)
799 (list 'and 802 (list 'and
@@ -813,9 +816,50 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
813(defvar byte-compile-last-warned-form nil) 816(defvar byte-compile-last-warned-form nil)
814(defvar byte-compile-last-logged-file nil) 817(defvar byte-compile-last-logged-file nil)
815 818
816(defvar byte-compile-last-line nil 819(defvar byte-compile-read-position nil
817 "Last known line number in the input.") 820 "Character position we began the last `read' from.")
818 821(defvar byte-compile-last-position nil
822 "Last known character position in the input.")
823
824;; copied from gnus-util.el
825(defun byte-compile-delete-first (elt list)
826 (if (eq (car list) elt)
827 (cdr list)
828 (let ((total list))
829 (while (and (cdr list)
830 (not (eq (cadr list) elt)))
831 (setq list (cdr list)))
832 (when (cdr list)
833 (setcdr list (cddr list)))
834 total)))
835
836;; The purpose of this function is to iterate through the
837;; `read-symbol-positions-list'. Each time we process, say, a
838;; function definition (`defun') we remove `defun' from
839;; `read-symbol-positions-list', and set `byte-compile-last-position'
840;; to that symbol's character position. Similarly, if we encounter a
841;; variable reference, like in (1+ foo), we remove `foo' from the
842;; list. If our current position is after the symbol's position, we
843;; assume we've already passed that point, and look for the next
844;; occurence of the symbol.
845;; So your're probably asking yourself: Isn't this function a
846;; gross hack? And the answer, of course, would be yes.
847(defun byte-compile-set-symbol-position (sym &optional allow-previous)
848 (when byte-compile-read-position
849 (let ((last nil))
850 (while (progn
851 (setq last byte-compile-last-position)
852 (let* ((entry (assq sym read-symbol-positions-list))
853 (cur (cdr entry)))
854 (setq byte-compile-last-position
855 (if cur
856 (+ byte-compile-read-position cur)
857 last))
858 (setq
859 read-symbol-positions-list
860 (byte-compile-delete-first entry read-symbol-positions-list)))
861 (or (and allow-previous (not (= last byte-compile-last-position)))
862 (> last byte-compile-last-position)))))))
819 863
820(defun byte-compile-display-log-head-p () 864(defun byte-compile-display-log-head-p ()
821 (and (not (eq byte-compile-current-form :end)) 865 (and (not (eq byte-compile-current-form :end))
@@ -841,8 +885,13 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
841 (buffer-name byte-compile-current-file))) 885 (buffer-name byte-compile-current-file)))
842 (t ""))) 886 (t "")))
843 (pos (if (and byte-compile-current-file 887 (pos (if (and byte-compile-current-file
844 (integerp byte-compile-last-line)) 888 (integerp byte-compile-read-position))
845 (format "%d:" byte-compile-last-line) 889 (with-current-buffer byte-compile-current-buffer
890 (format "%d:%d:" (count-lines (point-min)
891 byte-compile-last-position)
892 (save-excursion
893 (goto-char byte-compile-last-position)
894 (1+ (current-column)))))
846 "")) 895 ""))
847 (form (or byte-compile-current-form "toplevel form"))) 896 (form (or byte-compile-current-form "toplevel form")))
848 (cond (noninteractive 897 (cond (noninteractive
@@ -904,6 +953,7 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
904 (let* ((new (get (car form) 'byte-obsolete-info)) 953 (let* ((new (get (car form) 'byte-obsolete-info))
905 (handler (nth 1 new)) 954 (handler (nth 1 new))
906 (when (nth 2 new))) 955 (when (nth 2 new)))
956 (byte-compile-set-symbol-position (car form))
907 (if (memq 'obsolete byte-compile-warnings) 957 (if (memq 'obsolete byte-compile-warnings)
908 (byte-compile-warn "%s is an obsolete function%s; %s" (car form) 958 (byte-compile-warn "%s is an obsolete function%s; %s" (car form)
909 (if when (concat " since " when) "") 959 (if when (concat " since " when) "")
@@ -1053,16 +1103,17 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
1053 (not (numberp (cdr sig)))) 1103 (not (numberp (cdr sig))))
1054 (setcdr sig nil)) 1104 (setcdr sig nil))
1055 (if sig 1105 (if sig
1056 (if (or (< ncall (car sig)) 1106 (when (or (< ncall (car sig))
1057 (and (cdr sig) (> ncall (cdr sig)))) 1107 (and (cdr sig) (> ncall (cdr sig))))
1058 (byte-compile-warn 1108 (byte-compile-set-symbol-position (car form))
1059 "%s called with %d argument%s, but %s %s" 1109 (byte-compile-warn
1060 (car form) ncall 1110 "%s called with %d argument%s, but %s %s"
1061 (if (= 1 ncall) "" "s") 1111 (car form) ncall
1062 (if (< ncall (car sig)) 1112 (if (= 1 ncall) "" "s")
1063 "requires" 1113 (if (< ncall (car sig))
1064 "accepts only") 1114 "requires"
1065 (byte-compile-arglist-signature-string sig))) 1115 "accepts only")
1116 (byte-compile-arglist-signature-string sig)))
1066 (or (and (fboundp (car form)) ; might be a subr or autoload. 1117 (or (and (fboundp (car form)) ; might be a subr or autoload.
1067 (not (get (car form) 'byte-compile-noruntime))) 1118 (not (get (car form) 'byte-compile-noruntime)))
1068 (eq (car form) byte-compile-current-form) ; ## this doesn't work 1119 (eq (car form) byte-compile-current-form) ; ## this doesn't work
@@ -1090,13 +1141,15 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
1090 (aref old 0) 1141 (aref old 0)
1091 '(&rest def))))) 1142 '(&rest def)))))
1092 (sig2 (byte-compile-arglist-signature (nth 2 form)))) 1143 (sig2 (byte-compile-arglist-signature (nth 2 form))))
1093 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2) 1144 (unless (byte-compile-arglist-signatures-congruent-p sig1 sig2)
1094 (byte-compile-warn "%s %s used to take %s %s, now takes %s" 1145 (byte-compile-set-symbol-position (nth 1 form))
1095 (if (eq (car form) 'defun) "function" "macro") 1146 (byte-compile-warn
1096 (nth 1 form) 1147 "%s %s used to take %s %s, now takes %s"
1097 (byte-compile-arglist-signature-string sig1) 1148 (if (eq (car form) 'defun) "function" "macro")
1098 (if (equal sig1 '(1 . 1)) "argument" "arguments") 1149 (nth 1 form)
1099 (byte-compile-arglist-signature-string sig2)))) 1150 (byte-compile-arglist-signature-string sig1)
1151 (if (equal sig1 '(1 . 1)) "argument" "arguments")
1152 (byte-compile-arglist-signature-string sig2))))
1100 ;; This is the first definition. See if previous calls are compatible. 1153 ;; This is the first definition. See if previous calls are compatible.
1101 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions)) 1154 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions))
1102 nums sig min max) 1155 nums sig min max)
@@ -1106,20 +1159,23 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
1106 nums (sort (copy-sequence (cdr calls)) (function <)) 1159 nums (sort (copy-sequence (cdr calls)) (function <))
1107 min (car nums) 1160 min (car nums)
1108 max (car (nreverse nums))) 1161 max (car (nreverse nums)))
1109 (if (or (< min (car sig)) 1162 (when (or (< min (car sig))
1110 (and (cdr sig) (> max (cdr sig)))) 1163 (and (cdr sig) (> max (cdr sig))))
1111 (byte-compile-warn 1164 (byte-compile-set-symbol-position (nth 1 form))
1112 "%s being defined to take %s%s, but was previously called with %s" 1165 (byte-compile-warn
1113 (nth 1 form) 1166 "%s being defined to take %s%s, but was previously called with %s"
1114 (byte-compile-arglist-signature-string sig) 1167 (nth 1 form)
1115 (if (equal sig '(1 . 1)) " arg" " args") 1168 (byte-compile-arglist-signature-string sig)
1116 (byte-compile-arglist-signature-string (cons min max)))) 1169 (if (equal sig '(1 . 1)) " arg" " args")
1170 (byte-compile-arglist-signature-string (cons min max))))
1117 1171
1118 (setq byte-compile-unresolved-functions 1172 (setq byte-compile-unresolved-functions
1119 (delq calls byte-compile-unresolved-functions))))) 1173 (delq calls byte-compile-unresolved-functions)))))
1120 ))) 1174 )))
1121 1175
1122(defun byte-compile-print-syms (str1 strn syms) 1176(defun byte-compile-print-syms (str1 strn syms)
1177 (when syms
1178 (byte-compile-set-symbol-position (car syms) t))
1123 (cond ((and (cdr syms) (not noninteractive)) 1179 (cond ((and (cdr syms) (not noninteractive))
1124 (let* ((str strn) 1180 (let* ((str strn)
1125 (L (length str)) 1181 (L (length str))
@@ -1221,9 +1277,13 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property."
1221 (byte-goto-log-buffer) 1277 (byte-goto-log-buffer)
1222 (setq byte-compile-warnings-point-max (point-max)))) 1278 (setq byte-compile-warnings-point-max (point-max))))
1223 (unwind-protect 1279 (unwind-protect
1224 (condition-case error-info 1280 (let ((--displaying-byte-compile-warnings-fn (lambda ()
1225 (progn ,@body) 1281 ,@body)))
1226 (error (byte-compile-report-error error-info))) 1282 (if byte-compile-debug
1283 (funcall --displaying-byte-compile-warnings-fn)
1284 (condition-case error-info
1285 (funcall --displaying-byte-compile-warnings-fn)
1286 (error (byte-compile-report-error error-info)))))
1227 (with-current-buffer "*Compile-Log*" 1287 (with-current-buffer "*Compile-Log*"
1228 ;; If there were compilation warnings, display them. 1288 ;; If there were compilation warnings, display them.
1229 (unless (= byte-compile-warnings-point-max (point-max)) 1289 (unless (= byte-compile-warnings-point-max (point-max))
@@ -1403,8 +1463,8 @@ The value is non-nil if there were no errors, nil if errors."
1403 (condition-case nil (delete-file target-file) (error nil))) 1463 (condition-case nil (delete-file target-file) (error nil)))
1404 ;; We successfully didn't compile this file. 1464 ;; We successfully didn't compile this file.
1405 'no-byte-compile) 1465 'no-byte-compile)
1406 (if byte-compile-verbose 1466 (when byte-compile-verbose
1407 (message "Compiling %s..." filename)) 1467 (message "Compiling %s..." filename))
1408 (setq byte-compiler-error-flag nil) 1468 (setq byte-compiler-error-flag nil)
1409 ;; It is important that input-buffer not be current at this call, 1469 ;; It is important that input-buffer not be current at this call,
1410 ;; so that the value of point set in input-buffer 1470 ;; so that the value of point set in input-buffer
@@ -1412,8 +1472,8 @@ The value is non-nil if there were no errors, nil if errors."
1412 (setq output-buffer (byte-compile-from-buffer input-buffer filename)) 1472 (setq output-buffer (byte-compile-from-buffer input-buffer filename))
1413 (if byte-compiler-error-flag 1473 (if byte-compiler-error-flag
1414 nil 1474 nil
1415 (if byte-compile-verbose 1475 (when byte-compile-verbose
1416 (message "Compiling %s...done" filename)) 1476 (message "Compiling %s...done" filename))
1417 (kill-buffer input-buffer) 1477 (kill-buffer input-buffer)
1418 (with-current-buffer output-buffer 1478 (with-current-buffer output-buffer
1419 (goto-char (point-max)) 1479 (goto-char (point-max))
@@ -1482,9 +1542,15 @@ With argument, insert value in current buffer after the form."
1482 (end-of-defun) 1542 (end-of-defun)
1483 (beginning-of-defun) 1543 (beginning-of-defun)
1484 (let* ((byte-compile-current-file nil) 1544 (let* ((byte-compile-current-file nil)
1545 (byte-compile-current-buffer (current-buffer))
1546 (byte-compile-read-position (point))
1547 (byte-compile-last-position byte-compile-read-position)
1485 (byte-compile-last-warned-form 'nothing) 1548 (byte-compile-last-warned-form 'nothing)
1486 (value (eval (displaying-byte-compile-warnings 1549 (value (eval
1487 (byte-compile-sexp (read (current-buffer))))))) 1550 (let ((read-with-symbol-positions inbuffer)
1551 (read-symbol-positions-list nil))
1552 (displaying-byte-compile-warnings
1553 (byte-compile-sexp (read (current-buffer))))))))
1488 (cond (arg 1554 (cond (arg
1489 (message "Compiling from buffer... done.") 1555 (message "Compiling from buffer... done.")
1490 (prin1 value (current-buffer)) 1556 (prin1 value (current-buffer))
@@ -1495,6 +1561,9 @@ With argument, insert value in current buffer after the form."
1495(defun byte-compile-from-buffer (inbuffer &optional filename) 1561(defun byte-compile-from-buffer (inbuffer &optional filename)
1496 ;; Filename is used for the loading-into-Emacs-18 error message. 1562 ;; Filename is used for the loading-into-Emacs-18 error message.
1497 (let (outbuffer 1563 (let (outbuffer
1564 (byte-compile-current-buffer inbuffer)
1565 (byte-compile-read-position nil)
1566 (byte-compile-last-position nil)
1498 ;; Prevent truncation of flonums and lists as we read and print them 1567 ;; Prevent truncation of flonums and lists as we read and print them
1499 (float-output-format nil) 1568 (float-output-format nil)
1500 (case-fold-search nil) 1569 (case-fold-search nil)
@@ -1502,8 +1571,8 @@ With argument, insert value in current buffer after the form."
1502 (print-level nil) 1571 (print-level nil)
1503 ;; Prevent edebug from interfering when we compile 1572 ;; Prevent edebug from interfering when we compile
1504 ;; and put the output into a file. 1573 ;; and put the output into a file.
1505 (edebug-all-defs nil) 1574;; (edebug-all-defs nil)
1506 (edebug-all-forms nil) 1575;; (edebug-all-forms nil)
1507 ;; Simulate entry to byte-compile-top-level 1576 ;; Simulate entry to byte-compile-top-level
1508 (byte-compile-constants nil) 1577 (byte-compile-constants nil)
1509 (byte-compile-variables nil) 1578 (byte-compile-variables nil)
@@ -1511,6 +1580,10 @@ With argument, insert value in current buffer after the form."
1511 (byte-compile-depth 0) 1580 (byte-compile-depth 0)
1512 (byte-compile-maxdepth 0) 1581 (byte-compile-maxdepth 0)
1513 (byte-compile-output nil) 1582 (byte-compile-output nil)
1583 ;; This allows us to get the positions of symbols read; it's
1584 ;; new in Emacs 21.4.
1585 (read-with-symbol-positions inbuffer)
1586 (read-symbol-positions-list nil)
1514 ;; #### This is bound in b-c-close-variables. 1587 ;; #### This is bound in b-c-close-variables.
1515 ;; (byte-compile-warnings (if (eq byte-compile-warnings t) 1588 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
1516 ;; byte-compile-warning-types 1589 ;; byte-compile-warning-types
@@ -1543,9 +1616,10 @@ With argument, insert value in current buffer after the form."
1543 (looking-at ";")) 1616 (looking-at ";"))
1544 (forward-line 1)) 1617 (forward-line 1))
1545 (not (eobp))) 1618 (not (eobp)))
1546 (let ((byte-compile-last-line (count-lines (point-min) (point)))) 1619 (setq byte-compile-read-position (point)
1547 (byte-compile-file-form (read inbuffer)))) 1620 byte-compile-last-position byte-compile-read-position)
1548 1621 (let ((form (read inbuffer)))
1622 (byte-compile-file-form form)))
1549 ;; Compile pending forms at end of file. 1623 ;; Compile pending forms at end of file.
1550 (byte-compile-flush-pending) 1624 (byte-compile-flush-pending)
1551 (byte-compile-warn-about-unresolved-functions) 1625 (byte-compile-warn-about-unresolved-functions)
@@ -1930,7 +2004,7 @@ list that represents a doc string reference.
1930 (that-one (assq name (symbol-value that-kind))) 2004 (that-one (assq name (symbol-value that-kind)))
1931 (byte-compile-free-references nil) 2005 (byte-compile-free-references nil)
1932 (byte-compile-free-assignments nil)) 2006 (byte-compile-free-assignments nil))
1933 2007 (byte-compile-set-symbol-position name)
1934 ;; When a function or macro is defined, add it to the call tree so that 2008 ;; When a function or macro is defined, add it to the call tree so that
1935 ;; we can tell when functions are not used. 2009 ;; we can tell when functions are not used.
1936 (if byte-compile-generate-call-tree 2010 (if byte-compile-generate-call-tree
@@ -1953,34 +2027,35 @@ list that represents a doc string reference.
1953 (nth 1 form))) 2027 (nth 1 form)))
1954 (setcdr that-one nil)) 2028 (setcdr that-one nil))
1955 (this-one 2029 (this-one
1956 (if (and (memq 'redefine byte-compile-warnings) 2030 (when (and (memq 'redefine byte-compile-warnings)
1957 ;; hack: don't warn when compiling the magic internal 2031 ;; hack: don't warn when compiling the magic internal
1958 ;; byte-compiler macros in byte-run.el... 2032 ;; byte-compiler macros in byte-run.el...
1959 (not (assq (nth 1 form) 2033 (not (assq (nth 1 form)
1960 byte-compile-initial-macro-environment))) 2034 byte-compile-initial-macro-environment)))
1961 (byte-compile-warn "%s %s defined multiple times in this file" 2035 (byte-compile-warn "%s %s defined multiple times in this file"
1962 (if macrop "macro" "function") 2036 (if macrop "macro" "function")
1963 (nth 1 form)))) 2037 (nth 1 form))))
1964 ((and (fboundp name) 2038 ((and (fboundp name)
1965 (eq (car-safe (symbol-function name)) 2039 (eq (car-safe (symbol-function name))
1966 (if macrop 'lambda 'macro))) 2040 (if macrop 'lambda 'macro)))
1967 (if (memq 'redefine byte-compile-warnings) 2041 (when (memq 'redefine byte-compile-warnings)
1968 (byte-compile-warn "%s %s being redefined as a %s" 2042 (byte-compile-warn "%s %s being redefined as a %s"
1969 (if macrop "function" "macro") 2043 (if macrop "function" "macro")
1970 (nth 1 form) 2044 (nth 1 form)
1971 (if macrop "macro" "function"))) 2045 (if macrop "macro" "function")))
1972 ;; shadow existing definition 2046 ;; shadow existing definition
1973 (set this-kind 2047 (set this-kind
1974 (cons (cons name nil) (symbol-value this-kind)))) 2048 (cons (cons name nil) (symbol-value this-kind))))
1975 ) 2049 )
1976 (let ((body (nthcdr 3 form))) 2050 (let ((body (nthcdr 3 form)))
1977 (if (and (stringp (car body)) 2051 (when (and (stringp (car body))
1978 (symbolp (car-safe (cdr-safe body))) 2052 (symbolp (car-safe (cdr-safe body)))
1979 (car-safe (cdr-safe body)) 2053 (car-safe (cdr-safe body))
1980 (stringp (car-safe (cdr-safe (cdr-safe body))))) 2054 (stringp (car-safe (cdr-safe (cdr-safe body)))))
1981 (byte-compile-warn "probable `\"' without `\\' in doc string of %s" 2055 (byte-compile-set-symbol-position (nth 1 form))
1982 (nth 1 form)))) 2056 (byte-compile-warn "probable `\"' without `\\' in doc string of %s"
1983 2057 (nth 1 form))))
2058
1984 ;; Generate code for declarations in macro definitions. 2059 ;; Generate code for declarations in macro definitions.
1985 ;; Remove declarations from the body of the macro definition. 2060 ;; Remove declarations from the body of the macro definition.
1986 (when macrop 2061 (when macrop
@@ -2169,6 +2244,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2169 (let (vars) 2244 (let (vars)
2170 (while list 2245 (while list
2171 (let ((arg (car list))) 2246 (let ((arg (car list)))
2247 (when (symbolp arg)
2248 (byte-compile-set-symbol-position arg))
2172 (cond ((or (not (symbolp arg)) 2249 (cond ((or (not (symbolp arg))
2173 (keywordp arg) 2250 (keywordp arg)
2174 (memq arg '(t nil))) 2251 (memq arg '(t nil)))
@@ -2194,6 +2271,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2194(defun byte-compile-lambda (fun) 2271(defun byte-compile-lambda (fun)
2195 (unless (eq 'lambda (car-safe fun)) 2272 (unless (eq 'lambda (car-safe fun))
2196 (error "Not a lambda list: %S" fun)) 2273 (error "Not a lambda list: %S" fun))
2274 (byte-compile-set-symbol-position 'lambda)
2197 (byte-compile-check-lambda-list (nth 1 fun)) 2275 (byte-compile-check-lambda-list (nth 1 fun))
2198 (let* ((arglist (nth 1 fun)) 2276 (let* ((arglist (nth 1 fun))
2199 (byte-compile-bound-variables 2277 (byte-compile-bound-variables
@@ -2209,6 +2287,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2209 (setq body (cdr body)))))) 2287 (setq body (cdr body))))))
2210 (int (assq 'interactive body))) 2288 (int (assq 'interactive body)))
2211 (cond (int 2289 (cond (int
2290 (byte-compile-set-symbol-position 'interactive)
2212 ;; Skip (interactive) if it is in front (the most usual location). 2291 ;; Skip (interactive) if it is in front (the most usual location).
2213 (if (eq int (car body)) 2292 (if (eq int (car body))
2214 (setq body (cdr body))) 2293 (setq body (cdr body)))
@@ -2419,6 +2498,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2419(defun byte-compile-form (form &optional for-effect) 2498(defun byte-compile-form (form &optional for-effect)
2420 (setq form (macroexpand form byte-compile-macro-environment)) 2499 (setq form (macroexpand form byte-compile-macro-environment))
2421 (cond ((not (consp form)) 2500 (cond ((not (consp form))
2501 (when (symbolp form)
2502 (byte-compile-set-symbol-position form))
2422 (cond ((or (not (symbolp form)) (byte-compile-const-symbol-p form)) 2503 (cond ((or (not (symbolp form)) (byte-compile-const-symbol-p form))
2423 (byte-compile-constant form)) 2504 (byte-compile-constant form))
2424 ((and for-effect byte-compile-delete-errors) 2505 ((and for-effect byte-compile-delete-errors)
@@ -2427,8 +2508,9 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2427 ((symbolp (car form)) 2508 ((symbolp (car form))
2428 (let* ((fn (car form)) 2509 (let* ((fn (car form))
2429 (handler (get fn 'byte-compile))) 2510 (handler (get fn 'byte-compile)))
2430 (if (byte-compile-const-symbol-p fn) 2511 (byte-compile-set-symbol-position fn)
2431 (byte-compile-warn "%s called as a function" fn)) 2512 (when (byte-compile-const-symbol-p fn)
2513 (byte-compile-warn "%s called as a function" fn))
2432 (if (and handler 2514 (if (and handler
2433 (or (not (byte-compile-version-cond 2515 (or (not (byte-compile-version-cond
2434 byte-compile-compatibility)) 2516 byte-compile-compatibility))
@@ -2456,6 +2538,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2456 (byte-compile-out 'byte-call (length (cdr form)))) 2538 (byte-compile-out 'byte-call (length (cdr form))))
2457 2539
2458(defun byte-compile-variable-ref (base-op var) 2540(defun byte-compile-variable-ref (base-op var)
2541 (when (symbolp var)
2542 (byte-compile-set-symbol-position var))
2459 (if (or (not (symbolp var)) (byte-compile-const-symbol-p var)) 2543 (if (or (not (symbolp var)) (byte-compile-const-symbol-p var))
2460 (byte-compile-warn (if (eq base-op 'byte-varbind) 2544 (byte-compile-warn (if (eq base-op 'byte-varbind)
2461 "attempt to let-bind %s %s" 2545 "attempt to let-bind %s %s"
@@ -2505,6 +2589,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2505(defun byte-compile-constant (const) 2589(defun byte-compile-constant (const)
2506 (if for-effect 2590 (if for-effect
2507 (setq for-effect nil) 2591 (setq for-effect nil)
2592 (when (symbolp const)
2593 (byte-compile-set-symbol-position const))
2508 (byte-compile-out 'byte-constant (byte-compile-get-constant const)))) 2594 (byte-compile-out 'byte-constant (byte-compile-get-constant const))))
2509 2595
2510;; Use this for a constant that is not the value of its containing form. 2596;; Use this for a constant that is not the value of its containing form.
@@ -2682,6 +2768,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2682 2768
2683 2769
2684(defun byte-compile-subr-wrong-args (form n) 2770(defun byte-compile-subr-wrong-args (form n)
2771 (byte-compile-set-symbol-position (car form))
2685 (byte-compile-warn "%s called with %d arg%s, but requires %s" 2772 (byte-compile-warn "%s called with %d arg%s, but requires %s"
2686 (car form) (length (cdr form)) 2773 (car form) (length (cdr form))
2687 (if (= 1 (length (cdr form))) "" "s") n) 2774 (if (= 1 (length (cdr form))) "" "s") n)
@@ -3148,6 +3235,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
3148;; Even when optimization is off, /= is optimized to (not (= ...)). 3235;; Even when optimization is off, /= is optimized to (not (= ...)).
3149(defun byte-compile-negation-optimizer (form) 3236(defun byte-compile-negation-optimizer (form)
3150 ;; an optimizer for forms where <form1> is less efficient than (not <form2>) 3237 ;; an optimizer for forms where <form1> is less efficient than (not <form2>)
3238 (byte-compile-set-symbol-position (car form))
3151 (list 'not 3239 (list 'not
3152 (cons (or (get (car form) 'byte-compile-negated-op) 3240 (cons (or (get (car form) 'byte-compile-negated-op)
3153 (error 3241 (error
@@ -3194,9 +3282,10 @@ If FORM is a lambda or a macro, byte-compile it as a function."
3194 (byte-compile-bound-variables 3282 (byte-compile-bound-variables
3195 (if var (cons var byte-compile-bound-variables) 3283 (if var (cons var byte-compile-bound-variables)
3196 byte-compile-bound-variables))) 3284 byte-compile-bound-variables)))
3197 (or (symbolp var) 3285 (byte-compile-set-symbol-position 'condition-case)
3198 (byte-compile-warn 3286 (unless (symbolp var)
3199 "%s is not a variable-name or nil (in condition-case)" var)) 3287 (byte-compile-warn
3288 "%s is not a variable-name or nil (in condition-case)" var))
3200 (byte-compile-push-constant var) 3289 (byte-compile-push-constant var)
3201 (byte-compile-push-constant (byte-compile-top-level 3290 (byte-compile-push-constant (byte-compile-top-level
3202 (nth 2 form) for-effect)) 3291 (nth 2 form) for-effect))
@@ -3272,7 +3361,9 @@ If FORM is a lambda or a macro, byte-compile it as a function."
3272 3361
3273(defun byte-compile-defun (form) 3362(defun byte-compile-defun (form)
3274 ;; This is not used for file-level defuns with doc strings. 3363 ;; This is not used for file-level defuns with doc strings.
3275 (unless (symbolp (car form)) 3364 (if (symbolp (car form))
3365 (byte-compile-set-symbol-position (car form))
3366 (byte-compile-set-symbol-position 'defun)
3276 (error "defun name must be a symbol, not %s" (car form))) 3367 (error "defun name must be a symbol, not %s" (car form)))
3277 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning. 3368 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning.
3278 (list 'fset (list 'quote (nth 1 form)) 3369 (list 'fset (list 'quote (nth 1 form))
@@ -3299,6 +3390,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
3299 (var (nth 1 form)) 3390 (var (nth 1 form))
3300 (value (nth 2 form)) 3391 (value (nth 2 form))
3301 (string (nth 3 form))) 3392 (string (nth 3 form)))
3393 (byte-compile-set-symbol-position fun)
3302 (when (> (length form) 4) 3394 (when (> (length form) 4)
3303 (byte-compile-warn 3395 (byte-compile-warn
3304 "%s %s called with %d arguments, but accepts only %s" 3396 "%s %s called with %d arguments, but accepts only %s"
@@ -3328,6 +3420,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
3328 `',var)))) 3420 `',var))))
3329 3421
3330(defun byte-compile-autoload (form) 3422(defun byte-compile-autoload (form)
3423 (byte-compile-set-symbol-position 'autoload)
3331 (and (byte-compile-constp (nth 1 form)) 3424 (and (byte-compile-constp (nth 1 form))
3332 (byte-compile-constp (nth 5 form)) 3425 (byte-compile-constp (nth 5 form))
3333 (eval (nth 5 form)) ; macro-p 3426 (eval (nth 5 form)) ; macro-p
@@ -3341,6 +3434,7 @@ If FORM is a lambda or a macro, byte-compile it as a function."
3341;; Lambdas in valid places are handled as special cases by various code. 3434;; Lambdas in valid places are handled as special cases by various code.
3342;; The ones that remain are errors. 3435;; The ones that remain are errors.
3343(defun byte-compile-lambda-form (form) 3436(defun byte-compile-lambda-form (form)
3437 (byte-compile-set-symbol-position 'lambda)
3344 (error "`lambda' used as function name is invalid")) 3438 (error "`lambda' used as function name is invalid"))
3345 3439
3346;; Compile normally, but deal with warnings for the function being defined. 3440;; Compile normally, but deal with warnings for the function being defined.