From a3779d80dcfd8bd68c517d3d2b775be8aa7e5d75 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Mon, 25 Apr 2022 00:47:20 +0800 Subject: [PATCH 1/2] feat: support array-style cray pointers in Fortran77 --- src/Language/Fortran/Parser/Fixed/Fortran77.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Language/Fortran/Parser/Fixed/Fortran77.y b/src/Language/Fortran/Parser/Fixed/Fortran77.y index 1abca141..e4074664 100644 --- a/src/Language/Fortran/Parser/Fixed/Fortran77.y +++ b/src/Language/Fortran/Parser/Fixed/Fortran77.y @@ -607,7 +607,9 @@ POINTER_LIST :: { [ Declarator A0 ] } | POINTER { [ $1 ] } POINTER :: { Declarator A0 } -: '(' VARIABLE ',' VARIABLE ')' +: '(' VARIABLE ',' VARIABLE '(' DIMENSION_DECLARATORS ')' ')' + { Declarator () (getTransSpan $1 $8) $2 (ArrayDecl (aReverse $6)) Nothing (Just $4) } +| '(' VARIABLE ',' VARIABLE ')' { Declarator () (getTransSpan $1 $5) $2 ScalarDecl Nothing (Just $4) } COMMON_GROUPS :: { AList CommonGroup A0 } From eb1511c1502352453bd76426fa452270ea59fb61 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Tue, 26 Apr 2022 23:06:42 +0800 Subject: [PATCH 2/2] feat: make cray pointer AST node consistant --- src/Language/Fortran/Parser/Fixed/Fortran77.y | 5 +++-- .../Fortran/Parser/Fixed/Fortran77/ParserSpec.hs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Language/Fortran/Parser/Fixed/Fortran77.y b/src/Language/Fortran/Parser/Fixed/Fortran77.y index e4074664..420dc69e 100644 --- a/src/Language/Fortran/Parser/Fixed/Fortran77.y +++ b/src/Language/Fortran/Parser/Fixed/Fortran77.y @@ -606,11 +606,12 @@ POINTER_LIST :: { [ Declarator A0 ] } : POINTER_LIST ',' POINTER { $3 : $1 } | POINTER { [ $1 ] } +-- Cray pointers as of https://gcc.gnu.org/onlinedocs/gfortran/Cray-pointers.html POINTER :: { Declarator A0 } : '(' VARIABLE ',' VARIABLE '(' DIMENSION_DECLARATORS ')' ')' - { Declarator () (getTransSpan $1 $8) $2 (ArrayDecl (aReverse $6)) Nothing (Just $4) } + { Declarator () (getTransSpan $1 $8) $4 (ArrayDecl (aReverse $6)) Nothing (Just $2) } | '(' VARIABLE ',' VARIABLE ')' - { Declarator () (getTransSpan $1 $5) $2 ScalarDecl Nothing (Just $4) } + { Declarator () (getTransSpan $1 $5) $4 ScalarDecl Nothing (Just $2) } COMMON_GROUPS :: { AList CommonGroup A0 } : COMMON_GROUPS COMMON_GROUP { setSpan (getTransSpan $1 $2) $ $2 `aCons` $1 } diff --git a/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs b/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs index 0e709a2d..630be494 100644 --- a/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs +++ b/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs @@ -387,6 +387,20 @@ spec = resetSrcSpan (slParser autoSrc) `shouldBe` autoStmt resetSrcSpan (slParser staticSrc) `shouldBe` staticStmt + describe "Cray Pointer Extension" $ do + it "parses simple pointee decleration" $ do + let pointerStmt = StPointer () u (AList () u [p]) + p = Declarator () u (varGen "y") ScalarDecl Nothing (Just (varGen "x")) + pointerSrc = " pointer (x, y)" + resetSrcSpan (slParser pointerSrc) `shouldBe` pointerStmt + it "parses array pointee decleration" $ do + let pointerStmt = StPointer () u (AList () u [p]) + p = Declarator () u (varGen "y") arrayDecl Nothing (Just (varGen "x")) + arrayDecl = ArrayDecl (AList () u [dim]) + dim = DimensionDeclarator () u Nothing (Just $ intGen 3) + pointerSrc = " pointer (x, y(3))" + resetSrcSpan (slParser pointerSrc) `shouldBe` pointerStmt + exampleProgram1 :: String exampleProgram1 = unlines [ " program hello"