From 16f1e25b9c3ef1c73b198c67a41b38ca21df069b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 28 Aug 2014 16:37:13 -0400 Subject: [PATCH] * lisp/progmodes/cc-defs.el: Expose c-lanf-defconst's expressions to the byte-compiler. (lookup-syntax-properties): Silence byte-compiler. (c-lang-defconst): Quote the code with `lambda' rather than with `quote'. (c-lang-const): Avoid unneeded setq. (c-lang-constants-under-evaluation): Add docstring. (c-lang--novalue): New constant. (c-find-assignment-for-mode): Use it instead of c-lang-constants. (c-get-lang-constant): Same here. Get the mode's value using `funcall' now that the code is quoted with `lambda'. --- lisp/ChangeLog | 69 +++++++++++-------- lisp/progmodes/cc-defs.el | 166 ++++++++++++++++++++++++---------------------- 2 files changed, 128 insertions(+), 107 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c6a3f5d7282..e41633548c6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,18 @@ +2014-08-28 Stefan Monnier + + * progmodes/cc-defs.el: Expose c-lanf-defconst's expressions to the + byte-compiler. + (lookup-syntax-properties): Silence byte-compiler. + (c-lang-defconst): Quote the code with `lambda' rather than with + `quote'. + (c-lang-const): Avoid unneeded setq. + (c-lang-constants-under-evaluation): Add docstring. + (c-lang--novalue): New constant. + (c-find-assignment-for-mode): Use it instead of c-lang-constants. + (c-get-lang-constant): Same here. + Get the mode's value using `funcall' now that the code is quoted + with `lambda'. + 2014-08-28 Michael Albinus * net/tramp.el (tramp-handle-shell-command): Use `display-buffer'. @@ -67,8 +82,8 @@ * progmodes/cc-fonts.el (c-font-lock-declarations): Handle the "decltype" keyword. (c-font-lock-c++-new): Handle "decltype" constructions. - * progmodes/cc-langs.el (c-auto-ops, c-auto-ops-re): New - c-lang-defconsts/defvars. + * progmodes/cc-langs.el (c-auto-ops, c-auto-ops-re): + New c-lang-defconsts/defvars. (c-haskell-op, c-haskell-op-re): New c-lang-defconsts/defvars. (c-typeof-kwds, c-typeof-key): New c-lang-defconsts/defvars. (c-typeless-decl-kwds): Append "auto" onto the C++ value. @@ -79,8 +94,8 @@ off from c->-op-cont-re. (c->-op-cont-tokens): Change to use the above. (c->-op-without->-cont-regexp): New lang-const. - * progmodes/cc-engine.el (c-forward-<>-arglist-recur): Use - c->-op-without->-cont-regexp in place of c->-op-cont-tokens. + * progmodes/cc-engine.el (c-forward-<>-arglist-recur): + Use c->-op-without->-cont-regexp in place of c->-op-cont-tokens. 2014-08-23 Alan Mackenzie @@ -90,8 +105,8 @@ 2014-08-21 Eli Zaretskii - * textmodes/texnfo-upd.el (texinfo-specific-section-type): Don't - recognize a Top node if there are other sectioning commands + * textmodes/texnfo-upd.el (texinfo-specific-section-type): + Don't recognize a Top node if there are other sectioning commands earlier in the Texinfo file. This fixes a bug in texinfo-make-menu and avoids inflooping in texinfo-all-menus-update when they are invoked on texinfo.texi. @@ -193,7 +208,7 @@ 2014-08-12 Stefan Monnier - * mpc.el (mpc-reorder): Don't bother splitting the "active"s elements + * mpc.el (mpc-reorder): Don't bother splitting the "active" elements to the first part if they're the same as the selection. 2014-08-12 Lars Magne Ingebrigtsen @@ -337,8 +352,8 @@ 2014-08-07 Leo Liu - * help.el (temp-buffer-setup-hook,temp-buffer-show-hook): Revert - change on 2014-03-22. + * help.el (temp-buffer-setup-hook,temp-buffer-show-hook): + Revert change on 2014-03-22. 2014-08-06 Ulf Jasper @@ -371,8 +386,8 @@ * progmodes/python.el: Fix completions inside (i)pdb. (python-shell-completion-pdb-string-code): Make obsolete. - (python-shell-completion-get-completions): Use - python-shell-completion-string-code resending setup code + (python-shell-completion-get-completions): + Use python-shell-completion-string-code resending setup code continuously for (i)pdb. 2014-08-04 Paul Eggert @@ -399,8 +414,8 @@ 2014-08-02 Alan Mackenzie - Fix confusion in C++ file caused by comma in "= {1,2},". Bug - #17756. + Fix confusion in C++ file caused by comma in "= {1,2},". + Bug #17756. * progmodes/cc-engine.el (c-beginning-of-statement-1): In checking for a statement boundary marked by "}", check there's no "=" before the "{". @@ -429,8 +444,8 @@ 2014-07-30 Christophe Deleuze (tiny change) - * calendar/icalendar.el (icalendar--decode-isodatetime): Use - actual current-time-zone when converting to local time. (Bug#15408) + * calendar/icalendar.el (icalendar--decode-isodatetime): + Use actual current-time-zone when converting to local time. (Bug#15408) 2014-07-29 Martin Rudalics @@ -541,17 +556,17 @@ 2014-07-28 Fabián Ezequiel Gallina Grab all Python process output before inferior-python-mode hooks. - * progmodes/python.el (inferior-python-mode): Call - accept-process-output and sit-for to ensure all output for process + * progmodes/python.el (inferior-python-mode): + Call accept-process-output and sit-for to ensure all output for process has been received before running hooks. - (python-shell-internal-get-or-create-process): Cleanup - accept-process-output and sit-for calls. + (python-shell-internal-get-or-create-process): + Cleanup accept-process-output and sit-for calls. 2014-07-28 Fabián Ezequiel Gallina More robust shell startup and code setup. - * progmodes/python.el (python-shell-make-comint): Remove - accept-process-output call. + * progmodes/python.el (python-shell-make-comint): + Remove accept-process-output call. (python-shell-get-buffer): Return current buffer if major-mode is inferior-python-mode. (python-shell-get-or-create-process): Use it. @@ -560,8 +575,8 @@ 2014-07-27 Eli Zaretskii - * scroll-bar.el (scroll-bar-toolkit-horizontal-scroll): Add - rudimentary support for bidirectional text. + * scroll-bar.el (scroll-bar-toolkit-horizontal-scroll): + Add rudimentary support for bidirectional text. 2014-07-27 Martin Rudalics @@ -935,8 +950,8 @@ (linum-update-window): Use it to adjust margin to linum's width. * leim/quail/sisheng.el (sisheng-list): Don't bother with-case-table. - * eshell/em-smart.el (eshell-smart-scroll-window): Use - with-selected-window. + * eshell/em-smart.el (eshell-smart-scroll-window): + Use with-selected-window. * xt-mouse.el (xterm-mouse-translate-1): Intern drag event (bug#17894). Remove also pointless window&mark manipulation. @@ -3968,7 +3983,7 @@ 2014-03-23 Lars Ingebrigtsen * calendar/parse-time.el (parse-time-iso8601-regexp) - (parse-iso8601-time-string): Copied from `url-dav' so that we can use + (parse-iso8601-time-string): Copy from `url-dav' so that we can use it more generally. 2014-03-23 Lars Ingebrigtsen @@ -5570,7 +5585,7 @@ * help-at-pt.el (help-at-pt-string, help-at-pt-maybe-display): Also try to display local help from just before point. -2014-02-02 Alan Mackenzie +2014-02-02 Alan Mackenzie c-parse-state. Don't "append-lower-brace-pair" in certain circumstances. Also fix an obscure bug where "\\s!" shouldn't be diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index d6134a510b2..5d528caabb2 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el @@ -1556,6 +1556,8 @@ non-nil, a caret is prepended to invert the set." (cc-bytecomp-defvar open-paren-in-column-0-is-defun-start) +(defvar lookup-syntax-properties) ;XEmacs. + (defconst c-emacs-features (let (list) @@ -1801,18 +1803,18 @@ system." (error "Unknown base mode `%s'" base-mode)) (put mode 'c-fallback-mode base-mode)) -(defvar c-lang-constants (make-vector 151 0)) -;; This obarray is a cache to keep track of the language constants -;; defined by `c-lang-defconst' and the evaluated values returned by -;; `c-lang-const'. It's mostly used at compile time but it's not -;; stored in compiled files. -;; -;; The obarray contains all the language constants as symbols. The -;; value cells hold the evaluated values as alists where each car is -;; the mode name symbol and the corresponding cdr is the evaluated -;; value in that mode. The property lists hold the source definitions -;; and other miscellaneous data. The obarray might also contain -;; various other symbols, but those don't have any variable bindings. +(defvar c-lang-constants (make-vector 151 0) + "Obarray used as a cache to keep track of the language constants. +The constants stored are those defined by `c-lang-defconst' and the values +computed by `c-lang-const'. It's mostly used at compile time but it's not +stored in compiled files. + +The obarray contains all the language constants as symbols. The +value cells hold the evaluated values as alists where each car is +the mode name symbol and the corresponding cdr is the evaluated +value in that mode. The property lists hold the source definitions +and other miscellaneous data. The obarray might also contain +various other symbols, but those don't have any variable bindings.") (defvar c-lang-const-expansion nil) @@ -1897,7 +1899,7 @@ constant. A file is identified by its base name." pre-files) (or (symbolp name) - (error "Not a symbol: %s" name)) + (error "Not a symbol: %S" name)) (when (stringp (car-safe args)) ;; The docstring is hardly used anywhere since there's no normal @@ -1907,7 +1909,7 @@ constant. A file is identified by its base name." (setq args (cdr args))) (or args - (error "No assignments in `c-lang-defconst' for %s" name)) + (error "No assignments in `c-lang-defconst' for %S" name)) ;; Rework ARGS to an association list to make it easier to handle. ;; It's reversed at the same time to make it easier to implement @@ -1921,17 +1923,17 @@ constant. A file is identified by its base name." ((listp (car args)) (mapcar (lambda (lang) (or (symbolp lang) - (error "Not a list of symbols: %s" + (error "Not a list of symbols: %S" (car args))) (intern (concat (symbol-name lang) "-mode"))) (car args))) - (t (error "Not a symbol or a list of symbols: %s" + (t (error "Not a symbol or a list of symbols: %S" (car args))))) val) (or (cdr args) - (error "No value for %s" (car args))) + (error "No value for %S" (car args))) (setq args (cdr args) val (car args)) @@ -1945,7 +1947,7 @@ constant. A file is identified by its base name." ;; dependencies on the `c-lang-const's in VAL.) (setq val (macroexpand-all val)) - (setq bindings (cons (cons assigned-mode val) bindings) + (setq bindings `(cons (cons ',assigned-mode (lambda () ,val)) ,bindings) args (cdr args)))) ;; Compile in the other files that have provided source @@ -1957,7 +1959,7 @@ constant. A file is identified by its base name." (mapcar 'car (get sym 'source)))) `(eval-and-compile - (c-define-lang-constant ',name ',bindings + (c-define-lang-constant ',name ,bindings ,@(and pre-files `(',pre-files)))))) (put 'c-lang-defconst 'lisp-indent-function 1) @@ -2022,19 +2024,16 @@ language. NAME and LANG are not evaluated so they should not be quoted." (or (symbolp name) - (error "Not a symbol: %s" name)) + (error "Not a symbol: %S" name)) (or (symbolp lang) - (error "Not a symbol: %s" lang)) + (error "Not a symbol: %S" lang)) (let ((sym (intern (symbol-name name) c-lang-constants)) - mode source-files args) + (mode (when lang (intern (concat (symbol-name lang) "-mode"))))) - (when lang - (setq mode (intern (concat (symbol-name lang) "-mode"))) - (unless (get mode 'c-mode-prefix) - (error - "Unknown language %S since it got no `c-mode-prefix' property" - (symbol-name lang)))) + (or (get mode 'c-mode-prefix) (null mode) + (error "Unknown language %S: no `c-mode-prefix' property" + lang)) (if (eq c-lang-const-expansion 'immediate) ;; No need to find out the source file(s) when we evaluate @@ -2042,49 +2041,56 @@ quoted." ;; `source' property. `',(c-get-lang-constant name nil mode) - (let ((file (c-get-current-file))) - (if file (setq file (intern file))) - ;; Get the source file(s) that must be loaded to get the value - ;; of the constant. If the symbol isn't defined yet we assume - ;; that its definition will come later in this file, and thus - ;; are no file dependencies needed. - (setq source-files (nreverse - ;; Reverse to get the right load order. - (apply 'nconc - (mapcar (lambda (elem) - (if (eq file (car elem)) - nil ; Exclude our own file. - (list (car elem)))) - (get sym 'source)))))) - - ;; Make some effort to do a compact call to - ;; `c-get-lang-constant' since it will be compiled in. - (setq args (and mode `(',mode))) - (if (or source-files args) - (setq args (cons (and source-files `',source-files) - args))) - - (if (or (eq c-lang-const-expansion 'call) - (and (not c-lang-const-expansion) - (not mode)) - load-in-progress - (not (boundp 'byte-compile-dest-file)) - (not (stringp byte-compile-dest-file))) - ;; Either a straight call is requested in the context, or - ;; we're in an "uncontrolled" context and got no language, - ;; or we're not being byte compiled so the compile time - ;; stuff below is unnecessary. - `(c-get-lang-constant ',name ,@args) - - ;; Being compiled. If the loading and compiling version is - ;; the same we use a value that is evaluated at compile time, - ;; otherwise it's evaluated at runtime. - `(if (eq c-version-sym ',c-version-sym) - (cc-eval-when-compile - (c-get-lang-constant ',name ,@args)) - (c-get-lang-constant ',name ,@args)))))) - -(defvar c-lang-constants-under-evaluation nil) + (let ((source-files + (let ((file (c-get-current-file))) + (if file (setq file (intern file))) + ;; Get the source file(s) that must be loaded to get the value + ;; of the constant. If the symbol isn't defined yet we assume + ;; that its definition will come later in this file, and thus + ;; are no file dependencies needed. + (nreverse + ;; Reverse to get the right load order. + (apply 'nconc + (mapcar (lambda (elem) + (if (eq file (car elem)) + nil ; Exclude our own file. + (list (car elem)))) + (get sym 'source)))))) + ;; Make some effort to do a compact call to + ;; `c-get-lang-constant' since it will be compiled in. + (args (and mode `(',mode)))) + + (if (or source-files args) + (push (and source-files `',source-files) args)) + + (if (or (eq c-lang-const-expansion 'call) + (and (not c-lang-const-expansion) + (not mode)) + load-in-progress + (not (boundp 'byte-compile-dest-file)) + (not (stringp byte-compile-dest-file))) + ;; Either a straight call is requested in the context, or + ;; we're in an "uncontrolled" context and got no language, + ;; or we're not being byte compiled so the compile time + ;; stuff below is unnecessary. + `(c-get-lang-constant ',name ,@args) + + ;; Being compiled. If the loading and compiling version is + ;; the same we use a value that is evaluated at compile time, + ;; otherwise it's evaluated at runtime. + `(if (eq c-version-sym ',c-version-sym) + (cc-eval-when-compile + (c-get-lang-constant ',name ,@args)) + (c-get-lang-constant ',name ,@args))))))) + +(defvar c-lang-constants-under-evaluation nil + "Alist of constants in the process of being evaluated. +The `cdr' of each entry indicates how far we've looked in the list +of definitions, so that the def for var FOO in c-mode can be defined in +terms of the def for that same var FOO (which will then rely on the +fallback definition for all modes, to break the cycle).") + +(defconst c-lang--novalue "novalue") (defun c-get-lang-constant (name &optional source-files mode) ;; Used by `c-lang-const'. @@ -2150,7 +2156,7 @@ quoted." ;; mode might have an explicit entry before that. (eq (setq value (c-find-assignment-for-mode (cdr source-pos) mode nil name)) - c-lang-constants) + c-lang--novalue) ;; Try again with the fallback mode from the ;; original position. Note that ;; `c-buffer-is-cc-mode' still is the real mode if @@ -2158,22 +2164,22 @@ quoted." (eq (setq value (c-find-assignment-for-mode (setcdr source-pos backup-source-pos) fallback t name)) - c-lang-constants))) + c-lang--novalue))) ;; A simple lookup with no fallback mode. (eq (setq value (c-find-assignment-for-mode (cdr source-pos) mode t name)) - c-lang-constants)) + c-lang--novalue)) (error - "`%s' got no (prior) value in %s (might be a cyclic reference)" + "`%s' got no (prior) value in %S (might be a cyclic reference)" name mode)) (condition-case err - (setq value (eval value)) + (setq value (funcall value)) (error ;; Print a message to aid in locating the error. We don't ;; print the error itself since that will be done later by ;; some caller higher up. - (message "Eval error in the `c-lang-defconst' for `%s' in %s:" + (message "Eval error in the `c-lang-defconst' for `%S' in %s:" sym mode) (makunbound sym) (signal (car err) (cdr err)))) @@ -2181,13 +2187,13 @@ quoted." (set sym (cons (cons mode value) (symbol-value sym))) value)))) -(defun c-find-assignment-for-mode (source-pos mode match-any-lang name) +(defun c-find-assignment-for-mode (source-pos mode match-any-lang _name) ;; Find the first assignment entry that applies to MODE at or after ;; SOURCE-POS. If MATCH-ANY-LANG is non-nil, entries with `t' as ;; the language list are considered to match, otherwise they don't. ;; On return SOURCE-POS is updated to point to the next assignment ;; after the returned one. If no assignment is found, - ;; `c-lang-constants' is returned as a magic value. + ;; `c-lang--novalue' is returned as a magic value. ;; ;; SOURCE-POS is a vector that points out a specific assignment in ;; the double alist that's used in the `source' property. The first @@ -2243,7 +2249,7 @@ quoted." match-any-lang) (throw 'found (cdr assignment)))) - c-lang-constants))) + c-lang--novalue))) (defun c-lang-major-mode-is (mode) ;; `c-major-mode-is' expands to a call to this function inside -- 2.11.4.GIT