Skip to content

Commit 28525c2

Browse files
committed
Merge branch 'main' into without-expression
2 parents f6ea835 + 9f9e215 commit 28525c2

File tree

5 files changed

+157
-4
lines changed

5 files changed

+157
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ Class {
144144
'tReturnStatement',
145145
'tStatement',
146146
'collectionInitializer',
147-
'statement'
147+
'statement',
148+
'tConditionalStatement'
148149
],
149150
#category : 'FAST-Python-Model-Generator',
150151
#package : 'FAST-Python-Model-Generator'
@@ -233,7 +234,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
233234
globalStatement := builder ensureClassNamed: #GlobalStatement.
234235
identifier := builder ensureClassNamed: #Identifier."Todo"
235236
ifClause := builder ensureClassNamed: #IfClause."Todo"
236-
ifStatement := builder ensureClassNamed: #IfStatement."Todo"
237+
ifStatement := builder ensureClassNamed: #IfStatement.
237238
import := builder ensureClassNamed: #Import. "To review"
238239
importedEntity := builder ensureClassNamed: #ImportedEntity.
239240
importFromStatement := builder ensureClassNamed: #ImportFromStatement."Todo"
@@ -343,6 +344,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
343344
self flag: #todo. "I am not sure this should be the case but the importer is too young and we need this to not have everything breaking."
344345
identifier --|> expression.
345346

347+
ifStatement --|> statement.
348+
ifStatement --|> tConditionalStatement.
349+
346350
importStatement --|> import.
347351

348352
importFromStatement --|> import.
@@ -445,6 +449,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
445449
((globalStatement property: #variable) comment: 'The variable scoped')
446450
<>- ((variable property: #globalOwner) comment: 'The global statement defining my scope (if it''s the case)').
447451

452+
(ifStatement property: #thenBlock) <>- (block property: #ifStatementOwner).
453+
448454
((import property: #importedEntities) comment: 'List of the imported entities.')
449455
<>-* ((importedEntity property: #import) comment: 'Import declaring me as imported entity.').
450456

@@ -475,6 +481,7 @@ FASTPythonMetamodelGenerator >> defineTraits [
475481
tBinaryExpression := self remoteTrait: #TBinaryExpression withPrefix: #FAST.
476482
tBooleanLiteral := self remoteTrait: #TBooleanLiteral withPrefix: #FAST.
477483
tComment := self remoteTrait: #TComment withPrefix: #FAST.
484+
tConditionalStatement := self remoteTrait: #TConditionalStatement withPrefix: #FAST.
478485
tExpression := self remoteTrait: #TExpression withPrefix: #FAST.
479486
tInvocation := self remoteTrait: #TInvocation withPrefix: #FAST.
480487
tReturnStatement := self remoteTrait: #TReturnStatement withPrefix: #FAST.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
88
| `fastBehaviouralParent` | `FASTTStatementBlock` | `statementBlock` | `FASTTBehaviouralEntity` | Behavioural entity containing the statement block.|
9+
| `ifStatementOwner` | `FASTPyBlock` | `thenBlock` | `FASTPyIfStatement` | |
910
| `parentLoopStatement` | `FASTTStatement` | `body` | `FASTTLoopStatement` | Optional loop of which this statement is the body|
1011
| `statementContainer` | `FASTTStatement` | `statements` | `FASTTStatementBlock` | Block containing this statement.|
1112
@@ -29,6 +30,9 @@ Class {
2930
#superclass : 'FASTPyEntity',
3031
#traits : 'FASTTStatementBlock',
3132
#classTraits : 'FASTTStatementBlock classTrait',
33+
#instVars : [
34+
'#ifStatementOwner => FMOne type: #FASTPyIfStatement opposite: #thenBlock'
35+
],
3236
#category : 'FAST-Python-Model-Entities',
3337
#package : 'FAST-Python-Model',
3438
#tag : 'Entities'
@@ -42,3 +46,27 @@ FASTPyBlock class >> annotation [
4246
<generated>
4347
^ self
4448
]
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: 55 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+
| `parentLoopStatement` | `FASTTStatement` | `body` | `FASTTLoopStatement` | Optional loop of which this statement is the body|
9+
| `statementContainer` | `FASTTStatement` | `statements` | `FASTTStatementBlock` | Block containing this statement.|
10+
11+
### Children
12+
| Relation | Origin | Opposite | Type | Comment |
13+
|---|
14+
| `condition` | `FASTTConditionalStatement` | `parentConditionalStatement` | `FASTTExpression` | The boolean condition tested|
15+
| `thenBlock` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyBlock` | |
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 : 'FASTPyIfStatement',
3-
#superclass : 'FASTPyEntity',
29+
#superclass : 'FASTPyStatement',
30+
#traits : 'FASTTConditionalStatement',
31+
#classTraits : 'FASTTConditionalStatement classTrait',
32+
#instVars : [
33+
'#thenBlock => FMOne type: #FASTPyBlock opposite: #ifStatementOwner'
34+
],
435
#category : 'FAST-Python-Model-Entities',
536
#package : 'FAST-Python-Model',
637
#tag : 'Entities'
@@ -9,8 +40,30 @@ Class {
940
{ #category : 'meta' }
1041
FASTPyIfStatement class >> annotation [
1142

12-
<FMClass: #IfStatement super: #FASTPyEntity>
43+
<FMClass: #IfStatement super: #FASTPyStatement>
1344
<package: #'FAST-Python-Model'>
1445
<generated>
1546
^ self
1647
]
48+
49+
{ #category : 'accessing' }
50+
FASTPyIfStatement >> thenBlock [
51+
"Relation named: #thenBlock type: #FASTPyBlock opposite: #ifStatementOwner"
52+
53+
<generated>
54+
^ thenBlock
55+
]
56+
57+
{ #category : 'accessing' }
58+
FASTPyIfStatement >> thenBlock: anObject [
59+
60+
<generated>
61+
thenBlock := anObject
62+
]
63+
64+
{ #category : 'navigation' }
65+
FASTPyIfStatement >> thenBlockGroup [
66+
<generated>
67+
<navigation: 'ThenBlock'>
68+
^ MooseSpecializedGroup with: self thenBlock
69+
]

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,63 @@ FASTPythonImporterTest >> testGlobalStatement [
10061006

10071007
]
10081008

1009+
{ #category : 'tests - if' }
1010+
FASTPythonImporterTest >> testIf [
1011+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol: "
1012+
1013+
self parse: 'if x > 0:
1014+
3'.
1015+
1016+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
1017+
self assert: (fast allWithType: FASTPyBlock) size equals: 1.
1018+
self assert: (fast allWithType: FASTPyIfStatement) size equals: 1.
1019+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 1.
1020+
self assert: (fast allWithType: FASTPyComparisonOperator) size equals: 1.
1021+
self assert: (fast allWithType: FASTPyInteger) size equals: 2.
1022+
1023+
stack push: fast rootEntities anyOne genericChildren first.
1024+
self assert: self topEntity sourceCode equals: 'if x > 0:
1025+
3' withPlatformLineEndings.
1026+
self assert: (self topEntity isOfType: FASTPyIfStatement).
1027+
1028+
"Testing value of monovalue relation condition"
1029+
self assert: self topEntity condition isNotNil.
1030+
1031+
stack push: self topEntity condition.
1032+
self assert: self topEntity sourceCode equals: 'x > 0'.
1033+
self assert: (self topEntity isOfType: FASTPyComparisonOperator).
1034+
1035+
"Testing value of multivalued relation operands"
1036+
self assert: self topEntity operands size equals: 2.
1037+
1038+
stack push: (stack top operands at: 1).
1039+
self assert: self topEntity sourceCode equals: 'x'.
1040+
self assert: (self topEntity isOfType: FASTPyIdentifier).
1041+
stack pop.
1042+
1043+
stack push: (stack top operands at: 2).
1044+
self assert: self topEntity sourceCode equals: '0'.
1045+
self assert: (self topEntity isOfType: FASTPyInteger).
1046+
stack pop.
1047+
self assert: self topEntity operators equals: #('>').
1048+
stack pop.
1049+
1050+
"Testing value of monovalue relation thenBlock"
1051+
self assert: self topEntity thenBlock isNotNil.
1052+
1053+
stack push: self topEntity thenBlock.
1054+
self assert: self topEntity sourceCode equals: '3'.
1055+
self assert: (self topEntity isOfType: FASTPyBlock).
1056+
1057+
"Testing value of multivalued relation statements"
1058+
self assert: self topEntity statements size equals: 1.
1059+
1060+
stack push: (stack top statements at: 1).
1061+
self assert: self topEntity sourceCode equals: '3'.
1062+
self assert: (self topEntity isOfType: FASTPyInteger).
1063+
1064+
]
1065+
10091066
{ #category : 'tests - imports' }
10101067
FASTPythonImporterTest >> testImport [
10111068
"Generated as regression test by FASTPythonImporterTest class>>#generateTestNamed:fromCode: "

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ TSFASTPythonImporter >> visitIdentifier: aNode [
215215
^ self createEntityForNode: aNode
216216
]
217217

218+
{ #category : 'visiting' }
219+
TSFASTPythonImporter >> visitIfStatement: aTSNode [
220+
221+
self onNextContextDo: [ :contextEntry | contextEntry add: 'thenBlock' asAliasOfField: 'consequence' ].
222+
223+
^ self createEntityForNode: aTSNode kind: FASTPyIfStatement
224+
]
225+
218226
{ #category : 'visiting' }
219227
TSFASTPythonImporter >> visitImportFromStatement: aTSNode [
220228

0 commit comments

Comments
 (0)