From: Julia Lawall <julia.lawall@inria.fr>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: Coccinelle <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] Excluding quotes from strings of #define directives
Date: Sun, 4 Apr 2021 13:58:25 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.22.394.2104041357060.2958@hadrien> (raw)
In-Reply-To: <fa66fce2-e60e-1907-7c8b-fd9ceedb8086@web.de>
[-- Attachment #1: Type: text/plain, Size: 3484 bytes --]
On Sun, 4 Apr 2021, Markus Elfring wrote:
> > The following looks like what one might want to do to find #defines that
> > are near each other.
>
> I have tried another SmPL script variant out.
>
>
> @initialize:python@
> @@
> import sys
>
> records = {}
>
> class integrity_error:
> pass
>
> def store_positions(places, name, text):
> """Add source code positions to an internal table."""
> for place in places:
> key = place.file, place.line, int(place.column) + 1
>
> if key in records:
> sys.stderr.write("\n".join(["-> duplicate data",
> "file:", key[0],
> "function:", place.current_element,
> "line:", str(place.line)]))
> sys.stderr.write("\n")
> raise integrity_error
> else:
> records[key] = name, text, place.current_element
>
> @find@
> identifier i =~ "^(?:[A-Z]+_){3,3}[A-Z]+";
> expression e !~ "\"";
> position p;
> @@
> #define i@p e
>
> @script:python collection@
> i << find.i;
> e << find.e;
> places << find.p;
> @@
> store_positions(places, i, e)
>
> @finalize:python@
> @@
> if len(records) > 0:
> delimiter = "|"
> sys.stdout.write(delimiter.join(['name',
> 'text',
> 'function',
> '"source file"',
> 'line',
> 'column'
> ]))
> sys.stdout.write("\r\n")
>
> for key, value in records.items():
> sys.stdout.write(delimiter.join([value[0],
> value[1],
> value[2],
> key[0],
> key[1],
> str(key[2])
> ]))
> sys.stdout.write("\r\n")
> else:
> sys.stderr.write("No result for this analysis!\n")
>
>
> I wonder about the following test result then.
>
> elfring@Sonne:~/Projekte/PipeWire/lokal> spatch ~/Projekte/Coccinelle/janitor/check_define_usage.cocci spa/include/spa/node/type-info.h
> …
> name|text|function|"source file"|line|column
> SPA_TYPE_INFO_NodeCommand|SPA_TYPE_INFO_COMMAND_BASE "Node"|something_else|spa/include/spa/node/type-info.h|70|1
> SPA_TYPE_INFO_IO_BASE|SPA_TYPE_INFO_IO ":"|something_else|spa/include/spa/node/type-info.h|39|1
> SPA_TYPE_INFO_NODE_EVENT_BASE|SPA_TYPE_INFO_NodeEvent ":"|something_else|spa/include/spa/node/type-info.h|56|1
> SPA_TYPE_INFO_NodeEvent|SPA_TYPE_INFO_EVENT_BASE "Node"|something_else|spa/include/spa/node/type-info.h|55|1
> SPA_TYPE_INFO_IO|SPA_TYPE_INFO_ENUM_BASE "IO"|something_else|spa/include/spa/node/type-info.h|38|1
> SPA_TYPE_INFO_NODE_COMMAND_BASE|SPA_TYPE_INFO_NodeCommand ":"|something_else|spa/include/spa/node/type-info.h|71|1
>
>
> I hoped that the specified constraint for the metavariable “e” would mean
> that expressions which contain a double quotation character should be excluded
> for my source code analysis approach.
> Would you like to check the observed software functionality once more?
There is perhaps a problem, but it is surely not necessary to have all of
this python code around it to see the problem. Please make a minimal
example. A rule with a match and a * in front of it should be
sufficient.
julia
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2021-04-04 11:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-28 7:19 [Cocci] Replacing #define directives with the help of SmPL Markus Elfring
2021-03-28 9:29 ` Julia Lawall
[not found] ` <1b5f6d22-5b89-097f-37bd-13b3b2ab011a@web.de>
2021-03-28 10:47 ` Julia Lawall
[not found] ` <173fa182-4127-aaba-262e-e3953a81a1e2@web.de>
2021-03-28 11:46 ` Julia Lawall
[not found] ` <b80fe77f-0a11-2000-522e-836c9368eaa6@web.de>
2021-03-28 12:48 ` Julia Lawall
[not found] ` <b761969f-181b-5951-0730-11c340e236ab@web.de>
2021-03-28 14:08 ` Julia Lawall
[not found] ` <f720b262-708f-a603-3470-b374db625578@web.de>
2021-03-28 14:45 ` Julia Lawall
[not found] ` <fa66fce2-e60e-1907-7c8b-fd9ceedb8086@web.de>
2021-04-04 11:58 ` Julia Lawall [this message]
2021-04-04 12:11 ` [Cocci] Excluding quotes from strings of #define directives Markus Elfring
2021-04-04 12:19 ` Julia Lawall
[not found] ` <b9f6aceb-7e68-303d-bd1e-d41a7992b58b@web.de>
2021-04-05 7:09 ` [Cocci] Checking support for compound expressions (according to #define directives) Julia Lawall
[not found] ` <8561006e-7dc6-0f62-ecf0-c93146976925@web.de>
2021-04-05 7:54 ` Julia Lawall
2021-04-05 8:46 ` Markus Elfring
2021-04-05 8:53 ` Julia Lawall
2021-04-05 10:37 ` [Cocci] Improve the handling of string literals with SmPL Markus Elfring
[not found] ` <eaa316bd-4c73-fcbb-bfad-20426348b1c2@web.de>
2021-03-28 15:17 ` [Cocci] Replacing #define directives with the help of SmPL Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.22.394.2104041357060.2958@hadrien \
--to=julia.lawall@inria.fr \
--cc=Markus.Elfring@web.de \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).