Commit 7f6ffade authored by Rob Pike's avatar Rob Pike

gob: fix the grammar comments to match the encoder

(or at least a correct encoder, still to come).
Change the debug structure slightly to better represent
the grammar.
Minor tweaks for consistency in type.go.

R=rsc
CC=golang-dev
https://golang.org/cl/4007044
parent 7e84666d
...@@ -409,18 +409,8 @@ func (deb *debugger) typeDefinition(indent tab, id typeId, n int) int { ...@@ -409,18 +409,8 @@ func (deb *debugger) typeDefinition(indent tab, id typeId, n int) int {
// Value: // Value:
// ConcreteValue | InterfaceValue
func (deb *debugger) value(indent tab, id typeId, n int) int {
if id == tInterface {
return deb.interfaceValue(indent, n)
}
return deb.concreteValue(indent, id, n)
}
// ConcreteValue:
// SingletonValue | StructValue // SingletonValue | StructValue
func (deb *debugger) concreteValue(indent tab, id typeId, n int) int { func (deb *debugger) value(indent tab, id typeId, n int) int {
wire, ok := deb.wireType[id] wire, ok := deb.wireType[id]
if ok && wire.StructT != nil { if ok && wire.StructT != nil {
return deb.structValue(indent, id, n) return deb.structValue(indent, id, n)
...@@ -429,7 +419,7 @@ func (deb *debugger) concreteValue(indent tab, id typeId, n int) int { ...@@ -429,7 +419,7 @@ func (deb *debugger) concreteValue(indent tab, id typeId, n int) int {
} }
// SingletonValue: // SingletonValue:
// int(0) FieldValue // uint(0) FieldValue
func (deb *debugger) singletonValue(indent tab, id typeId, n int) int { func (deb *debugger) singletonValue(indent tab, id typeId, n int) int {
deb.dump(n, "Singleton value") deb.dump(n, "Singleton value")
// is it a builtin type? // is it a builtin type?
...@@ -438,7 +428,7 @@ func (deb *debugger) singletonValue(indent tab, id typeId, n int) int { ...@@ -438,7 +428,7 @@ func (deb *debugger) singletonValue(indent tab, id typeId, n int) int {
if !ok && wire == nil { if !ok && wire == nil {
errorf("type id %d not defined", id) errorf("type id %d not defined", id)
} }
m, w := deb.readInt() m, w := deb.readUint()
if m != 0 { if m != 0 {
errorf("expected zero; got %d", n) errorf("expected zero; got %d", n)
} }
...@@ -537,9 +527,14 @@ func (deb *debugger) printWireType(indent tab, wire *wireType) { ...@@ -537,9 +527,14 @@ func (deb *debugger) printWireType(indent tab, wire *wireType) {
} }
// fieldValue prints a value of any type, such as a struct field. // fieldValue prints a value of any type, such as a struct field.
// FieldValue:
// builtinValue | ArrayValue | MapValue | SliceValue | StructValue | InterfaceValue
func (deb *debugger) fieldValue(indent tab, id typeId, n int) int { func (deb *debugger) fieldValue(indent tab, id typeId, n int) int {
_, ok := builtinIdToType[id] _, ok := builtinIdToType[id]
if ok { if ok {
if id == tInterface {
return deb.interfaceValue(indent, n)
}
return deb.printBuiltin(indent, id, n) return deb.printBuiltin(indent, id, n)
} }
wire, ok := deb.wireType[id] wire, ok := deb.wireType[id]
...@@ -561,8 +556,6 @@ func (deb *debugger) fieldValue(indent tab, id typeId, n int) int { ...@@ -561,8 +556,6 @@ func (deb *debugger) fieldValue(indent tab, id typeId, n int) int {
// printBuiltin prints a value not of a fundamental type, that is, // printBuiltin prints a value not of a fundamental type, that is,
// one whose type is known to gobs at bootstrap time. // one whose type is known to gobs at bootstrap time.
// That includes interfaces, although they may require
// more unpacking down the line.
func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int { func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int {
switch id { switch id {
case tBool: case tBool:
...@@ -597,8 +590,6 @@ func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int { ...@@ -597,8 +590,6 @@ func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int {
deb.r.Read(b) deb.r.Read(b)
fmt.Fprintf(os.Stderr, "%s%q\n", indent, b) fmt.Fprintf(os.Stderr, "%s%q\n", indent, b)
return w + int(x) return w + int(x)
case tInterface:
return deb.interfaceValue(indent, n)
default: default:
fmt.Print("unknown\n") fmt.Print("unknown\n")
} }
...@@ -607,7 +598,7 @@ func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int { ...@@ -607,7 +598,7 @@ func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int {
// ArrayValue: // ArrayValue:
// uint(n) Value*n // uint(n) FieldValue*n
func (deb *debugger) arrayValue(indent tab, wire *wireType, n int) int { func (deb *debugger) arrayValue(indent tab, wire *wireType, n int) int {
elemId := wire.ArrayT.Elem elemId := wire.ArrayT.Elem
u, w := deb.readUint() u, w := deb.readUint()
...@@ -622,7 +613,7 @@ func (deb *debugger) arrayValue(indent tab, wire *wireType, n int) int { ...@@ -622,7 +613,7 @@ func (deb *debugger) arrayValue(indent tab, wire *wireType, n int) int {
} }
// MapValue: // MapValue:
// uint(n) (Value Value)*n [n (key, value) pairs] // uint(n) (FieldValue FieldValue)*n [n (key, value) pairs]
func (deb *debugger) mapValue(indent tab, wire *wireType, n int) int { func (deb *debugger) mapValue(indent tab, wire *wireType, n int) int {
keyId := wire.MapT.Key keyId := wire.MapT.Key
elemId := wire.MapT.Elem elemId := wire.MapT.Elem
...@@ -636,7 +627,7 @@ func (deb *debugger) mapValue(indent tab, wire *wireType, n int) int { ...@@ -636,7 +627,7 @@ func (deb *debugger) mapValue(indent tab, wire *wireType, n int) int {
} }
// SliceValue: // SliceValue:
// uint(n) (n Values) // uint(n) (n FieldValue)
func (deb *debugger) sliceValue(indent tab, wire *wireType, n int) int { func (deb *debugger) sliceValue(indent tab, wire *wireType, n int) int {
elemId := wire.SliceT.Elem elemId := wire.SliceT.Elem
u, w := deb.readUint() u, w := deb.readUint()
...@@ -648,7 +639,7 @@ func (deb *debugger) sliceValue(indent tab, wire *wireType, n int) int { ...@@ -648,7 +639,7 @@ func (deb *debugger) sliceValue(indent tab, wire *wireType, n int) int {
} }
// StructValue: // StructValue:
// (int(fieldDelta) FieldValue)* // (uint(fieldDelta) FieldValue)*
func (deb *debugger) structValue(indent tab, id typeId, n int) int { func (deb *debugger) structValue(indent tab, id typeId, n int) int {
deb.dump(n, "Start of struct value of %q id=%d\n<<\n", id.name(), id) deb.dump(n, "Start of struct value of %q id=%d\n<<\n", id.name(), id)
fmt.Fprintf(os.Stderr, "%s%s struct {\n", indent, id.name()) fmt.Fprintf(os.Stderr, "%s%s struct {\n", indent, id.name())
......
...@@ -240,11 +240,11 @@ TypedValue: ...@@ -240,11 +240,11 @@ TypedValue:
TypeDefinition: TypeDefinition:
int(-typeId) encodingOfWireType int(-typeId) encodingOfWireType
Value: Value:
ConcreteValue | InterfaceValue
ConcreteValue:
SingletonValue | StructValue SingletonValue | StructValue
SingletonValue: SingletonValue:
int(0) FieldValue uint(0) FieldValue
FieldValue:
builtinValue | ArrayValue | MapValue | SliceValue | StructValue | InterfaceValue
InterfaceValue: InterfaceValue:
NilInterfaceValue | NonNilInterfaceValue NilInterfaceValue | NonNilInterfaceValue
NilInterfaceValue: NilInterfaceValue:
...@@ -258,11 +258,11 @@ InterfaceContents: ...@@ -258,11 +258,11 @@ InterfaceContents:
DelimitedValue: DelimitedValue:
uint(length) Value uint(length) Value
ArrayValue: ArrayValue:
uint(n) Value*n [n elements] uint(n) FieldValue*n [n elements]
MapValue: MapValue:
uint(n) (Value Value)*n [n (key, value) pairs] uint(n) (FieldValue FieldValue)*n [n (key, value) pairs]
SliceValue: SliceValue:
uint(n) Value*n [n elements] uint(n) FieldValue*n [n elements]
StructValue: StructValue:
(uint(fieldDelta) FieldValue)* (uint(fieldDelta) FieldValue)*
*/ */
......
...@@ -93,7 +93,7 @@ var ( ...@@ -93,7 +93,7 @@ var (
tBool = bootstrapType("bool", false, 1) tBool = bootstrapType("bool", false, 1)
tInt = bootstrapType("int", int(0), 2) tInt = bootstrapType("int", int(0), 2)
tUint = bootstrapType("uint", uint(0), 3) tUint = bootstrapType("uint", uint(0), 3)
tFloat = bootstrapType("float", 0.0, 4) tFloat = bootstrapType("float", float64(0), 4)
tBytes = bootstrapType("bytes", make([]byte, 0), 5) tBytes = bootstrapType("bytes", make([]byte, 0), 5)
tString = bootstrapType("string", "", 6) tString = bootstrapType("string", "", 6)
tComplex = bootstrapType("complex", 0+0i, 7) tComplex = bootstrapType("complex", 0+0i, 7)
...@@ -530,7 +530,7 @@ func registerBasics() { ...@@ -530,7 +530,7 @@ func registerBasics() {
Register(uint32(0)) Register(uint32(0))
Register(uint64(0)) Register(uint64(0))
Register(float32(0)) Register(float32(0))
Register(0.0) Register(float64(0))
Register(complex64(0i)) Register(complex64(0i))
Register(complex128(0i)) Register(complex128(0i))
Register(false) Register(false)
......
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