Skip to content

Commit

Permalink
- add isInstanceVariable and isGlobalVariable to RBVariable
Browse files Browse the repository at this point in the history
- fix all senders of isInstance to call isInstanceVariable
- deprecate isInstance on RBVariableNode
- deprecate isInstance, isGlobal and isLocal on Variable

fixes #3236
  • Loading branch information
MarcusDenker committed Jul 14, 2020
1 parent 1621ee2 commit 82245f1
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 31 deletions.
5 changes: 0 additions & 5 deletions src/AST-Core/RBInstanceVariableNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ Class {
RBInstanceVariableNode >> acceptVisitor: aProgramNodeVisitor [
^ aProgramNodeVisitor visitInstanceVariableNode: self
]

{ #category : #testing }
RBInstanceVariableNode >> isInstance [
^true
]
6 changes: 3 additions & 3 deletions src/AST-Core/RBProgramNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,17 @@ RBProgramNode >> hashForCollection: aCollection [

{ #category : #querying }
RBProgramNode >> instanceVariableNodes [
^self variableNodes select: [:each | each isInstance]
^self variableNodes select: [:each | each isInstanceVariable]
]

{ #category : #querying }
RBProgramNode >> instanceVariableReadNodes [
^self variableReadNodes select: [:each | each isInstance]
^self variableReadNodes select: [:each | each isInstanceVariable]
]

{ #category : #querying }
RBProgramNode >> instanceVariableWriteNodes [
^self variableWriteNodes select: [:each | each isInstance]
^self variableWriteNodes select: [:each | each isInstanceVariable]
]

{ #category : #testing }
Expand Down
10 changes: 10 additions & 0 deletions src/AST-Core/RBVariableNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,21 @@ RBVariableNode >> isDefinition [
^ false
]

{ #category : #testing }
RBVariableNode >> isGlobalVariable [
^variable isGlobalVariable
]

{ #category : #testing }
RBVariableNode >> isImmediateNode [
^true
]

{ #category : #testing }
RBVariableNode >> isInstanceVariable [
^variable isInstanceVariable
]

{ #category : #testing }
RBVariableNode >> isRead [
^ self isWrite not and: [ self isUsed ]
Expand Down
4 changes: 2 additions & 2 deletions src/Calypso-Ring/RGMethod.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ RGMethod >> readsSlot: aSlot [
| nodes |
nodes := self ast allChildren.
nodes := nodes select: #isVariable.
nodes := nodes select: #isInstance.
nodes := nodes select: #isInstanceVariable.
nodes := nodes reject: [ :node | node parent isAssignment and: [ node parent variable = node ] ].
^ nodes anySatisfy: [ :node | node binding == aSlot ]
]
Expand Down Expand Up @@ -129,7 +129,7 @@ RGMethod >> writesSlot: aSlot [
node isVariable and: [
node parent isAssignment and: [
(node parent variable = node) and: [
node isInstance and: [
node isInstanceVariable and: [
(node binding == aSlot)
ifTrue: [^true]]]]]].
^false
Expand Down
2 changes: 1 addition & 1 deletion src/Calypso-SystemTools-Core/ClySourceCodeContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ClySourceCodeContext >> isVariableSelected [

binding := node binding.

^binding isClassVariable | binding isInstance | binding isGlobalVariable | binding isUndeclared
^binding isClassVariable | binding isInstanceVariable | binding isGlobalVariable | binding isUndeclared
]

{ #category : #selection }
Expand Down
4 changes: 2 additions & 2 deletions src/ClassParser-Tests/CDExistingClassDefinitionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CDExistingClassDefinitionTest >> testSharedSlotNodeArePolymorphicToRBVariableNod
self deny: classVarNode isTemp.
self deny: classVarNode isGlobalVariable.
self assert: classVarNode isClassVariable.
self deny: classVarNode isInstance.
self deny: classVarNode isInstanceVariable.
self deny: classVarNode isLiteralVariable.
self deny: classVarNode isUndeclared.
]
Expand All @@ -78,7 +78,7 @@ CDExistingClassDefinitionTest >> testSlotNodeArePolymorphicToRBVariableNodes [
self deny: slotNode isTemp.
self deny: slotNode isGlobalVariable.
self deny: slotNode isClassVariable.
self assert: slotNode isInstance.
self assert: slotNode isInstanceVariable.
self deny: slotNode isLiteralVariable.
self deny: slotNode isUndeclared.
]
Expand Down
2 changes: 1 addition & 1 deletion src/ClassParser/CDSharedVariableNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CDSharedVariableNode >> isClassVariable [
]

{ #category : #testing }
CDSharedVariableNode >> isInstance [
CDSharedVariableNode >> isInstanceVariable [
"To be polymorphic to RB method nodes"
^false
]
Expand Down
2 changes: 1 addition & 1 deletion src/ClassParser/CDSlotNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CDSlotNode >> isGlobalVariable [
]

{ #category : #testing }
CDSlotNode >> isInstance [
CDSlotNode >> isInstanceVariable [
"To be polymorphic to RB method nodes"
^true
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ReTestCaseShouldNotUseInitializeRule >> basicCheck: aClass [
ifFalse: [ ^ false ].

alteredVariables := (aClass >> #initialize) ast allChildren
select: [ :e | e isAssignment and: [ e variable isInstance ] ]
select: [ :e | e isAssignment and: [ e variable isInstanceVariable ] ]
thenCollect: [ :e | e variable ].

expectedVariables := aClass new instanceVariablesToKeep.
Expand Down
15 changes: 10 additions & 5 deletions src/Kernel/Variable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ Variable >> isClassVariable [

{ #category : #testing }
Variable >> isGlobal [
"this will be deprecated"
self
deprecated: 'Use #isGlobalVariable instead.'
transformWith: '`@receiver isGlobal' -> '`@receiver isGlobalVariable'.

^self isGlobalVariable
]

Expand All @@ -126,8 +129,9 @@ Variable >> isGlobalVariable [

{ #category : #testing }
Variable >> isInstance [
"this will be deprecated"
^ self isInstanceVariable
self
deprecated: 'Use #isInstanceVariable instead.'
transformWith: '`@receiver isInstance' -> '`@receiver isInstanceVariable'.
]

{ #category : #testing }
Expand All @@ -145,8 +149,9 @@ Variable >> isLiteralVariable [

{ #category : #testing }
Variable >> isLocal [
"this will be deprecated"
^self isLocalVariable
self
deprecated: 'Use #isLocalVariable instead.'
transformWith: '`@receiver isLocal' -> '`@receiver isLocalVariable'.
]

{ #category : #testing }
Expand Down
7 changes: 5 additions & 2 deletions src/OpalCompiler-Core/RBVariableNode.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RBVariableNode >> isArg [

{ #category : #'*opalcompiler-core' }
RBVariableNode >> isClean [
^ (self isInstance | self isReservedVariable) not
^ (self isInstanceVariable | self isReservedVariable) not
]

{ #category : #'*opalcompiler-core' }
Expand All @@ -32,7 +32,10 @@ RBVariableNode >> isGlobal [

{ #category : #'*opalcompiler-core' }
RBVariableNode >> isInstance [
^self binding isInstance
self
deprecated: 'Use #isInstanceVariable instead.'
transformWith: '`@receiver isInstance' -> '`@receiver isInstanceVariable'.
^variable isInstanceVariable
]

{ #category : #'*opalcompiler-core' }
Expand Down
10 changes: 5 additions & 5 deletions src/OpalCompiler-Tests/OCASTCheckerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ OCASTCheckerTest >> testInstanceVar [
self assertEmpty: ast scope tempVars.

self assert: ast scope outerScope isInstanceScope.
self assert: (ast scope outerScope lookupVar: 'iVar') isInstance.
self assert: (ast scope outerScope lookupVar: 'iVar') isInstanceVariable.

assignment := RBParseTreeSearcher treeMatching: '`var := ``@anything' in: ast.
self assert: assignment variable isInstance
self assert: assignment variable isInstanceVariable
]

{ #category : #'testing - variables' }
Expand Down Expand Up @@ -307,9 +307,9 @@ OCASTCheckerTest >> testSingleRemoteTempVar [
self assert: (ast scope lookupVar: 'theCollection') isEscaping.
self assert: (ast scope lookupVar: 'block') isTemp.
self assert: (ast scope lookupVar: 'theCollection') isTemp.
self deny: (ast scope lookupVar: 'theCollection') isInstance.
self deny: (ast scope lookupVar: 'index') isInstance.
self deny: (ast scope lookupVar: 'block') isInstance
self deny: (ast scope lookupVar: 'theCollection') isInstanceVariable.
self deny: (ast scope lookupVar: 'index') isInstanceVariable.
self deny: (ast scope lookupVar: 'block') isInstanceVariable
]
{ #category : #'testing - variables' }
Expand Down
4 changes: 2 additions & 2 deletions src/Reflectivity/RFOperationReification.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RFOperationReification >> genForRBAssignmentNode [
context: thisContext;
variableName: #{1}.' format: {entity variable name})].

entity variable isInstance ifTrue: [
entity variable isInstanceVariable ifTrue: [
^RBParser parseExpression: ('RFSlotWrite new
assignedValue: RFNewValueReificationVar;
object: self;
Expand Down Expand Up @@ -99,7 +99,7 @@ RFOperationReification >> genForRBReturnNode [

{ #category : #generate }
RFOperationReification >> genForRBVariableNode [
entity isInstance ifTrue: [
entity isInstanceVariable ifTrue: [
^RBParser parseExpression: ('RFSlotRead new
object: self;
variableName: #{1}.' format: {entity name})].
Expand Down
2 changes: 1 addition & 1 deletion src/Shout/SHRBTextStyler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ SHRBTextStyler >> resolveStyleFor: aVariableNode [
aVariableNode isArgument ifTrue: [ ^#methodArg].
aVariableNode isTemp ifTrue: [ ^#tempVar].
aVariableNode isGlobal ifTrue: [ ^#globalVar].
aVariableNode isInstance ifTrue: [ ^#instVar].
aVariableNode isInstanceVariable ifTrue: [ ^#instVar].

(self class formatIncompleteIdentifiers and: [ aVariableNode hasIncompleteIdentifier ])
ifTrue:[ ^#incompleteIdentifier] .
Expand Down

0 comments on commit 82245f1

Please sign in to comment.