On Mon, Feb 7, 2011 at 15:12, SF Markus Elfring
<[email protected]> wrote:
>
> Would it make sense to peek into strings and source code comments by the
> semantic patch language?

Not in my book. For it to be a useful feature, you need a use case where

* There is a good semantic-patch to normal-patch ratio. It is nice to
write 10 lines of semantic patch code and then get it expanded to 300
lines of patch code you don't have to write and you (more importantly)
don't have to find the transformation places in the code. If all your
changes are pin-point changes or can easier be done with
flyspell-prog-mode in emacs (or a like feature), it is probably better
to leave the change up to other tools.

* The cost/benefit analysis is on your side. It should be worthwhile
to add and should result in a large set of new semantic patches to
apply. If the numbers are not on your side, why add it?

* It can't be implemented easily by some other tool.

* It should be demonstrably *hard* to do with scripting. If it is easy
to script, then there is less need to add it to cocci.

* And finally, the case should fit into the puzzle inside the
machinery of Coccinelle. If what you are building is perpendicular and
can use almost none of the existing pieces inside Coccinelle there is
little warrant for adding it.

Coccinelle is powerful because it is more than a regular-expression
engine. The reason it works so well is because it operates on
programming languages which can be formally specified and thus as a
consequence analysed by machine. A string literal or a comment is
usually natural language and thus your best hope is to approach the
problem differently, perhaps with machine learning. Machines in
general have a much harder time than humans at coping with structures
that have no formal specification. In any case, the scope is outside
of that of Cocci.

In conclusion: String literals and comment-transformations does not
really fulfill these points that well.

> Would it be convenient and safer to avoid calls into SmPL's scripting
> interfaces?

I don't think so. Using Coccinelle requires some thought on safety of
your transformations, as you can quickly do very wrong things to
programs with it. On the other hand, your transformation is
*consistent* over all files which is usually better than a
time-consuming transformation by hand. The scripting feature is a
valve: if you can't do what you want in SmPL alone, you can harness
the power of a full, turing complete, programming language to do so.
Or in some cases, you can take the inverted viewpoint: Use SmPL to
constrain your general script to only look at points that are
interesting.

In other words: The safety concern is always there. As for the
convenience, scripting is not meant to be convenient. It is meant to
empower SmPL transformations by associating the execution of arbitrary
code with a rule match. Or in the dual view: As a tool which can find
the interesting points to apply your script on.

-- 
J.
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to