Skip to content

Commit 4ee41bd

Browse files
committed
Manage fully the try statement
1 parent 02f48a9 commit 4ee41bd

7 files changed

Lines changed: 717 additions & 14 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Class {
4141
'escapeSequence',
4242
'exceptClause',
4343
'execStatement',
44-
'expressionList',
4544
'finallyClause',
4645
'float',
4746
'forInClause',
@@ -401,6 +400,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
401400
expression --|> statement. "In Python expressions can also be expression statements."
402401
expression --|> tExpression.
403402

403+
finallyClause --|> tStatementBlock.
404+
404405
float --|> literal.
405406
float --|> tNumericalLiteral.
406407

@@ -541,6 +542,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
541542

542543
tryStatement --|> statement.
543544
tryStatement --|> tStatementBlock.
545+
tryStatement --|> tWithElseClause.
544546

545547
typeAliasStatement --|> statement.
546548

@@ -649,6 +651,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
649651

650652
((deleteStatement property: #expression) comment: 'The expression to apply the delete on')
651653
<>- ((tDeletable property: #parentDeleteStatement) comment: 'The delete statement that own the expression (if it''s the case)').
654+
655+
(exceptClause property: #expressions) <>-* (expression property: #parentExceptClause). "We could point less things than expression, but in reality in Python any expression can be provided. It will just end up in runtime error."
652656

653657
(forInClause property: #left) <>- (expression property: #forInClauseLeftOwner).
654658

@@ -735,6 +739,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
735739

736740
(typeAliasStatement property: #left) <>- (type property: #parentyTypeAliasStatementAlias).
737741
(typeAliasStatement property: #right) <>- (type property: #parentyTypeAliasStatementType).
742+
743+
(tryStatement property: #finally) <>- (finallyClause property: #parentTryStatement).
738744

739745
(tWithElseClause property: #elseClause) <>- (elseClause property: #ifStatementOwner).
740746

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Children
1414
| Relation | Origin | Opposite | Type | Comment |
1515
|---|
16+
| `expressions` | `FASTPyExceptClause` | `parentExceptClause` | `FASTPyExpression` | |
1617
| `statements` | `FASTTStatementBlock` | `statementContainer` | `FASTTStatement` | Statements enclosed in this block|
1718
1819
@@ -31,6 +32,7 @@ Class {
3132
#traits : 'FASTTStatementBlock',
3233
#classTraits : 'FASTTStatementBlock classTrait',
3334
#instVars : [
35+
'#expressions => FMMany type: #FASTPyExpression opposite: #parentExceptClause',
3436
'#parentTryStatement => FMOne type: #FASTPyTryStatement opposite: #excepts'
3537
],
3638
#category : 'FAST-Python-Model-Entities',
@@ -47,6 +49,35 @@ FASTPyExceptClause class >> annotation [
4749
^ self
4850
]
4951

52+
{ #category : 'adding' }
53+
FASTPyExceptClause >> addExpression: anObject [
54+
<generated>
55+
^ self expressions add: anObject
56+
]
57+
58+
{ #category : 'accessing' }
59+
FASTPyExceptClause >> expressions [
60+
"Relation named: #expressions type: #FASTPyExpression opposite: #parentExceptClause"
61+
62+
<generated>
63+
<derived>
64+
^ expressions
65+
]
66+
67+
{ #category : 'accessing' }
68+
FASTPyExceptClause >> expressions: anObject [
69+
70+
<generated>
71+
expressions value: anObject
72+
]
73+
74+
{ #category : 'navigation' }
75+
FASTPyExceptClause >> expressionsGroup [
76+
<generated>
77+
<navigation: 'Expressions'>
78+
^ MooseSpecializedGroup withAll: self expressions asSet
79+
]
80+
5081
{ #category : 'accessing' }
5182
FASTPyExceptClause >> parentTryStatement [
5283
"Relation named: #parentTryStatement type: #FASTPyTryStatement opposite: #excepts"

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
| `parentComparisonOperator` | `FASTPyExpression` | `operands` | `FASTPyComparisonOperator` | Parent comparison expression of which I am.|
3131
| `parentConditional` | `FASTTExpression` | `condition` | `FASTTWithCondition` | Optional condition statement/expression where this expression is used|
3232
| `parentDefaultParameterValue` | `FASTPyExpression` | `defaultValue` | `FASTPyParameter` | |
33+
| `parentExceptClause` | `FASTPyExpression` | `expressions` | `FASTPyExceptClause` | |
3334
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
3435
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
3536
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
@@ -81,6 +82,7 @@ Class {
8182
'#parentAwait => FMOne type: #FASTPyAwait opposite: #expression',
8283
'#parentComparisonOperator => FMOne type: #FASTPyComparisonOperator opposite: #operands',
8384
'#parentDefaultParameterValue => FMOne type: #FASTPyParameter opposite: #defaultValue',
85+
'#parentExceptClause => FMOne type: #FASTPyExceptClause opposite: #expressions',
8486
'#parentInterpolation => FMOne type: #FASTPyInterpolation opposite: #expression',
8587
'#parentMatchStatement => FMOne type: #FASTPyMatchStatement opposite: #subject',
8688
'#parentType => FMOne type: #FASTPyType opposite: #expression',
@@ -613,6 +615,29 @@ FASTPyExpression >> parentDefaultParameterValueGroup [
613615
^ MooseSpecializedGroup with: self parentDefaultParameterValue
614616
]
615617

618+
{ #category : 'accessing' }
619+
FASTPyExpression >> parentExceptClause [
620+
"Relation named: #parentExceptClause type: #FASTPyExceptClause opposite: #expressions"
621+
622+
<generated>
623+
<container>
624+
^ parentExceptClause
625+
]
626+
627+
{ #category : 'accessing' }
628+
FASTPyExpression >> parentExceptClause: anObject [
629+
630+
<generated>
631+
parentExceptClause := anObject
632+
]
633+
634+
{ #category : 'navigation' }
635+
FASTPyExpression >> parentExceptClauseGroup [
636+
<generated>
637+
<navigation: 'ParentExceptClause'>
638+
^ MooseSpecializedGroup with: self parentExceptClause
639+
]
640+
616641
{ #category : 'accessing' }
617642
FASTPyExpression >> parentInterpolation [
618643
"Relation named: #parentInterpolation type: #FASTPyInterpolation opposite: #expression"

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `fastBehaviouralParent` | `FASTTStatementBlock` | `statementBlock` | `FASTTWithStatements` | Behavioural entity containing the statement block.|
9+
| `parentLoopStatement` | `FASTTStatement` | `body` | `FASTTLoopStatement` | Optional loop of which this statement is the body|
10+
| `parentTryStatement` | `FASTPyFinallyClause` | `finally` | `FASTPyTryStatement` | |
11+
| `statementContainer` | `FASTTStatement` | `statements` | `FASTTStatementBlock` | Block containing this statement.|
12+
13+
### Children
14+
| Relation | Origin | Opposite | Type | Comment |
15+
|---|
16+
| `statements` | `FASTTStatementBlock` | `statementContainer` | `FASTTStatement` | Statements enclosed in this block|
17+
18+
19+
## Properties
20+
======================
21+
22+
| Name | Type | Default value | Comment |
23+
|---|
24+
| `endPos` | `Number` | nil | |
25+
| `startPos` | `Number` | nil | |
26+
27+
"
128
Class {
229
#name : 'FASTPyFinallyClause',
330
#superclass : 'FASTPyEntity',
31+
#traits : 'FASTTStatementBlock',
32+
#classTraits : 'FASTTStatementBlock classTrait',
33+
#instVars : [
34+
'#parentTryStatement => FMOne type: #FASTPyTryStatement opposite: #finally'
35+
],
436
#category : 'FAST-Python-Model-Entities',
537
#package : 'FAST-Python-Model',
638
#tag : 'Entities'
@@ -14,3 +46,27 @@ FASTPyFinallyClause class >> annotation [
1446
<generated>
1547
^ self
1648
]
49+
50+
{ #category : 'accessing' }
51+
FASTPyFinallyClause >> parentTryStatement [
52+
"Relation named: #parentTryStatement type: #FASTPyTryStatement opposite: #finally"
53+
54+
<generated>
55+
<container>
56+
<derived>
57+
^ parentTryStatement
58+
]
59+
60+
{ #category : 'accessing' }
61+
FASTPyFinallyClause >> parentTryStatement: anObject [
62+
63+
<generated>
64+
parentTryStatement := anObject
65+
]
66+
67+
{ #category : 'navigation' }
68+
FASTPyFinallyClause >> parentTryStatementGroup [
69+
<generated>
70+
<navigation: 'ParentTryStatement'>
71+
^ MooseSpecializedGroup with: self parentTryStatement
72+
]

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
### Children
1313
| Relation | Origin | Opposite | Type | Comment |
1414
|---|
15+
| `elseClause` | `FASTPyTWithElseClause` | `ifStatementOwner` | `FASTPyElseClause` | |
1516
| `excepts` | `FASTPyTryStatement` | `parentTryStatement` | `FASTPyExceptClause` | |
17+
| `finally` | `FASTPyTryStatement` | `parentTryStatement` | `FASTPyFinallyClause` | |
1618
| `statements` | `FASTTStatementBlock` | `statementContainer` | `FASTTStatement` | Statements enclosed in this block|
1719
1820
@@ -28,10 +30,11 @@
2830
Class {
2931
#name : 'FASTPyTryStatement',
3032
#superclass : 'FASTPyStatement',
31-
#traits : 'FASTTStatementBlock',
32-
#classTraits : 'FASTTStatementBlock classTrait',
33+
#traits : 'FASTPyTWithElseClause + FASTTStatementBlock',
34+
#classTraits : 'FASTPyTWithElseClause classTrait + FASTTStatementBlock classTrait',
3335
#instVars : [
34-
'#excepts => FMMany type: #FASTPyExceptClause opposite: #parentTryStatement'
36+
'#excepts => FMMany type: #FASTPyExceptClause opposite: #parentTryStatement',
37+
'#finally => FMOne type: #FASTPyFinallyClause opposite: #parentTryStatement'
3538
],
3639
#category : 'FAST-Python-Model-Entities',
3740
#package : 'FAST-Python-Model',
@@ -75,3 +78,25 @@ FASTPyTryStatement >> exceptsGroup [
7578
<navigation: 'Excepts'>
7679
^ MooseSpecializedGroup withAll: self excepts asSet
7780
]
81+
82+
{ #category : 'accessing' }
83+
FASTPyTryStatement >> finally [
84+
"Relation named: #finally type: #FASTPyFinallyClause opposite: #parentTryStatement"
85+
86+
<generated>
87+
^ finally
88+
]
89+
90+
{ #category : 'accessing' }
91+
FASTPyTryStatement >> finally: anObject [
92+
93+
<generated>
94+
finally := anObject
95+
]
96+
97+
{ #category : 'navigation' }
98+
FASTPyTryStatement >> finallyGroup [
99+
<generated>
100+
<navigation: 'Finally'>
101+
^ MooseSpecializedGroup with: self finally
102+
]

0 commit comments

Comments
 (0)