protogen: generate message skeletons

Copy generator.CamelCase for camel-casing names, with one change: Convert
'.' in names to '_'. This removes the need for the CamelCaseSlice function
which operates on a []string representing a name split along '.'s.

Add protogen.Message.

Reformat generated code.

Add regenerate.bash, largely copied from regenerate.sh.

Change-Id: Iecf0bfc43b552f53e458499a328b933b0c9c5f82
Reviewed-on: https://go-review.googlesource.com/130915
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go/main.go b/cmd/protoc-gen-go/main.go
index 9ea1420..7973895 100644
--- a/cmd/protoc-gen-go/main.go
+++ b/cmd/protoc-gen-go/main.go
@@ -30,6 +30,21 @@
 	g.P("// source: ", f.Desc.GetName())
 	g.P()
 	g.P("package TODO")
+	g.P()
+
+	for _, m := range f.Messages {
+		genMessage(gen, g, m)
+	}
 
 	// TODO: Everything.
 }
+
+func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, m *protogen.Message) {
+	g.P("type ", m.GoIdent, " struct {")
+	g.P("}")
+	g.P()
+
+	for _, nested := range m.Messages {
+		genMessage(gen, g, nested)
+	}
+}
diff --git a/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go b/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go
new file mode 100644
index 0000000..014d3a4
--- /dev/null
+++ b/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go
@@ -0,0 +1,13 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: proto2/nested_messages.proto
+
+package TODO
+
+type Layer1 struct {
+}
+
+type Layer1_Layer2 struct {
+}
+
+type Layer1_Layer2_Layer3 struct {
+}
diff --git a/cmd/protoc-gen-go/testdata/proto2/nested_messages.proto b/cmd/protoc-gen-go/testdata/proto2/nested_messages.proto
new file mode 100644
index 0000000..85e77b2
--- /dev/null
+++ b/cmd/protoc-gen-go/testdata/proto2/nested_messages.proto
@@ -0,0 +1,19 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+syntax = "proto2";
+
+package goproto.protoc.proto2;
+
+option go_package = "google.golang.org/proto/cmd/protoc-gen-go/testdata/proto2";
+
+message Layer1 {
+  message Layer2 {
+    message Layer3 {
+    }
+    optional Layer3 l3 = 1;
+  }
+  optional Layer2 l2 = 1;
+  optional Layer2.Layer3 l3 = 2;
+}
diff --git a/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go b/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
index 558363d..771028e 100644
--- a/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
@@ -2,3 +2,6 @@
 // source: proto2/proto2.proto
 
 package TODO
+
+type Message struct {
+}