Skip to content

Commit

Permalink
make JsonToIASTVisitorTests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
anquetil committed Sep 1, 2023
1 parent 14b7960 commit 2408132
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
41 changes: 22 additions & 19 deletions src/EsopeImporter-Tests/JsonToIASTVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,15 @@ JsonToIASTVisitorTest >> testAssignementStatementWithEsoAt [
| programFile stmt |
programFile := self visitJsonCode: '{"meta":{"miVersion":"fortran77","miFilename":"./fortran77.f"},"program_units":[{"anno":[],"arguments":null,"blocks":[{"anno":[],"label":null,"span":"(2:7)-(2:28)","statement":{"anno":[],"expression":{"anno":[],"arguments":{"anno":[],"list":[{"anno":[],"expr":{"contents":{"anno":[],"span":"(2:23)-(2:25)","tag":"value","value":{"contents":"var","tag":"variable"}},"tag":"expr"},"name":null,"span":"(2:23)-(2:25)"},{"anno":[],"expr":{"contents":{"anno":[],"span":"(2:27)-(2:27)","tag":"value","value":{"contents":["1",null],"tag":"integer"}},"tag":"expr"},"name":null,"span":"(2:27)-(2:27)"}],"span":"(2:23)-(2:27)"},"function":{"anno":[],"span":"(2:17)-(2:21)","tag":"value","value":{"contents":"d__","tag":"variable"}},"span":"(2:17)-(2:28)","tag":"function_call"},"span":"(2:7)-(2:28)","tag":"assign_expression","target":{"anno":[],"span":"(2:7)-(2:13)","tag":"value","value":{"contents":"somevar","tag":"variable"}}},"tag":"statement"}],"name":"hello","options":[null,null],"span":"(1:7)-(3:9)","subprograms":null,"tag":"subroutine"}]}'.

"first statement in body"
stmt := programFile progUnits first body first.
self assert: stmt size equals: 2.

self assert: programFile progUnits first body first size equals: 2.
self assert: stmt first class equals: IASTVarAccess.
self assert: stmt first entityName equals: 'somevar'.

stmt := programFile progUnits first body first first.
self assert: stmt class equals: IASTVarAccess.
self assert: stmt entityName equals: 'somevar'.

stmt := programFile progUnits first body first second.
self assert: stmt class equals: IASTVarEsoAt.
self deny: stmt isWrite.
self assert: stmt entities size equals: 1
self assert: stmt second class equals: IASTVarEsoAt.
self assert: stmt second entityName equals: 'd__'.

]

Expand Down Expand Up @@ -386,7 +384,7 @@ JsonToIASTVisitorTest >> testEsoArTwoArgs [
{ #category : #'tests-esope' }
JsonToIASTVisitorTest >> testEsoArWithDotArg [

" subroutine hello( )
" subroutine hello( )
d__(p,a(d__(p,i))) = 5
end
"
Expand All @@ -397,28 +395,33 @@ JsonToIASTVisitorTest >> testEsoArWithDotArg [


self assert: programFile progUnits first body first size equals: 1.
d__ := programFile progUnits first body first first.

"first statement in body, first entity in statement"
d__ := programFile progUnits first body first first.
self assert: d__ class equals: IASTVarEsoAt.
self assert: d__ isWrite.
self assert: d__ entities size equals: 2.
self assert: d__ isWrite.

arg := d__ entities first.
self assert: arg class equals: IASTVarAccess.
self deny: arg isWrite.
self assert: arg entityName equals: 'p'.
self deny: arg isWrite.


arg := d__ entities second.
self assert: arg class equals: IASTInvocation.
self assert: arg entityName equals: 'a'.
self assert: arg arguments size equals: 1.
self assert: arg arguments first class equals: IASTVarEsoAt.
self assert: arg arguments first entities size equals: 2.
self assert: arg arguments first entities first class equals: IASTParameter.
self assert: arg arguments first entities first entityName equals: 'p'.
self assert: arg arguments first entities second class equals: IASTParameter.
self assert: arg arguments first entities second entityName equals: 'i'.

d__ := arg arguments first.
self assert: d__ class equals: IASTVarEsoAt.

self assert: d__ entities size equals: 2.
self assert: d__ entities first class equals: IASTParameter.
self assert: d__ entities first entityName equals: 'p'.
self assert: d__ entities second class equals: IASTParameter.
self assert: d__ entities second entityName equals: 'i'.

]

{ #category : #'tests-esope' }
Expand Down
33 changes: 23 additions & 10 deletions src/EsopeImporter/JsonToIASTVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
#category : #'EsopeImporter-Visitor'
}

{ #category : #'private - parsing' }
{ #category : #'private - utilities' }
JsonToIASTVisitor >> astJSON: sourceCode [
FortranProjectImporter new
astJSON: sourceCode
Expand All @@ -30,7 +30,7 @@ JsonToIASTVisitor >> f77sourcefile [
^f77sourcefile
]

{ #category : #'private - parsing' }
{ #category : #'private - utilities' }
JsonToIASTVisitor >> fortranSrcPath [

^ 'fortran-src-extras'
Expand All @@ -50,6 +50,11 @@ JsonToIASTVisitor >> isESOPEFunction: aString [
^#(d__ s__) includes: aString
]

{ #category : #'private - utilities' }
JsonToIASTVisitor >> isSpecialFunctionName: functionName [
^#(d__ s__) includes: functionName
]

{ #category : #'private - utilities' }
JsonToIASTVisitor >> makeIndexedAnchor: aPointPair [
^IASTIndexedFileAnchor new
Expand Down Expand Up @@ -409,17 +414,25 @@ JsonToIASTVisitor >> visitFunctionWithBlocks: aFunctionNode [
{ #category : #'visiting statement' }
JsonToIASTVisitor >> visitFunction_call: aFunctionCallNode [

| astNode data |
| astNode data functionName |
data := super visitFunction_call: aFunctionCallNode.

astNode := IASTInvocation new
entityName: data second;
yourself.
functionName := data second.
astNode := (self isSpecialFunctionName: functionName)
ifTrue: [
(IASTVarEso newFrom: functionName)
entities: data third ;
yourself
]
ifFalse: [IASTInvocation new
arguments: data third ;
yourself
].

^ astNode
sourceAnchor: (self makeIndexedAnchor: data first);
arguments: data third;
yourself
^astNode
entityName: functionName ;
sourceAnchor: (self makeIndexedAnchor: data first) ;
yourself
]

{ #category : #'visiting statement' }
Expand Down

0 comments on commit 2408132

Please sign in to comment.