From d52b29861d4e9a031c78ae7c33212d7833921ebb Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 10 Apr 2018 20:01:45 +0200 Subject: [PATCH] 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. --- tmp-empty-fun.cocci | 56 +++++++++++++++++++++++++++++++++++++++++++++ tmp-empty-fun.el | 28 +++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tmp-empty-fun.cocci create mode 100644 tmp-empty-fun.el diff --git a/tmp-empty-fun.cocci b/tmp-empty-fun.cocci new file mode 100644 index 000000000..f65e15f3e --- /dev/null +++ b/tmp-empty-fun.cocci @@ -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]) diff --git a/tmp-empty-fun.el b/tmp-empty-fun.el new file mode 100644 index 000000000..36bf4c72f --- /dev/null +++ b/tmp-empty-fun.el @@ -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)))))