Skip to content

Commit

Permalink
Merge pull request #138 from moosetechnology/cleaning
Browse files Browse the repository at this point in the history
Cleaning
  • Loading branch information
NicolasAnquetil committed Jun 15, 2024
2 parents e7a74a6 + d622fb5 commit 2b24bac
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 83 deletions.
9 changes: 5 additions & 4 deletions src/EsopeImporter-Tests/FamixEsopeResolverTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ FamixEsopeResolverTest >> defaultImplicitNone [
FamixEsopeResolverTest >> defaultInvocation: name [

^ FamixF77Invocation new
mooseModel: mooseModel;
attributeAt: #entity put: (self defaultIASTInvocation: name);
sourceAnchor: self defaultAnchor;
yourself
mooseModel: mooseModel ;
attributeAt: #entity put: (self defaultIASTInvocation: name) ;
signature: name ;
sourceAnchor: self defaultAnchor ;
yourself
]

{ #category : #'default values' }
Expand Down
102 changes: 51 additions & 51 deletions src/EsopeImporter-Tests/IASTToFamixVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ IASTToFamixVisitorTest >> testComment [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateDummyFamixFortran77Subroutine [
IASTToFamixVisitorTest >> testDummyFamixFortran77Subroutine [

"
subroutine _$aFile_inc
Expand Down Expand Up @@ -260,7 +260,7 @@ c@_ end segment
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopeAccessors [
IASTToFamixVisitorTest >> testFamixEsopeAccessors [

"
d__(ptr,attr)
Expand Down Expand Up @@ -296,7 +296,7 @@ IASTToFamixVisitorTest >> testCreateFamixEsopeAccessors [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopeAccessorsWithArg [
IASTToFamixVisitorTest >> testFamixEsopeAccessorsWithArg [

"
d__(ptr,attr(i))
Expand Down Expand Up @@ -345,7 +345,7 @@ IASTToFamixVisitorTest >> testCreateFamixEsopeAccessorsWithArg [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopeAccessorsWithArgsWithDot [
IASTToFamixVisitorTest >> testFamixEsopeAccessorsWithArgsWithDot [

"
d__(ptr,attr(i,d__(p,j)))
Expand Down Expand Up @@ -388,7 +388,7 @@ IASTToFamixVisitorTest >> testCreateFamixEsopeAccessorsWithArgsWithDot [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopeCommandSegini [
IASTToFamixVisitorTest >> testFamixEsopeCommandSegini [

"
segini ptr
Expand All @@ -412,7 +412,7 @@ IASTToFamixVisitorTest >> testCreateFamixEsopeCommandSegini [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopePointerDeclaration [
IASTToFamixVisitorTest >> testFamixEsopePointerDeclaration [
" program main
segment, pers
end segment
Expand All @@ -438,7 +438,7 @@ IASTToFamixVisitorTest >> testCreateFamixEsopePointerDeclaration [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopeSegment [
IASTToFamixVisitorTest >> testFamixEsopeSegment [

"
segment myseg
Expand Down Expand Up @@ -487,7 +487,7 @@ IASTToFamixVisitorTest >> testCreateFamixEsopeSegment [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixEsopeSlashWithLitteralDim [
IASTToFamixVisitorTest >> testFamixEsopeSlashWithLitteralDim [

"
c ptr.attr(/1)
Expand Down Expand Up @@ -532,7 +532,7 @@ c ptr.attr(/1)
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77 [
IASTToFamixVisitorTest >> testFamixFortran77 [

| entity |
programFile progUnits: { IASTSubroutine new
Expand All @@ -557,7 +557,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77 [
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateFamixFortran77ESOAtWithArrayArgument [
IASTToFamixVisitorTest >> testFamixFortran77ESOAtWithArrayArgument [
"Special case of a D__ function call with an array as argument
subroutine hello
Expand All @@ -576,7 +576,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77ESOAtWithArrayArgument [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77Invocation [
IASTToFamixVisitorTest >> testFamixFortran77Invocation [
| entity invocation caller callee |

callee := IASTSubroutine new
Expand Down Expand Up @@ -604,7 +604,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77Invocation [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77LocalVariable [
IASTToFamixVisitorTest >> testFamixFortran77LocalVariable [

| entity var |
programFile progUnits: { IASTSubroutine new
Expand All @@ -629,7 +629,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77LocalVariable [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77PUBlockdata [
IASTToFamixVisitorTest >> testFamixFortran77PUBlockdata [

| entity |
programFile progUnits: { IASTBlockData new
Expand All @@ -648,7 +648,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77PUBlockdata [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77PUComment [
IASTToFamixVisitorTest >> testFamixFortran77PUComment [
| entity |
programFile progUnits: { IASTComment new
text: ' a comment' ;
Expand All @@ -667,7 +667,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77PUComment [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77PUFunction [
IASTToFamixVisitorTest >> testFamixFortran77PUFunction [

| entity |
programFile progUnits: { IASTFunction new
Expand All @@ -685,7 +685,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77PUFunction [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77PUFunctionWithParameter [
IASTToFamixVisitorTest >> testFamixFortran77PUFunctionWithParameter [

| entity param |
programFile progUnits: { IASTFunction new
Expand All @@ -710,7 +710,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77PUFunctionWithParameter [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77PUMain [
IASTToFamixVisitorTest >> testFamixFortran77PUMain [

| entity |
programFile progUnits: { IASTMainProgram new
Expand All @@ -728,7 +728,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77PUMain [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77ProgramFile [
IASTToFamixVisitorTest >> testFamixFortran77ProgramFile [
| entity |
programFile accept: visitor.

Expand All @@ -744,7 +744,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77ProgramFile [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77SourceAnchor [
IASTToFamixVisitorTest >> testFamixFortran77SourceAnchor [
| entity |
entity := self defaultAnchor accept: visitor.

Expand All @@ -757,7 +757,7 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77SourceAnchor [
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testCreateFamixFortran77Subroutine [
IASTToFamixVisitorTest >> testFamixFortran77Subroutine [

| entity |
programFile progUnits: { IASTSubroutine new
Expand All @@ -775,8 +775,38 @@ IASTToFamixVisitorTest >> testCreateFamixFortran77Subroutine [
self assert: entity parameters size equals: 0
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testImplicitWithRange [

| entity sub |
programFile progUnits: { (IASTSubroutine new
entityName: 'sub';
body: { IASTImplicit new
rules: { (self implicitRule: 'character' range: { #( $c $f ) }) }
};
yourself) }.

entity := programFile accept: visitor.

self assert: entity programUnits size equals: 1.

sub := entity programUnits first.

self assert: sub implicits size equals: 1.

entity := sub implicits anyOne.
self assert: entity class equals: IASTImplicitTypingRule.

self assert: entity ranges size equals: 1.

entity := entity ranges anyOne.
self assert: entity size equals: 2.
self assert: entity first equals: $c.
self assert: entity second equals: $f
]

{ #category : #'tests-esope' }
IASTToFamixVisitorTest >> testCreateIncludeFamixFortran77Subroutine [
IASTToFamixVisitorTest >> testIncludeFamixFortran77Subroutine [

"
subroutine test
Expand Down Expand Up @@ -809,36 +839,6 @@ c@_#include ""point.seg""
self assert: include source equals: programFile."
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testImplicitWithRange [

| entity sub |
programFile progUnits: { (IASTSubroutine new
entityName: 'sub';
body: { IASTImplicit new
rules: { (self implicitRule: 'character' range: { #( $c $f ) }) }
};
yourself) }.

entity := programFile accept: visitor.

self assert: entity programUnits size equals: 1.

sub := entity programUnits first.

self assert: sub implicits size equals: 1.

entity := sub implicits anyOne.
self assert: entity class equals: IASTImplicitTypingRule.

self assert: entity ranges size equals: 1.

entity := entity ranges anyOne.
self assert: entity size equals: 2.
self assert: entity first equals: $c.
self assert: entity second equals: $f
]

{ #category : #'tests-fortran' }
IASTToFamixVisitorTest >> testMultipleImplicit [

Expand Down
16 changes: 6 additions & 10 deletions src/EsopeImporter-Tests/JsonToIASTVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -826,22 +826,18 @@ JsonToIASTVisitorTest >> testFunctionWithFunctionInvocation [
end
"

| programFile fct |
| programFile stmt |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"./fortran77.f"},"program_units":[{"anno":[],"arguments":null,"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:22)","statement":{"anno":[],"expression":{"anno":[],"arguments":{"anno":[],"list":[{"anno":[],"expr":{"contents":{"anno":[],"span":"(2:18)-(2:18)","tag":"value","value":{"contents":"i","tag":"variable"}},"tag":"expr"},"name":null,"span":"(2:18)-(2:18)"},{"anno":[],"expr":{"contents":{"anno":[],"span":"(2:21)-(2:21)","tag":"value","value":{"contents":"j","tag":"variable"}},"tag":"expr"},"name":null,"span":"(2:21)-(2:21)"}],"span":"(2:18)-(2:21)"},"function":{"anno":[],"span":"(2:11)-(2:15)","tag":"value","value":{"contents":"ifunc","tag":"variable"}},"span":"(2:11)-(2:22)","tag":"function_call"},"span":"(2:7)-(2:22)","tag":"assign_expression","target":{"anno":[],"span":"(2:7)-(2:7)","tag":"value","value":{"contents":"i","tag":"variable"}}},"tag":"statement"}],"name":"efunc","result":null,"span":"(1:7)-(3:9)","subprograms":null,"tag":"function","type":{"anno":[],"base_type":"integer","selector":null,"span":"(1:7)-(1:13)"}}]}'.


self assert: programFile progUnits size equals: 1.

fct := programFile progUnits first.
stmt := programFile progUnits first body first.
self assert: stmt second class equals: IASTInvocation.
self assert: stmt second entityName equals: 'ifunc'.
self assert: stmt second arguments size equals: 2.
self assert: stmt second sourceAnchor isNotNil.

self assert: fct class equals: IASTFunction.
self assert: fct entityName equals: 'efunc'.
self assert: fct body first size equals: 2.
self assert: fct sourceAnchor startLine equals: 1.
self assert: fct sourceAnchor startColumn equals: 7.
self assert: fct sourceAnchor endLine equals: 3.
self assert: fct sourceAnchor endColumn equals: 10.

]

{ #category : #'tests-statement' }
Expand Down
17 changes: 7 additions & 10 deletions src/EsopeImporter/FamixEsopeResolver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ FamixEsopeResolver >> removeAttribute: aSymbol fromEntity: anEntity [
^entity
]

{ #category : #'private - utility' }
FamixEsopeResolver >> removeStoredIAST: anEntity [

^anEntity getAndRemoveAttribute: #entity
]

{ #category : #'symbols resolution' }
FamixEsopeResolver >> requalifyFunctionDeclaration: external [
"external declaration of function followed by a VariableDeclaration of the same function
Expand Down Expand Up @@ -347,7 +341,7 @@ FamixEsopeResolver >> resolveEsopeVariable: esopeVariable [
]

{ #category : #'symbols resolution' }
FamixEsopeResolver >> resolveImplicitFunction: function [
FamixEsopeResolver >> resolveImplicitFunctionType: function [

function declaredType:
(self resolveTypeName:
Expand Down Expand Up @@ -397,7 +391,7 @@ FamixEsopeResolver >> resolveIncludes [
detect: [ :includedFile |
includedFile programFile filename asPath basename beginsWith: include filename ]
ifFound: [ :includedFile | include included: includedFile ]
ifNone: [ Notification signal: ' no such file' , include filename ]
ifNone: [ Notification signal: ' no such file ' , include filename ]
]
]

Expand All @@ -418,7 +412,7 @@ FamixEsopeResolver >> resolveInvocation: anInvocation [

| invocated |

invocated := self removeStoredIAST: anInvocation.
invocated := anInvocation getAndRemoveAttribute: #entity .

(self resolveInvocables: invocated)
ifNotNil: [ :invocatedFound |
Expand All @@ -429,7 +423,10 @@ FamixEsopeResolver >> resolveInvocation: anInvocation [
FamixEsopeResolver >> resolveInvocations [

(self model allWithType: FamixF77Invocation) do: [ :invocation |
self resolveInvocation: invocation ]
self errorHandler enterContext: ('invocation: ' , invocation signature).
self resolveInvocation: invocation.
self errorHandler leaveContext
]
]

{ #category : #'symbols resolution' }
Expand Down
4 changes: 2 additions & 2 deletions src/EsopeImporter/FamixF77Invocation.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Extension { #name : #FamixF77Invocation }
{ #category : #'*EsopeImporter' }
FamixF77Invocation >> famixImportSanityCheck [

self assert: sender isNotNil description: 'Invocation without sender'.
self assert: candidates isNotEmpty description: 'Invocation without candidates'.
self assert: sender isNotNil description: signature , ' without sender'.
self assert: candidates isNotEmpty description: signature , ' without candidates'.
]
3 changes: 2 additions & 1 deletion src/EsopeImporter/FortranProjectImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ FortranProjectImporter >> jsonASTToIAST [
errorHandler enterContext: jsonFile fullName.
iastEntity := visitor visitProgramFile:
(NeoJSONReader fromString: jsonFile contents).
errorHandler leaveContext
errorHandler leaveContext.
iastEntity
]

]
Expand Down
11 changes: 6 additions & 5 deletions src/EsopeImporter/IASTToFamixFortranVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ IASTToFamixFortranVisitor >> visitIASTIncludedFile: anIncludedFile [
IASTToFamixFortranVisitor >> visitIASTInvocation: anInvocation [

^ self model newInvocation
sourceAnchor:
(self visitIndexedFileAnchor: anInvocation sourceAnchor);
attributeAt: #entity put: anInvocation;
sender: stack top;
yourself
sourceAnchor:
(self visitIndexedFileAnchor: anInvocation sourceAnchor);
attributeAt: #entity put: anInvocation;
signature: anInvocation entityName ;
sender: stack top;
yourself
]

{ #category : #visiting }
Expand Down

0 comments on commit 2b24bac

Please sign in to comment.