]> Cypherpunks repositories - gostls13.git/commit
cmd/cgo: modify source as text, not as AST
authorRuss Cox <rsc@golang.org>
Fri, 10 Nov 2017 16:45:16 +0000 (11:45 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 16 Nov 2017 16:33:06 +0000 (16:33 +0000)
commit85c3ebf4dde67026a703dd7c4a3b64ffc307e115
tree51bbc1490a5635910f0f2cfb88d4dd80525d3375
parent1d47a145913f76f64414bbbc14bff3c95450535e
cmd/cgo: modify source as text, not as AST

Cgo has always operated by rewriting the AST and invoking go/printer.
This CL converts it to use the AST to make decisions but then apply
its edits directly to the underlying source text. This approach worked
better in rsc.io/grind (used during the C to Go conversion) and also
more recently in cmd/cover. It guarantees that all comments and
line numbers are preserved exactly.

This eliminates a lot of special concern about comments and
problems with cgo not preserving meaningful comments.
Combined with the CL changing cmd/cover to use the same
approach, it means that the combination of applying cgo and
applying cover still guarantees all comments and line numbers
are preserved exactly.

This sets us up to fix some cgo vs cover bugs by swapping
the order in which they run during the go command.

This also sets up #16623 a bit: the edit list being
accumulated here is nearly exactly what you'd want
to pass to the compiler for that issue.

Change-Id: I7611815be22e7c5c0d4fc3fa11832c42b32c4eb3
Reviewed-on: https://go-review.googlesource.com/77153
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/cgo/ast.go
src/cmd/cgo/gcc.go
src/cmd/cgo/main.go
src/cmd/cgo/out.go
src/cmd/dist/buildtool.go