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

Conversation

ProgramFan
Copy link

This PR adds a parsing rule to handle array specs in cray pointers in fixed-form fortran. The spec is from https://docs.oracle.com/cd/E19957-01/805-4941/z40000a54ba7/index.html. Basic tests with a simple fortran 77 source with -v f77l passed.

@dorchard
Copy link
Member

Thanks for this! Would it be possible for you to put a comment in here to explain that this is for Cray pointers and also to add an example as a test in here: https://github.com/camfort/fortran-src/blob/master/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs?

@ProgramFan
Copy link
Author

Thanks for the review. I am preparing it.

@ProgramFan
Copy link
Author

ProgramFan commented Apr 26, 2022

I added two test cases for cray pointers in the aforementioned test suite, and also a comment line in Fortran77.y.

To be brief, this PR allows fortran-src to parse full cray pointers in fixed-form fortran 77 files. Cited from https://gcc.gnu.org/onlinedocs/gfortran/Cray-pointers.html:

Cray pointers are part of a non-standard extension that provides a C-like pointer in Fortran. This is accomplished through a pair of variables: an integer "pointer" that holds a memory address, and a "pointee" that is used to dereference the pointer.

Pointer/pointee pairs are declared in statements of the form:

pointer ( <pointer> , <pointee> )

or,

pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...

Current Fortran77.y does contain a rule POINTER_LIST to parse such pointers and an AST Node StPointer to store it in the parse tree. However, current grammar assumes pointee to be a scalar variable, while by definition it can be either a scalar or an array. This PR addresses this issue.

To allow for array pointees in cray pointers, this PR adds a matching rule in the POINTER matcher, which directly follows the grammar definition of an array pointee. However, since the AST chooses to store a single <pointer, pointee> pair as a declarator, we have to set the pointee as the declared variable and set the pointer as the initial value to make sense. So in addition to adding the new matching rule, I also swapped the pointer and pointee variable in the scalar pointee declarator definition.

I am open for any suggestions.

@raehik raehik self-assigned this Apr 26, 2022
@raehik
Copy link
Collaborator

raehik commented May 12, 2022

Thanks for this work.

I think we might want another Statement constructor for Cray pointers. StPointer is the standalone statement for the POINTER attribute. How about representing them as (Name, Expression) tuples? Expressions can be array accesses, so that's sorted. (I'm looking into this on my side.)

@raehik
Copy link
Collaborator

raehik commented May 12, 2022

No, that's wrong, I see that pointees can be array declarators. I would still hazard making separate types/constructors for them rather than using Declarator etc., so we can get well-behaving instances (e.g. pretty printing).

@ProgramFan
Copy link
Author

I agree with the idea of making separate constructors for cray pointers, since they can appear in both fixed and free form sources. It would also solve the awkward situation here that I need to workaround the limitation of Declarator. Unfortunately, I am still new to haskell, so I am afraid I am not capable of making such complex changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants