Commit e3fc1246 authored by Robert Griesemer's avatar Robert Griesemer

revert specification of pointer types to current implementation

(do not allow explicit type forward declarations) and more clearly
specify resolution

R=r
DELTA=30  (9 added, 7 deleted, 14 changed)
OCL=13967
CL=13987
parent 69353f0a
...@@ -4,7 +4,7 @@ The Go Programming Language (DRAFT) ...@@ -4,7 +4,7 @@ The Go Programming Language (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson Robert Griesemer, Rob Pike, Ken Thompson
---- ----
(August 4, 2008) (August 7, 2008)
This document is a semi-formal specification/proposal for a new This document is a semi-formal specification/proposal for a new
systems programming language. The document is under active systems programming language. The document is under active
...@@ -709,33 +709,33 @@ key-value pairs separated by a colon: ...@@ -709,33 +709,33 @@ key-value pairs separated by a colon:
TODO: helper syntax for nested arrays etc? (avoids repeating types but TODO: helper syntax for nested arrays etc? (avoids repeating types but
complicates the spec needlessly.) complicates the spec needlessly.)
Pointer types Pointer types
---- ----
Pointer types are similar to those in C. Pointer types are similar to those in C.
PointerType = "*" Type. PointerType = "*" ElementType.
Pointer arithmetic of any kind is not permitted. Pointer arithmetic of any kind is not permitted.
*int *int
*map[string] *chan *map[string] *chan
It is legal to write a pointer type (only) such as *T even if T is For pointer types (only), the pointer element type may be an
an incomplete type (i.e., either not yet fully defined or forward identifier referring to an incomplete (not yet fully defined) or undeclared
declared). This allows the construction of recursive types such as: type. This allows the construction of recursive and mutually recursive types
such as:
type S struct { s *S } type S struct { s *S }
Together with a type forward declaration, mutually recursive types
can be constructed such as:
type S2 // forward declaration of S2
type S1 struct { s2 *S2 } type S1 struct { s2 *S2 }
type S2 struct { s1 *S1 } type S2 struct { s1 *S1 }
By the end of the package source, all forward-declared types must be If the element type is an undeclared identifier, the declaration implicitly
fully declared if they are used. forward-declares an (incomplete) type with the respective name. By the end
of the package source, any such forward-declared type must be completely
declared in the same or an outer scope.
Channel types Channel types
...@@ -1059,26 +1059,28 @@ TODO move/re-arrange section on iota. ...@@ -1059,26 +1059,28 @@ TODO move/re-arrange section on iota.
Type declarations Type declarations
---- ----
A type declaration introduces a name as a shorthand for a type. The name refers A type declaration introduces a name as a shorthand for a type.
to an incomplete type until the type specification is complete. If no type is
provided at all, the declaration effectively serves as a forward declaration.
Incomplete types can be used together (and only) with pointer types.
TypeDecl = "type" ( TypeSpec | "(" TypeSpecList [ ";" ] ")" ). TypeDecl = "type" ( TypeSpec | "(" TypeSpecList [ ";" ] ")" ).
TypeSpec = identifier [ Type ] . TypeSpec = identifier Type .
TypeSpecList = TypeSpec { ";" TypeSpec }. TypeSpecList = TypeSpec { ";" TypeSpec }.
The name refers to an incomplete type until the type specification is complete.
Incomplete types can be referred to only by pointer types. Consequently, in a
type declaration a type may not refer to itself unless it does so with a pointer
type.
type List // forward declaration
type IntArray [16] int type IntArray [16] int
type ( type (
Point struct { x, y float }; Point struct { x, y float };
Polar Point Polar Point
) )
Since incomplete types can only be used with pointer types, in a type type TreeNode struct {
declaration a type may not refer to itself unless it does so with a left, right *TreeNode;
pointer type. value Point;
}
Variable declarations Variable declarations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment