aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-09-17 12:43:54 +0000
committerAlan Mackenzie2016-09-17 12:43:54 +0000
commit277e7b011d4131a1f0ecde38ecd48429d5fe388c (patch)
tree893a67957d329bd67d022cdf10f0e26a1d6c5003
parentaab079d1d2d391bd1d6892a6bed0bc98eebce02d (diff)
downloademacs-277e7b011d4131a1f0ecde38ecd48429d5fe388c.tar.gz
emacs-277e7b011d4131a1f0ecde38ecd48429d5fe388c.zip
Improve accuracy of line/column numbers in byte compiler's warning messages.
* lisp/emacs-lisp/bytecomp.el (byte-compile-set-symbol-position): ensure new value of byte-compile-last-position is not lower than old value. (byte-compile-function-warn): call byte-compile-set-symbol-position.
-rw-r--r--lisp/emacs-lisp/bytecomp.el48
1 files changed, 26 insertions, 22 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index b6bb1d6ab90..c34ec5cae0d 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1022,39 +1022,42 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
1022 (setcdr list (cddr list))) 1022 (setcdr list (cddr list)))
1023 total))) 1023 total)))
1024 1024
1025;; The purpose of this function is to iterate through the 1025;; The purpose of `byte-compile-set-symbol-position' is to attempt to
1026;; `read-symbol-positions-list'. Each time we process, say, a 1026;; set `byte-compile-last-position' to the "current position" in the
1027;; function definition (`defun') we remove `defun' from 1027;; raw source code. This is used for warning and error messages.
1028;; `read-symbol-positions-list', and set `byte-compile-last-position'
1029;; to that symbol's character position. Similarly, if we encounter a
1030;; variable reference, like in (1+ foo), we remove `foo' from the
1031;; list. If our current position is after the symbol's position, we
1032;; assume we've already passed that point, and look for the next
1033;; occurrence of the symbol.
1034;; 1028;;
1035;; This function should not be called twice for the same occurrence of 1029;; The function should be called for most occurrences of symbols in
1036;; a symbol, and it should not be called for symbols generated by the 1030;; the forms being compiled, strictly in the order they occur in the
1037;; byte compiler itself; because rather than just fail looking up the 1031;; source code. It should never be called twice for any single
1038;; symbol, we may find an occurrence of the symbol further ahead, and 1032;; occurrence, and should not be called for symbols generated by the
1039;; then `byte-compile-last-position' as advanced too far. 1033;; byte compiler itself.
1040;; 1034;;
1041;; So your're probably asking yourself: Isn't this function a 1035;; The function works by scanning the elements in the alist
1042;; gross hack? And the answer, of course, would be yes. 1036;; `read-symbol-positions-list' for the next match for the symbol
1037;; after the current value of `byte-compile-last-position', setting
1038;; that variable to the match's character position, then deleting the
1039;; matching element from the list. Thus the new value for
1040;; `byte-compile-last-position' is later than the old value unless,
1041;; perhaps, ALLOW-PREVIOUS is non-nil.
1042;;
1043;; So your're probably asking yourself: Isn't this function a gross
1044;; hack? And the answer, of course, would be yes.
1043(defun byte-compile-set-symbol-position (sym &optional allow-previous) 1045(defun byte-compile-set-symbol-position (sym &optional allow-previous)
1044 (when byte-compile-read-position 1046 (when byte-compile-read-position
1045 (let (last entry) 1047 (let ((last byte-compile-last-position)
1048 entry)
1046 (while (progn 1049 (while (progn
1047 (setq last byte-compile-last-position 1050 (setq entry (assq sym read-symbol-positions-list))
1048 entry (assq sym read-symbol-positions-list))
1049 (when entry 1051 (when entry
1050 (setq byte-compile-last-position 1052 (setq byte-compile-last-position
1051 (+ byte-compile-read-position (cdr entry)) 1053 (+ byte-compile-read-position (cdr entry))
1052 read-symbol-positions-list 1054 read-symbol-positions-list
1053 (byte-compile-delete-first 1055 (byte-compile-delete-first
1054 entry read-symbol-positions-list))) 1056 entry read-symbol-positions-list)))
1055 (or (and allow-previous 1057 (and entry
1056 (not (= last byte-compile-last-position))) 1058 (or (and allow-previous
1057 (> last byte-compile-last-position))))))) 1059 (not (= last byte-compile-last-position)))
1060 (> last byte-compile-last-position))))))))
1058 1061
1059(defvar byte-compile-last-warned-form nil) 1062(defvar byte-compile-last-warned-form nil)
1060(defvar byte-compile-last-logged-file nil) 1063(defvar byte-compile-last-logged-file nil)
@@ -1284,6 +1287,7 @@ when printing the error message."
1284 (t (format "%d-%d" (car signature) (cdr signature))))) 1287 (t (format "%d-%d" (car signature) (cdr signature)))))
1285 1288
1286(defun byte-compile-function-warn (f nargs def) 1289(defun byte-compile-function-warn (f nargs def)
1290 (byte-compile-set-symbol-position f)
1287 (when (get f 'byte-obsolete-info) 1291 (when (get f 'byte-obsolete-info)
1288 (byte-compile-warn-obsolete f)) 1292 (byte-compile-warn-obsolete f))
1289 1293