• Robert Griesemer's avatar
    cmd/compile/internal/syntax: establish principled position information · 5267ac27
    Robert Griesemer authored
    Until now, the parser set the position for each Node to the position of
    the first token belonging to that node. For compatibility with the now
    defunct gc parser, in many places that position information was modified
    when the gcCompat flag was set (which it was, by default). Furthermore,
    in some places, position information was not set at all.
    
    This change removes the gcCompat flag and all associated code, and sets
    position information for all nodes in a more principled way, as proposed
    by mdempsky (see #16943 for details). Specifically, the position of a
    node may not be at the very beginning of the respective production. For
    instance for an Operation `a + b`, the position associated with the node
    is the position of the `+`. Thus, for `a + b + c` we now get different
    positions for the two additions.
    
    This change does not pass toolstash -cmp because position information
    recorded in export data and pcline tables is different. There are no
    other functional changes.
    
    Added test suite testing the position of all nodes.
    
    Fixes #16943.
    
    Change-Id: I3fc02bf096bc3b3d7d2fa655dfd4714a1a0eb90c
    Reviewed-on: https://go-review.googlesource.com/37017
    Run-TryBot: Robert Griesemer <gri@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
    5267ac27
escape_closure.go 5.29 KB