[flang] Strip whitespace from parse tree source locations
authorTim Keith <tkeith@nvidia.com>
Tue, 19 Mar 2019 20:38:54 +0000 (13:38 -0700)
committerTim Keith <tkeith@nvidia.com>
Tue, 19 Mar 2019 20:38:54 +0000 (13:38 -0700)
commit299628e2cbcf1576deb8b451348ef87ef355d3d8
treea6b245fc1dcd8a220b77c0c076794981cf890c32
parentf697aacb3a33882b043b459e08c72d33049a5b29
[flang] Strip whitespace from parse tree source locations

Parse tree nodes have `source` fields that map the node back to
a range in the cooked input stream. These are used for names and
to locate error messages.

This change strips spaces from the beginning and end of those
source ranges before they are saved. This fixes two problems:
1. For a statement like this: `generic :: operator(+) => ...`,
   the name of the symbol we want to create is "operator(+)" but
   the parser was including the following space in the CharBlock
   it captured.
2. Error messages referring to parts of expressions sometimes included
   extra spaces in the source locations. For example:
   ```
   t.f90:9:29: error: subscripts may be applied only to an object or component
    integer, parameter :: b = a(1) + 1
                              ^^^^^
   t.f90:4:8: error: operands to LOGICAL operation must be LOGICAL
    i = j .or. k
         ^^^^^^^
   ```

Original-commit: flang-compiler/f18@fa14297967b7852fd130790eca4186f259f0a1f2
Reviewed-on: https://github.com/flang-compiler/f18/pull/343
Tree-same-pre-rewrite: false
flang/lib/parser/basic-parsers.h
flang/test/semantics/modfile07.f90
flang/test/semantics/resolve11.f90
flang/test/semantics/resolve13.f90