• Russ Cox's avatar
    cmd/cover: modify source as text, not as AST · 2c00dea1
    Russ Cox authored
    cmd/cover rewrites Go source code to add coverage annotations.
    The approach to date has been to parse the code to AST, analyze it,
    rewrite the AST, and print it back out. This approach fails to preserve
    line numbers in the original code and has a very difficult time with
    comments, because go/printer does as well.
    
    This CL changes cmd/cover to decide what to modify based on the
    AST but to apply the modifications as purely textual substitutions.
    In this way, cmd/cover can be sure it never adds or removes a newline
    character, nor a comment, so all line numbers and comments are
    preserved.
    
    This also allows us to emit a single //line comment at the beginning
    of the translated file and have the compiler report errors with
    correct line numbers in the original file.
    
    Fixes #6329.
    Fixes #15757.
    
    Change-Id: Ia95f6f894bb498e80d1f91fde56cd4a8009d7f9b
    Reviewed-on: https://go-review.googlesource.com/77150Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    2c00dea1
Name
Last commit
Last update
.github Loading commit data...
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...