Skip to content

Commit 46da1d4

Browse files
committed
Manage splat type
1 parent a24cafa commit 46da1d4

4 files changed

Lines changed: 96 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
522522

523523
slice --|> expression.
524524

525+
splatType --|> tTypeContent.
526+
splatType --|> tNamedEntity.
527+
525528
statement --|> tStatement.
526529

527530
string --|> literal.

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `invokedIn` | `FASTTNamedEntity` | `invoked` | `FASTTInvocation` | Optional invocation where this name is used|
9+
| `parentType` | `FASTPyTTypeContent` | `content` | `FASTPyType` | |
10+
11+
12+
## Properties
13+
======================
14+
15+
| Name | Type | Default value | Comment |
16+
|---|
17+
| `endPos` | `Number` | nil | |
18+
| `name` | `String` | nil | |
19+
| `startPos` | `Number` | nil | |
20+
21+
"
122
Class {
223
#name : 'FASTPySplatType',
324
#superclass : 'FASTPyEntity',
25+
#traits : 'FASTPyTTypeContent + FASTTNamedEntity',
26+
#classTraits : 'FASTPyTTypeContent classTrait + FASTTNamedEntity classTrait',
427
#category : 'FAST-Python-Model-Entities',
528
#package : 'FAST-Python-Model',
629
#tag : 'Entities'

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21406,6 +21406,73 @@ FASTPythonImporterTest >> testSliceWithStep [
2140621406
self assert: (self topEntity isOfType: FASTPyIdentifier)
2140721407
]
2140821408

21409+
{ #category : 'tests - types' }
21410+
FASTPythonImporterTest >> testSplatType [
21411+
<generated>
21412+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
21413+
Regenerate executing: self regenerateTest: #testSplatType "
21414+
21415+
self parse: 'def f(*items: *Ts): pass'.
21416+
21417+
self assert: (fast allWithType: FASTPyBlock) size equals: 1.
21418+
self assert: (fast allWithType: FASTPyFunctionDefinition) size equals: 1.
21419+
self assert: (fast allWithType: FASTPyListSplatParameter) size equals: 1.
21420+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
21421+
self assert: (fast allWithType: FASTPyPassStatement) size equals: 1.
21422+
self assert: (fast allWithType: FASTPySplatType) size equals: 1.
21423+
self assert: (fast allWithType: FASTPyType) size equals: 1.
21424+
21425+
stack push: fast rootEntities anyOne containedEntities first.
21426+
self assert: self topEntity sourceCode equals: 'def f(*items: *Ts): pass'.
21427+
self assert: (self topEntity isOfType: FASTPyFunctionDefinition).
21428+
self assert: (self topEntity isOfType: FASTPyTDefinition).
21429+
self assert: (self topEntity isOfType: FASTTWithParameters).
21430+
self assert: (self topEntity isOfType: FASTTWithStatements).
21431+
self assert: self topEntity name equals: 'f'.
21432+
21433+
"Testing value of multivalued relation parameters"
21434+
self assert: self topEntity parameters size equals: 1.
21435+
21436+
stack push: (stack top parameters at: 1).
21437+
self assert: self topEntity sourceCode equals: '*items: *Ts'.
21438+
self assert: (self topEntity isOfType: FASTPyListSplatParameter).
21439+
self assert: (self topEntity isOfType: FASTTVariableEntity).
21440+
self assert: self topEntity name equals: 'items'.
21441+
21442+
"Testing value of monovalue relation type"
21443+
self assert: self topEntity type isNotNil.
21444+
21445+
stack push: self topEntity type.
21446+
self assert: self topEntity sourceCode equals: '*Ts'.
21447+
self assert: (self topEntity isOfType: FASTPyType).
21448+
21449+
"Testing value of monovalue relation content"
21450+
self assert: self topEntity content isNotNil.
21451+
21452+
stack push: self topEntity content.
21453+
self assert: self topEntity sourceCode equals: '*Ts'.
21454+
self assert: (self topEntity isOfType: FASTPySplatType).
21455+
self assert: self topEntity name equals: 'Ts'.
21456+
stack pop.
21457+
stack pop.
21458+
stack pop.
21459+
21460+
"Testing value of monovalue relation statementBlock"
21461+
self assert: self topEntity statementBlock isNotNil.
21462+
21463+
stack push: self topEntity statementBlock.
21464+
self assert: self topEntity sourceCode equals: 'pass'.
21465+
self assert: (self topEntity isOfType: FASTPyBlock).
21466+
self assert: (self topEntity isOfType: FASTTStatementBlock).
21467+
21468+
"Testing value of multivalued relation statements"
21469+
self assert: self topEntity statements size equals: 1.
21470+
21471+
stack push: (stack top statements at: 1).
21472+
self assert: self topEntity sourceCode equals: 'pass'.
21473+
self assert: (self topEntity isOfType: FASTPyPassStatement)
21474+
]
21475+
2140921476
{ #category : 'tests - literals' }
2141021477
FASTPythonImporterTest >> testStringWithEscapedInterpolation [
2141121478
<generated>

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,9 @@ TSFASTPythonImporter >> isInParameter: aNode [
7070
{ #category : 'testing' }
7171
TSFASTPythonImporter >> shouldIdentifierSetNameProperty [
7272

73-
(context top isOfFASTType: FASTPyGenericType) ifTrue: [ ^ true ].
74-
75-
^ context top field = #name and: [
76-
{
77-
FASTPyMethodDefinition.
78-
FASTPyClassDefinition.
79-
FASTPyFunctionDefinition.
80-
FASTPyKeywordArgument } anySatisfy: [ :class | context top isOfFASTType: class ] ]
73+
({ FASTPyGenericType. FASTPySplatType } anySatisfy: [ :class | context top isOfFASTType: class ]) ifTrue: [ ^ true ].
74+
75+
^ context top field = #name and: [ context top isOfFASTType: FASTTNamedEntity ]
8176
]
8277

8378
{ #category : 'visiting - skip' }

0 commit comments

Comments
 (0)