]> Cypherpunks repositories - gostls13.git/commitdiff
gob: fix the grammar comments to match the encoder
authorRob Pike <r@golang.org>
Sat, 22 Jan 2011 00:10:39 +0000 (16:10 -0800)
committerRob Pike <r@golang.org>
Sat, 22 Jan 2011 00:10:39 +0000 (16:10 -0800)
(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

src/pkg/gob/debug.go
src/pkg/gob/doc.go
src/pkg/gob/type.go

index ba55cb497878f79f9c74fae1937cd5d5d91d958d..8d024e0079ea2206068ee13b82c3a974394eb9ad 100644 (file)
@@ -409,18 +409,8 @@ func (deb *debugger) typeDefinition(indent tab, id typeId, n int) int {
 
 
 // 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
-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]
        if ok && wire.StructT != nil {
                return deb.structValue(indent, id, n)
@@ -429,7 +419,7 @@ func (deb *debugger) concreteValue(indent tab, id typeId, n int) int {
 }
 
 // SingletonValue:
-//     int(0) FieldValue
+//     uint(0) FieldValue
 func (deb *debugger) singletonValue(indent tab, id typeId, n int) int {
        deb.dump(n, "Singleton value")
        // is it a builtin type?
@@ -438,7 +428,7 @@ func (deb *debugger) singletonValue(indent tab, id typeId, n int) int {
        if !ok && wire == nil {
                errorf("type id %d not defined", id)
        }
-       m, w := deb.readInt()
+       m, w := deb.readUint()
        if m != 0 {
                errorf("expected zero; got %d", n)
        }
@@ -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:
+//     builtinValue | ArrayValue | MapValue | SliceValue | StructValue | InterfaceValue
 func (deb *debugger) fieldValue(indent tab, id typeId, n int) int {
        _, ok := builtinIdToType[id]
        if ok {
+               if id == tInterface {
+                       return deb.interfaceValue(indent, n)
+               }
                return deb.printBuiltin(indent, id, n)
        }
        wire, ok := deb.wireType[id]
@@ -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,
 // 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 {
        switch id {
        case tBool:
@@ -597,8 +590,6 @@ func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int {
                deb.r.Read(b)
                fmt.Fprintf(os.Stderr, "%s%q\n", indent, b)
                return w + int(x)
-       case tInterface:
-               return deb.interfaceValue(indent, n)
        default:
                fmt.Print("unknown\n")
        }
@@ -607,7 +598,7 @@ func (deb *debugger) printBuiltin(indent tab, id typeId, n int) int {
 
 
 // ArrayValue:
-//     uint(n) Value*n
+//     uint(n) FieldValue*n
 func (deb *debugger) arrayValue(indent tab, wire *wireType, n int) int {
        elemId := wire.ArrayT.Elem
        u, w := deb.readUint()
@@ -622,7 +613,7 @@ func (deb *debugger) arrayValue(indent tab, wire *wireType, n int) int {
 }
 
 // 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 {
        keyId := wire.MapT.Key
        elemId := wire.MapT.Elem
@@ -636,7 +627,7 @@ func (deb *debugger) mapValue(indent tab, wire *wireType, n int) int {
 }
 
 // SliceValue:
-//     uint(n) (n Values)
+//     uint(n) (n FieldValue)
 func (deb *debugger) sliceValue(indent tab, wire *wireType, n int) int {
        elemId := wire.SliceT.Elem
        u, w := deb.readUint()
@@ -648,7 +639,7 @@ func (deb *debugger) sliceValue(indent tab, wire *wireType, n int) int {
 }
 
 // StructValue:
-//     (int(fieldDelta) FieldValue)*
+//     (uint(fieldDelta) FieldValue)*
 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)
        fmt.Fprintf(os.Stderr, "%s%s struct {\n", indent, id.name())
index b5ef7ef08cc65b7d0c522d6193f9a1f0d5484bb4..613974a000fbdc9c6109b33c3de96084bac8af87 100644 (file)
@@ -240,11 +240,11 @@ TypedValue:
 TypeDefinition:
        int(-typeId) encodingOfWireType
 Value:
-       ConcreteValue | InterfaceValue
-ConcreteValue:
        SingletonValue | StructValue
 SingletonValue:
-       int(0) FieldValue
+       uint(0) FieldValue
+FieldValue:
+       builtinValue | ArrayValue | MapValue | SliceValue | StructValue | InterfaceValue
 InterfaceValue:
        NilInterfaceValue | NonNilInterfaceValue
 NilInterfaceValue:
@@ -258,11 +258,11 @@ InterfaceContents:
 DelimitedValue:
        uint(length) Value
 ArrayValue:
-       uint(n) Value*n [n elements]
+       uint(n) FieldValue*n [n elements]
 MapValue:
-       uint(n) (Value Value)*n  [n (key, value) pairs]
+       uint(n) (FieldValue FieldValue)*n  [n (key, value) pairs]
 SliceValue:
-       uint(n) Value*n [n elements]
+       uint(n) FieldValue*n [n elements]
 StructValue:
        (uint(fieldDelta) FieldValue)*
 */
index 22502a6e6b9094cadf11144c460a2ed095086ffd..f613f6e8a9edbd196c1194729aa27ff881838877 100644 (file)
@@ -93,7 +93,7 @@ var (
        tBool      = bootstrapType("bool", false, 1)
        tInt       = bootstrapType("int", int(0), 2)
        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)
        tString    = bootstrapType("string", "", 6)
        tComplex   = bootstrapType("complex", 0+0i, 7)
@@ -530,7 +530,7 @@ func registerBasics() {
        Register(uint32(0))
        Register(uint64(0))
        Register(float32(0))
-       Register(0.0)
+       Register(float64(0))
        Register(complex64(0i))
        Register(complex128(0i))
        Register(false)