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

feat(spoon-smpl): initial support for the semantic patch language (Credits: Mikael Forsberg) #3282

Merged
merged 344 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
344 commits
Select commit Hold shift + click to select a range
f9fae66
additions to SmPLJavaDSL and DebugUtils
mkforsb Apr 20, 2020
3b4c797
implement more elements in Substitutor
mkforsb Apr 20, 2020
5945677
introduce AnchoredOperations
mkforsb Apr 20, 2020
1444fe0
introduce OperationFilter, soon to replace current prioritization scheme
mkforsb Apr 20, 2020
7c471f4
implement more cases in PatternBuilder
mkforsb Apr 20, 2020
bc8eebd
rename SmPLCFGAdapter to SmPLMethodCFG and only keep constructor taki…
mkforsb Apr 20, 2020
62df4e1
switch to new separating parsing and anchoring
mkforsb Apr 20, 2020
055a92f
have Transformer keep track of which nodes have been operated on and …
mkforsb Apr 20, 2020
2b328d4
add another batch of e2e tests
mkforsb Apr 20, 2020
6c91836
remove deletion anchors after additions have been anchored
mkforsb Apr 20, 2020
29dc14f
Substitutor: fix concurrent mod. for Invocation, implement TypeAccess
mkforsb Apr 21, 2020
6eeda4f
fix and test Environment.join potentially mutating inputs
mkforsb Apr 21, 2020
0491604
fix using wrong environment for merging in ResultSet.negate
mkforsb Apr 21, 2020
c5b0c8f
improve variable names in ResultSet.negate
mkforsb Apr 21, 2020
c374913
PatternBuilder: implement TypeAccess
mkforsb Apr 21, 2020
a363794
introduce VariableUseScanner and test
mkforsb Apr 21, 2020
4e31ead
use VariableUseScanner in CodeElementLabel and FormulaCompiler
mkforsb Apr 21, 2020
70812d5
add 'compile' action to CLI app
mkforsb Apr 21, 2020
0c446e4
escape strings from input in e2e test generator
mkforsb Apr 21, 2020
f0cd2a6
add an e2e test using a familiar example patch
mkforsb Apr 21, 2020
3dd1102
fix expressionless return pattern matching any return statement
mkforsb Apr 21, 2020
4071575
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Apr 22, 2020
4589a2d
introduce CombinationsGenerator and test
mkforsb Apr 22, 2020
884b097
fix logic errors in ModelChecker
mkforsb Apr 22, 2020
de04ac4
rename AnchoredOperations to AnchoredOperationsMap and add doc comments
mkforsb Apr 23, 2020
a75e268
deduplication refactoring in SmPLJavaDSL
mkforsb Apr 23, 2020
5a64ec0
implement 'when exists' constraint relaxation for dots
mkforsb Apr 23, 2020
6aab6ce
fix doc comment in Not formula
mkforsb Apr 23, 2020
b364d96
replace more hardcoded naming in SmPLParser with calls to SmPLJavaDSL
mkforsb Apr 23, 2020
0f0373f
basic implementation of shortest-path and 'when any' constraints for …
mkforsb Apr 23, 2020
331a4e8
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb May 5, 2020
3f25749
add e2e test validation script and fix all invalid (non-compilable) t…
mkforsb May 5, 2020
2ca7cef
add smplgui.py debugging tool
mkforsb May 5, 2020
a997c4c
toString() for pattern nodes
mkforsb May 5, 2020
0b66863
add DebugUtils::prettifyFormula
mkforsb May 5, 2020
82afa12
doc comment fixes for formula elements
mkforsb May 5, 2020
5108bc6
rename and refactor StatementPattern and BranchPattern formula elements
mkforsb May 5, 2020
015a66a
refactor VariableUsePredicate
mkforsb May 5, 2020
6f39dc9
add hashCode() and equals() to formula elements that were missing them
mkforsb May 5, 2020
4ad209c
introduce SequentialOr formula element
mkforsb May 5, 2020
002c091
use prettifyFormula in CLI app
mkforsb May 5, 2020
19e182c
have IdentifierConstraint reject CtFieldAccess
mkforsb May 5, 2020
bc7b439
implement CtConstructorCall in PatternBuilder
mkforsb May 5, 2020
95236b2
implement explicitly typed SmPL metavariables
mkforsb May 5, 2020
dd7c981
move to Spoon 8.2.0
mkforsb May 5, 2020
8a4010e
add a couple of null checks in ValueNode::toString
mkforsb May 5, 2020
a9ecd6f
fixes to invocations and field reads in PatternBuilder and Substitutor
mkforsb May 5, 2020
40d095c
introduce FormulaOptimizer and remove FormulaCompiler::optimizeFormula
mkforsb May 5, 2020
9fc11f2
introduce FormulaOptimizerTest
mkforsb May 5, 2020
bced30c
add final pieces for SmPL pattern disjunction
mkforsb May 5, 2020
342ea94
add an e2e test on field reads
mkforsb May 5, 2020
a1c9da4
add TODO in SmPLParser
mkforsb May 5, 2020
ec5affd
add comments on nullifyThisAccess in SmPLParser
mkforsb May 5, 2020
0da42f6
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb May 12, 2020
749247b
add datetime printout when executing command in smplgui.py
mkforsb May 17, 2020
20b2836
add test for disappearing FieldRead target bug
mkforsb May 17, 2020
2d2da7e
add DebugUtils::prettifyModel
mkforsb May 17, 2020
7269924
allow 'type' metavariables to bind the accessed type of a CtTypeAccess
mkforsb May 17, 2020
b4ff814
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb May 18, 2020
4e14764
minor doc comment fix
mkforsb May 18, 2020
0437a90
get rid of hardcoded 'SmPLGeneralIdentifier' and introduce a name for…
mkforsb May 18, 2020
a48d867
rename isDots to isStatementLevelDots in SmPLJavaDSL
mkforsb May 18, 2020
979422c
get rid of hardcoded 'SmPLUndeclared' strings in SmPLParser, change n…
mkforsb May 18, 2020
cf09e9c
implement matching and binding on method header, add tests
mkforsb May 18, 2020
7fa36fa
add e2e test for the 'sticky_broadcasts' c4j patch
mkforsb May 18, 2020
794bd2c
get rid of implicit dots that were generated by FormulaCompiler regar…
mkforsb May 18, 2020
b24385b
add 'gentest' mode to smplgui.py
mkforsb May 19, 2020
79c559c
add explicit matching of end-of-method-body and add implicit dots in …
mkforsb May 19, 2020
517472a
allow anchoring additions to the method body and detect unanchorable …
mkforsb May 19, 2020
e62f386
fix names of new e2e tests
mkforsb May 19, 2020
5e502fa
have SmPLParser separate pattern disjunctions before rewrite() rather…
mkforsb May 19, 2020
8f60434
rename getDotsElementName to getDotsStatementElementName in SmPLJavaDSL
mkforsb May 21, 2020
a55d467
implement dots for arguments in method calls
mkforsb May 21, 2020
a40990a
add nicer clearing of output before a new run in smplgui.py
mkforsb May 21, 2020
3d042fa
fix incorrect alternative generation in Environment.negate
mkforsb May 21, 2020
599d2d8
fix and test addition anchoring bug
mkforsb May 22, 2020
55b63dd
remove unused imports
mkforsb May 22, 2020
dfcd59e
explicitly limit constrained metavariable bindings to be CtElements
mkforsb May 22, 2020
6413e4f
revert ability for labels to return multiple results, introduce Envir…
mkforsb May 22, 2020
58ea8fe
add some documentation and a test for Environment.MultipleAlternative…
mkforsb May 22, 2020
1152076
add groundwork for handling unsupported elements and implement (un)su…
mkforsb May 22, 2020
69b0097
remove irrelevant leftover commented code
mkforsb May 22, 2020
f6dd746
restore unsupported elements after patching in CLI app
mkforsb May 22, 2020
f08627a
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb May 24, 2020
a093b36
minor reorganization in FormulaCompiler
mkforsb May 24, 2020
a6d9c1d
implement dots variant with optional match
mkforsb May 24, 2020
8a40c7a
add a TODO in FormulaCompiler
mkforsb May 24, 2020
d6dfce1
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb May 26, 2020
268c4df
change formula generation for branches from AX(Or(a,b)) to And(EX(a),…
mkforsb May 26, 2020
ada9db8
change the singular cutoffNode to a list cutoffNodes in FormulaCompiler
mkforsb May 26, 2020
ba19509
improve some naming and comments in SmPLParser
mkforsb May 27, 2020
b3b1daa
use separate contexts for statement dots params and optional dots in …
mkforsb May 27, 2020
4022e28
new approach for pattern disjunctions
mkforsb May 27, 2020
5ecf122
remove MainFeaturesTest since the notion is better served by EndToEnd…
mkforsb May 27, 2020
3503694
introduce Optional formula element and use it for dots-with-optional-…
mkforsb May 27, 2020
10f237d
new approach to assembling the shortest-path guards for dots
mkforsb May 27, 2020
0957390
introduce Metadata(Predicate|Label) and NodeTag.metadata, use to fix …
mkforsb May 27, 2020
68e9d94
doc comment additions and fixes
mkforsb May 27, 2020
da21eac
doc comment fix
mkforsb May 27, 2020
9c11a42
fix typo
mkforsb May 31, 2020
8f98bb7
remove try-catch around optdots formula compilation
mkforsb May 31, 2020
547b5b1
fix bug with SmPLParser.rewrite producing an extra closing brace
mkforsb May 31, 2020
6b116aa
fix FormulaCompiler generating a parent id guard for dots in method b…
mkforsb Jun 1, 2020
d2a9afc
add shortest path guards to dots-with-optional-match
mkforsb Jun 1, 2020
7380ae6
remove unused method
mkforsb Jun 1, 2020
dd15547
minor indent / comment / typo fixes in SmPLParser
mkforsb Jun 1, 2020
8bd83c9
implement patches adding methods to parent class of matching method
mkforsb Jun 1, 2020
c4ca613
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 2, 2020
816ab1e
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 10, 2020
0e389ba
reduce duplicated code generated by gen-e2e-testsuite
mkforsb Jun 10, 2020
c03ac30
implement CtArrayTypeReference in pattern builder
mkforsb Jun 10, 2020
2a4bb33
disable matching declaring type of executable references
mkforsb Jun 10, 2020
b6af924
ensure inputs compile in all e2e tests, remove test based on C4J patc…
mkforsb Jun 10, 2020
167bdbd
add formula optimization (And(T, phi) | And(phi, T)) -> phi
mkforsb Jun 11, 2020
8feef53
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 11, 2020
c7ea06f
implement basic support for exception flow nodes and fix bug with dot…
mkforsb Jun 11, 2020
721637c
add support for ternary expressions
mkforsb Jun 11, 2020
a9176c2
treat switch statement as unsupported in SmPLMethodCFG
mkforsb Jun 11, 2020
480e2e6
reintroduce test based on C4J sticky_broadcast patch, using a new app…
mkforsb Jun 11, 2020
5695e15
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 17, 2020
0e07023
introduce ZippedCodeBaseTestContext by extracting reusable parts from…
mkforsb Jun 17, 2020
f6721a6
fix typo in e2e test
mkforsb Jun 17, 2020
0eb46e0
new logic of dots traversing unsupported elements, support 'when exis…
mkforsb Jun 17, 2020
82bef26
introduce SmPLLexer for new lexer-parser approach to SmPLParser
mkforsb Jun 17, 2020
e5fd22f
remove duplicate e2e test
mkforsb Jun 17, 2020
4b0de54
implement sub-element/expression matching and transformation
mkforsb Jun 17, 2020
a177cd4
add test based on C4J patch 'get_color'
mkforsb Jun 17, 2020
05a82af
bump pom source level to 11
mkforsb Jun 17, 2020
2b76c28
bump pom versions of spoon-control-flow and junit
mkforsb Jun 17, 2020
7092401
fix inconsistent indentation
mkforsb Jun 17, 2020
82be144
remove redundant import generated in gen-e2e-testsuite.py
mkforsb Jun 18, 2020
4d4677c
simplify an e2e test
mkforsb Jun 18, 2020
5a25479
use less hacky fix for parsing expressions of the form 'foo.x' with z…
mkforsb Jun 18, 2020
a146cac
add test based on C4J patch 'should_vibrate'
mkforsb Jun 18, 2020
2b2edbe
allow PatternBuilder to generate parameter nodes for executable names…
mkforsb Jun 18, 2020
cbf4254
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 18, 2020
4274cbc
move all operation prep and anchoring responsibility into SmPLParser
mkforsb Jun 18, 2020
96665eb
implement transformation on method header
mkforsb Jun 18, 2020
4ca59bf
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 19, 2020
fcbe7b2
fix bug in metavariable substitution of variable name in added local …
mkforsb Jun 19, 2020
02d2418
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 24, 2020
d9930b4
add script missing-contracts.py for finding test cases missing contra…
mkforsb Jun 24, 2020
feb344b
add contract comments to C4J tests
mkforsb Jun 24, 2020
b77cf60
add missing contract comments to several tests
mkforsb Jun 24, 2020
776fb12
remove typo
mkforsb Jun 24, 2020
0b619df
fix and test for bug with metavariables not being quantified in all b…
mkforsb Jun 24, 2020
da1f3c3
implement and test getLine() and getColumn() for SmPLLexer tokens
mkforsb Jun 24, 2020
5e0b41c
introduce SmPLProblemDetector
mkforsb Jun 24, 2020
eedecbd
introduce ElemNode.matchClass and simplify some of the logic of bindi…
mkforsb Jun 26, 2020
ed28d0b
introduce LabelMatchResult, drop 'matched element' bindings from pred…
mkforsb Jun 26, 2020
f2ce361
introduce InnerAnd formula connective and use it for wrapping the Seq…
mkforsb Jun 26, 2020
091cbb8
change tracking of already-transformed elements in Transformer to use…
mkforsb Jun 26, 2020
5b45e2e
add test based on C4J patch 'on_console_message'
mkforsb Jun 26, 2020
dbf4f9c
add contract comment to C4J test based on 'on_console_message'
mkforsb Jun 27, 2020
b76c152
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jun 27, 2020
25ce04d
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 1, 2020
647f9ef
add support for dots constraint 'when != expr' for arbitrary expressi…
mkforsb Jul 1, 2020
55f3000
add test based on C4J patch 'get_height'
mkforsb Jul 1, 2020
363e7df
add a TODO in FormulaCompiler
mkforsb Jul 1, 2020
50d2518
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 2, 2020
47e0c2e
add problem detection of dots in pattern disjunctions
mkforsb Jul 2, 2020
dd70703
add problem detection of dots operators on addition lines
mkforsb Jul 2, 2020
c1bb768
change several CtMethod parameters into CtExecutables
mkforsb Jul 3, 2020
c283259
add test based on C4J patch 'set_text_size'
mkforsb Jul 3, 2020
7023659
introduce SmPLGrep
mkforsb Jul 3, 2020
36be2d9
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 7, 2020
e914059
add call to SmPLGrep optimization in e2e test generator
mkforsb Jul 7, 2020
439a6d0
change ElemNode.matchClass to .matchStr for more flexibility, change …
mkforsb Jul 7, 2020
41ee91c
introduce RegexConstraint
mkforsb Jul 7, 2020
3da2cb0
modify patch used in C4J test based on 'set_text_size' to use RegexCo…
mkforsb Jul 7, 2020
7a891dc
introduce TypeAccessReplacer and more consistent pattern matching of …
mkforsb Jul 7, 2020
fdc0db5
add mechanism for marking e2e tests as purposefully invalid in valida…
mkforsb Jul 7, 2020
601a629
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 10, 2020
377b448
make modified 'set_text_size' C4J patch closer to semantics of origin…
mkforsb Jul 10, 2020
b4f9c34
move operations and labels into subpackages for neater organization
mkforsb Jul 14, 2020
4057b11
remove unused imports
mkforsb Jul 14, 2020
c859c86
fix potential nullpointer dereference in smplgrep
mkforsb Jul 14, 2020
a776321
nullify type references to the smpl rule container class to avoid spo…
mkforsb Jul 14, 2020
8d5f2cb
change pattern builder handling of null targets for invocations and f…
mkforsb Jul 14, 2020
fb25eb3
fix handling of type accesses for static members in TypeAccessReplacer
mkforsb Jul 14, 2020
887453f
introduce SmPLProcessor
mkforsb Jul 14, 2020
ff564c2
micro optimization in smplgrep
mkforsb Jul 14, 2020
e89aff8
have SmPLGrep build patterns from the lexer token stream instead of t…
mkforsb Jul 14, 2020
95d0daf
improved detection of type accesses on static members in TypeAccessRe…
mkforsb Jul 14, 2020
a79a4bb
only run TypeAccessReplacer on tested methods in ZippedCodeBaseContext
mkforsb Jul 14, 2020
e965da9
fix a raw use of parameterized class and remove some outdated comments
mkforsb Jul 14, 2020
344d791
doc comment fix
mkforsb Jul 14, 2020
14cab64
use original source fragment / source code when available for smplgrep
mkforsb Jul 15, 2020
357376f
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 16, 2020
e54b41d
fix and test bug in SmPLGrep.Pattern
mkforsb Jul 16, 2020
ee0ac78
fix and test two bugs in SmPLMethodCFG.UnsupportedElementSwapper
mkforsb Jul 17, 2020
34c770a
add SmPLRule::isPotentialMatch(File)
mkforsb Jul 17, 2020
f57a5b6
implement skipping of full files and improve timing statistics in SmP…
mkforsb Jul 17, 2020
376341b
add swapping of CtSuperAccess to UnsupportedElementSwapper
mkforsb Jul 17, 2020
3eec393
add missing test case to C4J test for 'on_console_message'
mkforsb Jul 17, 2020
84e84fe
add missing newline
mkforsb Jul 17, 2020
b0bd103
apply a small patch to C4JShouldVibrate code base to avoid a Spoon pr…
mkforsb Jul 17, 2020
a3167a9
add scripts for running the processor on the C4J patches, called 'tes…
mkforsb Jul 17, 2020
ac6c70b
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 17, 2020
aeb3622
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jul 28, 2020
d7d1a4f
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Aug 20, 2020
fa6ca2c
fix mistakes in class doc comment of MetadataPredicate
mkforsb Aug 20, 2020
f1e16e7
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Oct 7, 2020
1ecdc09
set spoon version to non-snapshot 8.2.0 in pom.xml
mkforsb Oct 7, 2020
0a583a8
have procTimer include the time spent printing diffs in SmPLProcessor
mkforsb Oct 7, 2020
6dfc74c
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Oct 31, 2020
05424c4
correct doc comments on the Optional connective
mkforsb Oct 31, 2020
46d6f28
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Jan 29, 2021
637e8e9
add TODO in smpl_grammar.txt
mkforsb Jan 29, 2021
23576d2
add test utility class EndToEndTestReader
mkforsb Jan 29, 2021
47bdfcd
parse end-to-end tests at test runtime
mkforsb Jan 29, 2021
ed12d6b
add tools/gen-e2e-testsuite.py script to generate an end-to-end test …
mkforsb Jan 29, 2021
71db5b5
add README for endtoend test resources dir
mkforsb Jan 29, 2021
e38e223
move all tools to ./tools and ensure they all contain a short comment…
mkforsb Jan 29, 2021
d4a8409
delete old tool files
mkforsb Jan 29, 2021
197a9ef
replace the 'purposefully-invalid' e2e tag with 'intentionally-does-n…
mkforsb Jan 31, 2021
9d7793f
add missing doc comments and minor fixes to pattern package, add empt…
mkforsb Jan 31, 2021
fc3205a
rename patterns ElemNode.sub to ElemNode.subPatterns
mkforsb Jan 31, 2021
53addf9
add a couple of comments to Environment.java
mkforsb Feb 1, 2021
959ff96
update a TODO in MethodHeaderModel
mkforsb Feb 1, 2021
038c837
update and add TODOs in ModelChecker
mkforsb Feb 1, 2021
0623ecd
add main doc comment for TriConsumer
mkforsb Feb 1, 2021
3ea3acb
more TODOs and comments
mkforsb Feb 1, 2021
e98b777
add TODO in SmPLJavaDSL
mkforsb Feb 1, 2021
35091d9
formatting fix in PropositionLabel
mkforsb Feb 1, 2021
5ab9b34
rename OperationFilter to OperationCategory
mkforsb Feb 1, 2021
c64afe8
up
monperrus Feb 1, 2021
3aa71b5
up
monperrus Feb 1, 2021
01f946c
up
monperrus Feb 1, 2021
f1c4903
fix all checkstyle errors
mkforsb Feb 1, 2021
dce01aa
re-add pom dependency on spoon-core and bump it to latest snapshot
mkforsb Feb 1, 2021
42c7cab
add task for spoon-smpl in travis-extra.sh
mkforsb Feb 1, 2021
c2f0c8d
add MIT license to module root and all .java files
mkforsb Feb 1, 2021
ca5ba7b
remove DeletionAnchorRemover and SelfTypeReferenceNullifier
mkforsb Feb 3, 2021
40ff24b
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Feb 3, 2021
1d6b682
add TriConsumerTest
mkforsb Feb 3, 2021
83d675d
include TriConsumer::andThen in TriConsumerTest
mkforsb Feb 3, 2021
86e3ed0
remove processor-tests
mkforsb Feb 3, 2021
9e0c758
up
monperrus Feb 3, 2021
b56b0ef
up
monperrus Feb 3, 2021
f79474a
up
monperrus Feb 3, 2021
c4cf28d
update README
mkforsb Feb 3, 2021
c2d2ada
update README
mkforsb Feb 3, 2021
cd6b303
Update README.md
nharrand Feb 3, 2021
b132625
update smpl_grammar.txt
mkforsb Feb 4, 2021
2e7030a
add doc page for spoon-smpl
mkforsb Feb 7, 2021
2714e1c
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Feb 7, 2021
9bd2307
Merge branch 'smpl-doc' into smpl
mkforsb Feb 7, 2021
3e2b7d6
add section to spoon-smpl docs page on the scope of implementation / …
mkforsb Feb 23, 2021
e17f1a5
Merge remote-tracking branch 'upstream/master' into smpl
mkforsb Feb 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spoon-smpl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# spoon-smpl

This module aims to implement support for (a variant/subset of) [SmPL](https://en.wikipedia.org/wiki/Coccinelle_(software)#Semantic_Patch_Language "Wikipedia entry").

Papers:
* [SmPL: A Domain-Specific Language for Specifying Collateral Evolutions in Linux Device Drivers](http://coccinelle.lip6.fr/papers/ercim.pdf)
* [A Foundation for Flow-Based Program Matching Using Temporal Logic and Model Checking](http://coccinelle.lip6.fr/papers/popl09.pdf)
* [Semantic Patches for Java Program Transformation](https://drops.dagstuhl.de/opus/volltexte/2019/10814/pdf/LIPIcs-ECOOP-2019-22.pdf)
93 changes: 93 additions & 0 deletions spoon-smpl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-smpl</artifactId>
<version>0.0.1</version>
<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<parent>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-pom</artifactId>
<version>1.0</version>
<relativePath>../spoon-pom</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>../checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<configuration>
<header>LICENSE.txt</header>
<basedir>src</basedir>
<includes>
<include>main/java/**</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-core</artifactId>
<version>8.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>control-flow</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
68 changes: 68 additions & 0 deletions spoon-smpl/smpl_grammar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
TODO: markdownify this file

First milestone SmPL grammar:

Adapted from http://coccinelle.lip6.fr/docs/main_grammar.pdf



Note: This grammar is incomplete as it does not cover dot modifiers <...> and <+...+>,
pattern disjunction (p | ... | p) and conjunction (p && ... && p)

These constructs are to be part of the first milestone but could not be
trivially lifted from the official grammar PDF as they are buried in the
C-specific parts of that grammar.



program ::= include_cocci* changeset+

include_cocci ::= #include string
| using string patch-local isomorphism definitions?
| using pathToIsoFile
// | virtual id (,id)*

changeset ::= metavariables transformation
// | script_metavariables script_code

metavariables ::= @@ metadecl* @@ | @ rulename @ metadecl* @@

// rulename ::= id [extends id] [depends on] [scope] dep [iso] [disable-iso] [exists] [rulekind]
rulename ::= id

metadecl ::= identifier ids ;
| type ids ;
| expression [list] ids ;
| statement [list] ids ;
| constant ids ;
| JavaType ids ;
// too much removed to include here

ids ::= pmid (, pmid)*
pmid ::= id | mid
mid ::= rulename_id.id

transformation ::= OPTDOTSEQ(top, when)

top ::= java_expr | java_decl_stmt+ | java_fundecl this is where the java lives

when ::= when != when_code
// | when any lifting shortest path restriction
// | when strict applicable to error states (how are these determined?)
| when exists not all paths need to match
| when forall all paths must match the complete rule
// | when true != expr
// | when false != expr


OPTDOTSEQ(grammar, when) = [... (when)*] grammar (... (when)* grammar)* [... (when)*]




Notable omissions in first milestone:

dots in method calls: foo(...)
"when any" lifting of shortest-path restriction for dots
"fresh identifier" metavariables for code generation
constraints/regexes on metavariable ids
97 changes: 97 additions & 0 deletions spoon-smpl/src/main/java/spoon/smpl/BranchLabel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package spoon.smpl;

import spoon.reflect.code.CtIf;
import spoon.reflect.declaration.CtElement;
import spoon.smpl.formula.BranchPattern;
import spoon.smpl.formula.Predicate;
import spoon.smpl.pattern.PatternBuilder;
import spoon.smpl.pattern.PatternMatcher;
import spoon.smpl.pattern.PatternNode;

import java.util.Map;

/**
* A BranchLabel is a Label used to associate states with CtElement code
* elements that can be matched using BranchPattern Formula elements.
*/
public class BranchLabel implements Label {
/**
* Create a new BranchLabel.
* @param cond Condition element of a branch statement element such as CtIf
*/
public BranchLabel(CtElement cond) {
CtElement parent = cond.getParent(); // throws ParentNotInitializedException

boolean ok = false;

// check for supported type of branch element, more supported types to come
if (parent instanceof CtIf) {
ok = true;
}

if (!ok) {
throw new IllegalArgumentException("Invalid condition parent");
}

this.cond = cond;

PatternBuilder builder = new PatternBuilder();
cond.accept(builder);
this.condPattern = builder.getResult();

this.parameters = null;
}

/**
* Test whether the label matches the given predicate.
* @param obj Predicate to test
* @return True if the predicate is a StatementPattern element whose Pattern matches the code exactly once, false otherwise.
*/
public boolean matches(Predicate obj) {
if (obj instanceof BranchPattern) {
BranchPattern bp = (BranchPattern) obj;

if (!bp.getBranchType().isInstance(cond.getParent())) {
return false;
}

PatternMatcher matcher = new PatternMatcher(bp.getConditionPattern());
condPattern.accept(matcher);
parameters = matcher.getParameters();
return matcher.getResult() && bp.processParameterBindings(parameters);
} else {
return false;
}
}

@Override
public Map<String, Object> getMatchedParameters() {
return parameters;
}

@Override
public void reset() {
parameters = null;
}

/**
* Get the code element.
* @return The code element
*/
public CtElement getCondition() {
return cond;
}

/**
* The branch condition element.
*/
private CtElement cond;

/**
* The pattern corresponding to the branch condition element.
* Part of temporary substitute for spoon.pattern.
*/
private PatternNode condPattern;

private Map<String, Object> parameters;
}
115 changes: 115 additions & 0 deletions spoon-smpl/src/main/java/spoon/smpl/CFGModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package spoon.smpl;

import fr.inria.controlflow.BranchKind;
import fr.inria.controlflow.ControlFlowGraph;
import spoon.reflect.declaration.CtElement;
import spoon.smpl.formula.BranchPattern;

import java.util.*;

/**
* A CFGModel builds a CTL model from a given CFG.
*/
public class CFGModel implements Model {
/**
* Create a new CTL model from a given CFG.
* @param cfg The ControlFlowGraph to use as a model, must have been simplified
*/
public CFGModel(ControlFlowGraph cfg) {
if (cfg.findNodesOfKind(BranchKind.BLOCK_BEGIN).size() > 0) {
throw new IllegalArgumentException("The CFG must be simplified (see ControlFlowGraph::simplify)");
}

this.cfg = cfg;

states = new ArrayList<Integer>();
successors = new HashMap<Integer, List<Integer>>();
labels = new HashMap<Integer, List<Label>>();

cfg.vertexSet().forEach(node -> {
int state = node.getId();

// Add a state ID for each vertex ID and prepare lists of successors and labels
states.add(state);
successors.put(state, new ArrayList<Integer>());
labels.put(state, new ArrayList<Label>());

// Add successors
cfg.outgoingEdgesOf(node).forEach(edge -> {
successors.get(state).add(edge.getTargetNode().getId());
});

// Add self-loop on exit node
if (node.getKind() == BranchKind.EXIT) {
successors.get(state).add(state);
}

CtElement stmt = node.getStatement();

// Add label
if (stmt != null) {
switch (node.getKind()) {
case BRANCH:
labels.get(state).add(new BranchLabel(stmt));
break;
case STATEMENT:
labels.get(state).add(new StatementLabel(stmt));
break;
default:
break;
}
}
});
}

/**
* @return the set of state IDs in the model
*/
@Override
public List<Integer> getStates() {
return states;
}

/**
* @param state Parent state
* @return the set of immediate successors of the given state
*/
@Override
public List<Integer> getSuccessors(int state) {
return successors.get(state);
}

/**
* @param state Target state
* @return the set of labels associated with the given state
*/
@Override
public List<Label> getLabels(int state) {
return labels.get(state);
}

/**
* @return the Control Flow Graph used to generate the model
*/
public ControlFlowGraph getCfg() { return cfg; }

/**
* The Control Flow Graph used to generate the model.
*/
private ControlFlowGraph cfg;

/**
* The set of state IDs.
*/
private List<Integer> states;

/**
* The set of immediate successors.
*/
private Map<Integer, List<Integer>> successors;

/**
* The set of state labels.
*/
private Map<Integer, List<Label>> labels;
}
Loading