Skip to content

Commit e3856d7

Browse files
authored
Merge pull request #208 from moosetechnology/new-patch
New patch
2 parents daab6ba + 22bf6dc commit e3856d7

File tree

3 files changed

+88
-29
lines changed

3 files changed

+88
-29
lines changed

src/EsopeImporter-Tests/IASTToFamixVisitorTest.class.st

+42
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ IASTToFamixVisitorTest >> anchorFrom: startPoint to: endPoint [
2525
yourself
2626
]
2727

28+
{ #category : 'tests-esope' }
29+
IASTToFamixVisitorTest >> attribute: symbol for: famixEntity [
30+
31+
^ famixEntity attributeAt: symbol ifAbsent: [ nil ]
32+
]
33+
2834
{ #category : 'running' }
2935
IASTToFamixVisitorTest >> defaultAnchor [
3036

@@ -481,6 +487,42 @@ IASTToFamixVisitorTest >> testFamixEsopePointerAccess [
481487
(acc attributeAt: #entity ifAbsent: ["impossible"]) entityName = 'att']).
482488
]
483489

490+
{ #category : 'tests-esope' }
491+
IASTToFamixVisitorTest >> testFamixEsopePointerAccessWithSegment [
492+
"SUBROUTINE sub
493+
ptr.att = 5
494+
END
495+
"
496+
497+
| accesses iastVar segment access |
498+
iastVar := self defaultVarAccess: 'ptr' isWrite: true.
499+
iastVar dereferencedVariable: (self defaultVarAccess: 'att' isWrite: false).
500+
501+
visitor model: FamixEsopeModel new.
502+
segment := (visitor model newSegment name: 'foo').
503+
segment addAttribute: (visitor model newAttributeNamed: 'att').
504+
(visitor model newVariableNamed: 'ptr') declaredType: segment.
505+
506+
programFile body: { IASTSubroutine new
507+
entityName: 'sub';
508+
body: { iastVar } ;
509+
yourself
510+
}.
511+
512+
programFile accept: visitor.
513+
514+
accesses := visitor model allAccesses.
515+
self assert: accesses size equals: 2.
516+
517+
access := accesses detect: [:each |
518+
(self attribute: #entity for: each) ~= iastVar ].
519+
520+
self assert: (self attribute: #parentAccess for: access) isNotNil.
521+
522+
access := self attribute: #parentAccess for: access.
523+
self assert: (self attribute: #entity for: access) entityName equals: 'ptr'.
524+
]
525+
484526
{ #category : 'tests-esope' }
485527
IASTToFamixVisitorTest >> testFamixEsopePointerDeclaration [
486528
" program main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Extension { #name : 'FamixF77Model' }
2+
3+
{ #category : '*EsopeImporter' }
4+
FamixF77Model >> initialize [
5+
6+
super initialize.
7+
self name: 'F77MooseModel'.
8+
self attributeAt: #instrinsicTypes put: self intrinsicTypes.
9+
self attributeAt: #unknownType put: [ self newTypeUnknown ]
10+
]
11+
12+
{ #category : '*EsopeImporter' }
13+
FamixF77Model >> intrinsicTypes [
14+
^ {
15+
(#integer -> (self newTypeIntrinsic name: #integer)).
16+
(#real -> (self newTypeIntrinsic name: #real)).
17+
(#complex -> (self newTypeIntrinsic name: #complex)).
18+
(#logical -> (self newTypeIntrinsic name: #logical)).
19+
(#character -> (self newTypeIntrinsic name: #character))
20+
} asDictionary
21+
]

src/EsopeImporter/IASTAbstractFamixVisitor.class.st

+25-29
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ IASTAbstractFamixVisitor >> model [
7272
{ #category : 'accessing' }
7373
IASTAbstractFamixVisitor >> model: anObject [
7474

75-
model := anObject
75+
model := anObject.
76+
self setIntrinsicTypes
7677
]
7778

7879
{ #category : 'private-creation' }
@@ -83,33 +84,30 @@ IASTAbstractFamixVisitor >> newEntity: aClass [
8384
yourself
8485
]
8586

86-
{ #category : 'initialization' }
87-
IASTAbstractFamixVisitor >> retrieveType: aTypeName from: aMooseModel [
88-
89-
^ (aMooseModel
90-
attributeAt: #instrinsicTypes
91-
ifAbsent: [
92-
aMooseModel
93-
attributeAt: #unknownType
94-
ifAbsent: self typeNotFoundBlock.
95-
]
96-
) at: aTypeName ifAbsent: self typeNotFoundBlock.
97-
]
98-
9987
{ #category : 'initialization' }
10088
IASTAbstractFamixVisitor >> retrieveTypeFrom: aName [
10189

90+
| typeNotFoundBlock |
91+
typeNotFoundBlock := [ self newEntity: FamixF77TypeUnknown ].
92+
10293
^ (self model
10394
attributeAt: #instrinsicTypes
10495
ifAbsent: [
10596
self model
10697
attributeAt: #unknownType
107-
ifAbsent: self typeNotFoundBlock.
98+
ifAbsent: typeNotFoundBlock.
10899
]
109-
) at: aName ifAbsent: self typeNotFoundBlock.
100+
) at: aName ifAbsent: typeNotFoundBlock.
110101
]
111102

112-
{ #category : 'as yet unclassified' }
103+
{ #category : 'private - helpers' }
104+
IASTAbstractFamixVisitor >> setIntrinsicTypes [
105+
106+
model attributeAt: #instrinsicTypes put: model intrinsicTypes.
107+
model attributeAt: #unknownType put: [ model newTypeUnknown ]
108+
]
109+
110+
{ #category : 'spawn' }
113111
IASTAbstractFamixVisitor >> spawn: aVisitorClass [
114112
^aVisitorClass new
115113
model: self model ;
@@ -129,26 +127,20 @@ IASTAbstractFamixVisitor >> stack: anObject [
129127
stack := anObject
130128
]
131129

132-
{ #category : 'as yet unclassified' }
130+
{ #category : 'symbols resolution' }
133131
IASTAbstractFamixVisitor >> symbolTable: anEntity at: key [
134132

135133
^ anEntity attributeAt: key asSymbol ifAbsent: [ ]
136134
]
137135

138-
{ #category : 'as yet unclassified' }
136+
{ #category : 'symbols resolution' }
139137
IASTAbstractFamixVisitor >> symbolTable: anEntity at: key put: value [
140138

141139
(self symbolTable: anEntity at: #symbolTable)
142140
at: key asSymbol
143141
put: value
144142
]
145143

146-
{ #category : 'initialization' }
147-
IASTAbstractFamixVisitor >> typeNotFoundBlock [
148-
149-
^ [ self newEntity: FamixF77TypeUnknown ]
150-
]
151-
152144
{ #category : 'visiting' }
153145
IASTAbstractFamixVisitor >> visitIASTParameter: aParameter [
154146

@@ -183,21 +175,25 @@ IASTAbstractFamixVisitor >> visitIASTVarAccess: aVarAccess [
183175
- dereferencedVariable for example: deref.var(...) "
184176

185177
"Distinguish external accesses from other accesses"
178+
179+
| mainAccess |
180+
mainAccess := (self createFamixF77Access: aVarAccess).
181+
mainAccess isWrite: aVarAccess isWrite.
186182

187183
aVarAccess indices deepFlatten
188184
do: [ :indice |
189-
190185
(indice class = IASTVarAccess and: [ (indice entityName asLowercase = 's__') not ])
191186
ifTrue: [ (self createFamixF77Access: indice) isWrite: indice isWrite ]
192187
].
193188

194189
aVarAccess dereferencedVariable
195190
ifNotNil: [ :dereferencedVariable |
196-
(self createFamixF77Access: dereferencedVariable) isWrite: dereferencedVariable isWrite
191+
(self createFamixF77Access: dereferencedVariable)
192+
isWrite: dereferencedVariable isWrite;
193+
attributeAt: #parentAccess put: mainAccess
197194
].
198195

199-
200-
^(self createFamixF77Access: aVarAccess) isWrite: aVarAccess isWrite
196+
^ mainAccess
201197
]
202198

203199
{ #category : 'visiting' }

0 commit comments

Comments
 (0)