Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support for Coccinelle-like semantic patches mixing matching (TemplateMatcher) and transformation (Template) together #1918

Open
monperrus opened this issue Mar 16, 2018 · 7 comments
Labels
feature mastersthesis Potential topic for a bachelor/master's thesis at KTH roadmap

Comments

@monperrus
Copy link
Collaborator

monperrus commented Mar 16, 2018

Imagine that you want to match a code location and transform it at the same time, this is sometimes called a "semantic patch" (as opposed to a line-based patch).

In the C world, there is an excellent tool for this, called Coccinelle, see http://coccinelle.lip6.fr/.

In Spoon, it would mean creating an abstraction that would gather a TemplateMatcher and Template in a same object. In other terms, we are really close to have "semantic patches" in Spoon.

@pvojtechovsky since you're extensively working on this part, what do you think?

@monperrus monperrus changed the title question: mixing matching and template in question: mixing matching and template together Mar 16, 2018
@pvojtechovsky
Copy link
Collaborator

I am not sure if I understood you well. But have a look at
https://github.com/pvojtechovsky/spoon/blob/5919ed784e5fde86e4b9246c0ea24c989f269a45/src/test/java/spoon/test/template/CodeReplaceTest.java testTemplateReplace

There are two patterns, first is matching (founds a code location and takes current parameters) and second generates new code (using own template and current parameters) and then old code is replaced by new code.

@pvojtechovsky
Copy link
Collaborator

Have a look at https://github.com/pvojtechovsky/spoon/blob/5919ed784e5fde86e4b9246c0ea24c989f269a45/src/main/java/spoon/pattern/node/RootNode.java too
It is the core interface of Pattern node, which shows that Pattern can always do both matching and generating:

public interface RootNode extends Matchers {
/**
	 * Generates zero, one or more target depending on kind of this {@link RootNode}, expected `result` and input `parameters`
	 * @param generator {@link Generator} which drives generation process
	 * @param result holder for the generated objects
	 * @param parameters a {@link ParameterValueProvider} holding parameters
	 */
	<T> void generateTargets(Generator generator, ResultHolder<T> result, ParameterValueProvider parameters);
/**
	 * @param targets to be matched target nodes and input parameters
	 * @param nextMatchers Chain of matchers which has to be processed after this {@link RootNode}
	 * @return new parameters and container with remaining targets
	 */
	TobeMatched matchTargets(TobeMatched targets, Matchers nextMatchers);

@monperrus monperrus changed the title question: mixing matching and template together question: mixing matching and template together for having semantic patches Mar 16, 2018
@monperrus monperrus changed the title question: mixing matching and template together for having semantic patches feature: add support for semantic patches mixing matching (TemplateMatcher) and transformation (Template) together Mar 21, 2018
@monperrus
Copy link
Collaborator Author

Patterns (#1686) are almost this. The final step is to given then a Coccinelle look'n'feel.

@monperrus monperrus changed the title feature: add support for semantic patches mixing matching (TemplateMatcher) and transformation (Template) together feature: add support for Coccinelle-like semantic patches mixing matching (TemplateMatcher) and transformation (Template) together Sep 29, 2018
@monperrus
Copy link
Collaborator Author

Documentation about SmPL: http://coccinelle.lip6.fr/documentation.php

@monperrus
Copy link
Collaborator Author

See also
Automating Program Transformation for Java Using Semantic Patches
https://hal.inria.fr/hal-02023368v1

@monperrus
Copy link
Collaborator Author

FYI new version of @JuliaLawall's paper: Semantic Patches for Java Program Transformation

@monperrus monperrus added the mastersthesis Potential topic for a bachelor/master's thesis at KTH label Dec 20, 2019
@monperrus
Copy link
Collaborator Author

FYI, a paper on that topic "Semantic Patches for Adaptation of JavaScript Programs to Evolving Libraries." https://cs.au.dk/~amoeller/papers/jsfix/paper.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature mastersthesis Potential topic for a bachelor/master's thesis at KTH roadmap
Projects
None yet
Development

No branches or pull requests

2 participants