Skip to content

Commit 1bfed42

Browse files
committed
Manage for statement left and right
1 parent 1f748f5 commit 1bfed42

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

src/FAST-Python-Tools-Tests/FASTPythonLocalResolverTest.class.st

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,45 +86,39 @@ print(x)'.
8686
{ #category : 'tests' }
8787
FASTPythonLocalResolverTest >> testVariableAccessedInForIn [
8888

89-
| assignment1 assignment2 assignedVariable usedVariable |
90-
self skip. "Todo"
89+
| assignment assignedVariable usedVariable |
9190
self parseAndResolve: 'fruits = ["apple", "banana", "cherry"]
9291
for x in fruits:
93-
print(x)'.
92+
pass'.
9493

95-
assignment1 := model module statements first.
96-
assignedVariable := assignment1 left.
97-
self assert: assignedVariable localDeclaration equals: assignment1.
98-
self assert: assignedVariable localDeclaration left name equals: 'x'.
94+
assignment := model module statements first.
95+
assignedVariable := assignment left.
96+
self assert: assignedVariable localDeclaration equals: assignment.
97+
self assert: assignedVariable localDeclaration left name equals: 'fruits'.
9998
self deny: assignedVariable localDeclaration isNonLocalDeclaration.
10099
self assert: assignedVariable localDeclaration localUses size equals: 2.
101100

102-
assignment2 := model module statements second.
103-
assignedVariable := assignment2 left.
104-
self assert: assignedVariable localDeclaration equals: assignment1.
105-
self assert: assignedVariable equals: assignedVariable localDeclaration localUses first.
106-
107-
usedVariable := model module statements third.
108-
self assert: usedVariable localDeclaration equals: assignment1.
101+
usedVariable := model module statements second right.
102+
self assert: usedVariable localDeclaration equals: assignment.
109103
self assert: usedVariable equals: assignedVariable localDeclaration localUses second
110104
]
111105

112106
{ #category : 'tests' }
113107
FASTPythonLocalResolverTest >> testVariableOfFor [
114108

115109
| for declared usedVariable |
116-
self skip. "Todo"
117110
self parseAndResolve: 'for x in "banana":
118111
print(x)'.
119112

120113
for := model module statements first.
121114
declared := for left.
122115
self assert: declared localDeclaration equals: for.
123-
self assert: declared localDeclaration left name equals: 'x'.
116+
self assert: declared localDeclaration left sourceCode equals: 'x'.
124117
self deny: declared localDeclaration isNonLocalDeclaration.
125-
self assert: declared localDeclaration localUses size equals: 1.
118+
self assert: declared localDeclaration localUses size equals: 2.
119+
self assert: declared localDeclaration localUses first equals: declared.
126120

127121
usedVariable := for statements first arguments first.
128122
self assert: usedVariable localDeclaration equals: for.
129-
self assert: usedVariable equals: declared localDeclaration localUses first
123+
self assert: usedVariable equals: declared localDeclaration localUses second
130124
]

src/FAST-Python-Tools/FASTPythonLocalResolverVisitor.class.st

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ FASTPythonLocalResolverVisitor >> visitFASTPyForStatement: aForStatement [
4949

5050
{ #category : 'visiting' }
5151
FASTPythonLocalResolverVisitor >> visitFASTPyIdentifier: anIdentifier [
52-
"I define a variable in a for statement. Thus I need to create a new declaration"
5352

54-
self halt.
53+
| name |
54+
name := anIdentifier sourceCode.
55+
56+
"I define a variable in a for statement. Thus I need to create a new declaration"
5557
anIdentifier parentForStatementLeft ifNotNil: [ :forStatement |
56-
scoper scopeAdd: anIdentifier sourceCode declaration: forStatement.
58+
scoper scopeAdd: name declaration: forStatement.
5759
anIdentifier localDeclaration: forStatement ].
5860

59-
scoper bind: anIdentifier toLocalDeclaration: anIdentifier sourceCode
61+
scoper bind: anIdentifier toLocalDeclaration: name
6062
]
6163

6264
{ #category : 'visiting' }

0 commit comments

Comments
 (0)