Michael Sperber avatar Michael Sperber committed b3a2bff

Make f?boundp less necessary.

2013-03-02 Michael Sperber <mike@xemacs.org>;

* bytecomp.el (byte-compile-if): Port this patch from GNU Emacs:

Author: Dave Love <fx@gnu.org>;
Date: Thu Dec 12 20:27:43 2002 +0000

(byte-compile-if): Suppress warnings from
things protected by `(if (fboundp ...' or `(if (boundp ...'.

Comments (0)

Files changed (2)

+2013-03-02  Michael Sperber  <mike@xemacs.org>
+
+	* bytecomp.el (byte-compile-if): Port this patch from GNU Emacs:
+
+	Author: Dave Love <fx@gnu.org>
+	Date:   Thu Dec 12 20:27:43 2002 +0000
+
+	    (byte-compile-if): Suppress warnings from
+	    things protected by `(if (fboundp ...' or `(if (boundp ...'.
+
 2013-02-20  Michael Sperber  <mike@xemacs.org>
 
 	* files.el (file-remote-p): Remove an ancient piece of obsolete
 
 (defun byte-compile-if (form)
   (byte-compile-form (car (cdr form)))
-  (if (null (nthcdr 3 form))
-      ;; No else-forms
-      (let ((donetag (byte-compile-make-tag)))
-	(byte-compile-goto-if nil for-effect donetag)
-	(byte-compile-form (nth 2 form) for-effect)
-	(byte-compile-out-tag donetag))
-    (let ((donetag (byte-compile-make-tag)) (elsetag (byte-compile-make-tag)))
-      (byte-compile-goto 'byte-goto-if-nil elsetag)
-      (byte-compile-form (nth 2 form) for-effect)
-      (byte-compile-goto 'byte-goto donetag)
-      (byte-compile-out-tag elsetag)
-      (byte-compile-body (cdr (cdr (cdr form))) for-effect)
-      (byte-compile-out-tag donetag)))
+  ;; Check whether we have `(if (fboundp ...' or `(if (boundp ...'
+  ;; and avoid warnings about the relevent symbols in the consequent.
+  (let* ((clause (nth 1 form))
+	 (fbound (if (eq 'fboundp (car-safe clause))
+		     (and (eq 'quote (car-safe (nth 1 clause)))
+			  ;; Ignore if the symbol is already on the
+			  ;; unresolved list.
+			  (not (assq
+				(nth 1 (nth 1 clause)) ; the relevant symbol
+				byte-compile-unresolved-functions))
+			  (nth 1 (nth 1 clause)))))
+	 (bound (if (eq 'boundp (car-safe clause))
+		    (and (eq 'quote (car-safe (nth 1 clause)))
+			 (nth 1 (nth 1 clause)))))
+	 (donetag (byte-compile-make-tag)))
+    (if (null (nthcdr 3 form))
+	;; No else-forms
+	(progn
+	  (byte-compile-goto-if nil for-effect donetag)
+	  ;; Maybe add to the bound list.
+	  (let ((byte-compile-bound-variables
+		 (if bound
+		     (cons bound byte-compile-bound-variables)
+		   byte-compile-bound-variables)))
+	    (byte-compile-form (nth 2 form) for-effect))
+	  ;; Maybe remove the function symbol from the unresolved list.
+	  (if fbound
+	      (setq byte-compile-unresolved-functions
+		    (delq (assq fbound byte-compile-unresolved-functions)
+			  byte-compile-unresolved-functions)))
+	  (byte-compile-out-tag donetag))
+      (let ((elsetag (byte-compile-make-tag)))
+	(byte-compile-goto 'byte-goto-if-nil elsetag)
+	;; As above for the first form.
+	(let ((byte-compile-bound-variables
+		 (if bound
+		     (cons bound byte-compile-bound-variables)
+		   byte-compile-bound-variables)))
+	    (byte-compile-form (nth 2 form) for-effect))
+	(if fbound
+	    (setq byte-compile-unresolved-functions
+		  (delq (assq fbound byte-compile-unresolved-functions)
+			byte-compile-unresolved-functions)))
+	(byte-compile-goto 'byte-goto donetag)
+	(byte-compile-out-tag elsetag)
+	(byte-compile-body (cdr (cdr (cdr form))) for-effect)
+	(byte-compile-out-tag donetag))))
   (setq for-effect nil))
 
 (defun byte-compile-cond (clauses)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.