Skip to content

Commit 9f34d2b

Browse files
committed
Save parameters individually
1 parent 409e448 commit 9f34d2b

7 files changed

Lines changed: 91 additions & 24 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Class {
8888
'nonlocalStatement',
8989
'notOperator',
9090
'pair',
91-
'parameters',
91+
'parameter',
9292
'parenthesizedExpression',
9393
'parenthesizedListSplat',
9494
'passStatement',
@@ -130,7 +130,8 @@ Class {
130130
'yield',
131131
'tComment',
132132
'tNamedBehaviouralEntity',
133-
'tNamedEntity'
133+
'tNamedEntity',
134+
'tVariableEntity'
134135
],
135136
#category : 'FAST-Python-Model-Generator',
136137
#package : 'FAST-Python-Model-Generator'
@@ -242,7 +243,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
242243
nonlocalStatement := builder ensureClassNamed: #NonlocalStatement.
243244
notOperator := builder ensureClassNamed: #NotOperator.
244245
pair := builder ensureClassNamed: #Pair.
245-
parameters := builder ensureClassNamed: #Parameters.
246+
parameter := builder ensureClassNamed: #Parameter.
246247
parenthesizedExpression := builder ensureClassNamed: #ParenthesizedExpression.
247248
parenthesizedListSplat := builder ensureClassNamed: #ParenthesizedListSplat.
248249
passStatement := builder ensureClassNamed: #PassStatement.
@@ -296,6 +297,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
296297

297298
functionDefinition --|> tNamedBehaviouralEntity.
298299

300+
parameter --|> tVariableEntity.
301+
299302
module --|> #THasImmediateSource.
300303
"module withPrecedenceOf: #THasImmediateSource."
301304
]
@@ -319,7 +322,7 @@ FASTPythonMetamodelGenerator >> defineTraits [
319322
tNamedBehaviouralEntity := self remoteTrait: #TNamedBehaviouralEntity withPrefix: #FAST.
320323
tNamedEntity := self remoteTrait: #TNamedEntity withPrefix: #FAST.
321324
"tScopableEntity := self remoteTrait: #TScopableEntity withPrefix: #FAST.
322-
tVariableEntity := self remoteTrait: #TVariableEntity withPrefix: #FAST.
323-
tWithComments := self remoteTrait: #TWithComments withPrefix: #FAST.
324-
tWithParameters := self remoteTrait: #TWithParameters withPrefix: #FAST."
325+
"tVariableEntity := self remoteTrait: #TVariableEntity withPrefix: #FAST."
326+
tWithComments := self remoteTrait: #TWithComments withPrefix: #FAST."
327+
"tWithParameters := self remoteTrait: #TWithParameters withPrefix: #FAST."
325328
]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,10 @@ FASTPythonEntity >> isScopableEntity [
132132
<generated>
133133
^ false
134134
]
135+
136+
{ #category : 'testing' }
137+
FASTPythonEntity >> isVariableEntity [
138+
139+
<generated>
140+
^ false
141+
]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
| `parameterOwner` | `FASTTVariableEntity` | `parameters` | `FASTTWithParameters` | parameterOwner|
10+
| `parentAssignmentExpression` | `FASTTVariableEntity` | `variable` | `FASTTAssignment` | Optional assignment to the variable|
11+
12+
13+
## Properties
14+
======================
15+
16+
| Name | Type | Default value | Comment |
17+
|---|
18+
| `endPos` | `Number` | nil | |
19+
| `name` | `String` | nil | |
20+
| `startPos` | `Number` | nil | |
21+
22+
"
23+
Class {
24+
#name : 'FASTPythonParameter',
25+
#superclass : 'FASTPythonEntity',
26+
#traits : 'FASTTVariableEntity',
27+
#classTraits : 'FASTTVariableEntity classTrait',
28+
#category : 'FAST-Python-Model-Entities',
29+
#package : 'FAST-Python-Model',
30+
#tag : 'Entities'
31+
}
32+
33+
{ #category : 'meta' }
34+
FASTPythonParameter class >> annotation [
35+
36+
<FMClass: #Parameter super: #FASTPythonEntity>
37+
<package: #'FAST-Python-Model'>
38+
<generated>
39+
^ self
40+
]

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,10 @@ FASTPythonTEntityCreator >> newPair [
609609
]
610610

611611
{ #category : 'entity creation' }
612-
FASTPythonTEntityCreator >> newParameters [
612+
FASTPythonTEntityCreator >> newParameter [
613613

614614
<generated>
615-
^ self add: FASTPythonParameters new
615+
^ self add: FASTPythonParameter new
616616
]
617617

618618
{ #category : 'entity creation' }

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ FASTPythonImporterTest >> setUp [
2626
importer := FASTPythonImporter new
2727
]
2828

29+
{ #category : 'tests' }
30+
FASTPythonImporterTest >> testFileWithAFunctionDefinition [
31+
32+
self parse: 'def test():
33+
return 1'.
34+
35+
self assert: (fast allWithType: FASTPythonModule) size equals: 1.
36+
self assert: (fast allWithType: FASTPythonFunctionDefinition) size equals: 1
37+
]
38+
39+
{ #category : 'tests' }
40+
FASTPythonImporterTest >> testFileWithAFunctionDefinitionAndParameters [
41+
42+
| function |
43+
self parse: 'def add(a, b):
44+
return a + b'.
45+
46+
self assert: (fast allWithType: FASTPythonModule) size equals: 1.
47+
self assert: (fast allWithType: FASTPythonFunctionDefinition) size equals: 1.
48+
function := (fast allWithType: FASTPythonFunctionDefinition) anyOne.
49+
50+
self assert: (fast allWithType: FASTPythonParameter) size equals: 2.
51+
self assertCollection: (fast allWithType: FASTPythonParameter) hasSameElements: function parameters.
52+
function parameters do: [ :parameter | self assert: (parameter isOfType: FASTPythonParameter) ]
53+
]
54+
2955
{ #category : 'tests' }
3056
FASTPythonImporterTest >> testFileWithOneComment [
3157

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ TSFASTPythonImporter >> initialize [
1111
super initialize.
1212
self languageName: 'Python'
1313
]
14+
15+
{ #category : 'visiting' }
16+
TSFASTPythonImporter >> visitParameters: aNode [
17+
"For parameters we want one by parameter. Not one node for multiple ones."
18+
19+
aNode collectNamedChild do: [ :parameterNode | self createEntityForNode: parameterNode kind: FASTPythonParameter parentManagementBlock: [ :entity :parent | parent addParameter: entity ] ]
20+
]

0 commit comments

Comments
 (0)