[flang] Fix source location of some symbol names
authorTim Keith <tkeith@nvidia.com>
Mon, 12 Aug 2019 20:50:45 +0000 (13:50 -0700)
committerTim Keith <tkeith@nvidia.com>
Tue, 13 Aug 2019 16:15:44 +0000 (09:15 -0700)
commit7fcaf88bf807abc88688f8e3b869f5e188beeafb
treebac10cf4af3cd8fe1d76752cb1cb7746b8a1eec1
parent2bc9a1ebed0e1deadbad192822bbe3a6ce212f21
[flang] Fix source location of some symbol names

Symbols can be declared across multiple statements. The CharBlock
that is used for the symbol name is from the first of these.

Sometimes that is not the best choice. If a name appears in a
type-declaration-stmt or a derived-type-stmt, that occurrence is a
better choice. Errors referencing that symbol should normally point
at that name (not its appearance in an earlier PUBLIC statement,
for example).

Also, the order of symbols in .mod files is based on the order of
their names in the cooked source. Here is an example where it is
necessary to sort `a` based on where its type-declaration-stmt
occurs rather than the first occurrence of `a`:
```
  public :: a
  type t
  end type
  type(t), parameter :: a = t()
```

The fix is to add `Symbol::ReplaceName()` so that we can update the
CharBlock for a symbol name when a better one is found, without
changing the actual characters that make up the name.

Original-commit: flang-compiler/f18@5544f163486df1da80d0e343282afc18ce057672
Reviewed-on: https://github.com/flang-compiler/f18/pull/650
Tree-same-pre-rewrite: false
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/symbol.cc
flang/lib/semantics/symbol.h
flang/test/semantics/modfile19.f90
flang/test/semantics/modfile21.f90
flang/test/semantics/modfile30.f90