emacs/lisp/cedet/semantic/db-ref.el
Stefan Monnier 371fdd4f1b * lisp/cedet: Convert remaining files to lexical-binding
Remove a few more redundant `:group` args.
Make use of lexical scoping to replace `(lambda...) with proper closures.

* lisp/cedet/ede/custom.el (ede-project-sort-targets-list):
Use `dotimes` and replace `(lambda..) with closures.

* lisp/cedet/ede/proj-comp.el (proj-comp-insert-variable-once):
* lisp/cedet/ede/pmake.el (ede-pmake-insert-variable-once):
Remove unused var `addcr`.

* lisp/cedet/semantic/complete.el: Use lexical-binding.
(semantic-displayer-show-request): Remove unused var `typing-count`.
Use `equal` instead of `stringp+string=`.

* lisp/cedet/semantic/db-ebrowse.el: Use lexical-binding.
(semanticdb-create-ebrowse-database): Remove unused vars `mma` and `regexp`.
(semanticdb-ebrowse-strip-trees): Remove unused var `class` and `filename`.
(semanticdb-ebrowse-add-globals-to-table): Remove unused var `fname`.

* lisp/cedet/semantic/db-find.el: Use lexical-binding.
(semanticdb-find-adebug-insert-scanned-tag-cons): Remove always-nil var
`tip`.

* lisp/cedet/semantic/db-global.el: Use lexical-binding.
(semanticdb-enable-gnu-global-databases): Access local var
`semantic--ih` by sticking its value in the code passed to `eval`
rather than by dynamic scoping.

* lisp/cedet/semantic/db-typecache.el: Use lexical-binding.
(semanticdb-db-typecache-dump): Remove unused var `junk`.

* lisp/cedet/semantic/debug.el: Use lexical-binding.

* lisp/cedet/semantic/dep.el: Use lexical-binding.
(semantic-add-system-include): Avoid `add-to-list` on a local variable.
Access local var `value` by sticking its value in the code passed to
`eval` rather than by dynamic scoping.
(semantic-remove-system-include): Don't use `delete` on a list received
from elsewhere.
Access local var `value` by sticking its value in the code passed to
`eval` rather than by dynamic scoping.
(semantic-reset-system-include): Simplify a bit.

* lisp/cedet/semantic/ede-grammar.el: Use lexical-binding.
(project-compile-target): Remove unused vars `csrc` and `cb`.
Use `cl-incf`.  Remove apparently unneeded `with-no-warnings`.

* lisp/cedet/semantic/edit.el: Use lexical-binding.
(semantic-edits-change-over-tags): Remove unused var `inner-start`.
(semantic-edits-incremental-parser-1): Silence warnings about
intentionally unused var `last-cond`.

* lisp/cedet/semantic/fw.el: Use lexical-binding.
(recentf-exclude, semantic-init-hook, ede-auto-add-method)
(flymake-start-syntax-check-on-find-file, auto-insert): Declare vars.

* lisp/cedet/semantic/ia-sb.el: Use lexical-binding.
(semantic-ia-sb-key-map): Move initialization into declaration.
(semantic-ia-sb-more-buttons): Remove unused var `idx`.
(semantic-ia-sb-line-path): Simplify `if` -> `or`.

* lisp/cedet/semantic/idle.el (semantic-idle-breadcrumbs--tag-function):
Make it a function returning a closure.

* lisp/cedet/semantic/senator.el: Use lexical-binding.
(senator-search-set-tag-class-filter): Replace `(lambda..) with a closure.

* lisp/cedet/semantic/sort.el: Use lexical-binding.
(semanticdb-search-system-databases): Declare var.
(semantic-tag-external-member-children-default): Replace `(lambda..)
with a closure.

* lisp/cedet/semantic/tag-ls.el: Use lexical-binding.
(semantic-tag-protection-default, semantic-tag-abstract-p-default):
Simplify with `member`.

* lisp/cedet/semantic/util.el: Use lexical-binding.
(semantic-something-to-tag-table): Declare function
`semanticdb-abstract-table--eieio-childp` called via `cl-typep`.

* lisp/cedet/semantic/bovine/scm.el (semantic-default-scheme-setup):
Remove duplicate setting of `imenu-create-index-function`.

* lisp/cedet/semantic/decorate/mode.el (semantic-decoration-build-style-menu):
Replace `(lambda..) with a closure.

* lisp/cedet/srecode/cpp.el (srecode-semantic-apply-tag-to-dict):
Remove always-t variable `member`.

* lisp/cedet/srecode/mode.el (srecode-minor-mode-templates-menu):
Replace `(lambda..) with a closure.  Use `push`.

* lisp/cedet/semantic/chart.el: Use lexical-binding.
* lisp/cedet/semantic/db-debug.el: Use lexical-binding.
* lisp/cedet/semantic/db-el.el: Use lexical-binding.
* lisp/cedet/semantic/db-file.el: Use lexical-binding.
* lisp/cedet/semantic/db-javascript.el: Use lexical-binding.
* lisp/cedet/semantic/db-mode.el: Use lexical-binding.
* lisp/cedet/semantic/db-ref.el: Use lexical-binding.
* lisp/cedet/semantic/decorate.el: Use lexical-binding.
* lisp/cedet/semantic/doc.el: Use lexical-binding.
* lisp/cedet/semantic/find.el: Use lexical-binding.
* lisp/cedet/semantic/format.el: Use lexical-binding.
* lisp/cedet/semantic/html.el: Use lexical-binding.
* lisp/cedet/semantic/ia.el: Use lexical-binding.
* lisp/cedet/semantic/imenu.el: Use lexical-binding.
* lisp/cedet/semantic/java.el: Use lexical-binding.
* lisp/cedet/semantic/mru-bookmark.el: Use lexical-binding.
* lisp/cedet/semantic/symref.el: Use lexical-binding.
* lisp/cedet/semantic/tag-file.el: Use lexical-binding.
* lisp/cedet/semantic/tag-write.el: Use lexical-binding.
* lisp/cedet/semantic/texi.el: Use lexical-binding.
* lisp/cedet/semantic/util-modes.el: Use lexical-binding.
2021-03-15 00:08:34 -04:00

174 lines
5.7 KiB
EmacsLisp

;;; semantic/db-ref.el --- Handle cross-db file references -*- lexical-binding: t; -*-
;; Copyright (C) 2007-2021 Free Software Foundation, Inc.
;; Author: Eric M. Ludlam <zappo@gnu.org>
;; This file is part of GNU Emacs.
;; 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 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
;; 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
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Handle cross-database file references.
;;
;; Any given database may be referred to by some other database. For
;; example, if a .cpp file has a #include in a header, then that
;; header file should have a reference to the .cpp file that included
;; it.
;;
;; This is critical for purposes where a file (such as a .cpp file)
;; needs to have its caches flushed because of changes in the
;; header. Changing a header may cause a referring file to be
;; reparsed due to account for changes in defined macros, or perhaps
;; a change to files the header includes.
;;; Code:
(require 'eieio)
(require 'cl-generic)
(require 'semantic)
(require 'semantic/db)
(require 'semantic/tag)
;; For the semantic-find-tags-by-name-regexp macro.
(eval-when-compile (require 'semantic/find))
(cl-defmethod semanticdb-add-reference ((dbt semanticdb-abstract-table)
include-tag)
"Add a reference for the database table DBT based on INCLUDE-TAG.
DBT is the database table that owns the INCLUDE-TAG. The reference
will be added to the database that INCLUDE-TAG refers to."
;; NOTE: I should add a check to make sure include-tag is in DB.
;; but I'm too lazy.
(let* ((semanticdb-find-default-throttle
(if (featurep 'semantic/db-find)
(remq 'unloaded semanticdb-find-default-throttle)
nil))
(refdbt (semanticdb-find-table-for-include include-tag dbt))
;;(fullfile (semanticdb-full-filename dbt))
)
(when refdbt
;; Add our filename (full path)
;; (object-add-to-list refdbt 'file-refs fullfile)
;; Add our database.
(object-add-to-list refdbt 'db-refs dbt)
t)))
(cl-defmethod semanticdb-check-references ((_dbt semanticdb-abstract-table))
"Check and cleanup references in the database DBT.
Abstract tables would be difficult to reference."
;; Not sure how an abstract table can have references.
nil)
(cl-defmethod semanticdb-includes-in-table ((dbt semanticdb-abstract-table))
"Return a list of direct includes in table DBT."
(semantic-find-tags-by-class 'include (semanticdb-get-tags dbt)))
(cl-defmethod semanticdb-check-references ((dbt semanticdb-table))
"Check and cleanup references in the database DBT.
Any reference to a file that cannot be found, or whose file no longer
refers to DBT will be removed."
(let ((refs (oref dbt db-refs))
(myexpr (concat "\\<" (oref dbt file)))
)
(while refs
(let* ((ok t)
(db (car refs))
(f (when (cl-typep db 'semanticdb-table)
(semanticdb-full-filename db)))
)
;; The file was deleted
(when (and f (not (file-exists-p f)))
(setq ok nil))
;; The reference no longer includes the textual reference?
(let* ((refs (semanticdb-includes-in-table db))
(inc (semantic-find-tags-by-name-regexp
myexpr refs)))
(when (not inc)
(setq ok nil)))
;; Remove not-ok databases from the list.
(when (not ok)
(object-remove-from-list dbt 'db-refs db)
))
(setq refs (cdr refs)))))
(cl-defmethod semanticdb-refresh-references ((_dbt semanticdb-abstract-table))
"Refresh references to DBT in other files."
;; alternate tables can't be edited, so can't be changed.
nil
)
(cl-defmethod semanticdb-refresh-references ((dbt semanticdb-table))
"Refresh references to DBT in other files."
(let ((refs (semanticdb-includes-in-table dbt))
)
(while refs
(if (semanticdb-add-reference dbt (car refs))
nil
;; If we succeeded, then do... nothing?
nil
)
(setq refs (cdr refs)))
))
(cl-defmethod semanticdb-notify-references ((dbt semanticdb-table)
method)
"Notify all references of the table DBT using method.
METHOD takes two arguments.
(METHOD TABLE-TO-NOTIFY DBT)
TABLE-TO-NOTIFY is a semanticdb-table which is being notified.
DBT, the second argument is DBT."
(mapc (lambda (R) (funcall method R dbt))
(oref dbt db-refs)))
;;; DEBUG
;;
(defclass semanticdb-ref-adebug ()
((i-depend-on :initarg :i-depend-on)
(local-table :initarg :local-table)
(i-include :initarg :i-include))
"Simple class to allow ADEBUG to show a nice list.")
(declare-function data-debug-new-buffer "data-debug")
(declare-function data-debug-insert-object-slots "eieio-datadebug")
(defun semanticdb-ref-test (refresh)
"Dump out the list of references for the current buffer.
If REFRESH is non-nil, cause the current table to have its references
refreshed before dumping the result."
(interactive "p")
(require 'eieio-datadebug)
;; If we need to refresh... then do so.
(when refresh
(semanticdb-refresh-references semanticdb-current-table))
;; Do the debug system
(let* ((tab semanticdb-current-table)
(myrefs (oref tab db-refs))
(myinc (semanticdb-includes-in-table tab))
(adbc (semanticdb-ref-adebug :i-depend-on myrefs
:local-table tab
:i-include myinc)))
(data-debug-new-buffer "*References ADEBUG*")
(data-debug-insert-object-slots adbc "!"))
)
(provide 'semantic/db-ref)
;;; semantic/db-ref.el ends here