Lines Matching defs:File
75 // Generate produces the code generated by the plugin for this file,
77 Generate(file *FileDescriptor)
78 // GenerateImports produces the import declarations for this file.
80 GenerateImports(file *FileDescriptor)
93 // wrapping by placing each Proto inside a struct with the pointer to its File. The
97 // The file and package name method are common to messages and enums.
99 file *descriptor.FileDescriptorProto // File this object comes from.
102 // PackageName is name in the package clause in the generated file.
103 func (c *common) PackageName() string { return uniquePackageOf(c.file) }
105 func (c *common) File() *descriptor.FileDescriptorProto { return c.file }
107 func fileIsProto3(file *descriptor.FileDescriptorProto) bool {
108 return file.GetSyntax() == "proto3"
111 func (c *common) proto3() bool { return fileIsProto3(c.file) }
122 index int // The index into the container, whether the file or another message.
153 index int // The index into the container, whether the file or a message.
233 // ImportedDescriptor describes a type that has been publicly imported from another file.
241 // FileDescriptor describes an protocol buffer descriptor file (.proto).
246 desc []*Descriptor // All the messages defined in this file.
247 enum []*EnumDescriptor // All the enums defined in this file.
248 ext []*ExtensionDescriptor // All the top-level extensions defined in this file.
249 imp []*ImportedDescriptor // All types defined in files publicly imported by this file.
259 index int // The index of this file in the list of files to generate code for
261 proto3 bool // whether to generate proto3 code for this file
264 // PackageName is the package name we'll use in the generated code to refer to this file.
272 // goPackageOption interprets the file's go_package option.
298 // generated Go file. The result explicit reports whether the name
301 // or the input file name.
303 // Does the file have a "go_package" option?
308 // Does the file have a package clause?
312 // Use the file base name.
316 // goFileName returns the output name for the generated Go file.
324 // Does the file have a "go_package" option?
503 proto3 bool // Whether this came from a proto3 file.
536 File() *descriptor.FileDescriptorProto
560 ImportPrefix string // String to prefix to imported package file names.
561 ImportMap map[string]string // Mapping from .proto file name to import path
569 file *FileDescriptor // The file we are compiling now.
570 usedPackages map[string]bool // Names of packages used in current file.
602 // It then sets file name mappings defined by those entries.
646 // If its file is in a different package, it returns the package name we're using for this file, plus ".".
656 // For each input file, the unique package name to use, underscored.
659 // Package names already registered. Key is the name from the .proto file;
663 // Create and remember a guaranteed unique package name for this file descriptor.
665 // has no file descriptor.
746 // Let this file's go_package option serve for all input files.
794 // The file is a dependency, so we want to ignore its go_package option
805 // and FileDescriptorProtos into file-referenced objects within the Generator.
837 g.Fail("could not find file named", fileName)
844 // Scan the descriptors in this file. For each one, build the slice of nested descriptors
876 func newDescriptor(desc *descriptor.DescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) *Descriptor {
878 common: common{file},
893 if file.Package != nil {
894 parts = append([]string{*file.Package}, parts...)
906 d.ext = append(d.ext, &ExtensionDescriptor{common{file}, field, d})
912 // Return a slice of all the Descriptors defined within this file
913 func wrapDescriptors(file *descriptor.FileDescriptorProto) []*Descriptor {
914 sl := make([]*Descriptor, 0, len(file.MessageType)+10)
915 for i, desc := range file.MessageType {
916 sl = wrapThisDescriptor(sl, desc, nil, file, i)
922 func wrapThisDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) []*Descriptor {
923 sl = append(sl, newDescriptor(desc, parent, file, index))
926 sl = wrapThisDescriptor(sl, nested, me, file, i)
932 func newEnumDescriptor(desc *descriptor.EnumDescriptorProto, parent *Descriptor, file *descriptor.FileDescriptorProto, index int) *EnumDescriptor {
934 common: common{file},
947 // Return a slice of all the EnumDescriptors defined within this file
948 func wrapEnumDescriptors(file *descriptor.FileDescriptorProto, descs []*Descriptor) []*EnumDescriptor {
949 sl := make([]*EnumDescriptor, 0, len(file.EnumType)+10)
951 for i, enum := range file.EnumType {
952 sl = append(sl, newEnumDescriptor(enum, nil, file, i))
957 sl = append(sl, newEnumDescriptor(enum, nested, file, i))
963 // Return a slice of all the top-level ExtensionDescriptors defined within this file.
964 func wrapExtensions(file *descriptor.FileDescriptorProto) []*ExtensionDescriptor {
966 for _, field := range file.Extension {
967 sl = append(sl, &ExtensionDescriptor{common{file}, field, nil})
972 // Return a slice of all the types that are publicly imported into this file.
973 func wrapImported(file *descriptor.FileDescriptorProto, g *Generator) (sl []*ImportedDescriptor) {
974 for _, index := range file.PublicDependency {
975 df := g.fileByName(file.Dependency[index])
980 sl = append(sl, &ImportedDescriptor{common{file}, d})
983 sl = append(sl, &ImportedDescriptor{common{file}, e})
986 sl = append(sl, &ImportedDescriptor{common{file}, ext})
992 func extractComments(file *FileDescriptor) {
993 file.comments = make(map[string]*descriptor.SourceCodeInfo_Location)
994 for _, loc := range file
1002 file.comments[strings.Join(p, ",")] = loc
1038 // If the file of this object isn't a direct dependency of the current file,
1039 // or in the current file, then this object has been publicly imported into
1040 // a dependency of the current file.
1042 direct := *o.File().Name == *g.file.Name
1044 for _, dep := range g.file.Dependency {
1045 if *g.fileByName(dep).Name == *o.File().Name {
1054 for _, dep := range g.file.Dependency {
1066 log.Printf("protoc-gen-go: WARNING: failed finding publicly imported dependency for %v, used in %v", typeName, *g.file.Name)
1107 // addInitf stores the given statement to be printed inside the file's init function.
1129 // Generate the output. The generator runs for every file, even the files
1133 for _, file := range g.genFiles {
1134 genFileMap[file] = true
1136 for _, file := range g.allFiles {
1138 g.writeOutput = genFileMap[file]
1139 g.generate(file)
1143 g.Response.File = append(g.Response.File, &plugin.CodeGeneratorResponse_File{
1144 Name: proto.String(file.goFileName()),
1150 // Run all the plugins associated with the file.
1151 func (g *Generator) runPlugins(file *FileDescriptor) {
1153 p.Generate(file)
1159 for _, file := range g.allFiles {
1160 if file.FileDescriptorProto == fd {
1161 return file
1164 g.Fail("could not find file in table:", fd.GetName())
1170 func (g *Generator) generate(file *FileDescriptor) {
1171 g.file = g.FileOf(file.FileDescriptorProto)
1174 if g.file.index == 0 {
1175 // For one file in the package, assert version compatibility.
1176 g.P("// This is a compile-time assertion to ensure that this generated file")
1183 for _, td := range g.file.imp {
1186 for _, enum := range g.file.enum {
1189 for _, desc := range g.file.desc {
1196 for _, ext := range g.file.ext {
1202 g.runPlugins(file)
1204 g.generateFileDescriptor(file)
1241 g.P("// source: ", g.file.Name)
1244 name := g.file.PackageName()
1246 if g.file.index == 0 {
1247 // Generate package docs for the first file in the package.
1251 if loc, ok := g.file.comments[strconv.Itoa(packagePath)]; ok {
1285 // PrintComments prints any comments from the source .proto file.
1293 if loc, ok := g.file.comments[path]; ok {
1307 // weak returns whether the ith import of the current file is a weak import.
1309 for _, j := range g.file.WeakDependency {
1325 for i, s := range g.file.Dependency {
1355 p.GenerateImports(g.file)
1372 df := g.FileOf(id.o.File())
1401 g.file.addExport(enum, enumSymbol{ccTypeName, enum.proto3()})
1409 g.file.addExport(enum, constOrVarSymbol{name, "const", ccTypeName})
1471 g.P("func (", ccTypeName, ") EnumDescriptor() ([]byte, []int) { return ", g.file.VarName(), ", []int{", strings.Join(indexes, ", "), "} }")
1472 if enum.file.GetPackage() == "google.protobuf" && enum.GetName() == "NullValue" {
1545 if pkg := obj.File().GetPackage(); pkg != "" {
1611 // TypeName is the printed name appropriate for an item. If the object is in the current file,
1778 // in the proto file, meaning that a change in the field
1912 g.P("func (*", ccTypeName, ") Descriptor() ([]byte, []int) { return ", g.file.VarName(), ", []int{", strings.Join(indexes, ", "), "} }")
1915 if message.file.GetPackage() == "google.protobuf" && wellKnownTypes[message.GetName()] {
2020 g.file.addExport(message, constOrVarSymbol{fieldname, kind, ""})
2209 g.file.addExport(message, ms)
2504 if g.file.Package != nil {
2505 fullName = *g.file.Package + "." + fullName
2544 // For text formatting, the package must be exactly what the .proto file declares,
2547 if g.file.Package != nil {
2548 extName = *g.file.Package + "." + extName
2558 g.P(`Filename: "`, g.file.GetName(), `",`)
2569 g.file.addExport(ext, constOrVarSymbol{ccTypeName, "var", ""})
2573 for _, enum := range g.file.enum {
2576 for _, d := range g.file.desc {
2581 for _, ext := range g.file.ext {
2597 func (g *Generator) generateFileDescriptor(file *FileDescriptor) {
2600 pb := proto.Clone(file.FileDescriptorProto).(*descriptor.FileDescriptorProto)
2614 v := file.VarName()
2616 g.P("func init() { ", g.Pkg["proto"], ".RegisterFile(", strconv.Quote(*file.Name), ", ", v, ") }")
2640 pkg := enum.File().GetPackage()
2763 // which can be dotted in the input .proto file. It replaces non-identifier characters such as
2786 // .proto file by way of a "path", which is a sequence of integers that