| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (parsed_files.back() == NULL) { | 111 if (parsed_files.back() == NULL) { |
| 112 *error_msg = "protoc asked plugin to generate a file but " | 112 *error_msg = "protoc asked plugin to generate a file but " |
| 113 "did not provide a descriptor for the file: " + | 113 "did not provide a descriptor for the file: " + |
| 114 request.file_to_generate(i); | 114 request.file_to_generate(i); |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 GeneratorResponseContext context(response, parsed_files); | 119 GeneratorResponseContext context(response, parsed_files); |
| 120 | 120 |
| 121 if (generator.HasGenerateAll()) { | 121 string error; |
| 122 string error; | 122 bool succeeded = generator.GenerateAll( |
| 123 bool succeeded = generator.GenerateAll( | 123 parsed_files, request.parameter(), &context, &error); |
| 124 parsed_files, request.parameter(), &context, &error); | |
| 125 | 124 |
| 126 if (!succeeded && error.empty()) { | 125 if (!succeeded && error.empty()) { |
| 127 error = "Code generator returned false but provided no error " | 126 error = "Code generator returned false but provided no error " |
| 128 "description."; | 127 "description."; |
| 129 } | 128 } |
| 130 if (!error.empty()) { | 129 if (!error.empty()) { |
| 131 response->set_error(error); | 130 response->set_error(error); |
| 132 } | |
| 133 } else { | |
| 134 for (int i = 0; i < parsed_files.size(); i++) { | |
| 135 const FileDescriptor* file = parsed_files[i]; | |
| 136 | |
| 137 string error; | |
| 138 bool succeeded = generator.Generate( | |
| 139 file, request.parameter(), &context, &error); | |
| 140 | |
| 141 if (!succeeded && error.empty()) { | |
| 142 error = "Code generator returned false but provided no error " | |
| 143 "description."; | |
| 144 } | |
| 145 if (!error.empty()) { | |
| 146 response->set_error(file->name() + ": " + error); | |
| 147 break; | |
| 148 } | |
| 149 } | |
| 150 } | 131 } |
| 151 | 132 |
| 152 return true; | 133 return true; |
| 153 } | 134 } |
| 154 | 135 |
| 155 int PluginMain(int argc, char* argv[], const CodeGenerator* generator) { | 136 int PluginMain(int argc, char* argv[], const CodeGenerator* generator) { |
| 156 | 137 |
| 157 if (argc > 1) { | 138 if (argc > 1) { |
| 158 std::cerr << argv[0] << ": Unknown option: " << argv[1] << std::endl; | 139 std::cerr << argv[0] << ": Unknown option: " << argv[1] << std::endl; |
| 159 return 1; | 140 return 1; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 185 } | 166 } |
| 186 return 1; | 167 return 1; |
| 187 } | 168 } |
| 188 | 169 |
| 189 return 0; | 170 return 0; |
| 190 } | 171 } |
| 191 | 172 |
| 192 } // namespace compiler | 173 } // namespace compiler |
| 193 } // namespace protobuf | 174 } // namespace protobuf |
| 194 } // namespace google | 175 } // namespace google |
| OLD | NEW |