aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/nodes.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2016-09-15 17:40:26 -0700
committerRobert Griesemer <gri@golang.org>2016-09-16 20:58:20 +0000
commit32db3f2756324616b7c856ac9501deccc2491239 (patch)
tree28a6afe4150d7cdcda6f06a8abde0ffeb18de267 /src/cmd/compile/internal/syntax/nodes.go
parent28ed2b0cd9ad6e2015f073931c05c08e8bf7b247 (diff)
downloadgo-32db3f2756324616b7c856ac9501deccc2491239.tar.gz
go-32db3f2756324616b7c856ac9501deccc2491239.zip
cmd/compile/internal/syntax: support for alias declarations
Permits parsing of alias declarations with -newparser const/type/var/func T => p.T but the compiler will reject it with an error. For now this also accepts type T = p.T so we can experiment with a type-alias only scenario. - renamed _Arrow token to _Larrow (<-) - introduced _Rarrow token (=>) - introduced AliasDecl node - extended scanner to accept _Rarrow - extended parser and printer to handle alias declarations Change-Id: I0170d10a87df8255db9186d466b6fd405228c38e Reviewed-on: https://go-review.googlesource.com/29355 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/syntax/nodes.go')
-rw-r--r--src/cmd/compile/internal/syntax/nodes.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/syntax/nodes.go b/src/cmd/compile/internal/syntax/nodes.go
index 280a2e8f69..9555a4b9a8 100644
--- a/src/cmd/compile/internal/syntax/nodes.go
+++ b/src/cmd/compile/internal/syntax/nodes.go
@@ -25,14 +25,21 @@ func (n *node) Line() uint32 {
return n.line
}
+// TODO(gri) clean up init/initFrom once we have a good file pos story
func (n *node) init(p *parser) {
n.pos = uint32(p.pos)
n.line = uint32(p.line)
}
+func (n *node) initFrom(a *node) {
+ n.pos = a.pos
+ n.line = a.line
+}
+
// ----------------------------------------------------------------------------
// Files
+// package PkgName; DeclList[0], DeclList[1], ...
type File struct {
PkgName *Name
DeclList []Decl
@@ -49,6 +56,8 @@ type (
aDecl()
}
+ // Path
+ // LocalPkgName Path
ImportDecl struct {
LocalPkgName *Name // including "."; nil means no rename present
Path *BasicLit
@@ -56,6 +65,18 @@ type (
decl
}
+ // Name => Orig
+ AliasDecl struct {
+ Tok token // Const, Type, Var, or Func
+ Name *Name
+ Orig Expr
+ Group *Group // nil means not part of a group
+ decl
+ }
+
+ // NameList
+ // NameList = Values
+ // NameList Type = Values
ConstDecl struct {
NameList []*Name
Type Expr // nil means no type
@@ -64,13 +85,18 @@ type (
decl
}
+ // Name Type
TypeDecl struct {
Name *Name
Type Expr
+ Alias bool
Group *Group // nil means not part of a group
decl
}
+ // NameList Type
+ // NameList Type = Values
+ // NameList = Values
VarDecl struct {
NameList []*Name
Type Expr // nil means no type
@@ -79,6 +105,10 @@ type (
decl
}
+ // func Name Type { Body }
+ // func Name Type
+ // func Receiver Name Type { Body }
+ // func Receiver Name Type
FuncDecl struct {
Attr map[string]bool // go:attr map
Recv *Field // nil means regular function
@@ -418,6 +448,8 @@ func (simpleStmt) aSimpleStmt() {}
// ----------------------------------------------------------------------------
// Comments
+// TODO(gri) Consider renaming to CommentPos, CommentPlacement, etc.
+// Kind = Above doesn't make much sense.
type CommentKind uint
const (