Преглед изворни кода

goprotobuf: Minor internal change to track internal message indexes.

R=adg
CC=golang-dev
https://codereview.appspot.com/7395047
David Symonds пре 13 година
родитељ
комит
69cffb22f0
1 измењених фајлова са 9 додато и 4 уклоњено
  1. 9 4
      protoc-gen-go/generator/generator.go

+ 9 - 4
protoc-gen-go/generator/generator.go

@@ -103,7 +103,7 @@ type Descriptor struct {
 	nested   []*Descriptor          // Inner messages, if any.
 	nested   []*Descriptor          // Inner messages, if any.
 	ext      []*ExtensionDescriptor // Extensions, if any.
 	ext      []*ExtensionDescriptor // Extensions, if any.
 	typename []string               // Cached typename vector.
 	typename []string               // Cached typename vector.
-	index    int                    // If a top-level message, the index into message_type.
+	index    int                    // The index into the container, whether the file or another message.
 	group    bool
 	group    bool
 }
 }
 
 
@@ -684,7 +684,12 @@ func (g *Generator) buildNestedDescriptors(descs []*Descriptor) {
 
 
 // Construct the Descriptor and add it to the slice
 // Construct the Descriptor and add it to the slice
 func addDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) []*Descriptor {
 func addDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) []*Descriptor {
-	d := &Descriptor{common{file}, desc, parent, nil, nil, nil, index, false}
+	d := &Descriptor{
+		common:          common{file},
+		DescriptorProto: desc,
+		parent:          parent,
+		index:           index,
+	}
 
 
 	// The only way to distinguish a group from a message is whether
 	// The only way to distinguish a group from a message is whether
 	// the containing message has a TYPE_GROUP field that matches.
 	// the containing message has a TYPE_GROUP field that matches.
@@ -723,8 +728,8 @@ func wrapDescriptors(file *descriptor.FileDescriptorProto) []*Descriptor {
 func wrapThisDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) []*Descriptor {
 func wrapThisDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) []*Descriptor {
 	sl = addDescriptor(sl, desc, parent, file, index)
 	sl = addDescriptor(sl, desc, parent, file, index)
 	me := sl[len(sl)-1]
 	me := sl[len(sl)-1]
-	for _, nested := range desc.NestedType {
-		sl = wrapThisDescriptor(sl, nested, me, file, 0)
+	for i, nested := range desc.NestedType {
+		sl = wrapThisDescriptor(sl, nested, me, file, i)
 	}
 	}
 	return sl
 	return sl
 }
 }