Skip to content

Commit

Permalink
Clean management of FieldAccessExpressionNode
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Dec 11, 2024
1 parent cf70289 commit f04f996
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
16 changes: 16 additions & 0 deletions src/Famix-Python-Importer/FamixPythonImportPathNode.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"
I reperesent a specialization of `PyFieldAccessExpressionNode`. I represent a path in an import.
"
Class {
#name : 'FamixPythonImportPathNode',
#superclass : 'PyFieldAccessExpressionNode',
#category : 'Famix-Python-Importer-Nodes',
#package : 'Famix-Python-Importer',
#tag : 'Nodes'
}

{ #category : 'generated' }
FamixPythonImportPathNode >> acceptVisitor: aRootVisitor [

^ aRootVisitor visitImportPath: self
]
8 changes: 1 addition & 7 deletions src/Famix-Python-Importer/FamixPythonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ FamixPythonImporter >> importFileReference: aFileReference [
files first isPythonPackageDeclaration ifTrue: [ visitor popScope ] ].
^ self ].

(self isPythonExtension: aFileReference extension) ifFalse: [ ^ self ].
aFileReference extension = 'py' ifFalse: [ ^ self ].

self importPythonFile: aFileReference
]
Expand All @@ -82,12 +82,6 @@ FamixPythonImporter >> importPythonFile: aFileReference [
(PythonParser parseFileWithErrors: aFileReference) acceptVisitor: visitor
]

{ #category : 'testing' }
FamixPythonImporter >> isPythonExtension: aString [

^aString = 'py'
]

{ #category : 'accessing' }
FamixPythonImporter >> visitor [

Expand Down
12 changes: 9 additions & 3 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,12 @@ FamixPythonImporterVisitor >> visitFunctionDefinition: aFunctionDefinition [
^ self useCurrentEntity: fmx during: [ super visitFunctionDefinition: aFunctionDefinition ]
]

{ #category : 'generated' }
FamixPythonImporterVisitor >> visitImportPath: anImportPath [

^ anImportPath source
]

{ #category : 'visiting' }
FamixPythonImporterVisitor >> visitImportStatement: anImport [

Expand Down Expand Up @@ -920,9 +926,9 @@ FamixPythonImporterVisitor >> visitVariableExpression: aVariableExpression [
notFoundReplacementEntity: [ :unresolved :currentEntity | "1 halt." self ensureStubUnknownAccessedOrReferencedEntityNamed: unresolved identifier ];
yourself)
foundAction: [ :entity :currentEntity |
self flag: #todo. "The ifNotNil should be removed later."
(entity createAccessOrReferenceFrom: currentEntity node: aVariableExpression) ifNotNil: [ :association |
self setSourceAnchor: association from: aVariableExpression ] ].
| association |
association := entity createAccessOrReferenceFrom: currentEntity node: aVariableExpression.
self setSourceAnchor: association from: aVariableExpression ].

^ aVariableExpression name
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Class {
FamixPythonSmaCCASTSpecializer >> visitFieldAccessExpression: aFieldAccessExpression [
"This node is used in multiple situations. I am trying to remove some ambiguity by specializing the nodes."

aFieldAccessExpression isInstanceVariableAssignation ifTrue: [ ^ FamixPythonAssignedInstanceVariableNode adoptInstance: aFieldAccessExpression ]
aFieldAccessExpression isInstanceVariableAssignation ifTrue: [ ^ FamixPythonAssignedInstanceVariableNode adoptInstance: aFieldAccessExpression ].

aFieldAccessExpression isInImport ifTrue: [ ^ FamixPythonImportPathNode adoptInstance: aFieldAccessExpression ]
]

{ #category : 'generated' }
Expand Down
6 changes: 6 additions & 0 deletions src/Famix-Python-Importer/PyRootNode.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ PyRootNode >> isImport [
^ false
]

{ #category : '*Famix-Python-Importer' }
PyRootNode >> isInImport [

^ self parent isImport
]

{ #category : '*Famix-Python-Importer' }
PyRootNode >> isLeftSideOfAssignation: aNode [

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
Extension { #name : 'PyVariableExpressionNode' }

{ #category : '*Famix-Python-Importer' }
PyVariableExpressionNode >> isInImport [

^ self parent isImport
]

{ #category : '*Famix-Python-Importer' }
PyVariableExpressionNode >> isLeftSideOfAssignation [

Expand Down
5 changes: 5 additions & 0 deletions src/Famix-Python-Importer/TPyRootNodeVisitor.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ TPyRootNodeVisitor >> visitFunctionCallReceiverVariable: aFunctionCallReceiverVa
^ self visitVariableExpression: aFunctionCallReceiverVariable
]

{ #category : '*Famix-Python-Importer' }
TPyRootNodeVisitor >> visitImportPath: anImportPath [
^ self visitExpression: anImportPath
]

{ #category : '*Famix-Python-Importer' }
TPyRootNodeVisitor >> visitImportVariableExpression: anImportVariableExpression [

Expand Down

0 comments on commit f04f996

Please sign in to comment.