Skip to content

Commit ecaaf03

Browse files
committed
Manage binary operators, boolean operators, comparison operators and unary operators
1 parent 6504075 commit ecaaf03

File tree

2 files changed

+146
-3
lines changed

2 files changed

+146
-3
lines changed

src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,6 +5054,82 @@ FamixPythonProject1Test >> testReadAccessInANot [
50545054
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
50555055
]
50565056
5057+
{ #category : 'tests - accesses' }
5058+
FamixPythonProject1Test >> testReadAccessInBinaryOperator [
5059+
5060+
| global module access |
5061+
global := self globalVariableNamed: 'variableToAccessInBinaryOperator'.
5062+
module := self moduleNamed: 'moduleAtRoot13'.
5063+
5064+
access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].
5065+
5066+
self assert: access class equals: FamixPythonAccess.
5067+
self assert: access source equals: module.
5068+
self assert: access accessor equals: module.
5069+
self assert: access target equals: global.
5070+
self assert: access variable equals: global.
5071+
self deny: access isWrite.
5072+
self assert: access isRead.
5073+
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
5074+
]
5075+
5076+
{ #category : 'tests - accesses' }
5077+
FamixPythonProject1Test >> testReadAccessInBooleanOperator [
5078+
5079+
| global module access |
5080+
global := self globalVariableNamed: 'variableInBooleanOperator'.
5081+
module := self moduleNamed: 'moduleAtRoot13'.
5082+
5083+
access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].
5084+
5085+
self assert: access class equals: FamixPythonAccess.
5086+
self assert: access source equals: module.
5087+
self assert: access accessor equals: module.
5088+
self assert: access target equals: global.
5089+
self assert: access variable equals: global.
5090+
self deny: access isWrite.
5091+
self assert: access isRead.
5092+
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
5093+
]
5094+
5095+
{ #category : 'tests - accesses' }
5096+
FamixPythonProject1Test >> testReadAccessInComparisonOperator [
5097+
5098+
| global module access |
5099+
global := self globalVariableNamed: 'variableToAccessInComparisonOperator'.
5100+
module := self moduleNamed: 'moduleAtRoot13'.
5101+
5102+
access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].
5103+
5104+
self assert: access class equals: FamixPythonAccess.
5105+
self assert: access source equals: module.
5106+
self assert: access accessor equals: module.
5107+
self assert: access target equals: global.
5108+
self assert: access variable equals: global.
5109+
self deny: access isWrite.
5110+
self assert: access isRead.
5111+
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
5112+
]
5113+
5114+
{ #category : 'tests - accesses' }
5115+
FamixPythonProject1Test >> testReadAccessInUnaryOperator [
5116+
5117+
| global module access |
5118+
global := self globalVariableNamed: 'variableInUnaryOperator'.
5119+
module := self moduleNamed: 'moduleAtRoot13'.
5120+
5121+
access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ].
5122+
5123+
self assert: access class equals: FamixPythonAccess.
5124+
self assert: access source equals: module.
5125+
self assert: access accessor equals: module.
5126+
self assert: access target equals: global.
5127+
self assert: access variable equals: global.
5128+
self deny: access isWrite.
5129+
self assert: access isRead.
5130+
self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ])
5131+
]
5132+
50575133
{ #category : 'tests - accesses' }
50585134
FamixPythonProject1Test >> testReadAccessSourceAnchor [
50595135

src/Famix-Python-Importer/FamixPythonVisitor.class.st

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ FamixPythonVisitor >> isAccessOrReferenceNode: anIdentifierNode [
268268
"I should return true if an Identifier node represent an access or a reference."
269269

270270
^ #( elif_clause list argument_list return_statement lambda if_statement comparison_operator binary_operator assignment not_operator expression_statement
271-
augmented_assignment ) includes: anIdentifierNode parent type
271+
augmented_assignment unary_operator boolean_operator) includes: anIdentifierNode parent type
272272
]
273273

274274
{ #category : 'testing' }
@@ -704,6 +704,22 @@ FamixPythonVisitor >> visitAugmentedAssignment: aNode [
704704
^ self visitChildren: aNode
705705
]
706706

707+
{ #category : 'visiting - visitChildren' }
708+
FamixPythonVisitor >> visitBinaryOperator: aNode [
709+
"
710+
Children:
711+
- left: identifier / set_comprehension / binary_operator / concatenated_string / unary_operator / call / list / float / none / set / dictionary_comprehension / false / string / true / attribute / parenthesized_expression / integer / tuple / list_comprehension / subscript
712+
- right: identifier / set_comprehension / binary_operator / concatenated_string / unary_operator / dictionary / call / list / float / none / set / false / string / true / attribute / parenthesized_expression / integer / tuple / list_comprehension / subscript
713+
- <unnamedChild>: comment / line_continuation
714+
715+
Parents:
716+
- Visiting me: assignment / binary_operator / if_statement / argument_list / expression_statement / elif_clause / comparison_operator / return_statement / if_clause / augmented_assignment / named_expression / unary_operator / boolean_operator
717+
- Not yet managed: list / set / assert_statement / list_comprehension / type / yield / raise_statement / tuple / list_splat / conditional_expression / for_statement / expression_list / for_in_clause / typed_default_parameter / not_operator / interpolation / pair / default_parameter / set_comprehension / slice / keyword_argument / parenthesized_expression / generator_expression / subscript / lambda
718+
"
719+
720+
^ self visitChildren: aNode
721+
]
722+
707723
{ #category : 'visiting - visitChildren' }
708724
FamixPythonVisitor >> visitBlock: aNode [
709725
"
@@ -719,6 +735,22 @@ FamixPythonVisitor >> visitBlock: aNode [
719735
^ self visitChildren: aNode
720736
]
721737

738+
{ #category : 'visiting - visitChildren' }
739+
FamixPythonVisitor >> visitBooleanOperator: aNode [
740+
"
741+
Children:
742+
- left: identifier / set_comprehension / binary_operator / concatenated_string / unary_operator / call / list / float / none / set / dictionary_comprehension / false / string / true / attribute / parenthesized_expression / integer / tuple / list_comprehension / subscript
743+
- right: identifier / set_comprehension / binary_operator / concatenated_string / unary_operator / dictionary / call / list / float / none / set / false / string / true / attribute / parenthesized_expression / integer / tuple / list_comprehension / subscript
744+
- <unnamedChild>: comment / line_continuation
745+
746+
Parents:
747+
- Visiting me: boolean_operator / assignment / binary_operator / if_statement / not_operator / argument_list / expression_statement / elif_clause / comparison_operator / return_statement / if_clause / augmented_assignment / named_expression / unary_operator
748+
- Not yet managed: list / set / assert_statement / list_comprehension / type / yield / raise_statement / tuple / list_splat / conditional_expression / for_statement / expression_list / for_in_clause / typed_default_parameter / interpolation / pair / default_parameter / set_comprehension / slice / keyword_argument / parenthesized_expression / generator_expression / subscript / lambda
749+
"
750+
751+
^ self visitChildren: aNode
752+
]
753+
722754
{ #category : 'visiting - noop' }
723755
FamixPythonVisitor >> visitBreakStatement: aNode [
724756
"
@@ -779,6 +811,20 @@ FamixPythonVisitor >> visitComment: aCommentNode [
779811

780812
]
781813

814+
{ #category : 'visiting - visitChildren' }
815+
FamixPythonVisitor >> visitComparisonOperator: aNode [
816+
"
817+
Children:
818+
- <unnamedChild>: identifier / set_comprehension / binary_operator / comment / unary_operator / concatenated_string / dictionary / call / list / float / none / set / false / generator_expression / ellipsis / string / true / attribute / parenthesized_expression / integer / tuple / line_continuation / list_comprehension / subscript
819+
820+
Parents:
821+
- Visiting me: if_statement / elif_clause / if_clause / augmented_assignment / argument_list / not_operator / expression_statement / while_statement / return_statement / assignment / boolean_operator
822+
- Not yet managed: pair / list / expression_list / generator_expression / conditional_expression / keyword_argument / assert_statement / parenthesized_expression / lambda / tuple / list_comprehension / subscript
823+
"
824+
825+
^ self visitChildren: aNode
826+
]
827+
782828
{ #category : 'visiting - noop' }
783829
FamixPythonVisitor >> visitContinueStatement: aNode [
784830
"
@@ -1174,6 +1220,13 @@ FamixPythonVisitor >> visitRelativeImport: aRelativeImportNode [
11741220

11751221
{ #category : 'visiting - visitChildren' }
11761222
FamixPythonVisitor >> visitReturnStatement: aNode [
1223+
"
1224+
Children:
1225+
- <unnamedChild>: identifier / set_comprehension / binary_operator / unary_operator / await / dictionary / call / list / not_operator / boolean_operator / expression_list / float / none / dictionary_comprehension / set / false / conditional_expression / generator_expression / string / true / attribute / parenthesized_expression / integer / comparison_operator / lambda / tuple / list_comprehension / subscript
1226+
1227+
Parents:
1228+
- Visiting me: block
1229+
"
11771230

11781231
^ self visitChildren: aNode
11791232
]
@@ -1185,8 +1238,8 @@ FamixPythonVisitor >> visitString: aStringNode [
11851238
- unnamed: string_end / string_content / string_start / interpolation
11861239
11871240
Parents:
1188-
- Visiting me: for_statement / named_expression / argument_list / augmented_assignment / expression_statement / assignment / subscript
1189-
- Not yet managed: pair / set_comprehension / binary_operator / concatenated_string / for_in_clause / type / list / typed_default_parameter / slice / boolean_operator / expression_list / set / generator_expression / conditional_expression / keyword_argument / attribute / assert_statement / yield / default_parameter / parenthesized_expression / interpolation / comparison_operator / lambda / tuple / return_statement / list_comprehension"
1241+
- Visiting me: for_statement / named_expression / argument_list / augmented_assignment / expression_statement / assignment / subscript / return_statement / binary_operator / boolean_operator
1242+
- Not yet managed: pair / set_comprehension / concatenated_string / for_in_clause / type / list / typed_default_parameter / slice / expression_list / set / generator_expression / conditional_expression / keyword_argument / attribute / assert_statement / yield / default_parameter / parenthesized_expression / interpolation / comparison_operator / lambda / tuple / list_comprehension"
11901243

11911244
^ self visitChildren: aStringNode
11921245
]
@@ -1254,6 +1307,20 @@ FamixPythonVisitor >> visitTuplePattern: aNode [
12541307
^ self visitChildren: aNode
12551308
]
12561309

1310+
{ #category : 'visiting - visitChildren' }
1311+
FamixPythonVisitor >> visitUnaryOperator: aNode [
1312+
"
1313+
Children:
1314+
- argument: subscript / attribute / binary_operator / parenthesized_expression / identifier / false / true / float / integer / call
1315+
1316+
Parents:
1317+
- Visiting me: binary_operator / argument_list / augmented_assignment / expression_statement / comparison_operator / return_statement / assignment / boolean_operator
1318+
- Not yet managed: pair / type / list / typed_default_parameter / slice / expression_list / set / conditional_expression / keyword_argument / list_splat / default_parameter / parenthesized_expression / interpolation / lambda / tuple / list_comprehension / subscript
1319+
"
1320+
1321+
^ self visitChildren: aNode
1322+
]
1323+
12571324
{ #category : 'visiting - visitChildren' }
12581325
FamixPythonVisitor >> visitWhileStatement: aNode [
12591326
"

0 commit comments

Comments
 (0)