code_generator.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 
36 
42 
43 namespace google {
44 namespace protobuf {
45 namespace compiler {
46 
48 
49 bool CodeGenerator::GenerateAll(const std::vector<const FileDescriptor*>& files,
50  const std::string& parameter,
51  GeneratorContext* generator_context,
52  std::string* error) const {
53  // Default implemenation is just to call the per file method, and prefix any
54  // error string with the file to provide context.
55  bool succeeded = true;
56  for (int i = 0; i < files.size(); i++) {
57  const FileDescriptor* file = files[i];
58  succeeded = Generate(file, parameter, generator_context, error);
59  if (!succeeded && error && error->empty()) {
60  *error =
61  "Code generator returned false but provided no error "
62  "description.";
63  }
64  if (error && !error->empty()) {
65  *error = file->name() + ": " + *error;
66  break;
67  }
68  if (!succeeded) {
69  break;
70  }
71  }
72  return succeeded;
73 }
74 
76 
78  const std::string& filename) {
79  return NULL;
80 }
81 
83  const std::string& filename, const std::string& insertion_point) {
84  GOOGLE_LOG(FATAL) << "This GeneratorContext does not support insertion.";
85  return NULL; // make compiler happy
86 }
87 
89  std::vector<const FileDescriptor*>* output) {
90  GOOGLE_LOG(FATAL) << "This GeneratorContext does not support ListParsedFiles";
91 }
92 
94  version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000);
95  version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000);
96  version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000);
98 }
99 
100 // Parses a set of comma-delimited name/value pairs.
102  const std::string& text,
103  std::vector<std::pair<std::string, std::string> >* output) {
104  std::vector<std::string> parts = Split(text, ",", true);
105 
106  for (int i = 0; i < parts.size(); i++) {
107  std::string::size_type equals_pos = parts[i].find_first_of('=');
108  std::pair<std::string, std::string> value;
109  if (equals_pos == std::string::npos) {
110  value.first = parts[i];
111  value.second = "";
112  } else {
113  value.first = parts[i].substr(0, equals_pos);
114  value.second = parts[i].substr(equals_pos + 1);
115  }
116  output->push_back(value);
117  }
118 }
119 
120 } // namespace compiler
121 } // namespace protobuf
122 } // namespace google
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
google::protobuf::compiler::GeneratorContext::GetCompilerVersion
virtual void GetCompilerVersion(Version *version) const
Definition: code_generator.cc:93
NULL
NULL
Definition: test_security_zap.cpp:405
FATAL
const int FATAL
Definition: log_severity.h:60
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::compiler::GeneratorContext::ListParsedFiles
virtual void ListParsedFiles(std::vector< const FileDescriptor * > *output)
Definition: code_generator.cc:88
error
Definition: cJSON.c:88
strutil.h
google::protobuf::compiler::GeneratorContext::OpenForInsert
virtual io::ZeroCopyOutputStream * OpenForInsert(const std::string &filename, const std::string &insertion_point)
Definition: code_generator.cc:82
google::protobuf::compiler::GeneratorContext::~GeneratorContext
virtual ~GeneratorContext()
Definition: code_generator.cc:75
GOOGLE_LOG
#define GOOGLE_LOG(LEVEL)
Definition: logging.h:146
code_generator.h
google::protobuf::compiler::GeneratorContext::OpenForAppend
virtual io::ZeroCopyOutputStream * OpenForAppend(const std::string &filename)
Definition: code_generator.cc:77
i
int i
Definition: gmock-matchers_test.cc:764
google::protobuf::FileDescriptor::name
const std::string & name() const
GOOGLE_PROTOBUF_VERSION_SUFFIX
#define GOOGLE_PROTOBUF_VERSION_SUFFIX
Definition: common.h:87
google::protobuf::compiler::CodeGenerator::~CodeGenerator
virtual ~CodeGenerator()
Definition: code_generator.cc:47
google::protobuf.internal.api_implementation.Version
def Version()
Definition: api_implementation.py:147
common.h
google::protobuf::io::ZeroCopyOutputStream
Definition: zero_copy_stream.h:183
logging.h
google::protobuf::Split
std::vector< string > Split(const string &full, const char *delim, bool skip_empty=true)
Definition: strutil.h:235
descriptor.h
google::protobuf::compiler::ParseGeneratorParameter
void ParseGeneratorParameter(const std::string &text, std::vector< std::pair< std::string, std::string > > *output)
Definition: code_generator.cc:101
google::protobuf::compiler::CodeGenerator::Generate
virtual bool Generate(const FileDescriptor *file, const std::string &parameter, GeneratorContext *generator_context, std::string *error) const =0
google::protobuf::FileDescriptor
Definition: src/google/protobuf/descriptor.h:1320
GOOGLE_PROTOBUF_VERSION
#define GOOGLE_PROTOBUF_VERSION
Definition: common.h:84
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
google::protobuf::compiler::CodeGenerator::GenerateAll
virtual bool GenerateAll(const std::vector< const FileDescriptor * > &files, const std::string &parameter, GeneratorContext *generator_context, std::string *error) const
Definition: code_generator.cc:49
version
static struct @0 version
google::protobuf::compiler::GeneratorContext
Definition: code_generator.h:119
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11
plugin.pb.h


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48