Skip to content

Commit

Permalink
Merge pull request pharo-project#4642 from MarcusDenker/4641-OCASTClo…
Browse files Browse the repository at this point in the history
…sureAnalyzer-does-not-update-binding-of-temp-var-definitions

4641-OCASTClosureAnalyzer-does-not-update-binding-of-temp-var-definitions
  • Loading branch information
MarcusDenker committed Sep 18, 2019
2 parents e6ac2e2 + f2fb16c commit e0363c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/OpalCompiler-Core/OCASTClosureAnalyzer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ OCASTClosureAnalyzer >> doRemotes [

]

{ #category : #variables }
OCASTClosureAnalyzer >> lookupAndFixBinding: aVariableNode [
| var |
var := scope lookupVar: aVariableNode name.
aVariableNode binding: var.
^var
]

{ #category : #visiting }
OCASTClosureAnalyzer >> visitArgumentNode: aVariableNode [

Expand All @@ -38,6 +46,7 @@ OCASTClosureAnalyzer >> visitBlockNode: aBlockNode [
scope := aBlockNode scope.
self doRemotes; doCopying.
self visitNode: aBlockNode body.
aBlockNode temporaries do: [ :each | self lookupAndFixBinding: each ].
scope := scope popScope.
]

Expand All @@ -48,6 +57,7 @@ OCASTClosureAnalyzer >> visitMethodNode: aMethodNode [
scope := aMethodNode scope.
self doRemotes; doCopying.
self visitNode: aMethodNode body.
aMethodNode temporaries do: [ :each | self lookupAndFixBinding: each ]
]

{ #category : #visiting }
Expand All @@ -57,8 +67,7 @@ OCASTClosureAnalyzer >> visitVariableNode: aVariableNode [
| var |
aVariableNode adaptToSemanticNode.
aVariableNode isTemp ifFalse: [^self].
var := scope lookupVar: aVariableNode name.
aVariableNode binding: var.
var := self lookupAndFixBinding: aVariableNode.
var isTempVectorTemp ifTrue: [scope addCopyingTempToAllScopesUpToDefVector: var vectorName].
var isCopying ifTrue: [scope addCopyingTempToAllScopesUpToDefTemp: var].
]
18 changes: 18 additions & 0 deletions src/OpalCompiler-Tests/OCASTClosureAnalyzerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,24 @@ OCASTClosureAnalyzerTest >> testSingleRemoteTempVar [

]

{ #category : #'testing - variables' }
OCASTClosureAnalyzerTest >> testVariableDefintionScopeUpdate [
"the scope of local var definitons needs to be updated, too"

| ast |
ast := OpalCompiler new parse:
'm04_two_temps_one_temp_in_remote_vector
| t1 t2 |
t1 := 1.
[ t2 := t1 + 1.0 ] value.
^t2'.
ast doSemanticAnalysis.
self assert: ast temporaries second binding class equals: OCVectorTempVariable
]

{ #category : #'tests - special cases' }
OCASTClosureAnalyzerTest >> testWrittenAfterClosedOver [
| ast |
Expand Down

0 comments on commit e0363c3

Please sign in to comment.