All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/20] fix misspelling of current function in string
@ 2014-12-07 19:20 ` Julia Lawall
  0 siblings, 0 replies; 144+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
  To: linux-wireless
  Cc: kernel-janitors, linux, joe, devel, linux-scsi, dri-devel,
	intel-gfx, linux-mtd, linux-samsung-soc, linux-arm-kernel,
	linux-kernel, linux-pci, netdev, linux-usb

These patches replace what appears to be a reference to the name of the
current function but is misspelled in some way by either the name of the
function itself, or by %s and then __func__ in an argument list.

// <smpl>
// sudo apt-get install python-pip
// sudo pip install python-Levenshtein
// spatch requires the argument --in-place

virtual after_start

@initialize:ocaml@
@@

let extensible_functions = ref ([] : string list)
let restarted = ref false

let restart _ =
  restarted := true;
  let it = new iteration() in
  it#add_virtual_rule After_start;
  Printf.eprintf "restarting\n";
  it#register()

@initialize:python@
@@
import re
from Levenshtein import distance
mindist = 1 // 1 to find only misspellings
maxdist = 2
ignore_leading = True

// ---------------------------------------------------------------------

@r0@
constant char [] c;
identifier f;
@@

f(...,c,...)

@script:ocaml@
c << r0.c;
f << r0.f;
@@

(if not !restarted then restart());
match Str.split_delim (Str.regexp "%") c with
  _::_::_ ->
    if not (List.mem f !extensible_functions)
    then extensible_functions := f :: !extensible_functions
| _ -> ()

// ---------------------------------------------------------------------

@r depends on after_start@
constant char [] c;
position p;
identifier f;
@@

f(...,c@p,...)

@script:python flt@
c << r.c;
p << r.p;
matched;
@@

func = p[0].current_element
wpattern = "[a-zA-Z_][a-zA-Z0-9_]*"
if ignore_leading:
   func = func.strip("_")
   wpattern = "[a-zA-Z][a-zA-Z0-9_]*"
lf = len(func)
cocci.include_match(False)
// ignore extremely short function names
if lf > 3:
   words = [w for w in re.findall(wpattern, c) if abs(len(w) - lf) <= maxdist]
   for w in words:
       d = distance(w, func) 
       if mindist <= d and d <= maxdist:
          coccinelle.matched = w
          cocci.include_match(True)
     	  //print "%s:%d:%s():%d: %s" % (p[0].file, int(p[0].line), func, d, c)
	  break

@script:ocaml r2@
c << r.c;
f << r.f;
matched << flt.matched;
fixed;
@@

let pieces = Str.split_delim (Str.regexp_string matched) c in
match pieces with
  [before;after] ->
    let preceeding =
      List.length(Str.split (Str.regexp_string "%") before) > 1 in
    if preceeding
    then Coccilib.include_match false
    else
      if List.mem f !extensible_functions
      then fixed := before ^ "%s" ^ after
      else Coccilib.include_match false
| _ -> Coccilib.include_match false

@changed1@
constant char [] r.c;
identifier r2.fixed;
position r.p;
identifier r.f;
@@

f(...,
-c@p
+fixed,__func__
 ,...)

// -------------------------------------------------------------------

@s depends on after_start@
constant char [] c;
position p;
identifier f;
@@

f(...,c@p,...)

@script:python flt2@
c << s.c;
p << s.p;
matched;
@@

func = p[0].current_element
wpattern = "[a-zA-Z_][a-zA-Z0-9_]*"
if ignore_leading:
   func = func.strip("_")
   wpattern = "[a-zA-Z][a-zA-Z0-9_]*"
lf = len(func)
cocci.include_match(False)
// ignore extremely short function names
if lf > 3:
   words = [w for w in re.findall(wpattern, c) if abs(len(w) - lf) <= maxdist]
   for w in words:
       d = distance(w, func) 
       if mindist <= d and d <= maxdist:
          coccinelle.matched = w
          cocci.include_match(True)
     	  //print "%s:%d:%s():%d: %s" % (p[0].file, int(p[0].line), func, d, c)
	  break

@script:ocaml s2@
c << s.c;
f << s.f;
p << s.p;
matched << flt2.matched;
fixed;
@@

let ce = (List.hd p).current_element in
let pieces = Str.split_delim (Str.regexp_string matched) c in
match pieces with
  [before;after] ->
    let preceeding =
      List.length(Str.split (Str.regexp_string "%") before) > 1 in
    if preceeding
    then Coccilib.include_match false
    else
      if List.mem f !extensible_functions
      then Coccilib.include_match false
      else fixed := before ^ ce ^ after
| _ -> Coccilib.include_match false

@changed2@
constant char [] s.c;
identifier s2.fixed;
position s.p;
identifier s.f;
@@

f(...,
-c@p
+fixed
 ,...)
// </smpl>


^ permalink raw reply	[flat|nested] 144+ messages in thread

end of thread, other threads:[~2015-02-06 11:28 UTC | newest]

Thread overview: 144+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-07 19:20 [PATCH 0/20] fix misspelling of current function in string Julia Lawall
2014-12-07 19:20 ` Julia Lawall
2014-12-07 19:20 ` Julia Lawall
2014-12-07 19:20 ` Julia Lawall
2014-12-07 19:20 ` [PATCH 1/20] mtd: s3c2410: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 22:48   ` Richard Weinberger
2014-12-07 22:48     ` Richard Weinberger
2014-12-07 22:48     ` Richard Weinberger
2014-12-07 22:48     ` Richard Weinberger
2014-12-07 22:48     ` Richard Weinberger
2014-12-08  7:11     ` Julia Lawall
2014-12-08  7:11       ` Julia Lawall
2014-12-08  7:11       ` Julia Lawall
2014-12-08  7:11       ` Julia Lawall
2014-12-08  7:11       ` Julia Lawall
2014-12-08  9:16       ` Richard Weinberger
2014-12-08  9:16         ` Richard Weinberger
2014-12-08  9:16         ` Richard Weinberger
2014-12-08  9:16         ` Richard Weinberger
2014-12-08  9:16         ` Richard Weinberger
2015-02-06 11:28         ` Brian Norris
2015-02-06 11:28           ` Brian Norris
2015-02-06 11:28           ` Brian Norris
2015-02-06 11:28           ` Brian Norris
2015-02-06 11:28           ` Brian Norris
2014-12-07 19:20 ` [PATCH 2/20] PCI: keystone: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-08 15:14   ` Murali Karicheri
2014-12-08 15:14     ` Murali Karicheri
2014-12-08 15:14     ` Murali Karicheri
2015-01-09 18:31   ` Bjorn Helgaas
2015-01-09 18:31     ` Bjorn Helgaas
2015-01-09 18:31     ` Bjorn Helgaas
2014-12-07 19:20 ` [PATCH 3/20] PCI: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 20:41   ` Rasmus Villemoes
2014-12-07 20:41     ` Rasmus Villemoes
2014-12-07 20:43     ` Julia Lawall
2014-12-07 20:43       ` Julia Lawall
2014-12-07 19:20 ` [PATCH 4/20] dmfe: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 20:34   ` Grant Grundler
2014-12-07 20:34     ` Grant Grundler
2014-12-09 21:14   ` David Miller
2014-12-09 21:14     ` David Miller
2014-12-07 19:20 ` [PATCH 5/20] isdn: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-09 21:14   ` David Miller
2014-12-09 21:14     ` David Miller
2014-12-07 19:20 ` [PATCH 6/20] TTY: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-08  8:49   ` Jiri Slaby
2014-12-08  8:49     ` Jiri Slaby
2014-12-08  9:18     ` Joe Perches
2014-12-08  9:18       ` Joe Perches
2014-12-08  9:50       ` Jiri Slaby
2014-12-08  9:50         ` Jiri Slaby
2014-12-07 19:20 ` [PATCH 7/20] drm/i915: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-08 10:24   ` Jani Nikula
2014-12-08 10:24     ` Jani Nikula
2014-12-08 14:15     ` Daniel Vetter
2014-12-08 14:15       ` Daniel Vetter
2014-12-08 14:15       ` Daniel Vetter
2014-12-07 19:20 ` [PATCH 8/20] USB: isp1760: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 20:41   ` Jeremiah Mahler
2014-12-07 20:41     ` Jeremiah Mahler
2014-12-07 20:45     ` Julia Lawall
2014-12-07 20:45       ` Julia Lawall
2014-12-07 20:48       ` Jeremiah Mahler
2014-12-07 19:20 ` [PATCH 9/20] drivers/scsi: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20 ` [PATCH 10/20] uli526x: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 20:48   ` Grant Grundler
2014-12-07 20:48     ` Grant Grundler
2014-12-07 20:59     ` [PATCH 10/20 v2] " Julia Lawall
2014-12-07 20:59       ` Julia Lawall
2014-12-09 21:14   ` [PATCH 10/20] " David Miller
2014-12-09 21:14     ` David Miller
2014-12-07 19:20 ` [PATCH 11/20] vme: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20 ` [PATCH 12/20] hp100: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 20:44   ` Jeremiah Mahler
2014-12-07 20:44     ` Jeremiah Mahler
2014-12-09 21:13   ` David Miller
2014-12-09 21:13     ` David Miller
2014-12-09 21:14   ` David Miller
2014-12-09 21:14     ` David Miller
2014-12-07 19:20 ` [PATCH 13/20] zd1211rw: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20 ` [PATCH 14/20] chelsio: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-09 21:13   ` David Miller
2014-12-09 21:13     ` David Miller
2014-12-09 21:14   ` David Miller
2014-12-09 21:14     ` David Miller
2014-12-07 19:20 ` [PATCH 15/20] hostap_cs: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20 ` [PATCH 16/20] rtlwifi: rtl8821ae: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:20 ` [PATCH 17/20] drm/i2c: tda998x: " Julia Lawall
2014-12-07 19:20   ` Julia Lawall
2014-12-07 19:21 ` [PATCH 18/20] usb: gadget: " Julia Lawall
2014-12-07 19:21   ` Julia Lawall
2014-12-07 19:21 ` [PATCH 19/20] TTY: " Julia Lawall
2014-12-07 19:21   ` Julia Lawall
2014-12-07 20:54   ` Jeremiah Mahler
2014-12-07 20:54     ` Jeremiah Mahler
2014-12-07 21:05     ` Julia Lawall
2014-12-07 21:05       ` Julia Lawall
2014-12-07 19:21 ` [PATCH 20/20] drm/radeon: " Julia Lawall
2014-12-07 19:21   ` Julia Lawall
2014-12-08 15:44   ` Alex Deucher
2014-12-08 15:44     ` Alex Deucher
2014-12-08 15:44     ` Alex Deucher
2014-12-08 16:17     ` Julia Lawall
2014-12-08 16:17       ` Julia Lawall
2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
2014-12-07 23:44   ` Julian Calaby
2014-12-07 23:44   ` Julian Calaby
2014-12-07 23:44   ` Julian Calaby
2014-12-08  6:43   ` Julia Lawall
2014-12-08  6:43     ` Julia Lawall
2014-12-08  6:43     ` Julia Lawall
2014-12-08  6:43     ` Julia Lawall
2014-12-08  6:43     ` Julia Lawall
2014-12-10  2:56     ` Julian Calaby
2014-12-10  2:56       ` Julian Calaby
2014-12-10  2:56       ` Julian Calaby
2014-12-10  2:56       ` Julian Calaby
2014-12-10  2:56       ` Julian Calaby
2014-12-08  3:55 ` Joe Perches
2014-12-08  3:55   ` Joe Perches
2014-12-08  3:55   ` Joe Perches
2014-12-08  3:55   ` Joe Perches
2014-12-08  3:55   ` Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.