Skip to content

Commit

Permalink
First test on invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jan 6, 2025
1 parent 1ec7508 commit 929a77f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Famix-Python-Entities/FamixPythonClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| Relation | Origin | Opposite | Type | Comment |
|---|
| `accesses` | `FamixTWithAccesses` | `accessor` | `FamixTAccess` | Accesses to variables made by this behaviour.|
| `outgoingInvocations` | `FamixTWithInvocations` | `sender` | `FamixTInvocation` | Outgoing invocations sent by this behaviour.|
| `outgoingReferences` | `FamixTWithReferences` | `referencer` | `FamixTReference` | References from this entity to other entities.|
| `superInheritances` | `FamixTWithInheritances` | `subclass` | `FamixTInheritance` | Superinheritance relationships, i.e. known superclasses of this type.|
Expand Down Expand Up @@ -55,8 +56,8 @@
Class {
#name : 'FamixPythonClass',
#superclass : 'FamixPythonType',
#traits : 'FamixTClass + FamixTImportable + FamixTShadowable + FamixTShadower + FamixTWithAccesses + FamixTWithAnnotationInstances + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTClass classTrait + FamixTImportable classTrait + FamixTShadowable classTrait + FamixTShadower classTrait + FamixTWithAccesses classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#traits : 'FamixTClass + FamixTImportable + FamixTShadowable + FamixTShadower + FamixTWithAccesses + FamixTWithAnnotationInstances + FamixTWithInvocations + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTClass classTrait + FamixTImportable classTrait + FamixTShadowable classTrait + FamixTShadower classTrait + FamixTWithAccesses classTrait + FamixTWithAnnotationInstances classTrait + FamixTWithInvocations classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#instVars : [
'#instancedClasses => FMMany type: #FamixPythonClass opposite: #metaclass',
'#isMetaclass => FMProperty',
Expand Down
5 changes: 3 additions & 2 deletions src/Famix-Python-Entities/FamixPythonPackage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
| Relation | Origin | Opposite | Type | Comment |
|---|
| `accesses` | `FamixTWithAccesses` | `accessor` | `FamixTAccess` | Accesses to variables made by this behaviour.|
| `outgoingInvocations` | `FamixTWithInvocations` | `sender` | `FamixTInvocation` | Outgoing invocations sent by this behaviour.|
| `outgoingReferences` | `FamixTWithReferences` | `referencer` | `FamixTReference` | References from this entity to other entities.|
### Incoming dependencies
Expand All @@ -46,8 +47,8 @@
Class {
#name : 'FamixPythonPackage',
#superclass : 'FamixPythonContainerEntity',
#traits : 'FamixTImportable + FamixTPackage + FamixTPackageable + FamixTReferenceable + FamixTWithAccesses + FamixTWithComments + FamixTWithFunctions + FamixTWithGlobalVariables + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTImportable classTrait + FamixTPackage classTrait + FamixTPackageable classTrait + FamixTReferenceable classTrait + FamixTWithAccesses classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithGlobalVariables classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#traits : 'FamixTImportable + FamixTPackage + FamixTPackageable + FamixTReferenceable + FamixTWithAccesses + FamixTWithComments + FamixTWithFunctions + FamixTWithGlobalVariables + FamixTWithInvocations + FamixTWithLambdas + FamixTWithReferences',
#classTraits : 'FamixTImportable classTrait + FamixTPackage classTrait + FamixTPackageable classTrait + FamixTReferenceable classTrait + FamixTWithAccesses classTrait + FamixTWithComments classTrait + FamixTWithFunctions classTrait + FamixTWithGlobalVariables classTrait + FamixTWithInvocations classTrait + FamixTWithLambdas classTrait + FamixTWithReferences classTrait',
#category : 'Famix-Python-Entities-Entities',
#package : 'Famix-Python-Entities',
#tag : 'Entities'
Expand Down
2 changes: 2 additions & 0 deletions src/Famix-Python-Generator/FamixPythonGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ FamixPythonGenerator >> defineHierarchy [
class --|> #TShadower.
class --|> #TWithAccesses.
class --|> #TWithReferences.
class --|> #TWithInvocations.

containerEntity --|> namedEntity.
containerEntity --|> #TWithClasses.
Expand Down Expand Up @@ -185,6 +186,7 @@ FamixPythonGenerator >> defineHierarchy [
package --|> #TWithAccesses.
package --|> #TWithReferences.
package --|> #TReferenceable.
package --|> #TWithInvocations.

parameter --|> namedEntity.
parameter --|> #TParameter.
Expand Down
23 changes: 20 additions & 3 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,23 @@ FamixPythonProject1Test >> testFunctionInAPackage [
self assert: function functionOwner equals: (self packageNamed: 'subsubpackage1')
]

{ #category : 'tests - invocations' }
FamixPythonProject1Test >> testFunctionInvocationFromModule [

| module function invocation |
function := self functionNamed: 'function_printing_arg'.
module := self moduleNamed: 'moduleAtRoot'.

invocation := function incomingInvocations detect: [ :aReference | aReference sender = module ].

self assert: invocation class equals: FamixPythonInvocation.
self assert: invocation source equals: module.
self assert: invocation sender equals: module.
self assertCollection: invocation target hasSameElements: { function }.
self assert: invocation anyCandidate equals: function.
self assert: (module outgoingInvocations anySatisfy: [ :aReference | aReference anyCandidate = function ])
]

{ #category : 'tests - references' }
FamixPythonProject1Test >> testFunctionReferenceFromClass [

Expand Down Expand Up @@ -1019,9 +1036,9 @@ FamixPythonProject1Test >> testFunctionSourceAnchor [

self assert: function sourceAnchor isNotNil.
self assert: function sourceText equals: ('def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z' copyReplaceAll: String cr with: String lf)
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z' copyReplaceAll: String cr with: String lf)
]

{ #category : 'tests - functions' }
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Python-Importer/FamixPythonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FamixPythonImporter >> importFileReference: aFileReference [
FamixPythonImporter >> importPythonFile: aFileReference [

('Importing ' , aFileReference pathString) traceCr.
"(aFileReference basename = #'moduleAtRoot6.py') ifTrue: [ 1halt ]."
"(aFileReference basename = #'moduleAtRoot.py') ifTrue: [ 1halt ]."
(PythonParser parseFileWithErrors: aFileReference) acceptVisitor: visitor
]

Expand Down
33 changes: 33 additions & 0 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ FamixPythonImporterVisitor >> ensureStubContainerNamed: aString [
yourself ]
]

{ #category : 'private-entity-creation' }
FamixPythonImporterVisitor >> ensureStubFunctionNamed: aName [

^ model allFunctions
detect: [ :function | function isStub and: [ function name = aName ] ]
ifNone: [
(model newFunctionNamed: aName)
isStub: true;
yourself ]
]

{ #category : 'private-entity-creation' }
FamixPythonImporterVisitor >> ensureStubPackageNamed: aString [

Expand Down Expand Up @@ -811,6 +822,28 @@ FamixPythonImporterVisitor >> visitFile: aFileNode [
ifFalse: [ self popScope ]
]

{ #category : 'visiting' }
FamixPythonImporterVisitor >> visitFunctionCallExpression: aFunctionCallExpression [

self flag: #todo. "Temporary hack"
(aFunctionCallExpression receiver isKindOf: PyFunctionCallExpressionNode) ifFalse: [
self
resolve: ((SRInvocationWithNode identifier: aFunctionCallExpression receiver name)
expectedKind: FamixPythonFunction;
notFoundReplacementEntity: [ :unresolved :currentEntity | unresolved identifier = 'inner_function' ifTrue: [ 1halt ]. "1 halt." { (self ensureStubFunctionNamed: unresolved identifier) } ];
yourself)
foundAction: [ :entities :currentEntity |
| invocation |
invocation := self model newInvocation
candidates: entities;
sender: currentEntity;
yourself.
self setSourceAnchor: invocation from: aFunctionCallExpression ] ].


^ super visitFunctionCallExpression: aFunctionCallExpression
]

{ #category : 'visiting' }
FamixPythonImporterVisitor >> visitFunctionCallReceiverVariable: aFunctionCallReceiverVariable [

Expand Down

0 comments on commit 929a77f

Please sign in to comment.