Skip to content

Commit

Permalink
- fix the depcrecated call. fixes pharo-project#6890
Browse files Browse the repository at this point in the history
- add CompiledMethod>>#accessesField: and test, use it in InstanceVariable>>isAccessedIn:
- add #definingNode which where missed on the other PR (and yes, this is really a wrapper.. to be done later)
- remove empty OCVariableSpecialisationTest
- add #definedVariable to get all class and invars of a class
- remove deprecated #instanceVariables on ClassDescription
  • Loading branch information
MarcusDenker committed Jul 18, 2020
1 parent 0ef688e commit 8343fc3
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 23 deletions.
21 changes: 21 additions & 0 deletions src/Kernel-Tests-Extended/CompiledMethodTest.class.st
Expand Up @@ -271,6 +271,27 @@ CompiledMethodTest >> tearDown [
super tearDown
]

{ #category : #'tests - instance variable' }
CompiledMethodTest >> testAccessesField [
| method |
method := self class compiledMethodAt: #readX.
self assert: (method accessesField: 4).

method := self class compiledMethodAt: #readXandY.
self assert: (method accessesField: 5).


"read is not write"
method := self class compiledMethodAt: #writeX.
self assert: (method accessesField: 4).

method := self class compiledMethodAt: #writeXandY.
self assert: (method accessesField: 4).

method := self class compiledMethodAt: #writeXandY.
self assert: (method accessesField: 5)
]

{ #category : #'tests - slots' }
CompiledMethodTest >> testAccessesSlot [

Expand Down
8 changes: 7 additions & 1 deletion src/Kernel/Class.class.st
Expand Up @@ -453,6 +453,12 @@ Class >> declareClassVariables: newVars [
^conflicts
]

{ #category : #'pool variables' }
Class >> definedVariables [
"return all the Variables defined by this class"
^self slots, self classVariables
]

{ #category : #'class variables' }
Class >> definesClassVariable: aGlobal [
"Return whether the receiver has a class variables (shared variables among its class and subclasses) named: aString"
Expand Down Expand Up @@ -960,7 +966,7 @@ Class >> setName: aSymbol [
name := aSymbol.
]

{ #category : #accessing }
{ #category : #'pool variables' }
Class >> sharedPoolNames [
^ self sharedPools collect: [:ea |
ea isObsolete
Expand Down
9 changes: 0 additions & 9 deletions src/Kernel/ClassDescription.class.st
Expand Up @@ -789,15 +789,6 @@ ClassDescription >> instanceSide [
^ self subclassResponsibility
]

{ #category : #accessing }
ClassDescription >> instanceVariables [
"we deprecate this due to bad naming: it returns names, not variables!"
self
deprecated: 'Please use #instVarNames or #slotNames instead'
transformWith: '`@receiver instanceVariables' -> '`@receiver instVarNames'.
^self instVarNames
]

{ #category : #printing }
ClassDescription >> instanceVariablesString [
"Answer a string of my instance variable names separated by spaces."
Expand Down
7 changes: 7 additions & 0 deletions src/Kernel/CompiledCode.class.st
Expand Up @@ -71,6 +71,13 @@ CompiledCode >> = aCompiledMethod [
^ true
]

{ #category : #scanning }
CompiledCode >> accessesField: varIndex [
"Answer whether the receiver accesses the instance variable indexed by the argument."

^ (self readsField: varIndex) or: [ self writesField: varIndex ]
]

{ #category : #scanning }
CompiledCode >> accessesSlot: aSlot [
^aSlot isAccessedIn: self
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/InstanceVariableSlot.class.st
Expand Up @@ -59,7 +59,7 @@ InstanceVariableSlot >> emitValue: methodBuilder [

{ #category : #testing }
InstanceVariableSlot >> isAccessedIn: aCompiledCode [
^(aCompiledCode readsField: index) or: [aCompiledCode writesField: index]
^ aCompiledCode accessesField: index
]

{ #category : #testing }
Expand Down
5 changes: 1 addition & 4 deletions src/Kernel/UndefinedObject.class.st
Expand Up @@ -123,10 +123,7 @@ UndefinedObject >> findUndeclaredVariableIn: ast [
"Walk the ast of the current statment and find the undeclared variable node, or nil (if none).
Assumes there is only one such variable in an executing statement"

ast nodesDo: [:node |
(node isVariable and: [ node isUndeclared]) ifTrue: [ ^node ]].

^nil
^ast nodes detect: [:node | node isVariable and: [ node isUndeclared]] ifNone: [ nil ]
]

{ #category : #testing }
Expand Down
5 changes: 5 additions & 0 deletions src/OpalCompiler-Core/OCCopyingArgumentVariable.class.st
Expand Up @@ -10,6 +10,11 @@ Class {
#category : #'OpalCompiler-Core-Semantics'
}

{ #category : #queries }
OCCopyingArgumentVariable >> definingNode [
^originalVar definingNode
]

{ #category : #accessing }
OCCopyingArgumentVariable >> index: anIndex [
self scope == originalVar scope ifTrue: [ originalVar index: anIndex ].
Expand Down
5 changes: 5 additions & 0 deletions src/OpalCompiler-Core/OCCopyingTempVariable.class.st
Expand Up @@ -12,6 +12,11 @@ Class {
#category : #'OpalCompiler-Core-Semantics'
}

{ #category : #queries }
OCCopyingTempVariable >> definingNode [
^originalVar definingNode
]

{ #category : #accessing }
OCCopyingTempVariable >> index: anIndex [
self scope == originalVar scope ifTrue: [ originalVar index: anIndex ].
Expand Down
5 changes: 0 additions & 5 deletions src/OpalCompiler-Tests/OCVariableSpecialisationTest.class.st

This file was deleted.

4 changes: 2 additions & 2 deletions src/Slot-Tests/ArgumentVariableTest.class.st
Expand Up @@ -10,11 +10,11 @@ ArgumentVariableTest >> testDeclaringNode [

method := OrderedCollection >> #do:.
declaringNode := method ast arguments first.
declaringNodeViaVariable := method ast variableReadNodes third variable variable definingNode.
declaringNodeViaVariable := method ast variableReadNodes third variable definingNode.
self assert: declaringNodeViaVariable equals: declaringNode.

"check block argument"
declaringNode := method blockNodes first arguments first.
declaringNodeViaVariable := method ast variableReadNodes fifth variable variable definingNode.
declaringNodeViaVariable := method ast variableReadNodes fifth variable definingNode.
self assert: declaringNodeViaVariable equals: declaringNode.
]
2 changes: 1 addition & 1 deletion src/Slot-Tests/TemporaryVariableTest.class.st
Expand Up @@ -17,7 +17,7 @@ TemporaryVariableTest >> testDeclaringNode [

method := OrderedCollection >> #do:.
declaringNode := method ast arguments first.
declaringNodeViaVariable := method ast variableReadNodes third variable variable definingNode.
declaringNodeViaVariable := method ast variableReadNodes third variable definingNode.
self assert: declaringNodeViaVariable equals: declaringNode.
]

Expand Down

0 comments on commit 8343fc3

Please sign in to comment.