Skip to content

Commit

Permalink
inlined method & fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Durieux Pol committed Feb 9, 2024
1 parent 45420cc commit e20557f
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/MuTalk-Model/MTSubclassReplacementOperator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,35 @@ MTSubclassReplacementOperator >> initialize [
]

{ #category : 'private' }
MTSubclassReplacementOperator >> mutationFor: aCompiledMethod with: aParseTree number: aNumberOfSelector storeIn: aCollection [
MTSubclassReplacementOperator >> mutationsFor: aCompiledMethod with: aParseTree [

| classToReplace |
classToReplace := classesToReplace at: aNumberOfSelector.
aCollection addAll:
((1 to: classToReplace subclasses size) collect: [ :index |
| newExpression |
newExpression := self
newExpressionForClass: aNumberOfSelector
andSubclass: index.
Halt if: [ aCompiledMethod = (UUID>>#initialize) ].
MTMethodMutation
for: aCompiledMethod
using: self
nodeNumber: aNumberOfSelector
ofClass: aCompiledMethod methodClass
replacingWith: newExpression ]).
^ aCollection
]

{ #category : 'applying' }
MTSubclassReplacementOperator >> newExpressionForClass: classIndex andSubclass: subclassIndex [
| numberOfAffectedNodes |
((aCompiledMethod hasPragmaNamed: #ignoreForMutations) or: [
aCompiledMethod hasPragmaNamed: #ignoreForCoverage ]) ifTrue: [
^ #( ) ].

^ [ :anOldNode |
| nodeCopy |
nodeCopy := anOldNode copy.
nodeCopy name:
((classesToReplace at: classIndex) subclasses at: subclassIndex)
name.
nodeCopy ]
numberOfAffectedNodes := self
timesToApplyIn: aCompiledMethod
with: aParseTree.
^ (1 to: numberOfAffectedNodes)
inject: OrderedCollection new
into: [ :accumulator :nodeIndex |
| classToReplace affectedNode |
affectedNode := self affectedNodeFor: aParseTree at: nodeIndex.
"We know that the affectedNode is on a class reference to a class that exists and has subclasses"
classToReplace := self class environment at: affectedNode name.
accumulator addAll:
(classToReplace subclasses collect: [ :subclass |
| newExpression |
newExpression := [ :anOldNode |
RBVariableNode named: subclass name ].
MTMethodMutation
for: aCompiledMethod
using: self
nodeNumber: nodeIndex
ofClass: aCompiledMethod methodClass
replacingWith: newExpression ]).
accumulator ]
]

{ #category : 'applying' }
Expand All @@ -66,3 +65,12 @@ MTSubclassReplacementOperator >> nodeSelectionPredicate [
referencedClass isClass and: [
referencedClass subclasses notEmpty ] ] ] ]
]

{ #category : 'applying' }
MTSubclassReplacementOperator >> subclassesForNode: aNode [
"pre condition: aNode is a class reference node that exists"

| referencedClass |
referencedClass := self class environment at: aNode name.
^ referencedClass subclasses
]

0 comments on commit e20557f

Please sign in to comment.