Skip to content

Commit d7ae8b8

Browse files
authored
Merge pull request #209 from moosetechnology/segment-field-array
Segment field array
2 parents e3856d7 + f7b3a27 commit d7ae8b8

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

src/EsopeImporter-Tests/JsonToIASTVisitorTest.class.st

+40
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,46 @@ JsonToIASTVisitorTest >> testDeref [
337337

338338
]
339339

340+
{ #category : 'tests-esope' }
341+
JsonToIASTVisitorTest >> testDerefAccessWithDim [
342+
343+
" PROGRAM MYPROG
344+
var = lb.att(S__/2)
345+
END
346+
"
347+
348+
| programFile stmt varAccess entity |
349+
programFile := self visitJsonCode:
350+
'{"meta":{"miVersion":"fortran77","miFilename":"./srcCodeOrigin.f"},"program_units":[{"anno":[],"blocks":[{"anno":[],"label":null,"span":"(2:8)-(2:26)","statement":{"anno":[],"expression":{"anno":[],"expression":{"anno":[],"expression":{"anno":[],"span":"(2:14)-(2:15)","tag":"value","value":{"contents":"lb","tag":"variable"}},"field":{"anno":[],"span":"(2:17)-(2:19)","tag":"value","value":{"contents":"att","tag":"variable"}},"span":"(2:14)-(2:19)","tag":"deref"},"indices":{"anno":[],"list":[{"anno":[],"index":{"anno":[],"left":{"anno":[],"span":"(2:21)-(2:23)","tag":"value","value":{"contents":"s__","tag":"variable"}},"op":{"tag":"division"},"right":{"anno":[],"span":"(2:25)-(2:25)","tag":"value","value":{"contents":["2",null],"tag":"integer"}},"span":"(2:21)-(2:25)","tag":"binary"},"name":null,"span":"(2:21)-(2:25)","tag":"single"}],"span":"(2:21)-(2:25)"},"span":"(2:14)-(2:26)","tag":"subscript"},"span":"(2:8)-(2:26)","tag":"assign_expression","target":{"anno":[],"span":"(2:8)-(2:10)","tag":"value","value":{"contents":"var","tag":"variable"}}},"tag":"statement"}],"name":"myprog","span":"(1:7)-(3:9)","subprograms":null,"tag":"main"}]}'.
351+
352+
353+
self assert: programFile body first body size equals: 1.
354+
355+
stmt := programFile body first body first.
356+
357+
self assert: stmt size equals: 2.
358+
359+
varAccess := stmt first.
360+
self assert: varAccess class equals: IASTVarAccess.
361+
self assert: varAccess entityName equals: 'var'.
362+
363+
varAccess := stmt second.
364+
self assert: varAccess class equals: IASTVarAccess.
365+
self assert: varAccess entityName equals: 'lb'.
366+
self assert: varAccess dereferencedVariable isNotNil.
367+
368+
entity := varAccess dereferencedVariable.
369+
self assert: entity class equals: IASTVarAccess.
370+
self assert: entity entityName equals: 'att'.
371+
372+
self assert: varAccess indices size equals: 1.
373+
self assert: varAccess indices anyOne size equals: 1.
374+
entity := varAccess indices anyOne anyOne.
375+
self assert: entity class equals: IASTVarAccess.
376+
self assert: entity entityName equals: 's__'.
377+
378+
]
379+
340380
{ #category : 'tests-esope' }
341381
JsonToIASTVisitorTest >> testESOAtWithArrayArgument [
342382
"Special case of a D__ function call with an array as argument

src/EsopeImporter/IASTAbstractFamixVisitor.class.st

+15-14
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ Class {
1111
}
1212

1313
{ #category : 'private-creation' }
14-
IASTAbstractFamixVisitor >> createFamixF77Access: anIastObject [
15-
16-
| access |
17-
access := self model newAccess
18-
sourceAnchor:
19-
(self visitIndexedFileAnchor: anIastObject sourceAnchor);
20-
attributeAt: #entity put: anIastObject;
21-
isWrite: false;
22-
yourself.
23-
stack top addAccess: access.
24-
^access
14+
IASTAbstractFamixVisitor >> createFamixF77Access: anIastAccess [
15+
"For each FamixF77Access we create, we hide the anIastAccess in entityAttributes with the key '#entity'.
16+
so that the resolver can use the information carried by anIastAccess to resolve that access."
17+
18+
^self model newAccess
19+
sourceAnchor: (self visitIndexedFileAnchor: anIastAccess sourceAnchor);
20+
attributeAt: #entity put: anIastAccess;
21+
isWrite: false;
22+
accessor: stack top;
23+
yourself
2524
]
2625

2726
{ #category : 'private-creation' }
@@ -172,7 +171,9 @@ IASTAbstractFamixVisitor >> visitIASTTypeRef: aType [
172171
IASTAbstractFamixVisitor >> visitIASTVarAccess: aVarAccess [
173172
"an aVarAccess can have:
174173
- indices for example: varAccess(i, j, k) -> i j k are indices
175-
- dereferencedVariable for example: deref.var(...) "
174+
- dereferencedVariable for example: aVarAccess.deref(...) -> deref is dereferencedVariable
175+
176+
mainAccess correspond to aVarAccess"
176177

177178
"Distinguish external accesses from other accesses"
178179

@@ -182,7 +183,7 @@ IASTAbstractFamixVisitor >> visitIASTVarAccess: aVarAccess [
182183

183184
aVarAccess indices deepFlatten
184185
do: [ :indice |
185-
(indice class = IASTVarAccess and: [ (indice entityName asLowercase = 's__') not ])
186+
(indice class = IASTVarAccess and: [ indice entityName asLowercase ~= 's__' ])
186187
ifTrue: [ (self createFamixF77Access: indice) isWrite: indice isWrite ]
187188
].
188189

@@ -193,7 +194,7 @@ IASTAbstractFamixVisitor >> visitIASTVarAccess: aVarAccess [
193194
attributeAt: #parentAccess put: mainAccess
194195
].
195196

196-
^ mainAccess
197+
^ mainAccess
197198
]
198199

199200
{ #category : 'visiting' }

0 commit comments

Comments
 (0)