Re: Coccinelle: semantic patch for missing of_node_put
> We currently use the following Ocaml script to automatically > collect functions that need to be considered. > > @initialize:ocaml@ > @@ > > let relevant_str = "use of_node_put() on it when done" I suggest to reconsider this search pattern. The mentioned words are distributed over text lines in the discussed software documentation. Thus I imagine that an other documentation format would be safer and more helpful for the determination of a corresponding API system property. Regards, Markus
Re: [Cocci] Coccinelle: semantic patch for missing of_node_put
> > 2, A general method. > > We also try to get the list of functions to consider by writing a SmPL, > > but this method is not feasible at present, because it is not easy to parse > > the comment > > header information of these functions. > > The situation was improved once more also for the Coccinelle software. > How do you think about to develop any more variants based on information > from a script (like the following) for the semantic patch language? > > @initialize:python@ > @@ > import re, sys > filter = re.compile(" when done") > > @find@ > comments c; > identifier x; > type t; > @@ > t@c x(...) > { ... } > > @script:python selection@ > input << find.c; > @@ > if filter.search(input[0].before, 2): > sys.stderr.write(input[0].before + "\n=\n") > else: > cocci.include_match(False) > > @display@ > identifier find.x; > type find.t; > @@ > *t x(...) > { ... } > > > Does such a source code analysis approach indicate any details > which should be improved for the affected software documentation? Thank you for your example. We currently use the following Ocaml script to automatically collect functions that need to be considered. @initialize:ocaml@ @@ let relevant_str = "use of_node_put() on it when done" let contains s1 s2 = let re = Str.regexp_string s2 in try ignore (Str.search_forward re s1 0); true with Not_found -> false let relevant_functions = ref [] let add_function f c = if not (List.mem f !relevant_functions) then begin let s = String.concat " " ( (List.map String.lowercase_ascii (List.filter (function x -> Str.string_match (Str.regexp "[a-zA-Z_\\(\\)][-a-zA-Z0-9_\\(\\)]*$") x 0) (Str.split (Str.regexp "[ .;\t\n]+") c in Printf.printf "comments: %s\n" s; if contains s relevant_str then Printf.printf "Found relevant function: %s\n" f; relevant_functions := f :: !relevant_functions; end @r@ identifier fn; comments c; type T = struct device_node *; @@ T@c fn(...) { ... } @script:ocaml@ f << r.fn; c << r.c; @@ let (cb,cm,ca) = List.hd c in let c = String.concat " " cb in add_function f c -- Regards, Wen___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: Coccinelle: semantic patch for missing of_node_put
> 2, A general method. > We also try to get the list of functions to consider by writing a SmPL, > but this method is not feasible at present, because it is not easy to parse > the comment > header information of these functions. The situation was improved once more also for the Coccinelle software. How do you think about to develop any more variants based on information from a script (like the following) for the semantic patch language? @initialize:python@ @@ import re, sys filter = re.compile(" when done") @find@ comments c; identifier x; type t; @@ t@c x(...) { ... } @script:python selection@ input << find.c; @@ if filter.search(input[0].before, 2): sys.stderr.write(input[0].before + "\n=\n") else: cocci.include_match(False) @display@ identifier find.x; type find.t; @@ *t x(...) { ... } Does such a source code analysis approach indicate any details which should be improved for the affected software documentation? Regards, Markus
Re: [Cocci] Setting the match result by SmPL script rule
>> How do you think about to filter any text by regular expressions >> for semantic patch language constraints? > > Not supported. This software limitation and current development status has got consequences as usual. * It would be nice if comment contents could be directly restricted also by the means of SmPL constraints. I am unsure about the chances for extensions in this area. * The supported languages “OCaml” and “Python” offer known programming interfaces for the work with regular expressions. The evaluation of these regexes can trigger useful data processing. But I am looking for ways now to set the match result for SmPL script rules. How are the chances to extend Coccinelle's software library for this purpose? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Indentation when adding an if
On Mon, 3 Jun 2019, Christoph Böhmwalder wrote: > Hi, > > Consider the following C code and cocci patch: > > #include > > int x; > > int main(int argc, char **argv) > { > if (y) > do_something(x); > } > > > @@ > identifier x; > @@ > - do_something(x); > + if (x) > + do_one_thing(); > + else > + do_another_thing(); > > > For this input, spatch produces the following output: > > > $ spatch --sp-file test.cocci test.c > init_defs_builtins: /usr/lib/coccinelle/standard.h > HANDLING: test.c > diff = > --- test.c > +++ /tmp/cocci-output-18011-a28e99-test.c > @@ -5,5 +5,8 @@ int x; > int main(int argc, char **argv) > { > if (y) > -do_something(x); > +if (x) > +do_one_thing(); > +else > +do_another_thing(); > } > > > Obviously it gets the indentation wrong there. Is this a bug? > > Adding curly braces around the outer if (in the C code) yields the correct > indentation, while adding the braces around the inner if (in the cocci patch) > does not. > > Adding an else branch to the outer if also produces the wrong indentation. This is surely a bug. Thank you for the report. julia___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Indentation when adding an if
Hi, Consider the following C code and cocci patch: #include int x; int main(int argc, char **argv) { if (y) do_something(x); } @@ identifier x; @@ - do_something(x); + if (x) + do_one_thing(); + else + do_another_thing(); For this input, spatch produces the following output: $ spatch --sp-file test.cocci test.c init_defs_builtins: /usr/lib/coccinelle/standard.h HANDLING: test.c diff = --- test.c +++ /tmp/cocci-output-18011-a28e99-test.c @@ -5,5 +5,8 @@ int x; int main(int argc, char **argv) { if (y) -do_something(x); +if (x) +do_one_thing(); +else +do_another_thing(); } Obviously it gets the indentation wrong there. Is this a bug? Adding curly braces around the outer if (in the C code) yields the correct indentation, while adding the braces around the inner if (in the cocci patch) does not. Adding an else branch to the outer if also produces the wrong indentation. -- Regards, Christoph ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci