cmd/protoc-gen-go: add support for protobuf reflection

Implement support in protoc-gen-go for generating messages and enums
that satisfy the v2 protobuf reflection interfaces. Specifically, the following
are added:
* top-level variable representing the file descriptor
* ProtoReflect method on enums (to implement protoV2.Enum)
* ProtoReflect method on messages (to implement protoV2.Message)

The following are not supported yet:
* resolving transitive dependencies for file imports
* Extension descriptors
* Service descriptors

The implementation approach creates a single array for all the message and enum
declarations and references sections of that array to complete dependencies.
Since protobuf declarations can form a graph (a message may depend on itself),
it is difficult to construct a graph as a single literal. One way is to use
placeholder descriptors, but that is not efficient as it requires encoding
the full name of each dependent enum and message and then later resolving it;
thus, both expanding the binary size and also increasing initialization cost.
Instead, we add a prototype.{Enum,Message}.Reference method to obtain a
descriptor reference for the purposes for satisfying dependencies.
As such, nested declarations and dependencies are populated in an init function.

Other changes to support the implementation:
* Added a protoimpl package to expose the MessageType type and also the
MessageTypeOf and EnumTypeOf helper functions.
* Added a protogen.File.GoIdent field to provide a suggested variable name
for the file descriptor.
* Added prototype.{Enum,Message}.Reference that provides a descriptor reference
for the purposes for satisfying cyclic dependencies.
* Added protoreflect.{Syntax,Cardinality,Kind}.GoString to obtain a Go source
identifier that represents the given constant.

Change-Id: I9455764882dee6ad10f251901e7d419091e8bf1d
Reviewed-on: https://go-review.googlesource.com/c/150074
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/protogen/protogen.go b/protogen/protogen.go
index 95a499f..cdfccce 100644
--- a/protogen/protogen.go
+++ b/protogen/protogen.go
@@ -379,13 +379,14 @@
 	Desc  protoreflect.FileDescriptor
 	Proto *descriptorpb.FileDescriptorProto
 
-	GoPackageName GoPackageName // name of this file's Go package
-	GoImportPath  GoImportPath  // import path of this file's Go package
-	Messages      []*Message    // top-level message declarations
-	Enums         []*Enum       // top-level enum declarations
-	Extensions    []*Extension  // top-level extension declarations
-	Services      []*Service    // top-level service declarations
-	Generate      bool          // true if we should generate code for this file
+	GoDescriptorIdent GoIdent       // name of Go variable for the file descriptor
+	GoPackageName     GoPackageName // name of this file's Go package
+	GoImportPath      GoImportPath  // import path of this file's Go package
+	Messages          []*Message    // top-level message declarations
+	Enums             []*Enum       // top-level enum declarations
+	Extensions        []*Extension  // top-level extension declarations
+	Services          []*Service    // top-level service declarations
+	Generate          bool          // true if we should generate code for this file
 
 	// GeneratedFilenamePrefix is used to construct filenames for generated
 	// files associated with this source file.
@@ -429,6 +430,10 @@
 			prefix = path.Join(string(importPath), path.Base(prefix))
 		}
 	}
+	f.GoDescriptorIdent = GoIdent{
+		GoName:       camelCase(cleanGoName(path.Base(prefix), true)) + "_ProtoFile",
+		GoImportPath: f.GoImportPath,
+	}
 	f.GeneratedFilenamePrefix = prefix
 
 	for _, loc := range p.GetSourceCodeInfo().GetLocation() {