cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: Coccinelle <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] Reporting variations of condition checks according to function calls
Date: Sat, 11 Apr 2020 19:25:43 +0200	[thread overview]
Message-ID: <fcbca1d9-7375-b488-54b2-a3934b90c6ed@web.de> (raw)
In-Reply-To: <alpine.DEB.2.21.2004111600560.2369@hadrien>

> If you want something done, please do it yourself.

I hope that another clarification can be achieved also for the software
behaviour of the following source code analysis approach.


@initialize:python@
@@
import sqlalchemy, sys
sys.stderr.write("\n".join(["Using SQLAlchemy version:",
                            sqlalchemy.__version__]))
sys.stderr.write("\n")
from sqlalchemy import create_engine, Column, Integer, String
engine = create_engine("sqlite:///:memory:", echo = False)

from sqlalchemy.ext.declarative import declarative_base
base = declarative_base()

class pair(base):
   __tablename__ = "pairs"
   function = Column(String, primary_key = True)
   source_file = Column(String, primary_key = True)
   line = Column(Integer, primary_key = True)
   column = Column(Integer, primary_key = True)
   action = Column(String)
   check = Column(String)

from sqlalchemy.orm import sessionmaker
configured_session = sessionmaker(bind = engine)
session = configured_session()
base.metadata.create_all(engine)

def store_positions(places, check_in, action_in):
    """Add source code positions to an internal table."""
    for place in places:
       entry = pair(function = place.current_element,
                    source_file = place.file,
                    line = place.line,
                    column = int(place.column) + 1,
                    action = action_in,
                    check = check_in
                   )
       session.add(entry)

@find1@
expression action, e;
position p;
statement is, es;
@@
 e = action(...);
 if@p (<+... e ...+>)
    is
 else
    es

@check1@
expression check;
position find1.p;
statement find1.is, find1.es;
@@
 if@p (check)
    is
 else
    es

@script:python collection1@
c << check1.check;
action << find1.action;
places << find1.p;
@@
store_positions(places, c, action)

@finalize:python@
@@
session.commit()
from sqlalchemy import func
entries = session.query(func.count("*")).select_from(pair).scalar()

if entries > 0:
   delimiter = "|"
   sys.stdout.write(delimiter.join(['action',
                                    'check',
                                    '"source file"',
                                    "line",
                                    "column"
                                    ]))
   sys.stdout.write("\r\n")

   for action, \
       check, \
       file, \
       line, \
       column in session.query(pair.action,
                               pair.check,
                               pair.source_file,
                               pair.line,
                               pair.column
                              ).order_by(pair.action,
                                         pair.check,
                                         pair.source_file,
                                         pair.line,
                                         pair.column
                                        ):
      sys.stdout.write(delimiter.join([action,
                                       check,
                                       file,
                                       str(line),
                                       str(column)
                                      ]))
      sys.stdout.write("\r\n")
else:
   sys.stderr.write("No result for this analysis!\n")


elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci list_condition_checks_after_function_calls2.cocci
…
warning: iso drop_else does not match the code below on line 55
if@p (check) iselse es
…
elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/list_condition_checks_after_function_calls2.cocci drivers/gpu/drm/mcde/mcde_drv.c
…
Using SQLAlchemy version:
1.3.10
HANDLING: drivers/gpu/drm/mcde/mcde_drv.c
No result for this analysis!


Will any software development possibilities become interesting here?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  parent reply	other threads:[~2020-04-11 17:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10 15:07 [Cocci] Searching for functions with negative return values as error indication Markus Elfring
2020-04-10 15:12 ` Julia Lawall
2020-04-10 16:01   ` Markus Elfring
2020-04-11 13:43   ` [Cocci] Reporting variations of condition checks according to function calls Markus Elfring
2020-04-11 14:01     ` Julia Lawall
2020-04-11 14:06       ` Markus Elfring
2020-04-11 17:25       ` Markus Elfring [this message]
     [not found]         ` <alpine.DEB.2.21.2004112036270.2369@hadrien>
2020-04-11 18:50           ` Markus Elfring
2020-04-12  8:06           ` [Cocci] More support for SmPL data processing with databases? Markus Elfring
2020-04-12  8:51             ` Julia Lawall
2020-04-12  9:01               ` Markus Elfring
     [not found]                 ` <alpine.DEB.2.21.2004121115210.2419@hadrien>
2020-04-12  9:27                   ` [Cocci] Checking the application of the SmPL isomorphism “drop_else” Markus Elfring
2020-05-03  9:08                     ` Markus Elfring
2020-04-12 16:52               ` [Cocci] More support for SmPL data processing with databases? Markus Elfring
     [not found]                 ` <alpine.DEB.2.21.2004121904290.2419@hadrien>
2020-04-12 17:14                   ` Markus Elfring
2020-04-13  7:10                 ` Markus Elfring
     [not found]                   ` <alpine.DEB.2.21.2004130957540.3035@hadrien>
2020-04-13  8:23                     ` Markus Elfring
     [not found]                       ` <alpine.DEB.2.21.2004131029330.3035@hadrien>
2020-04-13  8:47                         ` Markus Elfring
     [not found]                           ` <alpine.DEB.2.21.2004131056350.3035@hadrien>
2020-04-13  9:03                             ` Markus Elfring
     [not found]                       ` <alpine.DEB.2.21.2004131031130.3035@hadrien>
2020-04-13  8:58                         ` Markus Elfring
2020-04-13 12:48                     ` Markus Elfring
2020-04-13 13:57                       ` Julia Lawall
2020-04-13 14:23                         ` Markus Elfring
     [not found]                           ` <alpine.DEB.2.21.2004131627470.3035@hadrien>
2020-04-13 14:50                             ` Markus Elfring
2020-04-13 14:59                               ` Julia Lawall
2020-04-13 15:19                                 ` Markus Elfring
2020-04-13 16:00                                   ` Julia Lawall
2020-04-13 16:08                                     ` Markus Elfring
2020-04-13 16:10                                       ` Julia Lawall
2020-04-13 16:14                                         ` Markus Elfring
2020-04-12 13:01           ` [Cocci] Reporting variations of condition checks according to function calls Markus Elfring
2020-04-12 13:27             ` Julia Lawall
2020-04-12 13:54               ` Markus Elfring
     [not found]                 ` <alpine.DEB.2.21.2004121624180.2419@hadrien>
2020-04-12 14:35                   ` Markus Elfring
2020-04-12 14:41                     ` Julia Lawall
2020-04-12 14:48                       ` Markus Elfring

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=fcbca1d9-7375-b488-54b2-a3934b90c6ed@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@systeme.lip6.fr \
    --cc=julia.lawall@inria.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).