2001-07-16 07:46:48 +00:00
|
|
|
|
;;; cc-bytecomp.el --- compile time setup for proper compilation
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
2020-01-01 00:19:43 +00:00
|
|
|
|
;; Copyright (C) 2000-2020 Free Software Foundation, Inc.
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Martin Stjernholm
|
|
|
|
|
;; Maintainer: bug-cc-mode@gnu.org
|
|
|
|
|
;; Created: 15-Jul-2000
|
2010-08-29 16:17:13 +00:00
|
|
|
|
;; Keywords: c languages
|
|
|
|
|
;; Package: cc-mode
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
2001-07-13 12:59:13 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2001-03-21 12:59:36 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
2001-07-13 12:59:13 +00:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2001-03-21 12:59:36 +00:00
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; This file is used to ensure that the CC Mode files are correctly
|
|
|
|
|
;; compiled regardless the environment (e.g. if an older CC Mode with
|
|
|
|
|
;; outdated macros are loaded during compilation). It also provides
|
|
|
|
|
;; features to defeat the compiler warnings for selected symbols.
|
2002-04-22 00:35:36 +00:00
|
|
|
|
;;
|
|
|
|
|
;; There's really nothing CC Mode specific here; this functionality
|
|
|
|
|
;; ought to be provided by the byte compilers or some accompanying
|
2003-07-03 12:30:59 +00:00
|
|
|
|
;; library. To use it from some package "foo.el", begin by putting
|
|
|
|
|
;; the following blurb at the top of the file:
|
|
|
|
|
;;
|
|
|
|
|
;; (eval-when-compile
|
|
|
|
|
;; (let ((load-path
|
|
|
|
|
;; (if (and (boundp 'byte-compile-dest-file)
|
|
|
|
|
;; (stringp byte-compile-dest-file))
|
|
|
|
|
;; (cons (file-name-directory byte-compile-dest-file) load-path)
|
|
|
|
|
;; load-path)))
|
|
|
|
|
;; (load "cc-bytecomp" nil t))
|
|
|
|
|
;;
|
|
|
|
|
;; This (unfortunately rather clumsy) form will ensure that the
|
|
|
|
|
;; cc-bytecomp.el in the same directory as foo.el is loaded during
|
|
|
|
|
;; byte compilation of the latter.
|
|
|
|
|
;;
|
|
|
|
|
;; At the end of foo.el there should normally be a "(provide 'foo)".
|
|
|
|
|
;; Replace it with "(cc-provide 'foo)"; that is necessary to restore
|
|
|
|
|
;; the environment after the byte compilation. If you don't have a
|
|
|
|
|
;; `provide' at the end, you have to add the following as the very
|
|
|
|
|
;; last form in the file:
|
|
|
|
|
;;
|
|
|
|
|
;; (eval-when-compile (cc-bytecomp-restore-environment))
|
|
|
|
|
;;
|
|
|
|
|
;; Now everything is set to use the various functions and macros in
|
|
|
|
|
;; this package.
|
|
|
|
|
;;
|
|
|
|
|
;; If your package is split into several files, you should use
|
|
|
|
|
;; `cc-require', `cc-require-when-compile' or `cc-load' to load them.
|
|
|
|
|
;; That ensures that the files in the same directory always are
|
|
|
|
|
;; loaded, to avoid mixup with other versions of them that might exist
|
|
|
|
|
;; elsewhere in the load path.
|
|
|
|
|
;;
|
|
|
|
|
;; To suppress byte compiler warnings, use the macros
|
Merge some of the differences from the standalone CC-mode.
The main change is to only use the `category' text-property only when
available. For that many calls are changed to use c-get-char-property,
c-next-single-property-change, c-sc-scan-lists,
c-sc-parse-partial-sexp, c-unmark-<->-as-paren.
* lisp/progmodes/cc-align.el (c-lineup-respect-col-0): New function.
* lisp/progmodes/cc-cmds.el (c-forward-into-nomenclature)
(c-backward-into-nomenclature): Use cc-subword if subword-mode is
not available.
(c-beginning-of-defun, c-end-of-defun, c-mark-function)
(c-indent-line-or-region): Use c-region-is-active-p.
* lisp/progmodes/cc-defs.el (c-version): Bump up to 5.33.
(c-use-category): New const.
(c-next-single-property-change): New macro.
(c-region-is-active-p): Prefer region-active-p when available.
(c-search-backward-char-property): Fix old min/max typo; probably
a copy/paste error.
(c-mark-<-as-paren, c-mark->-as-paren, c-unmark-<->-as-paren):
Turn them into macros that obey c-use-category.
(c-sc-scan-lists-no-category+1+1, c-sc-scan-lists-no-category+1-1)
(c-sc-scan-lists-no-category-1+1, c-sc-scan-lists-no-category-1-1)
(c-sc-scan-lists, c-sc-parse-partial-sexp)
(c-looking-at-non-alphnumspace): New macros.
(c-sc-parse-partial-sexp-no-category): New function.
(c-emacs-features): Add `category-properties' element.
* lisp/progmodes/cc-engine.el (c-invalidate-state-cache, c-parse-state):
Handle the case where categories are not available.
(c-record-parse-state-state, c-replay-parse-state-state):
Handle marker values.
(c-before-change-check-<>-operators): Look for the `syntax-table'
property rather than for the corresponding `category'.
(c-looking-at-decl-block): Remove unused var
`c-disallow-comma-in-<>-arglists'.
(c-forward-<>-arglist-recur): Remove unused var
`orig-record-found-types'.
* lisp/progmodes/cc-langs.el (c-modified-constant): New lang var.
(c-known-type-key): Don't make a list just to throw it away.
* lisp/progmodes/cc-bytecomp.el (cc-bytecomp-unbound-variables)
(cc-bytecomp-original-functions, cc-bytecomp-original-properties)
(cc-bytecomp-loaded-files): Re-set each time the file is loaded.
(cc-bytecomp-obsolete-var, cc-bytecomp-ignore-obsolete)
(cc-bytecomp-obsolete-fun): Delete unused functions.
* lisp/progmodes/cc-mode.el (c-just-done-before-change): New var.
(c-basic-common-init): Initialize it.
(c-common-init): Only use mode-require-final-newline when available.
(c-before-change): Check and set c-just-done-before-change.
(c-after-change): Re-set c-just-done-before-change.
(c-advise-fl-for-region): New macro.
(lazy-lock-defer-rest-after-change, lazy-lock-defer-line-after-change)
(font-lock-after-change-function, jit-lock-after-change):
Advise if needed.
2014-12-01 20:06:49 +00:00
|
|
|
|
;; `cc-bytecomp-defun' and `cc-bytecomp-defvar'.
|
2003-07-03 12:30:59 +00:00
|
|
|
|
;;
|
|
|
|
|
;; This file is not used at all after the package has been byte
|
|
|
|
|
;; compiled. It is however necessary when running uncompiled.
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-16 07:46:48 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(defvar cc-bytecomp-unbound-variables nil)
|
|
|
|
|
(defvar cc-bytecomp-original-functions nil)
|
|
|
|
|
(defvar cc-bytecomp-original-properties nil)
|
|
|
|
|
(defvar cc-bytecomp-loaded-files nil)
|
Merge some of the differences from the standalone CC-mode.
The main change is to only use the `category' text-property only when
available. For that many calls are changed to use c-get-char-property,
c-next-single-property-change, c-sc-scan-lists,
c-sc-parse-partial-sexp, c-unmark-<->-as-paren.
* lisp/progmodes/cc-align.el (c-lineup-respect-col-0): New function.
* lisp/progmodes/cc-cmds.el (c-forward-into-nomenclature)
(c-backward-into-nomenclature): Use cc-subword if subword-mode is
not available.
(c-beginning-of-defun, c-end-of-defun, c-mark-function)
(c-indent-line-or-region): Use c-region-is-active-p.
* lisp/progmodes/cc-defs.el (c-version): Bump up to 5.33.
(c-use-category): New const.
(c-next-single-property-change): New macro.
(c-region-is-active-p): Prefer region-active-p when available.
(c-search-backward-char-property): Fix old min/max typo; probably
a copy/paste error.
(c-mark-<-as-paren, c-mark->-as-paren, c-unmark-<->-as-paren):
Turn them into macros that obey c-use-category.
(c-sc-scan-lists-no-category+1+1, c-sc-scan-lists-no-category+1-1)
(c-sc-scan-lists-no-category-1+1, c-sc-scan-lists-no-category-1-1)
(c-sc-scan-lists, c-sc-parse-partial-sexp)
(c-looking-at-non-alphnumspace): New macros.
(c-sc-parse-partial-sexp-no-category): New function.
(c-emacs-features): Add `category-properties' element.
* lisp/progmodes/cc-engine.el (c-invalidate-state-cache, c-parse-state):
Handle the case where categories are not available.
(c-record-parse-state-state, c-replay-parse-state-state):
Handle marker values.
(c-before-change-check-<>-operators): Look for the `syntax-table'
property rather than for the corresponding `category'.
(c-looking-at-decl-block): Remove unused var
`c-disallow-comma-in-<>-arglists'.
(c-forward-<>-arglist-recur): Remove unused var
`orig-record-found-types'.
* lisp/progmodes/cc-langs.el (c-modified-constant): New lang var.
(c-known-type-key): Don't make a list just to throw it away.
* lisp/progmodes/cc-bytecomp.el (cc-bytecomp-unbound-variables)
(cc-bytecomp-original-functions, cc-bytecomp-original-properties)
(cc-bytecomp-loaded-files): Re-set each time the file is loaded.
(cc-bytecomp-obsolete-var, cc-bytecomp-ignore-obsolete)
(cc-bytecomp-obsolete-fun): Delete unused functions.
* lisp/progmodes/cc-mode.el (c-just-done-before-change): New var.
(c-basic-common-init): Initialize it.
(c-common-init): Only use mode-require-final-newline when available.
(c-before-change): Check and set c-just-done-before-change.
(c-after-change): Re-set c-just-done-before-change.
(c-advise-fl-for-region): New macro.
(lazy-lock-defer-rest-after-change, lazy-lock-defer-line-after-change)
(font-lock-after-change-function, jit-lock-after-change):
Advise if needed.
2014-12-01 20:06:49 +00:00
|
|
|
|
|
|
|
|
|
(setq cc-bytecomp-unbound-variables nil)
|
|
|
|
|
(setq cc-bytecomp-original-functions nil)
|
|
|
|
|
(setq cc-bytecomp-original-properties nil)
|
|
|
|
|
(setq cc-bytecomp-loaded-files nil)
|
|
|
|
|
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(defvar cc-bytecomp-environment-set nil)
|
|
|
|
|
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(defmacro cc-bytecomp-debug-msg (&rest args)
|
2017-07-05 02:29:49 +00:00
|
|
|
|
(ignore args)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
;;`(message ,@args)
|
|
|
|
|
)
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
2015-01-13 15:39:36 +00:00
|
|
|
|
(defun cc-bytecomp-compiling-or-loading ()
|
|
|
|
|
;; Determine whether byte-compilation or loading is currently active,
|
|
|
|
|
;; returning 'compiling, 'loading or nil.
|
|
|
|
|
;; If both are active, the "innermost" activity counts. Note that
|
|
|
|
|
;; compilation can trigger loading (various `require' type forms)
|
|
|
|
|
;; and loading can trigger compilation (the package manager does
|
|
|
|
|
;; this). We walk the lisp stack if necessary.
|
|
|
|
|
(cond
|
|
|
|
|
((and load-in-progress
|
|
|
|
|
(boundp 'byte-compile-dest-file)
|
|
|
|
|
(stringp byte-compile-dest-file))
|
|
|
|
|
(let ((n 0) elt)
|
|
|
|
|
(while (and
|
|
|
|
|
(setq elt (backtrace-frame n))
|
|
|
|
|
(not (and (car elt)
|
|
|
|
|
(memq (cadr elt)
|
|
|
|
|
'(load require
|
|
|
|
|
byte-compile-file byte-recompile-directory
|
|
|
|
|
batch-byte-compile)))))
|
|
|
|
|
(setq n (1+ n)))
|
|
|
|
|
(cond
|
|
|
|
|
((memq (cadr elt) '(load require))
|
|
|
|
|
'loading)
|
|
|
|
|
((memq (cadr elt) '(byte-compile-file
|
|
|
|
|
byte-recompile-directory
|
|
|
|
|
batch-byte-compile))
|
|
|
|
|
'compiling)
|
|
|
|
|
(t ; Can't happen.
|
|
|
|
|
(message "cc-bytecomp-compiling-or-loading: System flags spuriously set")
|
|
|
|
|
nil))))
|
|
|
|
|
(load-in-progress
|
|
|
|
|
;; Being loaded.
|
|
|
|
|
'loading)
|
|
|
|
|
((and (boundp 'byte-compile-dest-file)
|
|
|
|
|
(stringp byte-compile-dest-file))
|
|
|
|
|
;; Being compiled.
|
|
|
|
|
'compiling)
|
|
|
|
|
(t
|
|
|
|
|
;; Being evaluated interactively.
|
|
|
|
|
nil)))
|
|
|
|
|
|
|
|
|
|
(defsubst cc-bytecomp-is-compiling ()
|
|
|
|
|
"Return non-nil if eval'ed during compilation."
|
|
|
|
|
(eq (cc-bytecomp-compiling-or-loading) 'compiling))
|
|
|
|
|
|
|
|
|
|
(defsubst cc-bytecomp-is-loading ()
|
|
|
|
|
"Return non-nil if eval'ed during loading.
|
|
|
|
|
Nil will be returned if we're in a compilation triggered by the loading."
|
|
|
|
|
(eq (cc-bytecomp-compiling-or-loading) 'loading))
|
|
|
|
|
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(defun cc-bytecomp-setup-environment ()
|
|
|
|
|
;; Eval'ed during compilation to setup variables, functions etc
|
|
|
|
|
;; declared with `cc-bytecomp-defvar' et al.
|
2015-01-13 15:39:36 +00:00
|
|
|
|
(if (not (cc-bytecomp-is-loading))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(let (p)
|
|
|
|
|
(if cc-bytecomp-environment-set
|
|
|
|
|
(error "Byte compilation environment already set - \
|
|
|
|
|
perhaps a `cc-bytecomp-restore-environment' is forgotten somewhere"))
|
|
|
|
|
(setq p cc-bytecomp-unbound-variables)
|
|
|
|
|
(while p
|
|
|
|
|
(if (not (boundp (car p)))
|
|
|
|
|
(progn
|
|
|
|
|
(eval `(defvar ,(car p)))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(set (car p) (intern (concat "cc-bytecomp-ignore-var:"
|
|
|
|
|
(symbol-name (car p)))))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-setup-environment: Covered variable %s"
|
|
|
|
|
(car p))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(setq p (cdr p)))
|
|
|
|
|
(setq p cc-bytecomp-original-functions)
|
|
|
|
|
(while p
|
|
|
|
|
(let ((fun (car (car p)))
|
|
|
|
|
(temp-macro (car (cdr (car p)))))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(if (not (fboundp fun))
|
|
|
|
|
(if temp-macro
|
|
|
|
|
(progn
|
|
|
|
|
(eval `(defmacro ,fun ,@temp-macro))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-setup-environment: Bound macro %s" fun))
|
|
|
|
|
(fset fun (intern (concat "cc-bytecomp-ignore-fun:"
|
|
|
|
|
(symbol-name fun))))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-setup-environment: Covered function %s" fun))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(setq p (cdr p)))
|
|
|
|
|
(setq p cc-bytecomp-original-properties)
|
|
|
|
|
(while p
|
|
|
|
|
(let ((sym (car (car (car p))))
|
|
|
|
|
(prop (cdr (car (car p))))
|
|
|
|
|
(tempdef (car (cdr (car p)))))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(put sym prop tempdef)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-setup-environment: Bound property %s for %s to %s"
|
|
|
|
|
prop sym tempdef))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(setq p (cdr p)))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(setq cc-bytecomp-environment-set t)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-setup-environment: Done"))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
(defun cc-bytecomp-restore-environment ()
|
|
|
|
|
;; Eval'ed during compilation to restore variables, functions etc
|
|
|
|
|
;; declared with `cc-bytecomp-defvar' et al.
|
2015-01-13 15:39:36 +00:00
|
|
|
|
(if (not (cc-bytecomp-is-loading))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(let (p)
|
|
|
|
|
(setq p cc-bytecomp-unbound-variables)
|
|
|
|
|
(while p
|
|
|
|
|
(let ((var (car p)))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(if (boundp var)
|
|
|
|
|
(if (eq (intern (concat "cc-bytecomp-ignore-var:"
|
|
|
|
|
(symbol-name var)))
|
|
|
|
|
(symbol-value var))
|
|
|
|
|
(progn
|
|
|
|
|
(makunbound var)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Unbound variable %s"
|
|
|
|
|
var))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Not restoring variable %s"
|
|
|
|
|
var))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(setq p (cdr p)))
|
|
|
|
|
(setq p cc-bytecomp-original-functions)
|
|
|
|
|
(while p
|
|
|
|
|
(let ((fun (car (car p)))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(temp-macro (car (cdr (car p))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(def (car (cdr (cdr (car p))))))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(if (fboundp fun)
|
|
|
|
|
(if (eq (or temp-macro
|
|
|
|
|
(intern (concat "cc-bytecomp-ignore-fun:"
|
|
|
|
|
(symbol-name fun))))
|
|
|
|
|
(symbol-function fun))
|
|
|
|
|
(if (eq def 'unbound)
|
|
|
|
|
(progn
|
|
|
|
|
(fmakunbound fun)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Unbound function %s"
|
|
|
|
|
fun))
|
|
|
|
|
(fset fun def)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Restored function %s"
|
|
|
|
|
fun))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Not restoring function %s"
|
|
|
|
|
fun))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(setq p (cdr p)))
|
|
|
|
|
(setq p cc-bytecomp-original-properties)
|
|
|
|
|
(while p
|
|
|
|
|
(let ((sym (car (car (car p))))
|
|
|
|
|
(prop (cdr (car (car p))))
|
|
|
|
|
(tempdef (car (cdr (car p))))
|
|
|
|
|
(origdef (cdr (cdr (car p)))))
|
|
|
|
|
(if (eq (get sym prop) tempdef)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(progn
|
|
|
|
|
(put sym prop origdef)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Restored property %s for %s to %s"
|
|
|
|
|
prop sym origdef))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Not restoring property %s for %s"
|
|
|
|
|
prop sym)))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(setq p (cdr p)))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(setq cc-bytecomp-environment-set nil)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-restore-environment: Done"))))
|
|
|
|
|
|
2017-07-05 02:29:49 +00:00
|
|
|
|
(defun cc-bytecomp-load (_cc-part)
|
2015-11-24 22:20:47 +00:00
|
|
|
|
;; A dummy function which will immediately be overwritten by the
|
|
|
|
|
;; following at load time. This should suppress the byte compiler
|
|
|
|
|
;; error that the function is "not known to be defined".
|
|
|
|
|
)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(eval
|
|
|
|
|
;; This eval is to avoid byte compilation of the function below.
|
|
|
|
|
;; There's some bug in XEmacs 21.4.6 that can cause it to dump core
|
|
|
|
|
;; here otherwise. My theory is that `cc-bytecomp-load' might be
|
|
|
|
|
;; redefined recursively during the `load' inside it, and if it in
|
|
|
|
|
;; that case is byte compiled then the byte interpreter gets
|
|
|
|
|
;; confused. I haven't succeeded in isolating the bug, though. /mast
|
|
|
|
|
|
|
|
|
|
'(defun cc-bytecomp-load (cc-part)
|
|
|
|
|
;; Eval'ed during compilation to load a CC Mode file from the source
|
|
|
|
|
;; directory (assuming it's the same as the compiled file
|
|
|
|
|
;; destination dir).
|
|
|
|
|
(if (and (boundp 'byte-compile-dest-file)
|
|
|
|
|
(stringp byte-compile-dest-file))
|
|
|
|
|
(progn
|
|
|
|
|
(cc-bytecomp-restore-environment)
|
|
|
|
|
(let ((load-path
|
|
|
|
|
(cons (file-name-directory byte-compile-dest-file)
|
|
|
|
|
load-path))
|
|
|
|
|
(cc-file (concat cc-part ".el")))
|
|
|
|
|
(if (member cc-file cc-bytecomp-loaded-files)
|
|
|
|
|
()
|
|
|
|
|
(setq cc-bytecomp-loaded-files
|
|
|
|
|
(cons cc-file cc-bytecomp-loaded-files))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-load: Loading %S" cc-file)
|
|
|
|
|
(load cc-file nil t t)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-load: Loaded %S" cc-file)))
|
|
|
|
|
(cc-bytecomp-setup-environment)
|
|
|
|
|
t))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
(defmacro cc-require (cc-part)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
"Force loading of the corresponding .el file in the current directory
|
|
|
|
|
during compilation, but compile in a `require'. Don't use within
|
|
|
|
|
`eval-when-compile'.
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
Having cyclic cc-require's will result in infinite recursion. That's
|
|
|
|
|
somewhat intentional."
|
|
|
|
|
`(progn
|
2013-05-30 23:20:05 +00:00
|
|
|
|
(eval-when-compile
|
|
|
|
|
(cc-bytecomp-load (symbol-name ,cc-part)))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(require ,cc-part)))
|
2015-11-24 19:44:34 +00:00
|
|
|
|
|
|
|
|
|
(defmacro cc-conditional-require (cc-part condition)
|
|
|
|
|
"If the CONDITION is satisfied at compile time, (i) force the
|
|
|
|
|
file CC-PART.el in the current directory to be loaded at compile
|
|
|
|
|
time, (ii) generate code to load the file at load time.
|
|
|
|
|
|
2019-11-11 18:30:13 +00:00
|
|
|
|
CC-PART will normally be a quoted name such as \\='cc-fix.
|
2015-11-24 19:44:34 +00:00
|
|
|
|
CONDITION should not be quoted."
|
|
|
|
|
(if (eval condition)
|
|
|
|
|
(progn
|
|
|
|
|
(cc-bytecomp-load (symbol-name (eval cc-part)))
|
|
|
|
|
`(require ,cc-part))
|
|
|
|
|
'(progn)))
|
|
|
|
|
|
|
|
|
|
(defmacro cc-conditional-require-after-load (cc-part file condition)
|
2015-11-30 05:50:59 +00:00
|
|
|
|
"If the CONDITION is satisfied at compile time, (i) force the
|
2015-11-24 19:44:34 +00:00
|
|
|
|
file CC-PART.el in the current directory to be loaded at compile
|
|
|
|
|
time, (ii) generate an `eval-after-load' form to load CC-PART.el
|
|
|
|
|
after the loading of FILE.
|
|
|
|
|
|
2019-11-11 18:30:13 +00:00
|
|
|
|
CC-PART will normally be a quoted name such as \\='cc-fix. FILE
|
2015-11-24 19:44:34 +00:00
|
|
|
|
should be a string. CONDITION should not be quoted."
|
|
|
|
|
(if (eval condition)
|
|
|
|
|
(progn
|
|
|
|
|
(cc-bytecomp-load (symbol-name (eval cc-part)))
|
|
|
|
|
`(eval-after-load ,file
|
|
|
|
|
'(require ,cc-part)))
|
|
|
|
|
'(progn)))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
(defmacro cc-provide (feature)
|
|
|
|
|
"A replacement for the `provide' form that restores the environment
|
|
|
|
|
after the compilation. Don't use within `eval-when-compile'."
|
|
|
|
|
`(progn
|
|
|
|
|
(eval-when-compile (cc-bytecomp-restore-environment))
|
|
|
|
|
(provide ,feature)))
|
|
|
|
|
|
|
|
|
|
(defmacro cc-load (cc-part)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
"Force loading of the corresponding .el file in the current directory
|
|
|
|
|
during compilation. Don't use outside `eval-when-compile' or
|
|
|
|
|
`eval-and-compile'.
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
Having cyclic cc-load's will result in infinite recursion. That's
|
|
|
|
|
somewhat intentional."
|
|
|
|
|
`(or (and (featurep 'cc-bytecomp)
|
|
|
|
|
(cc-bytecomp-load ,cc-part))
|
|
|
|
|
(load ,cc-part nil t nil)))
|
|
|
|
|
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(defmacro cc-require-when-compile (cc-part)
|
|
|
|
|
"Force loading of the corresponding .el file in the current directory
|
|
|
|
|
during compilation, but do a compile time `require' otherwise. Don't
|
|
|
|
|
use within `eval-when-compile'."
|
|
|
|
|
`(eval-when-compile
|
2013-05-30 23:20:05 +00:00
|
|
|
|
(if (and (fboundp 'cc-bytecomp-is-compiling)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(cc-bytecomp-is-compiling))
|
2015-01-13 15:39:36 +00:00
|
|
|
|
(if (not (featurep ,cc-part))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(cc-bytecomp-load (symbol-name ,cc-part)))
|
|
|
|
|
(require ,cc-part))))
|
|
|
|
|
|
|
|
|
|
(defmacro cc-external-require (feature)
|
|
|
|
|
"Do a `require' of an external package.
|
|
|
|
|
This restores and sets up the compilation environment before and
|
|
|
|
|
afterwards. Don't use within `eval-when-compile'."
|
|
|
|
|
`(progn
|
|
|
|
|
(eval-when-compile (cc-bytecomp-restore-environment))
|
|
|
|
|
(require ,feature)
|
|
|
|
|
(eval-when-compile (cc-bytecomp-setup-environment))))
|
|
|
|
|
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(defmacro cc-bytecomp-defvar (var)
|
|
|
|
|
"Binds the symbol as a variable during compilation of the file,
|
|
|
|
|
to silence the byte compiler. Don't use within `eval-when-compile'."
|
|
|
|
|
`(eval-when-compile
|
|
|
|
|
(if (boundp ',var)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-defvar: %s bound already as variable" ',var)
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(if (not (memq ',var cc-bytecomp-unbound-variables))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(progn
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-defvar: Saving %s (as unbound)" ',var)
|
|
|
|
|
(setq cc-bytecomp-unbound-variables
|
|
|
|
|
(cons ',var cc-bytecomp-unbound-variables))))
|
2015-01-13 15:39:36 +00:00
|
|
|
|
(if (cc-bytecomp-is-compiling)
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(progn
|
|
|
|
|
(defvar ,var)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(set ',var (intern (concat "cc-bytecomp-ignore-var:"
|
|
|
|
|
(symbol-name ',var))))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-defvar: Covered variable %s" ',var))))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
(defmacro cc-bytecomp-defun (fun)
|
|
|
|
|
"Bind the symbol as a function during compilation of the file,
|
2003-07-03 12:30:59 +00:00
|
|
|
|
to silence the byte compiler. Don't use within `eval-when-compile'.
|
|
|
|
|
|
|
|
|
|
If the symbol already is bound as a function, it will keep that
|
|
|
|
|
definition. That means that this macro will not shut up warnings
|
|
|
|
|
about incorrect number of arguments. It's dangerous to try to replace
|
|
|
|
|
existing functions since the byte compiler might need the definition
|
|
|
|
|
at compile time, e.g. for macros and inline functions."
|
2001-03-21 12:59:36 +00:00
|
|
|
|
`(eval-when-compile
|
2002-11-16 01:37:44 +00:00
|
|
|
|
(if (fboundp ',fun)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-defun: %s bound already as function" ',fun)
|
2002-11-16 01:37:44 +00:00
|
|
|
|
(if (not (assq ',fun cc-bytecomp-original-functions))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(progn
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-defun: Saving %s (as unbound)" ',fun)
|
|
|
|
|
(setq cc-bytecomp-original-functions
|
|
|
|
|
(cons (list ',fun nil 'unbound)
|
|
|
|
|
cc-bytecomp-original-functions))))
|
2015-01-13 15:39:36 +00:00
|
|
|
|
(if (cc-bytecomp-is-compiling)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(progn
|
|
|
|
|
(fset ',fun (intern (concat "cc-bytecomp-ignore-fun:"
|
|
|
|
|
(symbol-name ',fun))))
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-defun: Covered function %s" ',fun))))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
(defmacro cc-bytecomp-put (symbol propname value)
|
|
|
|
|
"Set a property on a symbol during compilation (and evaluation) of
|
|
|
|
|
the file. Don't use outside `eval-when-compile'."
|
2003-07-03 12:30:59 +00:00
|
|
|
|
`(eval-when-compile
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(if (not (assoc (cons ,symbol ,propname) cc-bytecomp-original-properties))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(progn
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-put: Saving property %s for %s with value %s"
|
|
|
|
|
,propname ,symbol (get ,symbol ,propname))
|
|
|
|
|
(setq cc-bytecomp-original-properties
|
|
|
|
|
(cons (cons (cons ,symbol ,propname)
|
|
|
|
|
(cons ,value (get ,symbol ,propname)))
|
|
|
|
|
cc-bytecomp-original-properties))))
|
|
|
|
|
(put ,symbol ,propname ,value)
|
|
|
|
|
(cc-bytecomp-debug-msg
|
|
|
|
|
"cc-bytecomp-put: Bound property %s for %s to %s"
|
|
|
|
|
,propname ,symbol ,value)))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(defmacro cc-bytecomp-boundp (symbol)
|
|
|
|
|
"Return non-nil if the given symbol is bound as a variable outside
|
|
|
|
|
the compilation. This is the same as using `boundp' but additionally
|
|
|
|
|
exclude any variables that have been bound during compilation with
|
|
|
|
|
`cc-bytecomp-defvar'."
|
|
|
|
|
(if (and (cc-bytecomp-is-compiling)
|
|
|
|
|
(memq (car (cdr symbol)) cc-bytecomp-unbound-variables))
|
|
|
|
|
nil
|
|
|
|
|
`(boundp ,symbol)))
|
|
|
|
|
|
|
|
|
|
(defmacro cc-bytecomp-fboundp (symbol)
|
|
|
|
|
"Return non-nil if the given symbol is bound as a function outside
|
|
|
|
|
the compilation. This is the same as using `fboundp' but additionally
|
|
|
|
|
exclude any functions that have been bound during compilation with
|
|
|
|
|
`cc-bytecomp-defun'."
|
|
|
|
|
(let (fun-elem)
|
|
|
|
|
(if (and (cc-bytecomp-is-compiling)
|
|
|
|
|
(setq fun-elem (assq (car (cdr symbol))
|
|
|
|
|
cc-bytecomp-original-functions))
|
|
|
|
|
(eq (elt fun-elem 2) 'unbound))
|
|
|
|
|
nil
|
|
|
|
|
`(fboundp ,symbol))))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'cc-bytecomp)
|
2001-07-16 07:46:48 +00:00
|
|
|
|
|
2015-08-22 03:46:21 +00:00
|
|
|
|
;; Local Variables:
|
|
|
|
|
;; indent-tabs-mode: t
|
|
|
|
|
;; tab-width: 8
|
|
|
|
|
;; End:
|
2001-07-16 07:46:48 +00:00
|
|
|
|
;;; cc-bytecomp.el ends here
|