Skip to content

Commit

Permalink
#isReferenced for TemporaryVariables need to check if the var is real…
Browse files Browse the repository at this point in the history
…ly accessed. This implementation does it using the AST: if there are no astNodes for this variables, it is not used.

- Implement isReferenced
- add test
- move implementation isReferenced from Variable to Slo
- add isReferenced as subclassResponsability in Variable
  • Loading branch information
MarcusDenker committed Jun 13, 2020
1 parent f8772ce commit 5c2086f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Kernel/Slot.class.st
Expand Up @@ -231,6 +231,11 @@ Slot >> isReadIn: aCompiledCode [
anySatisfy: [ :node | node binding slot == self ]
]

{ #category : #testing }
Slot >> isReferenced [
^self usingMethods isNotEmpty
]

{ #category : #testing }
Slot >> isSelfEvaluating [
^true
Expand Down
5 changes: 5 additions & 0 deletions src/Kernel/TemporaryVariable.class.st
Expand Up @@ -79,6 +79,11 @@ TemporaryVariable >> isFromBlock [
^startpc isNotNil
]

{ #category : #testing }
TemporaryVariable >> isReferenced [
^self astNodes isNotEmpty
]

{ #category : #accessing }
TemporaryVariable >> method [
^ method
Expand Down
3 changes: 1 addition & 2 deletions src/Kernel/Variable.class.st
Expand Up @@ -66,8 +66,7 @@ Variable >> hash [

{ #category : #testing }
Variable >> isReferenced [
"Subclasses can implement optimized version avoiding all methods collections"
^self usingMethods isNotEmpty
^ self subclassResponsibility
]

{ #category : #accessing }
Expand Down
2 changes: 1 addition & 1 deletion src/Slot-Core/CompiledMethod.extension.st
Expand Up @@ -35,6 +35,6 @@ CompiledMethod >> temporaryVariableNamed: aName [

{ #category : #'*Slot-Core' }
CompiledMethod >> temporaryVariables [
^self tempNames collect: [ :name | TemporaryVariable new name: name ]
^self tempNames collect: [ :name | TemporaryVariable name: name method: self]

]
9 changes: 9 additions & 0 deletions src/Slot-Tests/TemporaryVariableTest.class.st
Expand Up @@ -21,6 +21,15 @@ TemporaryVariableTest >> testHasTemporaryVariablesMethod [
self assert: (method hasTemporaryVariableNamed: #method)
]

{ #category : #tests }
TemporaryVariableTest >> testIsReferenced [
| method notReferenced |
"The temp notReferenced is not used as we test exactly that here"
method := self class >> #testIsReferenced.
self assert: method temporaryVariables first isReferenced.
self deny: method temporaryVariables second isReferenced.
]

{ #category : #properties }
TemporaryVariableTest >> testPropertyAtPut [

Expand Down

0 comments on commit 5c2086f

Please sign in to comment.