aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-06-21 11:51:34 -0700
committerRobert Griesemer <gri@golang.org>2017-06-21 23:27:59 +0000
commit7a2fb4048e4f16c5cad5e90f87a62afd199d3367 (patch)
tree712865e725d2bebf48c7669a736d5e53f3f2bd6a /src
parent0b6fbaae6ec4218fc35d8a6f4415ae8f88198301 (diff)
downloadgo-7a2fb4048e4f16c5cad5e90f87a62afd199d3367.tar.xz
go/ast: improved documentation for comments associated with an AST
Fixes #18593. Change-Id: Ibe33ad9b536fee909120b3654b9d831e469eb285 Reviewed-on: https://go-review.googlesource.com/46370 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/go/ast/ast.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/go/ast/ast.go b/src/go/ast/ast.go
index 2ecc48b741..7336a5d2d0 100644
--- a/src/go/ast/ast.go
+++ b/src/go/ast/ast.go
@@ -967,6 +967,19 @@ func (*FuncDecl) declNode() {}
// appearance, including the comments that are pointed to from other nodes
// via Doc and Comment fields.
//
+// For correct printing of source code containing comments (using packages
+// go/format and go/printer), special care must be taken to update comments
+// when a File's syntax tree is modified: For printing, comments are inter-
+// spersed between tokens based on their position. If syntax tree nodes are
+// removed or moved, relevant comments in their vicinity must also be removed
+// (from the File.Comments list) or moved accordingly (by updating their
+// positions). A CommentMap may be used to facilitate some of these operations.
+//
+// Whether and how a comment is associated with a node depends on the inter-
+// pretation of the syntax tree by the manipulating program: Except for Doc
+// and Comment comments directly associated with nodes, the remaining comments
+// are "free-floating" (see also issues #18593, #20744).
+//
type File struct {
Doc *CommentGroup // associated documentation; or nil
Package token.Pos // position of "package" keyword