[flang] Handle parameter-dependent types in PDT initializers
authorPeter Klausler <pklausler@nvidia.com>
Wed, 13 Apr 2022 17:39:16 +0000 (10:39 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Fri, 15 Apr 2022 23:20:41 +0000 (16:20 -0700)
commit9e7eef9989d365214b2b62be630d0bc9d9e94968
treeb722f70aec5359dd9ecf46f1b484165f605c23e1
parent3be3b401888ace347018abd077912868bbc416b3
[flang] Handle parameter-dependent types in PDT initializers

For parameterized derived type component initializers whose
expressions' types depend on parameter values, f18's current
scheme of analyzing the initialization expression once during
name resolution fails.  For example,

  type :: pdt(k)
    integer, kind :: k
    real :: component = real(0.0, kind=k)
  end type

To handle such cases, it is necessary to re-analyze the parse
trees of these initialization expressions once for each distinct
initialization of the type.

This patch adds code to wipe an expression parse tree of its
typed expressions, and update those of its symbol table pointers
that reference type parameters, and then re-analyze that parse
tree to generate the properly typed component initializers.

Differential Revision: https://reviews.llvm.org/D123728
13 files changed:
flang/include/flang/Common/indirection.h
flang/include/flang/Parser/unparse.h
flang/include/flang/Semantics/expression.h
flang/include/flang/Semantics/symbol.h
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/expression.cpp
flang/lib/Semantics/mod-file.cpp
flang/lib/Semantics/resolve-names.cpp
flang/lib/Semantics/symbol.cpp
flang/lib/Semantics/type.cpp
flang/test/Semantics/init01.f90
flang/test/Semantics/modfile48.f90 [new file with mode: 0644]
flang/test/Semantics/structconst02.f90