Index: third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/code_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc |
similarity index 50% |
copy from third_party/protobuf/src/google/protobuf/compiler/code_generator.cc |
copy to third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc |
index 455c239a936bd9cec724ab65e85092b743fa1070..375b4e0f548b4b05db2996c0faebf0cab9e72009 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/code_generator.cc |
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -28,53 +28,64 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// Author: kenton@google.com (Kenton Varda) |
-// Based on original Protocol Buffers design by |
-// Sanjay Ghemawat, Jeff Dean, and others. |
- |
-#include <google/protobuf/compiler/code_generator.h> |
- |
-#include <google/protobuf/stubs/common.h> |
+#include <iostream> |
+#include <google/protobuf/compiler/objectivec/objectivec_generator.h> |
+#include <google/protobuf/compiler/objectivec/objectivec_file.h> |
+#include <google/protobuf/compiler/objectivec/objectivec_helpers.h> |
+#include <google/protobuf/io/printer.h> |
+#include <google/protobuf/io/zero_copy_stream.h> |
#include <google/protobuf/stubs/strutil.h> |
namespace google { |
namespace protobuf { |
namespace compiler { |
+namespace objectivec { |
-CodeGenerator::~CodeGenerator() {} |
-GeneratorContext::~GeneratorContext() {} |
+ObjectiveCGenerator::ObjectiveCGenerator() {} |
-io::ZeroCopyOutputStream* GeneratorContext::OpenForInsert( |
- const string& filename, const string& insertion_point) { |
- GOOGLE_LOG(FATAL) << "This GeneratorContext does not support insertion."; |
- return NULL; // make compiler happy |
-} |
+ObjectiveCGenerator::~ObjectiveCGenerator() {} |
-void GeneratorContext::ListParsedFiles( |
- vector<const FileDescriptor*>* output) { |
- GOOGLE_LOG(FATAL) << "This GeneratorContext does not support ListParsedFiles"; |
-} |
+bool ObjectiveCGenerator::Generate(const FileDescriptor* file, |
+ const string& parameter, |
+ OutputDirectory* output_directory, |
+ string* error) const { |
+ // ObjC doesn't have any options at the moment, error if passed one. |
+ vector<pair<string, string> > options; |
+ ParseGeneratorParameter(parameter, &options); |
+ for (int i = 0; i < options.size(); i++) { |
+ *error = "error:: Unknown generator option: " + options[i].first; |
+ return false; |
+ } |
-// Parses a set of comma-delimited name/value pairs. |
-void ParseGeneratorParameter(const string& text, |
- vector<pair<string, string> >* output) { |
- vector<string> parts; |
- SplitStringUsing(text, ",", &parts); |
+ // Validate the objc prefix/package pairing. |
+ if (!ValidateObjCClassPrefix(file, error)) { |
+ // *error will have been filled in. |
+ return false; |
+ } |
+ |
+ FileGenerator file_generator(file); |
+ string filepath = FilePath(file); |
- for (int i = 0; i < parts.size(); i++) { |
- string::size_type equals_pos = parts[i].find_first_of('='); |
- pair<string, string> value; |
- if (equals_pos == string::npos) { |
- value.first = parts[i]; |
- value.second = ""; |
- } else { |
- value.first = parts[i].substr(0, equals_pos); |
- value.second = parts[i].substr(equals_pos + 1); |
- } |
- output->push_back(value); |
+ // Generate header. |
+ { |
+ scoped_ptr<io::ZeroCopyOutputStream> output( |
+ output_directory->Open(filepath + ".pbobjc.h")); |
+ io::Printer printer(output.get(), '$'); |
+ file_generator.GenerateHeader(&printer); |
} |
+ |
+ // Generate m file. |
+ { |
+ scoped_ptr<io::ZeroCopyOutputStream> output( |
+ output_directory->Open(filepath + ".pbobjc.m")); |
+ io::Printer printer(output.get(), '$'); |
+ file_generator.GenerateSource(&printer); |
+ } |
+ |
+ return true; |
} |
+} // namespace objectivec |
} // namespace compiler |
} // namespace protobuf |
} // namespace google |