forked from pharo-contributions/mutalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTParseRewriterMutantOperator.class.st
84 lines (72 loc) · 2.3 KB
/
MTParseRewriterMutantOperator.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Class {
#name : 'MTParseRewriterMutantOperator',
#superclass : 'MTAbstractMutantOperator',
#category : 'MuTalk-Model-Operators - Abstract',
#package : 'MuTalk-Model',
#tag : 'Operators - Abstract'
}
{ #category : 'testing' }
MTParseRewriterMutantOperator class >> isAbstract [
^ self == MTParseRewriterMutantOperator
]
{ #category : 'applying' }
MTParseRewriterMutantOperator >> applyTo: anOldNode [
| rewriter |
rewriter := RBParseTreeRewriter new.
rewriter
replace: self expressionToReplace
withValueFrom: [ :oNode | | aNewNode |
aNewNode := RBParser parseRewriteExpression: self newExpression.
aNewNode copyInContext: rewriter context ].
rewriter executeTree: anOldNode copy.
^ rewriter tree
]
{ #category : 'applying' }
MTParseRewriterMutantOperator >> expressionToReplace [
self subclassResponsibility
]
{ #category : 'private' }
MTParseRewriterMutantOperator >> modifiedSourceFor: aCompiledMethod with: aParseTree number: aNumber newExpression: anExpression [
| rewriter parser number nNode |
rewriter := RBParseTreeRewriter new.
number := aNumber.
parser := aParseTree copy.
rewriter
replace: self expressionToReplace
withValueFrom: [ :oNode |
| oldNode newNode |
nNode := RBParser parseRewriteExpression: anExpression.
nNode := nNode copyInContext: rewriter context.
oldNode := oNode.
newNode := nNode.
newNode ]
when: [ :node |
number := number - 1.
number = 0 ].
rewriter executeTree: parser.
parser := rewriter tree.
^ parser formattedCode
]
{ #category : 'private' }
MTParseRewriterMutantOperator >> mutationsFor: aCompiledMethod with: aParseTree number: nodeIndex storeIn: accumulator [
accumulator add: (MTMethodMutation
for: aCompiledMethod
using: self
nodeNumber: nodeIndex
ofClass: aCompiledMethod methodClass).
^ accumulator
]
{ #category : 'applying' }
MTParseRewriterMutantOperator >> newExpression [
self subclassResponsibility
]
{ #category : 'applying' }
MTParseRewriterMutantOperator >> timesToApplyIn: aCompiledMethod with: aParseTree [
"Evaluates how many times can the operator be applyied"
|searcher timesToApply|
searcher := RBParseTreeSearcher new.
timesToApply := 0.
searcher matches:self expressionToReplace do:[:node :answer | timesToApply := timesToApply + 1].
searcher executeTree: aParseTree copy.
^timesToApply.
]