spicelib/devices/*, tmp-empty-fun.cocci script

Remove empty XXXmDelete(), XXXdestroy(), XXXdelete() functions.

This cocci script has low confidence,
  thus the actual patch needs to be browsed for accidental surplus deletions.
This commit is contained in:
rlar 2018-04-10 20:01:45 +02:00
parent e725d728fc
commit d52b29861d
2 changed files with 84 additions and 0 deletions

56
tmp-empty-fun.cocci Normal file
View File

@ -0,0 +1,56 @@
// (compile "for i in $(git ls-files -- 'src/spicelib/devices/*/*.c' | xargs -n 1 dirname | uniq); do spatch --in-place --sp-file tmp-empty-fun.cocci $i/*.[ch]; done")
// (compile "git commit -am 'spicelib/devices/*, drop empty destroy functions'")
// (compile "spatch --sp-file tmp-empty-fun.cocci src/spicelib/devices/mos1/*.[ch]")
// (compile "spatch --sp-file tmp-empty-fun.cocci src/spicelib/devices/ind/*.[ch]")
// fixme, beware of the xml files !!!
@thefun@
type T1;
identifier fun =~ "(destroy|mDelete|delete)$";
position pfun;
identifier arg;
symbol OK;
@@
T1 fun@pfun(...)
{
? NG_IGNORE(arg);
? return OK;
}
@null_init@
identifier devinit;
identifier thefun.fun;
identifier member;
@@
SPICEdev devinit = {
...,
- .member = fun,
+ .member = NULL,
...
};
@remove_proto@
type thefun.T1;
identifier thefun.fun;
@@
- T1 fun(...);
@initialize:python@
@@
import os
import subprocess
files = []
@script:python collect@
p << thefun.pfun;
@@
files.append(p[0].file)
@finalize:python@
@@
for f in files:
print f
os.remove(f)
subprocess.call(["emacs", "-q", "--no-site-lisp", "--script", "tmp-empty-fun.el", f])

28
tmp-empty-fun.el Normal file
View File

@ -0,0 +1,28 @@
;;; (compile "emacs -q --no-site-lisp --script tmp-empty-fun.el src/spicelib/devices/mos1/mos1dest.c")
(defun drop(file base)
(with-temp-file file
(insert-file-contents-literally file)
(while (re-search-forward (concat (rx bol (* any) bow)
(regexp-quote base)
(rx eow (* any) "\n"))
nil t)
(replace-match ""))))
(defun moan(file)
(unless (string-match "ChangeLog" file)
(message "remnant found in %s" file)))
(let* ((file (car argv))
(dir (file-name-directory file))
(base (file-name-nondirectory file)))
(message "processing %s" file)
(mapcar (lambda (process-file)
(drop process-file base))
(ignore-errors
(process-lines "git" "grep" "-l" base
"--" dir "*.vcxproj")))
(mapcar #'moan
(ignore-errors
(process-lines "git" "grep" "-l" (file-name-base file)))))