~ubuntu-branches/ubuntu/precise/protobuf/precise

« back to all changes in this revision

Viewing changes to src/google/protobuf/compiler/command_line_interface.cc

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2009-11-16 10:41:33 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091116104133-ykhy3deg5l4975tw
Tags: 2.1.0-1ubuntu1
* Merge from Debian testing.
* Remaining Ubuntu changes:
  - Disable the death tests on IA64, now as a quilt patch.
  - Don't use python2.4, also as a quilt patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
133
133
                                           public io::ErrorCollector {
134
134
 public:
135
 
  ErrorPrinter() {}
 
135
  ErrorPrinter(ErrorFormat format) : format_(format) {}
136
136
  ~ErrorPrinter() {}
137
137
 
138
138
  // implements MultiFileErrorCollector ------------------------------
139
139
  void AddError(const string& filename, int line, int column,
140
140
                const string& message) {
 
141
 
 
142
    cerr << filename;
 
143
 
141
144
    // Users typically expect 1-based line/column numbers, so we add 1
142
145
    // to each here.
143
 
    cerr << filename;
144
146
    if (line != -1) {
145
 
      cerr << ":" << (line + 1) << ":" << (column + 1);
 
147
      // Allow for both GCC- and Visual-Studio-compatible output.
 
148
      switch (format_) {
 
149
        case CommandLineInterface::ERROR_FORMAT_GCC:
 
150
          cerr << ":" << (line + 1) << ":" << (column + 1);
 
151
          break;
 
152
        case CommandLineInterface::ERROR_FORMAT_MSVS:
 
153
          cerr << "(" << (line + 1) << ") : error in column=" << (column + 1);
 
154
          break;
 
155
      }
146
156
    }
 
157
 
147
158
    cerr << ": " << message << endl;
148
159
  }
149
160
 
151
162
  void AddError(int line, int column, const string& message) {
152
163
    AddError("input", line, column, message);
153
164
  }
 
165
 
 
166
 private:
 
167
  const ErrorFormat format_;
154
168
};
155
169
 
156
170
// -------------------------------------------------------------------
294
308
 
295
309
CommandLineInterface::CommandLineInterface()
296
310
  : mode_(MODE_COMPILE),
 
311
    error_format_(ERROR_FORMAT_GCC),
297
312
    imports_in_descriptor_set_(false),
298
313
    disallow_services_(false),
299
314
    inputs_are_proto_path_relative_(false) {}
326
341
  }
327
342
 
328
343
  // Allocate the Importer.
329
 
  ErrorPrinter error_collector;
 
344
  ErrorPrinter error_collector(error_format_);
330
345
  Importer importer(&source_tree, &error_collector);
331
346
 
332
347
  vector<const FileDescriptor*> parsed_files;
657
672
 
658
673
    codec_type_ = value;
659
674
 
 
675
  } else if (name == "--error_format") {
 
676
    if (value == "gcc") {
 
677
      error_format_ = ERROR_FORMAT_GCC;
 
678
    } else if (value == "msvs") {
 
679
      error_format_ = ERROR_FORMAT_MSVS;
 
680
    } else {
 
681
      cerr << "Unknown error format: " << value << endl;
 
682
      return false;
 
683
    }
 
684
 
660
685
  } else {
661
686
    // Some other flag.  Look it up in the generators list.
662
687
    GeneratorMap::const_iterator iter = generators_.find(name);
722
747
"                              the input files to FILE.\n"
723
748
"  --include_imports           When using --descriptor_set_out, also include\n"
724
749
"                              all dependencies of the input files in the\n"
725
 
"                              set, so that the set is self-contained." << endl;
 
750
"                              set, so that the set is self-contained.\n"
 
751
"  --error_format=FORMAT       Set the format in which to print errors.\n"
 
752
"                              FORMAT may be 'gcc' (the default) or 'msvs'\n"
 
753
"                              (Microsoft Visual Studio format)." << endl;
726
754
 
727
755
  for (GeneratorMap::iterator iter = generators_.begin();
728
756
       iter != generators_.end(); ++iter) {
751
779
  if (!output_directive.generator->Generate(
752
780
      parsed_file, output_directive.parameter, &output_directory, &error)) {
753
781
    // Generator returned an error.
754
 
    cerr << output_directive.name << ": " << error << endl;
 
782
    cerr << parsed_file->name() << ": " << output_directive.name << ": "
 
783
         << error << endl;
755
784
    return false;
756
785
  }
757
786
 
787
816
 
788
817
  if (mode_ == MODE_ENCODE) {
789
818
    // Input is text.
790
 
    ErrorPrinter error_collector;
 
819
    ErrorPrinter error_collector(error_format_);
791
820
    TextFormat::Parser parser;
792
821
    parser.RecordErrorsTo(&error_collector);
793
822
    parser.AllowPartialMessage(true);