~verterok/ubuntu/lucid/protobuf/2.4.0a-backport

« back to all changes in this revision

Viewing changes to src/google/protobuf/compiler/python/python_generator.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
 
231
231
bool Generator::Generate(const FileDescriptor* file,
232
232
                         const string& parameter,
233
 
                         OutputDirectory* output_directory,
 
233
                         GeneratorContext* context,
234
234
                         string* error) const {
235
235
 
236
236
  // Completely serialize all Generate() calls on this instance.  The
252
252
  fdp.SerializeToString(&file_descriptor_serialized_);
253
253
 
254
254
 
255
 
  scoped_ptr<io::ZeroCopyOutputStream> output(output_directory->Open(filename));
 
255
  scoped_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
256
256
  GOOGLE_CHECK(output.get());
257
257
  io::Printer printer(output.get(), '$');
258
258
  printer_ = &printer;
259
259
 
260
260
  PrintTopBoilerplate(printer_, file_, GeneratingDescriptorProto());
 
261
  PrintImports();
261
262
  PrintFileDescriptor();
262
263
  PrintTopLevelEnums();
263
264
  PrintTopLevelExtensions();
264
265
  PrintAllNestedEnumsInFile();
265
266
  PrintMessageDescriptors();
266
 
  // We have to print the imports after the descriptors, so that mutually
267
 
  // recursive protos in separate files can successfully reference each other.
268
 
  PrintImports();
269
267
  FixForeignFieldsInDescriptors();
270
268
  PrintMessages();
271
269
  // We have to fix up the extensions after the message classes themselves,
377
375
  printer_->Print("containing_type=None,\n");
378
376
  printer_->Print("options=$options_value$,\n",
379
377
                  "options_value",
380
 
                  OptionsValue("EnumOptions", CEscape(options_string)));
 
378
                  OptionsValue("EnumOptions", options_string));
381
379
  EnumDescriptorProto edp;
382
380
  PrintSerializedPbInterval(enum_descriptor, edp);
383
381
  printer_->Outdent();
674
672
  }
675
673
}
676
674
 
 
675
void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
 
676
  map<string, string> m;
 
677
  m["descriptor_name"] = kDescriptorKey;
 
678
  m["message_name"] = descriptor.name();
 
679
  m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
 
680
  const char file_descriptor_template[] =
 
681
      "$descriptor_name$.message_types_by_name['$message_name$'] = "
 
682
      "$message_descriptor_name$\n";
 
683
  printer_->Print(m, file_descriptor_template);
 
684
}
 
685
 
677
686
// Sets any necessary message_type and enum_type attributes
678
687
// for the Python version of |field|.
679
688
//
752
761
  for (int i = 0; i < file_->message_type_count(); ++i) {
753
762
    FixForeignFieldsInDescriptor(*file_->message_type(i), NULL);
754
763
  }
 
764
  for (int i = 0; i < file_->message_type_count(); ++i) {
 
765
    AddMessageToFileDescriptor(*file_->message_type(i));
 
766
  }
755
767
  printer_->Print("\n");
756
768
}
757
769
 
823
835
      "  type=None)");
824
836
}
825
837
 
 
838
// Returns a Python expression that calls descriptor._ParseOptions using
 
839
// the given descriptor class name and serialized options protobuf string.
826
840
string Generator::OptionsValue(
827
841
    const string& class_name, const string& serialized_options) const {
828
842
  if (serialized_options.length() == 0 || GeneratingDescriptorProto()) {