Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14039-P12-RBVariableisDefinition-does-not-return-true-when-it-should #14051

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/AST-Core-Tests/RBVariableNodeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,29 @@ RBVariableNodeTest >> testIsDefinedByBlock [

{ #category : #tests }
RBVariableNodeTest >> testIsDefinition [

| ast temps |
ast := self class compiler
parse:
'myMethod: arg
| test |
ast := self class compiler parse: 'myMethod: arg
| test testCopied testTempVector|
test := 2.
test.
[ testCopied. testTempVector := 1 ].
^test'.
temps := ast allChildren select: [:each | each isTempVariable].
temps := ast allChildren select: [ :each | each isTempVariable ].

"arguments define variables"
self assert: ast arguments first isDefinition.
"this is the || definition"
self assert: temps first variable class identicalTo: TemporaryVariable.
self assert: temps first isDefinition.
self assert: temps second variable class identicalTo: CopiedLocalVariable.
self assert: temps second isDefinition.
self assert: temps third variable class identicalTo: OCVectorTempVariable .
self assert: temps third isDefinition.
"all the rest are just uses"
self deny: temps second isDefinition.
self deny: temps third isDefinition.
self deny: temps fourth isDefinition
self deny: temps fourth isDefinition.
self deny: (temps at: 5) isDefinition.
self deny: (temps at: 6) isDefinition
]

{ #category : #tests }
Expand Down
4 changes: 3 additions & 1 deletion src/OpalCompiler-Core/CopiedLocalVariable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ CopiedLocalVariable >> acceptVisitor: aProgramNodeVisitor node: aNode [

{ #category : #queries }
CopiedLocalVariable >> definingNode [
^originalVar definingNode
^ scope node temporaries
detect: [ :each | each variable == self ]
ifNone: [ nil ]
]

{ #category : #accessing }
Expand Down
1 change: 0 additions & 1 deletion src/OpalCompiler-Core/OpalCompiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ OpalCompiler class >> stopUsingOverlayForDevelopment [
]

{ #category : #plugins }

OpalCompiler >> addParsePlugin: aClass [
self compilationContext addParseASTTransformationPlugin: aClass
]
Expand Down
2 changes: 1 addition & 1 deletion src/Slot-Tests/ArgumentVariableTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
}

{ #category : #tests }
ArgumentVariableTest >> testDeclaringNode [
ArgumentVariableTest >> testDefiningNode [
| method declaringNode declaringNodeViaVariable|

method := OrderedCollection >> #do:.
Expand Down
23 changes: 13 additions & 10 deletions src/Slot-Tests/TemporaryVariableTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ Class {
}

{ #category : #tests }
TemporaryVariableTest >> testDeclaringNode [
| method declaringNode declaringNodeViaVariable|
method := self class >> #testTemporaryVariablesMethod.
declaringNode := method ast body temporaries first.
declaringNodeViaVariable := method assignmentNodes first variable variable definingNode.
self assert: declaringNodeViaVariable equals: declaringNode.
TemporaryVariableTest >> testDefiningNode [
"test for normal temps, copied and tempvector"
| ast tempsNodes tempDefintions tempUses |
ast := self class compiler parse: 'myMethod: arg
| test testCopied testTempVector|
test := 2.
test.
[ testCopied. testTempVector := 1 ].
^test'.
tempsNodes := ast allChildren select: [ :each | each isTempVariable ].
tempDefintions := tempsNodes select: [ :each | each isDefinition ].
tempUses := tempsNodes reject: [ :each | each isDefinition ].
tempUses do: [ :use | self assert: (tempDefintions includes: use variable definingNode)].

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

{ #category : #tests }
Expand Down