428
|
1 ;;; bytecomp-runtime.el --- byte-compiler support for inlining
|
|
2
|
|
3 ;; Copyright (C) 1992, 1997 Free Software Foundation, Inc.
|
771
|
4 ;; Copyright (C) 2002 Ben Wing.
|
428
|
5
|
|
6 ;; Author: Jamie Zawinski <jwz@jwz.org>
|
|
7 ;; Author: Hallvard Furuseth <hbf@ulrik.uio.no>
|
|
8 ;; Maintainer: XEmacs Development Team
|
|
9 ;; Keywords: internal, dumped
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Synched up with: FSF 19.30.
|
|
29
|
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; This file is dumped with XEmacs.
|
|
33
|
|
34 ;; The code in this file should always be loaded, because it defines things
|
|
35 ;; like "defsubst" which should work interpreted as well. The code in
|
|
36 ;; bytecomp.el and byte-optimize.el can be loaded as needed.
|
|
37
|
|
38 ;; interface to selectively inlining functions.
|
|
39 ;; This only happens when source-code optimization is turned on.
|
|
40
|
|
41 ;;; Code:
|
|
42
|
|
43 ;; Redefined in byte-optimize.el.
|
|
44 ;; This is not documented--it's not clear that we should promote it.
|
|
45 (fset 'inline 'progn)
|
|
46 (put 'inline 'lisp-indent-hook 0)
|
|
47
|
|
48
|
|
49 ;;; Interface to inline functions.
|
|
50
|
|
51 ;; FSF comments the next two out, but I see no reason to do so. --ben
|
|
52 (defmacro proclaim-inline (&rest fns)
|
|
53 "Cause the named functions to be open-coded when called from compiled code.
|
|
54 They will only be compiled open-coded when `byte-optimize' is true."
|
|
55 (cons 'eval-and-compile
|
|
56 (apply
|
|
57 'nconc
|
|
58 (mapcar
|
|
59 #'(lambda (x)
|
|
60 `((or (memq (get ',x 'byte-optimizer)
|
|
61 '(nil byte-compile-inline-expand))
|
|
62 (error
|
|
63 "%s already has a byte-optimizer, can't make it inline"
|
|
64 ',x))
|
|
65 (put ',x 'byte-optimizer 'byte-compile-inline-expand)))
|
|
66 fns))))
|
|
67
|
|
68
|
|
69 (defmacro proclaim-notinline (&rest fns)
|
|
70 "Cause the named functions to no longer be open-coded."
|
|
71 (cons 'eval-and-compile
|
|
72 (apply
|
|
73 'nconc
|
|
74 (mapcar
|
|
75 #'(lambda (x)
|
|
76 `((if (eq (get ',x 'byte-optimizer)
|
|
77 'byte-compile-inline-expand)
|
|
78 (put ',x 'byte-optimizer nil))))
|
|
79 fns))))
|
|
80
|
|
81 ;; This has a special byte-hunk-handler in bytecomp.el.
|
|
82 (defmacro defsubst (name arglist &rest body)
|
|
83 "Define an inline function. The syntax is just like that of `defun'."
|
|
84 (or (memq (get name 'byte-optimizer)
|
|
85 '(nil byte-compile-inline-expand))
|
|
86 (error "`%s' is a primitive" name))
|
|
87 (list 'prog1
|
|
88 (cons 'defun (cons name (cons arglist body)))
|
|
89 (list 'proclaim-inline name)))
|
|
90 ; Instead of the above line, FSF has this:
|
|
91 ; (list 'eval-and-compile
|
|
92 ; (list 'put (list 'quote name)
|
|
93 ; ''byte-optimizer ''byte-compile-inline-expand))))
|
|
94
|
2444
|
95 (defun make-obsolete (fn new &optional when)
|
991
|
96 "Make the byte-compiler warn that function FN is obsolete.
|
428
|
97 The warning will say that NEW should be used instead.
|
2444
|
98 If NEW is a string, that is the `use instead' message.
|
|
99 If provided, WHEN should be a string indicating when the function
|
|
100 was first made obsolete, for example a date or a release number."
|
428
|
101 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
|
|
102 (let ((handler (get fn 'byte-compile)))
|
|
103 (if (eq 'byte-compile-obsolete handler)
|
|
104 (setcar (get fn 'byte-obsolete-info) new)
|
|
105 (put fn 'byte-obsolete-info (cons new handler))
|
|
106 (put fn 'byte-compile 'byte-compile-obsolete)))
|
|
107 fn)
|
|
108
|
2444
|
109 (defun make-obsolete-variable (var new &optional when)
|
991
|
110 "Make the byte-compiler warn that variable VAR is obsolete,
|
428
|
111 and NEW should be used instead. If NEW is a string, then that is the
|
2444
|
112 `use instead' message.
|
|
113 If provided, WHEN should be a string indicating when the variable
|
|
114 was first made obsolete, for example a date or a release number."
|
428
|
115 (interactive
|
|
116 (list
|
|
117 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
|
|
118 (if (equal str "") (error ""))
|
|
119 (intern str))
|
|
120 (car (read-from-string (read-string "Obsoletion replacement: ")))))
|
|
121 (put var 'byte-obsolete-variable new)
|
|
122 var)
|
|
123
|
|
124 ;; By overwhelming demand, we separate out truly obsolete symbols from
|
|
125 ;; those that are present for GNU Emacs compatibility.
|
|
126 (defun make-compatible (fn new)
|
991
|
127 "Make the byte-compiler know that function FN is provided for compatibility.
|
428
|
128 The warning will say that NEW should be used instead.
|
|
129 If NEW is a string, that is the `use instead' message."
|
|
130 (interactive "aMake function compatible: \nxCompatible replacement: ")
|
|
131 (let ((handler (get fn 'byte-compile)))
|
|
132 (if (eq 'byte-compile-compatible handler)
|
|
133 (setcar (get fn 'byte-compatible-info) new)
|
|
134 (put fn 'byte-compatible-info (cons new handler))
|
|
135 (put fn 'byte-compile 'byte-compile-compatible)))
|
|
136 fn)
|
|
137
|
|
138 (defun make-compatible-variable (var new)
|
991
|
139 "Make the byte-compiler know that variable VAR is provided for compatibility,
|
428
|
140 and NEW should be used instead. If NEW is a string, then that is the
|
|
141 `use instead' message."
|
|
142 (interactive
|
|
143 (list
|
|
144 (let ((str (completing-read "Make variable compatible: "
|
|
145 obarray 'boundp t)))
|
|
146 (if (equal str "") (error ""))
|
|
147 (intern str))
|
|
148 (car (read-from-string (read-string "Compatible replacement: ")))))
|
|
149 (put var 'byte-compatible-variable new)
|
|
150 var)
|
|
151
|
|
152 (put 'dont-compile 'lisp-indent-hook 0)
|
|
153 (defmacro dont-compile (&rest body)
|
|
154 "Like `progn', but the body always runs interpreted (not compiled).
|
|
155 If you think you need this, you're probably making a mistake somewhere."
|
|
156 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
|
|
157
|
|
158
|
|
159 ;;; interface to evaluating things at compile time and/or load time
|
|
160 ;;; these macro must come after any uses of them in this file, as their
|
|
161 ;;; definition in the file overrides the magic definitions on the
|
|
162 ;;; byte-compile-macro-environment.
|
|
163
|
|
164 (put 'eval-when-compile 'lisp-indent-hook 0)
|
|
165 (defmacro eval-when-compile (&rest body)
|
|
166 "Like `progn', but evaluates the body at compile time.
|
|
167 The result of the body appears to the compiler as a quoted constant."
|
|
168 ;; Not necessary because we have it in b-c-initial-macro-environment
|
|
169 ;; (list 'quote (eval (cons 'progn body)))
|
|
170 (cons 'progn body))
|
|
171
|
|
172 (put 'eval-and-compile 'lisp-indent-hook 0)
|
|
173 (defmacro eval-and-compile (&rest body)
|
|
174 "Like `progn', but evaluates the body at compile time and at load time."
|
|
175 ;; Remember, it's magic.
|
|
176 (cons 'progn body))
|
|
177
|
|
178 ;;; From Emacs 20.
|
|
179 (put 'eval-when-feature 'lisp-indent-hook 1)
|
|
180 (defmacro eval-when-feature (feature &rest body)
|
|
181 "Run the body forms when FEATURE is featurep, be it now or later.
|
|
182 Called (eval-when-feature (FEATURE [. FILENAME]) BODYFORMS...).
|
|
183 If (featurep 'FEATURE), evals now; otherwise adds an elt to
|
|
184 `after-load-alist' (which see), using FEATURE as filename if FILENAME is nil."
|
|
185 (let ((file (or (cdr feature) (symbol-name (car feature)))))
|
|
186 `(let ((bodythunk #'(lambda () ,@body)))
|
|
187 (if (featurep ',(car feature))
|
|
188 (funcall bodythunk)
|
|
189 (setq after-load-alist (cons '(,file . (list 'lambda '() bodythunk))
|
|
190 after-load-alist))))))
|
502
|
191
|
|
192
|
|
193
|
|
194 ;;; Functions to cleanly eliminate warnings about undefined functions
|
|
195 ;;; or variables when the code knows what it's doing. These macros DO
|
|
196 ;;; NOT rely on any byte-compiler changes, and thus can be copied into
|
|
197 ;;; a package and used within it.
|
|
198
|
|
199 ;; NOTE: As a result of the above requirement, the macros rely on
|
|
200 ;; "tricks" to get the warnings suppressed. A cleaner way, of course,
|
|
201 ;; would be to extend the byte compiler to provide a proper interface.
|
|
202
|
|
203 ;; #### Should we require an unquoted symbol rather than a quoted one,
|
|
204 ;; as we currently do? The quoting gets no generality, as `eval' is
|
|
205 ;; called at compile time. But most functions and macros want quoted
|
|
206 ;; arguments, and I find it extremely confusing to deal with cases
|
|
207 ;; such as `throw' requiring a quoted argument but `block' an unquoted
|
|
208 ;; one.
|
|
209
|
|
210 (put 'with-boundp 'lisp-indent-function 1)
|
771
|
211 (defmacro with-boundp (variables &rest body)
|
|
212 "Evaluate BODY, but do not issue bytecomp warnings about VARIABLES undefined.
|
|
213 VARIABLES can be a symbol or a list of symbols and must be quoted. When
|
|
214 compiling this file, the warnings `reference to free variable VARIABLE' and
|
|
215 `assignment to free variable VARIABLE' will not occur anywhere in BODY, for
|
|
216 any of the listed variables. This is a clean way to avoid such warnings.
|
776
|
217
|
|
218 See also `if-boundp', `when-boundp', and `and-boundp' (ways to
|
|
219 conditionalize on a variable being bound and avoid warnings),
|
|
220 `declare-boundp' (issue a variable call without warnings), and
|
|
221 `globally-declare-boundp' (avoid warnings throughout a file about a
|
|
222 variable)."
|
771
|
223 (setq variables (eval variables))
|
|
224 (unless (consp variables)
|
|
225 (setq variables (list variables)))
|
502
|
226 `(progn
|
771
|
227 (declare (special ,@variables))
|
502
|
228 ,@body))
|
|
229
|
|
230 (put 'if-boundp 'lisp-indent-function 2)
|
771
|
231 (defmacro if-boundp (variable then &rest else)
|
|
232 "Equivalent to (if (boundp VARIABLE) THEN ELSE) but handles bytecomp warnings.
|
|
233 VARIABLE should be a quoted symbol. When compiling this file, the warnings
|
|
234 `reference to free variable VARIABLE' and `assignment to free variable
|
|
235 VARIABLE' will not occur anywhere in the if-statement. This is a clean way
|
776
|
236 to avoid such warnings. See also `with-boundp' and friends."
|
771
|
237 `(with-boundp ,variable
|
|
238 (if (boundp ,variable) ,then ,@else)))
|
502
|
239
|
771
|
240 (put 'when-boundp 'lisp-indent-function 1)
|
|
241 (defmacro when-boundp (variable &rest body)
|
|
242 "Equivalent to (when (boundp VARIABLE) BODY) but handles bytecomp warnings.
|
|
243 VARIABLE should be a quoted symbol. When compiling this file, the warnings
|
|
244 `reference to free variable VARIABLE' and `assignment to free variable
|
|
245 VARIABLE' will not occur anywhere in the when-statement. This is a clean
|
776
|
246 way to avoid such warnings. See also `with-boundp' and friends."
|
771
|
247 `(with-boundp ,variable
|
|
248 (when (boundp ,variable) ,@body)))
|
|
249
|
776
|
250 (put 'and-boundp 'lisp-indent-function 1)
|
|
251 (defmacro and-boundp (variable &rest args)
|
|
252 "Equivalent to (and (boundp VARIABLE) ARGS) but handles bytecomp warnings.
|
|
253 VARIABLE should be a quoted symbol. When compiling this file, the warnings
|
|
254 `reference to free variable VARIABLE' and `assignment to free variable
|
|
255 VARIABLE' will not occur anywhere in the and-statement. This is a clean
|
|
256 way to avoid such warnings. See also `with-boundp' and friends."
|
|
257 `(with-boundp ,variable
|
|
258 (and (boundp ,variable) ,@args)))
|
|
259
|
771
|
260 (defmacro declare-boundp (variable)
|
|
261 "Evaluate VARIABLE without bytecomp warnings about the symbol.
|
|
262
|
502
|
263 Sample usage is
|
|
264
|
|
265 (declare-boundp gpm-minor-mode)
|
|
266
|
|
267 which is equivalent to
|
|
268
|
771
|
269 (with-boundp 'gpm-minor-mode
|
776
|
270 gpm-minor-mode)
|
|
271
|
|
272 See also `with-boundp' and friends."
|
771
|
273 `(with-boundp ',variable ,variable))
|
502
|
274
|
771
|
275 (defmacro globally-declare-boundp (variables)
|
|
276 "Declare that all free uses of VARIABLES in this file are valid.
|
|
277 VARIABLES can be a symbol or a list of symbols and must be quoted.
|
502
|
278
|
771
|
279 When compiling this file, the warnings `reference to free variable
|
|
280 VARIABLE' and `assignment to free variable VARIABLE' will not occur
|
|
281 regardless of where references to VARIABLE occur in the file.
|
502
|
282
|
776
|
283 In general, you should *NOT* use this; use `with-boundp' or its friends to
|
|
284 wrap individual uses, as necessary. That way, you're more likely to
|
|
285 remember to put in the explicit checks for the variable's existence that
|
|
286 are usually necessary. However, `globally-declare-boundp' is better in
|
|
287 some circumstances, such as when writing an ELisp package that makes
|
|
288 integral use of optionally-compiled-in functionality (typically, an
|
|
289 interface onto a system library) and checks for the existence of the
|
|
290 functionality at some entry point to the package. See
|
|
291 `globally-declare-fboundp' for more information."
|
771
|
292 (setq variables (eval variables))
|
|
293 (if (not (consp variables))
|
|
294 (setq variables (list variables)))
|
502
|
295 `(progn
|
|
296 ;; (defvar FOO) has no side effects.
|
771
|
297 ,@(mapcar #'(lambda (sym) `(defvar ,sym)) variables)))
|
502
|
298
|
|
299 (defun byte-compile-with-fboundp (form)
|
|
300 (byte-compile-form (cons 'progn (cdr (cdr form))))
|
|
301 ;; Unfortunately, byte-compile-unresolved-functions is used not only
|
|
302 ;; for unresolved-function warnings, but also in connection with the
|
|
303 ;; following warnings:
|
|
304
|
|
305 ;; "defsubst %s was used before it was defined"
|
|
306 ;; "%s being defined to take %s%s, but was previously called with %s"
|
|
307
|
|
308 ;; By hacking byte-compile-unresolved-functions like this, we
|
|
309 ;; effectively disable these warnings. But code should not be using
|
|
310 ;; `with-fboundp' with a function defined later on in the same
|
|
311 ;; file, so this is not a big deal.
|
|
312
|
|
313 (let ((symbols (eval (car (cdr form)))))
|
|
314 (unless (consp symbols)
|
|
315 (setq symbols (list symbols)))
|
|
316 (setq symbols (mapcar #'(lambda (sym) (cons sym nil)) symbols))
|
|
317 (setq byte-compile-unresolved-functions
|
|
318 (set-difference byte-compile-unresolved-functions symbols
|
|
319 :key #'car))
|
|
320 ))
|
|
321
|
|
322 ;; EEEEEEEEVIL hack. We need to create our own byte-compilation
|
|
323 ;; method so that the proper variables are bound while compilation
|
|
324 ;; takes place (which is when the warnings get noticed and batched
|
|
325 ;; up). What we really want to do is make `with-fboundp' a macro
|
|
326 ;; that simply `progn's its BODY; but GOD DAMN IT, macros can't have
|
|
327 ;; their own byte-compilation methods! So we make `with-fboundp' a
|
|
328 ;; macro calling `with-fboundp-1', which is cleverly aliased to
|
|
329 ;; progn. This way we can put a byte-compilation method on
|
|
330 ;; `with-fboundp-1', and when interpreting, progn will duly skip
|
|
331 ;; the first, quoted argument, i.e. the symbol name. (We could make
|
|
332 ;; `with-fboundp-1' a regular function, but then we'd have to thunk
|
|
333 ;; BODY and eval it at runtime. We could probably just do this using
|
|
334 ;; (apply 'progn BODY), but the existing method is more obviously
|
|
335 ;; guaranteed to work.)
|
|
336 ;;
|
|
337 ;; In defense, cl-macs.el does a very similar thing with
|
|
338 ;; `cl-block-wrapper'.
|
|
339
|
|
340 (put 'with-fboundp-1 'byte-compile 'byte-compile-with-fboundp)
|
|
341 (defalias 'with-fboundp-1 'progn)
|
|
342
|
|
343 (put 'with-fboundp 'lisp-indent-function 1)
|
771
|
344 (defmacro with-fboundp (functions &rest body)
|
|
345 "Evaluate BODY, but do not issue bytecomp warnings about FUNCTIONS undefined.
|
|
346 FUNCTIONS can be a symbol or a list of symbols and must be quoted. When
|
|
347 compiling this file, the warning `the function FUNCTION is not known to be
|
|
348 defined' will not occur anywhere in BODY, for any of the listed functions.
|
776
|
349 This is a clean way to avoid such warnings.
|
|
350
|
|
351 See also `if-fboundp', `when-fboundp', and `and-fboundp' (ways to
|
|
352 conditionalize on a function being bound and avoid warnings),
|
|
353 `declare-fboundp' (issue a function call without warnings), and
|
|
354 `globally-declare-fboundp' (avoid warnings throughout a file about a
|
|
355 function)."
|
771
|
356 `(with-fboundp-1 ,functions ,@body))
|
502
|
357
|
|
358 (put 'if-fboundp 'lisp-indent-function 2)
|
771
|
359 (defmacro if-fboundp (function then &rest else)
|
|
360 "Equivalent to (if (fboundp FUNCTION) THEN ELSE) but handles bytecomp warnings.
|
|
361 FUNCTION should be a quoted symbol. When compiling this file, the warning
|
|
362 `the function FUNCTION is not known to be defined' will not occur anywhere
|
|
363 in the if-statement. This is a clean way to avoid such warnings. See also
|
776
|
364 `with-fboundp' and friends."
|
771
|
365 `(with-fboundp ,function
|
|
366 (if (fboundp ,function) ,then ,@else)))
|
|
367
|
|
368 (put 'when-fboundp 'lisp-indent-function 1)
|
|
369 (defmacro when-fboundp (function &rest body)
|
|
370 "Equivalent to (when (fboundp FUNCTION) BODY) but handles bytecomp warnings.
|
|
371 FUNCTION should be a quoted symbol. When compiling this file, the warning
|
|
372 `the function FUNCTION is not known to be defined' will not occur anywhere
|
776
|
373 in the when-statement. This is a clean way to avoid such warnings. See also
|
|
374 `with-fboundp' and friends."
|
771
|
375 `(with-fboundp ,function
|
|
376 (when (fboundp ,function) ,@body)))
|
502
|
377
|
776
|
378 (put 'and-fboundp 'lisp-indent-function 1)
|
|
379 (defmacro and-fboundp (function &rest args)
|
|
380 "Equivalent to (and (fboundp FUNCTION) ARGS) but handles bytecomp warnings.
|
|
381 FUNCTION should be a quoted symbol. When compiling this file, the warning
|
|
382 `the function FUNCTION is not known to be defined' will not occur anywhere
|
|
383 in the and-statement. This is a clean way to avoid such warnings. See also
|
|
384 `with-fboundp' and friends."
|
|
385 `(with-fboundp ,function
|
|
386 (and (fboundp ,function) ,@args)))
|
|
387
|
502
|
388 (defmacro declare-fboundp (form)
|
|
389 "Execute FORM (a function call) without bytecomp warnings about the call.
|
|
390 Sample usage is
|
|
391
|
|
392 (declare-fboundp (x-keysym-on-keyboard-sans-modifiers-p 'backspace))
|
|
393
|
|
394 which is equivalent to
|
|
395
|
|
396 (with-fboundp 'x-keysym-on-keyboard-sans-modifiers-p
|
776
|
397 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))
|
|
398
|
|
399 See also `with-fboundp' and friends."
|
502
|
400 `(with-fboundp ',(car form) ,form))
|
|
401
|
771
|
402 (defmacro globally-declare-fboundp (functions)
|
|
403 "Declare that all calls to function FUNCTIONS in this file are valid.
|
|
404 FUNCTIONS can be a symbol or a list of symbols and must be quoted.
|
502
|
405
|
771
|
406 When compiling this file, the warning `the function FUNCTION is not known
|
|
407 to be defined' will not occur regardless of where calls to FUNCTION occur
|
|
408 in the file.
|
502
|
409
|
776
|
410 In general, you should *NOT* use this; use `with-fboundp' or its friends to
|
|
411 wrap individual uses, as necessary. That way, you're more likely to
|
|
412 remember to put in the explicit checks for the function's existence that
|
|
413 are usually necessary. However, `globally-declare-fboundp' is better in
|
|
414 some circumstances, such as when writing an ELisp package that makes
|
|
415 integral use of optionally-compiled-in functionality (typically, an
|
|
416 interface onto a system library) and checks for the existence of the
|
|
417 functionality at some entry point to the package. The file `ldap.el' is a
|
|
418 good example: It provides a layer on top of the optional LDAP ELisp
|
|
419 primitives, makes calls to them throughout its code, and verifies the
|
|
420 presence of LDAP support at load time. Putting calls to `declare-fboundp'
|
|
421 throughout the code would be a major annoyance."
|
502
|
422 (when (cl-compiling-file)
|
771
|
423 (setq functions (eval functions))
|
|
424 (if (not (consp functions))
|
|
425 (setq functions (list functions)))
|
502
|
426 ;; Another hack. This works because the autoload environment is
|
|
427 ;; currently used ONLY to suppress warnings, and the actual
|
|
428 ;; autoload definition is not used. (NOTE: With this definition,
|
|
429 ;; we will get spurious "multiple autoloads for %s" warnings if we
|
771
|
430 ;; have an autoload later in the file for any functions in FUNCTIONS.
|
502
|
431 ;; This is not something that code should ever do, though.)
|
|
432 (setq byte-compile-autoload-environment
|
771
|
433 (append (mapcar #'(lambda (sym) (cons sym nil)) functions)
|
502
|
434 byte-compile-autoload-environment)))
|
|
435 nil)
|
|
436
|
|
437 (defun byte-compile-with-byte-compiler-warnings-suppressed (form)
|
|
438 (let ((byte-compile-warnings byte-compile-warnings)
|
|
439 (types (car (cdr form))))
|
|
440 (unless (consp types)
|
|
441 (setq types (list types)))
|
|
442 (if (eq byte-compile-warnings t)
|
|
443 (setq byte-compile-warnings byte-compile-default-warnings))
|
|
444 (setq byte-compile-warnings (set-difference byte-compile-warnings types))
|
|
445 (byte-compile-form (cons 'progn (cdr (cdr form))))))
|
|
446
|
|
447 ;; Same hack here as with `with-fboundp'.
|
|
448 (put 'with-byte-compiler-warnings-suppressed-1 'byte-compile
|
|
449 'byte-compile-with-byte-compiler-warnings-suppressed)
|
|
450 (defalias 'with-byte-compiler-warnings-suppressed-1 'progn)
|
|
451
|
|
452 (put 'with-byte-compiler-warnings-suppressed 'lisp-indent-function 1)
|
|
453 (defmacro with-byte-compiler-warnings-suppressed (type &rest body)
|
|
454 "Evaluate BODY, but do not issue bytecomp warnings TYPE.
|
|
455 TYPE should be one of `redefine', `callargs', `subr-callargs',
|
|
456 `free-vars', `unresolved', `unused-vars', `obsolete', or `pedantic',
|
|
457 or a list of one or more of these symbols. (See `byte-compile-warnings'.)
|
|
458 TYPE must be quoted.
|
|
459
|
|
460 NOTE: You should *NOT* under normal circumstances be using this!
|
|
461 There are better ways of avoiding most of these warnings. In particular:
|
|
462
|
|
463 -- use (declare (special ...)) if you are making use of
|
|
464 dynamically-scoped variables.
|
776
|
465 -- use `with-fboundp' and friends to avoid warnings about undefined functions
|
771
|
466 when you know the function actually exists.
|
776
|
467 -- use `with-boundp' and friends to avoid warnings about undefined variables
|
771
|
468 when you know the variable actually exists.
|
502
|
469 -- use `with-obsolete-variable' or `with-obsolete-function' if you
|
|
470 are purposely using such a variable or function."
|
|
471 `(with-byte-compiler-warnings-suppressed-1 ,type ,@body))
|
|
472
|
|
473 ;; #### These should be more clever. You could (e.g.) try fletting
|
|
474 ;; `byte-compile-obsolete' or temporarily removing the obsolete info
|
|
475 ;; from the symbol and putting it back with an unwind-protect. (Or
|
|
476 ;; better, modify the byte-compiler to provide a proper solution, and
|
|
477 ;; fix these macros to use it if available, or fall back on the way
|
|
478 ;; below. Remember, these definitions need to work with an unchanged
|
|
479 ;; byte compiler so that they can be copied and used in packages.)
|
|
480
|
|
481 (put 'with-obsolete-variable 'lisp-indent-function 1)
|
|
482 (defmacro with-obsolete-variable (symbol &rest body)
|
|
483 "Evaluate BODY but do not warn about usage of obsolete variable SYMBOL.
|
826
|
484 SYMBOL must be quoted and can be a list of SYMBOLS. See also
|
|
485 `with-obsolete-function'."
|
502
|
486 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body))
|
|
487
|
|
488 (put 'with-obsolete-function 'lisp-indent-function 1)
|
|
489 (defmacro with-obsolete-function (symbol &rest body)
|
|
490 "Evaluate BODY but do not warn about usage of obsolete function SYMBOL.
|
826
|
491 SYMBOL must be quoted and can be a list of SYMBOLS. See also
|
|
492 `with-obsolete-variable'."
|
502
|
493 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body))
|
428
|
494
|
|
495
|
|
496 ;;; Interface to file-local byte-compiler parameters.
|
|
497 ;;; Redefined in bytecomp.el.
|
|
498
|
|
499 ;;; The great RMS speaketh:
|
|
500 ;;;
|
|
501 ;;; I nuked this because it's not a good idea for users to think of
|
|
502 ;;; using it. These options are a matter of installation preference,
|
|
503 ;;; and have nothing to do with particular source files; it's a
|
|
504 ;;; mistake to suggest to users that they should associate these with
|
|
505 ;;; particular source files. There is hardly any reason to change
|
|
506 ;;; these parameters, anyway. --rms.
|
|
507 ;;;
|
|
508 ;;; But I'll leave this stuff alone. --ben
|
|
509
|
|
510 (put 'byte-compiler-options 'lisp-indent-hook 0)
|
|
511 (defmacro byte-compiler-options (&rest args)
|
|
512 "Set some compilation-parameters for this file.
|
|
513 This will affect only the file in which it appears; this does nothing when
|
|
514 evaluated, or when loaded from a .el file.
|
|
515
|
|
516 Each argument to this macro must be a list of a key and a value.
|
|
517
|
|
518 Keys: Values: Corresponding variable:
|
|
519
|
|
520 verbose t, nil byte-compile-verbose
|
|
521 optimize t, nil, source, byte byte-optimize
|
|
522 warnings list of warnings byte-compile-warnings
|
|
523 file-format emacs19, emacs20 byte-compile-emacs19-compatibility
|
|
524
|
|
525 The value specified with the `warnings' option must be a list, containing
|
|
526 some subset of the following flags:
|
|
527
|
|
528 free-vars references to variables not in the current lexical scope.
|
|
529 unused-vars references to non-global variables bound but not referenced.
|
|
530 unresolved calls to unknown functions.
|
|
531 callargs lambda calls with args that don't match the definition.
|
502
|
532 subr-callargs calls to subrs with args that don't match the definition.
|
428
|
533 redefine function cell redefined from a macro to a lambda or vice
|
|
534 versa, or redefined to take a different number of arguments.
|
502
|
535 obsolete use of an obsolete function or variable.
|
|
536 pedantic warn of use of compatible symbols.
|
428
|
537
|
|
538 If the first element if the list is `+' or `-' then the specified elements
|
|
539 are added to or removed from the current set of warnings, instead of the
|
|
540 entire set of warnings being overwritten.
|
|
541
|
|
542 For example, something like this might appear at the top of a source file:
|
|
543
|
|
544 (byte-compiler-options
|
|
545 (optimize t)
|
|
546 (warnings (- callargs)) ; Don't warn about arglist mismatch
|
|
547 (warnings (+ unused-vars)) ; Do warn about unused bindings
|
|
548 (file-format emacs19))"
|
|
549 nil)
|
|
550
|
|
551 ;;; bytecomp-runtime.el ends here
|