Skip to content

Commit

Permalink
Merge pull request #75 from DurieuxPol/feat/newOps
Browse files Browse the repository at this point in the history
Subclass replacement operator
  • Loading branch information
guillep committed Feb 14, 2024
2 parents 7b19d75 + 7b3307a commit aee676f
Show file tree
Hide file tree
Showing 107 changed files with 1,426 additions and 670 deletions.
149 changes: 149 additions & 0 deletions src/MuTalk-Model/MTAbstractMutantOperator.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
Class {
#name : 'MTAbstractMutantOperator',
#superclass : 'Object',
#category : 'MuTalk-Model-Operators',
#package : 'MuTalk-Model',
#tag : 'Operators'
}

{ #category : 'accessing' }
MTAbstractMutantOperator class >> allConcreteSubclasses [

^ self allSubclasses reject: [ :ea |
ea isAbstract | ea isOriginalOperator not ]
]

{ #category : 'accessing' }
MTAbstractMutantOperator class >> contents [
"This returns only the traditional operators "

^ ((self allConcreteSubclasses reject: #isDeprecated) collect: [
:class | class new ]) asSortedCollection: [ :elem1 :elem2 |
elem1 description <= elem2 description ]
]

{ #category : 'accessing' }
MTAbstractMutantOperator class >> contentsAll [
"This returns all operators (block based and traditional) "

^ ((self allSubclasses reject: [ :ea |
ea isAbstract or: [ ea isDeprecated ] ]) collect: [ :class |
class new ]) asSortedCollection: [ :elem1 :elem2 |
elem1 description <= elem2 description ]
]

{ #category : 'testing' }
MTAbstractMutantOperator class >> isAbstract [

^ self == MTAbstractMutantOperator
]

{ #category : 'testing' }
MTAbstractMutantOperator class >> isOriginalOperator [

^ true
]

{ #category : 'as yet unclassified' }
MTAbstractMutantOperator class >> recursionsDetectionStatement [

^ RBParser parseExpression:
('MuTalkInfiniteRecursionError onCount: {1}' format: { self recursionsDetectionThreshold } )
]

{ #category : 'as yet unclassified' }
MTAbstractMutantOperator class >> recursionsDetectionThreshold [

"We need a big enough number"

^ 1024
]

{ #category : 'printing' }
MTAbstractMutantOperator >> description [
self subclassResponsibility
]

{ #category : 'private' }
MTAbstractMutantOperator >> is: originalRBMethodNode equalTo: nodeThatMatches [
^ nodeThatMatches formattedCode = originalRBMethodNode formattedCode
]

{ #category : 'private' }
MTAbstractMutantOperator >> modifiedSourceFor: aCompiledMethod number: aNumber [

^ self
modifiedSourceFor: aCompiledMethod
with: aCompiledMethod parseTree
number: aNumber
newExpression: self newExpression
]

{ #category : 'private' }
MTAbstractMutantOperator >> modifiedSourceFor: aCompiledMethod number: aNumber newExpression: anExpression [

^ self
modifiedSourceFor: aCompiledMethod
with: aCompiledMethod parseTree
number: aNumber
newExpression: anExpression
]

{ #category : 'private' }
MTAbstractMutantOperator >> modifiedSourceFor: aCompiledMethod with: aParseTree number: aNumber newExpression: anExpression [

self subclassResponsibility
]

{ #category : 'mutant generation' }
MTAbstractMutantOperator >> mutationsFor: aCompiledMethod [

(aCompiledMethod ignoredMutationOperators includes: self class) ifTrue: [ ^ Array new ].

^self mutationsFor: aCompiledMethod with: aCompiledMethod parseTree.

]

{ #category : 'mutant generation' }
MTAbstractMutantOperator >> mutationsFor: aCompiledMethod with: aParseTree [

| numberOfAffectedNodes |
((aCompiledMethod hasPragmaNamed: #ignoreForMutations) or: [
aCompiledMethod hasPragmaNamed: #ignoreForCoverage ]) ifTrue: [
^ #( ) ].

numberOfAffectedNodes := self
timesToApplyIn: aCompiledMethod
with: aParseTree.
^ (1 to: numberOfAffectedNodes)
inject: OrderedCollection new
into: [ :accumulator :nodeIndex |
self
mutationsFor: aCompiledMethod
with: aParseTree
number: nodeIndex
storeIn: accumulator ]
]

{ #category : 'private' }
MTAbstractMutantOperator >> mutationsFor: aCompiledMethod with: aParseTree number: nodeIndex storeIn: accumulator [

self subclassResponsibility
]

{ #category : 'suggestions' }
MTAbstractMutantOperator >> suggestionFor: aMutation using: aMutantKillingSuggestionGenerator [
^'No Suggestion'
]

{ #category : 'applying' }
MTAbstractMutantOperator >> timesToApplyIn: aCompiledMethod [
^self timesToApplyIn: aCompiledMethod with: aCompiledMethod parseTree.

]

{ #category : 'applying' }
MTAbstractMutantOperator >> timesToApplyIn: aCompiledMethod with: aParseTree [

self subclassResponsibility
]
2 changes: 1 addition & 1 deletion src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ MTAnalysis >> defaultMutantSelectionStrategy [
{ #category : 'accessing - defaults' }
MTAnalysis >> defaultOperators [

^ MTMutantOperator contents
^ MTAbstractMutantOperator contents
]

{ #category : 'accessing - defaults' }
Expand Down
25 changes: 12 additions & 13 deletions src/MuTalk-Model/MTAssignmentNullifierOperator.class.st
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
Class {
#name : 'MTAssignmentNullifierOperator',
#superclass : 'MTBlockBasedMutantOperator',
#superclass : 'MTPredicateBasedMutantOperator',
#category : 'MuTalk-Model-Operators',
#package : 'MuTalk-Model',
#tag : 'Operators'
}

{ #category : 'applying' }
MTAssignmentNullifierOperator >> appliesToNode: aNode [

^ aNode isAssignment & aNode value isNotNil
]

{ #category : 'printing' }
MTAssignmentNullifierOperator >> description [

^ 'Nullify the value assigned'
]

{ #category : 'applying' }
MTAssignmentNullifierOperator >> expressionToReplace [

^ [ :aNode | aNode isAssignment & aNode value isNotNil ]
]

{ #category : 'applying' }
MTAssignmentNullifierOperator >> newExpression [
MTAssignmentNullifierOperator >> newNodeFrom: anOldNode [

^ [ :anOldNode |
| nodeCopy |
nodeCopy := anOldNode copy.
nodeCopy value: (RBLiteralValueNode value: nil).
nodeCopy ]
| nodeCopy |
nodeCopy := anOldNode copy.
nodeCopy value: (RBLiteralValueNode value: nil).
^ nodeCopy
]
61 changes: 0 additions & 61 deletions src/MuTalk-Model/MTBlockBasedMutantOperator.class.st

This file was deleted.

19 changes: 9 additions & 10 deletions src/MuTalk-Model/MTEmptyMethodOperator.class.st
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
Class {
#name : 'MTEmptyMethodOperator',
#superclass : 'MTBlockBasedMutantOperator',
#superclass : 'MTPredicateBasedMutantOperator',
#category : 'MuTalk-Model-Operators',
#package : 'MuTalk-Model',
#tag : 'Operators'
}

{ #category : 'printing' }
MTEmptyMethodOperator >> description [
{ #category : 'applying' }
MTEmptyMethodOperator >> appliesToNode: aNode [

^ 'Removing all lines in a method'
^ aNode isSequence and: [ aNode parent isMethod ]
]

{ #category : 'applying' }
MTEmptyMethodOperator >> expressionToReplace [
{ #category : 'printing' }
MTEmptyMethodOperator >> description [

^ [ :aNode |
aNode isSequence and: [ aNode parent isMethod] ]
^ 'Removing all lines in a method'
]

{ #category : 'applying' }
MTEmptyMethodOperator >> newExpression [
MTEmptyMethodOperator >> newNodeFrom: anOldNode [

^ [ :anOldNode | RBSequenceNode statements: #() ]
^ RBSequenceNode statements: #( )
]
21 changes: 10 additions & 11 deletions src/MuTalk-Model/MTLiteralBooleanNegateOperator.class.st
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
Class {
#name : 'MTLiteralBooleanNegateOperator',
#superclass : 'MTBlockBasedMutantOperator',
#superclass : 'MTPredicateBasedMutantOperator',
#category : 'MuTalk-Model-Operators',
#package : 'MuTalk-Model',
#tag : 'Operators'
}

{ #category : 'printing' }
MTLiteralBooleanNegateOperator >> description [
{ #category : 'applying' }
MTLiteralBooleanNegateOperator >> appliesToNode: aNode [

^ 'Negate a literal boolean'
^ aNode isLiteralNode & aNode isLiteralArray not and: [
{ true. false } includes: aNode value ]
]

{ #category : 'applying' }
MTLiteralBooleanNegateOperator >> expressionToReplace [
{ #category : 'printing' }
MTLiteralBooleanNegateOperator >> description [

^ [ :aNode |
aNode isLiteralNode & aNode isLiteralArray not and: [
{ true. false } includes: aNode value ] ]
^ 'Negate a literal boolean'
]

{ #category : 'applying' }
MTLiteralBooleanNegateOperator >> newExpression [
MTLiteralBooleanNegateOperator >> newNodeFrom: anOldNode [

^ [ :anOldNode | RBLiteralValueNode value: anOldNode value not ]
^ RBLiteralValueNode value: anOldNode value not
]
19 changes: 10 additions & 9 deletions src/MuTalk-Model/MTLiteralIntegersDecreaseOperator.class.st
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
Class {
#name : 'MTLiteralIntegersDecreaseOperator',
#superclass : 'MTBlockBasedMutantOperator',
#superclass : 'MTPredicateBasedMutantOperator',
#category : 'MuTalk-Model-Operators',
#package : 'MuTalk-Model',
#tag : 'Operators'
}

{ #category : 'printing' }
MTLiteralIntegersDecreaseOperator >> description [
{ #category : 'applying' }
MTLiteralIntegersDecreaseOperator >> appliesToNode: aNode [

^ 'Decrease a literal integer'
^ aNode isLiteralNode & aNode isLiteralArray not and: [
aNode value isInteger ]
]

{ #category : 'applying' }
MTLiteralIntegersDecreaseOperator >> expressionToReplace [
{ #category : 'printing' }
MTLiteralIntegersDecreaseOperator >> description [

^ [ :aNode | aNode isLiteralNode & aNode isLiteralArray not and: [ aNode value isInteger ] ]
^ 'Decrease a literal integer'
]

{ #category : 'applying' }
MTLiteralIntegersDecreaseOperator >> newExpression [
MTLiteralIntegersDecreaseOperator >> newNodeFrom: anOldNode [

^ [ :anOldNode | RBLiteralValueNode value: anOldNode value - 1 ]
^ RBLiteralValueNode value: anOldNode value - 1
]
Loading

0 comments on commit aee676f

Please sign in to comment.