Skip to content

Commit

Permalink
Testing export of statements/comments in the proper order (sorted on …
Browse files Browse the repository at this point in the history
…their startPos
  • Loading branch information
anquetil committed Sep 12, 2023
1 parent 56f3c21 commit 3135f27
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,30 @@ FASTFortranExporterVisitorTest >> testAssignementStatementVariable [
'
]

{ #category : #'tests - statements' }
FASTFortranExporterVisitorTest >> testBlockStatementWithCommentAndStatement [
"note: positions are approximate, all we need is that the assignement is after the comment"
| stmt cmt block |

stmt := self assignementStatement: 'i' value: (self integerLiteral: '1').
stmt startPos: 34.
stmt endPos: 38.

cmt := self comment: ' comment before assignement'.
cmt startPos: 1.
cmt endPos: 26.

block := self statementBlock: { stmt }.
block addComment: cmt.

self
assertExport: block
equals:
'C comment before assignement
i = 1
'
]

{ #category : #'tests - statements' }
FASTFortranExporterVisitorTest >> testCallStatementNoArgs [
| stmt |
Expand Down Expand Up @@ -585,17 +609,20 @@ FASTFortranExporterVisitorTest >> testTwoDeclarationsArray [

{ #category : #'tests - statements' }
FASTFortranExporterVisitorTest >> testTwoDeclarationsTwoVariables [
| sub |
| sub stmt |
sub := self subroutine: 'blah'.
self
entity: sub
statementBlock: {
self
declarationStatement: (self integerType: nil)
variables: #(i) .
self
declarationStatement: (self integerType: nil)
variables: #(j) }.

stmt := self
declarationStatement: (self integerType: nil)
variables: #(i).
sub statementBlock addStatement: stmt.

stmt := self
declarationStatement: (self integerType: nil)
variables: #(j).
stmt startPos: 11.
stmt endPos: 15.
sub statementBlock addStatement: stmt.

self
assertExport: sub
Expand Down
10 changes: 10 additions & 0 deletions src/FAST-Fortran/FASTFortranExporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ FASTFortranExporterVisitor >> visitFASTFortranScalarVariable: aFASTFortranScalar
self << aFASTFortranScalarVariable name
]

{ #category : #'visiting - statements' }
FASTFortranExporterVisitor >> visitFASTFortranStatementBlock: aFASTFortranStatementBlock [
"must output statements and comments in the right order"

(SortedCollection sortBlock: [ :a :b | a startPos < b startPos ])
addAll: aFASTFortranStatementBlock statements ;
addAll: aFASTFortranStatementBlock comments ;
do: [ :each | each accept: self ]
]

{ #category : #'visiting - programUnits' }
FASTFortranExporterVisitor >> visitFASTFortranSubroutine: aFASTFortranSubroutine [
self
Expand Down

0 comments on commit 3135f27

Please sign in to comment.