From f04f996b3b478f58eab1ed0a67d508aade6bf180 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Wed, 11 Dec 2024 17:40:06 +0100 Subject: [PATCH] Clean management of FieldAccessExpressionNode --- .../FamixPythonImportPathNode.class.st | 16 ++++++++++++++++ .../FamixPythonImporter.class.st | 8 +------- .../FamixPythonImporterVisitor.class.st | 12 +++++++++--- .../FamixPythonSmaCCASTSpecializer.class.st | 4 +++- .../PyRootNode.extension.st | 6 ++++++ .../PyVariableExpressionNode.extension.st | 6 ------ .../TPyRootNodeVisitor.extension.st | 5 +++++ 7 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 src/Famix-Python-Importer/FamixPythonImportPathNode.class.st diff --git a/src/Famix-Python-Importer/FamixPythonImportPathNode.class.st b/src/Famix-Python-Importer/FamixPythonImportPathNode.class.st new file mode 100644 index 0000000..c4a3b00 --- /dev/null +++ b/src/Famix-Python-Importer/FamixPythonImportPathNode.class.st @@ -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 +] diff --git a/src/Famix-Python-Importer/FamixPythonImporter.class.st b/src/Famix-Python-Importer/FamixPythonImporter.class.st index 8825280..6825f18 100644 --- a/src/Famix-Python-Importer/FamixPythonImporter.class.st +++ b/src/Famix-Python-Importer/FamixPythonImporter.class.st @@ -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 ] @@ -82,12 +82,6 @@ FamixPythonImporter >> importPythonFile: aFileReference [ (PythonParser parseFileWithErrors: aFileReference) acceptVisitor: visitor ] -{ #category : 'testing' } -FamixPythonImporter >> isPythonExtension: aString [ - - ^aString = 'py' -] - { #category : 'accessing' } FamixPythonImporter >> visitor [ diff --git a/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st b/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st index 19a59af..4d2c17c 100644 --- a/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st +++ b/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st @@ -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 [ @@ -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 ] diff --git a/src/Famix-Python-Importer/FamixPythonSmaCCASTSpecializer.class.st b/src/Famix-Python-Importer/FamixPythonSmaCCASTSpecializer.class.st index 3165a16..59a7a33 100644 --- a/src/Famix-Python-Importer/FamixPythonSmaCCASTSpecializer.class.st +++ b/src/Famix-Python-Importer/FamixPythonSmaCCASTSpecializer.class.st @@ -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' } diff --git a/src/Famix-Python-Importer/PyRootNode.extension.st b/src/Famix-Python-Importer/PyRootNode.extension.st index 245d1b6..e039c3d 100644 --- a/src/Famix-Python-Importer/PyRootNode.extension.st +++ b/src/Famix-Python-Importer/PyRootNode.extension.st @@ -41,6 +41,12 @@ PyRootNode >> isImport [ ^ false ] +{ #category : '*Famix-Python-Importer' } +PyRootNode >> isInImport [ + + ^ self parent isImport +] + { #category : '*Famix-Python-Importer' } PyRootNode >> isLeftSideOfAssignation: aNode [ diff --git a/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st b/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st index 7c8f4fa..de6083f 100644 --- a/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st +++ b/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st @@ -1,11 +1,5 @@ Extension { #name : 'PyVariableExpressionNode' } -{ #category : '*Famix-Python-Importer' } -PyVariableExpressionNode >> isInImport [ - - ^ self parent isImport -] - { #category : '*Famix-Python-Importer' } PyVariableExpressionNode >> isLeftSideOfAssignation [ diff --git a/src/Famix-Python-Importer/TPyRootNodeVisitor.extension.st b/src/Famix-Python-Importer/TPyRootNodeVisitor.extension.st index 537d4bf..9584fa1 100644 --- a/src/Famix-Python-Importer/TPyRootNodeVisitor.extension.st +++ b/src/Famix-Python-Importer/TPyRootNodeVisitor.extension.st @@ -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 [