Skip to content

Commit

Permalink
Merge pull request #16 from moosetechnology/cleaning
Browse files Browse the repository at this point in the history
Cleaning JsonToIAST
  • Loading branch information
NicolasAnquetil authored Sep 2, 2023
2 parents 40f16cc + cf6c62d commit 8c32e25
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 21 deletions.
90 changes: 89 additions & 1 deletion src/EsopeImporter-Tests/JsonToIASTVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ JsonToIASTVisitorTest >> testCommentOutside [

]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testContinueStatement [
" PROGRAM MYPROG
continue
END
"

| programFile |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"fortran77.f"},"program_units":[{"anno":[],"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:14)","statement":{"anno":[],"span":"(2:7)-(2:14)","tag":"continue"},"tag":"statement"}],"name":"myprog","span":"(1:7)-(3:9)","subprograms":null,"tag":"main"}]}'.


self assert: programFile progUnits first body isEmpty
]

{ #category : #'tests-progUnit' }
JsonToIASTVisitorTest >> testEmptyBlockData [
"BLOCK data hello
Expand All @@ -222,6 +236,20 @@ JsonToIASTVisitorTest >> testEmptyBlockData [
self assert: block comments isEmpty.
]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testEmptyExitStatement [
" PROGRAM MYPROG
exit
END
"

| programFile |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"fortran77.f"},"program_units":[{"anno":[],"arguments":null,"blocks":[{"anno":[],"label":null,"span":"(2:8)-(2:11)","statement":{"anno":[],"span":"(2:8)-(2:11)","tag":"exit","var":null},"tag":"statement"}],"name":"hello","options":[null,null],"span":"(1:7)-(3:9)","subprograms":null,"tag":"subroutine"}]}'.


self assert: programFile progUnits first body isEmpty
]

{ #category : #'tests-progUnit' }
JsonToIASTVisitorTest >> testEmptyFunction [
"integer function hello()
Expand Down Expand Up @@ -301,6 +329,21 @@ JsonToIASTVisitorTest >> testEmptyProgram [

]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testEmptyReturnStatement [
" subroutine hello
return
end
"
| programFile fct |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"fortran77.f"},"program_units":[{"anno":[],"arguments":null,"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:12)","statement":{"anno":[],"span":"(2:7)-(2:12)","tag":"return","target":null},"tag":"statement"}],"name":"hello","options":[null,null],"span":"(1:7)-(3:9)","subprograms":null,"tag":"subroutine"}]}'.

self assert: programFile progUnits size equals: 1.

fct := programFile progUnits first.
self assert: fct body isEmpty
]

{ #category : #'tests-progUnit' }
JsonToIASTVisitorTest >> testEmptySubroutine [
"subroutine hello
Expand Down Expand Up @@ -629,7 +672,7 @@ JsonToIASTVisitorTest >> testEsoSlWithTwoDot [

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testFunctionWithFunctionInvocation [
"integer function efunc()
" integer function efunc()
i = ifunc (i, j)
end
"
Expand All @@ -652,6 +695,20 @@ JsonToIASTVisitorTest >> testFunctionWithFunctionInvocation [

]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testGotoStatement [
" PROGRAM MYPROG
goto 100
END
"

| programFile |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"fortran77.f"},"program_units":[{"anno":[],"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:14)","statement":{"anno":[],"span":"(2:7)-(2:14)","tag":"goto","target":{"anno":[],"span":"(2:12)-(2:14)","tag":"value","value":{"contents":["100",null],"tag":"integer"}}},"tag":"statement"}],"name":"myprog","span":"(1:7)-(3:9)","subprograms":null,"tag":"main"}]}'.


self assert: programFile progUnits first body isEmpty
]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testImplicitNoneStatement [
"PROGRAM MYPROG
Expand Down Expand Up @@ -988,6 +1045,37 @@ JsonToIASTVisitorTest >> testProgramWithSimpleIfStatementWithoutBody [



]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testReturnConstantStatement [
" integer function hello()
return 42
end
"
| programFile fct |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"fortran77.f"},"program_units":[{"anno":[],"arguments":null,"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:15)","statement":{"anno":[],"span":"(2:7)-(2:15)","tag":"return","target":{"anno":[],"span":"(2:14)-(2:15)","tag":"value","value":{"contents":["42",null],"tag":"integer"}}},"tag":"statement"}],"name":"hello","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.
self assert: fct body isEmpty
]

{ #category : #'tests-statement' }
JsonToIASTVisitorTest >> testReturnStatement [
" integer function hello()
return someVar
end
"
| programFile fct |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"fortran77.f"},"program_units":[{"anno":[],"arguments":null,"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:20)","statement":{"anno":[],"span":"(2:7)-(2:20)","tag":"return","target":{"anno":[],"span":"(2:14)-(2:20)","tag":"value","value":{"contents":"somevar","tag":"variable"}}},"tag":"statement"}],"name":"hello","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.
self assert: fct body first class equals: IASTVarAccess.
self assert: fct body first entityName equals: 'somevar'.
]

{ #category : #'tests-esope' }
Expand Down
22 changes: 2 additions & 20 deletions src/EsopeImporter/IASTToFortranVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,8 @@ IASTToFortranVisitor >> visitIASTProgramUnit: aProgramUnit toFamix: aFamixFortra
self createSymbolTableFor: progUnit.

aProgramUnit body ifNotNil: [ :body |
body do: [ :node |
node isArray
ifTrue: [
self flag: #FIXME. "1 halt."
node flattened
reject: [ :each | each isPoint ]
thenDo: [ :stmt | stmt accept: self ] ]
ifFalse: [ node accept: self ] ] ].

"aProgramUnit localVariables do: [ :localVariable |
progUnit addLocalVariable: (localVariable accept: self) ].
aProgramUnit accesses do: [ :access |
progUnit addAccess: (access accept: self) ].
aProgramUnit invocations do: [ :invocation |
progUnit addOutgoingInvocation: (invocation accept: self) ].
aProgramUnit localComments do: [ :comment |
progUnit addComment: (comment accept: self) ]."
body deepFlatten do: [ :expr | expr accept: self ]
].

progUnit attributeAt: #implicits put: aProgramUnit implicits.

Expand Down
25 changes: 25 additions & 0 deletions src/EsopeImporter/JsonToIASTVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ JsonToIASTVisitor >> visitConditions: aConditionList [
^(data collect: #first) , (data collect: #second)
]

{ #category : #'visiting statement' }
JsonToIASTVisitor >> visitContinueStatement: aContinueStatementNode [
^nil
]

{ #category : #visiting }
JsonToIASTVisitor >> visitData: aDataNode [
self flag: #TODO.
Expand Down Expand Up @@ -340,6 +345,12 @@ JsonToIASTVisitor >> visitEsopeSegsupComment: anEsopeCommentNode [
yourself
]

{ #category : #'visiting statement' }
JsonToIASTVisitor >> visitExitStatement: anExitNode [

^(super visitExitStatement: anExitNode) second
]

{ #category : #'visiting esope' }
JsonToIASTVisitor >> visitExternalStatement: anExternalStatementNode [

Expand Down Expand Up @@ -428,6 +439,12 @@ JsonToIASTVisitor >> visitFunction_call: aFunctionCallNode [
yourself
]

{ #category : #'visiting statement' }
JsonToIASTVisitor >> visitGotoStatement: aGotoStatementNode [

^nil
]

{ #category : #'visiting statement' }
JsonToIASTVisitor >> visitIf: anIfNode [
"super visit keys: #(span label conditions blocks)"
Expand Down Expand Up @@ -525,6 +542,14 @@ JsonToIASTVisitor >> visitReal: aRealNode [
^nil
]

{ #category : #'visiting statement' }
JsonToIASTVisitor >> visitReturnStatement: aReturnStatementNode [
| data |
data := super visitReturnStatement: aReturnStatementNode.

^data second
]

{ #category : #visiting }
JsonToIASTVisitor >> visitSpanOf: aNode [
^self makeIndexedAnchor: (self visitSpan: (aNode at: 'span'))
Expand Down

0 comments on commit 8c32e25

Please sign in to comment.