X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/e983096bb6a50fdae6625cb363642bcd74ec39c5..23373930daa192623bfda56960ccb04b2703fbe5:/lisp/emacs-lisp/byte-run.el diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index 06b28beab7..3fb3d841ed 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -1,19 +1,19 @@ ;;; byte-run.el --- byte-compiler support for inlining -;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005, -;; 2006, 2007, 2008 Free Software Foundation, Inc. +;; Copyright (C) 1992, 2001-2011 Free Software Foundation, Inc. ;; Author: Jamie Zawinski ;; Hallvard Furuseth ;; Maintainer: FSF ;; Keywords: internal +;; Package: emacs ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,9 +21,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -47,14 +45,19 @@ The return value of this function is not used." ;; Ignore the first element of `decl' (it's always `declare'). (while (setq decl (cdr decl)) (setq d (car decl)) - (cond ((and (consp d) (eq (car d) 'indent)) - (put macro 'lisp-indent-function (car (cdr d)))) - ((and (consp d) (eq (car d) 'debug)) - (put macro 'edebug-form-spec (car (cdr d)))) - ((and (consp d) (eq (car d) 'doc-string)) - (put macro 'doc-string-elt (car (cdr d)))) - (t - (message "Unknown declaration %s" d)))))) + (if (and (consp d) + (listp (cdr d)) + (null (cdr (cdr d)))) + (cond ((eq (car d) 'indent) + (put macro 'lisp-indent-function (car (cdr d)))) + ((eq (car d) 'debug) + (put macro 'edebug-form-spec (car (cdr d)))) + ((eq (car d) 'doc-string) + (put macro 'doc-string-elt (car (cdr d)))) + (t + (message "Unknown declaration %s" d))) + (message "Invalid declaration %s" d))))) + (setq macro-declaration-function 'macro-declaration-function) @@ -62,7 +65,6 @@ The return value of this function is not used." ;; Redefined in byte-optimize.el. ;; This is not documented--it's not clear that we should promote it. (fset 'inline 'progn) -(put 'inline 'lisp-indent-function 0) ;;; Interface to inline functions. @@ -103,6 +105,16 @@ The return value of this function is not used." (eval-and-compile (put ',name 'byte-optimizer 'byte-compile-inline-expand)))) +(defvar advertised-signature-table (make-hash-table :test 'eq :weakness 'key)) + +(defun set-advertised-calling-convention (function signature when) + "Set the advertised SIGNATURE of FUNCTION. +This will allow the byte-compiler to warn the programmer when she uses +an obsolete calling convention. WHEN specifies since when the calling +convention was modified." + (puthash (indirect-function function) signature + advertised-signature-table)) + (defun make-obsolete (obsolete-name current-name &optional when) "Make the byte-compiler warn that OBSOLETE-NAME is obsolete. The warning will say that CURRENT-NAME should be used instead. @@ -111,12 +123,14 @@ If CURRENT-NAME is a string, that is the `use instead' message If provided, WHEN should be a string indicating when the function was first made obsolete, for example a date or a release number." (interactive "aMake function obsolete: \nxObsoletion replacement: ") - (let ((handler (get obsolete-name 'byte-compile))) - (if (eq 'byte-compile-obsolete handler) - (setq handler (nth 1 (get obsolete-name 'byte-obsolete-info))) - (put obsolete-name 'byte-compile 'byte-compile-obsolete)) - (put obsolete-name 'byte-obsolete-info (list current-name handler when))) + (put obsolete-name 'byte-obsolete-info + ;; The second entry used to hold the `byte-compile' handler, but + ;; is not used any more nowadays. + (list (purecopy current-name) nil (purecopy when))) obsolete-name) +(set-advertised-calling-convention + ;; New code should always provide the `when' argument. + 'make-obsolete '(obsolete-name current-name when) "23.1") (defmacro define-obsolete-function-alias (obsolete-name current-name &optional when docstring) @@ -134,6 +148,10 @@ See the docstrings of `defalias' and `make-obsolete' for more details." `(progn (defalias ,obsolete-name ,current-name ,docstring) (make-obsolete ,obsolete-name ,current-name ,when))) +(set-advertised-calling-convention + ;; New code should always provide the `when' argument. + 'define-obsolete-function-alias + '(obsolete-name current-name when &optional docstring) "23.1") (defun make-obsolete-variable (obsolete-name current-name &optional when) "Make the byte-compiler warn that OBSOLETE-NAME is obsolete. @@ -147,35 +165,64 @@ was first made obsolete, for example a date or a release number." (if (equal str "") (error "")) (intern str)) (car (read-from-string (read-string "Obsoletion replacement: "))))) - (put obsolete-name 'byte-obsolete-variable (cons current-name when)) + (put obsolete-name 'byte-obsolete-variable + (cons + (if (stringp current-name) + (purecopy current-name) + current-name) (purecopy when))) obsolete-name) +(set-advertised-calling-convention + ;; New code should always provide the `when' argument. + 'make-obsolete-variable '(obsolete-name current-name when) "23.1") (defmacro define-obsolete-variable-alias (obsolete-name current-name &optional when docstring) "Make OBSOLETE-NAME a variable alias for CURRENT-NAME and mark it obsolete. - -\(define-obsolete-variable-alias 'old-var 'new-var \"22.1\" \"old-var's doc.\") - -is equivalent to the following two lines of code: - -\(defvaralias 'old-var 'new-var \"old-var's doc.\") -\(make-obsolete-variable 'old-var 'new-var \"22.1\") +This uses `defvaralias' and `make-obsolete-variable' (which see). +See the Info node `(elisp)Variable Aliases' for more details. If CURRENT-NAME is a defcustom (more generally, any variable where OBSOLETE-NAME may be set, e.g. in a .emacs file, before the alias is defined), then the define-obsolete-variable-alias -statement should be placed before the defcustom. This is so that -any user customizations are applied before the defcustom tries to -initialize the variable (this is due to the way `defvaralias' works). -Exceptions to this rule occur for define-obsolete-variable-alias -statements that are autoloaded, or in files dumped with Emacs. - -See the docstrings of `defvaralias' and `make-obsolete-variable' or -Info node `(elisp)Variable Aliases' for more details." +statement should be evaluated before the defcustom, if user +customizations are to be respected. The simplest way to achieve +this is to place the alias statement before the defcustom (this +is not necessary for aliases that are autoloaded, or in files +dumped with Emacs). This is so that any user customizations are +applied before the defcustom tries to initialize the +variable (this is due to the way `defvaralias' works). + +For the benefit of `custom-set-variables', if OBSOLETE-NAME has +any of the following properties, they are copied to +CURRENT-NAME, if it does not already have them: +'saved-value, 'saved-variable-comment." (declare (doc-string 4)) `(progn (defvaralias ,obsolete-name ,current-name ,docstring) + ;; See Bug#4706. + (dolist (prop '(saved-value saved-variable-comment)) + (and (get ,obsolete-name prop) + (null (get ,current-name prop)) + (put ,current-name prop (get ,obsolete-name prop)))) (make-obsolete-variable ,obsolete-name ,current-name ,when))) +(set-advertised-calling-convention + ;; New code should always provide the `when' argument. + 'define-obsolete-variable-alias + '(obsolete-name current-name when &optional docstring) "23.1") + +;; FIXME This is only defined in this file because the variable- and +;; function- versions are too. Unlike those two, this one is not used +;; by the byte-compiler (would be nice if it could warn about obsolete +;; faces, but it doesn't really do anything special with faces). +;; It only really affects M-x describe-face output. +(defmacro define-obsolete-face-alias (obsolete-face current-face when) + "Make OBSOLETE-FACE a face alias for CURRENT-FACE and mark it obsolete. +The string WHEN gives the Emacs version where OBSOLETE-FACE became +obsolete." + `(progn + (put ,obsolete-face 'face-alias ,current-face) + ;; Used by M-x describe-face. + (put ,obsolete-face 'obsolete-face (or (purecopy ,when) t)))) (defmacro dont-compile (&rest body) "Like `progn', but the body always runs interpreted (not compiled). @@ -242,5 +289,4 @@ In interpreted code, this is entirely equivalent to `progn'." ;; (file-format emacs19))" ;; nil) -;; arch-tag: 76f8328a-1f66-4df2-9b6d-5c3666dc05e9 ;;; byte-run.el ends here