Skip to content

Commit d7b844f

Browse files
committed
Start to manage all cases of if statement
1 parent 71ff74a commit d7b844f

9 files changed

Lines changed: 754 additions & 50 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ Class {
145145
'tStatement',
146146
'collectionInitializer',
147147
'tConditionalStatement',
148-
'complex'
148+
'complex',
149+
'thenClause'
149150
],
150151
#category : 'FAST-Python-Model-Generator',
151152
#package : 'FAST-Python-Model-Generator'
@@ -281,6 +282,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
281282
string := builder ensureClassNamed: #String.
282283
structuralEntity := builder ensureClassNamed: #StructuralEntity.
283284
subscript := builder ensureClassNamed: #Subscript."Todo"
285+
thenClause := builder ensureClassNamed: #ThenClause.
284286
tryStatement := builder ensureClassNamed: #TryStatement."Todo"
285287
tuple := builder ensureClassNamed: #Tuple."To Review"
286288
tupleExpression := builder ensureClassNamed: #TupleExpression."Todo"
@@ -346,6 +348,11 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
346348

347349
dictionary --|> collectionInitializer.
348350

351+
elseClause --|> block.
352+
353+
elifClause --|> block.
354+
elifClause --|> tConditionalStatement.
355+
349356
expression --|> tExpression.
350357
expression --|> tStatement. "In python expressions can be statements"
351358

@@ -402,6 +409,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
402409

403410
structuralEntity --|> tVariableEntity.
404411

412+
thenClause --|> block.
413+
405414
tuple --|> collectionInitializer.
406415

407416
unaryOperator --|> operator.
@@ -457,7 +466,11 @@ FASTPythonMetamodelGenerator >> defineRelations [
457466
((globalStatement property: #variable) comment: 'The variable scoped')
458467
<>- ((variable property: #globalOwner) comment: 'The global statement defining my scope (if it''s the case)').
459468

460-
(ifStatement property: #thenBlock) <>- (block property: #ifStatementOwner).
469+
(ifStatement property: #thenClause) <>- (thenClause property: #ifStatementOwner).
470+
471+
(ifStatement property: #elseClause) <>- (elseClause property: #ifStatementOwner).
472+
473+
(ifStatement property: #elifClauses) <>-* (elifClause property: #ifStatementOwner).
461474

462475
((import property: #importedEntities) comment: 'List of the imported entities.')
463476
<>-* ((importedEntity property: #import) comment: 'Import declaring me as imported entity.').

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
88
| `fastBehaviouralParent` | `FASTTStatementBlock` | `statementBlock` | `FASTTWithStatements` | Behavioural entity containing the statement block.|
9-
| `ifStatementOwner` | `FASTPyBlock` | `thenBlock` | `FASTPyIfStatement` | |
109
| `parentLoopStatement` | `FASTTStatement` | `body` | `FASTTLoopStatement` | Optional loop of which this statement is the body|
1110
| `statementContainer` | `FASTTStatement` | `statements` | `FASTTStatementBlock` | Block containing this statement.|
1211

@@ -30,9 +29,6 @@ Class {
3029
#superclass : 'FASTPyEntity',
3130
#traits : 'FASTTStatementBlock',
3231
#classTraits : 'FASTTStatementBlock classTrait',
33-
#instVars : [
34-
'#ifStatementOwner => FMOne type: #FASTPyIfStatement opposite: #thenBlock'
35-
],
3632
#category : 'FAST-Python-Model-Entities',
3733
#package : 'FAST-Python-Model',
3834
#tag : 'Entities'
@@ -46,27 +42,3 @@ FASTPyBlock class >> annotation [
4642
<generated>
4743
^ self
4844
]
49-
50-
{ #category : 'accessing' }
51-
FASTPyBlock >> ifStatementOwner [
52-
"Relation named: #ifStatementOwner type: #FASTPyIfStatement opposite: #thenBlock"
53-
54-
<generated>
55-
<container>
56-
<derived>
57-
^ ifStatementOwner
58-
]
59-
60-
{ #category : 'accessing' }
61-
FASTPyBlock >> ifStatementOwner: anObject [
62-
63-
<generated>
64-
ifStatementOwner := anObject
65-
]
66-
67-
{ #category : 'navigation' }
68-
FASTPyBlock >> ifStatementOwnerGroup [
69-
<generated>
70-
<navigation: 'IfStatementOwner'>
71-
^ MooseSpecializedGroup with: self ifStatementOwner
72-
]
Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `ifStatementOwner` | `FASTPyElifClause` | `elifClauses` | `FASTPyIfStatement` | |
9+
| `parentLoopStatement` | `FASTTStatement` | `body` | `FASTTLoopStatement` | Optional loop of which this statement is the body|
10+
| `statementContainer` | `FASTTStatement` | `statements` | `FASTTStatementBlock` | Block containing this statement.|
11+
12+
### Children
13+
| Relation | Origin | Opposite | Type | Comment |
14+
|---|
15+
| `condition` | `FASTTConditionalStatement` | `parentConditionalStatement` | `FASTTExpression` | The boolean condition tested|
16+
17+
18+
## Properties
19+
======================
20+
21+
| Name | Type | Default value | Comment |
22+
|---|
23+
| `endPos` | `Number` | nil | |
24+
| `startPos` | `Number` | nil | |
25+
26+
"
127
Class {
228
#name : 'FASTPyElifClause',
3-
#superclass : 'FASTPyEntity',
29+
#superclass : 'FASTPyBlock',
30+
#traits : 'FASTTConditionalStatement',
31+
#classTraits : 'FASTTConditionalStatement classTrait',
32+
#instVars : [
33+
'#ifStatementOwner => FMOne type: #FASTPyIfStatement opposite: #elifClauses'
34+
],
435
#category : 'FAST-Python-Model-Entities',
536
#package : 'FAST-Python-Model',
637
#tag : 'Entities'
@@ -9,8 +40,31 @@ Class {
940
{ #category : 'meta' }
1041
FASTPyElifClause class >> annotation [
1142

12-
<FMClass: #ElifClause super: #FASTPyEntity>
43+
<FMClass: #ElifClause super: #FASTPyBlock>
1344
<package: #'FAST-Python-Model'>
1445
<generated>
1546
^ self
1647
]
48+
49+
{ #category : 'accessing' }
50+
FASTPyElifClause >> ifStatementOwner [
51+
"Relation named: #ifStatementOwner type: #FASTPyIfStatement opposite: #elifClauses"
52+
53+
<generated>
54+
<container>
55+
^ ifStatementOwner
56+
]
57+
58+
{ #category : 'accessing' }
59+
FASTPyElifClause >> ifStatementOwner: anObject [
60+
61+
<generated>
62+
ifStatementOwner := anObject
63+
]
64+
65+
{ #category : 'navigation' }
66+
FASTPyElifClause >> ifStatementOwnerGroup [
67+
<generated>
68+
<navigation: 'IfStatementOwner'>
69+
^ MooseSpecializedGroup with: self ifStatementOwner
70+
]
Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `ifStatementOwner` | `FASTPyElseClause` | `elseClause` | `FASTPyIfStatement` | |
9+
10+
11+
12+
"
113
Class {
214
#name : 'FASTPyElseClause',
3-
#superclass : 'FASTPyEntity',
15+
#superclass : 'FASTPyBlock',
16+
#instVars : [
17+
'#ifStatementOwner => FMOne type: #FASTPyIfStatement opposite: #elseClause'
18+
],
419
#category : 'FAST-Python-Model-Entities',
520
#package : 'FAST-Python-Model',
621
#tag : 'Entities'
@@ -9,8 +24,32 @@ Class {
924
{ #category : 'meta' }
1025
FASTPyElseClause class >> annotation [
1126

12-
<FMClass: #ElseClause super: #FASTPyEntity>
27+
<FMClass: #ElseClause super: #FASTPyBlock>
1328
<package: #'FAST-Python-Model'>
1429
<generated>
1530
^ self
1631
]
32+
33+
{ #category : 'accessing' }
34+
FASTPyElseClause >> ifStatementOwner [
35+
"Relation named: #ifStatementOwner type: #FASTPyIfStatement opposite: #elseClause"
36+
37+
<generated>
38+
<container>
39+
<derived>
40+
^ ifStatementOwner
41+
]
42+
43+
{ #category : 'accessing' }
44+
FASTPyElseClause >> ifStatementOwner: anObject [
45+
46+
<generated>
47+
ifStatementOwner := anObject
48+
]
49+
50+
{ #category : 'navigation' }
51+
FASTPyElseClause >> ifStatementOwnerGroup [
52+
<generated>
53+
<navigation: 'IfStatementOwner'>
54+
^ MooseSpecializedGroup with: self ifStatementOwner
55+
]

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

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
| Relation | Origin | Opposite | Type | Comment |
1313
|---|
1414
| `condition` | `FASTTConditionalStatement` | `parentConditionalStatement` | `FASTTExpression` | The boolean condition tested|
15-
| `thenBlock` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyBlock` | |
15+
| `elifClauses` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyElifClause` | |
16+
| `elseClause` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyElseClause` | |
17+
| `thenClause` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyThenClause` | |
1618

1719

1820
## Properties
@@ -30,7 +32,9 @@ Class {
3032
#traits : 'FASTTConditionalStatement + FASTTStatement',
3133
#classTraits : 'FASTTConditionalStatement classTrait + FASTTStatement classTrait',
3234
#instVars : [
33-
'#thenBlock => FMOne type: #FASTPyBlock opposite: #ifStatementOwner'
35+
'#elifClauses => FMMany type: #FASTPyElifClause opposite: #ifStatementOwner',
36+
'#elseClause => FMOne type: #FASTPyElseClause opposite: #ifStatementOwner',
37+
'#thenClause => FMOne type: #FASTPyThenClause opposite: #ifStatementOwner'
3438
],
3539
#category : 'FAST-Python-Model-Entities',
3640
#package : 'FAST-Python-Model',
@@ -46,24 +50,75 @@ FASTPyIfStatement class >> annotation [
4650
^ self
4751
]
4852

53+
{ #category : 'adding' }
54+
FASTPyIfStatement >> addElifClause: anObject [
55+
<generated>
56+
^ self elifClauses add: anObject
57+
]
58+
59+
{ #category : 'accessing' }
60+
FASTPyIfStatement >> elifClauses [
61+
"Relation named: #elifClauses type: #FASTPyElifClause opposite: #ifStatementOwner"
62+
63+
<generated>
64+
<derived>
65+
^ elifClauses
66+
]
67+
68+
{ #category : 'accessing' }
69+
FASTPyIfStatement >> elifClauses: anObject [
70+
71+
<generated>
72+
elifClauses value: anObject
73+
]
74+
75+
{ #category : 'navigation' }
76+
FASTPyIfStatement >> elifClausesGroup [
77+
<generated>
78+
<navigation: 'ElifClauses'>
79+
^ MooseSpecializedGroup withAll: self elifClauses asSet
80+
]
81+
82+
{ #category : 'accessing' }
83+
FASTPyIfStatement >> elseClause [
84+
"Relation named: #elseClause type: #FASTPyElseClause opposite: #ifStatementOwner"
85+
86+
<generated>
87+
^ elseClause
88+
]
89+
90+
{ #category : 'accessing' }
91+
FASTPyIfStatement >> elseClause: anObject [
92+
93+
<generated>
94+
elseClause := anObject
95+
]
96+
97+
{ #category : 'navigation' }
98+
FASTPyIfStatement >> elseClauseGroup [
99+
<generated>
100+
<navigation: 'ElseClause'>
101+
^ MooseSpecializedGroup with: self elseClause
102+
]
103+
49104
{ #category : 'accessing' }
50-
FASTPyIfStatement >> thenBlock [
51-
"Relation named: #thenBlock type: #FASTPyBlock opposite: #ifStatementOwner"
105+
FASTPyIfStatement >> thenClause [
106+
"Relation named: #thenClause type: #FASTPyThenClause opposite: #ifStatementOwner"
52107

53108
<generated>
54-
^ thenBlock
109+
^ thenClause
55110
]
56111

57112
{ #category : 'accessing' }
58-
FASTPyIfStatement >> thenBlock: anObject [
113+
FASTPyIfStatement >> thenClause: anObject [
59114

60115
<generated>
61-
thenBlock := anObject
116+
thenClause := anObject
62117
]
63118

64119
{ #category : 'navigation' }
65-
FASTPyIfStatement >> thenBlockGroup [
120+
FASTPyIfStatement >> thenClauseGroup [
66121
<generated>
67-
<navigation: 'ThenBlock'>
68-
^ MooseSpecializedGroup with: self thenBlock
122+
<navigation: 'ThenClause'>
123+
^ MooseSpecializedGroup with: self thenClause
69124
]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,13 @@ FASTPyTEntityCreator >> newSubscript [
769769
^ self add: FASTPySubscript new
770770
]
771771

772+
{ #category : 'entity creation' }
773+
FASTPyTEntityCreator >> newThenClause [
774+
775+
<generated>
776+
^ self add: FASTPyThenClause new
777+
]
778+
772779
{ #category : 'entity creation' }
773780
FASTPyTEntityCreator >> newTryStatement [
774781

0 commit comments

Comments
 (0)