Skip to content

Commit d8e3015

Browse files
committed
Manage constrained_type and start to manage type_parameters
Also rename the property of Type
1 parent ac7f41c commit d8e3015

14 files changed

Lines changed: 736 additions & 133 deletions

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ Class {
153153
'tPattern',
154154
'tClassPatternElement',
155155
'tUnionMember',
156-
'tDeletable'
156+
'tDeletable',
157+
'tTypeContent',
158+
'typeParameter',
159+
'tWithTypeParameters'
157160
],
158161
#category : 'FAST-Python-Model-Generator',
159162
#package : 'FAST-Python-Model-Generator'
@@ -282,6 +285,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
282285
type := builder ensureClassNamed: #Type."Todo"
283286
typeAliasStatement := builder ensureClassNamed: #TypeAliasStatement."Todo"
284287
typeConversion := builder ensureClassNamed: #TypeConversion."Todo"
288+
typeParameter := builder ensureClassNamed: #TypeParameter.
285289
unaryOperator := builder ensureClassNamed: #UnaryOperator.
286290
unionPattern := builder ensureClassNamed: #UnionPattern."Todo"
287291
unionType := builder ensureClassNamed: #UnionType."Todo"
@@ -346,6 +350,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
346350

347351
classDefinition --|> statement.
348352
classDefinition --|> tDefinition.
353+
classDefinition --|> tWithTypeParameters.
349354

350355
classPattern --|> tPattern.
351356

@@ -369,6 +374,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
369374
conditionalExpression --|> tWithCondition.
370375

371376
continueStatement --|> statement.
377+
378+
constrainedType --|> tTypeContent.
372379

373380
deleteStatement --|> statement.
374381

@@ -399,6 +406,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
399406

400407
expression --|> statement. "In Python expressions can also be expression statements."
401408
expression --|> tExpression.
409+
expression --|> tTypeContent. "Not sure all expressions should be but it's simpler like this."
402410

403411
finallyClause --|> tStatementBlock.
404412

@@ -413,9 +421,13 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
413421

414422
functionDefinition --|> statement.
415423
functionDefinition --|> tDefinition.
424+
functionDefinition --|> tWithTypeParameters.
416425

417426
generatorExpression --|> expression.
418427
generatorExpression --|> tComprehension.
428+
429+
genericType --|> tTypeContent.
430+
genericType --|> tWithTypeParameters.
419431

420432
globalStatement --|> statement.
421433

@@ -472,6 +484,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
472484

473485
methodDefinition --|> statement.
474486
methodDefinition --|> tDefinition.
487+
methodDefinition --|> tWithTypeParameters.
475488

476489
module --|> tStatementBlock.
477490
module --|> #THasImmediateSource.
@@ -544,6 +557,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
544557
tryStatement --|> tWithElseClause.
545558

546559
typeAliasStatement --|> statement.
560+
561+
typeParameter --|> tTypeContent.
547562

548563
unaryOperator --|> operator.
549564
unaryOperator --|> tUnaryOperator.
@@ -652,6 +667,10 @@ FASTPythonMetamodelGenerator >> defineRelations [
652667
(conditionalExpression property: #thenExpression) <>- (expression property: #conditionalExpressionThenOwner).
653668

654669
(conditionalExpression property: #elseExpression) <>- (expression property: #conditionalExpressionElseOwner).
670+
671+
(constrainedType property: #type) <>- (type property: #parentContrainedType).
672+
673+
(constrainedType property: #bound) <>- (type property: #parentContrainedTypeBound).
655674

656675
(decorator property: #expression) <>- (tDecoratorExpression property: #parentDeclarator).
657676

@@ -741,7 +760,7 @@ FASTPythonMetamodelGenerator >> defineRelations [
741760
((tUnaryOperator property: #argument) comment: 'Expression influanced by the unary operator..')
742761
<>- ((expression property: #parentUnaryOperator) comment: 'Parent unary operator in which I am.').
743762

744-
(type property: #expression) <>- (expression property: #parentType). "I am not 100% sure I should point to an expression because all of them cannot be a type."
763+
(type property: #content) <>- (tTypeContent property: #parentType).
745764

746765
(typeAliasStatement property: #left) <>- (type property: #parentyTypeAliasStatementAlias).
747766
(typeAliasStatement property: #right) <>- (type property: #parentyTypeAliasStatementType).
@@ -750,6 +769,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
750769

751770
(tWithElseClause property: #elseClause) <>- (elseClause property: #ifStatementOwner).
752771

772+
(tWithTypeParameters property: #typeParameters) <>-* (type property: #parentWithTypeParameters).
773+
753774
(unionPattern property: #members) <>-* (tPattern property: #parentUnionPattern).
754775

755776
(withStatement property: #items) <>-* (tWithStatementItem property: #parentWithStatementItem)
@@ -791,12 +812,16 @@ FASTPythonMetamodelGenerator >> defineTraits [
791812
(tSplatParameter := builder newTraitNamed: #TSplatParameter) comment: 'I represent a parameter that is a list or dictionary splat.'.
792813

793814
tSplatParameterTarget := (builder newTraitNamed: #TSplatParameterTarget) comment: 'My users are parameter target in a splat. For example in `def f(*list): pass`, we have a list splat parameter named list.'.
815+
816+
(tTypeContent := builder newTraitNamed: #TTypeContent) comment: 'My user can be used as a type declaration'.
794817

795818
tUnaryOperator := builder newTraitNamed: #TUnaryOperator.
819+
820+
tWithElseClause := builder newTraitNamed: #TWithElseClause.
796821

797822
tWithStatementItem := (builder newTraitNamed: #TWithStatementItem) comment: 'I represent an entity that can be the item of a with_statement.'.
798823

799-
tWithElseClause := builder newTraitNamed: #TWithElseClause.
824+
(tWithTypeParameters := builder newTraitNamed: #TWithTypeParameters) comment: 'I represent an entity with type parameters such as generic types, function/method definition or class definition'.
800825

801826
"Remotes"
802827
tAssignment := self remoteTrait: #TAssignment withPrefix: #FAST.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| `decorators` | `FASTPyTDefinition` | `definitionOwner` | `FASTPyDecorator` | |
1414
| `parameters` | `FASTTWithParameters` | `parameterOwner` | `FASTTVariableEntity` | My parameters|
1515
| `statementBlock` | `FASTTWithStatements` | `fastBehaviouralParent` | `FASTTStatementBlock` | Statements block of the behavioural entity|
16+
| `typeParameters` | `FASTPyTWithTypeParameters` | `parentWithTypeParameters` | `FASTPyType` | |
1617
1718
1819
## Properties
@@ -28,8 +29,8 @@
2829
Class {
2930
#name : 'FASTPyClassDefinition',
3031
#superclass : 'FASTPyStatement',
31-
#traits : 'FASTPyTDefinition',
32-
#classTraits : 'FASTPyTDefinition classTrait',
32+
#traits : 'FASTPyTDefinition + FASTPyTWithTypeParameters',
33+
#classTraits : 'FASTPyTDefinition classTrait + FASTPyTWithTypeParameters classTrait',
3334
#category : 'FAST-Python-Model-Entities',
3435
#package : 'FAST-Python-Model',
3536
#tag : 'Entities'

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `parentType` | `FASTPyTTypeContent` | `content` | `FASTPyType` | |
9+
10+
### Children
11+
| Relation | Origin | Opposite | Type | Comment |
12+
|---|
13+
| `bound` | `FASTPyConstrainedType` | `parentContrainedTypeBound` | `FASTPyType` | |
14+
| `type` | `FASTPyConstrainedType` | `parentContrainedType` | `FASTPyType` | |
15+
16+
17+
18+
"
119
Class {
220
#name : 'FASTPyConstrainedType',
321
#superclass : 'FASTPyEntity',
22+
#traits : 'FASTPyTTypeContent',
23+
#classTraits : 'FASTPyTTypeContent classTrait',
24+
#instVars : [
25+
'#bound => FMOne type: #FASTPyType opposite: #parentContrainedTypeBound',
26+
'#type => FMOne type: #FASTPyType opposite: #parentContrainedType'
27+
],
428
#category : 'FAST-Python-Model-Entities',
529
#package : 'FAST-Python-Model',
630
#tag : 'Entities'
@@ -14,3 +38,47 @@ FASTPyConstrainedType class >> annotation [
1438
<generated>
1539
^ self
1640
]
41+
42+
{ #category : 'accessing' }
43+
FASTPyConstrainedType >> bound [
44+
"Relation named: #bound type: #FASTPyType opposite: #parentContrainedTypeBound"
45+
46+
<generated>
47+
^ bound
48+
]
49+
50+
{ #category : 'accessing' }
51+
FASTPyConstrainedType >> bound: anObject [
52+
53+
<generated>
54+
bound := anObject
55+
]
56+
57+
{ #category : 'navigation' }
58+
FASTPyConstrainedType >> boundGroup [
59+
<generated>
60+
<navigation: 'Bound'>
61+
^ MooseSpecializedGroup with: self bound
62+
]
63+
64+
{ #category : 'accessing' }
65+
FASTPyConstrainedType >> type [
66+
"Relation named: #type type: #FASTPyType opposite: #parentContrainedType"
67+
68+
<generated>
69+
^ type
70+
]
71+
72+
{ #category : 'accessing' }
73+
FASTPyConstrainedType >> type: anObject [
74+
75+
<generated>
76+
type := anObject
77+
]
78+
79+
{ #category : 'navigation' }
80+
FASTPyConstrainedType >> typeGroup [
81+
<generated>
82+
<navigation: 'Type'>
83+
^ MooseSpecializedGroup with: self type
84+
]

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

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
3838
| `parentInterpolation` | `FASTPyExpression` | `expression` | `FASTPyInterpolation` | |
3939
| `parentMatchStatement` | `FASTPyExpression` | `subject` | `FASTPyMatchStatement` | |
40-
| `parentType` | `FASTPyExpression` | `expression` | `FASTPyType` | |
40+
| `parentType` | `FASTPyTTypeContent` | `content` | `FASTPyType` | |
4141
| `parentUnaryOperator` | `FASTPyExpression` | `argument` | `FASTPyTUnaryOperator` | Parent unary operator in which I am.|
4242
| `prarentPrintStatement` | `FASTPyExpression` | `expressions` | `FASTPyPrintStatement` | |
4343
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
@@ -58,8 +58,8 @@
5858
Class {
5959
#name : 'FASTPyExpression',
6060
#superclass : 'FASTPyStatement',
61-
#traits : 'FASTTExpression',
62-
#classTraits : 'FASTTExpression classTrait',
61+
#traits : 'FASTPyTTypeContent + FASTTExpression',
62+
#classTraits : 'FASTPyTTypeContent classTrait + FASTTExpression classTrait',
6363
#instVars : [
6464
'#attributeObjectOwner => FMOne type: #FASTPyAttributeAccess opposite: #object',
6565
'#caller => FMOne type: #FASTPyCall opposite: #callee',
@@ -86,7 +86,6 @@ Class {
8686
'#parentExceptClause => FMOne type: #FASTPyExceptClause opposite: #expressions',
8787
'#parentInterpolation => FMOne type: #FASTPyInterpolation opposite: #expression',
8888
'#parentMatchStatement => FMOne type: #FASTPyMatchStatement opposite: #subject',
89-
'#parentType => FMOne type: #FASTPyType opposite: #expression',
9089
'#parentUnaryOperator => FMOne type: #FASTPyTUnaryOperator opposite: #argument',
9190
'#prarentPrintStatement => FMOne type: #FASTPyPrintStatement opposite: #expressions',
9291
'#sliceOwner => FMOne type: #FASTPySlice opposite: #components',
@@ -710,30 +709,6 @@ FASTPyExpression >> parentMatchStatementGroup [
710709
^ MooseSpecializedGroup with: self parentMatchStatement
711710
]
712711

713-
{ #category : 'accessing' }
714-
FASTPyExpression >> parentType [
715-
"Relation named: #parentType type: #FASTPyType opposite: #expression"
716-
717-
<generated>
718-
<container>
719-
<derived>
720-
^ parentType
721-
]
722-
723-
{ #category : 'accessing' }
724-
FASTPyExpression >> parentType: anObject [
725-
726-
<generated>
727-
parentType := anObject
728-
]
729-
730-
{ #category : 'navigation' }
731-
FASTPyExpression >> parentTypeGroup [
732-
<generated>
733-
<navigation: 'ParentType'>
734-
^ MooseSpecializedGroup with: self parentType
735-
]
736-
737712
{ #category : 'accessing' }
738713
FASTPyExpression >> parentUnaryOperator [
739714
"Relation named: #parentUnaryOperator type: #FASTPyTUnaryOperator opposite: #argument"

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| `parameters` | `FASTTWithParameters` | `parameterOwner` | `FASTTVariableEntity` | My parameters|
1515
| `returnType` | `FASTPyFunctionDefinition` | `parentFunctionDefinition` | `FASTPyType` | |
1616
| `statementBlock` | `FASTTWithStatements` | `fastBehaviouralParent` | `FASTTStatementBlock` | Statements block of the behavioural entity|
17+
| `typeParameters` | `FASTPyTWithTypeParameters` | `parentWithTypeParameters` | `FASTPyType` | |
1718
1819
1920
## Properties
@@ -29,8 +30,8 @@
2930
Class {
3031
#name : 'FASTPyFunctionDefinition',
3132
#superclass : 'FASTPyStatement',
32-
#traits : 'FASTPyTDefinition',
33-
#classTraits : 'FASTPyTDefinition classTrait',
33+
#traits : 'FASTPyTDefinition + FASTPyTWithTypeParameters',
34+
#classTraits : 'FASTPyTDefinition classTrait + FASTPyTWithTypeParameters classTrait',
3435
#instVars : [
3536
'#returnType => FMOne type: #FASTPyType opposite: #parentFunctionDefinition'
3637
],

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `parentType` | `FASTPyTTypeContent` | `content` | `FASTPyType` | |
9+
10+
### Children
11+
| Relation | Origin | Opposite | Type | Comment |
12+
|---|
13+
| `typeParameters` | `FASTPyTWithTypeParameters` | `parentWithTypeParameters` | `FASTPyType` | |
14+
15+
16+
17+
"
118
Class {
219
#name : 'FASTPyGenericType',
320
#superclass : 'FASTPyEntity',
21+
#traits : 'FASTPyTTypeContent + FASTPyTWithTypeParameters',
22+
#classTraits : 'FASTPyTTypeContent classTrait + FASTPyTWithTypeParameters classTrait',
423
#category : 'FAST-Python-Model-Entities',
524
#package : 'FAST-Python-Model',
625
#tag : 'Entities'

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| `decorators` | `FASTPyTDefinition` | `definitionOwner` | `FASTPyDecorator` | |
1414
| `parameters` | `FASTTWithParameters` | `parameterOwner` | `FASTTVariableEntity` | My parameters|
1515
| `statementBlock` | `FASTTWithStatements` | `fastBehaviouralParent` | `FASTTStatementBlock` | Statements block of the behavioural entity|
16+
| `typeParameters` | `FASTPyTWithTypeParameters` | `parentWithTypeParameters` | `FASTPyType` | |
1617
1718
1819
## Properties
@@ -28,8 +29,8 @@
2829
Class {
2930
#name : 'FASTPyMethodDefinition',
3031
#superclass : 'FASTPyStatement',
31-
#traits : 'FASTPyTDefinition',
32-
#classTraits : 'FASTPyTDefinition classTrait',
32+
#traits : 'FASTPyTDefinition + FASTPyTWithTypeParameters',
33+
#classTraits : 'FASTPyTDefinition classTrait + FASTPyTWithTypeParameters classTrait',
3334
#category : 'FAST-Python-Model-Entities',
3435
#package : 'FAST-Python-Model',
3536
#tag : 'Entities'

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,13 @@ FASTPyTEntityCreator >> newTypeConversion [
720720
^ self add: FASTPyTypeConversion new
721721
]
722722

723+
{ #category : 'entity creation' }
724+
FASTPyTEntityCreator >> newTypeParameter [
725+
726+
<generated>
727+
^ self add: FASTPyTypeParameter new
728+
]
729+
723730
{ #category : 'entity creation' }
724731
FASTPyTEntityCreator >> newUnaryOperator [
725732

0 commit comments

Comments
 (0)