Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for array specs in fortran 77 cray pointers #216

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Language/Fortran/Parser/Fixed/Fortran77.y
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +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 ')'
{ Declarator () (getTransSpan $1 $5) $2 ScalarDecl Nothing (Just $4) }
: '(' VARIABLE ',' VARIABLE '(' DIMENSION_DECLARATORS ')' ')'
{ Declarator () (getTransSpan $1 $8) $4 (ArrayDecl (aReverse $6)) Nothing (Just $2) }
| '(' VARIABLE ',' VARIABLE ')'
{ 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 }
Expand Down
14 changes: 14 additions & 0 deletions test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down