[flang] Process specification parts before execution parts
authorTim Keith <tkeith@nvidia.com>
Mon, 6 May 2019 14:26:43 +0000 (07:26 -0700)
committerTim Keith <tkeith@nvidia.com>
Mon, 6 May 2019 14:26:43 +0000 (07:26 -0700)
commit14094c71c87d3c3ea077c0162d76d8730343b503
treeaab59e70a38c78518513f0dd9ad7c5d8266e576e
parent12f166011725a04c1c043fce817a96169b5e0a2a
[flang] Process specification parts before execution parts

Change the order in which names are resolved. Before resolving names
in the execution part of a subprogram we need to know the interface
of contained subprograms. This is because the type of some construct
entities can depend on the return type of contained functions, e.g.
```
  associate(x => f())
  end associate
contains
  function f()...
```

To do this, we now build a tree rooted at each program unit with
child nodes corresponding to subprograms contained in the parent.
This provides flexibility in choosing an order to resolve names.
The current implementation processes all specification parts before
any execution parts. This ensures contained subprogram interfaces
are know before analyzing constructs like ASSOCIATE.

Resolving a specification part involves first adding
`SubprogramNameDetails` symbols for each contained subprogram, then
processing the statement that introduces the program unit (`ModuleStmt`,
`SubroutineStmt`, etc.), then visiting all of the statements in the
specification part.

If it proves necessary, we can add a phase to do implicit declarations
in the execution part before processing the specification part of
contained subprograms.

Original-commit: flang-compiler/f18@20e803fd9289759a4e421794bdb9b401ee709da2
Reviewed-on: https://github.com/flang-compiler/f18/pull/443
Tree-same-pre-rewrite: false
flang/lib/semantics/resolve-names-utils.cc
flang/lib/semantics/resolve-names-utils.h
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/symbol.cc
flang/test/semantics/resolve36.f90
flang/test/semantics/symbol02.f90
flang/test/semantics/symbol11.f90