Skip to content

Commit 21bfea9

Browse files
committed
Begin to manage comprehensions
1 parent 76a9525 commit 21bfea9

9 files changed

Lines changed: 493 additions & 23 deletions

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ Class {
148148
'tLoopStatement',
149149
'statement',
150150
'tWithStatements',
151-
'tNumericalLiteral'
151+
'tNumericalLiteral',
152+
'tComprehension'
152153
],
153154
#category : 'FAST-Python-Model-Generator',
154155
#package : 'FAST-Python-Model-Generator'
@@ -369,12 +370,19 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
369370

370371
float --|> literal.
371372
float --|> tNumericalLiteral.
373+
374+
forInClause --|> expression. "This is wrong! I am just here temporarily until we rework the relation to the for in clause (I need to be able to be a clause of a list comprehension)"
372375

373376
forStatement --|> statement.
374377
forStatement --|> tLoopStatement.
375378

376379
functionDefinition --|> tNamedBehaviouralEntity.
377380

381+
generatorExpression --|> expression.
382+
generatorExpression --|> tComprehension.
383+
384+
globalStatement --|> statement.
385+
378386
identifier --|> expression.
379387

380388
ifStatement --|> statement.
@@ -389,43 +397,45 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
389397

390398
keywordArgument --|> expression.
391399
keywordArgument --|> tNamedEntity.
392-
393-
globalStatement --|> statement.
394-
400+
395401
list --|> collectionInitializer.
402+
403+
listComprehension --|> expression.
404+
listComprehension --|> tComprehension.
396405

397406
literal --|> expression.
398407
literal --|> tLiteral.
399-
400-
none --|> literal.
401-
402-
nonlocalStatement --|> statement.
403-
404-
pair --|> expression.
405-
406-
parameter --|> tVariableEntity.
407-
408-
passStatement --|> statement.
409408

410409
listSplat --|> expression.
411410

412411
methodDefinition --|> tNamedBehaviouralEntity.
413412

414413
module --|> block. "A Module has statements."
415414
module --|> #THasImmediateSource.
415+
416+
none --|> literal.
416417

418+
nonlocalStatement --|> statement.
419+
417420
notOperator --|> operator.
418421
notOperator --|> tUnaryOperator.
419422

420423
operator --|> expression.
421424

422425
pair --|> expression.
423426

427+
parameter --|> tVariableEntity.
428+
429+
passStatement --|> statement.
430+
424431
returnStatement --|> statement.
425432
returnStatement --|> tReturnStatement.
426433

427434
set --|> collectionInitializer.
428435

436+
setComprehension --|> expression.
437+
setComprehension --|> tComprehension.
438+
429439
slice --|> expression.
430440

431441
statement --|> tStatement.
@@ -508,7 +518,7 @@ FASTPythonMetamodelGenerator >> defineRelations [
508518
(expressionList property: #expressions) <>-* (expression property: #expressionListOwner).
509519

510520
(forInClause property: #left) <>- (expression property: #forInClauseLeftOwner).
511-
521+
512522
(forInClause property: #right) <>- (expression property: #forInClauseRightOwner).
513523

514524
((forStatement property: #right) comment: 'The list that the for statement iterates over')
@@ -554,6 +564,10 @@ FASTPythonMetamodelGenerator >> defineRelations [
554564
((subscript property: #indices) comment: 'The elements defining the indices to select in a subscript.')
555565
<>-* ((expression property: #subscriptIndiceOwner) comment: 'My parent if I am defining an index to select of a subscript (if it''s the case)').
556566

567+
(tComprehension property: #body) <>- (expression property: #comprehensionBodyOwner).
568+
569+
(tComprehension property: #clause) <>- (expression property: #comprehensionClauseOwner).
570+
557571
((tUnaryOperator property: #argument) comment: 'Expression influanced by the unary operator..')
558572
<>- ((expression property: #parentUnaryOperator) comment: 'Parent unary operator in which I am.')
559573
]
@@ -567,6 +581,7 @@ FASTPythonMetamodelGenerator >> defineTraits [
567581
tEntity := self remoteTrait: #TEntity withPrefix: #FAST.
568582

569583
"FAST-Python"
584+
tComprehension := builder newTraitNamed: #TComprehension.
570585
tUnaryOperator := builder newTraitNamed: #TUnaryOperator.
571586

572587
"Remotes"

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
| `attributeObjectOwner` | `FASTPyExpression` | `object` | `FASTPyAttributeAccess` | My parent if I define the object of an attribute access (if it's the case).|
1212
| `caller` | `FASTPyExpression` | `callee` | `FASTPyCall` | The call entity calling me (if it's the case)|
1313
| `collectionInitializer` | `FASTPyExpression` | `initializers` | `FASTPyCollectionInitializer` | The owner of the expression|
14+
| `comprehensionBodyOwner` | `FASTPyExpression` | `body` | `FASTPyTComprehension` | |
15+
| `comprehensionClauseOwner` | `FASTPyExpression` | `clause` | `FASTPyTComprehension` | |
1416
| `deleteOwner` | `FASTPyExpression` | `expression` | `FASTPyDeleteStatement` | The delete statement that own the expression (if it's the case)|
1517
| `expressionListOwner` | `FASTPyExpression` | `expressions` | `FASTPyExpressionList` | |
1618
| `expressionStatementOwner` | `FASTTExpression` | `expression` | `FASTTExpressionStatement` | The expression statement that own me (if it's the case|
@@ -53,6 +55,8 @@ Class {
5355
'#attributeObjectOwner => FMOne type: #FASTPyAttributeAccess opposite: #object',
5456
'#caller => FMOne type: #FASTPyCall opposite: #callee',
5557
'#collectionInitializer => FMOne type: #FASTPyCollectionInitializer opposite: #initializers',
58+
'#comprehensionBodyOwner => FMOne type: #FASTPyTComprehension opposite: #body',
59+
'#comprehensionClauseOwner => FMOne type: #FASTPyTComprehension opposite: #clause',
5660
'#deleteOwner => FMOne type: #FASTPyDeleteStatement opposite: #expression',
5761
'#expressionListOwner => FMOne type: #FASTPyExpressionList opposite: #expressions',
5862
'#forInClauseLeftOwner => FMOne type: #FASTPyForInClause opposite: #left',
@@ -180,6 +184,54 @@ FASTPyExpression >> collectionInitializerGroup [
180184
^ MooseSpecializedGroup with: self collectionInitializer
181185
]
182186

187+
{ #category : 'accessing' }
188+
FASTPyExpression >> comprehensionBodyOwner [
189+
"Relation named: #comprehensionBodyOwner type: #FASTPyTComprehension opposite: #body"
190+
191+
<generated>
192+
<container>
193+
<derived>
194+
^ comprehensionBodyOwner
195+
]
196+
197+
{ #category : 'accessing' }
198+
FASTPyExpression >> comprehensionBodyOwner: anObject [
199+
200+
<generated>
201+
comprehensionBodyOwner := anObject
202+
]
203+
204+
{ #category : 'navigation' }
205+
FASTPyExpression >> comprehensionBodyOwnerGroup [
206+
<generated>
207+
<navigation: 'ComprehensionBodyOwner'>
208+
^ MooseSpecializedGroup with: self comprehensionBodyOwner
209+
]
210+
211+
{ #category : 'accessing' }
212+
FASTPyExpression >> comprehensionClauseOwner [
213+
"Relation named: #comprehensionClauseOwner type: #FASTPyTComprehension opposite: #clause"
214+
215+
<generated>
216+
<container>
217+
<derived>
218+
^ comprehensionClauseOwner
219+
]
220+
221+
{ #category : 'accessing' }
222+
FASTPyExpression >> comprehensionClauseOwner: anObject [
223+
224+
<generated>
225+
comprehensionClauseOwner := anObject
226+
]
227+
228+
{ #category : 'navigation' }
229+
FASTPyExpression >> comprehensionClauseOwnerGroup [
230+
<generated>
231+
<navigation: 'ComprehensionClauseOwner'>
232+
^ MooseSpecializedGroup with: self comprehensionClauseOwner
233+
]
234+
183235
{ #category : 'accessing' }
184236
FASTPyExpression >> deleteOwner [
185237
"Relation named: #deleteOwner type: #FASTPyDeleteStatement opposite: #expression"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"
1414
Class {
1515
#name : 'FASTPyForInClause',
16-
#superclass : 'FASTPyEntity',
16+
#superclass : 'FASTPyExpression',
1717
#instVars : [
1818
'#left => FMOne type: #FASTPyExpression opposite: #forInClauseLeftOwner',
1919
'#right => FMOne type: #FASTPyExpression opposite: #forInClauseRightOwner'
@@ -26,7 +26,7 @@ Class {
2626
{ #category : 'meta' }
2727
FASTPyForInClause class >> annotation [
2828

29-
<FMClass: #ForInClause super: #FASTPyEntity>
29+
<FMClass: #ForInClause super: #FASTPyExpression>
3030
<package: #'FAST-Python-Model'>
3131
<generated>
3232
^ self

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `body` | `FASTPyTComprehension` | `comprehensionBodyOwner` | `FASTPyExpression` | |
9+
| `clause` | `FASTPyTComprehension` | `comprehensionClauseOwner` | `FASTPyExpression` | |
10+
11+
12+
13+
"
114
Class {
215
#name : 'FASTPyGeneratorExpression',
3-
#superclass : 'FASTPyEntity',
16+
#superclass : 'FASTPyExpression',
17+
#traits : 'FASTPyTComprehension',
18+
#classTraits : 'FASTPyTComprehension classTrait',
419
#category : 'FAST-Python-Model-Entities',
520
#package : 'FAST-Python-Model',
621
#tag : 'Entities'
@@ -9,7 +24,7 @@ Class {
924
{ #category : 'meta' }
1025
FASTPyGeneratorExpression class >> annotation [
1126

12-
<FMClass: #GeneratorExpression super: #FASTPyEntity>
27+
<FMClass: #GeneratorExpression super: #FASTPyExpression>
1328
<package: #'FAST-Python-Model'>
1429
<generated>
1530
^ self

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `body` | `FASTPyTComprehension` | `comprehensionBodyOwner` | `FASTPyExpression` | |
9+
| `clause` | `FASTPyTComprehension` | `comprehensionClauseOwner` | `FASTPyExpression` | |
10+
11+
12+
13+
"
114
Class {
215
#name : 'FASTPyListComprehension',
3-
#superclass : 'FASTPyEntity',
16+
#superclass : 'FASTPyExpression',
17+
#traits : 'FASTPyTComprehension',
18+
#classTraits : 'FASTPyTComprehension classTrait',
419
#category : 'FAST-Python-Model-Entities',
520
#package : 'FAST-Python-Model',
621
#tag : 'Entities'
@@ -9,7 +24,7 @@ Class {
924
{ #category : 'meta' }
1025
FASTPyListComprehension class >> annotation [
1126

12-
<FMClass: #ListComprehension super: #FASTPyEntity>
27+
<FMClass: #ListComprehension super: #FASTPyExpression>
1328
<package: #'FAST-Python-Model'>
1429
<generated>
1530
^ self

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `body` | `FASTPyTComprehension` | `comprehensionBodyOwner` | `FASTPyExpression` | |
9+
| `clause` | `FASTPyTComprehension` | `comprehensionClauseOwner` | `FASTPyExpression` | |
10+
11+
12+
13+
"
114
Class {
215
#name : 'FASTPySetComprehension',
3-
#superclass : 'FASTPyEntity',
16+
#superclass : 'FASTPyExpression',
17+
#traits : 'FASTPyTComprehension',
18+
#classTraits : 'FASTPyTComprehension classTrait',
419
#category : 'FAST-Python-Model-Entities',
520
#package : 'FAST-Python-Model',
621
#tag : 'Entities'
@@ -9,7 +24,7 @@ Class {
924
{ #category : 'meta' }
1025
FASTPySetComprehension class >> annotation [
1126

12-
<FMClass: #SetComprehension super: #FASTPyEntity>
27+
<FMClass: #SetComprehension super: #FASTPyExpression>
1328
<package: #'FAST-Python-Model'>
1429
<generated>
1530
^ self
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `body` | `FASTPyTComprehension` | `comprehensionBodyOwner` | `FASTPyExpression` | |
9+
| `clause` | `FASTPyTComprehension` | `comprehensionClauseOwner` | `FASTPyExpression` | |
10+
11+
12+
13+
"
14+
Trait {
15+
#name : 'FASTPyTComprehension',
16+
#instVars : [
17+
'#body => FMOne type: #FASTPyExpression opposite: #comprehensionBodyOwner',
18+
'#clause => FMOne type: #FASTPyExpression opposite: #comprehensionClauseOwner'
19+
],
20+
#category : 'FAST-Python-Model-Traits',
21+
#package : 'FAST-Python-Model',
22+
#tag : 'Traits'
23+
}
24+
25+
{ #category : 'meta' }
26+
FASTPyTComprehension classSide >> annotation [
27+
28+
<FMClass: #TComprehension super: #Object>
29+
<package: #'FAST-Python-Model'>
30+
<generated>
31+
^ self
32+
]
33+
34+
{ #category : 'accessing' }
35+
FASTPyTComprehension >> body [
36+
"Relation named: #body type: #FASTPyExpression opposite: #comprehensionBodyOwner"
37+
38+
<generated>
39+
^ body
40+
]
41+
42+
{ #category : 'accessing' }
43+
FASTPyTComprehension >> body: anObject [
44+
45+
<generated>
46+
body := anObject
47+
]
48+
49+
{ #category : 'navigation' }
50+
FASTPyTComprehension >> bodyGroup [
51+
<generated>
52+
<navigation: 'Body'>
53+
^ MooseSpecializedGroup with: self body
54+
]
55+
56+
{ #category : 'accessing' }
57+
FASTPyTComprehension >> clause [
58+
"Relation named: #clause type: #FASTPyExpression opposite: #comprehensionClauseOwner"
59+
60+
<generated>
61+
^ clause
62+
]
63+
64+
{ #category : 'accessing' }
65+
FASTPyTComprehension >> clause: anObject [
66+
67+
<generated>
68+
clause := anObject
69+
]
70+
71+
{ #category : 'navigation' }
72+
FASTPyTComprehension >> clauseGroup [
73+
<generated>
74+
<navigation: 'Clause'>
75+
^ MooseSpecializedGroup with: self clause
76+
]

0 commit comments

Comments
 (0)