From aad7a8fd3b27ecfef06f4b760cbad096404aed56 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 11 Feb 2018 14:08:22 +0100 Subject: [PATCH] GENmodel, GENinstance, change layout, #3/4, klag-5.cocci for coccinelle --- klag-5.cocci | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ klag-5.el | 58 +++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 klag-5.cocci create mode 100644 klag-5.el diff --git a/klag-5.cocci b/klag-5.cocci new file mode 100644 index 000000000..e0f1880dc --- /dev/null +++ b/klag-5.cocci @@ -0,0 +1,109 @@ +// GENmodule and GENinstance for each device specific instance and module struct +// +// (compile "git grep -l -e 'modPtr\\|nextModel' -- '*.h' | xargs -P8 -n1 spatch --defined XSPICE --sp-file klag-5.cocci --in-place && emacs -q --no-site-file --batch --load klag-5.el && git commit -am 'GENmodel, GENinstance, change layout, #3/4, coccinelle semantic patch'") + +// (compile "spatch --sp-file klag-5.cocci src/spicelib/devices/bsim3v32/bsim3v32def.h") +// (compile "spatch --sp-file klag-5.cocci src/spicelib/devices/cap/capdefs.h") +// (compile "spatch --sp-file klag-5.cocci src/spicelib/devices/asrc/asrcdefs.h") +// (compile "spatch --sp-file klag-5.cocci src/include/ngspice/numgen.h") +// (compile "spatch --sp-file klag-5.cocci src/include/ngspice/mifdefs.h") +// (compile "spatch --sp-file klag-5.cocci src/spicelib/devices/soi3/soi3defs.h") + + +@struc1@ +identifier Xstruct !~ "GENinstance$"; +identifier XmodPtr =~ "modPtr$"; +identifier XnextInstance =~ "nextInstance$"; +identifier Xname =~ "name$"; +identifier Xstates =~ "states?$"; +type T1, T2; +typedef IFuid; +type xx; +@@ +( +typedef struct Xstruct { +- T1 XmodPtr; +- T2 XnextInstance; +- IFuid Xname; +- int Xstates; ++ ++ struct GENinstance gen; ++ /* emacs-place-here */ ++ + ... +} xx ; ++/* emacs-from-here */ ++#define XmodPtr(inst) ((T1)((inst)->gen.GENmodPtr)) ++#define XnextInstance(inst) ((T2)((inst)->gen.GENnextInstance)) ++#define Xname gen.GENname ++#define Xstates gen.GENstate ++/* emacs-upto-here */ +| +struct Xstruct { +- T1 XmodPtr; +- T2 XnextInstance; +- IFuid Xname; +- int Xstates; ++ ++ struct GENinstance gen; ++ /* emacs-place-here */ ++ + ... +}; ++/* emacs-from-here */ ++#define XmodPtr(inst) ((T1)((inst)->gen.GENmodPtr)) ++#define XnextInstance(inst) ((T2)((inst)->gen.GENnextInstance)) ++#define Xname gen.GENname ++#define Xstates gen.GENstate ++/* emacs-upto-here */ +) + + + +@struc2@ +identifier Xstruct !~ "GENmodel$"; +identifier XmodType =~ "modType$"; +identifier XnextModel =~ "nextModel$"; +identifier Xinstances =~ "instances$"; +identifier XmodName =~ "modName$"; +type T1, T2; +typedef IFuid; +type xx; +@@ +( +typedef struct Xstruct { +- int XmodType; +- T1 XnextModel; +- T2 Xinstances; +- IFuid XmodName; ++ ++ struct GENmodel gen; ++ /* emacs-place-here */ ++ + ... +} xx ; ++/* emacs-from-here */ ++#define XmodType gen.GENmodType ++#define XnextModel(inst) ((T1)((inst)->gen.GENnextModel)) ++#define Xinstances(inst) ((T2)((inst)->gen.GENinstances)) ++#define XmodName gen.GENmodName ++/* emacs-upto-here */ +| +struct Xstruct { +- int XmodType; +- T1 XnextModel; +- T2 Xinstances; +- IFuid XmodName; ++ ++ struct GENmodel gen; ++ /* emacs-place-here */ ++ + ... +}; ++/* emacs-from-here */ ++#define XmodType gen.GENmodType ++#define XnextModel(inst) ((T1)((inst)->gen.GENnextModel)) ++#define Xinstances(inst) ((T2)((inst)->gen.GENinstances)) ++#define XmodName gen.GENmodName ++/* emacs-upto-here */ +) diff --git a/klag-5.el b/klag-5.el new file mode 100644 index 000000000..170efb7f1 --- /dev/null +++ b/klag-5.el @@ -0,0 +1,58 @@ +;;; (load (buffer-file-name)) + +(require 'cl-lib) + +(defun mx-klag-5 () + (goto-char (point-min)) + (while (re-search-forward (rx bol (*? space) + "/* emacs-place-here */" + ;; inclusive comments + (* (* (or space + (: "/*" (*? (or (not (any "/*")) + (: "*" (not (any "/"))) + (: "/" (not (any "/*"))))) + "*/"))) + "\n")) + nil t) + (let ((p (match-beginning 0))) + (replace-match "\n") + (save-excursion + (save-match-data + (when (re-search-forward (rx bol (*? space) + "/* emacs-from-here */" + (group (+? anything)) + "/* emacs-upto-here */" + (*? space) "\n") + nil t) + (let ((s (match-string 1))) + (replace-match "") + (goto-char p) + (insert s)))))))) + + +(defun mx-klag-5+ () + "mop up some whitespace from cocci" + (goto-char (point-min)) + (while (re-search-forward (rx bol (* (*? space) "\n") + (group + (*? space) + (or "struct GENinstance gen" + "struct GENmodel gen"))) + nil t) + (replace-match "\n\\1"))) + + +(loop + with files = (process-lines "git" "grep" "-l" + "-e" "emacs-place-here" + "--" "*.[ch]") + for file in files + do + (progn + (with-temp-file file + (insert-file-contents file) + (c-mode) + (setq c-file-style "BSD") + (setq c-basic-offset 4) + (mx-klag-5) + (mx-klag-5+))))