[flang-dev] Indirect reference in grammar.h

Kiran Chandramohan via flang-dev flang-dev at lists.llvm.org
Fri May 1 15:58:24 PDT 2020


Hi,

I think an explanation for this can be found in the following comment in parse-tree.h.

"// These are the unavoidable recursively-defined productions of Fortran.
// Some references to the representations of their parses require
// indirection.  The Indirect<> pointer wrapper class is used to
// enforce ownership semantics and non-nullability."


Consider the definition of action-stmt (copied from https://github.com/llvm/llvm-project/blob/master/flang/documentation/f2018-grammar.txt) given below. You can see that action-stmt is recursively defined in terms of itself through the if-stmt. We know that C/C++ does not support recursively defined types (structs, tuples, variants). But it is possible to have a reference or pointer to the same type. Hence the use of the indirection.
https://stackoverflow.com/questions/588623/self-referential-struct-definition


"R515 action-stmt ->
       allocate-stmt | assignment-stmt | backspace-stmt | call-stmt |
       close-stmt | continue-stmt | cycle-stmt | deallocate-stmt |
       endfile-stmt | error-stop-stmt | event-post-stmt | event-wait-stmt |
       exit-stmt | fail-image-stmt | flush-stmt | form-team-stmt |
       goto-stmt | if-stmt | inquire-stmt | lock-stmt | nullify-stmt |
       open-stmt | pointer-assignment-stmt | print-stmt | read-stmt |
       return-stmt | rewind-stmt | stop-stmt | sync-all-stmt |
       sync-images-stmt | sync-memory-stmt | sync-team-stmt | unlock-stmt |
       wait-stmt | where-stmt | write-stmt | computed-goto-stmt | forall-stmt

R1139 if-stmt -> IF ( scalar-logical-expr ) action-stmt"

--Kiran

________________________________
From: flang-dev <flang-dev-bounces at lists.llvm.org> on behalf of ankit sharma via flang-dev <flang-dev at lists.llvm.org>
Sent: 30 April 2020 11:23
To: flang-dev at lists.llvm.org <flang-dev at lists.llvm.org>
Subject: [flang-dev] Indirect reference in grammar.h

Hi,

I am looking into source code and in grammar.h file, few production rules include indirect reference to parser's return type e.g. in ProgramUnit and ActionStmt.
How these productions are different from others by using indirect reference?

Thanks,
Ankit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/flang-dev/attachments/20200501/550e3dc4/attachment.html>


More information about the flang-dev mailing list