Skip to content

Commit e308d57

Browse files
committed
Start to manage assigment (WIP)
1 parent cc9ff30 commit e308d57

10 files changed

Lines changed: 181 additions & 17 deletions

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ Class {
137137
'expression',
138138
'tBinaryExpression',
139139
'operator',
140-
'tUnaryOperator'
140+
'tUnaryOperator',
141+
'tAssignment',
142+
'variable',
143+
'structuralEntity'
141144
],
142145
#category : 'FAST-Python-Model-Generator',
143146
#package : 'FAST-Python-Model-Generator'
@@ -171,8 +174,8 @@ FASTPythonMetamodelGenerator >> defineClasses [
171174
asPattern := builder ensureClassNamed: #AsPattern."Todo"
172175
asPatternTarget := builder ensureClassNamed: #AsPatternTarget."Todo"
173176
assertStatement := builder ensureClassNamed: #AssertStatement."Todo"
174-
assignment := builder ensureClassNamed: #Assignment."Todo"
175-
attribute := builder ensureClassNamed: #Attribute."Todo"
177+
assignment := builder ensureClassNamed: #Assignment."To review"
178+
attribute := builder ensureClassNamed: #Attribute."To review"
176179
augmentedAssignment := builder ensureClassNamed: #AugmentedAssignment."Todo"
177180
await := builder ensureClassNamed: #Await."Todo"
178181
binaryOperator := builder ensureClassNamed: #BinaryOperator.
@@ -270,6 +273,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
270273
splatPattern := builder ensureClassNamed: #SplatPattern."Todo"
271274
splatType := builder ensureClassNamed: #SplatType."Todo"
272275
string := builder ensureClassNamed: #String.
276+
structuralEntity := builder ensureClassNamed: #StructuralEntity.
273277
subscript := builder ensureClassNamed: #Subscript."Todo"
274278
tryStatement := builder ensureClassNamed: #TryStatement."Todo"
275279
tuple := builder ensureClassNamed: #Tuple."Todo"
@@ -284,6 +288,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
284288
unaryOperator := builder ensureClassNamed: #UnaryOperator.
285289
unionPattern := builder ensureClassNamed: #UnionPattern."Todo"
286290
unionType := builder ensureClassNamed: #UnionType."Todo"
291+
variable := builder ensureClassNamed: #Variable. "To review"
287292
whileStatement := builder ensureClassNamed: #WhileStatement."Todo"
288293
wildcardImport := builder ensureClassNamed: #WildcardImport."Todo"
289294
withClause := builder ensureClassNamed: #WithClause."Todo"
@@ -302,6 +307,10 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
302307
self flag: #todo. "The next line is WRONG and NEEDS to be reviewed but we currently need it because else everything will break until the MM is in a better state."
303308
entity --|> tExpression.
304309

310+
assignment --|> tAssignment.
311+
312+
attribute --|> structuralEntity.
313+
305314
booleanOperator --|> operator.
306315
booleanOperator --|> tBinaryExpression. "I am not 100% sure this is the best trait to use but it seems to work well for now"
307316

@@ -332,7 +341,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
332341

333342
none --|> literal.
334343

335-
parameter --|> tVariableEntity.
344+
parameter --|> structuralEntity.
336345

337346
methodDefinition --|> tNamedBehaviouralEntity.
338347

@@ -346,8 +355,12 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
346355
string --|> literal.
347356
string --|> tStringLiteral.
348357

358+
structuralEntity --|> tVariableEntity.
359+
349360
unaryOperator --|> operator.
350-
unaryOperator --|> tUnaryOperator
361+
unaryOperator --|> tUnaryOperator.
362+
363+
variable --|> structuralEntity
351364
]
352365

353366
{ #category : 'definition' }
@@ -383,13 +396,14 @@ FASTPythonMetamodelGenerator >> defineRelations [
383396
FASTPythonMetamodelGenerator >> defineTraits [
384397

385398
super defineTraits.
386-
399+
387400
"From FAST"
388401
tEntity := self remoteTrait: #TEntity withPrefix: #FAST.
389-
390-
402+
403+
391404
tUnaryOperator := builder newTraitNamed: #TUnaryOperator.
392405

406+
tAssignment := self remoteTrait: #TAssignment withPrefix: #FAST.
393407
tBinaryExpression := self remoteTrait: #TBinaryExpression withPrefix: #FAST.
394408
tBooleanLiteral := self remoteTrait: #TBooleanLiteral withPrefix: #FAST.
395409
tComment := self remoteTrait: #TComment withPrefix: #FAST.
@@ -398,5 +412,5 @@ FASTPythonMetamodelGenerator >> defineTraits [
398412
tNamedBehaviouralEntity := self remoteTrait: #TNamedBehaviouralEntity withPrefix: #FAST.
399413
tNamedEntity := self remoteTrait: #TNamedEntity withPrefix: #FAST.
400414
tStringLiteral := self remoteTrait: #TStringLiteral withPrefix: #FAST.
401-
tVariableEntity := self remoteTrait: #TVariableEntity withPrefix: #FAST.
415+
tVariableEntity := self remoteTrait: #TVariableEntity withPrefix: #FAST
402416
]

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
1+
"
2+
## Relations
3+
======================
4+
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+
| `parentComparisonOperator` | `FASTTExpression` | `operands` | `FASTPyComparisonOperator` | Parent comparison expression of which I am.|
12+
| `parentConditionalStatement` | `FASTTExpression` | `condition` | `FASTTConditionalStatement` | Optional condition statement where this expression is used|
13+
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
14+
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
15+
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
16+
| `parentUnaryOperator` | `FASTTExpression` | `argument` | `FASTPyTUnaryOperator` | Parent unary operator in which I am.|
17+
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
18+
19+
### Children
20+
| Relation | Origin | Opposite | Type | Comment |
21+
|---|
22+
| `expression` | `FASTTAssignment` | `assignedIn` | `FASTTExpression` | Assigned expression (rhs of assignment)|
23+
| `variable` | `FASTTAssignment` | `parentAssignmentExpression` | `FASTTVariableEntity` | An assigned variable (lhs of assignment)|
24+
25+
26+
## Properties
27+
======================
28+
29+
| Name | Type | Default value | Comment |
30+
|---|
31+
| `endPos` | `Number` | nil | |
32+
| `startPos` | `Number` | nil | |
33+
34+
"
135
Class {
236
#name : 'FASTPyAssignment',
337
#superclass : 'FASTPyEntity',
38+
#traits : 'FASTTAssignment',
39+
#classTraits : 'FASTTAssignment classTrait',
440
#category : 'FAST-Python-Model-Entities',
541
#package : 'FAST-Python-Model',
642
#tag : 'Entities'

‎src/FAST-Python-Model/FASTPyAttribute.class.st‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Class {
22
#name : 'FASTPyAttribute',
3-
#superclass : 'FASTPyEntity',
3+
#superclass : 'FASTPyStructuralEntity',
44
#category : 'FAST-Python-Model-Entities',
55
#package : 'FAST-Python-Model',
66
#tag : 'Entities'
@@ -9,7 +9,7 @@ Class {
99
{ #category : 'meta' }
1010
FASTPyAttribute class >> annotation [
1111

12-
<FMClass: #Attribute super: #FASTPyEntity>
12+
<FMClass: #Attribute super: #FASTPyStructuralEntity>
1313
<package: #'FAST-Python-Model'>
1414
<generated>
1515
^ self

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ FASTPyEntity >> genericParentGroup [
122122
^ MooseSpecializedGroup with: self genericParent
123123
]
124124

125+
{ #category : 'testing' }
126+
FASTPyEntity >> isAssignment [
127+
128+
<generated>
129+
^ false
130+
]
131+
125132
{ #category : 'testing' }
126133
FASTPyEntity >> isBehaviouralEntity [
127134

‎src/FAST-Python-Model/FASTPyParameter.class.st‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"
2323
Class {
2424
#name : 'FASTPyParameter',
25-
#superclass : 'FASTPyEntity',
26-
#traits : 'FASTTVariableEntity',
27-
#classTraits : 'FASTTVariableEntity classTrait',
25+
#superclass : 'FASTPyStructuralEntity',
2826
#category : 'FAST-Python-Model-Entities',
2927
#package : 'FAST-Python-Model',
3028
#tag : 'Entities'
@@ -33,7 +31,7 @@ Class {
3331
{ #category : 'meta' }
3432
FASTPyParameter class >> annotation [
3533

36-
<FMClass: #Parameter super: #FASTPyEntity>
34+
<FMClass: #Parameter super: #FASTPyStructuralEntity>
3735
<package: #'FAST-Python-Model'>
3836
<generated>
3937
^ self
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `invokedIn` | `FASTTNamedEntity` | `invoked` | `FASTTInvocation` | Optional invocation where this name is used|
9+
| `parameterOwner` | `FASTTVariableEntity` | `parameters` | `FASTTWithParameters` | parameterOwner|
10+
| `parentAssignmentExpression` | `FASTTVariableEntity` | `variable` | `FASTTAssignment` | Optional assignment to the variable|
11+
12+
13+
## Properties
14+
======================
15+
16+
| Name | Type | Default value | Comment |
17+
|---|
18+
| `endPos` | `Number` | nil | |
19+
| `name` | `String` | nil | |
20+
| `startPos` | `Number` | nil | |
21+
22+
"
23+
Class {
24+
#name : 'FASTPyStructuralEntity',
25+
#superclass : 'FASTPyEntity',
26+
#traits : 'FASTTVariableEntity',
27+
#classTraits : 'FASTTVariableEntity classTrait',
28+
#category : 'FAST-Python-Model-Entities',
29+
#package : 'FAST-Python-Model',
30+
#tag : 'Entities'
31+
}
32+
33+
{ #category : 'meta' }
34+
FASTPyStructuralEntity class >> annotation [
35+
36+
<FMClass: #StructuralEntity super: #FASTPyEntity>
37+
<package: #'FAST-Python-Model'>
38+
<generated>
39+
^ self
40+
]

‎src/FAST-Python-Model/FASTPyTEntityCreator.trait.st‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,13 @@ FASTPyTEntityCreator >> newString [
748748
^ self add: FASTPyString new
749749
]
750750

751+
{ #category : 'entity creation' }
752+
FASTPyTEntityCreator >> newStructuralEntity [
753+
754+
<generated>
755+
^ self add: FASTPyStructuralEntity new
756+
]
757+
751758
{ #category : 'entity creation' }
752759
FASTPyTEntityCreator >> newSubscript [
753760

@@ -846,6 +853,13 @@ FASTPyTEntityCreator >> newUnionType [
846853
^ self add: FASTPyUnionType new
847854
]
848855

856+
{ #category : 'entity creation' }
857+
FASTPyTEntityCreator >> newVariable [
858+
859+
<generated>
860+
^ self add: FASTPyVariable new
861+
]
862+
849863
{ #category : 'entity creation' }
850864
FASTPyTEntityCreator >> newWhileStatement [
851865

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Class {
2+
#name : 'FASTPyVariable',
3+
#superclass : 'FASTPyStructuralEntity',
4+
#category : 'FAST-Python-Model-Entities',
5+
#package : 'FAST-Python-Model',
6+
#tag : 'Entities'
7+
}
8+
9+
{ #category : 'meta' }
10+
FASTPyVariable class >> annotation [
11+
12+
<FMClass: #Variable super: #FASTPyStructuralEntity>
13+
<package: #'FAST-Python-Model'>
14+
<generated>
15+
^ self
16+
]

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ FASTPythonImporterTest >> setUp [
2626
importer := FASTPythonImporter new
2727
]
2828

29+
{ #category : 'tests' }
30+
FASTPythonImporterTest >> testAssignment [
31+
32+
| assignment |
33+
self parse: 'x = 1'.
34+
35+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
36+
self assert: (fast allWithType: FASTPyAssignment) size equals: 1.
37+
38+
assignment := (fast allWithType: FASTPyAssignment) anyOne.
39+
self assert: assignment sourceCode equals: 'x = 1'.
40+
self assert: (assignment isOfType: FASTTAssignment).
41+
self assert: assignment variable sourceCode equals: 'x'.
42+
self assert: assignment expression sourceCode equals: '1'.
43+
self assert: (assignment variable isOfType: FASTPyVariable).
44+
self assert: (assignment expression isOfType: FASTPyInteger)
45+
]
46+
2947
{ #category : 'tests - opererators' }
3048
FASTPythonImporterTest >> testBinaryOperator [
3149

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ TSFASTPythonImporter >> manageBinaryOperator: aTSNode ofKind: aClass [
3232
^ fastEntity
3333
]
3434

35+
{ #category : 'visiting' }
36+
TSFASTPythonImporter >> visitAssignment: aTSNode [
37+
38+
| fastEntity |
39+
fastEntity := self instantiateFastEntity: FASTPyAssignment from: aTSNode.
40+
41+
self setParentOf: fastEntity.
42+
43+
self pushContext: fastEntity node: aTSNode during: [
44+
context top add: 'variable' asAliasOfField: 'left'.
45+
context top add: 'expression' asAliasOfField: 'right'.
46+
self visitChildren: aTSNode in: fastEntity ].
47+
48+
^ fastEntity
49+
]
50+
3551
{ #category : 'visiting' }
3652
TSFASTPythonImporter >> visitBinaryOperator: aTSNode [
3753

@@ -83,8 +99,13 @@ TSFASTPythonImporter >> visitFunctionDefinition: aNode [
8399
TSFASTPythonImporter >> visitIdentifier: aNode [
84100

85101
"If we are in a field `name` then we are probably in a definition of an entity and we set my content as a name."
86-
(context anySatisfy: [ :entry | entry field = #name and: [ #( 'function_definition' 'class_definition' ) includes: entry tsNode type ] ]) ifTrue: [
87-
^ self topFastEntity name: (self sourceCodeOf: aNode) ].
102+
(context anySatisfy: [ :entry |
103+
entry field = #name and: [
104+
{ FASTPyMethodDefinition. FASTPyClassDefinition. FASTPyFunctionDefinition } anySatisfy: [ :class | entry isOfFASTType: class ] ] ]) ifTrue: [ ^ self topFastEntity name: (self sourceCodeOf: aNode) ].
105+
106+
"If I am on the left side of an assignation then I am a variable."
107+
(context anySatisfy: [ :entry | entry field = #left and: [ entry isOfFASTType: FASTPyAssignment ] ]) ifTrue: [
108+
^ self createEntityForNode: aNode kind: FASTPyVariable ].
88109

89110
^ self createEntityForNode: aNode
90111
]

0 commit comments

Comments
 (0)