Skip to content

Commit fd2c315

Browse files
committed
Refine implementation of assignment (WIP)
1 parent 36f4a03 commit fd2c315

8 files changed

Lines changed: 171 additions & 57 deletions

File tree

src/FAST-Python-Model-Generator/FASTPythonMetamodelGenerator.class.st

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ Class {
157157
'tAsPatternTarget',
158158
'tAsPatternSource',
159159
'tWithStatementItem',
160-
'tRaised'
160+
'tRaised',
161+
'tAssignable'
161162
],
162163
#category : 'FAST-Python-Model-Generator',
163164
#package : 'FAST-Python-Model-Generator'
@@ -322,7 +323,6 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
322323
asPattern --|> tWithStatementItem.
323324

324325
assignment --|> statement.
325-
assignment --|> tAssignment.
326326

327327
assertStatement --|> statement.
328328

@@ -534,6 +534,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
534534

535535
variable --|> expression.
536536
variable --|> tVariableEntity.
537+
variable --|> tAssignable.
537538

538539
whileStatement --|> statement.
539540
whileStatement --|> tConditionalStatement.
@@ -575,6 +576,9 @@ FASTPythonMetamodelGenerator >> defineRelations [
575576
super defineRelations.
576577

577578
(entity property: #genericChildren) <>-* (entity property: #genericParent).
579+
580+
(assignment property: #left) <>- (tAssignable property: #parentAssignmentLeft).
581+
(assignment property: #right) <>- (expression property: #parentAssignmentRight).
578582

579583
(asPattern property: #target) <>- (tAsPatternTarget property: #parentAsPatternTarget).
580584

@@ -703,6 +707,7 @@ FASTPythonMetamodelGenerator >> defineTraits [
703707
"FAST-Python"
704708
tAsPatternTarget := (builder newTraitNamed: #TAsPatternTarget) comment: 'I represent an entity that could be the alias/target of an as pattern.'.
705709
tAsPatternSource := (builder newTraitNamed: #TAsPatternSource) comment: 'I represent an entity that could be aliased in an as pattern.'.
710+
(tAssignable := builder newTraitNamed: #TAssignable) comment: 'I represent something that can be assigned in an assignment'.
706711
tCanBeSplatExpression := (builder newTraitNamed: #TCanBeSplatExpression) comment: 'My users are expressions that can be in a collection splat. For example in `[ *getList(), 3 ]`, we have a list splat on the call `getList()`. Get list, is the expression of the splat.'.
707712
tComprehension := builder newTraitNamed: #TComprehension.
708713
tDefinition := builder newTraitNamed: #TDefinition.

src/FAST-Python-Model/FASTPyAssignment.class.st

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,22 @@
22
## Relations
33
======================
44
5-
### Parents
6-
| Relation | Origin | Opposite | Type | Comment |
7-
|---|
8-
| `argumentOwner` | `FASTTExpression` | `arguments` | `FASTTWithArguments` | my owner|
9-
| `assignedIn` | `FASTTExpression` | `expression` | `FASTTAssignment` | Optional assignment where this expression is used|
10-
| `expressionStatementOwner` | `FASTTExpression` | `expression` | `FASTTExpressionStatement` | The expression statement that own me (if it's the case|
11-
| `parentConditional` | `FASTTExpression` | `condition` | `FASTTWithCondition` | Optional condition statement/expression where this expression is used|
12-
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
13-
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
14-
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
15-
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
16-
175
### Children
186
| Relation | Origin | Opposite | Type | Comment |
197
|---|
20-
| `expression` | `FASTTAssignment` | `assignedIn` | `FASTTExpression` | Assigned expression (rhs of assignment)|
21-
| `variable` | `FASTTAssignment` | `parentAssignmentExpression` | `FASTTVariableEntity` | An assigned variable (lhs of assignment)|
8+
| `left` | `FASTPyAssignment` | `parentAssignmentLeft` | `FASTPyTAssignable` | |
9+
| `right` | `FASTPyAssignment` | `parentAssignmentRight` | `FASTPyExpression` | |
2210
2311
24-
## Properties
25-
======================
26-
27-
| Name | Type | Default value | Comment |
28-
|---|
29-
| `endPos` | `Number` | nil | |
30-
| `startPos` | `Number` | nil | |
3112
3213
"
3314
Class {
3415
#name : 'FASTPyAssignment',
3516
#superclass : 'FASTPyStatement',
36-
#traits : 'FASTTAssignment',
37-
#classTraits : 'FASTTAssignment classTrait',
17+
#instVars : [
18+
'#left => FMOne type: #FASTPyTAssignable opposite: #parentAssignmentLeft',
19+
'#right => FMOne type: #FASTPyExpression opposite: #parentAssignmentRight'
20+
],
3821
#category : 'FAST-Python-Model-Entities',
3922
#package : 'FAST-Python-Model',
4023
#tag : 'Entities'
@@ -48,3 +31,47 @@ FASTPyAssignment class >> annotation [
4831
<generated>
4932
^ self
5033
]
34+
35+
{ #category : 'accessing' }
36+
FASTPyAssignment >> left [
37+
"Relation named: #left type: #FASTPyTAssignable opposite: #parentAssignmentLeft"
38+
39+
<generated>
40+
^ left
41+
]
42+
43+
{ #category : 'accessing' }
44+
FASTPyAssignment >> left: anObject [
45+
46+
<generated>
47+
left := anObject
48+
]
49+
50+
{ #category : 'navigation' }
51+
FASTPyAssignment >> leftGroup [
52+
<generated>
53+
<navigation: 'Left'>
54+
^ MooseSpecializedGroup with: self left
55+
]
56+
57+
{ #category : 'accessing' }
58+
FASTPyAssignment >> right [
59+
"Relation named: #right type: #FASTPyExpression opposite: #parentAssignmentRight"
60+
61+
<generated>
62+
^ right
63+
]
64+
65+
{ #category : 'accessing' }
66+
FASTPyAssignment >> right: anObject [
67+
68+
<generated>
69+
right := anObject
70+
]
71+
72+
{ #category : 'navigation' }
73+
FASTPyAssignment >> rightGroup [
74+
<generated>
75+
<navigation: 'Right'>
76+
^ MooseSpecializedGroup with: self right
77+
]

src/FAST-Python-Model/FASTPyEntity.class.st

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@ FASTPyEntity >> hasImmediateSource [
120120
^ false
121121
]
122122

123-
{ #category : 'testing' }
124-
FASTPyEntity >> isAssignment [
125-
126-
<generated>
127-
^ false
128-
]
129-
130123
{ #category : 'testing' }
131124
FASTPyEntity >> isBehaviouralEntity [
132125

src/FAST-Python-Model/FASTPyExpression.class.st

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| `pairKeyOwner` | `FASTPyExpression` | `key` | `FASTPyPair` | |
2828
| `pairValueOwner` | `FASTPyExpression` | `value` | `FASTPyPair` | |
2929
| `parentAssertStatement` | `FASTPyExpression` | `expressions` | `FASTPyAssertStatement` | The assert statement that own the expression (if it's the case)|
30+
| `parentAssignmentRight` | `FASTPyExpression` | `right` | `FASTPyAssignment` | |
3031
| `parentAwait` | `FASTPyExpression` | `expression` | `FASTPyAwait` | |
3132
| `parentComparisonOperator` | `FASTPyExpression` | `operands` | `FASTPyComparisonOperator` | Parent comparison expression of which I am.|
3233
| `parentConditional` | `FASTTExpression` | `condition` | `FASTTWithCondition` | Optional condition statement/expression where this expression is used|
@@ -78,6 +79,7 @@ Class {
7879
'#pairKeyOwner => FMOne type: #FASTPyPair opposite: #key',
7980
'#pairValueOwner => FMOne type: #FASTPyPair opposite: #value',
8081
'#parentAssertStatement => FMOne type: #FASTPyAssertStatement opposite: #expressions',
82+
'#parentAssignmentRight => FMOne type: #FASTPyAssignment opposite: #right',
8183
'#parentAwait => FMOne type: #FASTPyAwait opposite: #expression',
8284
'#parentComparisonOperator => FMOne type: #FASTPyComparisonOperator opposite: #operands',
8385
'#parentInterpolation => FMOne type: #FASTPyInterpolation opposite: #expression',
@@ -563,6 +565,30 @@ FASTPyExpression >> parentAssertStatementGroup [
563565
^ MooseSpecializedGroup with: self parentAssertStatement
564566
]
565567

568+
{ #category : 'accessing' }
569+
FASTPyExpression >> parentAssignmentRight [
570+
"Relation named: #parentAssignmentRight type: #FASTPyAssignment opposite: #right"
571+
572+
<generated>
573+
<container>
574+
<derived>
575+
^ parentAssignmentRight
576+
]
577+
578+
{ #category : 'accessing' }
579+
FASTPyExpression >> parentAssignmentRight: anObject [
580+
581+
<generated>
582+
parentAssignmentRight := anObject
583+
]
584+
585+
{ #category : 'navigation' }
586+
FASTPyExpression >> parentAssignmentRightGroup [
587+
<generated>
588+
<navigation: 'ParentAssignmentRight'>
589+
^ MooseSpecializedGroup with: self parentAssignmentRight
590+
]
591+
566592
{ #category : 'accessing' }
567593
FASTPyExpression >> parentAwait [
568594
"Relation named: #parentAwait type: #FASTPyAwait opposite: #expression"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"
2+
I represent something that can be assigned in an assignment
3+
4+
## Relations
5+
======================
6+
7+
### Parents
8+
| Relation | Origin | Opposite | Type | Comment |
9+
|---|
10+
| `parentAssignmentLeft` | `FASTPyTAssignable` | `left` | `FASTPyAssignment` | |
11+
12+
13+
14+
"
15+
Trait {
16+
#name : 'FASTPyTAssignable',
17+
#instVars : [
18+
'#parentAssignmentLeft => FMOne type: #FASTPyAssignment opposite: #left'
19+
],
20+
#category : 'FAST-Python-Model-Traits',
21+
#package : 'FAST-Python-Model',
22+
#tag : 'Traits'
23+
}
24+
25+
{ #category : 'meta' }
26+
FASTPyTAssignable classSide >> annotation [
27+
28+
<FMClass: #TAssignable super: #Object>
29+
<package: #'FAST-Python-Model'>
30+
<generated>
31+
^ self
32+
]
33+
34+
{ #category : 'accessing' }
35+
FASTPyTAssignable >> parentAssignmentLeft [
36+
"Relation named: #parentAssignmentLeft type: #FASTPyAssignment opposite: #left"
37+
38+
<generated>
39+
<container>
40+
<derived>
41+
^ parentAssignmentLeft
42+
]
43+
44+
{ #category : 'accessing' }
45+
FASTPyTAssignable >> parentAssignmentLeft: anObject [
46+
47+
<generated>
48+
parentAssignmentLeft := anObject
49+
]
50+
51+
{ #category : 'navigation' }
52+
FASTPyTAssignable >> parentAssignmentLeftGroup [
53+
<generated>
54+
<navigation: 'ParentAssignmentLeft'>
55+
^ MooseSpecializedGroup with: self parentAssignmentLeft
56+
]

src/FAST-Python-Model/FASTPyVariable.class.st

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| `nonlocalOwner` | `FASTPyVariable` | `variables` | `FASTPyNonlocalStatement` | The global statement defining my scope (if it's the case)|
1212
| `parameterOwner` | `FASTTVariableEntity` | `parameters` | `FASTTWithParameters` | parameterOwner|
1313
| `parentAssignmentExpression` | `FASTTVariableEntity` | `variable` | `FASTTAssignment` | Optional assignment to the variable|
14+
| `parentAssignmentLeft` | `FASTPyTAssignable` | `left` | `FASTPyAssignment` | |
1415
1516
1617
## Properties
@@ -26,8 +27,8 @@
2627
Class {
2728
#name : 'FASTPyVariable',
2829
#superclass : 'FASTPyExpression',
29-
#traits : 'FASTTVariableEntity',
30-
#classTraits : 'FASTTVariableEntity classTrait',
30+
#traits : 'FASTPyTAssignable + FASTTVariableEntity',
31+
#classTraits : 'FASTPyTAssignable classTrait + FASTTVariableEntity classTrait',
3132
#instVars : [
3233
'#attributeOwner => FMOne type: #FASTPyAttributeAccess opposite: #attribute',
3334
'#globalOwner => FMOne type: #FASTPyGlobalStatement opposite: #variables',

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -835,23 +835,41 @@ FASTPythonImporterTest >> testAssertStatementWithConcatenatedString [
835835
self assert: (self topEntity isOfType: FASTTStringLiteral)
836836
]
837837

838-
{ #category : 'tests' }
838+
{ #category : 'tests - assignment' }
839839
FASTPythonImporterTest >> testAssignment [
840+
<generated>
841+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
842+
Regenerate executing: self regenerateTest: #testAssignment "
840843

841-
| assignment |
842844
self parse: 'x = 1'.
843845

844-
self assert: (fast allWithType: FASTPyModule) size equals: 1.
845846
self assert: (fast allWithType: FASTPyAssignment) size equals: 1.
847+
self assert: (fast allWithType: FASTPyInteger) size equals: 1.
848+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
849+
self assert: (fast allWithType: FASTPyVariable) size equals: 1.
850+
851+
stack push: fast rootEntities anyOne containedEntities first.
852+
self assert: self topEntity sourceCode equals: 'x = 1'.
853+
self assert: (self topEntity isOfType: FASTPyAssignment).
854+
855+
"Testing value of monovalue relation left"
856+
self assert: self topEntity left isNotNil.
857+
858+
stack push: self topEntity left.
859+
self assert: self topEntity sourceCode equals: 'x'.
860+
self assert: (self topEntity isOfType: FASTPyVariable).
861+
self assert: (self topEntity isOfType: FASTPyTAssignable).
862+
self assert: (self topEntity isOfType: FASTTVariableEntity).
863+
stack pop.
864+
865+
"Testing value of monovalue relation right"
866+
self assert: self topEntity right isNotNil.
846867

847-
assignment := (fast allWithType: FASTPyAssignment) anyOne.
848-
self assert: assignment sourceCode equals: 'x = 1'.
849-
self assert: (assignment isOfType: FASTTAssignment).
850-
self skip. "TODO"
851-
self assert: assignment variable sourceCode equals: 'x'.
852-
self assert: assignment expression sourceCode equals: '1'.
853-
self assert: (assignment variable isOfType: FASTPyVariable).
854-
self assert: (assignment expression isOfType: FASTPyInteger)
868+
stack push: self topEntity right.
869+
self assert: self topEntity sourceCode equals: '1'.
870+
self assert: (self topEntity isOfType: FASTPyInteger).
871+
self assert: (self topEntity isOfType: FASTTLiteral).
872+
self assert: (self topEntity isOfType: FASTTNumericalLiteral)
855873
]
856874

857875
{ #category : 'tests - accesses' }

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,6 @@ TSFASTPythonImporter >> visitAssertStatement: aTSNode [
7777
^ self handleNode: aTSNode kind: FASTPyAssertStatement
7878
]
7979

80-
{ #category : 'visiting - alias' }
81-
TSFASTPythonImporter >> visitAssignment: aTSNode [
82-
83-
self onNextContextDo: [ :entry |
84-
self flag: #todo.
85-
entry
86-
"add: 'variable' asAliasOfField: 'left';"
87-
add: 'expression' asAliasOfField: 'right' ].
88-
89-
^ self handleNode: aTSNode
90-
]
91-
9280
{ #category : 'visiting' }
9381
TSFASTPythonImporter >> visitAttribute: aTSNode [
9482

0 commit comments

Comments
 (0)