diff --git a/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st b/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st index 23e900b..1ce014b 100644 --- a/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st +++ b/src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st @@ -5,8 +5,7 @@ Class { #classTraits : 'SRTSolverUserVisitor classTrait', #instVars : [ 'model', - 'rootFilePath', - 'isInLeftSideOfAssignation' + 'rootFilePath' ], #category : 'Famix-Python-Importer-Visitors', #package : 'Famix-Python-Importer', @@ -464,8 +463,7 @@ FamixPythonImporterVisitor >> initialize [ super initialize. model := FamixPythonModel new name: 'default Python Model'. - self initialiseSolver. - isInLeftSideOfAssignation := false "In Python variables are created during their assignation. So it is good to know if some nodes are visited during this assignation." + self initialiseSolver ] { #category : 'private - searching' } @@ -668,10 +666,6 @@ FamixPythonImporterVisitor >> unknownImportedNamed: aString [ { #category : 'visiting' } FamixPythonImporterVisitor >> visitAssignmentExpression: anAssignmentExpression [ - | oldValue | - oldValue := isInLeftSideOfAssignation. - isInLeftSideOfAssignation := true. - [ | variable | variable := self acceptNode: anAssignmentExpression variable. variable isMooseEntity @@ -683,17 +677,13 @@ FamixPythonImporterVisitor >> visitAssignmentExpression: anAssignmentExpression accessor: self currentEntity; isWrite: true. self setSourceAnchor: access from: anAssignmentExpression ] - ifFalse: [ self flag: #todo "Is it normal?" ] ] ensure: [ isInLeftSideOfAssignation := oldValue ]. + ifFalse: [ self flag: #todo "Is it normal?" ]. ^ super visitAssignmentExpression: anAssignmentExpression ] { #category : 'visiting' } FamixPythonImporterVisitor >> visitAssignmentStatement: anAssignmentStatement [ - | oldValue | - oldValue := isInLeftSideOfAssignation. - isInLeftSideOfAssignation := true. - [ | variables | variables := self acceptNode: anAssignmentStatement lhs. "It is possible in case of multiple assignations that we end up with a collection of variables while visiting the left side of an assignation. Else we will have only one assignation. The next line is to make sure of the type of entity we have." @@ -708,7 +698,7 @@ FamixPythonImporterVisitor >> visitAssignmentStatement: anAssignmentStatement [ accessor: self currentEntity; isWrite: true. self setSourceAnchor: access from: anAssignmentStatement ] - ifFalse: [ self flag: #todo "Is it normal?" ] ] ] ensure: [ isInLeftSideOfAssignation := oldValue ]. + ifFalse: [ self flag: #todo "Is it normal?" ] ]. ^ super visitAssignmentStatement: anAssignmentStatement ] @@ -722,7 +712,7 @@ FamixPythonImporterVisitor >> visitClassDefinition: aClassDef [ FamixPythonImporterVisitor >> visitFieldAccessExpression: aFieldAccessExpression [ "If the receiver is self in an assignation then we have an assignation to an instance variable" - (isInLeftSideOfAssignation and: [ aFieldAccessExpression receiver isSelf ]) ifTrue: [ + aFieldAccessExpression isInstanceVariableAssignation ifTrue: [ | class | class := self currentEntityOfType: FamixPythonClass. @@ -870,7 +860,7 @@ FamixPythonImporterVisitor >> visitString: aStringNode [ FamixPythonImporterVisitor >> visitVariableExpression: aVariableExpression [ "This node is used in multiple situations. If it is in an assignation we need to check if the variable we assign is created. Other uses can be for example in an import, in this case we want to only return the name." - isInLeftSideOfAssignation ifTrue: [ "If we have a variable of this name already, we should not recreate it. Except if this variable got shadowed! In that case, we should recreate it." + aVariableExpression isLeftSideOfAssignation ifTrue: [ "If we have a variable of this name already, we should not recreate it. Except if this variable got shadowed! In that case, we should recreate it." ^ (self currentEntity query descendants ofType: FamixTStructuralEntity) detect: [ :child | child name = aVariableExpression name and: [ child isShadowable not or: [ child isShadowed not ] ] ] ifNone: [ diff --git a/src/Famix-Python-Importer/PyAssignmentExpressionNode.extension.st b/src/Famix-Python-Importer/PyAssignmentExpressionNode.extension.st new file mode 100644 index 0000000..4f1edf2 --- /dev/null +++ b/src/Famix-Python-Importer/PyAssignmentExpressionNode.extension.st @@ -0,0 +1,7 @@ +Extension { #name : 'PyAssignmentExpressionNode' } + +{ #category : '*Famix-Python-Importer' } +PyAssignmentExpressionNode >> isLeftSideOfAssignation: aNode [ + + ^ self variable = aNode +] diff --git a/src/Famix-Python-Importer/PyAssignmentStatementNode.extension.st b/src/Famix-Python-Importer/PyAssignmentStatementNode.extension.st new file mode 100644 index 0000000..ff2f8c4 --- /dev/null +++ b/src/Famix-Python-Importer/PyAssignmentStatementNode.extension.st @@ -0,0 +1,7 @@ +Extension { #name : 'PyAssignmentStatementNode' } + +{ #category : '*Famix-Python-Importer' } +PyAssignmentStatementNode >> isLeftSideOfAssignation: aNode [ + + ^ self lhs = aNode +] diff --git a/src/Famix-Python-Importer/PyFieldAccessExpressionNode.extension.st b/src/Famix-Python-Importer/PyFieldAccessExpressionNode.extension.st index c575551..9b07790 100644 --- a/src/Famix-Python-Importer/PyFieldAccessExpressionNode.extension.st +++ b/src/Famix-Python-Importer/PyFieldAccessExpressionNode.extension.st @@ -1,5 +1,15 @@ Extension { #name : 'PyFieldAccessExpressionNode' } +{ #category : '*Famix-Python-Importer' } +PyFieldAccessExpressionNode >> isInstanceVariableAssignation [ + + self parent + ifNil: [ ^ false ] + ifNotNil: [ :node | (node isLeftSideOfAssignation: self) ifFalse: [ ^ false ] ]. + + ^ self receiver isSelf +] + { #category : '*Famix-Python-Importer' } PyFieldAccessExpressionNode >> isSelf [ diff --git a/src/Famix-Python-Importer/PyListExpressionNode.extension.st b/src/Famix-Python-Importer/PyListExpressionNode.extension.st new file mode 100644 index 0000000..f13f32f --- /dev/null +++ b/src/Famix-Python-Importer/PyListExpressionNode.extension.st @@ -0,0 +1,9 @@ +Extension { #name : 'PyListExpressionNode' } + +{ #category : '*Famix-Python-Importer' } +PyListExpressionNode >> isLeftSideOfAssignation: aNode [ + + ^ self parent + ifNil: [ false ] + ifNotNil: [ :node | node isLeftSideOfAssignation: self ] +] diff --git a/src/Famix-Python-Importer/PyRootNode.extension.st b/src/Famix-Python-Importer/PyRootNode.extension.st index 76eb660..ce82796 100644 --- a/src/Famix-Python-Importer/PyRootNode.extension.st +++ b/src/Famix-Python-Importer/PyRootNode.extension.st @@ -7,6 +7,18 @@ PyRootNode >> fileReference [ ^ self filename ] +{ #category : '*Famix-Python-Importer' } +PyRootNode >> isAssignation [ + + ^ false +] + +{ #category : '*Famix-Python-Importer' } +PyRootNode >> isLeftSideOfAssignation: aNode [ + + ^ false +] + { #category : '*Famix-Python-Importer' } PyRootNode >> isSubscriptExpression [ diff --git a/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st b/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st index c711526..97e7ac5 100644 --- a/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st +++ b/src/Famix-Python-Importer/PyVariableExpressionNode.extension.st @@ -1,5 +1,13 @@ Extension { #name : 'PyVariableExpressionNode' } +{ #category : '*Famix-Python-Importer' } +PyVariableExpressionNode >> isLeftSideOfAssignation [ + + ^ self parent + ifNil: [ false ] + ifNotNil: [ :node | node isLeftSideOfAssignation: self ] +] + { #category : '*Famix-Python-Importer' } PyVariableExpressionNode >> isSelf [