Mercurial > emacs
comparison lisp/emacs-lisp/bytecomp.el @ 39769:3bea53c3ecea
(byte-compile-display-log-head-p): New
function extracted from byte-compile-log-1.
(byte-compile-log-1): Change output to be more in line with
the output of other GNU tools.
(byte-compile-warn): Emit `warning' instead of `**' for warnings.
(byte-compile-report-error): Downcase error message. Use
`error' instead of `!!' for error messages.
(byte-compile-print-syms): Treat non-interactive case specially.
(displaying-byte-compile-warnings): Use backquote.
(byte-compile-from-buffer): Bind byte-compile-last-line.
(batch-byte-compile): Remove `Done' message.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 11 Oct 2001 12:57:18 +0000 |
parents | ea9e28db82d5 |
children | d9f8c7370b3a |
comparison
equal
deleted
inserted
replaced
39768:e2bfb4d00b04 | 39769:3bea53c3ecea |
---|---|
8 ;; Maintainer: FSF | 8 ;; Maintainer: FSF |
9 ;; Keywords: lisp | 9 ;; Keywords: lisp |
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.86 $") | 13 (defconst byte-compile-version "$Revision: 2.87 $") |
14 | 14 |
15 ;; This file is part of GNU Emacs. | 15 ;; This file is part of GNU Emacs. |
16 | 16 |
17 ;; GNU Emacs is free software; you can redistribute it and/or modify | 17 ;; GNU Emacs is free software; you can redistribute it and/or modify |
18 ;; it under the terms of the GNU General Public License as published by | 18 ;; it under the terms of the GNU General Public License as published by |
811 args))))))) | 811 args))))))) |
812 | 812 |
813 (defconst byte-compile-last-warned-form nil) | 813 (defconst byte-compile-last-warned-form nil) |
814 (defconst byte-compile-last-logged-file nil) | 814 (defconst byte-compile-last-logged-file nil) |
815 | 815 |
816 (defvar byte-compile-last-line nil | |
817 "Last known line number in the input.") | |
818 | |
819 | |
820 (defun byte-compile-display-log-head-p () | |
821 (and (not (eq byte-compile-current-form :end)) | |
822 (or (and byte-compile-current-file | |
823 (not (equal byte-compile-current-file | |
824 byte-compile-last-logged-file))) | |
825 (and byte-compile-last-warned-form | |
826 (not (eq byte-compile-current-form | |
827 byte-compile-last-warned-form)))))) | |
828 | |
829 | |
816 ;; Log a message STRING in *Compile-Log*. | 830 ;; Log a message STRING in *Compile-Log*. |
817 ;; Also log the current function and file if not already done. | 831 ;; Also log the current function and file if not already done. |
818 (defun byte-compile-log-1 (string &optional fill) | 832 (defun byte-compile-log-1 (string &optional fill) |
819 (cond (noninteractive | 833 (let* ((file (cond ((stringp byte-compile-current-file) |
820 (if (or (and byte-compile-current-file | 834 (format "%s:" byte-compile-current-file)) |
821 (not (equal byte-compile-current-file | 835 ((bufferp byte-compile-current-file) |
822 byte-compile-last-logged-file))) | 836 (format "Buffer %s:" |
823 (and byte-compile-last-warned-form | 837 (buffer-name byte-compile-current-file))) |
824 (not (eq byte-compile-current-form | 838 (t ""))) |
825 byte-compile-last-warned-form)))) | 839 (pos (if (and byte-compile-current-file |
826 (message "While compiling %s%s:" | 840 (integerp byte-compile-last-line)) |
827 (or byte-compile-current-form "toplevel forms") | 841 (format "%d:" byte-compile-last-line) |
828 (if byte-compile-current-file | 842 "")) |
829 (if (stringp byte-compile-current-file) | 843 (form (or byte-compile-current-form "toplevel form"))) |
830 (concat " in file " byte-compile-current-file) | 844 (cond (noninteractive |
831 (concat " in buffer " | 845 (when (byte-compile-display-log-head-p) |
832 (buffer-name byte-compile-current-file))) | 846 (message "%s In %s" file form)) |
833 ""))) | 847 (message "%s%s %s" file pos string)) |
834 (message " %s" string)) | 848 (t |
835 (t | 849 (save-excursion |
836 (save-excursion | 850 (set-buffer (get-buffer-create "*Compile-Log*")) |
837 (set-buffer (get-buffer-create "*Compile-Log*")) | 851 (goto-char (point-max)) |
838 (goto-char (point-max)) | 852 (when (byte-compile-display-log-head-p) |
839 (cond ((or (and byte-compile-current-file | 853 (insert (format "\nIn %s" form))) |
840 (not (equal byte-compile-current-file | 854 (insert (format "\n%s%s\n%s\n" file pos string)) |
841 byte-compile-last-logged-file))) | 855 (when (and fill (not (string-match "\n" string))) |
842 (and byte-compile-last-warned-form | 856 (let ((fill-prefix " ") (fill-column 78)) |
843 (not (eq byte-compile-current-form | 857 (fill-paragraph nil))))))) |
844 byte-compile-last-warned-form)))) | |
845 ;; This is redundant, since it is given at the start of the | |
846 ;; file, and the extra clutter gets in the way -- rms. | |
847 ;; (if (and byte-compile-current-file | |
848 ;; (not (equal byte-compile-current-file | |
849 ;; byte-compile-last-logged-file))) | |
850 ;; (insert "\n\^L\n" (current-time-string) "\n")) | |
851 (insert "\nWhile compiling " | |
852 (if byte-compile-current-form | |
853 (format "%s" byte-compile-current-form) | |
854 "toplevel forms")) | |
855 ;; This is redundant, since it is given at the start of the file, | |
856 ;; and the extra clutter gets in the way -- rms. | |
857 ;; (if byte-compile-current-file | |
858 ;; (if (stringp byte-compile-current-file) | |
859 ;; (insert " in file " byte-compile-current-file) | |
860 ;; (insert " in buffer " | |
861 ;; (buffer-name byte-compile-current-file)))) | |
862 (insert ":\n"))) | |
863 (insert " " string "\n") | |
864 (if (and fill (not (string-match "\n" string))) | |
865 (let ((fill-prefix " ") | |
866 (fill-column 78)) | |
867 (fill-paragraph nil))) | |
868 ))) | |
869 (setq byte-compile-last-logged-file byte-compile-current-file | 858 (setq byte-compile-last-logged-file byte-compile-current-file |
870 byte-compile-last-warned-form byte-compile-current-form)) | 859 byte-compile-last-warned-form byte-compile-current-form)) |
871 | 860 |
872 ;; Log the start of a file in *Compile-Log*, and mark it as done. | 861 ;; Log the start of a file in *Compile-Log*, and mark it as done. |
873 ;; But do nothing in batch mode. | 862 ;; But do nothing in batch mode. |
887 | 876 |
888 (defun byte-compile-warn (format &rest args) | 877 (defun byte-compile-warn (format &rest args) |
889 (setq format (apply 'format format args)) | 878 (setq format (apply 'format format args)) |
890 (if byte-compile-error-on-warn | 879 (if byte-compile-error-on-warn |
891 (error "%s" format) ; byte-compile-file catches and logs it | 880 (error "%s" format) ; byte-compile-file catches and logs it |
892 (byte-compile-log-1 (concat "** " format) t) | 881 (byte-compile-log-1 (concat "warning: " format) t) |
893 ;; It is useless to flash warnings too fast to be read. | 882 ;; It is useless to flash warnings too fast to be read. |
894 ;; Besides, they will all be shown at the end. | 883 ;; Besides, they will all be shown at the end. |
895 ;; (or noninteractive ; already written on stdout. | 884 ;; (or noninteractive ; already written on stdout. |
896 ;; (message "Warning: %s" format)) | 885 ;; (message "Warning: %s" format)) |
897 )) | 886 )) |
899 ;;; This function should be used to report errors that have halted | 888 ;;; This function should be used to report errors that have halted |
900 ;;; compilation of the current file. | 889 ;;; compilation of the current file. |
901 (defun byte-compile-report-error (error-info) | 890 (defun byte-compile-report-error (error-info) |
902 (setq byte-compiler-error-flag t) | 891 (setq byte-compiler-error-flag t) |
903 (byte-compile-log-1 | 892 (byte-compile-log-1 |
904 (concat "!! " | 893 (concat "error: " |
905 (format (if (cdr error-info) "%s (%s)" "%s") | 894 (format (if (cdr error-info) "%s (%s)" "%s") |
906 (get (car error-info) 'error-message) | 895 (downcase (get (car error-info) 'error-message)) |
907 (prin1-to-string (cdr error-info)))))) | 896 (prin1-to-string (cdr error-info)))))) |
908 | 897 |
909 ;;; Used by make-obsolete. | 898 ;;; Used by make-obsolete. |
910 (defun byte-compile-obsolete (form) | 899 (defun byte-compile-obsolete (form) |
911 (let* ((new (get (car form) 'byte-obsolete-info)) | 900 (let* ((new (get (car form) 'byte-obsolete-info)) |
1125 (setq byte-compile-unresolved-functions | 1114 (setq byte-compile-unresolved-functions |
1126 (delq calls byte-compile-unresolved-functions))))) | 1115 (delq calls byte-compile-unresolved-functions))))) |
1127 ))) | 1116 ))) |
1128 | 1117 |
1129 (defun byte-compile-print-syms (str1 strn syms) | 1118 (defun byte-compile-print-syms (str1 strn syms) |
1130 (cond | 1119 (cond ((and (cdr syms) (not noninteractive)) |
1131 ((cdr syms) | 1120 (let* ((str strn) |
1132 (let* ((str strn) | 1121 (L (length str)) |
1133 (L (length str)) | 1122 s) |
1134 s) | 1123 (while syms |
1135 (while syms | 1124 (setq s (symbol-name (pop syms)) |
1136 (setq s (symbol-name (pop syms)) | 1125 L (+ L (length s) 2)) |
1137 L (+ L (length s) 2)) | 1126 (if (< L (1- fill-column)) |
1138 (if (< L (1- fill-column)) | 1127 (setq str (concat str " " s (and syms ","))) |
1139 (setq str (concat str " " s (and syms ","))) | 1128 (setq str (concat str "\n " s (and syms ",")) |
1140 (setq str (concat str "\n " s (and syms ",")) | 1129 L (+ (length s) 4)))) |
1141 L (+ (length s) 4)))) | 1130 (byte-compile-warn "%s" str))) |
1142 (byte-compile-warn "%s" str))) | 1131 ((cdr syms) |
1143 (syms | 1132 (byte-compile-warn "%s %s" |
1144 (byte-compile-warn str1 (car syms))))) | 1133 strn |
1134 (mapconcat #'symbol-name syms ", "))) | |
1135 | |
1136 (syms | |
1137 (byte-compile-warn str1 (car syms))))) | |
1145 | 1138 |
1146 ;; If we have compiled any calls to functions which are not known to be | 1139 ;; If we have compiled any calls to functions which are not known to be |
1147 ;; defined, issue a warning enumerating them. | 1140 ;; defined, issue a warning enumerating them. |
1148 ;; `unresolved' in the list `byte-compile-warnings' disables this. | 1141 ;; `unresolved' in the list `byte-compile-warnings' disables this. |
1149 (defun byte-compile-warn-about-unresolved-functions () | 1142 (defun byte-compile-warn-about-unresolved-functions () |
1150 (when (memq 'unresolved byte-compile-warnings) | 1143 (when (memq 'unresolved byte-compile-warnings) |
1151 (let ((byte-compile-current-form "the end of the data") | 1144 (let ((byte-compile-current-form :end) |
1152 (noruntime nil) | 1145 (noruntime nil) |
1153 (unresolved nil)) | 1146 (unresolved nil)) |
1154 ;; Separate the functions that will not be available at runtime | 1147 ;; Separate the functions that will not be available at runtime |
1155 ;; from the truly unresolved ones. | 1148 ;; from the truly unresolved ones. |
1156 (dolist (f byte-compile-unresolved-functions) | 1149 (dolist (f byte-compile-unresolved-functions) |
1157 (setq f (car f)) | 1150 (setq f (car f)) |
1158 (if (fboundp f) (push f noruntime) (push f unresolved))) | 1151 (if (fboundp f) (push f noruntime) (push f unresolved))) |
1159 ;; Complain about the no-run-time functions | 1152 ;; Complain about the no-run-time functions |
1160 (byte-compile-print-syms | 1153 (byte-compile-print-syms |
1161 "The function `%s' might not be defined at runtime." | 1154 "the function `%s' might not be defined at runtime." |
1162 "The following functions might not be defined at runtime:" | 1155 "the following functions might not be defined at runtime:" |
1163 noruntime) | 1156 noruntime) |
1164 ;; Complain about the unresolved functions | 1157 ;; Complain about the unresolved functions |
1165 (byte-compile-print-syms | 1158 (byte-compile-print-syms |
1166 "The function `%s' is not known to be defined." | 1159 "the function `%s' is not known to be defined." |
1167 "The following functions are not known to be defined:" | 1160 "the following functions are not known to be defined:" |
1168 unresolved))) | 1161 unresolved))) |
1169 nil) | 1162 nil) |
1170 | 1163 |
1171 | 1164 |
1172 (defsubst byte-compile-const-symbol-p (symbol) | 1165 (defsubst byte-compile-const-symbol-p (symbol) |
1211 ) | 1204 ) |
1212 body))) | 1205 body))) |
1213 | 1206 |
1214 (defvar byte-compile-warnings-point-max nil) | 1207 (defvar byte-compile-warnings-point-max nil) |
1215 (defmacro displaying-byte-compile-warnings (&rest body) | 1208 (defmacro displaying-byte-compile-warnings (&rest body) |
1216 (list 'let | 1209 `(let ((byte-compile-warnings-point-max byte-compile-warnings-point-max)) |
1217 '((byte-compile-warnings-point-max byte-compile-warnings-point-max)) | |
1218 ;; Log the file name. | 1210 ;; Log the file name. |
1219 '(byte-compile-log-file) | 1211 (byte-compile-log-file) |
1220 ;; Record how much is logged now. | 1212 ;; Record how much is logged now. |
1221 ;; We will display the log buffer if anything more is logged | 1213 ;; We will display the log buffer if anything more is logged |
1222 ;; before the end of BODY. | 1214 ;; before the end of BODY. |
1223 '(or byte-compile-warnings-point-max | 1215 (unless byte-compile-warnings-point-max |
1224 (save-excursion | 1216 (save-excursion |
1225 (set-buffer (get-buffer-create "*Compile-Log*")) | 1217 (set-buffer (get-buffer-create "*Compile-Log*")) |
1226 (setq byte-compile-warnings-point-max (point-max)))) | 1218 (setq byte-compile-warnings-point-max (point-max)))) |
1227 (list 'unwind-protect | 1219 (unwind-protect |
1228 (list 'condition-case 'error-info | 1220 (condition-case error-info |
1229 (cons 'progn body) | 1221 (progn ,@body) |
1230 '(error | 1222 (error (byte-compile-report-error error-info))) |
1231 (byte-compile-report-error error-info))) | 1223 (save-excursion |
1232 '(save-excursion | 1224 ;; If there were compilation warnings, display them. |
1233 ;; If there were compilation warnings, display them. | 1225 (set-buffer "*Compile-Log*") |
1234 (set-buffer "*Compile-Log*") | 1226 (if (= byte-compile-warnings-point-max (point-max)) |
1235 (if (= byte-compile-warnings-point-max (point-max)) | 1227 nil |
1236 nil | 1228 (select-window |
1237 (select-window | 1229 (prog1 (selected-window) |
1238 (prog1 (selected-window) | 1230 (select-window (display-buffer (current-buffer))) |
1239 (select-window (display-buffer (current-buffer))) | 1231 (goto-char byte-compile-warnings-point-max) |
1240 (goto-char byte-compile-warnings-point-max) | 1232 (beginning-of-line) |
1241 (beginning-of-line) | 1233 (forward-line -1) |
1242 (forward-line -1) | 1234 (recenter 0)))))))) |
1243 (recenter 0)))))))) | |
1244 | 1235 |
1245 | 1236 |
1246 ;;;###autoload | 1237 ;;;###autoload |
1247 (defun byte-force-recompile (directory) | 1238 (defun byte-force-recompile (directory) |
1248 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file. | 1239 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file. |
1535 (while (progn | 1526 (while (progn |
1536 (while (progn (skip-chars-forward " \t\n\^l") | 1527 (while (progn (skip-chars-forward " \t\n\^l") |
1537 (looking-at ";")) | 1528 (looking-at ";")) |
1538 (forward-line 1)) | 1529 (forward-line 1)) |
1539 (not (eobp))) | 1530 (not (eobp))) |
1540 (byte-compile-file-form (read inbuffer))) | 1531 (let ((byte-compile-last-line (count-lines (point-min) (point)))) |
1532 (byte-compile-file-form (read inbuffer)))) | |
1541 | 1533 |
1542 ;; Compile pending forms at end of file. | 1534 ;; Compile pending forms at end of file. |
1543 (byte-compile-flush-pending) | 1535 (byte-compile-flush-pending) |
1544 (byte-compile-warn-about-unresolved-functions) | 1536 (byte-compile-warn-about-unresolved-functions) |
1545 ;; Should we always do this? When calling multiple files, it | 1537 ;; Should we always do this? When calling multiple files, it |
1969 (let ((body (nthcdr 3 form))) | 1961 (let ((body (nthcdr 3 form))) |
1970 (if (and (stringp (car body)) | 1962 (if (and (stringp (car body)) |
1971 (symbolp (car-safe (cdr-safe body))) | 1963 (symbolp (car-safe (cdr-safe body))) |
1972 (car-safe (cdr-safe body)) | 1964 (car-safe (cdr-safe body)) |
1973 (stringp (car-safe (cdr-safe (cdr-safe body))))) | 1965 (stringp (car-safe (cdr-safe (cdr-safe body))))) |
1974 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s" | 1966 (byte-compile-warn "probable `\"' without `\\' in doc string of %s" |
1975 (nth 1 form)))) | 1967 (nth 1 form)))) |
1976 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form)))) | 1968 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form)))) |
1977 (code (byte-compile-byte-code-maker new-one))) | 1969 (code (byte-compile-byte-code-maker new-one))) |
1978 (if this-one | 1970 (if this-one |
1979 (setcdr this-one new-one) | 1971 (setcdr this-one new-one) |
2408 (byte-compile-out 'byte-call (length (cdr form)))) | 2400 (byte-compile-out 'byte-call (length (cdr form)))) |
2409 | 2401 |
2410 (defun byte-compile-variable-ref (base-op var) | 2402 (defun byte-compile-variable-ref (base-op var) |
2411 (if (or (not (symbolp var)) (byte-compile-const-symbol-p var)) | 2403 (if (or (not (symbolp var)) (byte-compile-const-symbol-p var)) |
2412 (byte-compile-warn (if (eq base-op 'byte-varbind) | 2404 (byte-compile-warn (if (eq base-op 'byte-varbind) |
2413 "Attempt to let-bind %s %s" | 2405 "attempt to let-bind %s %s" |
2414 "Variable reference to %s %s") | 2406 "variable reference to %s %s") |
2415 (if (symbolp var) "constant" "nonvariable") | 2407 (if (symbolp var) "constant" "nonvariable") |
2416 (prin1-to-string var)) | 2408 (prin1-to-string var)) |
2417 (if (and (get var 'byte-obsolete-variable) | 2409 (if (and (get var 'byte-obsolete-variable) |
2418 (memq 'obsolete byte-compile-warnings)) | 2410 (memq 'obsolete byte-compile-warnings)) |
2419 (let* ((ob (get var 'byte-obsolete-variable)) | 2411 (let* ((ob (get var 'byte-obsolete-variable)) |
3262 ;; just as a real defvar would, but only in top-level forms. | 3254 ;; just as a real defvar would, but only in top-level forms. |
3263 (when (and (cddr form) (null byte-compile-current-form)) | 3255 (when (and (cddr form) (null byte-compile-current-form)) |
3264 `(push ',var current-load-list)) | 3256 `(push ',var current-load-list)) |
3265 (when (> (length form) 3) | 3257 (when (> (length form) 3) |
3266 (when (and string (not (stringp string))) | 3258 (when (and string (not (stringp string))) |
3267 (byte-compile-warn "Third arg to %s %s is not a string: %s" | 3259 (byte-compile-warn "third arg to %s %s is not a string: %s" |
3268 fun var string)) | 3260 fun var string)) |
3269 `(put ',var 'variable-documentation ,string)) | 3261 `(put ',var 'variable-documentation ,string)) |
3270 (if (cdr (cdr form)) ; `value' provided | 3262 (if (cdr (cdr form)) ; `value' provided |
3271 (if (eq fun 'defconst) | 3263 (if (eq fun 'defconst) |
3272 ;; `defconst' sets `var' unconditionally. | 3264 ;; `defconst' sets `var' unconditionally. |
3548 (setq error t))) | 3540 (setq error t))) |
3549 (setq files (cdr files)))) | 3541 (setq files (cdr files)))) |
3550 (if (null (batch-byte-compile-file (car command-line-args-left))) | 3542 (if (null (batch-byte-compile-file (car command-line-args-left))) |
3551 (setq error t))) | 3543 (setq error t))) |
3552 (setq command-line-args-left (cdr command-line-args-left))) | 3544 (setq command-line-args-left (cdr command-line-args-left))) |
3553 (message "Done") | |
3554 (kill-emacs (if error 1 0)))) | 3545 (kill-emacs (if error 1 0)))) |
3555 | 3546 |
3556 (defun batch-byte-compile-file (file) | 3547 (defun batch-byte-compile-file (file) |
3557 (condition-case err | 3548 (condition-case err |
3558 (byte-compile-file file) | 3549 (byte-compile-file file) |