From 7431a5078a188b2edb8c5985798b72b7d2eb5662 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 12 Sep 2023 13:46:41 +0200 Subject: [PATCH 1/4] exporting comments --- .../FASTFortranExporterVisitorTest.class.st | 19 +++++++++++++++++++ .../FASTFortranExporterVisitor.class.st | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st b/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st index 67b43a98..f2d90c62 100644 --- a/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st +++ b/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st @@ -57,6 +57,13 @@ FASTFortranExporterVisitorTest >> characterType: dimension [ ^FASTFortranCharacterType new ] +{ #category : #'entity creation' } +FASTFortranExporterVisitorTest >> comment: text [ + ^FASTFortranComment new + content: text ; + yourself +] + { #category : #'entity creation' } FASTFortranExporterVisitorTest >> declarationStatement: type variables: aCollection [ ^FASTFortranDeclarationStatement new @@ -275,6 +282,18 @@ FASTFortranExporterVisitorTest >> testCallStatementWithArgs [ ' ] +{ #category : #tests } +FASTFortranExporterVisitorTest >> testComment [ + | cmt | + cmt := self comment: 'This is a comment'. + + self + assertExport: cmt + equals: +'CThis is a comment +'. +] + { #category : #'tests - statements' } FASTFortranExporterVisitorTest >> testDoStatement [ | stmt init | diff --git a/src/FAST-Fortran/FASTFortranExporterVisitor.class.st b/src/FAST-Fortran/FASTFortranExporterVisitor.class.st index 7fea1ade..ed4e2d25 100644 --- a/src/FAST-Fortran/FASTFortranExporterVisitor.class.st +++ b/src/FAST-Fortran/FASTFortranExporterVisitor.class.st @@ -273,6 +273,15 @@ FASTFortranExporterVisitor >> visitFASTFortranTCharacterLiteral: aFASTFortranTLi << '''' ] +{ #category : #'visiting - traits' } +FASTFortranExporterVisitor >> visitFASTFortranTComment: aFASTFortranTComment [ + + self + << 'C' ; + << aFASTFortranTComment content ; + newLine +] + { #category : #'visiting - traits' } FASTFortranExporterVisitor >> visitFASTFortranTLiteral: aFASTFortranTLiteral [ self << aFASTFortranTLiteral primitiveValue From e24399941380e82addb7746ea0851ce9fa5c2646 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 12 Sep 2023 13:47:13 +0200 Subject: [PATCH 2/4] recategorizing a method --- src/FAST-Fortran/FASTFortranExporterVisitor.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FAST-Fortran/FASTFortranExporterVisitor.class.st b/src/FAST-Fortran/FASTFortranExporterVisitor.class.st index ed4e2d25..97d05918 100644 --- a/src/FAST-Fortran/FASTFortranExporterVisitor.class.st +++ b/src/FAST-Fortran/FASTFortranExporterVisitor.class.st @@ -35,7 +35,7 @@ FASTFortranExporterVisitor >> resetStream [ stream := nil ] -{ #category : #visiting } +{ #category : #accessing } FASTFortranExporterVisitor >> rootEntitiesIn: aFASTFortranModel [ ^aFASTFortranModel entities select: [ :entity | entity parents isEmpty From 56f3c214100eb73b28a9da68941a6aa280f6f3d8 Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 12 Sep 2023 14:30:38 +0200 Subject: [PATCH 3/4] Adding start/end-pos to created entities in tests --- .../FASTFortranExporterVisitorTest.class.st | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st b/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st index f2d90c62..1a92acc7 100644 --- a/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st +++ b/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st @@ -20,9 +20,13 @@ FASTFortranExporterVisitorTest >> assertExport: anEntity equals: expectedString { #category : #'entity creation' } FASTFortranExporterVisitorTest >> assignementStatement: aName value: rhs [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranAssignmentStatement new variable: (self scalarVariable: aName) ; expression: rhs ; + startPos: 1 ; + endPos: aName size + 3 ; yourself ] @@ -38,10 +42,14 @@ FASTFortranExporterVisitorTest >> binary: op left: lhsVar right: rhsVal [ ] { #category : #'entity creation' } -FASTFortranExporterVisitorTest >> callStatement: aName arguments: aCollection [ +FASTFortranExporterVisitorTest >> callStatement: aName arguments: aCollection [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranCallStatement new name: aName ; arguments: aCollection ; + startPos: 1 ; + endPos: aName size + 4 ; yourself ] @@ -60,23 +68,33 @@ FASTFortranExporterVisitorTest >> characterType: dimension [ { #category : #'entity creation' } FASTFortranExporterVisitorTest >> comment: text [ ^FASTFortranComment new - content: text ; + content: text asString ; + startPos: 1 ; + endPos: text asString size + 1 ; yourself ] { #category : #'entity creation' } FASTFortranExporterVisitorTest >> declarationStatement: type variables: aCollection [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranDeclarationStatement new type: type ; declarators: (self scalarVariables: aCollection) ; + startPos: 1 ; + endPos: 10 ; yourself ] { #category : #'entity creation' } FASTFortranExporterVisitorTest >> doStatement: control statements: stmtBlock [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranDoStatement new loopControl: control ; statementBlock: (self statementBlock: stmtBlock) ; + startPos: 1 ; + endPos: 20 ; yourself ] @@ -87,27 +105,24 @@ FASTFortranExporterVisitorTest >> entity: owner parameters: aCollection [ yourself ] -{ #category : #'entity creation' } -FASTFortranExporterVisitorTest >> entity: owner statementBlock: aCollection [ - ^owner - statementBlock: (FASTFortranStatementBlock new - statements: aCollection ; - yourself) - yourself -] - { #category : #'entity creation' } FASTFortranExporterVisitorTest >> externalStatement: aName [ ^FASTFortranExternalStatement new name: aName ; + startPos: 1 ; + endPos: 8 ; yourself ] { #category : #'entity creation' } FASTFortranExporterVisitorTest >> functionCall: aName arguments: aCollection [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranFunctionCall new name: aName ; arguments: aCollection ; + startPos: 1 ; + endPos: aName size + 3 ; yourself ] @@ -123,6 +138,10 @@ FASTFortranExporterVisitorTest >> ifBlock: condition then: thenBlock else: elseB { #category : #'entity creation' } FASTFortranExporterVisitorTest >> implicitStatement [ ^FASTFortranImplicitStatement new + startPos: 1 ; + endPos: 13 ; + yourself + ] { #category : #'entity creation' } @@ -174,8 +193,12 @@ FASTFortranExporterVisitorTest >> realType: dimension [ { #category : #'entity creation' } FASTFortranExporterVisitorTest >> returnStatement: expression [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranReturnStatement new expression: expression ; + startPos: 1 ; + endPos: 6 ; yourself ] @@ -202,14 +225,20 @@ FASTFortranExporterVisitorTest >> setUp [ FASTFortranExporterVisitorTest >> statementBlock: aCollection [ ^FASTFortranStatementBlock new statements: aCollection ; + startPos: 1 ; + endPos: (aCollection ifNotEmpty: [ aCollection last endPos ] ifEmpty: [ 2 ]) ; yourself ] { #category : #'entity creation' } FASTFortranExporterVisitorTest >> subroutine: aName [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranSubroutine new name: aName ; statementBlock: (self statementBlock: #()) ; + startPos: 1 ; + endPos: 50 ; yourself ] @@ -592,8 +621,12 @@ FASTFortranExporterVisitorTest >> testWriteStatement [ { #category : #'entity creation' } FASTFortranExporterVisitorTest >> writeStatement: aCollection [ + "end position is approximate, test should adjust if a real value is needed" + ^FASTFortranWriteStatement new format: { FASTFortranAsterisk new . FASTFortranAsterisk new } ; arguments: aCollection ; + startPos: 1 ; + endPos: 30 ; yourself ] From 3135f273fc69ec4761c570f292c7af1c943bc88b Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 12 Sep 2023 14:31:34 +0200 Subject: [PATCH 4/4] Testing export of statements/comments in the proper order (sorted on their startPos --- .../FASTFortranExporterVisitorTest.class.st | 47 +++++++++++++++---- .../FASTFortranExporterVisitor.class.st | 10 ++++ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st b/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st index 1a92acc7..e8e0eecb 100644 --- a/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st +++ b/src/FAST-Fortran-Tests/FASTFortranExporterVisitorTest.class.st @@ -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 | @@ -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 diff --git a/src/FAST-Fortran/FASTFortranExporterVisitor.class.st b/src/FAST-Fortran/FASTFortranExporterVisitor.class.st index 97d05918..c62d57ff 100644 --- a/src/FAST-Fortran/FASTFortranExporterVisitor.class.st +++ b/src/FAST-Fortran/FASTFortranExporterVisitor.class.st @@ -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